PlayerAndroid/app/src/main/java/code/name/monkey/retromusic/App.kt

89 lines
2.9 KiB
Kotlin
Raw Normal View History

2019-03-03 09:29:03 +00:00
/*
2020-10-06 08:46:04 +00:00
* Copyright (c) 2020 Hemanth Savarla.
2019-03-03 09:29:03 +00:00
*
* Licensed under the GNU General Public License v3
*
2020-10-06 08:46:04 +00:00
* This is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
2019-03-03 09:29:03 +00:00
*
* This software is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
2020-10-06 08:46:04 +00:00
*
2019-03-03 09:29:03 +00:00
*/
2018-11-30 01:06:16 +00:00
package code.name.monkey.retromusic
2018-12-09 06:38:34 +00:00
import android.widget.Toast
2018-11-30 01:06:16 +00:00
import androidx.multidex.MultiDexApplication
import code.name.monkey.appthemehelper.ThemeStore
2018-12-08 03:33:02 +00:00
import code.name.monkey.appthemehelper.util.VersionUtils
2020-07-04 17:35:36 +00:00
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
2018-12-08 03:33:02 +00:00
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
2018-11-30 01:06:16 +00:00
import com.anjlab.android.iab.v3.BillingProcessor
import com.anjlab.android.iab.v3.TransactionDetails
2020-07-20 19:05:48 +00:00
import org.koin.android.ext.koin.androidContext
import org.koin.core.context.startKoin
2019-01-02 03:55:55 +00:00
class App : MultiDexApplication() {
2018-11-30 01:06:16 +00:00
lateinit var billingProcessor: BillingProcessor
override fun onCreate() {
super.onCreate()
instance = this
2019-09-04 19:30:24 +00:00
2020-07-20 19:05:48 +00:00
startKoin {
androidContext(this@App)
modules(appModules)
2020-07-20 19:05:48 +00:00
}
2018-11-30 01:06:16 +00:00
// default theme
if (!ThemeStore.isConfigured(this, 3)) {
ThemeStore.editTheme(this)
2019-12-30 11:01:50 +00:00
.accentColorRes(R.color.md_deep_purple_A200)
.coloredNavigationBar(true)
.commit()
2018-11-30 01:06:16 +00:00
}
2018-12-08 03:33:02 +00:00
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(this).initDynamicShortcuts()
2018-11-30 01:06:16 +00:00
// automatically restores purchases
2018-12-09 06:38:34 +00:00
billingProcessor = BillingProcessor(this, BuildConfig.GOOGLE_PLAY_LICENSING_KEY,
2019-12-30 11:01:50 +00:00
object : BillingProcessor.IBillingHandler {
override fun onProductPurchased(productId: String, details: TransactionDetails?) {}
2018-11-30 01:06:16 +00:00
2019-12-30 11:01:50 +00:00
override fun onPurchaseHistoryRestored() {
Toast.makeText(
this@App,
R.string.restored_previous_purchase_please_restart,
Toast.LENGTH_LONG
2020-05-07 07:35:33 +00:00
).show()
2019-12-30 11:01:50 +00:00
}
2018-11-30 01:06:16 +00:00
2019-12-30 11:01:50 +00:00
override fun onBillingError(errorCode: Int, error: Throwable?) {}
2018-11-30 01:06:16 +00:00
2019-12-30 11:01:50 +00:00
override fun onBillingInitialized() {}
})
2018-11-30 01:06:16 +00:00
}
override fun onTerminate() {
super.onTerminate()
billingProcessor.release()
}
companion object {
private var instance: App? = null
2018-11-30 01:06:16 +00:00
fun getContext(): App {
return instance!!
}
fun isProVersion(): Boolean {
return BuildConfig.DEBUG || instance?.billingProcessor!!.isPurchased(
PRO_VERSION_PRODUCT_ID
)
}
2018-11-30 01:06:16 +00:00
}
}