mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
Some foldable optimizations
This commit is contained in:
parent
7c44527f91
commit
4a8918a9c6
10 changed files with 256 additions and 184 deletions
28
Habitica/res/layout-w600dp/activity_main.xml
Normal file
28
Habitica/res/layout-w600dp/activity_main.xml
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
<!-- A DrawerLayout is intended to be used as the top-level content view using match_parent for both width and height to consume the full space available. -->
|
||||
<androidx.drawerlayout.widget.DrawerLayout
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
android:id="@+id/drawer_layout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context="com.habitrpg.android.habitica.ui.activities.MainActivity"
|
||||
android:background="@color/content_background">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:animateLayoutChanges="true">
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/navigation_drawer"
|
||||
class="com.habitrpg.android.habitica.ui.fragments.NavigationDrawerFragment"
|
||||
android:layout_width="@dimen/drawer_width"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="start"
|
||||
tools:layout="@layout/drawer_main"/>
|
||||
<View
|
||||
android:layout_width="1dp"
|
||||
android:layout_height="match_parent"
|
||||
android:background="@color/window_background"/>
|
||||
<include layout="@layout/activity_main_content" android:id="@+id/content" />
|
||||
</LinearLayout>
|
||||
</androidx.drawerlayout.widget.DrawerLayout>
|
||||
|
|
@ -11,149 +11,7 @@
|
|||
|
||||
<!-- As the main content view, the view below consumes the entire
|
||||
space available using match_parent in both dimensions. -->
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
tools:context=".ui.activities.MainActivity">
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/navigation" />
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsing_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:titleEnabled="false"
|
||||
app:contentScrim="?attr/headerBackgroundColor"
|
||||
android:background="?attr/headerBackgroundColor"
|
||||
app:expandedTitleMarginEnd="?attr/actionBarSize"
|
||||
app:expandedTitleMarginStart="0dp"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed">
|
||||
|
||||
<include
|
||||
android:id="@+id/avatar_with_bars"
|
||||
layout="@layout/avatar_with_bars"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:layout_marginEnd="@dimen/header_border_spacing"
|
||||
android:layout_marginStart="@dimen/header_border_spacing"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
style="@style/Toolbar.Modern"
|
||||
android:background="?attr/headerBackgroundColor"
|
||||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/Theme.AppCompat.DayNight"
|
||||
app:contentInsetStart="0dp"
|
||||
app:contentInsetStartWithNavigation="0dp">
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:layout_alignParentStart="true"
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
tools:text="Habitica"
|
||||
android:background="@drawable/teams_title_bg"
|
||||
android:paddingHorizontal="@dimen/spacing_large"
|
||||
android:paddingVertical="1dp"
|
||||
/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/toolbar_accessory_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="centerCrop"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/detail_tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?headerOffsetColor"
|
||||
android:elevation="0dp"
|
||||
android:fillViewport="false"
|
||||
app:layout_anchor="@+id/collapsing_toolbar"
|
||||
app:layout_anchorGravity="bottom"
|
||||
app:layout_collapseMode="pin"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="?colorPrimary"
|
||||
app:tabMode="fixed" />
|
||||
<FrameLayout
|
||||
android:id="@+id/connection_issue_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingVertical="2dp"
|
||||
android:paddingHorizontal="@dimen/spacing_medium"
|
||||
android:background="@color/error_banner_background"
|
||||
tools:visibility="visible"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/connection_issue_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/maroon_500"
|
||||
android:textSize="14sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/internal_error_api"
|
||||
app:drawableStartCompat="@drawable/ic_warning_black"
|
||||
app:drawableTint="@color/maroon_500"
|
||||
android:drawablePadding="4dp"/>
|
||||
</FrameLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/overlayFrameLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom|center_horizontal">
|
||||
<FrameLayout
|
||||
android:id="@+id/snackbar_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="400dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:paddingBottom="50dp"/>
|
||||
|
||||
<com.habitrpg.android.habitica.ui.views.navigation.HabiticaBottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
</RelativeLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
<include layout="@layout/activity_main_content" android:id="@+id/content" />
|
||||
|
||||
<!-- The drawer is given a fixed width in dp and extends the full height of
|
||||
the container. -->
|
||||
|
|
|
|||
146
Habitica/res/layout/activity_main_content.xml
Normal file
146
Habitica/res/layout/activity_main_content.xml
Normal file
|
|
@ -0,0 +1,146 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
xmlns:tools="http://schemas.android.com/tools"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
tools:context=".ui.activities.MainActivity">
|
||||
<androidx.fragment.app.FragmentContainerView
|
||||
android:id="@+id/nav_host_fragment"
|
||||
android:name="androidx.navigation.fragment.NavHostFragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
app:layout_behavior="@string/appbar_scrolling_view_behavior"
|
||||
app:defaultNavHost="true"
|
||||
app:navGraph="@navigation/navigation" />
|
||||
<com.google.android.material.appbar.AppBarLayout
|
||||
android:id="@+id/appbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
<com.google.android.material.appbar.CollapsingToolbarLayout
|
||||
android:id="@+id/collapsing_toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:titleEnabled="false"
|
||||
app:contentScrim="?attr/headerBackgroundColor"
|
||||
android:background="?attr/headerBackgroundColor"
|
||||
app:expandedTitleMarginEnd="?attr/actionBarSize"
|
||||
app:expandedTitleMarginStart="0dp"
|
||||
app:layout_scrollFlags="scroll|exitUntilCollapsed">
|
||||
|
||||
<include
|
||||
android:id="@+id/avatar_with_bars"
|
||||
layout="@layout/avatar_with_bars"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="?attr/actionBarSize"
|
||||
android:layout_marginEnd="@dimen/header_border_spacing"
|
||||
android:layout_marginStart="@dimen/header_border_spacing"
|
||||
android:layout_marginBottom="@dimen/spacing_medium"
|
||||
app:layout_collapseMode="parallax" />
|
||||
|
||||
<androidx.appcompat.widget.Toolbar
|
||||
android:id="@+id/toolbar"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:minHeight="?attr/actionBarSize"
|
||||
style="@style/Toolbar.Modern"
|
||||
android:background="?attr/headerBackgroundColor"
|
||||
app:layout_collapseMode="pin"
|
||||
app:popupTheme="@style/Theme.AppCompat.DayNight"
|
||||
app:contentInsetStart="0dp"
|
||||
app:contentInsetStartWithNavigation="0dp">
|
||||
<RelativeLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/toolbar_title"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_centerVertical="true"
|
||||
android:ellipsize="end"
|
||||
android:maxLines="1"
|
||||
android:singleLine="true"
|
||||
android:layout_alignParentStart="true"
|
||||
style="@style/TextAppearance.AppCompat.Widget.ActionBar.Title"
|
||||
tools:text="Habitica"
|
||||
android:background="@drawable/teams_title_bg"
|
||||
android:paddingHorizontal="@dimen/spacing_large"
|
||||
android:paddingVertical="1dp"
|
||||
/>
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/toolbar_accessory_container"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:scaleType="centerCrop"
|
||||
android:adjustViewBounds="true"
|
||||
android:layout_centerVertical="true"
|
||||
android:layout_alignParentEnd="true"/>
|
||||
|
||||
</RelativeLayout>
|
||||
</androidx.appcompat.widget.Toolbar>
|
||||
</com.google.android.material.appbar.CollapsingToolbarLayout>
|
||||
|
||||
<com.google.android.material.tabs.TabLayout
|
||||
android:id="@+id/detail_tabs"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="48dp"
|
||||
android:layout_gravity="bottom"
|
||||
android:background="?headerOffsetColor"
|
||||
android:elevation="0dp"
|
||||
android:fillViewport="false"
|
||||
app:layout_anchor="@+id/collapsing_toolbar"
|
||||
app:layout_anchorGravity="bottom"
|
||||
app:layout_collapseMode="pin"
|
||||
app:tabGravity="fill"
|
||||
app:tabIndicatorColor="?colorPrimary"
|
||||
app:tabMode="fixed" />
|
||||
<FrameLayout
|
||||
android:id="@+id/connection_issue_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingVertical="2dp"
|
||||
android:paddingHorizontal="@dimen/spacing_medium"
|
||||
android:background="@color/error_banner_background"
|
||||
tools:visibility="visible"
|
||||
android:visibility="gone"
|
||||
>
|
||||
<TextView
|
||||
android:id="@+id/connection_issue_textview"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/maroon_500"
|
||||
android:textSize="14sp"
|
||||
android:layout_gravity="center"
|
||||
android:gravity="center_vertical"
|
||||
android:text="@string/internal_error_api"
|
||||
app:drawableStartCompat="@drawable/ic_warning_black"
|
||||
app:drawableTint="@color/maroon_500"
|
||||
android:drawablePadding="4dp"/>
|
||||
</FrameLayout>
|
||||
</com.google.android.material.appbar.AppBarLayout>
|
||||
|
||||
<RelativeLayout
|
||||
android:id="@+id/overlayFrameLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom|center_horizontal">
|
||||
<FrameLayout
|
||||
android:id="@+id/snackbar_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="400dp"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:paddingBottom="50dp"/>
|
||||
|
||||
<com.habitrpg.android.habitica.ui.views.navigation.HabiticaBottomNavigationView
|
||||
android:id="@+id/bottom_navigation"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_alignParentBottom="true"
|
||||
android:layout_alignParentStart="true"
|
||||
android:layout_alignParentEnd="true" />
|
||||
</RelativeLayout>
|
||||
</androidx.coordinatorlayout.widget.CoordinatorLayout>
|
||||
4
Habitica/res/values-w600dp/dimens.xml
Normal file
4
Habitica/res/values-w600dp/dimens.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<dimen name="drawer_width">260dp</dimen>
|
||||
</resources>
|
||||
4
Habitica/res/values-w600dp/values.xml
Normal file
4
Habitica/res/values-w600dp/values.xml
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<resources>
|
||||
<bool name="isTabletUI">true</bool>
|
||||
</resources>
|
||||
|
|
@ -234,4 +234,6 @@
|
|||
<item>compact</item>
|
||||
<item>minimal</item>
|
||||
</string-array>
|
||||
|
||||
<bool name="isTabletUI">false</bool>
|
||||
</resources>
|
||||
|
|
|
|||
|
|
@ -98,7 +98,7 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
lateinit var binding: ActivityMainBinding
|
||||
|
||||
val snackbarContainer: ViewGroup
|
||||
get() = binding.snackbarContainer
|
||||
get() = binding.content.snackbarContainer
|
||||
|
||||
private var avatarInHeader: AvatarWithBarsViewModel? = null
|
||||
val notificationsViewModel: NotificationsViewModel by viewModels()
|
||||
|
|
@ -111,7 +111,7 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
private var lastNotificationOpen: Long? = null
|
||||
|
||||
val isAppBarExpanded: Boolean
|
||||
get() = binding.appbar.height - binding.appbar.bottom == 0
|
||||
get() = binding.content.appbar.height - binding.content.appbar.bottom == 0
|
||||
|
||||
override fun getLayoutResId(): Int {
|
||||
return R.layout.activity_main
|
||||
|
|
@ -145,9 +145,9 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
Wearable.getCapabilityClient(this).addLocalCapability("provide_auth")
|
||||
}
|
||||
|
||||
setupToolbar(binding.toolbar)
|
||||
setupToolbar(binding.content.toolbar)
|
||||
|
||||
avatarInHeader = AvatarWithBarsViewModel(this, binding.avatarWithBars, viewModel.userViewModel)
|
||||
avatarInHeader = AvatarWithBarsViewModel(this, binding.content.avatarWithBars, viewModel.userViewModel)
|
||||
sideAvatarView = AvatarView(this, showBackground = true, showMount = false, showPet = false)
|
||||
|
||||
viewModel.user.observe(this) {
|
||||
|
|
@ -215,11 +215,11 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
}
|
||||
|
||||
override fun setTitle(title: CharSequence?) {
|
||||
binding.toolbarTitle.text = title
|
||||
binding.content.toolbarTitle.text = title
|
||||
}
|
||||
|
||||
override fun setTitle(titleId: Int) {
|
||||
binding.toolbarTitle.text = getString(titleId)
|
||||
binding.content.toolbarTitle.text = getString(titleId)
|
||||
}
|
||||
|
||||
private fun updateToolbarTitle(destination: NavDestination, arguments: Bundle?) {
|
||||
|
|
@ -249,9 +249,9 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
}
|
||||
|
||||
private fun setupBottomnavigationLayoutListener() {
|
||||
binding.bottomNavigation.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
if (binding.bottomNavigation.visibility == View.VISIBLE) {
|
||||
snackbarContainer.setPadding(0, 0, 0, binding.bottomNavigation.barHeight + 12.dpToPx(this))
|
||||
binding.content.bottomNavigation.viewTreeObserver.addOnGlobalLayoutListener {
|
||||
if (binding.content.bottomNavigation.visibility == View.VISIBLE) {
|
||||
snackbarContainer.setPadding(0, 0, 0, binding.content.bottomNavigation.barHeight + 12.dpToPx(this))
|
||||
} else {
|
||||
snackbarContainer.setPadding(0, 0, 0, 0)
|
||||
}
|
||||
|
|
@ -272,7 +272,10 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
}
|
||||
|
||||
override fun onOptionsItemSelected(item: MenuItem): Boolean {
|
||||
return if (drawerToggle?.onOptionsItemSelected(item) == true) {
|
||||
return if (binding.root.parent is DrawerLayout && drawerToggle?.onOptionsItemSelected(item) == true) {
|
||||
true
|
||||
} else if (item.itemId == android.R.id.home) {
|
||||
drawerFragment?.toggleDrawer()
|
||||
true
|
||||
} else super.onOptionsItemSelected(item)
|
||||
}
|
||||
|
|
@ -326,7 +329,7 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
launchTrace?.stop()
|
||||
launchTrace = null
|
||||
|
||||
if (binding.toolbarTitle.text?.isNotBlank() != true) {
|
||||
if (binding.content.toolbarTitle.text?.isNotBlank() != true) {
|
||||
navigationController.currentDestination?.let { updateToolbarTitle(it, null) }
|
||||
}
|
||||
}
|
||||
|
|
@ -401,7 +404,7 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
viewModel.updateUser("flags.welcomed", true)
|
||||
}
|
||||
|
||||
val title = binding.toolbarTitle.text
|
||||
val title = binding.content.toolbarTitle.text
|
||||
if (title.isBlank()) {
|
||||
viewModel.getToolbarTitle(0, null, null) { newTitle ->
|
||||
this.title = newTitle
|
||||
|
|
@ -485,12 +488,12 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
val view = TutorialView(this, step, viewModel)
|
||||
view.setTutorialTexts(texts)
|
||||
view.setCanBeDeferred(canBeDeferred)
|
||||
binding.overlayFrameLayout.children.forEach {
|
||||
binding.content.overlayFrameLayout.children.forEach {
|
||||
if (it is TutorialView) {
|
||||
binding.overlayFrameLayout.removeView(it)
|
||||
binding.content.overlayFrameLayout.removeView(it)
|
||||
}
|
||||
}
|
||||
binding.overlayFrameLayout.addView(view)
|
||||
binding.content.overlayFrameLayout.addView(view)
|
||||
viewModel.logTutorialStatus(step, false)
|
||||
}
|
||||
|
||||
|
|
@ -544,11 +547,11 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
// a new error resets the timer to hide the error message
|
||||
errorJob?.cancel()
|
||||
}
|
||||
binding.connectionIssueView.visibility = View.VISIBLE
|
||||
binding.connectionIssueTextview.text = message
|
||||
binding.content.connectionIssueView.visibility = View.VISIBLE
|
||||
binding.content.connectionIssueTextview.text = message
|
||||
errorJob = lifecycleScope.launch(Dispatchers.Main) {
|
||||
delay(1.toDuration(DurationUnit.MINUTES))
|
||||
binding.connectionIssueView.visibility = View.GONE
|
||||
binding.content.connectionIssueView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -558,8 +561,8 @@ open class MainActivity : BaseActivity(), SnackbarActivity {
|
|||
errorJob?.cancel()
|
||||
}
|
||||
lifecycleScope.launch(Dispatchers.Main) {
|
||||
if (binding.connectionIssueView.visibility == View.VISIBLE) {
|
||||
binding.connectionIssueView.visibility = View.GONE
|
||||
if (binding.content.connectionIssueView.visibility == View.VISIBLE) {
|
||||
binding.content.connectionIssueView.visibility = View.GONE
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,10 +36,10 @@ abstract class BaseMainFragment<VB : ViewBinding> : BaseFragment<VB>() {
|
|||
protected var showsBackButton: Boolean = false
|
||||
|
||||
open val activity get() = getActivity() as? MainActivity
|
||||
val tabLayout get() = activity?.binding?.detailTabs
|
||||
val collapsingToolbar get() = activity?.binding?.toolbar
|
||||
val toolbarAccessoryContainer get() = activity?.binding?.toolbarAccessoryContainer
|
||||
val bottomNavigation get() = activity?.binding?.bottomNavigation
|
||||
val tabLayout get() = activity?.binding?.content?.detailTabs
|
||||
val collapsingToolbar get() = activity?.binding?.content?.toolbar
|
||||
val toolbarAccessoryContainer get() = activity?.binding?.content?.toolbarAccessoryContainer
|
||||
val bottomNavigation get() = activity?.binding?.content?.bottomNavigation
|
||||
var usesTabLayout: Boolean = false
|
||||
var hidesToolbar: Boolean = false
|
||||
var usesBottomNavigation = false
|
||||
|
|
@ -94,11 +94,11 @@ abstract class BaseMainFragment<VB : ViewBinding> : BaseFragment<VB>() {
|
|||
var isTitleInteractive = false
|
||||
|
||||
open fun updateToolbarInteractivity() {
|
||||
activity?.binding?.toolbarTitle?.background?.alpha = if (isTitleInteractive) 255 else 0
|
||||
activity?.binding?.content?.toolbarTitle?.background?.alpha = if (isTitleInteractive) 255 else 0
|
||||
if (isTitleInteractive) {
|
||||
activity?.binding?.toolbarTitle?.setScaledPadding(context, 16, 4, 16, 4)
|
||||
activity?.binding?.content?.toolbarTitle?.setScaledPadding(context, 16, 4, 16, 4)
|
||||
} else {
|
||||
activity?.binding?.toolbarTitle?.setPadding(0)
|
||||
activity?.binding?.content?.toolbarTitle?.setPadding(0)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -118,11 +118,11 @@ abstract class BaseMainFragment<VB : ViewBinding> : BaseFragment<VB>() {
|
|||
}
|
||||
|
||||
private fun hideToolbar() {
|
||||
activity?.binding?.avatarWithBars?.root?.visibility = View.GONE
|
||||
activity?.binding?.content?.avatarWithBars?.root?.visibility = View.GONE
|
||||
}
|
||||
|
||||
private fun showToolbar() {
|
||||
activity?.binding?.avatarWithBars?.root?.visibility = View.VISIBLE
|
||||
activity?.binding?.content?.avatarWithBars?.root?.visibility = View.VISIBLE
|
||||
}
|
||||
|
||||
private fun disableToolbarScrolling() {
|
||||
|
|
|
|||
|
|
@ -14,6 +14,8 @@ import androidx.core.content.ContextCompat
|
|||
import androidx.core.content.edit
|
||||
import androidx.core.os.bundleOf
|
||||
import androidx.core.view.GravityCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.drawerlayout.widget.DrawerLayout
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.SimpleItemAnimator
|
||||
|
|
@ -27,8 +29,6 @@ import com.habitrpg.android.habitica.databinding.DrawerMainBinding
|
|||
import com.habitrpg.android.habitica.extensions.getMinuteOrSeconds
|
||||
import com.habitrpg.android.habitica.extensions.getRemainingString
|
||||
import com.habitrpg.android.habitica.extensions.getShortRemainingString
|
||||
import com.habitrpg.common.habitica.extensions.getThemeColor
|
||||
import com.habitrpg.common.habitica.extensions.isUsingNightModeResources
|
||||
import com.habitrpg.android.habitica.extensions.subscribeWithErrorHandler
|
||||
import com.habitrpg.android.habitica.helpers.AppConfigManager
|
||||
import com.habitrpg.android.habitica.helpers.MainNavigationController
|
||||
|
|
@ -46,6 +46,7 @@ import com.habitrpg.android.habitica.ui.menu.HabiticaDrawerItem
|
|||
import com.habitrpg.android.habitica.ui.viewmodels.MainUserViewModel
|
||||
import com.habitrpg.android.habitica.ui.viewmodels.NotificationsViewModel
|
||||
import com.habitrpg.android.habitica.ui.views.HabiticaSnackbar
|
||||
import com.habitrpg.common.habitica.extensions.getThemeColor
|
||||
import io.reactivex.rxjava3.core.Flowable
|
||||
import io.reactivex.rxjava3.disposables.CompositeDisposable
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
|
|
@ -83,7 +84,7 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
|
||||
private var activePromo: HabiticaPromotion? = null
|
||||
|
||||
private var drawerLayout: androidx.drawerlayout.widget.DrawerLayout? = null
|
||||
private var drawerLayout: DrawerLayout? = null
|
||||
private var fragmentContainerView: View? = null
|
||||
|
||||
private var mCurrentSelectedPosition = 0
|
||||
|
|
@ -96,6 +97,8 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
val isDrawerOpen: Boolean
|
||||
get() = drawerLayout?.isDrawerOpen(GravityCompat.START) ?: false
|
||||
|
||||
private var isTabletUI: Boolean = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val context = context
|
||||
adapter = if (context != null) {
|
||||
|
|
@ -111,6 +114,7 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
mCurrentSelectedPosition = savedInstanceState.getInt(STATE_SELECTED_POSITION)
|
||||
mFromSavedInstanceState = true
|
||||
}
|
||||
isTabletUI = resources.getBoolean(R.bool.isTabletUI)
|
||||
setHasOptionsMenu(true)
|
||||
}
|
||||
|
||||
|
|
@ -265,7 +269,9 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
if (!user.hasClass && !hasSpecialItems) {
|
||||
item.isVisible = false
|
||||
} else {
|
||||
if (user.stats?.lvl ?: 0 < HabiticaSnackbar.MIN_LEVEL_FOR_SKILLS && (!hasSpecialItems)) {
|
||||
if ((user.stats?.lvl
|
||||
?: 0) < HabiticaSnackbar.MIN_LEVEL_FOR_SKILLS && (!hasSpecialItems)
|
||||
) {
|
||||
item.pillText = getString(R.string.unlock_lvl_11)
|
||||
} else {
|
||||
item.pillText = null
|
||||
|
|
@ -277,7 +283,7 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
val statsItem = getItemWithIdentifier(SIDEBAR_STATS)
|
||||
if (statsItem != null) {
|
||||
if (user.preferences?.disableClasses != true) {
|
||||
if (user.stats?.lvl ?: 0 >= 10 && user.stats?.points ?: 0 > 0) {
|
||||
if ((user.stats?.lvl ?: 0) >= 10 && (user.stats?.points ?: 0) > 0) {
|
||||
statsItem.pillText = user.stats?.points.toString()
|
||||
} else {
|
||||
statsItem.pillText = null
|
||||
|
|
@ -399,7 +405,9 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
openSelection: Boolean = true,
|
||||
preventReselection: Boolean = true
|
||||
) {
|
||||
closeDrawer()
|
||||
if (!isTabletUI) {
|
||||
closeDrawer()
|
||||
}
|
||||
if (adapter.selectedItem != null && adapter.selectedItem == transitionId && bundle == null && preventReselection) return
|
||||
adapter.selectedItem = transitionId
|
||||
|
||||
|
|
@ -417,7 +425,9 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
}
|
||||
|
||||
private fun startNotificationsActivity() {
|
||||
closeDrawer()
|
||||
if (!isTabletUI) {
|
||||
closeDrawer()
|
||||
}
|
||||
|
||||
val activity = activity as? MainActivity
|
||||
if (activity != null) {
|
||||
|
|
@ -445,7 +455,7 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
*/
|
||||
fun setUp(
|
||||
fragmentId: Int,
|
||||
drawerLayout: androidx.drawerlayout.widget.DrawerLayout,
|
||||
drawerLayout: DrawerLayout,
|
||||
viewModel: NotificationsViewModel
|
||||
) {
|
||||
fragmentContainerView = activity?.findViewById(fragmentId)
|
||||
|
|
@ -475,15 +485,32 @@ class NavigationDrawerFragment : DialogFragment() {
|
|||
|
||||
fun openDrawer() {
|
||||
val containerView = fragmentContainerView
|
||||
if (containerView != null) {
|
||||
if (containerView != null && containerView.parent is DrawerLayout) {
|
||||
drawerLayout?.openDrawer(containerView)
|
||||
} else {
|
||||
containerView?.isVisible = true
|
||||
}
|
||||
}
|
||||
|
||||
fun closeDrawer() {
|
||||
val containerView = fragmentContainerView
|
||||
if (containerView != null) {
|
||||
if (containerView != null && containerView.parent is DrawerLayout) {
|
||||
drawerLayout?.closeDrawer(containerView)
|
||||
} else {
|
||||
containerView?.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
fun toggleDrawer() {
|
||||
val containerView = fragmentContainerView
|
||||
if (containerView != null && containerView.parent is DrawerLayout) {
|
||||
if (drawerLayout?.isDrawerOpen(containerView) == true) {
|
||||
drawerLayout?.closeDrawer(containerView)
|
||||
} else {
|
||||
drawerLayout?.openDrawer(containerView)
|
||||
}
|
||||
} else {
|
||||
containerView?.isVisible = containerView?.isVisible != true
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -119,7 +119,7 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
bottomNavigation?.listener = this
|
||||
bottomNavigation?.canAddTasks = viewModel.isPersonalBoard
|
||||
|
||||
activity?.binding?.toolbarTitle?.setOnClickListener {
|
||||
activity?.binding?.content?.toolbarTitle?.setOnClickListener {
|
||||
viewModel.cycleOwnerIDs()
|
||||
}
|
||||
}
|
||||
|
|
@ -199,7 +199,7 @@ class TasksFragment : BaseMainFragment<FragmentViewpagerBinding>(), SearchView.O
|
|||
dialog.viewModel = viewModel
|
||||
|
||||
// There are some cases where these things might not be correctly set after the app resumes. This is just to catch that as best as possible
|
||||
val navigation = bottomNavigation ?: activity?.binding?.bottomNavigation
|
||||
val navigation = bottomNavigation ?: activity?.binding?.content?.bottomNavigation
|
||||
val taskType = navigation?.activeTaskType ?: activeFragment?.taskType
|
||||
|
||||
dialog.setOnDismissListener { updateFilterIcon() }
|
||||
|
|
|
|||
Loading…
Reference in a new issue