Skip to content

Commit

Permalink
Apply suggestion from code review
Browse files Browse the repository at this point in the history
  • Loading branch information
NicolasBourdin88 committed May 13, 2024
1 parent 6ae1736 commit 135de25
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,6 @@ class MessageController @Inject constructor(private val mailboxContentRealm: Rea
fun getNewestMessages(folderId: String, limit: Int, realm: MutableRealm): List<Message> {
return getOldestOrNewestMessagesQuery(folderId, Sort.DESCENDING, realm, limit).find()
}

//endregion

//region Edit data
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/java/com/infomaniak/mail/ui/MainViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -617,11 +617,11 @@ class MainViewModel @Inject constructor(

//region Archive
fun archiveMessage(threadUid: String, message: Message) {
archiveThreadsOrMessage(listOf(threadUid), message = message)
archiveThreadsOrMessage(threadsUids = listOf(threadUid), message = message)
}

fun archiveThread(threadUid: String) {
archiveThreadsOrMessage(listOf(threadUid))
archiveThreadsOrMessage(threadsUids = listOf(threadUid))
}

fun archiveThreads(threadsUids: List<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -293,11 +293,11 @@ class ThreadListAdapter @Inject constructor(
if (multiSelection?.isEnabled == true) {
toggleMultiSelectedThread(thread)
} else {
previousThreadClickedPosition?.let { previousThreadClickedPosition ->
if (position > previousThreadClickedPosition) {
localSettings.autoAdvanceIntelligentMode = AutoAdvanceMode.FOLLOWING_THREAD
previousThreadClickedPosition?.let {
localSettings.autoAdvanceIntelligentMode = if (position > it) {
AutoAdvanceMode.FOLLOWING_THREAD
} else {
localSettings.autoAdvanceIntelligentMode = AutoAdvanceMode.PREVIOUS_THREAD
AutoAdvanceMode.PREVIOUS_THREAD
}
}

Expand All @@ -311,6 +311,7 @@ class ThreadListAdapter @Inject constructor(
}

fun selectNewThread(newPosition: Int?, threadUid: String?) {

val oldPosition = openedThreadPosition

openedThreadPosition = newPosition
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,16 +173,13 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
override fun getRightPane(): FragmentContainerView? = _binding?.threadHostFragment

override fun getAnchor(): View? {
return if (isSelectedThreadAtLastPositionOrStart() || !isOnlyRightShown()) {
_binding?.newMessageFab
} else {
return if (isOnlyRightShown()) {
_binding?.threadHostFragment?.getFragment<ThreadFragment?>()?.getAnchor()
} else {
_binding?.newMessageFab
}
}

private fun isSelectedThreadAtLastPositionOrStart() =
threadListAdapter.openedThreadPosition == 1 || threadListAdapter.openedThreadPosition == threadListAdapter.dataSet.size

override fun doAfterFolderChanged() {
navigateFromNotificationToThread()
}
Expand Down Expand Up @@ -632,7 +629,6 @@ class ThreadListFragment : TwoPaneFragment(), SwipeRefreshLayout.OnRefreshListen
}
}


private fun checkLastUpdateDay() {
if (lastUpdatedDate?.isToday() == false) mainViewModel.forceTriggerCurrentFolder()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ class SettingRadioButtonView @JvmOverloads constructor(
associatedValue = getString(R.styleable.SettingRadioButtonView_value)

setIcon(iconDrawable)

text.text = textString
checkMark.setColorFilter(checkMarkColor)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,6 @@ class ThreadFragment : Fragment() {

private fun observeClosedThread() {
mainViewModel.autoAdvanceTrigger.observe(viewLifecycleOwner) { listThreadsUids ->
println("called")
tryToAutoAdvance(localSettings.autoAdvanceMode, listThreadsUids)
}
}
Expand Down Expand Up @@ -631,22 +630,6 @@ class ThreadFragment : Fragment() {
twoPaneViewModel.navArgs.value = NavData(resId, args)
}

private fun getNextThreadToOpenByPosition(startingThreadIndex: Int, autoAdvanceMode: AutoAdvanceMode): Pair<Thread, Int>? =
with(twoPaneFragment.threadListAdapter) {
return when (autoAdvanceMode) {
AutoAdvanceMode.PREVIOUS_THREAD -> getNextThread(startingThreadIndex, direction = PREVIOUS_CHRONOLOGICAL_THREAD)
AutoAdvanceMode.FOLLOWING_THREAD -> getNextThread(startingThreadIndex, direction = NEXT_CHRONOLOGICAL_THREAD)
AutoAdvanceMode.LIST_THREAD -> null
AutoAdvanceMode.NATURAL_THREAD -> {
if (localSettings.autoAdvanceIntelligentMode == AutoAdvanceMode.PREVIOUS_THREAD) {
getNextThread(startingThreadIndex, direction = PREVIOUS_CHRONOLOGICAL_THREAD)
} else {
getNextThread(startingThreadIndex, direction = NEXT_CHRONOLOGICAL_THREAD)
}
}
}
}

private fun tryToAutoAdvance(autoAdvanceMode: AutoAdvanceMode, listThreadUids: List<String>) =
with(twoPaneFragment.threadListAdapter) {
if (!listThreadUids.contains(openedThreadUid)) return@with
Expand All @@ -665,6 +648,22 @@ class ThreadFragment : Fragment() {
}
}

private fun getNextThreadToOpenByPosition(startingThreadIndex: Int, autoAdvanceMode: AutoAdvanceMode): Pair<Thread, Int>? =
with(twoPaneFragment.threadListAdapter) {
return when (autoAdvanceMode) {
AutoAdvanceMode.PREVIOUS_THREAD -> getNextThread(startingThreadIndex, direction = PREVIOUS_CHRONOLOGICAL_THREAD)
AutoAdvanceMode.FOLLOWING_THREAD -> getNextThread(startingThreadIndex, direction = NEXT_CHRONOLOGICAL_THREAD)
AutoAdvanceMode.LIST_THREAD -> null
AutoAdvanceMode.NATURAL_THREAD -> {
if (localSettings.autoAdvanceIntelligentMode == AutoAdvanceMode.PREVIOUS_THREAD) {
getNextThread(startingThreadIndex, direction = PREVIOUS_CHRONOLOGICAL_THREAD)
} else {
getNextThread(startingThreadIndex, direction = NEXT_CHRONOLOGICAL_THREAD)
}
}
}
}

enum class HeaderState {
ELEVATED,
LOWERED,
Expand Down
12 changes: 3 additions & 9 deletions app/src/main/res/layout/view_setting_radio_button.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,12 @@
android:importantForAccessibility="no"
android:visibility="gone" />

<LinearLayout
<TextView
android:id="@+id/text"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">

<TextView
android:id="@+id/text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:text="Simple messages" />
</LinearLayout>
tools:text="Simple messages" />

<ImageView
android:id="@+id/checkMark"
Expand Down

0 comments on commit 135de25

Please sign in to comment.