@@ -258,7 +258,7 @@ class MainActivity : SimpleActivity() {
258258
259259 updateUnreadCountBadge(conversations)
260260 runOnUiThread {
261- setupConversations(conversations)
261+ setupConversations(conversations, cached = true )
262262 getNewConversations(conversations)
263263 }
264264 conversations.forEach {
@@ -349,40 +349,50 @@ class MainActivity : SimpleActivity() {
349349 return currAdapter as ConversationsAdapter
350350 }
351351
352- private fun setupConversations (conversations : ArrayList <Conversation >) {
353- val hasConversations = conversations.isNotEmpty()
352+ private fun setupConversations (conversations : ArrayList <Conversation >, cached : Boolean = false) {
354353 val sortedConversations = conversations.sortedWith(
355354 compareByDescending<Conversation > { config.pinnedConversations.contains(it.threadId.toString()) }
356355 .thenByDescending { it.date }
357356 ).toMutableList() as ArrayList <Conversation >
358357
359- conversations_fastscroller.beVisibleIf(hasConversations)
360- no_conversations_placeholder.beGoneIf(hasConversations)
361- no_conversations_placeholder_2.beGoneIf(hasConversations)
362-
363- if (! hasConversations && config.appRunCount == 1 ) {
364- no_conversations_placeholder.text = getString(R .string.loading_messages)
365- no_conversations_placeholder_2.beGone()
366- conversations_progress_bar.beVisible()
358+ if (cached && config.appRunCount == 1 ) {
359+ // there are no cached conversations on the first run so we show the loading placeholder and progress until we are done loading from telephony
360+ showOrHideProgress(conversations.isEmpty())
367361 } else {
368- conversations_progress_bar.beGone()
362+ showOrHideProgress(false )
363+ showOrHidePlaceholder(conversations.isEmpty())
369364 }
370365
371366 try {
372367 getOrCreateConversationsAdapter().apply {
373368 updateConversations(sortedConversations) {
374- if (currentList.isEmpty()) {
375- conversations_fastscroller.beGone()
376- no_conversations_placeholder.text = getString(R .string.no_conversations_found)
377- no_conversations_placeholder.beVisible()
378- no_conversations_placeholder_2.beVisible()
369+ if (! cached) {
370+ showOrHidePlaceholder(currentList.isEmpty())
379371 }
380372 }
381373 }
382374 } catch (ignored: Exception ) {
383375 }
384376 }
385377
378+ private fun showOrHideProgress (show : Boolean ) {
379+ if (show) {
380+ conversations_progress_bar.show()
381+ no_conversations_placeholder.beVisible()
382+ no_conversations_placeholder.text = getString(R .string.loading_messages)
383+ } else {
384+ conversations_progress_bar.hide()
385+ no_conversations_placeholder.beGone()
386+ }
387+ }
388+
389+ private fun showOrHidePlaceholder (show : Boolean ) {
390+ conversations_fastscroller.beGoneIf(show)
391+ no_conversations_placeholder.beVisibleIf(show)
392+ no_conversations_placeholder.text = getString(R .string.no_conversations_found)
393+ no_conversations_placeholder_2.beVisibleIf(show)
394+ }
395+
386396 private fun fadeOutSearch () {
387397 search_holder.animate().alpha(0f ).setDuration(SHORT_ANIMATION_DURATION ).withEndAction {
388398 search_holder.beGone()
0 commit comments