Skip to content

Commit

Permalink
[Version] 🎉 Welcome to 1.00.12
Browse files Browse the repository at this point in the history
  • Loading branch information
Mercandj committed Sep 12, 2018
1 parent 5ed37f4 commit 121914c
Show file tree
Hide file tree
Showing 75 changed files with 2,074 additions and 57 deletions.
14 changes: 13 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,12 +146,20 @@ repositories {
maven { url 'https://maven.fabric.io/public' }
}

kotlin {
experimental {
coroutines 'enable'
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(":monetization")

// Language
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:$kotlin_coroutines_version"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:$kotlin_coroutines_version"

// Android - Support
implementation "androidx.annotation:annotation:1.0.0-rc02"
Expand All @@ -162,6 +170,8 @@ dependencies {

// Google
implementation 'com.google.code.gson:gson:2.8.2'
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation "com.google.firebase:firebase-config:16.0.0"

// Third party - Monitoring
implementation('com.crashlytics.sdk.android:crashlytics:2.9.4@aar') {
Expand Down Expand Up @@ -191,7 +201,7 @@ dependencies {
}

testImplementation 'junit:junit:4.12'
testImplementation 'org.mockito:mockito-core:2.21.0'
testImplementation 'org.mockito:mockito-core:2.22.0'
}

// Spoon
Expand Down Expand Up @@ -232,3 +242,5 @@ if (rootProject.ext.spoonEnable) {
adbTimeout = 30
}
}

apply plugin: 'com.google.gms.google-services'
42 changes: 42 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
{
"project_info": {
"project_number": "966913976495",
"firebase_url": "https://browser-e3b83.firebaseio.com",
"project_id": "browser-e3b83",
"storage_bucket": "browser-e3b83.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:966913976495:android:7f07c0d7905eb43b",
"android_client_info": {
"package_name": "com.mercandalli.android.browser"
}
},
"oauth_client": [
{
"client_id": "966913976495-sfk9eeao7js481r57ijv0adfp4pcc0ve.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyDy9zFmaVwBHij08mOuoKLBuI8e461EswA"
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 2
}
}
}
],
"configuration_version": "1"
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package com.mercandalli.android.browser.ad_blocker

interface AdBlockerManager {

fun isFeatureAvailable(): Boolean

fun isEnabled(): Boolean

fun setEnabled(enabled: Boolean)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,42 @@
package com.mercandalli.android.browser.ad_blocker

import android.content.SharedPreferences
import com.mercandalli.android.browser.product.ProductManager

class AdBlockerManagerImpl(
private val sharedPreferences: SharedPreferences
private val sharedPreferences: SharedPreferences,
private val productManager: ProductManager
) : AdBlockerManager {

private var enabled = false
private var enabledLoaded = false
private var loaded = false

override fun isFeatureAvailable() = productManager.isFullVersionAvailable()

override fun isEnabled(): Boolean {
if (!isFeatureAvailable()) {
return false
}
load()
return enabled
}

override fun setEnabled(enabled: Boolean) {
this.enabled = enabled
sharedPreferences.edit().putBoolean(KEY, enabled).apply()
sharedPreferences.edit().putBoolean(KEY_ENABLED, this.enabled).apply()
}

private fun load() {
if (enabledLoaded) {
if (loaded) {
return
}
enabledLoaded = true
enabled = sharedPreferences.getBoolean(KEY, enabled)
loaded = true
enabled = sharedPreferences.getBoolean(KEY_ENABLED, enabled)
}

companion object {
@JvmStatic
val PREFERENCE_NAME = "AdBlockerManager"
private const val KEY = "ad-blocker-enabled"
val PREFERENCE_NAME = "ad-blocker"
private const val KEY_ENABLED = "enabled"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.mercandalli.android.browser.ad_blocker

import android.content.Context
import com.mercandalli.android.browser.main.ApplicationGraph

class AdBlockerModule(
private val context: Context
) {

fun createAdBlockerManager(): AdBlockerManager {
val sharedPreferences = context.getSharedPreferences(
AdBlockerManagerImpl.PREFERENCE_NAME,
Context.MODE_PRIVATE
)
val productManager = ApplicationGraph.getProductManager()
return AdBlockerManagerImpl(
sharedPreferences,
productManager
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import android.view.View
import android.webkit.*
import com.mercandalli.android.browser.main.ApplicationGraph
import com.mercandalli.android.browser.ad_blocker.AdBlocker
import com.mercandalli.android.browser.main.MainApplication
import com.mercandalli.android.libs.monetization.MonetizationGraph

class BrowserView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@ package com.mercandalli.android.browser.main

import android.annotation.SuppressLint
import android.content.Context
import com.mercandalli.android.browser.ad_blocker.AdBloackerModule
import com.mercandalli.android.browser.ad_blocker.AdBlockerModule
import com.mercandalli.android.browser.product.ProductModule
import com.mercandalli.android.browser.remote_config.RemoteConfigModule
import com.mercandalli.android.browser.theme.ThemeModule
import com.mercandalli.android.browser.thread.MainThreadModule
import com.mercandalli.android.browser.toast.ToastModule
import com.mercandalli.android.browser.update.UpdateModule
import com.mercandalli.android.browser.version.VersionModule

class ApplicationGraph(
private val context: Context
) {

private val adBlockerManagerInternal by lazy { AdBloackerModule().createAdBlockerManager(context) }
private val adBlockerManagerInternal by lazy { AdBlockerModule(context).createAdBlockerManager() }
private val productManagerInternal by lazy { ProductModule().createProductManager() }
private val mainThreadPostInternal by lazy { MainThreadModule().createMainThreadPost() }
private val remoteConfigInternal by lazy { RemoteConfigModule().createRemoteConfig(mainThreadPostInternal) }
private val themeManagerInternal by lazy { ThemeModule(context).createThemeManager() }
private val toastManagerInternal by lazy { ToastModule().createToastManager(context, mainThreadPostInternal) }
private val updateManagerInternal by lazy { UpdateModule().createUpdateManager(context, versionManagerInternal) }
private val versionManagerInternal by lazy { VersionModule().createVersionManager(context) }

companion object {
Expand All @@ -34,12 +40,21 @@ class ApplicationGraph(
@JvmStatic
fun getAdBlockerManager() = graph!!.adBlockerManagerInternal

@JvmStatic
fun getProductManager() = graph!!.productManagerInternal

@JvmStatic
fun getRemoteConfig() = graph!!.remoteConfigInternal

@JvmStatic
fun getThemeManager() = graph!!.themeManagerInternal

@JvmStatic
fun getToastManager() = graph!!.toastManagerInternal

@JvmStatic
fun getUpdateManager() = graph!!.updateManagerInternal

@JvmStatic
fun getVersionManager() = graph!!.versionManagerInternal
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import com.mercandalli.android.browser.R
import com.mercandalli.android.browser.browser.BrowserView
import com.mercandalli.android.browser.keyboard.KeyboardUtils
import com.mercandalli.android.browser.settings.SettingsActivity
import com.mercandalli.android.libs.monetization.MonetizationGraph

class MainActivity : AppCompatActivity(), MainActivityContract.Screen {

Expand All @@ -44,9 +45,16 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {

private val browserWebViewListener = createBrowserWebViewListener()
private val userAction = createUserAction()
private var forceDestroy = false

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
if (MonetizationGraph.startOnBoardingIfNeeded(this)) {
forceDestroy = true
finish()
MainApplication.onOnBoardingStarted()
return
}
setContentView(R.layout.activity_main)
setSupportActionBar(toolbar)
more.setOnClickListener { showOverflowPopupMenu(more) }
Expand All @@ -67,13 +75,19 @@ class MainActivity : AppCompatActivity(), MainActivityContract.Screen {
}

override fun onDestroy() {
super.onDestroy()
if (forceDestroy) {
return
}
webView.browserWebViewListener = null
userAction.onDestroy()
super.onDestroy()
}

override fun onSaveInstanceState(outState: Bundle?) {
super.onSaveInstanceState(outState)
if (forceDestroy) {
return
}
webView.saveState(outState)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ package com.mercandalli.android.browser.main
import android.app.Application
import android.content.pm.ApplicationInfo
import android.os.Build
import android.util.Log
import android.webkit.WebView
import com.crashlytics.android.Crashlytics
import com.crashlytics.android.core.CrashlyticsCore
import com.mercandalli.android.browser.BuildConfig
import com.mercandalli.android.browser.ad_blocker.AdBlocker
import com.mercandalli.android.browser.remote_config.RemoteConfig
import com.mercandalli.android.libs.monetization.Monetization
import com.mercandalli.android.libs.monetization.MonetizationGraph
import com.mercandalli.android.libs.monetization.log.MonetizationLog
import io.fabric.sdk.android.Fabric
Expand Down Expand Up @@ -40,12 +43,21 @@ class MainApplication : Application() {
private fun setupMonetizationGraph() {
val monetizationLog = object : MonetizationLog {
override fun d(tag: String, message: String) {

Log.d(tag, message)
}
}
val activityAction = object : MonetizationGraph.ActivityAction {
override fun startFirstActivity() {
MainActivity.start(this@MainApplication)
}
}
MonetizationGraph.init(
this,
monetizationLog
Monetization.create(
SKU_SUBSCRIPTION_FULL_VERSION
),
monetizationLog,
activityAction
)
MonetizationGraph.getInAppManager().initialize()
}
Expand All @@ -66,6 +78,21 @@ class MainApplication : Application() {
}

companion object {
const val SKU_SUBSCRIPTION_ADS_BLOCKER = "googleplay.com.mercandalli.android.browser.subscription.1"
const val SKU_SUBSCRIPTION_FULL_VERSION = "googleplay.com.mercandalli.android.browser.subscription.1"

@JvmStatic
fun onOnBoardingStarted() {
val remoteConfig = ApplicationGraph.getRemoteConfig()
updateOnBoardingStorePageAvailable(remoteConfig)
remoteConfig.registerListener(object : RemoteConfig.RemoteConfigListener {
override fun onInitialized() {
updateOnBoardingStorePageAvailable(remoteConfig)
}
})
}

private fun updateOnBoardingStorePageAvailable(remoteConfig: RemoteConfig) {
MonetizationGraph.setOnBoardingStorePageAvailable(remoteConfig.isOnBoardingStoreAvailable)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.mercandalli.android.browser.product

interface ProductManager {

fun isFullVersionAvailable(): Boolean

fun isSubscribeToFullVersion(): Boolean
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.mercandalli.android.browser.product

import com.mercandalli.android.browser.main.MainApplication
import com.mercandalli.android.browser.remote_config.RemoteConfig
import com.mercandalli.android.libs.monetization.in_app.InAppManager

class ProductManagerImpl(
private val remoteConfig: RemoteConfig,
private val inAppManager: InAppManager
) : ProductManager {

override fun isFullVersionAvailable() = remoteConfig.isFullVersionAvailable

override fun isSubscribeToFullVersion() = inAppManager.isPurchased(MainApplication.SKU_SUBSCRIPTION_FULL_VERSION)
}
Loading

0 comments on commit 121914c

Please sign in to comment.