mirror of
https://codeberg.org/timelimit/timelimit-android.git
synced 2025-10-06 03:50:23 +02:00
Remove option to assign all Apps which were not assigned yet
This commit is contained in:
parent
8123fd691e
commit
f8d0aa0dd9
7 changed files with 5 additions and 166 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
|
||||
|
@ -33,7 +33,6 @@ class ChildAppsAdapter: RecyclerView.Adapter<ChildAppsHolder>() {
|
|||
private const val TYPE_CATEGORY_HEADER = 0
|
||||
private const val TYPE_APP = 1
|
||||
private const val TYPE_EMPTY = 2
|
||||
private const val TYPE_ASSIGN_ALL = 3
|
||||
}
|
||||
|
||||
var data: List<ChildAppsEntry> by Delegates.observable(emptyList()) { _, _, _ -> notifyDataSetChanged() }
|
||||
|
@ -48,7 +47,6 @@ class ChildAppsAdapter: RecyclerView.Adapter<ChildAppsHolder>() {
|
|||
is ChildAppsCategoryHeader -> TYPE_CATEGORY_HEADER
|
||||
is ChildAppsApp -> TYPE_APP
|
||||
is ChildAppsEmptyCategory -> TYPE_EMPTY
|
||||
is ChildAppsAssignAll -> TYPE_ASSIGN_ALL
|
||||
}
|
||||
|
||||
override fun getItemId(position: Int): Long {
|
||||
|
@ -58,7 +56,6 @@ class ChildAppsAdapter: RecyclerView.Adapter<ChildAppsHolder>() {
|
|||
is ChildAppsCategoryHeader -> (item.categoryId ?: "no category").hashCode().toLong()
|
||||
is ChildAppsApp -> item.app.packageName.hashCode().toLong()
|
||||
is ChildAppsEmptyCategory -> (item.categoryId ?: "no category").hashCode().toLong()
|
||||
is ChildAppsAssignAll -> "assign all".hashCode().toLong()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,13 +84,6 @@ class ChildAppsAdapter: RecyclerView.Adapter<ChildAppsHolder>() {
|
|||
executePendingBindings()
|
||||
}.root
|
||||
)
|
||||
TYPE_ASSIGN_ALL -> {
|
||||
AssignAllAppsViewHolder(
|
||||
Button(parent.context).apply {
|
||||
setText(R.string.child_apps_assign_all)
|
||||
}
|
||||
)
|
||||
}
|
||||
else -> throw IllegalArgumentException()
|
||||
}
|
||||
|
||||
|
@ -127,15 +117,6 @@ class ChildAppsAdapter: RecyclerView.Adapter<ChildAppsHolder>() {
|
|||
|
||||
// nothing to do
|
||||
}
|
||||
is ChildAppsAssignAll -> {
|
||||
holder as AssignAllAppsViewHolder
|
||||
|
||||
holder.itemView.setOnClickListener {
|
||||
handlers?.onAssignAppsClicked(item.packageNames)
|
||||
}
|
||||
|
||||
null
|
||||
}
|
||||
}.let { /* require handling all paths */ }
|
||||
}
|
||||
}
|
||||
|
@ -148,5 +129,4 @@ class AssignAllAppsViewHolder(view: View): ChildAppsHolder(view)
|
|||
|
||||
interface Handlers {
|
||||
fun onAppClicked(app: App)
|
||||
fun onAssignAppsClicked(packageNames: List<String>)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
@ -30,7 +30,6 @@ import io.timelimit.android.databinding.ChildAppsFragmentBinding
|
|||
import io.timelimit.android.ui.main.ActivityViewModel
|
||||
import io.timelimit.android.ui.main.ActivityViewModelHolder
|
||||
import io.timelimit.android.ui.manage.child.ManageChildFragmentArgs
|
||||
import io.timelimit.android.ui.manage.child.apps.assign.AssignAllAppsCategoryDialogFragment
|
||||
import io.timelimit.android.ui.manage.child.apps.assign.AssignAppCategoryDialogFragment
|
||||
import io.timelimit.android.ui.view.AppFilterView
|
||||
|
||||
|
@ -88,15 +87,6 @@ class ChildAppsFragment : Fragment() {
|
|||
).show(fragmentManager!!)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onAssignAppsClicked(packageNames: List<String>) {
|
||||
if (auth.requestAuthenticationOrReturnTrue()) {
|
||||
AssignAllAppsCategoryDialogFragment.newInstance(
|
||||
childId = args.childId,
|
||||
appPackageNames = packageNames
|
||||
).show(fragmentManager!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return binding.root
|
||||
|
|
|
@ -88,12 +88,6 @@ class ChildAppsModel(application: Application): AndroidViewModel(application) {
|
|||
.distinctBy { it.packageName }
|
||||
.sortedBy { it.title.toLowerCase() }
|
||||
|
||||
if (categoryId == null) {
|
||||
result.add(ChildAppsAssignAll(
|
||||
packageNames = sortedApps.map { it.packageName }
|
||||
))
|
||||
}
|
||||
|
||||
result.addAll(
|
||||
sortedApps.map { app ->
|
||||
ChildAppsApp(
|
||||
|
@ -152,4 +146,3 @@ sealed class ChildAppsEntry
|
|||
data class ChildAppsCategoryHeader(val title: String, val categoryId: String?): ChildAppsEntry()
|
||||
data class ChildAppsApp(val app: App, val shownCategoryName: String?): ChildAppsEntry()
|
||||
data class ChildAppsEmptyCategory(val categoryId: String?): ChildAppsEntry()
|
||||
data class ChildAppsAssignAll(val packageNames: List<String>): ChildAppsEntry()
|
||||
|
|
|
@ -1,121 +0,0 @@
|
|||
/*
|
||||
* 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.child.apps.assign
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import android.widget.CheckedTextView
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import io.timelimit.android.R
|
||||
import io.timelimit.android.data.Database
|
||||
import io.timelimit.android.data.model.Category
|
||||
import io.timelimit.android.data.model.UserType
|
||||
import io.timelimit.android.databinding.BottomSheetSelectionListBinding
|
||||
import io.timelimit.android.extensions.showSafe
|
||||
import io.timelimit.android.logic.AppLogic
|
||||
import io.timelimit.android.logic.DefaultAppLogic
|
||||
import io.timelimit.android.sync.actions.AddCategoryAppsAction
|
||||
import io.timelimit.android.ui.main.ActivityViewModel
|
||||
import io.timelimit.android.ui.main.ActivityViewModelHolder
|
||||
|
||||
class AssignAllAppsCategoryDialogFragment: BottomSheetDialogFragment() {
|
||||
companion object {
|
||||
private const val EXTRA_CHILD_ID = "a"
|
||||
private const val EXTRA_PACKAGE_NAMES = "b"
|
||||
private const val TAG = "aaacdf"
|
||||
|
||||
fun newInstance(childId: String, appPackageNames: List<String>) = AssignAllAppsCategoryDialogFragment().apply {
|
||||
arguments = Bundle().apply {
|
||||
putString(EXTRA_CHILD_ID, childId)
|
||||
putStringArray(EXTRA_PACKAGE_NAMES, appPackageNames.toTypedArray())
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
val childId: String by lazy { arguments!!.getString(EXTRA_CHILD_ID)!! }
|
||||
val appPackageNames: Array<String> by lazy { arguments!!.getStringArray(EXTRA_PACKAGE_NAMES)!! }
|
||||
|
||||
val logic: AppLogic by lazy { DefaultAppLogic.with(context!!) }
|
||||
val database: Database by lazy { logic.database }
|
||||
val auth: ActivityViewModel by lazy { (activity as ActivityViewModelHolder).getActivityViewModel() }
|
||||
|
||||
val childCategoryEntries: LiveData<List<Category>> by lazy {
|
||||
database.category().getCategoriesByChildId(childId)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
auth.authenticatedUser.observe(this, Observer {
|
||||
if (it?.second?.type != UserType.Parent) {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
val binding = BottomSheetSelectionListBinding.inflate(inflater, container, false)
|
||||
val list = binding.list
|
||||
|
||||
binding.title = resources.getQuantityString(R.plurals.generic_plural_app, appPackageNames.size, appPackageNames.size)
|
||||
|
||||
childCategoryEntries.observe(this, Observer { categories ->
|
||||
fun buildRow(): CheckedTextView = LayoutInflater.from(context!!).inflate(
|
||||
android.R.layout.simple_list_item_single_choice,
|
||||
list,
|
||||
false
|
||||
) as CheckedTextView
|
||||
|
||||
categories.forEach { category ->
|
||||
buildRow().let { row ->
|
||||
row.text = category.title
|
||||
row.setOnClickListener {
|
||||
auth.tryDispatchParentAction(
|
||||
AddCategoryAppsAction(
|
||||
categoryId = category.id,
|
||||
packageNames = appPackageNames.toList()
|
||||
)
|
||||
)
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
||||
list.addView(row)
|
||||
}
|
||||
}
|
||||
|
||||
buildRow().let { row ->
|
||||
row.setText(R.string.child_apps_unassigned)
|
||||
row.isChecked = true
|
||||
row.setOnClickListener {
|
||||
dismiss()
|
||||
}
|
||||
|
||||
list.addView(row)
|
||||
}
|
||||
})
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
fun show(fragmentManager: FragmentManager) = showSafe(fragmentManager, TAG)
|
||||
}
|
|
@ -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.
|
||||
|
@ -19,5 +19,4 @@
|
|||
<string name="child_apps_sort_by_title">Nach Namen sortieren</string>
|
||||
<string name="child_apps_unassigned">ohne Kategorie</string>
|
||||
<string name="child_apps_empty_category">Diese Kategorie ist leer</string>
|
||||
<string name="child_apps_assign_all">Alle nicht zugeordneten Apps zuordnen, die der aktuellen Filterregel entsprechen</string>
|
||||
</resources>
|
||||
|
|
|
@ -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.
|
||||
|
@ -19,5 +19,4 @@
|
|||
<string name="child_apps_sort_by_title">Ordenar por título</string>
|
||||
<string name="child_apps_unassigned">sem categoria</string>
|
||||
<string name="child_apps_empty_category">Esta categoria está vazia</string>
|
||||
<string name="child_apps_assign_all">Atribuir todos os Aplicativos não atribuídos que correspondam à configuração atual do filtro</string>
|
||||
</resources>
|
||||
|
|
|
@ -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.
|
||||
|
@ -19,5 +19,4 @@
|
|||
<string name="child_apps_sort_by_title">Sort by title</string>
|
||||
<string name="child_apps_unassigned">without category</string>
|
||||
<string name="child_apps_empty_category">This category is empty</string>
|
||||
<string name="child_apps_assign_all">Assign all unassigned Apps which match the current filter setting</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue