Fix updating

This commit is contained in:
Niels Andriesse 2019-12-19 11:49:23 +01:00
parent ded709a58b
commit 4bfb51e6e2
3 changed files with 36 additions and 8 deletions

View File

@ -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()
}

View File

@ -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<Cursor> {
override fun onCreateLoader(id: Int, bundle: Bundle?): Loader<Cursor> {
return HomeLoader(this@HomeActivity)
}
override fun onLoadFinished(loader: Loader<Cursor>, cursor: Cursor?) {
homeAdapter.changeCursor(cursor)
}
override fun onLoaderReset(cursor: Loader<Cursor>) {
homeAdapter.changeCursor(null)
}
})
// Set up new conversation button
newConversationButton.setOnClickListener { createPrivateChat() }
// Set up typing observer
ApplicationContext.getInstance(this).typingStatusRepository.typingThreads.observe(this, object : Observer<Set<Long>> {
override fun onChanged(threadIDs: Set<Long>?) {
val adapter = recyclerView.adapter as HomeAdapter
adapter.typingThreadIDs = threadIDs ?: setOf()
}
ApplicationContext.getInstance(this).typingStatusRepository.typingThreads.observe(this, Observer<Set<Long>> { 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 */ }

View File

@ -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
}
}