Skip to content

Commit

Permalink
Add condition to do not navigate to 0
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean-BaptisteC committed Nov 26, 2023
1 parent 82d1aa7 commit 303b9e8
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.eu.exodus_privacy.exodusprivacy.fragments.apps.model

import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.graphics.drawable.toDrawable
Expand All @@ -18,6 +19,8 @@ class AppsRVAdapter(
private val currentDestinationId: Int
) : ListAdapter<ExodusApplication, AppsRVAdapter.ViewHolder>(AppsDiffUtil()) {

private val TAG = AppsRVAdapter::class.java.simpleName

inner class ViewHolder(val binding: RecyclerViewAppItemBinding) :
RecyclerView.ViewHolder(binding.root)

Expand All @@ -37,14 +40,19 @@ 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().navigate(action)
}
else {
Log.d(TAG,"Unable to navigate to destination")
}
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 @@ -108,18 +108,24 @@ 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().navigate(action)
}
else {
Log.d(TAG,"Unable to navigate to destination")
}
holder.itemView.findNavController().navigate(action)
}
}
}
Expand Down

0 comments on commit 303b9e8

Please sign in to comment.