-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
146 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
49 changes: 48 additions & 1 deletion
49
app/src/main/kotlin/com/ray/template/android/TemplateApplication.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,63 @@ | ||
package com.ray.template.android | ||
|
||
import android.app.Application | ||
import android.content.Intent | ||
import androidx.lifecycle.Lifecycle | ||
import androidx.lifecycle.ProcessLifecycleOwner | ||
import androidx.lifecycle.lifecycleScope | ||
import androidx.lifecycle.repeatOnLifecycle | ||
import com.google.firebase.analytics.ktx.analytics | ||
import com.google.firebase.crashlytics.ktx.crashlytics | ||
import com.google.firebase.ktx.Firebase | ||
import com.ray.template.android.domain.repository.AuthenticationRepository | ||
import com.ray.template.android.presentation.ui.invalid.InvalidJwtTokenActivity | ||
import dagger.hilt.android.HiltAndroidApp | ||
import io.sentry.Sentry | ||
import javax.inject.Inject | ||
import kotlinx.coroutines.CoroutineExceptionHandler | ||
import kotlinx.coroutines.launch | ||
import timber.log.Timber | ||
|
||
@HiltAndroidApp | ||
open class TemplateApplication : Application() { | ||
|
||
@Inject | ||
lateinit var authenticationRepository: AuthenticationRepository | ||
|
||
private val handler = CoroutineExceptionHandler { _, exception -> | ||
Timber.d(exception) | ||
Sentry.captureException(exception) | ||
Firebase.crashlytics.recordException(exception) | ||
} | ||
|
||
override fun onCreate() { | ||
super.onCreate() | ||
initializeFirebase() | ||
observeRefreshTokenValidation() | ||
} | ||
|
||
// Firebase Initialize | ||
private fun initializeFirebase() { | ||
Firebase.analytics | ||
} | ||
|
||
private fun observeRefreshTokenValidation() { | ||
with(ProcessLifecycleOwner.get()) { | ||
lifecycleScope.launch(handler) { | ||
repeatOnLifecycle(Lifecycle.State.STARTED) { | ||
authenticationRepository.isRefreshTokenInvalid.collect { isRefreshTokenInvalid -> | ||
if (isRefreshTokenInvalid) { | ||
val intent = Intent( | ||
this@TemplateApplication, | ||
InvalidJwtTokenActivity::class.java | ||
).apply { | ||
flags = | ||
Intent.FLAG_ACTIVITY_NEW_TASK or Intent.FLAG_ACTIVITY_CLEAR_TASK | ||
} | ||
startActivity(intent) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
3 changes: 3 additions & 0 deletions
3
...in/src/main/kotlin/com/ray/template/android/domain/repository/AuthenticationRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
...c/main/kotlin/com/ray/template/android/presentation/ui/invalid/InvalidJwtTokenActivity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.ray.template.android.presentation.ui.invalid | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import androidx.activity.compose.setContent | ||
import androidx.appcompat.app.AppCompatActivity | ||
import androidx.compose.runtime.Composable | ||
import androidx.compose.ui.platform.LocalContext | ||
import androidx.compose.ui.res.stringResource | ||
import androidx.hilt.navigation.compose.hiltViewModel | ||
import com.ray.template.android.presentation.R | ||
import com.ray.template.android.presentation.common.theme.TemplateTheme | ||
import com.ray.template.android.presentation.common.view.DialogScreen | ||
import com.ray.template.android.presentation.ui.main.MainActivity | ||
import dagger.hilt.android.AndroidEntryPoint | ||
|
||
@AndroidEntryPoint | ||
class InvalidJwtTokenActivity : AppCompatActivity() { | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContent { | ||
InvalidJwtTokenScreen() | ||
} | ||
} | ||
|
||
@Composable | ||
fun InvalidJwtTokenScreen( | ||
viewModel: InvalidJwtTokenViewModel = hiltViewModel() | ||
) { | ||
val context = LocalContext.current | ||
TemplateTheme { | ||
DialogScreen( | ||
title = stringResource(R.string.invalid_jwt_token_dialog_title), | ||
message = stringResource(R.string.invalid_jwt_token_dialog_content), | ||
onConfirm = { | ||
val intent = Intent(context, MainActivity::class.java) | ||
context.startActivity(intent) | ||
finishAfterTransition() | ||
}, | ||
onDismissRequest = {} | ||
) | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
.../main/kotlin/com/ray/template/android/presentation/ui/invalid/InvalidJwtTokenViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.ray.template.android.presentation.ui.invalid | ||
|
||
import com.ray.template.android.presentation.common.base.BaseViewModel | ||
import dagger.hilt.android.lifecycle.HiltViewModel | ||
import javax.inject.Inject | ||
|
||
@HiltViewModel | ||
class InvalidJwtTokenViewModel @Inject constructor() : BaseViewModel() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters