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
|
2020-07-04 23:05:36 +05:30
|
|
|
import code.name.monkey.retromusic.Constants.PRO_VERSION_PRODUCT_ID
|
2018-12-08 09:03:02 +05:30
|
|
|
import code.name.monkey.retromusic.appshortcuts.DynamicShortcutManager
|
2018-11-30 06:36:16 +05:30
|
|
|
import com.anjlab.android.iab.v3.BillingProcessor
|
|
|
|
import com.anjlab.android.iab.v3.TransactionDetails
|
2020-07-21 00:35:48 +05:30
|
|
|
import org.koin.android.ext.koin.androidContext
|
|
|
|
import org.koin.core.context.startKoin
|
2019-01-02 09:25:55 +05:30
|
|
|
|
2018-12-05 09:59:55 +05:30
|
|
|
class App : MultiDexApplication() {
|
2018-11-30 06:36:16 +05:30
|
|
|
|
|
|
|
lateinit var billingProcessor: BillingProcessor
|
|
|
|
|
|
|
|
override fun onCreate() {
|
|
|
|
super.onCreate()
|
|
|
|
instance = this
|
2019-09-05 01:00:24 +05:30
|
|
|
|
2020-07-21 00:35:48 +05:30
|
|
|
startKoin {
|
|
|
|
androidContext(this@App)
|
2020-07-26 01:52:37 +05:30
|
|
|
modules(appModules)
|
2020-07-21 00:35:48 +05:30
|
|
|
}
|
2018-11-30 06:36:16 +05:30
|
|
|
// default theme
|
|
|
|
if (!ThemeStore.isConfigured(this, 3)) {
|
|
|
|
ThemeStore.editTheme(this)
|
2019-12-30 16:31:50 +05:30
|
|
|
.accentColorRes(R.color.md_deep_purple_A200)
|
|
|
|
.coloredNavigationBar(true)
|
|
|
|
.commit()
|
2018-11-30 06:36:16 +05:30
|
|
|
}
|
|
|
|
|
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,
|
2019-12-30 16:31:50 +05:30
|
|
|
object : BillingProcessor.IBillingHandler {
|
|
|
|
override fun onProductPurchased(productId: String, details: TransactionDetails?) {}
|
2018-11-30 06:36:16 +05:30
|
|
|
|
2019-12-30 16:31:50 +05:30
|
|
|
override fun onPurchaseHistoryRestored() {
|
2020-02-26 22:19:24 +05:30
|
|
|
Toast.makeText(
|
|
|
|
this@App,
|
|
|
|
R.string.restored_previous_purchase_please_restart,
|
|
|
|
Toast.LENGTH_LONG
|
2020-05-07 13:05:33 +05:30
|
|
|
).show()
|
2019-12-30 16:31:50 +05:30
|
|
|
}
|
2018-11-30 06:36:16 +05:30
|
|
|
|
2019-12-30 16:31:50 +05:30
|
|
|
override fun onBillingError(errorCode: Int, error: Throwable?) {}
|
2018-11-30 06:36:16 +05:30
|
|
|
|
2019-12-30 16:31:50 +05:30
|
|
|
override fun onBillingInitialized() {}
|
|
|
|
})
|
2018-11-30 06:36:16 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
override fun onTerminate() {
|
|
|
|
super.onTerminate()
|
|
|
|
billingProcessor.release()
|
|
|
|
}
|
|
|
|
|
|
|
|
companion object {
|
2019-09-09 18:34:53 +05:30
|
|
|
private var instance: App? = null
|
2018-11-30 06:36:16 +05:30
|
|
|
|
2019-09-09 18:34:53 +05:30
|
|
|
fun getContext(): App {
|
|
|
|
return instance!!
|
|
|
|
}
|
|
|
|
|
|
|
|
fun isProVersion(): Boolean {
|
2020-02-26 22:19:24 +05:30
|
|
|
return BuildConfig.DEBUG || instance?.billingProcessor!!.isPurchased(
|
|
|
|
PRO_VERSION_PRODUCT_ID
|
|
|
|
)
|
2019-09-09 18:34:53 +05:30
|
|
|
}
|
2018-11-30 06:36:16 +05:30
|
|
|
}
|
|
|
|
}
|