Skip to content

Commit

Permalink
Merge pull request #172 from alexandr7035/develop
Browse files Browse the repository at this point in the history
Release v4.5.4

Improve navigation stability
  • Loading branch information
alexandr7035 authored Nov 14, 2021
2 parents 4934470 + 5cabaa2 commit 34c2ee5
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 68 deletions.
18 changes: 9 additions & 9 deletions app/src/main/java/by/alexandr7035/gitstat/view/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import androidx.drawerlayout.widget.DrawerLayout
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import androidx.navigation.ui.setupWithNavController
import by.alexandr7035.gitstat.NavGraphDirections
import by.alexandr7035.gitstat.R
import by.alexandr7035.gitstat.SyncGraphDirections
import by.alexandr7035.gitstat.data.SyncForegroundService
import by.alexandr7035.gitstat.databinding.ActivityMainBinding
import by.alexandr7035.gitstat.extensions.navigateSafe
import by.alexandr7035.gitstat.view.datasync.SyncHostFragmentDirections
import by.alexandr7035.gitstat.view.login.LoginFragmentDirections
import by.alexandr7035.gitstat.view.login.LogoutConfirmationDialogDirections
import by.alexandr7035.gitstat.view.profile.ProfileViewModel
import com.squareup.picasso.Picasso
import dagger.hilt.android.AndroidEntryPoint
Expand Down Expand Up @@ -123,16 +123,16 @@ class MainActivity : AppCompatActivity() {
when (menuItem.itemId) {

R.id.item_logout -> {
navController.navigateSafe(MainActivityDirections.actionGlobalLogoutConfirmationDialog())
navController.navigateSafe(NavGraphDirections.actionGlobalLogoutConfirmationDialog())
binding.drawerLayout.closeDrawer(GravityCompat.START)
}

R.id.item_privacy_policy -> navController.navigateSafe(MainActivityDirections.actionGlobalWebViewFragment(
R.id.item_privacy_policy -> navController.navigateSafe(NavGraphDirections.actionGlobalWebViewFragment(
getString(R.string.privacy_policy),
getString(R.string.privacy_policy_url)
))

R.id.item_about_app -> navController.navigateSafe(MainActivityDirections.actionGlobalAboutAppFragment())
R.id.item_about_app -> navController.navigateSafe(NavGraphDirections.actionGlobalAboutAppFragment())
}

true
Expand All @@ -153,21 +153,21 @@ class MainActivity : AppCompatActivity() {
// FIXME find better solution
// than public method accessible from fragments
fun startSyncData() {
navController.navigateSafe(LoginFragmentDirections.actionLoginFragmentToSyncGraph())
navController.navigateSafe(NavGraphDirections.actionGlobalSyncHostFragment())
}

// FIXME find better solution
// than public method accessible from fragments
fun startLogOut() {
viewModel.clearCache()
viewModel.clearToken()
navController.navigateSafe(LogoutConfirmationDialogDirections
.actionLogoutConfirmationDialogToLoginFragment())
navController.navigateSafe(NavGraphDirections
.actionGlobalLoginFragment())
}

// FIXME
fun syncFinishedCallback() {
navController.navigateSafe(SyncGraphDirections.actionGlobalProfileFragment())
navController.navigateSafe(SyncHostFragmentDirections.actionSyncHostFragmentToProfileFragment())
}

fun openDrawerMenu() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.navGraphViewModels
import by.alexandr7035.gitstat.R
import by.alexandr7035.gitstat.databinding.FragmentSyncFailedNetworkBinding
import by.alexandr7035.gitstat.view.MainActivity

class SyncFailedNetworkFragment : Fragment() {

private var binding: FragmentSyncFailedNetworkBinding? = null
private val viewModel by navGraphViewModels<SyncViewModel>(R.id.syncGraph) { defaultViewModelProviderFactory }

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
Expand All @@ -26,7 +24,7 @@ class SyncFailedNetworkFragment : Fragment() {
super.onViewCreated(view, savedInstanceState)

binding?.retryBtn?.setOnClickListener {
viewModel.syncData()
(requireActivity() as MainActivity).startSyncData()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.Fragment
import androidx.navigation.navGraphViewModels
import androidx.fragment.app.viewModels
import by.alexandr7035.gitstat.BuildConfig
import by.alexandr7035.gitstat.R
import by.alexandr7035.gitstat.core.DataSyncStatus
Expand All @@ -18,7 +18,7 @@ import timber.log.Timber
class SyncHostFragment : Fragment() {

private var binding: FragmentSyncHostBinding? = null
private val viewModel by navGraphViewModels<SyncViewModel>(R.id.syncGraph) { defaultViewModelProviderFactory }
private val viewModel by viewModels<SyncViewModel>()

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
binding = FragmentSyncHostBinding.inflate(inflater, container, false)
Expand All @@ -27,14 +27,11 @@ class SyncHostFragment : Fragment() {

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
Timber.d("show sync stub")

viewModel.syncData()

viewModel.getSyncStatusLiveData().observe(viewLifecycleOwner, { status ->
Timber.d("sync status updated $status")
// Toast.makeText(requireContext(), "$status", Toast.LENGTH_SHORT).show()


when (status) {
DataSyncStatus.SUCCESS -> {
Expand Down
73 changes: 23 additions & 50 deletions app/src/main/res/navigation/nav_graph.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,6 @@
android:label="fragment_login"
tools:layout="@layout/fragment_login" >

<action
android:id="@+id/action_loginFragment_to_syncGraph"
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true"
app:destination="@id/syncGraph" />
<action
android:id="@+id/action_loginFragment_to_webViewFragment"
app:destination="@id/webViewFragment" />
Expand All @@ -25,6 +20,7 @@
app:popUpTo="@id/loginFragment"
app:popUpToInclusive="true"
app:destination="@id/profileFragment" />

</fragment>

<fragment
Expand Down Expand Up @@ -88,46 +84,11 @@
</navigation>


<navigation android:id="@+id/syncGraph"
app:startDestination="@id/syncHostFragment">

<fragment
android:id="@+id/syncHostFragment"
android:name="by.alexandr7035.gitstat.view.datasync.SyncHostFragment"
android:label="fragment_sync_host"
tools:layout="@layout/fragment_sync_host" />

<fragment
android:id="@+id/syncPendingFragment"
android:name="by.alexandr7035.gitstat.view.datasync.SyncPendingFragment"
android:label="fragment_sync_pending"
tools:layout="@layout/fragment_sync_pending" />

<fragment
android:id="@+id/syncFailedNoCacheFragment"
android:name="by.alexandr7035.gitstat.view.datasync.SyncFailedNetworkFragment"
android:label="fragment_sync_failed_no_cache"
tools:layout="@layout/fragment_sync_failed_network" />

<action
android:id="@+id/action_global_profileFragment"
app:popUpTo="@id/syncGraph"
app:popUpToInclusive="true"
app:destination="@id/profileFragment" />

</navigation>

<dialog
tools:layout="@layout/fragment_logout_confirmation_dialog"
android:id="@+id/logoutConfirmationDialog"
android:name="by.alexandr7035.gitstat.view.login.LogoutConfirmationDialog"
android:label="LogoutConfirmationDialog" >
<action
android:id="@+id/action_logoutConfirmationDialog_to_loginFragment"
app:popUpTo="@id/profileFragment"
app:popUpToInclusive="true"
app:destination="@id/loginFragment" />
</dialog>
android:label="LogoutConfirmationDialog" />

<fragment
android:id="@+id/webViewFragment"
Expand Down Expand Up @@ -195,11 +156,6 @@
app:argType="string"
app:nullable="false"/>
</action>
<activity
android:id="@+id/mainActivity"
android:name="by.alexandr7035.gitstat.view.MainActivity"
android:label="MainActivity"
tools:layout="@layout/activity_main"/>
<fragment
android:id="@+id/aboutAppFragment"
android:name="by.alexandr7035.gitstat.view.info.AboutAppFragment"
Expand All @@ -208,10 +164,27 @@

<action android:id="@+id/action_global_aboutAppFragment" app:destination="@id/aboutAppFragment" />

<action android:id="@+id/action_global_syncGraph"
app:destination="@id/syncGraph"
app:popUpTo="@id/nav_graph"
<fragment
android:id="@+id/syncHostFragment"
android:name="by.alexandr7035.gitstat.view.datasync.SyncHostFragment"
android:label="fragment_sync_host"
tools:layout="@layout/fragment_sync_pending" >

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

<action android:id="@+id/action_global_syncHostFragment"
app:destination="@id/syncHostFragment"
app:popUpToInclusive="true"
app:popUpTo="@id/nav_graph" />

<action android:id="@+id/action_global_loginFragment"
app:destination="@id/loginFragment"
app:popUpToInclusive="true"
/>
app:popUpTo="@id/nav_graph" />

</navigation>

0 comments on commit 34c2ee5

Please sign in to comment.