Add option to move Apps to other categories

This commit is contained in:
Jonas Lochmann 2021-01-18 01:00:00 +01:00
parent 7211abbdf1
commit a0676d543a
No known key found for this signature in database
GPG key ID: 8B8C9AEE10FA5B36
4 changed files with 19 additions and 10 deletions

View file

@ -1,5 +1,5 @@
/* /*
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann * TimeLimit Copyright <C> 2019 - 2021 Jonas Lochmann
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -19,5 +19,6 @@ import io.timelimit.android.ui.manage.category.appsandrules.AppAndRuleItem
interface AppAdapterHandlers { interface AppAdapterHandlers {
fun onAppClicked(app: AppAndRuleItem.AppEntry) fun onAppClicked(app: AppAndRuleItem.AppEntry)
fun onAppLongClicked(app: AppAndRuleItem.AppEntry): Boolean
fun onAddAppsClicked() fun onAddAppsClicked()
} }

View file

@ -1,5 +1,5 @@
/* /*
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann * TimeLimit Copyright <C> 2019 - 2021 Jonas Lochmann
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -141,6 +141,8 @@ class AppAndRuleAdapter: RecyclerView.Adapter<AppAndRuleAdapter.Holder>() {
binding.handlers = handlers binding.handlers = handlers
binding.executePendingBindings() binding.executePendingBindings()
binding.root.setOnLongClickListener { handlers?.onAppLongClicked(item) ?: false }
binding.icon.setImageDrawable( binding.icon.setImageDrawable(
DummyApps.getIcon(item.packageNameWithoutActivityName, context) ?: DummyApps.getIcon(item.packageNameWithoutActivityName, context) ?:
DefaultAppLogic.with(context) DefaultAppLogic.with(context)

View file

@ -1,5 +1,5 @@
/* /*
* TimeLimit Copyright <C> 2019 - 2020 Jonas Lochmann * TimeLimit Copyright <C> 2019 - 2021 Jonas Lochmann
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -41,6 +41,7 @@ import io.timelimit.android.ui.main.getActivityViewModel
import io.timelimit.android.ui.manage.category.apps.add.AddCategoryAppsFragment import io.timelimit.android.ui.manage.category.apps.add.AddCategoryAppsFragment
import io.timelimit.android.ui.manage.category.timelimit_rules.edit.EditTimeLimitRuleDialogFragment import io.timelimit.android.ui.manage.category.timelimit_rules.edit.EditTimeLimitRuleDialogFragment
import io.timelimit.android.ui.manage.category.timelimit_rules.edit.EditTimeLimitRuleDialogFragmentListener import io.timelimit.android.ui.manage.category.timelimit_rules.edit.EditTimeLimitRuleDialogFragmentListener
import io.timelimit.android.ui.manage.child.apps.assign.AssignAppCategoryDialogFragment
import kotlinx.android.synthetic.main.fragment_category_apps_and_rules.* import kotlinx.android.synthetic.main.fragment_category_apps_and_rules.*
abstract class CategoryAppsAndRulesFragment: Fragment(), Handlers, EditTimeLimitRuleDialogFragmentListener { abstract class CategoryAppsAndRulesFragment: Fragment(), Handlers, EditTimeLimitRuleDialogFragmentListener {
@ -152,6 +153,17 @@ abstract class CategoryAppsAndRulesFragment: Fragment(), Handlers, EditTimeLimit
} }
} }
override fun onAppLongClicked(app: AppAndRuleItem.AppEntry): Boolean {
return if (auth.requestAuthenticationOrReturnTrue()) {
AssignAppCategoryDialogFragment.newInstance(
childId = childId,
appPackageName = app.packageName
).show(parentFragmentManager)
true
} else false
}
override fun onAddAppsClicked() { override fun onAddAppsClicked() {
if (auth.requestAuthenticationOrReturnTrueAllowChild(childId = childId)) { if (auth.requestAuthenticationOrReturnTrueAllowChild(childId = childId)) {
AddCategoryAppsFragment.newInstance( AddCategoryAppsFragment.newInstance(

View file

@ -1,5 +1,5 @@
/* /*
* TimeLimit Copyright <C> 2019 Jonas Lochmann * TimeLimit Copyright <C> 2019 - 2021 Jonas Lochmann
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -95,12 +95,6 @@ class AssignAppCategoryDialogFragment: BottomSheetDialogFragment() {
dismissAllowingStateLoss() dismissAllowingStateLoss()
} }
}) })
matchingAppEntries.observe(this, Observer {
if (it.isEmpty()) {
dismissAllowingStateLoss()
}
})
} }
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {