From 4bfb51e6e2012cfab70b4e4a134b8f8ab764d9df Mon Sep 17 00:00:00 2001 From: Niels Andriesse Date: Thu, 19 Dec 2019 11:49:23 +0100 Subject: [PATCH] Fix updating --- .../activities/CreatePrivateChatActivity.kt | 2 +- .../loki/redesign/activities/HomeActivity.kt | 29 ++++++++++++++----- .../loki/redesign/activities/HomeLoader.kt | 13 +++++++++ 3 files changed, 36 insertions(+), 8 deletions(-) create mode 100644 src/org/thoughtcrime/securesms/loki/redesign/activities/HomeLoader.kt diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt index ff7251cc75..56b185c99b 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/CreatePrivateChatActivity.kt @@ -87,7 +87,7 @@ private class CreatePrivateChatActivityAdapter(val activity: CreatePrivateChatAc override fun getPageTitle(index: Int): CharSequence? { return when (index) { - 0 -> "Enter Public Key" + 0 -> "Enter Session ID" 1 -> "Scan QR Code" else -> throw IllegalStateException() } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt index ab740cfc2f..8f5165a3ae 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeActivity.kt @@ -2,7 +2,10 @@ package org.thoughtcrime.securesms.loki.redesign.activities import android.arch.lifecycle.Observer import android.content.Intent +import android.database.Cursor import android.os.Bundle +import android.support.v4.app.LoaderManager +import android.support.v4.content.Loader import android.support.v7.widget.LinearLayoutManager import android.view.Menu import android.view.MenuItem @@ -40,15 +43,27 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe homeAdapter.conversationClickListener = this recyclerView.adapter = homeAdapter recyclerView.layoutManager = LinearLayoutManager(this) + // This is a workaround for the fact that CursorRecyclerViewAdapter doesn't actually auto-update (even though it says it will) + LoaderManager.getInstance(this).restartLoader(0, null, object : LoaderManager.LoaderCallbacks { + + override fun onCreateLoader(id: Int, bundle: Bundle?): Loader { + return HomeLoader(this@HomeActivity) + } + + override fun onLoadFinished(loader: Loader, cursor: Cursor?) { + homeAdapter.changeCursor(cursor) + } + + override fun onLoaderReset(cursor: Loader) { + homeAdapter.changeCursor(null) + } + }) // Set up new conversation button newConversationButton.setOnClickListener { createPrivateChat() } // Set up typing observer - ApplicationContext.getInstance(this).typingStatusRepository.typingThreads.observe(this, object : Observer> { - - override fun onChanged(threadIDs: Set?) { - val adapter = recyclerView.adapter as HomeAdapter - adapter.typingThreadIDs = threadIDs ?: setOf() - } + ApplicationContext.getInstance(this).typingStatusRepository.typingThreads.observe(this, Observer> { threadIDs -> + val adapter = recyclerView.adapter as HomeAdapter + adapter.typingThreadIDs = threadIDs ?: setOf() }) // Set up public chats and RSS feeds if needed if (TextSecurePreferences.getLocalNumber(this) != null) { @@ -68,7 +83,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe // region Interaction override fun onOptionsItemSelected(item: MenuItem): Boolean { - val id = item.getItemId() + val id = item.itemId when (id) { R.id.joinPublicChatItem -> joinPublicChat() else -> { /* Do nothing */ } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeLoader.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeLoader.kt new file mode 100644 index 0000000000..07f5391392 --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/HomeLoader.kt @@ -0,0 +1,13 @@ +package org.thoughtcrime.securesms.loki.redesign.activities + +import android.content.Context +import android.database.Cursor +import org.thoughtcrime.securesms.database.DatabaseFactory +import org.thoughtcrime.securesms.util.AbstractCursorLoader + +class HomeLoader(context: Context) : AbstractCursorLoader(context) { + + override fun getCursor(): Cursor { + return DatabaseFactory.getThreadDatabase(context).conversationList + } +} \ No newline at end of file