mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-28 20:45:17 +00:00
fix: tests and main thread blocking db fetch for path status view
This commit is contained in:
parent
1676e97bc6
commit
eb173d72e0
@ -57,7 +57,7 @@ class LibSessionTests {
|
||||
|
||||
private fun fakePollNewConfig(configBase: ConfigBase, toMerge: ByteArray) {
|
||||
configBase.merge(nextFakeHash to toMerge)
|
||||
MessagingModuleConfiguration.shared.configFactory.persist(configBase)
|
||||
MessagingModuleConfiguration.shared.configFactory.persist(configBase, System.currentTimeMillis())
|
||||
}
|
||||
|
||||
@Before
|
||||
|
@ -60,6 +60,7 @@ import org.thoughtcrime.securesms.database.LokiAPIDatabase;
|
||||
import org.thoughtcrime.securesms.database.Storage;
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper;
|
||||
import org.thoughtcrime.securesms.database.model.EmojiSearchData;
|
||||
import org.thoughtcrime.securesms.dependencies.AppComponent;
|
||||
import org.thoughtcrime.securesms.dependencies.ConfigFactory;
|
||||
import org.thoughtcrime.securesms.dependencies.DatabaseComponent;
|
||||
import org.thoughtcrime.securesms.dependencies.DatabaseModule;
|
||||
@ -162,6 +163,10 @@ public class ApplicationContext extends Application implements DefaultLifecycleO
|
||||
return (ApplicationContext) context.getApplicationContext();
|
||||
}
|
||||
|
||||
public TextSecurePreferences getPrefs() {
|
||||
return EntryPoints.get(getApplicationContext(), AppComponent.class).getPrefs();
|
||||
}
|
||||
|
||||
public DatabaseComponent getDatabaseComponent() {
|
||||
return EntryPoints.get(getApplicationContext(), DatabaseComponent.class);
|
||||
}
|
||||
|
@ -2,6 +2,7 @@ package org.thoughtcrime.securesms.dependencies
|
||||
|
||||
import dagger.Binds
|
||||
import dagger.Module
|
||||
import dagger.hilt.EntryPoint
|
||||
import dagger.hilt.InstallIn
|
||||
import dagger.hilt.components.SingletonComponent
|
||||
import org.session.libsession.utilities.AppTextSecurePreferences
|
||||
@ -20,3 +21,9 @@ abstract class AppModule {
|
||||
abstract fun bindConversationRepository(repository: DefaultConversationRepository): ConversationRepository
|
||||
|
||||
}
|
||||
|
||||
@EntryPoint
|
||||
@InstallIn(SingletonComponent::class)
|
||||
interface AppComponent {
|
||||
fun getPrefs(): TextSecurePreferences
|
||||
}
|
@ -9,9 +9,14 @@ import android.graphics.Paint
|
||||
import android.util.AttributeSet
|
||||
import android.view.View
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.lifecycle.coroutineScope
|
||||
import androidx.localbroadcastmanager.content.LocalBroadcastManager
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.withContext
|
||||
import network.loki.messenger.R
|
||||
import org.session.libsession.snode.OnionRequestAPI
|
||||
import org.thoughtcrime.securesms.conversation.v2.ViewUtil
|
||||
import org.thoughtcrime.securesms.util.getColorWithID
|
||||
import org.thoughtcrime.securesms.util.toPx
|
||||
|
||||
@ -29,6 +34,8 @@ class PathStatusView : View {
|
||||
result
|
||||
}
|
||||
|
||||
private var updateJob: Job? = null
|
||||
|
||||
constructor(context: Context) : super(context) {
|
||||
initialize()
|
||||
}
|
||||
@ -87,7 +94,10 @@ class PathStatusView : View {
|
||||
private fun handlePathsBuiltEvent() { 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)
|
||||
val hasPathsColor = context.getColor(R.color.accent_green)
|
||||
mainColor = hasPathsColor
|
||||
@ -99,6 +109,8 @@ class PathStatusView : View {
|
||||
sessionShadowColor = pathsBuildingColor
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDraw(c: Canvas) {
|
||||
val w = width.toFloat()
|
||||
|
Loading…
Reference in New Issue
Block a user