mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-03 17:59:51 +02:00
Add warning when adding an app with category to an other category
This commit is contained in:
parent
f8aadd0c05
commit
dc7cfc5bf8
6 changed files with 71 additions and 26 deletions
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* TimeLimit Copyright <C> 2019 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.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*/
|
||||
package io.timelimit.android.ui.manage.category.apps.add
|
||||
|
||||
import android.app.Dialog
|
||||
import android.os.Bundle
|
||||
import androidx.appcompat.app.AlertDialog
|
||||
import androidx.fragment.app.DialogFragment
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import io.timelimit.android.R
|
||||
import io.timelimit.android.extensions.showSafe
|
||||
|
||||
class AddAlreadyAssignedAppsInfoDialog: DialogFragment() {
|
||||
companion object {
|
||||
private const val DIALOG_TAG = "AddAlreadyAssignedAppsInfoDialog"
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog = AlertDialog.Builder(context!!, theme)
|
||||
.setMessage(R.string.must_read_add_already_assigned_apps)
|
||||
.setPositiveButton(R.string.generic_ok, null)
|
||||
.create()
|
||||
|
||||
fun show(fragmentManager: FragmentManager) = showSafe(fragmentManager, DIALOG_TAG)
|
||||
}
|
|
@ -20,7 +20,6 @@ import android.view.ViewGroup
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import io.timelimit.android.data.model.App
|
||||
import io.timelimit.android.databinding.FragmentAddCategoryAppsItemBinding
|
||||
import io.timelimit.android.extensions.toggle
|
||||
import io.timelimit.android.logic.DefaultAppLogic
|
||||
import kotlin.properties.Delegates
|
||||
|
||||
|
@ -28,17 +27,7 @@ class AddAppAdapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
var data: List<App>? by Delegates.observable(null as List<App>?) { _, _, _ -> notifyDataSetChanged() }
|
||||
var listener: AddAppAdapterListener? = null
|
||||
var categoryTitleByPackageName: Map<String, String> by Delegates.observable(emptyMap()) { _, _, _ -> notifyDataSetChanged() }
|
||||
val selectedApps = mutableSetOf<String>()
|
||||
|
||||
private val itemHandlers = object: ItemHandlers {
|
||||
override fun onAppClicked(app: App) {
|
||||
selectedApps.toggle(app.packageName)
|
||||
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onAppLongClicked(app: App) = listener?.onAppLongClicked(app) ?: false
|
||||
}
|
||||
var selectedApps: Set<String> by Delegates.observable(emptySet()) { _, _, _ -> notifyDataSetChanged() }
|
||||
|
||||
init {
|
||||
setHasStableIds(true)
|
||||
|
@ -67,7 +56,7 @@ class AddAppAdapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
LayoutInflater.from(parent.context),
|
||||
parent,
|
||||
false
|
||||
).apply { handlers = itemHandlers }
|
||||
)
|
||||
)
|
||||
|
||||
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
|
||||
|
@ -77,6 +66,7 @@ class AddAppAdapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
binding.item = item
|
||||
binding.checked = selectedApps.contains(item.packageName)
|
||||
binding.currentCategoryTitle = categoryTitleByPackageName[item.packageName]
|
||||
binding.handlers = listener
|
||||
binding.executePendingBindings()
|
||||
|
||||
binding.icon.setImageDrawable(
|
||||
|
@ -89,10 +79,7 @@ class AddAppAdapter: RecyclerView.Adapter<ViewHolder>() {
|
|||
|
||||
class ViewHolder(val binding: FragmentAddCategoryAppsItemBinding): RecyclerView.ViewHolder(binding.root)
|
||||
|
||||
interface ItemHandlers: AddAppAdapterListener {
|
||||
fun onAppClicked(app: App)
|
||||
}
|
||||
|
||||
interface AddAppAdapterListener {
|
||||
fun onAppClicked(app: App)
|
||||
fun onAppLongClicked(app: App): Boolean
|
||||
}
|
|
@ -49,6 +49,7 @@ class AddCategoryAppsFragment : DialogFragment() {
|
|||
companion object {
|
||||
private const val DIALOG_TAG = "x"
|
||||
private const val STATUS_PACKAGE_NAMES = "d"
|
||||
private const val STATUS_EDUCATED = "e"
|
||||
|
||||
fun newInstance(params: ManageCategoryFragmentArgs) = AddCategoryAppsFragment().apply {
|
||||
arguments = params.toBundle()
|
||||
|
@ -59,6 +60,7 @@ class AddCategoryAppsFragment : DialogFragment() {
|
|||
private val database: Database by lazy { DefaultAppLogic.with(context!!).database }
|
||||
private val auth: ActivityViewModel by lazy { getActivityViewModel(activity!!) }
|
||||
private val adapter = AddAppAdapter()
|
||||
private var didEducateAboutAddingAssignedApps = false
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
@ -70,9 +72,8 @@ class AddCategoryAppsFragment : DialogFragment() {
|
|||
})
|
||||
|
||||
if (savedInstanceState != null) {
|
||||
adapter.selectedApps.addAll(
|
||||
savedInstanceState.getStringArrayList(STATUS_PACKAGE_NAMES)!!
|
||||
)
|
||||
adapter.selectedApps = savedInstanceState.getStringArrayList(STATUS_PACKAGE_NAMES)!!.toSet()
|
||||
didEducateAboutAddingAssignedApps = savedInstanceState.getBoolean(STATUS_EDUCATED)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -80,6 +81,7 @@ class AddCategoryAppsFragment : DialogFragment() {
|
|||
super.onSaveInstanceState(outState)
|
||||
|
||||
outState.putStringArrayList(STATUS_PACKAGE_NAMES, ArrayList(adapter.selectedApps))
|
||||
outState.putBoolean(STATUS_EDUCATED, didEducateAboutAddingAssignedApps)
|
||||
}
|
||||
|
||||
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
|
||||
|
@ -194,14 +196,26 @@ class AddCategoryAppsFragment : DialogFragment() {
|
|||
}
|
||||
|
||||
binding.selectAllButton.setOnClickListener {
|
||||
adapter.selectedApps.addAll(
|
||||
adapter.data?.map { it.packageName } ?: emptySet()
|
||||
)
|
||||
|
||||
adapter.notifyDataSetChanged()
|
||||
adapter.selectedApps = adapter.selectedApps + (adapter.data?.map { it.packageName }?.toSet() ?: emptySet())
|
||||
}
|
||||
|
||||
adapter.listener = object: AddAppAdapterListener {
|
||||
override fun onAppClicked(app: App) {
|
||||
if (adapter.selectedApps.contains(app.packageName)) {
|
||||
adapter.selectedApps = adapter.selectedApps - setOf(app.packageName)
|
||||
} else {
|
||||
if (!didEducateAboutAddingAssignedApps) {
|
||||
if (adapter.categoryTitleByPackageName[app.packageName] != null) {
|
||||
didEducateAboutAddingAssignedApps = true
|
||||
|
||||
AddAlreadyAssignedAppsInfoDialog().show(fragmentManager!!)
|
||||
}
|
||||
}
|
||||
|
||||
adapter.selectedApps = adapter.selectedApps + setOf(app.packageName)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAppLongClicked(app: App): Boolean {
|
||||
return if (adapter.selectedApps.isEmpty()) {
|
||||
AddAppActivitiesDialogFragment.newInstance(
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
|
||||
<variable
|
||||
name="handlers"
|
||||
type="io.timelimit.android.ui.manage.category.apps.add.ItemHandlers" />
|
||||
type="io.timelimit.android.ui.manage.category.apps.add.AddAppAdapterListener" />
|
||||
|
||||
<variable
|
||||
name="checked"
|
||||
|
|
|
@ -29,4 +29,7 @@
|
|||
Wenn je eine Regel für die Tage von Montag bis Freitag mit jeweils 3 Stunden gewählt wird,
|
||||
kann die Kategorie an jedem dieser Tage für 3 Stunden genutzt werden.
|
||||
</string>
|
||||
<string name="must_read_add_already_assigned_apps">
|
||||
Apps mit Kategorie werden beim Hinzufügen aus der vorherigen Kategorie entfernt - für mehrere Kategorien gleichzeitig können Sie Ober- und Unter-Kategorien verwenden
|
||||
</string>
|
||||
</resources>
|
|
@ -29,4 +29,8 @@
|
|||
If there is one rule per day with 3 hours,
|
||||
then there is a limit of 3 hours per day.
|
||||
</string>
|
||||
<string name="must_read_add_already_assigned_apps">
|
||||
Apps with category are removed from the previous category when they are added to a new category -
|
||||
use parent and child categories to \"add\" an App to multiple categories
|
||||
</string>
|
||||
</resources>
|
Loading…
Add table
Add a link
Reference in a new issue