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

97 lines
3.3 KiB
Kotlin
Raw Normal View History

2019-03-03 14:59:03 +05:30
/*
* Copyright (c) 2019 Hemanth Savarala.
*
* Licensed under the GNU General Public License v3
*
* 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.
*
* 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.
*/
2018-11-30 06:36:16 +05:30
package code.name.monkey.retromusic
2018-12-09 12:08:34 +05:30
import android.widget.Toast
2018-11-30 06:36:16 +05:30
import androidx.multidex.MultiDexApplication
import code.name.monkey.appthemehelper.ThemeStore
2018-12-08 09:03:02 +05:30
import code.name.monkey.appthemehelper.util.VersionUtils
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
2019-09-05 01:00:24 +05:30
import code.name.monkey.retromusic.dagger.DaggerMusicComponent
import code.name.monkey.retromusic.dagger.MusicComponent
import code.name.monkey.retromusic.dagger.module.AppModule
2018-11-30 06:36:16 +05:30
import com.anjlab.android.iab.v3.BillingProcessor
import com.anjlab.android.iab.v3.TransactionDetails
2019-01-02 09:25:55 +05:30
2018-11-30 06:36:16 +05:30
class App : MultiDexApplication() {
2018-11-30 06:36:16 +05:30
lateinit var billingProcessor: BillingProcessor
override fun onCreate() {
2019-09-18 01:06:13 +05:30
/* if (MissingSplitsManagerFactory.create(this).disableAppIfMissingRequiredSplits()) {
return
2019-09-18 01:06:13 +05:30
}*/
2018-11-30 06:36:16 +05:30
super.onCreate()
instance = this
2019-09-05 01:00:24 +05:30
musicComponent = DaggerMusicComponent.builder()
.appModule(AppModule(this))
.build()
2018-11-30 06:36:16 +05:30
// default theme
if (!ThemeStore.isConfigured(this, 3)) {
ThemeStore.editTheme(this)
.accentColorRes(R.color.md_green_A200)
.coloredNavigationBar(true)
.commit()
}
2018-12-08 09:03:02 +05:30
if (VersionUtils.hasNougatMR())
DynamicShortcutManager(this).initDynamicShortcuts()
2018-11-30 06:36:16 +05:30
// automatically restores purchases
2018-12-09 12:08:34 +05:30
billingProcessor = BillingProcessor(this, BuildConfig.GOOGLE_PLAY_LICENSING_KEY,
2018-11-30 06:36:16 +05:30
object : BillingProcessor.IBillingHandler {
override fun onProductPurchased(productId: String, details: TransactionDetails?) {}
override fun onPurchaseHistoryRestored() {
2018-12-09 12:08:34 +05:30
Toast.makeText(this@App, R.string.restored_previous_purchase_please_restart, Toast.LENGTH_LONG).show();
2018-11-30 06:36:16 +05:30
}
override fun onBillingError(errorCode: Int, error: Throwable?) {}
override fun onBillingInitialized() {}
})
}
override fun onTerminate() {
super.onTerminate()
billingProcessor.release()
}
companion object {
private var instance: App? = null
2018-11-30 06:36:16 +05:30
fun getContext(): App {
return instance!!
}
fun isProVersion(): Boolean {
return BuildConfig.DEBUG || instance?.billingProcessor!!.isPurchased(PRO_VERSION_PRODUCT_ID)
}
2019-09-05 01:00:24 +05:30
lateinit var musicComponent: MusicComponent
2018-11-30 06:36:16 +05:30
const val PRO_VERSION_PRODUCT_ID = "pro_version"
/*val context: Context
get() = (instance as App).applicationContext*/
2018-11-30 06:36:16 +05:30
/*val isProVersion: Boolean
get() = BuildConfig.DEBUG || instance.billingProcessor.isPurchased(PRO_VERSION_PRODUCT_ID)*/
2018-11-30 06:36:16 +05:30
}
}