mirror of
https://github.com/iSoron/uhabits.git
synced 2025-12-06 09:08:52 -06:00
Konvert BaseSelectionMenu
Co-authored-by: Alinson S. Xavier <git@axavier.org>
This commit is contained in:
@@ -16,50 +16,43 @@
|
|||||||
* You should have received a copy of the GNU General Public License along
|
* You should have received a copy of the GNU General Public License along
|
||||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
package org.isoron.androidbase.activities
|
||||||
|
|
||||||
package org.isoron.androidbase.activities;
|
import android.view.*
|
||||||
|
import androidx.appcompat.view.ActionMode
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.view.ActionMode;
|
|
||||||
import android.view.*;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Base class for all the selection menus in the application.
|
* Base class for all the selection menus in the application.
|
||||||
* <p>
|
*
|
||||||
* A selection menu is a menu that appears when the screen starts a selection
|
* A selection menu is a menu that appears when the screen starts a selection
|
||||||
* operation. It contains actions that modify the selected items, such as delete
|
* operation. It contains actions that modify the selected items, such as delete
|
||||||
* or archive. Since it replaces the toolbar, it also has a title.
|
* or archive. Since it replaces the toolbar, it also has a title.
|
||||||
* <p>
|
*
|
||||||
* This class hides many implementation details of creating such menus in
|
* This class hides many implementation details of creating such menus in
|
||||||
* Android. The interface is supposed to look very similar to {@link BaseMenu},
|
* Android. The interface is supposed to look very similar to [BaseMenu],
|
||||||
* with a few additional methods, such as finishing the selection operation.
|
* with a few additional methods, such as finishing the selection operation.
|
||||||
* Internally, it uses an {@link ActionMode}.
|
* Internally, it uses an [ActionMode].
|
||||||
*/
|
*/
|
||||||
public abstract class BaseSelectionMenu
|
abstract class BaseSelectionMenu {
|
||||||
{
|
private var actionMode: ActionMode? = null
|
||||||
@Nullable
|
|
||||||
private ActionMode actionMode;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finishes the selection operation.
|
* Finishes the selection operation.
|
||||||
*/
|
*/
|
||||||
public void finish()
|
fun finish() {
|
||||||
{
|
actionMode?.finish()
|
||||||
if (actionMode != null) actionMode.finish();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Declare that the menu has changed, and should be recreated.
|
* Declare that the menu has changed, and should be recreated.
|
||||||
*/
|
*/
|
||||||
public void invalidate()
|
fun invalidate() {
|
||||||
{
|
actionMode?.invalidate()
|
||||||
if (actionMode != null) actionMode.invalidate();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the menu is first displayed.
|
* Called when the menu is first displayed.
|
||||||
* <p>
|
*
|
||||||
* This method should not be overridden. The application should override
|
* This method should not be overridden. The application should override
|
||||||
* the methods onCreate(Menu) and getMenuResourceId instead.
|
* the methods onCreate(Menu) and getMenuResourceId instead.
|
||||||
*
|
*
|
||||||
@@ -67,22 +60,16 @@ public abstract class BaseSelectionMenu
|
|||||||
* @param mode the action mode associated with this menu.
|
* @param mode the action mode associated with this menu.
|
||||||
* @param menu the menu that is being created.
|
* @param menu the menu that is being created.
|
||||||
*/
|
*/
|
||||||
public void onCreate(@NonNull MenuInflater inflater,
|
fun onCreate(inflater: MenuInflater, mode: ActionMode, menu: Menu) {
|
||||||
@NonNull ActionMode mode,
|
actionMode = mode
|
||||||
@NonNull Menu menu)
|
inflater.inflate(getResourceId(), menu)
|
||||||
{
|
onCreate(menu)
|
||||||
this.actionMode = mode;
|
|
||||||
inflater.inflate(getResourceId(), menu);
|
|
||||||
onCreate(menu);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the selection operation is about to finish.
|
* Called when the selection operation is about to finish.
|
||||||
*/
|
*/
|
||||||
public void onFinish()
|
open fun onFinish() {}
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever an item on the menu is selected.
|
* Called whenever an item on the menu is selected.
|
||||||
@@ -90,11 +77,7 @@ public abstract class BaseSelectionMenu
|
|||||||
* @param item the item that was selected.
|
* @param item the item that was selected.
|
||||||
* @return true if the event was consumed, or false otherwise
|
* @return true if the event was consumed, or false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean onItemClicked(@NonNull MenuItem item)
|
open fun onItemClicked(item: MenuItem): Boolean = false
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called whenever the menu is invalidated.
|
* Called whenever the menu is invalidated.
|
||||||
@@ -102,29 +85,23 @@ public abstract class BaseSelectionMenu
|
|||||||
* @param menu the menu to be refreshed
|
* @param menu the menu to be refreshed
|
||||||
* @return true if the menu has changes, false otherwise
|
* @return true if the menu has changes, false otherwise
|
||||||
*/
|
*/
|
||||||
public boolean onPrepare(@NonNull Menu menu)
|
open fun onPrepare(menu: Menu): Boolean = false
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets the title of the selection menu.
|
* Sets the title of the selection menu.
|
||||||
*
|
*
|
||||||
* @param title the new title.
|
* @param title the new title.
|
||||||
*/
|
*/
|
||||||
public void setTitle(String title)
|
fun setTitle(title: String?) {
|
||||||
{
|
actionMode?.title = title
|
||||||
if (actionMode != null) actionMode.setTitle(title);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract int getResourceId();
|
protected abstract fun getResourceId(): Int
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Called when the menu is first created.
|
* Called when the menu is first created.
|
||||||
*
|
*
|
||||||
* @param menu the menu being created
|
* @param menu the menu being created
|
||||||
*/
|
*/
|
||||||
protected void onCreate(@NonNull Menu menu)
|
protected fun onCreate(menu: Menu) {}
|
||||||
{
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user