ref: v3.7.0
app/src/main/java/xyz/apiote/bimba/czwek/onboarding/FirstRunActivity.kt
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
// SPDX-FileCopyrightText: Adam Evyčędo // // SPDX-License-Identifier: GPL-3.0-or-later package xyz.apiote.bimba.czwek.onboarding import android.app.NotificationChannel import android.app.NotificationManager import android.content.Context import android.content.Intent import android.os.Build import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import androidx.core.content.edit import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen import androidx.work.OneTimeWorkRequest import androidx.work.WorkManager import xyz.apiote.bimba.czwek.R import xyz.apiote.bimba.czwek.dashboard.MainActivity import xyz.apiote.bimba.czwek.repo.migrateDB import xyz.apiote.bimba.czwek.settings.DownloadCitiesWorker import xyz.apiote.bimba.czwek.settings.feeds.migrateFeedsSettings class FirstRunActivity : AppCompatActivity() { override fun onCreate(savedInstanceState: Bundle?) { installSplashScreen() super.onCreate(savedInstanceState) migrateFeedsSettings(this) migrateDB(this) createNotificationChannels() if (DownloadCitiesWorker.shouldUpdate(this)) { WorkManager.getInstance(this) .enqueue(OneTimeWorkRequest.from(DownloadCitiesWorker::class.java)) } val intent = if (getFirstRun(this)) { Intent(this, OnboardingActivity::class.java) } else { Intent(this, MainActivity::class.java) } startActivity(intent) finish() } private fun createNotificationChannels() { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) { val name = getString(R.string.cities_channel_name) val descriptionText = getString(R.string.cities_channel_description) val importance = NotificationManager.IMPORTANCE_LOW val channel = NotificationChannel(DownloadCitiesWorker.NOTIFICATION_CHANNEL, name, importance).apply { description = descriptionText } val notificationManager: NotificationManager = getSystemService(NOTIFICATION_SERVICE) as NotificationManager notificationManager.createNotificationChannel(channel) } } companion object { private const val PREFERENCES_NAME = "shp" private const val FIRST_RUN_KEY = "firstRun" fun setFirstRunDone(context: Context) { context.getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE).edit { putBoolean(FIRST_RUN_KEY, false) } } fun getFirstRun(context: Context): Boolean { return context.getSharedPreferences(PREFERENCES_NAME, MODE_PRIVATE).getBoolean(FIRST_RUN_KEY, true) } } } |