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) {
|
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
|
||||||
|
@ -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);
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
@ -19,4 +20,10 @@ abstract class AppModule {
|
|||||||
@Binds
|
@Binds
|
||||||
abstract fun bindConversationRepository(repository: DefaultConversationRepository): ConversationRepository
|
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.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,16 +94,21 @@ 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
|
||||||
setBackgroundResource(R.drawable.accent_dot)
|
updateJob = ViewUtil.getActivityLifecycle(this)?.coroutineScope?.launchWhenStarted {
|
||||||
val hasPathsColor = context.getColor(R.color.accent_green)
|
val paths = withContext(Dispatchers.IO) { OnionRequestAPI.paths }
|
||||||
mainColor = hasPathsColor
|
if (paths.isNotEmpty()) {
|
||||||
sessionShadowColor = hasPathsColor
|
setBackgroundResource(R.drawable.accent_dot)
|
||||||
} else {
|
val hasPathsColor = context.getColor(R.color.accent_green)
|
||||||
setBackgroundResource(R.drawable.paths_building_dot)
|
mainColor = hasPathsColor
|
||||||
val pathsBuildingColor = resources.getColorWithID(R.color.paths_building, context.theme)
|
sessionShadowColor = hasPathsColor
|
||||||
mainColor = pathsBuildingColor
|
} else {
|
||||||
sessionShadowColor = pathsBuildingColor
|
setBackgroundResource(R.drawable.paths_building_dot)
|
||||||
|
val pathsBuildingColor = resources.getColorWithID(R.color.paths_building, context.theme)
|
||||||
|
mainColor = pathsBuildingColor
|
||||||
|
sessionShadowColor = pathsBuildingColor
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user