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

96 lines
3.1 KiB
Kotlin
Raw Normal View History

2019-03-03 09:29:03 +00:00
/*
* 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 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
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
2019-09-04 19:30:24 +00:00
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 01:06:16 +00:00
import com.anjlab.android.iab.v3.BillingProcessor
import com.anjlab.android.iab.v3.TransactionDetails
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-12-30 11:01:50 +00:00
musicComponent = initDagger(this)
2019-09-04 19:30:24 +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
)
2019-12-30 11:01:50 +00:00
.show()
}
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
}
2019-12-30 11:01:50 +00:00
private fun initDagger(app: App): MusicComponent =
DaggerMusicComponent.builder()
.appModule(AppModule(app))
.build()
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
)
}
2019-09-04 19:30:24 +00:00
lateinit var musicComponent: MusicComponent
2018-11-30 01:06:16 +00:00
const val PRO_VERSION_PRODUCT_ID = "pro_version"
}
}