kopia lustrzana https://github.com/meshtastic/Meshtastic-Android
fix null currentActivity
rodzic
99e9502a29
commit
c2d681b11e
|
@ -1,10 +1,9 @@
|
|||
package com.geeksville.mesh
|
||||
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.content.SharedPreferences
|
||||
import android.os.Bundle
|
||||
import androidx.core.content.edit
|
||||
import androidx.fragment.app.Fragment
|
||||
import com.geeksville.mesh.model.UIViewModel
|
||||
import com.github.appintro.AppIntro
|
||||
import com.github.appintro.AppIntroFragment
|
||||
|
||||
|
@ -42,27 +41,21 @@ class AppIntroduction : AppIntro() {
|
|||
//addSlide(SlideTwoFragment())
|
||||
}
|
||||
|
||||
private fun done() {
|
||||
val prefs = UIViewModel.getPreferences(this)
|
||||
prefs.edit { putBoolean("app_intro_completed", true) }
|
||||
finish()
|
||||
}
|
||||
|
||||
override fun onSkipPressed(currentFragment: Fragment?) {
|
||||
super.onSkipPressed(currentFragment)
|
||||
// Decide what to do when the user clicks on "Skip"
|
||||
finish()
|
||||
val preferences = getSharedPreferences("PREFERENCES", Context.MODE_PRIVATE)
|
||||
var editor = preferences.edit()
|
||||
editor.putBoolean("app_intro_completed", true)
|
||||
editor.apply()
|
||||
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
done()
|
||||
}
|
||||
|
||||
override fun onDonePressed(currentFragment: Fragment?) {
|
||||
super.onDonePressed(currentFragment)
|
||||
// Decide what to do when the user clicks on "Done"
|
||||
finish()
|
||||
val preferences = getSharedPreferences("PREFERENCES", Context.MODE_PRIVATE)
|
||||
var editor = preferences.edit()
|
||||
editor.putBoolean("app_intro_completed", true)
|
||||
editor.apply()
|
||||
|
||||
startActivity(Intent(this, MainActivity::class.java))
|
||||
done()
|
||||
}
|
||||
}
|
|
@ -263,20 +263,16 @@ class MainActivity : BaseActivity(), Logging {
|
|||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
val preferences = getSharedPreferences("PREFERENCES", Context.MODE_PRIVATE)
|
||||
|
||||
installSplashScreen()
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
if (!preferences.getBoolean("app_intro_completed", false)) {
|
||||
val prefs = UIViewModel.getPreferences(this)
|
||||
if (!prefs.getBoolean("app_intro_completed", false)) {
|
||||
startActivity(Intent(this, AppIntroduction::class.java))
|
||||
}
|
||||
|
||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||
|
||||
val prefs = UIViewModel.getPreferences(this)
|
||||
model.setOwner(prefs.getString("owner", ""))
|
||||
|
||||
/// Set theme
|
||||
setUITheme(prefs)
|
||||
setContentView(binding.root)
|
||||
|
|
|
@ -32,10 +32,9 @@ open class GeeksvilleApplication(
|
|||
companion object {
|
||||
lateinit var analytics: AnalyticsProvider
|
||||
var currentActivity: Activity? = null
|
||||
private val backstack = mutableListOf<Activity>()
|
||||
}
|
||||
|
||||
var splunk: AnalyticsProvider? = null
|
||||
|
||||
private val lifecycleCallbacks = object : ActivityLifecycleCallbacks {
|
||||
override fun onActivityPaused(activity: Activity) {
|
||||
}
|
||||
|
@ -44,7 +43,8 @@ open class GeeksvilleApplication(
|
|||
}
|
||||
|
||||
override fun onActivityDestroyed(activity: Activity) {
|
||||
currentActivity = null
|
||||
if (backstack.contains(activity)) backstack.remove(activity)
|
||||
currentActivity = backstack.lastOrNull()
|
||||
}
|
||||
|
||||
override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {
|
||||
|
@ -54,7 +54,8 @@ open class GeeksvilleApplication(
|
|||
}
|
||||
|
||||
override fun onActivityCreated(activity: Activity, savedInstanceState: Bundle?) {
|
||||
currentActivity = activity
|
||||
backstack.add(activity)
|
||||
currentActivity = backstack.lastOrNull()
|
||||
}
|
||||
|
||||
override fun onActivityResumed(activity: Activity) {
|
||||
|
@ -72,16 +73,13 @@ open class GeeksvilleApplication(
|
|||
}
|
||||
|
||||
private val analyticsPrefs: SharedPreferences by lazy {
|
||||
getSharedPreferences(
|
||||
"analytics-prefs",
|
||||
Context.MODE_PRIVATE
|
||||
)
|
||||
getSharedPreferences("analytics-prefs", Context.MODE_PRIVATE)
|
||||
}
|
||||
|
||||
var isAnalyticsAllowed: Boolean
|
||||
get() = analyticsPrefs.getBoolean("allowed", true)
|
||||
set(value) {
|
||||
analyticsPrefs.edit(commit = true) {
|
||||
analyticsPrefs.edit {
|
||||
putBoolean("allowed", value)
|
||||
}
|
||||
|
||||
|
@ -112,13 +110,3 @@ open class GeeksvilleApplication(
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
fun geeksvilleApp(context: Context) = context.applicationContext as GeeksvilleApplication
|
||||
|
||||
|
||||
interface GeeksvilleApplicationClient {
|
||||
|
||||
fun getAnalytics() = GeeksvilleApplication.analytics
|
||||
|
||||
}
|
Ładowanie…
Reference in New Issue