Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Lock MenuDrawer in ThreadFragment #1672

Merged
merged 4 commits into from
Feb 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
*/
package com.infomaniak.mail.ui.main.folder

import android.content.res.Configuration
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
Expand All @@ -30,6 +31,7 @@ import com.infomaniak.mail.MatomoMail.trackNewMessageEvent
import com.infomaniak.mail.R
import com.infomaniak.mail.data.cache.mailboxContent.FolderController
import com.infomaniak.mail.data.models.thread.Thread
import com.infomaniak.mail.ui.MainActivity
import com.infomaniak.mail.ui.MainViewModel
import com.infomaniak.mail.ui.main.NoAnimSlidingPaneLayout
import com.infomaniak.mail.ui.main.search.SearchFragment
Expand Down Expand Up @@ -77,6 +79,11 @@ abstract class TwoPaneFragment : Fragment() {
observeThreadNavigation()
}

override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
updateDrawerLockMode()
}

private fun setupSlidingPane() = with(slidingPaneLayout) {
lockMode = SlidingPaneLayout.LOCK_MODE_LOCKED
addPanelSlideListener(object : SlidingPaneLayout.PanelSlideListener {
Expand Down Expand Up @@ -121,7 +128,10 @@ abstract class TwoPaneFragment : Fragment() {
val isOpeningThread = threadUid != null
if (isOpeningThread) {
val hasOpened = slidingPaneLayout.openPaneNoAnimation()
if (hasOpened) setSystemBarsColors(statusBarColor = R.color.backgroundColor, navigationBarColor = null)
if (hasOpened) {
updateDrawerLockMode()
setSystemBarsColors(statusBarColor = R.color.backgroundColor, navigationBarColor = null)
}
} else {
resetPanes()
}
Expand Down Expand Up @@ -160,6 +170,7 @@ abstract class TwoPaneFragment : Fragment() {
private fun resetPanes() {

val hasClosed = slidingPaneLayout.closePaneNoAnimation()
updateDrawerLockMode()

if (hasClosed) {
setSystemBarsColors(
Expand All @@ -172,4 +183,13 @@ abstract class TwoPaneFragment : Fragment() {

childFragmentManager.beginTransaction().replace(R.id.threadHostFragment, ThreadFragment()).commit()
}

// TODO: When we'll add the feature of swiping between Threads, we'll need to check if this function is still needed.
private fun updateDrawerLockMode() {
if (this is ThreadListFragment) {
(requireActivity() as MainActivity).setDrawerLockMode(
isLocked = twoPaneViewModel.isInThreadInPhoneMode(requireContext()),
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ import com.infomaniak.mail.data.models.message.Message
import com.infomaniak.mail.data.models.thread.Thread
import com.infomaniak.mail.ui.newMessage.NewMessageActivityArgs
import com.infomaniak.mail.utils.Utils.runCatchingRealm
import com.infomaniak.mail.utils.canDisplayBothPanes
import com.infomaniak.mail.utils.canDisplayOnlyOnePane
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject

Expand Down Expand Up @@ -94,7 +94,7 @@ class TwoPaneViewModel @Inject constructor(
)
}

fun isInThreadInPhoneMode(context: Context): Boolean = isThreadOpen && !context.canDisplayBothPanes()
fun isInThreadInPhoneMode(context: Context): Boolean = isThreadOpen && context.canDisplayOnlyOnePane()

data class NavData(
@IdRes val resId: Int,
Expand Down
4 changes: 3 additions & 1 deletion app/src/main/java/com/infomaniak/mail/utils/Extensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -159,8 +159,10 @@ fun Date.isLastWeek(): Boolean {
//region UI
fun Context.isInPortrait(): Boolean = resources.configuration.orientation == Configuration.ORIENTATION_PORTRAIT

fun Fragment.canDisplayBothPanes(): Boolean = requireContext().canDisplayBothPanes()
fun Context.canDisplayBothPanes(): Boolean = resources.getBoolean(R.bool.canDisplayBothPanes)
fun Fragment.canDisplayBothPanes(): Boolean = requireContext().canDisplayBothPanes()
fun Context.canDisplayOnlyOnePane(): Boolean = !canDisplayBothPanes()
fun Fragment.canDisplayOnlyOnePane(): Boolean = requireContext().canDisplayOnlyOnePane()

fun View.toggleChevron(
isCollapsed: Boolean,
Expand Down
Loading