Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sergpetrov committed Dec 3, 2020
2 parents 46eedbb + bf4507b commit a7fb60e
Show file tree
Hide file tree
Showing 30 changed files with 291 additions and 132 deletions.
12 changes: 8 additions & 4 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,14 @@ android {
dependencies {
implementation project(':base')

implementation 'com.google.firebase:firebase-crashlytics:17.3.0'
implementation 'com.google.firebase:firebase-analytics:18.0.0'
implementation 'com.google.firebase:firebase-core:18.0.0'
implementation 'com.google.firebase:firebase-config:19.2.0'
implementation "com.google.android.play:core:1.8.3"
implementation platform('com.google.firebase:firebase-bom:26.1.0')

// Declare the dependencies for the Remote Config and Analytics libraries
// When using the BoM, you don't specify versions in Firebase library dependencies
implementation 'com.google.firebase:firebase-config-ktx'
implementation 'com.google.firebase:firebase-analytics-ktx'
implementation 'com.google.firebase:firebase-crashlytics-ktx'

kapt "com.github.moxy-community:moxy-compiler:$moxyVersion"
kapt 'com.github.stephanenicolas.toothpick:toothpick-compiler:3.0.2'
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.telex">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application android:name=".App">
<activity
android:name=".base.presentation.splash.SplashActivity"
Expand Down
6 changes: 2 additions & 4 deletions app/src/main/java/com/telex/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ import com.telex.base.BaseApp
import com.telex.base.di.AppModule
import com.telex.base.di.Scopes
import com.telex.base.utils.Constants
import com.telex.di.AnalyticsModule
import com.telex.di.RemoteConfigModule
import com.telex.di.AppToolsModule
import com.telex.utils.DebugTree
import com.telex.utils.ReleaseTree
import timber.log.Timber
Expand All @@ -21,8 +20,7 @@ class App : BaseApp() {
val scope = Toothpick.openScope(Scopes.App)
scope.installModules(
AppModule(this),
AnalyticsModule(this),
RemoteConfigModule()
AppToolsModule(this)
)
return scope
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
package com.telex.analytics

import android.content.Context
import android.os.Bundle
import com.google.firebase.analytics.FirebaseAnalytics
import com.google.firebase.analytics.ktx.analytics
import com.google.firebase.ktx.Firebase
import com.telex.base.analytics.AnalyticsReporter

/**
* @author Sergey Petrov
*/
class FirebaseAnalyticsReporter(
private val context: Context
) : AnalyticsReporter {
class FirebaseAnalyticsReporter : AnalyticsReporter {

private val firebaseAnalytics = Firebase.analytics

override fun logEvent(eventKey: String) {
FirebaseAnalytics.getInstance(context).logEvent(eventKey, Bundle())
firebaseAnalytics.logEvent(eventKey, Bundle())
}
}
12 changes: 0 additions & 12 deletions app/src/main/java/com/telex/di/AnalyticsModule.kt

This file was deleted.

25 changes: 25 additions & 0 deletions app/src/main/java/com/telex/di/AppToolsModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.telex.di

import android.content.Context
import com.telex.analytics.FirebaseAnalyticsReporter
import com.telex.base.analytics.AnalyticsReporter
import com.telex.base.model.interactors.RemoteConfigInteractor
import com.telex.base.model.source.local.AppData
import com.telex.base.review.AppReviewManager
import com.telex.model.interactors.FirebaseRemoteConfigInteractor
import com.telex.review.InAppReviewManager
import toothpick.config.Module

class AppToolsModule(context: Context) : Module() {
init {
val appData = AppData(context)
bind(AppData::class.java).toInstance(appData)

val analyticsReporter = FirebaseAnalyticsReporter()
bind(AnalyticsReporter::class.java).toInstance(analyticsReporter)
bind(RemoteConfigInteractor::class.java).toInstance(FirebaseRemoteConfigInteractor())

val appReviewManager = InAppReviewManager(context, appData)
bind(AppReviewManager::class.java).toInstance(appReviewManager)
}
}
11 changes: 0 additions & 11 deletions app/src/main/java/com/telex/di/RemoteConfigModule.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ import com.google.firebase.remoteconfig.FirebaseRemoteConfigSettings
import com.google.gson.Gson
import com.google.gson.JsonSyntaxException
import com.telex.R
import com.telex.base.BuildConfig
import com.telex.base.model.interactors.RemoteConfigInteractor
import com.telex.base.model.interactors.RemoteConfigInteractor.Companion.CACHE_EXPIRATION
import com.telex.base.model.interactors.RemoteConfigInteractor.Companion.CREATED_WITH_CAPTION_DISABLED
import com.telex.base.model.interactors.RemoteConfigInteractor.Companion.MINIMUM_FETCH_INTERVAL_IN_SECONDS
import com.telex.base.model.interactors.RemoteConfigInteractor.Companion.TOP_BANNER
import com.telex.base.model.source.remote.data.TopBannerData
import com.telex.base.utils.Constants.isDebug
import timber.log.Timber

/**
Expand All @@ -19,21 +19,23 @@ import timber.log.Timber
class FirebaseRemoteConfigInteractor : RemoteConfigInteractor {
private var remoteConfig = FirebaseRemoteConfig.getInstance()

private val minimumFetchIntervalInSeconds = when {
isDebug() -> 0
else -> MINIMUM_FETCH_INTERVAL_IN_SECONDS
}

init {
val configSettings = FirebaseRemoteConfigSettings.Builder()
.setDeveloperModeEnabled(BuildConfig.DEBUG)
.setMinimumFetchIntervalInSeconds(minimumFetchIntervalInSeconds)
.build()
remoteConfig.setConfigSettings(configSettings)
remoteConfig.setDefaults(R.xml.remote_config_defaults)
remoteConfig.setConfigSettingsAsync(configSettings)
remoteConfig.setDefaultsAsync(R.xml.remote_config_defaults)
}

override fun fetch(onCompleted: () -> Unit) {
val cacheExpiration = if (BuildConfig.DEBUG) 0 else CACHE_EXPIRATION

remoteConfig.fetch(cacheExpiration)
remoteConfig.fetchAndActivate()
.addOnCompleteListener { task ->
if (task.isSuccessful) {
remoteConfig.activateFetched()
onCompleted.invoke()
}
}
Expand Down
62 changes: 62 additions & 0 deletions app/src/main/java/com/telex/review/InAppReviewManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.telex.review

import android.app.Activity
import android.content.Context
import com.google.android.play.core.review.ReviewManagerFactory
import com.telex.base.analytics.AnalyticsHelper
import com.telex.base.model.source.local.AppData
import com.telex.base.review.AppReviewManager
import io.reactivex.Completable
import java.lang.ref.WeakReference
import java.util.concurrent.TimeUnit
import javax.inject.Singleton

/**
* @author Sergey Petrov
*/
private val APP_REVIEW_REQUEST_INTERVAL = TimeUnit.DAYS.toMillis(60) // 2 months

@Singleton
class InAppReviewManager constructor(
private val context: Context,
private val appData: AppData
) : AppReviewManager {

override fun tryRequestAppReview(activity: Activity): Completable {
val activityReference = WeakReference(activity)
return Completable.create { emitter ->
if (needRequestAppReview()) {
val reviewManager = ReviewManagerFactory.create(context)
val requestReviewFlow = reviewManager.requestReviewFlow()

AnalyticsHelper.logAppReviewRequested()
appData.putLastAppReviewRequestTime(System.currentTimeMillis())

requestReviewFlow.addOnCompleteListener { request ->
when {
request.isSuccessful -> {
activityReference.get()?.apply {
reviewManager.launchReviewFlow(this, request.result)
.addOnCompleteListener {
emitter.onComplete()
}.addOnFailureListener { emitter.tryOnError(it) }
} ?: emitter.onComplete()
}
else -> {
emitter.onComplete()
}
}
}.addOnFailureListener { emitter.tryOnError(it) }
} else emitter.onComplete()
}
}

override fun trackAuthorizedAppLaunch() {
appData.putAuthorizedAppLaunch(appData.getAuthorizedAppLaunch() + 1)
}

private fun needRequestAppReview(): Boolean {
return appData.getAuthorizedAppLaunch() % 10 == 0 &&
System.currentTimeMillis() - appData.getLastAppReviewRequestTime() > APP_REVIEW_REQUEST_INTERVAL
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,23 @@ package com.telex.base.presentation.home

import android.content.Intent
import com.telex.base.model.source.remote.data.TopBannerData
import com.telex.base.presentation.base.BaseActivity
import com.telex.base.presentation.pages.BaseTopBannerDelegate
import com.telex.base.presentation.pages.PagesFragment

/**
* @author Sergey Petrov
*/
class TopBannerDelegate(
activity: BaseActivity,
fragment: PagesFragment?,
banner: TopBannerData
) : BaseTopBannerDelegate(activity, banner) {
) : BaseTopBannerDelegate(fragment, banner) {

override val enabled: Boolean
get() = !banner.disabled

override fun showDefaultOnSecondActionClicked() {
activity.startActivity(Intent(activity, UpgradeToProActivity::class.java))
fragment?.activity?.apply {
startActivity(Intent(this, UpgradeToProActivity::class.java))
}
}
}
6 changes: 2 additions & 4 deletions base/src/main/java/com/telex/base/BaseApp.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@ package com.telex.base

import androidx.appcompat.app.AppCompatDelegate
import androidx.multidex.MultiDexApplication
import com.telex.base.di.AnalyticsModule
import com.telex.base.di.AppModule
import com.telex.base.di.RemoteConfigModule
import com.telex.base.di.AppToolsModule
import com.telex.base.di.Scopes
import com.telex.base.model.interactors.RemoteConfigInteractor
import com.telex.base.model.source.local.AppData
Expand Down Expand Up @@ -53,8 +52,7 @@ abstract class BaseApp : MultiDexApplication() {
val scope = Toothpick.openScope(Scopes.App)
scope.installModules(
AppModule(this),
AnalyticsModule(),
RemoteConfigModule()
AppToolsModule(this)
)
return scope
}
Expand Down
51 changes: 28 additions & 23 deletions base/src/main/java/com/telex/base/analytics/AnalyticsHelper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,35 @@ import toothpick.Toothpick
* @author Sergey Petrov
*/
object AnalyticsHelper {
private const val LAUNCH_TELEGRAM = "Launch Telegram"
private const val LAUNCH_TELEGRAM = "Launch_Telegram"
private const val LOGOUT = "Logout"
private const val CREATE_PAGE = "Create Page"
private const val EDIT_PAGE = "Edit Page"
private const val EDIT_ACCOUNT_INFO = "Edit Account Info"
private const val OPEN_ACCOUNT_SETTINGS = "Open Account Settings"
private const val OPEN_PROXY = "Open Proxy"
private const val SAVE_PROXY = "Save Proxy"
private const val PROXY_ON = "Proxy On"
private const val PROXY_OFF = "Proxy Off"
private const val OPEN_PAGE_IN_BROWSER = "Open Page In Browser"
private const val COPY_PAGE_LINK = "Copy Page Link"
private const val SHARE_PAGE = "Share Page"
private const val OPEN_ABOUT_DEVELOPER = "About Developer"
private const val MOVE_BLOCK_UP = "Move Block Up"
private const val MOVE_BLOCK_DOWN = "Move Block Down"
private const val DELETE_BLOCK = "Delete Block"
private const val DUPLICATE_BLOCK = "Duplicate Block"
private const val OPEN_PAGE_STATISTICS = "Open Page Statistics"
private const val CLICK_DELETE_POST = "Click Delete Post"
private const val CLICK_TOP_BANNER = "Click Top Banner"
private const val CLICK_ADD_ACCOUNT = "Click Add Account"
private const val CLICK_DRAWER_UPGRADE_TO_PRO_BUTTON = "Click Drawer Upgrade To Pro Button"
private const val CREATE_PAGE = "Create_Page"
private const val EDIT_PAGE = "Edit_Page"
private const val EDIT_ACCOUNT_INFO = "Edit_Account_Info"
private const val OPEN_ACCOUNT_SETTINGS = "Open_Account_Settings"
private const val OPEN_PROXY = "Open_Proxy"
private const val SAVE_PROXY = "Save_Proxy"
private const val PROXY_ON = "Proxy_On"
private const val PROXY_OFF = "Proxy_Off"
private const val OPEN_PAGE_IN_BROWSER = "Open_Page_In_Browser"
private const val COPY_PAGE_LINK = "Copy_Page_Link"
private const val SHARE_PAGE = "Share_Page"
private const val OPEN_ABOUT_DEVELOPER = "About_Developer"
private const val MOVE_BLOCK_UP = "Move_Block_Up"
private const val MOVE_BLOCK_DOWN = "Move_Block_Down"
private const val DELETE_BLOCK = "Delete_Block"
private const val DUPLICATE_BLOCK = "Duplicate_Block"
private const val OPEN_PAGE_STATISTICS = "Open_Page_Statistics"
private const val CLICK_DELETE_POST = "Click_Delete_Post"
private const val CLICK_TOP_BANNER = "Click_Top_Banner"
private const val CLICK_ADD_ACCOUNT = "Click_Add_Account"
private const val CLICK_DRAWER_UPGRADE_TO_PRO_BUTTON = "Click_Drawer_Upgrade_To_Pro_Button"
private const val APP_REVIEW_REQUESTED = "App_Review_Requested"

private var analyticsReporter: AnalyticsReporter = Toothpick.openScope(Scopes.App).getInstance(AnalyticsReporter::class.java)

private fun logEvent(eventKey: String) {
if (!BuildConfig.DEBUG) {
if (BuildConfig.DEBUG) {
analyticsReporter.logEvent(eventKey)
}
}
Expand Down Expand Up @@ -131,4 +132,8 @@ object AnalyticsHelper {
fun logClickDrawerUpgradeToProButton() {
logEvent(CLICK_DRAWER_UPGRADE_TO_PRO_BUTTON)
}

fun logAppReviewRequested() {
logEvent(APP_REVIEW_REQUESTED)
}
}
11 changes: 0 additions & 11 deletions base/src/main/java/com/telex/base/di/AnalyticsModule.kt

This file was deleted.

22 changes: 22 additions & 0 deletions base/src/main/java/com/telex/base/di/AppToolsModule.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.telex.base.di

import android.content.Context
import com.telex.base.analytics.AnalyticsReporter
import com.telex.base.analytics.DefaultAnalyticsReporter
import com.telex.base.model.interactors.DefaultRemoteConfigInteractor
import com.telex.base.model.interactors.RemoteConfigInteractor
import com.telex.base.model.source.local.AppData
import com.telex.base.review.AppReviewManager
import com.telex.base.review.DefaultAppReviewManager
import toothpick.config.Module

class AppToolsModule(context: Context) : Module() {
init {
val appData = AppData(context)
bind(AppData::class.java).toInstance(appData)

bind(AnalyticsReporter::class.java).toInstance(DefaultAnalyticsReporter())
bind(RemoteConfigInteractor::class.java).toInstance(DefaultRemoteConfigInteractor())
bind(AppReviewManager::class.java).toInstance(DefaultAppReviewManager())
}
}
11 changes: 0 additions & 11 deletions base/src/main/java/com/telex/base/di/RemoteConfigModule.kt

This file was deleted.

Loading

0 comments on commit a7fb60e

Please sign in to comment.