From f8bcc74155b8d239e9f7d503e9208456c4a9a88a Mon Sep 17 00:00:00 2001 From: Naveen Date: Tue, 17 Jan 2023 00:18:32 +0530 Subject: [PATCH] Hide progress bar after loading from telephony --- .../smsmessenger/activities/MainActivity.kt | 50 +++++++++++-------- app/src/main/res/layout/activity_main.xml | 6 +-- 2 files changed, 33 insertions(+), 23 deletions(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt index 1c5647fb..1a41e316 100644 --- a/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/smsmessenger/activities/MainActivity.kt @@ -111,8 +111,8 @@ class MainActivity : SimpleActivity() { search_holder.setBackgroundColor(getProperBackgroundColor()) val properPrimaryColor = getProperPrimaryColor() - no_conversations_placeholder_2.setTextColor(properPrimaryColor) - no_conversations_placeholder_2.underlineText() + start_conversation_placeholder.setTextColor(properPrimaryColor) + start_conversation_placeholder.underlineText() conversations_fastscroller.updateColors(properPrimaryColor) conversations_progress_bar.setIndicatorColor(properPrimaryColor) conversations_progress_bar.trackColor = properPrimaryColor.adjustAlpha(LOWER_ALPHA) @@ -239,7 +239,7 @@ class MainActivity : SimpleActivity() { storeStateVariables() getCachedConversations() - no_conversations_placeholder_2.setOnClickListener { + start_conversation_placeholder.setOnClickListener { launchNewConversation() } @@ -258,7 +258,7 @@ class MainActivity : SimpleActivity() { updateUnreadCountBadge(conversations) runOnUiThread { - setupConversations(conversations) + setupConversations(conversations, cached = true) getNewConversations(conversations) } conversations.forEach { @@ -349,33 +349,25 @@ class MainActivity : SimpleActivity() { return currAdapter as ConversationsAdapter } - private fun setupConversations(conversations: ArrayList) { - val hasConversations = conversations.isNotEmpty() + private fun setupConversations(conversations: ArrayList, cached: Boolean = false) { val sortedConversations = conversations.sortedWith( compareByDescending { config.pinnedConversations.contains(it.threadId.toString()) } .thenByDescending { it.date } ).toMutableList() as ArrayList - conversations_fastscroller.beVisibleIf(hasConversations) - no_conversations_placeholder.beGoneIf(hasConversations) - no_conversations_placeholder_2.beGoneIf(hasConversations) - - if (!hasConversations && config.appRunCount == 1) { - no_conversations_placeholder.text = getString(R.string.loading_messages) - no_conversations_placeholder_2.beGone() - conversations_progress_bar.beVisible() + if (cached && config.appRunCount == 1) { + // there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony + showOrHideProgress(show = conversations.isEmpty()) } else { - conversations_progress_bar.beGone() + showOrHideProgress(show = false) + showOrHidePlaceholder(show = conversations.isEmpty()) } try { getOrCreateConversationsAdapter().apply { updateConversations(sortedConversations) { - if (currentList.isEmpty()) { - conversations_fastscroller.beGone() - no_conversations_placeholder.text = getString(R.string.no_conversations_found) - no_conversations_placeholder.beVisible() - no_conversations_placeholder_2.beVisible() + if (!cached) { + showOrHidePlaceholder(show = currentList.isEmpty()) } } } @@ -383,6 +375,24 @@ class MainActivity : SimpleActivity() { } } + private fun showOrHideProgress(show: Boolean) { + if (show) { + conversations_progress_bar.show() + conversations_placeholder.beVisible() + conversations_placeholder.text = getString(R.string.loading_messages) + } else { + conversations_progress_bar.hide() + conversations_placeholder.beGone() + } + } + + private fun showOrHidePlaceholder(show: Boolean) { + conversations_fastscroller.beGoneIf(show) + conversations_placeholder.beVisibleIf(show) + conversations_placeholder.text = getString(R.string.no_conversations_found) + start_conversation_placeholder.beVisibleIf(show) + } + private fun fadeOutSearch() { search_holder.animate().alpha(0f).setDuration(SHORT_ANIMATION_DURATION).withEndAction { search_holder.beGone() diff --git a/app/src/main/res/layout/activity_main.xml b/app/src/main/res/layout/activity_main.xml index 221108ee..5444a08e 100644 --- a/app/src/main/res/layout/activity_main.xml +++ b/app/src/main/res/layout/activity_main.xml @@ -42,7 +42,7 @@ tools:visibility="visible" />