splash screen

This commit is contained in:
Milos Kozak 2023-08-18 20:05:51 +02:00
parent 9940578aee
commit 3870ebaa53
11 changed files with 216 additions and 108 deletions

View file

@ -63,6 +63,7 @@ import info.nightscout.interfaces.versionChecker.VersionCheckerUtils
import info.nightscout.plugins.constraints.signatureVerifier.SignatureVerifierPlugin import info.nightscout.plugins.constraints.signatureVerifier.SignatureVerifierPlugin
import info.nightscout.rx.AapsSchedulers import info.nightscout.rx.AapsSchedulers
import info.nightscout.rx.events.EventAppExit import info.nightscout.rx.events.EventAppExit
import info.nightscout.rx.events.EventAppInitialized
import info.nightscout.rx.events.EventPreferenceChange import info.nightscout.rx.events.EventPreferenceChange
import info.nightscout.rx.events.EventRebuildTabs import info.nightscout.rx.events.EventRebuildTabs
import info.nightscout.rx.logging.LTag import info.nightscout.rx.logging.LTag
@ -134,10 +135,6 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
} }
}) })
//Check here if loop plugin is disabled. Else check via constraints
if (!(loop as PluginBase).isEnabled()) versionCheckerUtils.triggerCheckVersion()
setUserStats()
setupViews()
disposable += rxBus disposable += rxBus
.toObservable(EventRebuildTabs::class.java) .toObservable(EventRebuildTabs::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
@ -150,6 +147,36 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
.toObservable(EventPreferenceChange::class.java) .toObservable(EventPreferenceChange::class.java)
.observeOn(aapsSchedulers.main) .observeOn(aapsSchedulers.main)
.subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException) .subscribe({ processPreferenceChange(it) }, fabricPrivacy::logException)
disposable += rxBus
.toObservable(EventAppInitialized::class.java)
.observeOn(aapsSchedulers.main)
.subscribe({
// 1st run of app
start()
}, fabricPrivacy::logException)
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (binding.mainDrawerLayout.isDrawerOpen(GravityCompat.START))
binding.mainDrawerLayout.closeDrawers()
else if (menuOpen)
menu?.close()
else if (binding.mainPager.currentItem != 0)
binding.mainPager.currentItem = 0
else finish()
}
})
// Setup views on 2nd and next activity start
// On 1st start app is still initializing, start() is delayed and run from EventAppInitialized
if (config.appInitialized) start()
}
private fun start() {
binding.splash.visibility = View.GONE
//Check here if loop plugin is disabled. Else check via constraints
if (!(loop as PluginBase).isEnabled()) versionCheckerUtils.triggerCheckVersion()
setUserStats()
setupViews()
if (startWizard() && !isRunningRealPumpTest()) { if (startWizard() && !isRunningRealPumpTest()) {
protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, { protectionCheck.queryProtection(this, ProtectionCheck.Protection.PREFERENCES, {
startActivity(Intent(this, SetupWizardActivity::class.java).setAction("info.nightscout.androidaps.MainActivity")) startActivity(Intent(this, SetupWizardActivity::class.java).setAction("info.nightscout.androidaps.MainActivity"))
@ -164,17 +191,6 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
androidPermission.notifyForBtConnectPermission(this) androidPermission.notifyForBtConnectPermission(this)
} }
passwordResetCheck(this) passwordResetCheck(this)
onBackPressedDispatcher.addCallback(this, object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
if (binding.mainDrawerLayout.isDrawerOpen(GravityCompat.START))
binding.mainDrawerLayout.closeDrawers()
else if (menuOpen)
menu?.close()
else if (binding.mainPager.currentItem != 0)
binding.mainPager.currentItem = 0
else finish()
}
})
} }
private fun checkPluginPreferences(viewPager: ViewPager2) { private fun checkPluginPreferences(viewPager: ViewPager2) {
@ -196,6 +212,7 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
if (config.appInitialized) binding.splash.visibility = View.GONE
if (!isProtectionCheckActive) { if (!isProtectionCheckActive) {
isProtectionCheckActive = true isProtectionCheckActive = true
protectionCheck.queryProtection(this, ProtectionCheck.Protection.APPLICATION, UIRunnable { isProtectionCheckActive = false }, protectionCheck.queryProtection(this, ProtectionCheck.Protection.APPLICATION, UIRunnable { isProtectionCheckActive = false },
@ -321,9 +338,6 @@ class MainActivity : DaggerAppCompatActivityWithResult() {
this.menu = menu this.menu = menu
menuInflater.inflate(R.menu.menu_main, menu) menuInflater.inflate(R.menu.menu_main, menu)
pluginPreferencesMenuItem = menu.findItem(R.id.nav_plugin_preferences) pluginPreferencesMenuItem = menu.findItem(R.id.nav_plugin_preferences)
setPluginPreferenceMenuName()
checkPluginPreferences(binding.mainPager)
setDisabledMenuItemColorPluginPreferences()
return true return true
} }

View file

@ -51,6 +51,10 @@ import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.exceptions.UndeliverableException import io.reactivex.rxjava3.exceptions.UndeliverableException
import io.reactivex.rxjava3.kotlin.plusAssign import io.reactivex.rxjava3.kotlin.plusAssign
import io.reactivex.rxjava3.plugins.RxJavaPlugins import io.reactivex.rxjava3.plugins.RxJavaPlugins
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import kotlinx.coroutines.launch
import rxdogtag2.RxDogTag import rxdogtag2.RxDogTag
import java.io.IOException import java.io.IOException
import java.util.concurrent.TimeUnit import java.util.concurrent.TimeUnit
@ -83,13 +87,16 @@ class MainApp : DaggerApplication() {
private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper) private var handler = Handler(HandlerThread(this::class.simpleName + "Handler").also { it.start() }.looper)
private lateinit var refreshWidget: Runnable private lateinit var refreshWidget: Runnable
private val scope = CoroutineScope(Dispatchers.Default + Job())
override fun onCreate() { override fun onCreate() {
super.onCreate() super.onCreate()
aapsLogger.debug("onCreate") aapsLogger.debug("onCreate")
ProcessLifecycleOwner.get().lifecycle.addObserver(processLifecycleListener.get())
scope.launch {
RxDogTag.install() RxDogTag.install()
setRxErrorHandler() setRxErrorHandler()
LocaleHelper.update(this) LocaleHelper.update(this@MainApp)
var gitRemote: String? = BuildConfig.REMOTE var gitRemote: String? = BuildConfig.REMOTE
var commitHash: String? = BuildConfig.HEAD var commitHash: String? = BuildConfig.HEAD
@ -134,7 +141,7 @@ class MainApp : DaggerApplication() {
.subscribe() .subscribe()
}, 10000 }, 10000
) )
WorkManager.getInstance(this).enqueueUniquePeriodicWork( WorkManager.getInstance(this@MainApp).enqueueUniquePeriodicWork(
KeepAliveWorker.KA_0, KeepAliveWorker.KA_0,
ExistingPeriodicWorkPolicy.UPDATE, ExistingPeriodicWorkPolicy.UPDATE,
PeriodicWorkRequest.Builder(KeepAliveWorker::class.java, 15, TimeUnit.MINUTES) PeriodicWorkRequest.Builder(KeepAliveWorker::class.java, 15, TimeUnit.MINUTES)
@ -146,14 +153,15 @@ class MainApp : DaggerApplication() {
localAlertUtils.preSnoozeAlarms() localAlertUtils.preSnoozeAlarms()
doMigrations() doMigrations()
uel.log(UserEntry.Action.START_AAPS, UserEntry.Sources.Aaps) uel.log(UserEntry.Action.START_AAPS, UserEntry.Sources.Aaps)
ProcessLifecycleOwner.get().lifecycle.addObserver(processLifecycleListener.get())
// schedule widget update // schedule widget update
refreshWidget = Runnable { refreshWidget = Runnable {
handler.postDelayed(refreshWidget, 60000) handler.postDelayed(refreshWidget, 60000)
Widget.updateWidget(this, "ScheduleEveryMin") Widget.updateWidget(this@MainApp, "ScheduleEveryMin")
} }
handler.postDelayed(refreshWidget, 60000) handler.postDelayed(refreshWidget, 60000)
config.appInitialized = true
}
} }
private fun setRxErrorHandler() { private fun setRxErrorHandler() {

View file

@ -35,6 +35,8 @@ class ConfigImpl @Inject constructor(
Build.MANUFACTURER + " " + Build.MODEL + " (" + Build.DEVICE + ")" Build.MANUFACTURER + " " + Build.MODEL + " (" + Build.DEVICE + ")"
override val appName: Int = R.string.app_name override val appName: Int = R.string.app_name
override var appInitialized: Boolean = false
private var devBranch = false private var devBranch = false
private var engineeringMode = false private var engineeringMode = false
private var unfinishedMode = false private var unfinishedMode = false

View file

@ -7,6 +7,28 @@
android:clipChildren="false" android:clipChildren="false"
android:clipToPadding="false"> android:clipToPadding="false">
<LinearLayout
android:id="@+id/splash"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="30dp"
android:text="@string/loading"
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.AppCompat.Display1" />
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="20dp"
app:srcCompat="@drawable/splash_logo" />
</LinearLayout>
<com.google.android.material.appbar.MaterialToolbar <com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar" android:id="@+id/toolbar"
android:layout_width="match_parent" android:layout_width="match_parent"

View file

@ -20,6 +20,8 @@ interface Config {
val currentDeviceModelString : String val currentDeviceModelString : String
val appName: Int val appName: Int
var appInitialized: Boolean
fun isEngineeringModeOrRelease(): Boolean fun isEngineeringModeOrRelease(): Boolean
fun isEngineeringMode(): Boolean fun isEngineeringMode(): Boolean
fun isUnfinishedMode(): Boolean fun isUnfinishedMode(): Boolean

View file

@ -1,18 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- The android:opacity=”opaque” linethis is critical in preventing a flash of black as your theme transitions. -->
<layer-list xmlns:android="http://schemas.android.com/apk/res/android" android:opacity="opaque">
<!-- The background color, preferably the same as your normal theme -->
<item android:drawable="?attr/splashBackgroundColor"/>
<!-- Your product logo - 144dp color version of your app icon -->
<item>
<bitmap
android:src="@drawable/splash_icon"
android:gravity="center"/>
</item>
</layer-list>

Binary file not shown.

Before

Width:  |  Height:  |  Size: 24 KiB

File diff suppressed because one or more lines are too long

View file

@ -21,8 +21,6 @@
<item name="colorOnBackground">@color/white</item> <item name="colorOnBackground">@color/white</item>
<item name="colorOnError">@color/black</item> <item name="colorOnError">@color/black</item>
<item name="scrimBackground">@color/mtrl_scrim_color</item> <item name="scrimBackground">@color/mtrl_scrim_color</item>
<!---Splash Background -->
<item name="splashBackgroundColor">@color/splashBackground</item>
<!---Application Background Color --> <!---Application Background Color -->
<item name="android:windowBackground">@color/black</item> <item name="android:windowBackground">@color/black</item>
<!---Text Colors --> <!---Text Colors -->
@ -399,7 +397,6 @@
<!-- The launcher theme. It sets the main window background to the launch_screen drawable --> <!-- The launcher theme. It sets the main window background to the launch_screen drawable -->
<style name="AppTheme.Launcher" parent="AppTheme.NoActionBar"> <style name="AppTheme.Launcher" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style> </style>
<style name="section_header_label"> <style name="section_header_label">

View file

@ -75,8 +75,6 @@
<attr name="notificationLow" format="reference|color" /> <attr name="notificationLow" format="reference|color" />
<attr name="notificationInfo" format="reference|color" /> <attr name="notificationInfo" format="reference|color" />
<attr name="notificationAnnouncement" format="reference|color" /> <attr name="notificationAnnouncement" format="reference|color" />
<!---Splash Background -->
<attr name="splashBackgroundColor" format="reference|color" />
<!---Disabled Text Color --> <!---Disabled Text Color -->
<attr name="disabledTextColor" format="reference|color" /> <attr name="disabledTextColor" format="reference|color" />
<!---Overview and History browser --> <!---Overview and History browser -->

View file

@ -24,8 +24,6 @@
<item name="colorPrimaryVariant">@color/primaryLightColorDefault</item> <item name="colorPrimaryVariant">@color/primaryLightColorDefault</item>
<item name="colorSecondaryVariant">@color/secondaryLightColorDefault</item> <item name="colorSecondaryVariant">@color/secondaryLightColorDefault</item>
<item name="scrimBackground">@color/mtrl_scrim_color</item> <item name="scrimBackground">@color/mtrl_scrim_color</item>
<!---Splash Background -->
<item name="splashBackgroundColor">@color/aaps_theme_light_background</item>
<!---Application Background Color --> <!---Application Background Color -->
<item name="android:windowBackground">@color/aaps_theme_light_background</item> <item name="android:windowBackground">@color/aaps_theme_light_background</item>
<!---Text Colors --> <!---Text Colors -->
@ -409,7 +407,6 @@
<!-- The launcher theme. It sets the main window background to the launch_screen drawable --> <!-- The launcher theme. It sets the main window background to the launch_screen drawable -->
<style name="AppTheme.Launcher" parent="AppTheme.NoActionBar"> <style name="AppTheme.Launcher" parent="AppTheme.NoActionBar">
<item name="android:windowBackground">@drawable/launch_screen</item>
</style> </style>
<style name="section_header_label"> <style name="section_header_label">