Commit d07d8601 authored by Konstantin Tskhovrebov's avatar Konstantin Tskhovrebov 🤖

Add first launch check and show privacy policy if needed.

parent 4c3d5777
......@@ -17,6 +17,9 @@ class Prefs @Inject constructor(
private val KEY_SERVER_PATH = "ad_server_path"
private val KEY_IS_OAUTH = "ad_is_oauth"
private val APP_DATA = "app_data"
private val KEY_FIRST_LAUNCH_TIME = "launch_ts"
private fun getSharedPreferences(prefsName: String) = context.getSharedPreferences(prefsName, Context.MODE_PRIVATE)
override var token: String?
......@@ -36,4 +39,10 @@ class Prefs @Inject constructor(
set(value) {
getSharedPreferences(AUTH_DATA).edit().putBoolean(KEY_IS_OAUTH, value).apply()
}
var firstLaunchTimeStamp: Long?
get() = getSharedPreferences(APP_DATA).getLong(KEY_FIRST_LAUNCH_TIME, 0).takeIf { it > 0 }
set(value) {
getSharedPreferences(APP_DATA).edit().putLong(KEY_FIRST_LAUNCH_TIME, value ?: 0).apply()
}
}
\ No newline at end of file
package ru.terrakok.gitlabclient.model.interactor.launch
import ru.terrakok.gitlabclient.model.repository.app.AppInfoRepository
import javax.inject.Inject
/**
* Created by Konstantin Tskhovrebov (aka @terrakok) on 26.09.18.
*/
class LaunchInteractor @Inject constructor(
private val appInfoRepository: AppInfoRepository
) {
val isFirstLaunch: Boolean
get() {
val timeStamp = appInfoRepository.firstLaunchTimeStamp
if (timeStamp == null) {
appInfoRepository.firstLaunchTimeStamp = System.currentTimeMillis()
return true
} else {
return false
}
}
}
\ No newline at end of file
......@@ -2,6 +2,7 @@ package ru.terrakok.gitlabclient.model.repository.app
import io.reactivex.Single
import ru.terrakok.gitlabclient.entity.app.develop.AppInfo
import ru.terrakok.gitlabclient.model.data.storage.Prefs
import ru.terrakok.gitlabclient.model.data.storage.RawAppData
import ru.terrakok.gitlabclient.model.system.SchedulersProvider
import javax.inject.Inject
......@@ -12,9 +13,16 @@ import javax.inject.Inject
class AppInfoRepository @Inject constructor(
private val rawAppData: RawAppData,
private val appInfo: AppInfo,
private val prefs: Prefs,
private val schedulers: SchedulersProvider
) {
var firstLaunchTimeStamp: Long?
get() = prefs.firstLaunchTimeStamp
set(value) {
prefs.firstLaunchTimeStamp = value
}
fun getAppInfo() = Single.just(appInfo)
fun getAppLibraries() = rawAppData
......
......@@ -5,6 +5,7 @@ import com.arellomobile.mvp.MvpView
import ru.terrakok.cicerone.Router
import ru.terrakok.gitlabclient.Screens
import ru.terrakok.gitlabclient.model.interactor.auth.AuthInteractor
import ru.terrakok.gitlabclient.model.interactor.launch.LaunchInteractor
import javax.inject.Inject
/**
......@@ -12,11 +13,19 @@ import javax.inject.Inject
*/
class AppPresenter @Inject constructor(
private val router: Router,
private val authInteractor: AuthInteractor
private val authInteractor: AuthInteractor,
private val launchInteractor: LaunchInteractor
) : MvpPresenter<MvpView>() {
fun coldStart() {
if (authInteractor.isSignedIn()) router.newRootScreen(Screens.DRAWER_FLOW)
else router.newRootScreen(Screens.AUTH_FLOW)
if (authInteractor.isSignedIn()) {
router.newRootScreen(Screens.DRAWER_FLOW)
} else {
router.newRootScreen(Screens.AUTH_FLOW)
}
if (launchInteractor.isFirstLaunch) {
router.navigateTo(Screens.PRIVACY_POLICY_FLOW)
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment