Skip to content

Commit

Permalink
fix: crash on orientation change by adding to configChanges (#181)
Browse files Browse the repository at this point in the history
Closes #179
properly
  • Loading branch information
Yash-Garg authored Nov 27, 2022
1 parent f9e8012 commit d6feeee
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 7 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
applicationId = "dev.yashgarg.qbit"
minSdk = 24
targetSdk = 33
versionCode = 6
versionCode = 7
versionName = "v0.1.$versionCode-$commitHash"

multiDexEnabled = true
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<activity
android:name=".MainActivity"
android:configChanges="orientation|screenSize"
android:exported="true"
android:theme="@style/Theme.Qbit">
<intent-filter>
Expand Down
8 changes: 2 additions & 6 deletions app/src/main/kotlin/dev/yashgarg/qbit/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.yashgarg.qbit

import android.content.Context
import android.content.pm.ActivityInfo
import android.os.Build
import android.os.Bundle
import android.util.Log
Expand All @@ -13,7 +12,7 @@ import androidx.core.os.bundleOf
import androidx.core.view.WindowCompat
import androidx.datastore.core.DataStore
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.whenStarted
import androidx.lifecycle.whenResumed
import androidx.navigation.Navigation.findNavController
import androidx.work.ExistingWorkPolicy
import androidx.work.OneTimeWorkRequestBuilder
Expand All @@ -39,7 +38,6 @@ class MainActivity : AppCompatActivity() {
@Inject lateinit var serverPrefsStore: DataStore<ServerPreferences>

override fun onCreate(savedInstanceState: Bundle?) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
WindowCompat.setDecorFitsSystemWindows(window, false)
super.onCreate(savedInstanceState)

Expand All @@ -48,14 +46,12 @@ class MainActivity : AppCompatActivity() {
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)

Log.i(this.javaClass.simpleName, "SavedInstanceState: $savedInstanceState")

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
checkPermissions(applicationContext)
}

lifecycleScope.launch {
whenStarted {
whenResumed {
clientManager.configStatus.collect { status ->
when (status) {
ConfigStatus.EXISTS -> {
Expand Down

0 comments on commit d6feeee

Please sign in to comment.