Selection and reodering favourites categories
parent
451b9fc0f1
commit
80db7f0b74
@ -1,178 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui
|
|
||||||
|
|
||||||
import android.os.Bundle
|
|
||||||
import android.view.LayoutInflater
|
|
||||||
import android.view.View
|
|
||||||
import android.view.ViewGroup
|
|
||||||
import androidx.appcompat.view.ActionMode
|
|
||||||
import androidx.appcompat.widget.PopupMenu
|
|
||||||
import androidx.core.graphics.Insets
|
|
||||||
import androidx.core.view.children
|
|
||||||
import androidx.core.view.isVisible
|
|
||||||
import androidx.core.view.updatePadding
|
|
||||||
import com.google.android.material.snackbar.Snackbar
|
|
||||||
import com.google.android.material.tabs.TabLayout
|
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
|
||||||
import org.koin.androidx.viewmodel.ext.android.viewModel
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.base.ui.BaseFragment
|
|
||||||
import org.koitharu.kotatsu.base.ui.util.ActionModeListener
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import org.koitharu.kotatsu.databinding.FragmentFavouritesBinding
|
|
||||||
import org.koitharu.kotatsu.databinding.ItemEmptyStateBinding
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.CategoriesEditDelegate
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.FavouritesCategoriesViewModel
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoryListModel
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity
|
|
||||||
import org.koitharu.kotatsu.utils.ext.addMenuProvider
|
|
||||||
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
|
|
||||||
|
|
||||||
class FavouritesContainerFragment :
|
|
||||||
BaseFragment<FragmentFavouritesBinding>(),
|
|
||||||
FavouritesTabLongClickListener,
|
|
||||||
CategoriesEditDelegate.CategoriesEditCallback,
|
|
||||||
ActionModeListener,
|
|
||||||
View.OnClickListener {
|
|
||||||
|
|
||||||
private val viewModel by viewModel<FavouritesCategoriesViewModel>()
|
|
||||||
private val editDelegate by lazy(LazyThreadSafetyMode.NONE) {
|
|
||||||
CategoriesEditDelegate(requireContext(), this)
|
|
||||||
}
|
|
||||||
private var pagerAdapter: FavouritesPagerAdapter? = null
|
|
||||||
private var stubBinding: ItemEmptyStateBinding? = null
|
|
||||||
|
|
||||||
override fun onInflateView(
|
|
||||||
inflater: LayoutInflater,
|
|
||||||
container: ViewGroup?
|
|
||||||
) = FragmentFavouritesBinding.inflate(inflater, container, false)
|
|
||||||
|
|
||||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
|
||||||
super.onViewCreated(view, savedInstanceState)
|
|
||||||
val adapter = FavouritesPagerAdapter(this, this)
|
|
||||||
viewModel.allCategories.value?.let(::onCategoriesChanged)
|
|
||||||
binding.pager.adapter = adapter
|
|
||||||
pagerAdapter = adapter
|
|
||||||
TabLayoutMediator(binding.tabs, binding.pager, adapter).attach()
|
|
||||||
actionModeDelegate.addListener(this, viewLifecycleOwner)
|
|
||||||
addMenuProvider(FavouritesContainerMenuProvider(view.context))
|
|
||||||
|
|
||||||
viewModel.allCategories.observe(viewLifecycleOwner, ::onCategoriesChanged)
|
|
||||||
viewModel.onError.observe(viewLifecycleOwner, ::onError)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDestroyView() {
|
|
||||||
pagerAdapter = null
|
|
||||||
stubBinding = null
|
|
||||||
super.onDestroyView()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActionModeStarted(mode: ActionMode) {
|
|
||||||
binding.pager.isUserInputEnabled = false
|
|
||||||
binding.tabs.setTabsEnabled(false)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onActionModeFinished(mode: ActionMode) {
|
|
||||||
binding.pager.isUserInputEnabled = true
|
|
||||||
binding.tabs.setTabsEnabled(true)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onWindowInsetsChanged(insets: Insets) {
|
|
||||||
binding.tabs.apply {
|
|
||||||
updatePadding(
|
|
||||||
left = insets.left,
|
|
||||||
right = insets.right
|
|
||||||
)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onCategoriesChanged(categories: List<CategoryListModel>) {
|
|
||||||
pagerAdapter?.replaceData(categories)
|
|
||||||
if (categories.isEmpty()) {
|
|
||||||
binding.pager.isVisible = false
|
|
||||||
binding.tabs.isVisible = false
|
|
||||||
showStub()
|
|
||||||
} else {
|
|
||||||
binding.pager.isVisible = true
|
|
||||||
binding.tabs.isVisible = true
|
|
||||||
(stubBinding?.root ?: binding.stubEmptyState).isVisible = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun onError(e: Throwable) {
|
|
||||||
Snackbar.make(binding.pager, e.getDisplayMessage(resources), Snackbar.LENGTH_LONG).show()
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onTabLongClick(tabView: View, item: CategoryListModel): Boolean {
|
|
||||||
/*when (item) {
|
|
||||||
is CategoryListModel.All -> showAllCategoriesMenu(tabView)
|
|
||||||
is CategoryListModel.CategoryItem -> showCategoryMenu(tabView, item.category)
|
|
||||||
}*/
|
|
||||||
return true
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onClick(v: View) {
|
|
||||||
when (v.id) {
|
|
||||||
R.id.button_retry -> startActivity(FavouritesCategoryEditActivity.newIntent(v.context))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onDeleteCategory(category: FavouriteCategory) {
|
|
||||||
viewModel.deleteCategory(category.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun TabLayout.setTabsEnabled(enabled: Boolean) {
|
|
||||||
val tabStrip = getChildAt(0) as? ViewGroup ?: return
|
|
||||||
for (tab in tabStrip.children) {
|
|
||||||
tab.isEnabled = enabled
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showCategoryMenu(tabView: View, category: FavouriteCategory) {
|
|
||||||
val menu = PopupMenu(tabView.context, tabView)
|
|
||||||
menu.inflate(R.menu.popup_category)
|
|
||||||
menu.setOnMenuItemClickListener {
|
|
||||||
when (it.itemId) {
|
|
||||||
R.id.action_remove -> editDelegate.deleteCategory(category)
|
|
||||||
R.id.action_edit -> startActivity(
|
|
||||||
FavouritesCategoryEditActivity.newIntent(
|
|
||||||
tabView.context,
|
|
||||||
category.id
|
|
||||||
)
|
|
||||||
)
|
|
||||||
else -> return@setOnMenuItemClickListener false
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
menu.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showAllCategoriesMenu(tabView: View) {
|
|
||||||
val menu = PopupMenu(tabView.context, tabView)
|
|
||||||
menu.inflate(R.menu.popup_category_all)
|
|
||||||
menu.setOnMenuItemClickListener {
|
|
||||||
when (it.itemId) {
|
|
||||||
R.id.action_create -> startActivity(FavouritesCategoryEditActivity.newIntent(requireContext()))
|
|
||||||
R.id.action_hide -> viewModel.setAllCategoriesVisible(false)
|
|
||||||
}
|
|
||||||
true
|
|
||||||
}
|
|
||||||
menu.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
private fun showStub() {
|
|
||||||
val stub = stubBinding ?: ItemEmptyStateBinding.bind(binding.stubEmptyState.inflate())
|
|
||||||
stub.root.isVisible = true
|
|
||||||
stub.icon.setImageResource(R.drawable.ic_heart_outline)
|
|
||||||
stub.textPrimary.setText(R.string.text_empty_holder_primary)
|
|
||||||
stub.textSecondary.setText(R.string.empty_favourite_categories)
|
|
||||||
stub.buttonRetry.setText(R.string.add)
|
|
||||||
stub.buttonRetry.isVisible = true
|
|
||||||
stub.buttonRetry.setOnClickListener(this)
|
|
||||||
stubBinding = stub
|
|
||||||
}
|
|
||||||
|
|
||||||
companion object {
|
|
||||||
|
|
||||||
fun newInstance() = FavouritesContainerFragment()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,28 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import android.view.Menu
|
|
||||||
import android.view.MenuInflater
|
|
||||||
import android.view.MenuItem
|
|
||||||
import androidx.core.view.MenuProvider
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.FavouriteCategoriesActivity
|
|
||||||
|
|
||||||
class FavouritesContainerMenuProvider(
|
|
||||||
private val context: Context,
|
|
||||||
) : MenuProvider {
|
|
||||||
|
|
||||||
override fun onCreateMenu(menu: Menu, menuInflater: MenuInflater) {
|
|
||||||
menuInflater.inflate(R.menu.opt_favourites, menu)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
|
|
||||||
return when (menuItem.itemId) {
|
|
||||||
R.id.action_categories -> {
|
|
||||||
context.startActivity(FavouriteCategoriesActivity.newIntent(context))
|
|
||||||
true
|
|
||||||
}
|
|
||||||
else -> false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,70 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui
|
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
|
||||||
import android.view.View
|
|
||||||
import androidx.fragment.app.Fragment
|
|
||||||
import androidx.recyclerview.widget.AsyncListDiffer
|
|
||||||
import androidx.recyclerview.widget.DiffUtil
|
|
||||||
import androidx.viewpager2.adapter.FragmentStateAdapter
|
|
||||||
import com.google.android.material.tabs.TabLayout
|
|
||||||
import com.google.android.material.tabs.TabLayoutMediator
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoryListModel
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.list.FavouritesListFragment
|
|
||||||
|
|
||||||
class FavouritesPagerAdapter(
|
|
||||||
fragment: Fragment,
|
|
||||||
private val longClickListener: FavouritesTabLongClickListener
|
|
||||||
) : FragmentStateAdapter(fragment.childFragmentManager, fragment.viewLifecycleOwner.lifecycle),
|
|
||||||
TabLayoutMediator.TabConfigurationStrategy,
|
|
||||||
View.OnLongClickListener {
|
|
||||||
|
|
||||||
private val differ = AsyncListDiffer(this, DiffCallback())
|
|
||||||
|
|
||||||
override fun getItemCount() = differ.currentList.size
|
|
||||||
|
|
||||||
override fun createFragment(position: Int): Fragment {
|
|
||||||
val item = differ.currentList[position]
|
|
||||||
return FavouritesListFragment.newInstance(item.category.id)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun getItemId(position: Int): Long {
|
|
||||||
return differ.currentList[position].category.id
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun containsItem(itemId: Long): Boolean {
|
|
||||||
return differ.currentList.any { it.category.id == itemId }
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onConfigureTab(tab: TabLayout.Tab, position: Int) {
|
|
||||||
val item = differ.currentList[position]
|
|
||||||
tab.text = item.category.title
|
|
||||||
tab.view.tag = item.category.id
|
|
||||||
tab.view.setOnLongClickListener(this)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun replaceData(data: List<CategoryListModel>) {
|
|
||||||
differ.submitList(data)
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun onLongClick(v: View): Boolean {
|
|
||||||
val itemId = v.tag as? Long ?: return false
|
|
||||||
val item = differ.currentList.find { x -> x.category.id == itemId } ?: return false
|
|
||||||
return longClickListener.onTabLongClick(v, item)
|
|
||||||
}
|
|
||||||
|
|
||||||
private class DiffCallback : DiffUtil.ItemCallback<CategoryListModel>() {
|
|
||||||
|
|
||||||
override fun areItemsTheSame(
|
|
||||||
oldItem: CategoryListModel,
|
|
||||||
newItem: CategoryListModel
|
|
||||||
): Boolean {
|
|
||||||
return oldItem.category.id == newItem.category.id
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("DiffUtilEquals")
|
|
||||||
override fun areContentsTheSame(
|
|
||||||
oldItem: CategoryListModel,
|
|
||||||
newItem: CategoryListModel
|
|
||||||
): Boolean = oldItem == newItem
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -1,9 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui
|
|
||||||
|
|
||||||
import android.view.View
|
|
||||||
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoryListModel
|
|
||||||
|
|
||||||
fun interface FavouritesTabLongClickListener {
|
|
||||||
|
|
||||||
fun onTabLongClick(tabView: View, item: CategoryListModel): Boolean
|
|
||||||
}
|
|
||||||
@ -1,30 +0,0 @@
|
|||||||
package org.koitharu.kotatsu.favourites.ui.categories
|
|
||||||
|
|
||||||
import android.content.Context
|
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
|
||||||
import org.koitharu.kotatsu.R
|
|
||||||
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
|
||||||
import com.google.android.material.R as materialR
|
|
||||||
|
|
||||||
class CategoriesEditDelegate(
|
|
||||||
private val context: Context,
|
|
||||||
private val callback: CategoriesEditCallback
|
|
||||||
) {
|
|
||||||
|
|
||||||
fun deleteCategory(category: FavouriteCategory) {
|
|
||||||
MaterialAlertDialogBuilder(context, materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
|
|
||||||
.setMessage(context.getString(R.string.category_delete_confirm, category.title))
|
|
||||||
.setTitle(R.string.remove_category)
|
|
||||||
.setIcon(R.drawable.ic_delete)
|
|
||||||
.setNegativeButton(android.R.string.cancel, null)
|
|
||||||
.setPositiveButton(R.string.remove) { _, _ ->
|
|
||||||
callback.onDeleteCategory(category)
|
|
||||||
}.create()
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CategoriesEditCallback {
|
|
||||||
|
|
||||||
fun onDeleteCategory(category: FavouriteCategory)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@ -0,0 +1,64 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
|
import android.view.Menu
|
||||||
|
import android.view.MenuItem
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.ListSelectionController
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.categories.edit.FavouritesCategoryEditActivity
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
class CategoriesSelectionCallback(
|
||||||
|
private val recyclerView: RecyclerView,
|
||||||
|
private val viewModel: FavouritesCategoriesViewModel,
|
||||||
|
) : ListSelectionController.Callback2 {
|
||||||
|
|
||||||
|
override fun onSelectionChanged(controller: ListSelectionController, count: Int) {
|
||||||
|
recyclerView.invalidateItemDecorations()
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onCreateActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
mode.menuInflater.inflate(R.menu.mode_category, menu)
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onPrepareActionMode(controller: ListSelectionController, mode: ActionMode, menu: Menu): Boolean {
|
||||||
|
val isOneItem = controller.count == 1
|
||||||
|
menu.findItem(R.id.action_edit)?.isVisible = isOneItem
|
||||||
|
mode.title = controller.count.toString()
|
||||||
|
return true
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onActionItemClicked(controller: ListSelectionController, mode: ActionMode, item: MenuItem): Boolean {
|
||||||
|
return when (item.itemId) {
|
||||||
|
R.id.action_edit -> {
|
||||||
|
val id = controller.peekCheckedIds().singleOrNull() ?: return false
|
||||||
|
val context = recyclerView.context
|
||||||
|
val intent = FavouritesCategoryEditActivity.newIntent(context, id)
|
||||||
|
context.startActivity(intent)
|
||||||
|
mode.finish()
|
||||||
|
true
|
||||||
|
}
|
||||||
|
R.id.action_remove -> {
|
||||||
|
confirmDeleteCategories(controller.snapshot(), mode)
|
||||||
|
true
|
||||||
|
}
|
||||||
|
else -> false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private fun confirmDeleteCategories(ids: Set<Long>, mode: ActionMode) {
|
||||||
|
val context = recyclerView.context
|
||||||
|
MaterialAlertDialogBuilder(context, materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered)
|
||||||
|
.setMessage(R.string.categories_delete_confirm)
|
||||||
|
.setTitle(R.string.remove_category)
|
||||||
|
.setIcon(R.drawable.ic_delete)
|
||||||
|
.setNegativeButton(android.R.string.cancel, null)
|
||||||
|
.setPositiveButton(R.string.remove) { _, _ ->
|
||||||
|
viewModel.deleteCategories(ids)
|
||||||
|
mode.finish()
|
||||||
|
}.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
|
import android.content.Context
|
||||||
|
import android.graphics.Canvas
|
||||||
|
import android.graphics.Color
|
||||||
|
import android.graphics.Paint
|
||||||
|
import android.graphics.RectF
|
||||||
|
import android.view.View
|
||||||
|
import androidx.core.graphics.ColorUtils
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.R
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.decor.AbstractSelectionItemDecoration
|
||||||
|
import org.koitharu.kotatsu.favourites.ui.categories.adapter.CategoryListModel
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getItem
|
||||||
|
import org.koitharu.kotatsu.utils.ext.getThemeColor
|
||||||
|
import com.google.android.material.R as materialR
|
||||||
|
|
||||||
|
class CategoriesSelectionDecoration(context: Context) : AbstractSelectionItemDecoration() {
|
||||||
|
|
||||||
|
private val paint = Paint(Paint.ANTI_ALIAS_FLAG)
|
||||||
|
private val radius = context.resources.getDimension(R.dimen.list_selector_corner)
|
||||||
|
private val strokeColor = context.getThemeColor(materialR.attr.colorPrimary, Color.RED)
|
||||||
|
private val fillColor = ColorUtils.setAlphaComponent(
|
||||||
|
ColorUtils.blendARGB(strokeColor, context.getThemeColor(materialR.attr.colorSurface), 0.8f),
|
||||||
|
0x74
|
||||||
|
)
|
||||||
|
private val padding = context.resources.getDimension(R.dimen.grid_spacing_outer)
|
||||||
|
|
||||||
|
init {
|
||||||
|
paint.strokeWidth = context.resources.getDimension(R.dimen.selection_stroke_width)
|
||||||
|
hasForeground = true
|
||||||
|
hasBackground = false
|
||||||
|
isIncludeDecorAndMargins = false
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun getItemId(parent: RecyclerView, child: View): Long {
|
||||||
|
val holder = parent.getChildViewHolder(child) ?: return RecyclerView.NO_ID
|
||||||
|
val item = holder.getItem(CategoryListModel::class.java) ?: return RecyclerView.NO_ID
|
||||||
|
return item.category.id
|
||||||
|
}
|
||||||
|
|
||||||
|
override fun onDrawForeground(
|
||||||
|
canvas: Canvas,
|
||||||
|
parent: RecyclerView,
|
||||||
|
child: View,
|
||||||
|
bounds: RectF,
|
||||||
|
state: RecyclerView.State,
|
||||||
|
) {
|
||||||
|
bounds.inset(padding, padding)
|
||||||
|
paint.color = fillColor
|
||||||
|
paint.style = Paint.Style.FILL
|
||||||
|
canvas.drawRoundRect(bounds, radius, radius, paint)
|
||||||
|
paint.color = strokeColor
|
||||||
|
paint.style = Paint.Style.STROKE
|
||||||
|
canvas.drawRoundRect(bounds, radius, radius, paint)
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,10 @@
|
|||||||
|
package org.koitharu.kotatsu.favourites.ui.categories
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
|
import org.koitharu.kotatsu.base.ui.list.OnListItemClickListener
|
||||||
|
import org.koitharu.kotatsu.core.model.FavouriteCategory
|
||||||
|
|
||||||
|
interface FavouriteCategoriesListListener : OnListItemClickListener<FavouriteCategory> {
|
||||||
|
|
||||||
|
fun onDragHandleTouch(holder: RecyclerView.ViewHolder): Boolean
|
||||||
|
}
|
||||||
@ -0,0 +1,13 @@
|
|||||||
|
package org.koitharu.kotatsu.utils.ext
|
||||||
|
|
||||||
|
import android.graphics.Rect
|
||||||
|
import kotlin.math.roundToInt
|
||||||
|
|
||||||
|
fun Rect.scale(factor: Double) {
|
||||||
|
val newWidth = (width() * factor).roundToInt()
|
||||||
|
val newHeight = (height() * factor).roundToInt()
|
||||||
|
inset(
|
||||||
|
(width() - newWidth) / 2,
|
||||||
|
(height() - newHeight) / 2,
|
||||||
|
)
|
||||||
|
}
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?attr/colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#000"
|
||||||
|
android:pathData="M20.71,7.04C21.1,6.65 21.1,6 20.71,5.63L18.37,3.29C18,2.9 17.35,2.9 16.96,3.29L15.12,5.12L18.87,8.87M3,17.25V21H6.75L17.81,9.93L14.06,6.18L3,17.25Z" />
|
||||||
|
</vector>
|
||||||
@ -0,0 +1,12 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<vector
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="24dp"
|
||||||
|
android:height="24dp"
|
||||||
|
android:tint="?colorControlNormal"
|
||||||
|
android:viewportWidth="24"
|
||||||
|
android:viewportHeight="24">
|
||||||
|
<path
|
||||||
|
android:fillColor="#000"
|
||||||
|
android:pathData="M9,3L5,7H8V14H10V7H13M16,17V10H14V17H11L15,21L19,17H16Z" />
|
||||||
|
</vector>
|
||||||
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<menu
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_edit"
|
||||||
|
android:icon="@drawable/ic_edit"
|
||||||
|
android:title="@string/edit"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@+id/action_remove"
|
||||||
|
android:icon="@drawable/ic_delete"
|
||||||
|
android:title="@string/remove"
|
||||||
|
app:showAsAction="ifRoom" />
|
||||||
|
|
||||||
|
</menu>
|
||||||
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_remove"
|
|
||||||
android:title="@string/remove" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_edit"
|
|
||||||
android:title="@string/edit" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
@ -1,13 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
|
||||||
<menu
|
|
||||||
xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_hide"
|
|
||||||
android:title="@string/hide" />
|
|
||||||
|
|
||||||
<item
|
|
||||||
android:id="@+id/action_create"
|
|
||||||
android:title="@string/create_category" />
|
|
||||||
|
|
||||||
</menu>
|
|
||||||
Loading…
Reference in New Issue