diff --git a/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt b/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt index 31fb0333..6d0f31f8 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/data/DataSyncRepository.kt @@ -196,4 +196,8 @@ class DataSyncRepository @Inject constructor( } } + fun checkIfCacheExists(): Boolean { + return appPreferences.lastSuccessCacheSyncDate != 0L + } + } \ No newline at end of file diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt index 507fc254..931c1275 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt @@ -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(R.id.drawerProfileImage) val drawerLoginView = binding.drawerNavigationView.getHeaderView(0).findViewById(R.id.drawerLoginView) diff --git a/app/src/main/java/by/alexandr7035/gitstat/view/MainViewModel.kt b/app/src/main/java/by/alexandr7035/gitstat/view/MainViewModel.kt index cb18beaf..cffdfdc1 100644 --- a/app/src/main/java/by/alexandr7035/gitstat/view/MainViewModel.kt +++ b/app/src/main/java/by/alexandr7035/gitstat/view/MainViewModel.kt @@ -2,6 +2,7 @@ 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 @@ -9,12 +10,16 @@ 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() diff --git a/app/src/main/res/navigation/nav_graph.xml b/app/src/main/res/navigation/nav_graph.xml index 4d8fc2d4..ab9a8ad5 100644 --- a/app/src/main/res/navigation/nav_graph.xml +++ b/app/src/main/res/navigation/nav_graph.xml @@ -19,6 +19,12 @@ + +