~gardenapple/mitch

9fafe3fc83309101db2bbd0c65e33eace38faa4a — gardenapple a month ago c4082de
Init database in the background
M app/src/main/java/ua/gardenapple/itchupdater/client/ItchBrowseHandler.kt => app/src/main/java/ua/gardenapple/itchupdater/client/ItchBrowseHandler.kt +0 -1
@@ 107,7 107,6 @@ class ItchBrowseHandler(
            }
            val locale = ItchWebsiteParser.getLocale(doc)
            if (locale != ItchWebsiteParser.UNKNOWN_LOCALE) {
                Log.d(LOGGING_TAG, "Site locale is $locale")
                putString(PREF_LANG_SITE_LOCALE, locale)
            }
        }

M app/src/main/java/ua/gardenapple/itchupdater/ui/MainActivity.kt => app/src/main/java/ua/gardenapple/itchupdater/ui/MainActivity.kt +17 -3
@@ 20,17 20,19 @@ import androidx.fragment.app.FragmentTransaction
import androidx.preference.PreferenceManager
import androidx.work.ExistingPeriodicWorkPolicy
import com.google.android.material.bottomnavigation.BottomNavigationView
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.runBlocking
import kotlinx.coroutines.*
import ua.gardenapple.itchupdater.*
import ua.gardenapple.itchupdater.database.AppDatabase
import ua.gardenapple.itchupdater.database.DatabaseCleanup
import ua.gardenapple.itchupdater.database.game.Game
import ua.gardenapple.itchupdater.databinding.ActivityMainBinding

/**
 * The [MainActivity] handles a lot of things, including day/night themes and languages
 */
class MainActivity : MitchActivity(), ActivityCompat.OnRequestPermissionsResultCallback {
class MainActivity : MitchActivity(), CoroutineScope by MainScope(),
    ActivityCompat.OnRequestPermissionsResultCallback {

    private lateinit var browseFragment: BrowseFragment
    private lateinit var currentFragmentTag: String



@@ 178,6 180,13 @@ class MainActivity : MitchActivity(), ActivityCompat.OnRequestPermissionsResultC
        } else if (intent.getBooleanExtra(EXTRA_SHOULD_OPEN_LIBRARY, false)) {
            setActiveFragment(LIBRARY_FRAGMENT_TAG)
        }

        launch(Dispatchers.IO) {
            // Force lazy-init database to fully initialize, in the background
            val db = AppDatabase.getDatabase(this@MainActivity)
            if (!db.isOpen)
                db.installDao.getInstallationByPackageName(packageName)
        }
    }

    override fun onResume() {


@@ 203,6 212,11 @@ class MainActivity : MitchActivity(), ActivityCompat.OnRequestPermissionsResultC
        super.onBackPressed()
    }

    override fun onDestroy() {
        super.onDestroy()
        cancel()
    }

    override fun onSaveInstanceState(outState: Bundle) {
        super.onSaveInstanceState(outState)
        outState.putString(ACTIVE_FRAGMENT_KEY, currentFragmentTag)