Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import org.thoughtcrime.securesms.api.snode.GetInfoApi
import org.thoughtcrime.securesms.api.snode.SnodeApiExecutor
import org.thoughtcrime.securesms.api.snode.SnodeApiRequest
import org.thoughtcrime.securesms.api.snode.execute
import org.thoughtcrime.securesms.util.NetworkConnectivity
import java.util.concurrent.atomic.AtomicBoolean
import javax.inject.Inject
import javax.inject.Provider
Expand All @@ -48,6 +49,7 @@ open class PathManager @Inject constructor(
private val prefs: TextSecurePreferences,
private val snodeApiExecutor: Provider<SnodeApiExecutor>,
private val getInfoApi: Provider<GetInfoApi>,
private val networkConnectivity: NetworkConnectivity,
) {
companion object {
private const val STRIKE_THRESHOLD = 3
Expand Down Expand Up @@ -75,10 +77,10 @@ open class PathManager @Inject constructor(

@OptIn(FlowPreview::class)
val status: StateFlow<PathStatus> =
combine(_paths, _isBuilding) { paths, building ->
combine(_paths, _isBuilding, networkConnectivity.networkAvailable) { paths, building, hasNetwork ->
when {
building -> PathStatus.BUILDING
paths.isEmpty() -> PathStatus.ERROR
hasNetwork && building -> PathStatus.BUILDING
!hasNetwork || paths.isEmpty() -> PathStatus.ERROR
else -> PathStatus.READY
}
}
Expand Down
22 changes: 11 additions & 11 deletions app/src/main/java/org/thoughtcrime/securesms/home/PathActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import android.widget.TextView
import androidx.annotation.ColorRes
import androidx.core.content.ContextCompat
import androidx.core.view.doOnLayout
import androidx.core.view.isVisible
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
Expand All @@ -21,28 +22,24 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.Job
import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.distinctUntilChanged
import kotlinx.coroutines.flow.flow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.mapNotNull
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.flow.withIndex
import kotlinx.coroutines.isActive
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import network.loki.messenger.R
import network.loki.messenger.databinding.ActivityPathBinding
import org.session.libsession.network.model.PathStatus
import org.session.libsession.network.onion.PathManager
import org.session.libsession.utilities.NonTranslatableStringConstants.APP_NAME
import org.session.libsession.utilities.StringSubstitutionConstants.APP_NAME_KEY
import org.session.libsession.utilities.getColorFromAttr
import org.session.libsignal.utilities.Snode
import org.thoughtcrime.securesms.ScreenLockActionBarActivity
import org.thoughtcrime.securesms.pro.ProDetailsRepository
import org.thoughtcrime.securesms.reviews.InAppReviewManager
import org.thoughtcrime.securesms.ui.getSubbedString
import org.thoughtcrime.securesms.ui.openUrl
Expand Down Expand Up @@ -131,14 +128,17 @@ class PathActivity : ScreenLockActionBarActivity() {

lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.STARTED) {
pathState.map { it.isEmpty() }
pathManager.status
.map { it == PathStatus.BUILDING || it == PathStatus.ERROR }
.collectLatest { isLoading ->
if (isLoading) {
binding.spinner.fadeIn()
} else {
binding.spinner.fadeOut()
}
if (isLoading) {
binding.spinner.fadeIn()
} else {
binding.spinner.fadeOut()
}

binding.pathRowsContainer.isVisible = !isLoading
}
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.thoughtcrime.securesms.network

import com.google.common.truth.Truth.assertThat
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.test.runTest
import org.junit.Before
import org.junit.Rule
Expand All @@ -15,6 +16,7 @@ import org.session.libsignal.utilities.Snode
import org.thoughtcrime.securesms.database.SnodeDatabase
import org.thoughtcrime.securesms.database.SnodeDatabaseTest
import org.thoughtcrime.securesms.util.MockLoggingRule
import org.thoughtcrime.securesms.util.NetworkConnectivity

@RunWith(RobolectricTestRunner::class)
@Config(minSdk = 36) // Setting min sdk 36 to use recent sqlite version as we use some modern features in the app code
Expand All @@ -25,9 +27,15 @@ class PathManagerTest {

lateinit var snodeDb: SnodeDatabase

private lateinit var networkConnectivity: NetworkConnectivity

@Before
fun setUp() {
snodeDb = SnodeDatabaseTest.createInMemorySnodeDatabase()

networkConnectivity = mock {
on { networkAvailable } doReturn MutableStateFlow(true)
}
}

private fun snode(id: String): Snode =
Expand Down Expand Up @@ -57,6 +65,7 @@ class PathManagerTest {
prefs = mock(),
snodeApiExecutor = { mock() },
getInfoApi = { mock() },
networkConnectivity = networkConnectivity,
)

val chosen = pm.getPath(exclude = b)
Expand All @@ -83,6 +92,7 @@ class PathManagerTest {
prefs = mock(),
snodeApiExecutor = { mock() },
getInfoApi = { mock() },
networkConnectivity = networkConnectivity,
)

pm.handleBadSnode(snode = b, forceRemove = true)
Expand Down Expand Up @@ -115,6 +125,7 @@ class PathManagerTest {
prefs = mock(),
snodeApiExecutor = { mock() },
getInfoApi = { mock() },
networkConnectivity = networkConnectivity,
)

pm.handleBadSnode(snode = b, forceRemove = true)
Expand Down
Loading