mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 09:49:25 +02:00
Sort categories in the category screen
This commit is contained in:
parent
9fda41a006
commit
412966df26
3 changed files with 90 additions and 55 deletions
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -126,6 +126,7 @@ class Adapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
}
|
||||
binding.usedForAppsWithoutCategory = item.usedForNotAssignedApps
|
||||
binding.parentCategoryTitle = item.parentCategoryTitle
|
||||
binding.isChildCategory = item.parentCategoryTitle != null
|
||||
|
||||
binding.card.setOnClickListener { handlers?.onCategoryClicked(item.category) }
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
|
@ -20,6 +20,7 @@ import android.util.SparseLongArray
|
|||
import androidx.lifecycle.AndroidViewModel
|
||||
import androidx.lifecycle.MutableLiveData
|
||||
import io.timelimit.android.data.extensions.mapToTimezone
|
||||
import io.timelimit.android.data.model.Category
|
||||
import io.timelimit.android.data.model.HintsToShow
|
||||
import io.timelimit.android.date.DateInTimezone
|
||||
import io.timelimit.android.date.getMinuteOfWeek
|
||||
|
@ -29,6 +30,7 @@ import io.timelimit.android.livedata.map
|
|||
import io.timelimit.android.livedata.switchMap
|
||||
import io.timelimit.android.logic.DefaultAppLogic
|
||||
import io.timelimit.android.logic.RemainingTime
|
||||
import java.util.*
|
||||
|
||||
class ManageChildCategoriesModel(application: Application): AndroidViewModel(application) {
|
||||
private val logic = DefaultAppLogic.with(application)
|
||||
|
@ -76,8 +78,25 @@ class ManageChildCategoriesModel(application: Application): AndroidViewModel(app
|
|||
)
|
||||
}
|
||||
|
||||
private val sortedCategories = categories.map { categories ->
|
||||
val categoryById = categories.associateBy { it.id }
|
||||
|
||||
val sortedCategories = mutableListOf<Category>()
|
||||
val childCategories = categories.filter { categoryById.containsKey(it.parentCategoryId) }.groupBy { it.parentCategoryId }
|
||||
|
||||
categories.filterNot { categoryById.containsKey(it.parentCategoryId) }.sortedBy { it.title.toLowerCase(Locale.getDefault()) }.forEach { category ->
|
||||
sortedCategories.add(category)
|
||||
|
||||
childCategories[category.id]?.sortedBy { it.title.toLowerCase(Locale.getDefault()) }?.let { items ->
|
||||
sortedCategories.addAll(items)
|
||||
}
|
||||
}
|
||||
|
||||
sortedCategories.toList()
|
||||
}
|
||||
|
||||
private val categoryItems = categoryForUnassignedAppsLive.switchMap { categoryForUnassignedApps ->
|
||||
categories.switchMap { categories ->
|
||||
sortedCategories.switchMap { categories ->
|
||||
timeLimitRules.switchMap { timeLimitRules ->
|
||||
childDate.switchMap { childDate ->
|
||||
usedTimeItemsForWeek.switchMap { usedTimeItemsForWeek ->
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<!--
|
||||
TimeLimit Copyright <C> 2019 Jonas Lochmann
|
||||
TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation version 3 of the License.
|
||||
|
@ -42,10 +42,24 @@
|
|||
name="parentCategoryTitle"
|
||||
type="String" />
|
||||
|
||||
<variable
|
||||
name="isChildCategory"
|
||||
type="boolean" />
|
||||
|
||||
<import type="android.text.TextUtils" />
|
||||
<import type="android.view.View" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:orientation="horizontal">
|
||||
|
||||
<View
|
||||
android:visibility="@{isChildCategory ? View.VISIBLE : View.GONE}"
|
||||
android:layout_width="32dp"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<androidx.cardview.widget.CardView
|
||||
android:foreground="?selectableItemBackground"
|
||||
android:id="@+id/card"
|
||||
|
@ -107,4 +121,5 @@
|
|||
|
||||
</LinearLayout>
|
||||
</androidx.cardview.widget.CardView>
|
||||
</LinearLayout>
|
||||
</layout>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue