Skip to content

Commit

Permalink
Add condition to do not navigate to 0 (#357)
Browse files Browse the repository at this point in the history
Co-authored-by: Benjamin Falière <[email protected]>
  • Loading branch information
Jean-BaptisteC and Benjamin Falière authored Dec 9, 2023
1 parent 4cdbca5 commit 1579260
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import org.eu.exodus_privacy.exodusprivacy.databinding.RecyclerViewAppItemBindin
import org.eu.exodus_privacy.exodusprivacy.fragments.apps.AppsFragmentDirections
import org.eu.exodus_privacy.exodusprivacy.fragments.trackerdetail.TrackerDetailFragmentDirections
import org.eu.exodus_privacy.exodusprivacy.manager.database.app.ExodusApplication
import org.eu.exodus_privacy.exodusprivacy.utils.safeNavigate
import org.eu.exodus_privacy.exodusprivacy.utils.setExodusColor

class AppsRVAdapter(
Expand All @@ -37,14 +38,16 @@ class AppsRVAdapter(

holder.binding.apply {
root.setOnClickListener {
val action = if (currentDestinationId == R.id.appsFragment) {
AppsFragmentDirections.actionAppsFragmentToAppDetailFragment(app.packageName)
} else {
TrackerDetailFragmentDirections.actionTrackerDetailFragmentToAppDetailFragment(
app.packageName
)
if (currentDestinationId != 0) {
val action = if (currentDestinationId == R.id.appsFragment) {
AppsFragmentDirections.actionAppsFragmentToAppDetailFragment(app.packageName)
} else {
TrackerDetailFragmentDirections.actionTrackerDetailFragmentToAppDetailFragment(
app.packageName
)
}
it.findNavController().safeNavigate(action)
}
it.findNavController().navigate(action)
}
appIconIV.background = app.icon.toDrawable(context.resources)
appNameTV.text = app.name
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.eu.exodus_privacy.exodusprivacy.databinding.RecyclerViewTrackerItemBi
import org.eu.exodus_privacy.exodusprivacy.fragments.appdetail.AppDetailFragmentDirections
import org.eu.exodus_privacy.exodusprivacy.fragments.trackers.TrackersFragmentDirections
import org.eu.exodus_privacy.exodusprivacy.manager.database.tracker.TrackerData
import org.eu.exodus_privacy.exodusprivacy.utils.safeNavigate

class TrackersRVAdapter(
private val showSuggestions: Boolean,
Expand Down Expand Up @@ -107,18 +108,21 @@ class TrackersRVAdapter(
}
}
root.setOnClickListener {
val action = if (currentDestinationId == R.id.appDetailFragment) {
AppDetailFragmentDirections.actionAppDetailFragmentToTrackerDetailFragment(
app.id,
trackerPercentage.toInt()
)
} else {
TrackersFragmentDirections.actionTrackersFragmentToTrackerDetailFragment(
app.id,
trackerPercentage.toInt()
)
if (currentDestinationId != 0) {
val action =
if (currentDestinationId == R.id.appDetailFragment) {
AppDetailFragmentDirections.actionAppDetailFragmentToTrackerDetailFragment(
app.id,
trackerPercentage.toInt()
)
} else {
TrackersFragmentDirections.actionTrackersFragmentToTrackerDetailFragment(
app.id,
trackerPercentage.toInt()
)
}
holder.itemView.findNavController().safeNavigate(action)
}
holder.itemView.findNavController().navigate(action)
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package org.eu.exodus_privacy.exodusprivacy.utils

import androidx.navigation.NavController
import androidx.navigation.NavDirections

fun NavController.safeNavigate(direction: NavDirections) {
currentDestination?.getAction(direction.actionId)?.run {
navigate(direction)
}
}

0 comments on commit 1579260

Please sign in to comment.