Popup menu on favourite tabs
parent
e497781359
commit
95a4bf41d2
@ -0,0 +1,9 @@
|
||||
package org.koitharu.kotatsu.ui.list.favourites
|
||||
|
||||
import android.view.View
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
|
||||
fun interface FavouritesTabLongClickListener {
|
||||
|
||||
fun onTabLongClick(tabView: View, category: FavouriteCategory): Boolean
|
||||
}
|
||||
@ -0,0 +1,61 @@
|
||||
package org.koitharu.kotatsu.ui.list.favourites.categories
|
||||
|
||||
import android.content.Context
|
||||
import android.text.InputType
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import org.koitharu.kotatsu.R
|
||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||
import org.koitharu.kotatsu.ui.base.dialog.TextInputDialog
|
||||
|
||||
class CategoriesEditDelegate(
|
||||
private val context: Context,
|
||||
private val callback: CategoriesEditCallback
|
||||
) {
|
||||
|
||||
fun deleteCategory(category: FavouriteCategory) {
|
||||
MaterialAlertDialogBuilder(context)
|
||||
.setMessage(context.getString(R.string.category_delete_confirm, category.title))
|
||||
.setTitle(R.string.remove_category)
|
||||
.setNegativeButton(android.R.string.cancel, null)
|
||||
.setPositiveButton(R.string.remove) { _, _ ->
|
||||
callback.onDeleteCategory(category)
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
fun renameCategory(category: FavouriteCategory) {
|
||||
TextInputDialog.Builder(context)
|
||||
.setTitle(R.string.rename)
|
||||
.setText(category.title)
|
||||
.setHint(R.string.enter_category_name)
|
||||
.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setMaxLength(12, false)
|
||||
.setPositiveButton(R.string.rename) { _, name ->
|
||||
callback.onRenameCategory(category, name)
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
fun createCategory() {
|
||||
TextInputDialog.Builder(context)
|
||||
.setTitle(R.string.add_new_category)
|
||||
.setHint(R.string.enter_category_name)
|
||||
.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME or InputType.TYPE_TEXT_FLAG_CAP_SENTENCES)
|
||||
.setNegativeButton(android.R.string.cancel)
|
||||
.setMaxLength(12, false)
|
||||
.setPositiveButton(R.string.add) { _, name ->
|
||||
callback.onCreateCategory(name)
|
||||
}.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
interface CategoriesEditCallback {
|
||||
|
||||
fun onDeleteCategory(category: FavouriteCategory)
|
||||
|
||||
fun onRenameCategory(category: FavouriteCategory, newName: String)
|
||||
|
||||
fun onCreateCategory(name: String)
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu
|
||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_create"
|
||||
android:title="@string/create_category" />
|
||||
|
||||
</menu>
|
||||
Loading…
Reference in New Issue