Skip to content

Commit

Permalink
Merge pull request #558 from TwidereProject/bugfix/connectivity_manag…
Browse files Browse the repository at this point in the history
…er_crash

fix ConnectivityManager crash
  • Loading branch information
Tlaster authored Jan 19, 2023
2 parents 216aaf1 + 134fcb6 commit 5ebe4d3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
8 changes: 8 additions & 0 deletions android/src/main/kotlin/com/twidere/twiderex/TwidereApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,16 @@
package com.twidere.twiderex

import android.content.Context
import android.net.ConnectivityManager
import androidx.startup.AppInitializer
import com.twidere.twiderex.initializer.DirectMessageInitializer
import com.twidere.twiderex.initializer.NotificationChannelInitializer
import com.twidere.twiderex.initializer.NotificationInitializer
import com.twidere.twiderex.initializer.TwidereServiceInitializer
import com.twidere.twiderex.utils.TwiderexLogger
import com.twidere.twiderex.utils.asIsActiveNetworkFlow
import io.github.aakira.napier.Napier
import kotlinx.coroutines.flow.Flow

class TwidereApp : TwidereApplication() {
override fun onCreate() {
Expand All @@ -46,9 +49,14 @@ class TwidereApp : TwidereApplication() {
initializeComponent(DirectMessageInitializer::class.java)
initializeComponent(TwidereServiceInitializer::class.java)
}
isNetworkActiveFlow = (this.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager).asIsActiveNetworkFlow()
}

interface MissingSplitsChecker {
fun requiredSplits(context: Context): Boolean
}

companion object {
lateinit var isNetworkActiveFlow: Flow<Boolean>
}
}
15 changes: 3 additions & 12 deletions android/src/main/kotlin/com/twidere/twiderex/TwidereXActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ import android.Manifest
import android.content.ContentResolver.SCHEME_ANDROID_RESOURCE
import android.content.Intent
import android.content.res.Configuration
import android.net.ConnectivityManager
import android.net.Uri
import android.os.Build
import android.os.Bundle
Expand Down Expand Up @@ -69,6 +68,7 @@ import com.twidere.twiderex.component.PermissionCheck
import com.twidere.twiderex.component.foundation.LocalInAppNotification
import com.twidere.twiderex.compose.LocalResLoader
import com.twidere.twiderex.di.ext.get
import com.twidere.twiderex.extensions.flowWithLifecycle
import com.twidere.twiderex.extensions.observeAsState
import com.twidere.twiderex.kmp.LocalPlatformWindow
import com.twidere.twiderex.kmp.LocalRemoteNavigator
Expand All @@ -87,10 +87,6 @@ import com.twidere.twiderex.ui.LocalIsActiveNetworkMetered
import com.twidere.twiderex.utils.BrowserLoginDeepLinksChannel
import com.twidere.twiderex.utils.LocalPlatformResolver
import com.twidere.twiderex.utils.PlatformResolver
import com.twidere.twiderex.utils.asIsActiveNetworkFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import moe.tlaster.kfilepicker.FilePicker
import moe.tlaster.precompose.lifecycle.PreComposeActivity
import moe.tlaster.precompose.lifecycle.setContent
Expand All @@ -114,23 +110,18 @@ class TwidereXActivity : PreComposeActivity(), KoinComponent {

private val inAppNotification: InAppNotification by inject()

private val connectivityManager: ConnectivityManager by inject()

private val platformResolver: PlatformResolver by inject()

private val remoteNavigator: RemoteNavigator by inject()

private val isActiveNetworkMetered = MutableStateFlow(false)
private val isActiveNetworkMetered =
TwidereApp.isNetworkActiveFlow.flowWithLifecycle(lifecycle)

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
FilePicker.init(activityResultRegistry, this, contentResolver)
WindowCompat.setDecorFitsSystemWindows(window, false)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
connectivityManager.asIsActiveNetworkFlow()
.flowWithLifecycle(getLifecycle())
.onEach { isActiveNetworkMetered.value = it }
.launchIn(lifecycleScope)
setContent {
var showSplash by rememberSaveable { mutableStateOf(true) }
LaunchedEffect(Unit) {
Expand Down

0 comments on commit 5ebe4d3

Please sign in to comment.