fix: tests and main thread blocking db fetch for path status view

This commit is contained in:
0x330a 2023-06-26 17:38:47 +10:00
parent 1676e97bc6
commit eb173d72e0
No known key found for this signature in database
GPG Key ID: 267811D6E6A2698C
4 changed files with 35 additions and 11 deletions

View File

@ -57,7 +57,7 @@ class LibSessionTests {
private fun fakePollNewConfig(configBase: ConfigBase, toMerge: ByteArray) { private fun fakePollNewConfig(configBase: ConfigBase, toMerge: ByteArray) {
configBase.merge(nextFakeHash to toMerge) configBase.merge(nextFakeHash to toMerge)
MessagingModuleConfiguration.shared.configFactory.persist(configBase) MessagingModuleConfiguration.shared.configFactory.persist(configBase, System.currentTimeMillis())
} }
@Before @Before

View File

@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.database.LokiAPIDatabase;
import org.thoughtcrime.securesms.database.Storage; import org.thoughtcrime.securesms.database.Storage;
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper; import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
import org.thoughtcrime.securesms.database.model.EmojiSearchData; import org.thoughtcrime.securesms.database.model.EmojiSearchData;
import org.thoughtcrime.securesms.dependencies.AppComponent;
import org.thoughtcrime.securesms.dependencies.ConfigFactory; import org.thoughtcrime.securesms.dependencies.ConfigFactory;
import org.thoughtcrime.securesms.dependencies.DatabaseComponent; import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
import org.thoughtcrime.securesms.dependencies.DatabaseModule; import org.thoughtcrime.securesms.dependencies.DatabaseModule;
@ -162,6 +163,10 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
return (ApplicationContext) context.getApplicationContext(); return (ApplicationContext) context.getApplicationContext();
} }
public TextSecurePreferences getPrefs() {
return EntryPoints.get(getApplicationContext(), AppComponent.class).getPrefs();
}
public DatabaseComponent getDatabaseComponent() { public DatabaseComponent getDatabaseComponent() {
return EntryPoints.get(getApplicationContext(), DatabaseComponent.class); return EntryPoints.get(getApplicationContext(), DatabaseComponent.class);
} }

View File

@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.dependencies
import dagger.Binds import dagger.Binds
import dagger.Module import dagger.Module
import dagger.hilt.EntryPoint
import dagger.hilt.InstallIn import dagger.hilt.InstallIn
import dagger.hilt.components.SingletonComponent import dagger.hilt.components.SingletonComponent
import org.session.libsession.utilities.AppTextSecurePreferences import org.session.libsession.utilities.AppTextSecurePreferences
@ -20,3 +21,9 @@ abstract class AppModule {
abstract fun bindConversationRepository(repository: DefaultConversationRepository): ConversationRepository abstract fun bindConversationRepository(repository: DefaultConversationRepository): ConversationRepository
} }
@EntryPoint
@InstallIn(SingletonComponent::class)
interface AppComponent {
fun getPrefs(): TextSecurePreferences
}

View File

@ -9,9 +9,14 @@ import android.graphics.Paint
import android.util.AttributeSet import android.util.AttributeSet
import android.view.View import android.view.View
import androidx.annotation.ColorInt import androidx.annotation.ColorInt
import androidx.lifecycle.coroutineScope
import androidx.localbroadcastmanager.content.LocalBroadcastManager import androidx.localbroadcastmanager.content.LocalBroadcastManager
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.withContext
import network.loki.messenger.R import network.loki.messenger.R
import org.session.libsession.snode.OnionRequestAPI import org.session.libsession.snode.OnionRequestAPI
import org.thoughtcrime.securesms.conversation.v2.ViewUtil
import org.thoughtcrime.securesms.util.getColorWithID import org.thoughtcrime.securesms.util.getColorWithID
import org.thoughtcrime.securesms.util.toPx import org.thoughtcrime.securesms.util.toPx
@ -29,6 +34,8 @@ class PathStatusView : View {
result result
} }
private var updateJob: Job? = null
constructor(context: Context) : super(context) { constructor(context: Context) : super(context) {
initialize() initialize()
} }
@ -87,7 +94,10 @@ class PathStatusView : View {
private fun handlePathsBuiltEvent() { update() } private fun handlePathsBuiltEvent() { update() }
private fun update() { private fun update() {
if (OnionRequestAPI.paths.isNotEmpty()) { if (updateJob?.isActive != true) { // false or null
updateJob = ViewUtil.getActivityLifecycle(this)?.coroutineScope?.launchWhenStarted {
val paths = withContext(Dispatchers.IO) { OnionRequestAPI.paths }
if (paths.isNotEmpty()) {
setBackgroundResource(R.drawable.accent_dot) setBackgroundResource(R.drawable.accent_dot)
val hasPathsColor = context.getColor(R.color.accent_green) val hasPathsColor = context.getColor(R.color.accent_green)
mainColor = hasPathsColor mainColor = hasPathsColor
@ -99,6 +109,8 @@ class PathStatusView : View {
sessionShadowColor = pathsBuildingColor sessionShadowColor = pathsBuildingColor
} }
} }
}
}
override fun onDraw(c: Canvas) { override fun onDraw(c: Canvas) {
val w = width.toFloat() val w = width.toFloat()