mirror of
https://codeberg.org/timelimit/opentimelimit-android.git
synced 2025-10-05 10:49:29 +02:00
Move category deletion to dialog
This commit is contained in:
parent
aa6266ac3f
commit
96df39eead
7 changed files with 146 additions and 15 deletions
|
@ -66,8 +66,7 @@ class CategorySettingsFragment : Fragment() {
|
|||
}
|
||||
})
|
||||
|
||||
checkbox_delete_category.setOnCheckedChangeListener { _, isChecked -> btn_delete_category.isEnabled = isChecked }
|
||||
btn_delete_category.setOnClickListener { doDeleteCategory() }
|
||||
btn_delete_category.setOnClickListener { deleteCategory() }
|
||||
|
||||
edit_category_title_go.setOnClickListener { doRenameCategory() }
|
||||
edit_category_title.setOnEditorActionListener { _, actionId, _ ->
|
||||
|
@ -126,9 +125,9 @@ class CategorySettingsFragment : Fragment() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun doDeleteCategory() {
|
||||
auth.tryDispatchParentAction(DeleteCategoryAction(
|
||||
categoryId = params.categoryId
|
||||
))
|
||||
private fun deleteCategory() {
|
||||
if (auth.requestAuthenticationOrReturnTrue()) {
|
||||
DeleteCategoryDialogFragment.newInstance(params).show(fragmentManager!!)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,73 @@
|
|||
package io.timelimit.android.ui.manage.category.settings
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.FragmentManager
|
||||
import androidx.lifecycle.LiveData
|
||||
import androidx.lifecycle.Observer
|
||||
import io.timelimit.android.R
|
||||
import io.timelimit.android.data.model.Category
|
||||
import io.timelimit.android.data.model.UserType
|
||||
import io.timelimit.android.extensions.showSafe
|
||||
import io.timelimit.android.logic.AppLogic
|
||||
import io.timelimit.android.logic.DefaultAppLogic
|
||||
import io.timelimit.android.sync.actions.DeleteCategoryAction
|
||||
import io.timelimit.android.ui.main.ActivityViewModel
|
||||
import io.timelimit.android.ui.main.getActivityViewModel
|
||||
import io.timelimit.android.ui.manage.category.ManageCategoryFragmentArgs
|
||||
import io.timelimit.android.ui.util.ConfirmDeleteDialogFragment
|
||||
|
||||
class DeleteCategoryDialogFragment: ConfirmDeleteDialogFragment() {
|
||||
companion object {
|
||||
private const val TAG = "DeleteCategoryDialogFragment"
|
||||
|
||||
fun newInstance(args: ManageCategoryFragmentArgs) = DeleteCategoryDialogFragment().apply {
|
||||
arguments = args.toBundle()
|
||||
}
|
||||
}
|
||||
|
||||
private val params: ManageCategoryFragmentArgs by lazy { ManageCategoryFragmentArgs.fromBundle(arguments!!) }
|
||||
private val appLogic: AppLogic by lazy { DefaultAppLogic.with(context!!) }
|
||||
private val auth: ActivityViewModel by lazy { getActivityViewModel(activity!!) }
|
||||
|
||||
val categoryEntry: LiveData<Category?> by lazy {
|
||||
appLogic.database.category().getCategoryByChildIdAndId(
|
||||
categoryId = params.categoryId,
|
||||
childId = params.childId
|
||||
)
|
||||
}
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
auth.authenticatedUser.observe(this, Observer {
|
||||
if (it?.second?.type != UserType.Parent) {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
})
|
||||
|
||||
categoryEntry.observe(this, Observer {
|
||||
if (it == null) {
|
||||
dismissAllowingStateLoss()
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
categoryEntry.observe(this, Observer {
|
||||
binding.text = getString(R.string.category_settings_delete_dialog, it?.title)
|
||||
})
|
||||
}
|
||||
|
||||
override fun onConfirmDeletion() {
|
||||
auth.tryDispatchParentAction(DeleteCategoryAction(
|
||||
categoryId = params.categoryId
|
||||
))
|
||||
|
||||
dismiss()
|
||||
}
|
||||
|
||||
fun show(fragmentManager: FragmentManager) = showSafe(fragmentManager, TAG)
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
package io.timelimit.android.ui.util
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
|
||||
import io.timelimit.android.databinding.ConfirmDeleteDialogBinding
|
||||
|
||||
abstract class ConfirmDeleteDialogFragment: BottomSheetDialogFragment(), ConfirmDeleteDialogFragmentHandlers {
|
||||
lateinit var binding: ConfirmDeleteDialogBinding
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
binding = ConfirmDeleteDialogBinding.inflate(inflater, container, false)
|
||||
|
||||
binding.handlers = this
|
||||
|
||||
return binding.root
|
||||
}
|
||||
|
||||
abstract override fun onConfirmDeletion()
|
||||
}
|
||||
|
||||
interface ConfirmDeleteDialogFragmentHandlers {
|
||||
fun onConfirmDeletion()
|
||||
}
|
38
app/src/main/res/layout/confirm_delete_dialog.xml
Normal file
38
app/src/main/res/layout/confirm_delete_dialog.xml
Normal file
|
@ -0,0 +1,38 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<layout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<data>
|
||||
<variable
|
||||
name="text"
|
||||
type="String" />
|
||||
|
||||
<variable
|
||||
name="handlers"
|
||||
type="io.timelimit.android.ui.util.ConfirmDeleteDialogFragmentHandlers" />
|
||||
</data>
|
||||
|
||||
<LinearLayout
|
||||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content">
|
||||
|
||||
<TextView
|
||||
android:gravity="center_horizontal"
|
||||
android:padding="8dp"
|
||||
android:textAppearance="?android:textAppearanceMedium"
|
||||
android:text="@{text}"
|
||||
tools:text="Are you sure that you want to delete?"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:onClick="@{() -> handlers.onConfirmDeletion()}"
|
||||
android:textColor="@color/red"
|
||||
android:background="?selectableItemBackground"
|
||||
android:layout_gravity="end"
|
||||
android:text="@string/generic_delete"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
</LinearLayout>
|
||||
</layout>
|
|
@ -112,14 +112,7 @@
|
|||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<CheckBox
|
||||
android:id="@+id/checkbox_delete_category"
|
||||
android:text="@string/category_settings_delete_checkbox"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content" />
|
||||
|
||||
<Button
|
||||
android:enabled="false"
|
||||
android:id="@+id/btn_delete_category"
|
||||
android:text="@string/category_settings_delete"
|
||||
android:layout_width="match_parent"
|
||||
|
|
|
@ -20,11 +20,12 @@
|
|||
<string name="category_settings_rename_empty">Der neue Name darf nicht leer sein</string>
|
||||
<string name="category_settings_rename_success">Der neue Name wurde gespeichert</string>
|
||||
<string name="category_settings_delete">Kategorie löschen</string>
|
||||
<string name="category_settings_delete_checkbox">Ich bin mir sicher, dass ich diese Kategorie löschen möchte</string>
|
||||
<string name="category_settings_extra_time_title">Extrazeit</string>
|
||||
<string name="category_settings_extra_time_info">
|
||||
Die Extrazeit ermöglicht (sofern nicht durch entsprechende Regeln eingschränkt) die Nutzung über die normale Nutzungsdauer hinaus. Sie wird erst nach dem Verbrauch der regulären Zeit verbraucht und verfällt sonst nicht.
|
||||
</string>
|
||||
<string name="category_settings_extra_time_change">Extrazeit ändern</string>
|
||||
<string name="category_settings_extra_time_change_toast">Die neue Extrazeit wurde gespeichert</string>
|
||||
|
||||
<string name="category_settings_delete_dialog">Möchten Sie die Kategorie %s löschen?</string>
|
||||
</resources>
|
||||
|
|
|
@ -20,7 +20,6 @@
|
|||
<string name="category_settings_rename_empty">The new name must not be empty</string>
|
||||
<string name="category_settings_rename_success">The new name was saved</string>
|
||||
<string name="category_settings_delete">Delete category</string>
|
||||
<string name="category_settings_delete_checkbox">I am sure that I want to delete this category</string>
|
||||
<string name="category_settings_extra_time_title">Extra time</string>
|
||||
<string name="category_settings_extra_time_info">
|
||||
The extra time allows (if not limited by rules) to use the category longer than usually.
|
||||
|
@ -28,4 +27,6 @@
|
|||
</string>
|
||||
<string name="category_settings_extra_time_change">Change extra time</string>
|
||||
<string name="category_settings_extra_time_change_toast">The new extra time was saved</string>
|
||||
|
||||
<string name="category_settings_delete_dialog">Do you want to delete the category %s?</string>
|
||||
</resources>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue