mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Remove BaseSelectionMenu
This commit is contained in:
@@ -66,8 +66,7 @@ class ListHabitsScreen
|
||||
private val confirmSyncKeyDialogFactory: ConfirmSyncKeyDialogFactory,
|
||||
private val colorPickerFactory: ColorPickerDialogFactory,
|
||||
private val numberPickerFactory: NumberPickerFactory,
|
||||
private val behavior: Lazy<ListHabitsBehavior>,
|
||||
private val selectionMenu: Lazy<ListHabitsSelectionMenu>
|
||||
private val behavior: Lazy<ListHabitsBehavior>
|
||||
) : BaseScreen(activity),
|
||||
CommandRunner.Listener,
|
||||
ListHabitsBehavior.Screen,
|
||||
@@ -79,7 +78,6 @@ class ListHabitsScreen
|
||||
}
|
||||
|
||||
fun onAttached() {
|
||||
setSelectionMenu(selectionMenu.get())
|
||||
commandRunner.addListener(this)
|
||||
if(activity.intent.action == "android.intent.action.VIEW") {
|
||||
val uri = activity.intent.data!!.toString()
|
||||
|
||||
@@ -20,6 +20,7 @@
|
||||
package org.isoron.uhabits.activities.habits.list
|
||||
|
||||
import android.view.*
|
||||
import androidx.appcompat.view.ActionMode
|
||||
import dagger.*
|
||||
import org.isoron.androidbase.activities.*
|
||||
import org.isoron.uhabits.*
|
||||
@@ -33,21 +34,55 @@ import javax.inject.*
|
||||
|
||||
@ActivityScope
|
||||
class ListHabitsSelectionMenu @Inject constructor(
|
||||
private val screen: ListHabitsScreen,
|
||||
private val activity: BaseActivity,
|
||||
private val listAdapter: HabitCardListAdapter,
|
||||
var commandRunner: CommandRunner,
|
||||
private val prefs: Preferences,
|
||||
private val behavior: ListHabitsSelectionMenuBehavior,
|
||||
private val listController: Lazy<HabitCardListController>,
|
||||
private val notificationTray: NotificationTray
|
||||
) : BaseSelectionMenu() {
|
||||
) : ActionMode.Callback {
|
||||
|
||||
override fun onFinish() {
|
||||
listController.get().onSelectionFinished()
|
||||
super.onFinish()
|
||||
var activeActionMode: ActionMode? = null
|
||||
|
||||
fun onSelectionStart() {
|
||||
activity.startSupportActionMode(this)
|
||||
}
|
||||
|
||||
override fun onItemClicked(item: MenuItem): Boolean {
|
||||
fun onSelectionChange() {
|
||||
activeActionMode?.invalidate()
|
||||
}
|
||||
|
||||
fun onSelectionFinish() {
|
||||
activeActionMode?.finish()
|
||||
}
|
||||
|
||||
override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
activeActionMode = mode
|
||||
activity.menuInflater.inflate(R.menu.list_habits_selection, menu)
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean {
|
||||
val itemEdit = menu.findItem(R.id.action_edit_habit)
|
||||
val itemColor = menu.findItem(R.id.action_color)
|
||||
val itemArchive = menu.findItem(R.id.action_archive_habit)
|
||||
val itemUnarchive = menu.findItem(R.id.action_unarchive_habit)
|
||||
val itemNotify = menu.findItem(R.id.action_notify)
|
||||
|
||||
itemColor.isVisible = true
|
||||
itemEdit.isVisible = behavior.canEdit()
|
||||
itemArchive.isVisible = behavior.canArchive()
|
||||
itemUnarchive.isVisible = behavior.canUnarchive()
|
||||
itemNotify.isVisible = prefs.isDeveloper
|
||||
activeActionMode?.title = listAdapter.selected.size.toString()
|
||||
return true
|
||||
}
|
||||
override fun onDestroyActionMode(mode: ActionMode?) {
|
||||
listController.get().onSelectionFinished()
|
||||
}
|
||||
|
||||
override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean {
|
||||
when (item.itemId) {
|
||||
R.id.action_edit_habit -> {
|
||||
behavior.onEditHabits()
|
||||
@@ -75,7 +110,7 @@ class ListHabitsSelectionMenu @Inject constructor(
|
||||
}
|
||||
|
||||
R.id.action_notify -> {
|
||||
for(h in listAdapter.selected)
|
||||
for (h in listAdapter.selected)
|
||||
notificationTray.show(h, DateUtils.getToday(), 0)
|
||||
return true
|
||||
}
|
||||
@@ -83,26 +118,4 @@ class ListHabitsSelectionMenu @Inject constructor(
|
||||
else -> return false
|
||||
}
|
||||
}
|
||||
|
||||
override fun onPrepare(menu: Menu): Boolean {
|
||||
val itemEdit = menu.findItem(R.id.action_edit_habit)
|
||||
val itemColor = menu.findItem(R.id.action_color)
|
||||
val itemArchive = menu.findItem(R.id.action_archive_habit)
|
||||
val itemUnarchive = menu.findItem(R.id.action_unarchive_habit)
|
||||
val itemNotify = menu.findItem(R.id.action_notify)
|
||||
|
||||
itemColor.isVisible = true
|
||||
itemEdit.isVisible = behavior.canEdit()
|
||||
itemArchive.isVisible = behavior.canArchive()
|
||||
itemUnarchive.isVisible = behavior.canUnarchive()
|
||||
setTitle(Integer.toString(listAdapter.selected.size))
|
||||
itemNotify.isVisible = prefs.isDeveloper
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
fun onSelectionStart() = screen.startSelection()
|
||||
fun onSelectionChange() = invalidate()
|
||||
fun onSelectionFinish() = finish()
|
||||
override fun getResourceId() = R.menu.list_habits_selection
|
||||
}
|
||||
|
||||
@@ -25,8 +25,9 @@
|
||||
<item name="android:navigationBarColor">?attr/colorPrimary</item>
|
||||
<item name="android:itemBackground">?attr/highContrastReverseTextColor</item>
|
||||
|
||||
|
||||
<item name="windowActionModeOverlay">true</item>
|
||||
<item name="actionModeBackground">@color/blue_grey_700</item>
|
||||
<item name="actionModeBackground">@color/grey_700</item>
|
||||
<item name="actionBarPopupTheme">@style/ThemeOverlay.AppCompat.Light</item>
|
||||
|
||||
<item name="selectedBackground">@drawable/selected_box_light</item>
|
||||
|
||||
Reference in New Issue
Block a user