Skip to content

Commit

Permalink
WIP: favorited page
Browse files Browse the repository at this point in the history
  • Loading branch information
mikolasan committed Dec 2, 2023
1 parent be4fbed commit 8a41cb8
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
1 change: 0 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

plugins {
id 'kotlin-android'
id 'com.android.application'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import java.util.Locale
class ImperialListAdapter(private val workingUnits: WorkingUnits) : BaseAdapter(), Filterable {
var allUnits: Array<ImperialUnit> = workingUnits.orderedUnits
var units: Array<ImperialUnit> = workingUnits.orderedUnits
var names: List<String> = listOf()
var names: List<String> = allUnits.map { u -> u.unitName.name.lowercase(Locale.ROOT) }

private var arrowClickListener: (Int, View, ImperialUnit) -> Unit = { position, _, _ ->
println("arrowClickListener $position")
Expand Down Expand Up @@ -184,7 +184,7 @@ class ImperialListAdapter(private val workingUnits: WorkingUnits) : BaseAdapter(
val bookmark: ImageView = layout.findViewById(R.id.bookmark)
bookmark.setOnClickListener {
unit.bookmarked = !unit.bookmarked
// bookmarkClickListener(dataPosition, it, unit)
bookmarkClickListener(dataPosition, it, unit)
notifyDataSetChanged()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,17 +268,19 @@ class MainActivity : FragmentActivity() {

}


try {
val nav = findNavController(R.id.nav_host_fragment)
val bundle = bundleOf(
"category" to unit.category.type.name,
"topUnit" to workingUnits.topUnit.unitName.name,
"bottomUnit" to workingUnits.bottomUnit.unitName.name
)
nav.navigate(R.id.action_select_unit, bundle)
} catch (e: Exception) {
// ignore
// TODO: only when the second unit is selected as fav
if (workingUnits.favoritedUnits.size > 1) {
try {
val nav = findNavController(R.id.nav_host_fragment)
val bundle = bundleOf(
"category" to unit.category.type.name,
"topUnit" to workingUnits.topUnit.unitName.name,
"bottomUnit" to workingUnits.bottomUnit.unitName.name
)
nav.navigate(R.id.action_select_unit, bundle)
} catch (e: Exception) {
// ignore
}
}

settings.saveTopUnit(workingUnits.topUnit, workingUnits.topUnit.formattedString)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,12 @@ class UnitListFragment : Fragment() {
unitsList.setSelectionAfterHeaderView()
}
listAdapter.setOnBookmarkClickListener { _: Int, arrow: View, unit: ImperialUnit ->

if (unit.bookmarked) {
(activity as MainActivity).workingUnits.favoritedUnits.plusAssign(unit)
(activity as MainActivity).onUnitSelected(unit)
} else {
(activity as MainActivity).workingUnits.favoritedUnits.minusAssign(unit)
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class WorkingUnits() {
lateinit var allUnits: Map<ImperialUnitType, Array<ImperialUnit>>
var selectedCategory: ImperialUnitType? = null
lateinit var orderedUnits: Array<ImperialUnit>
var favoritedUnits: MutableList<ImperialUnit> = mutableListOf()
lateinit var topUnit: ImperialUnit
lateinit var bottomUnit: ImperialUnit
lateinit var listAdapter: ImperialListAdapter
Expand Down
1 change: 0 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ buildscript {

def nav_version = "2.7.5"
classpath "androidx.navigation:navigation-safe-args-gradle-plugin:$nav_version"

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
Expand Down

0 comments on commit 8a41cb8

Please sign in to comment.