Skip to content

Commit

Permalink
If cache exists navigate directly to MainActivity
Browse files Browse the repository at this point in the history
Related #155
  • Loading branch information
alexandr7035 committed Nov 8, 2021
1 parent 5633a8d commit 8f70354
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -196,4 +196,8 @@ class DataSyncRepository @Inject constructor(
}
}

fun checkIfCacheExists(): Boolean {
return appPreferences.lastSuccessCacheSyncDate != 0L
}

}
12 changes: 7 additions & 5 deletions app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -81,13 +81,15 @@ class MainActivity : AppCompatActivity() {


if (viewModel.checkIfTokenSaved()) {
startSyncData()
}
else {
// TODO
if (viewModel.checkIfCacheExists()) {
// FIXME
navController.navigate(R.id.action_loginFragment_to_profileFragment)
}
else {
startSyncData()
}
}


// Drawer settings
val drawerPictureView = binding.drawerNavigationView.getHeaderView(0).findViewById<CircleImageView>(R.id.drawerProfileImage)
val drawerLoginView = binding.drawerNavigationView.getHeaderView(0).findViewById<TextView>(R.id.drawerLoginView)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,24 @@ package by.alexandr7035.gitstat.view

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import by.alexandr7035.gitstat.data.DataSyncRepository
import by.alexandr7035.gitstat.data.SyncRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor(private val syncRepository: SyncRepository): ViewModel() {
class MainViewModel @Inject constructor(private val syncRepository: SyncRepository, private val dataSyncRepository: DataSyncRepository): ViewModel() {

fun checkIfTokenSaved(): Boolean {
return syncRepository.checkIfTokenSaved()
}

fun checkIfCacheExists(): Boolean {
return dataSyncRepository.checkIfCacheExists()
}

fun clearCache() {
viewModelScope.launch(Dispatchers.IO) {
syncRepository.clearCache()
Expand Down
6 changes: 6 additions & 0 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@
<action
android:id="@+id/action_loginFragment_to_webViewFragment"
app:destination="@id/webViewFragment" />

<action
android:id="@+id/action_loginFragment_to_profileFragment"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true"
app:destination="@id/profileFragment" />
</fragment>

<fragment
Expand Down

0 comments on commit 8f70354

Please sign in to comment.