Konvert BaseMenu

Co-authored-by: Alinson S. Xavier <git@axavier.org>
pull/610/head
olegivo 5 years ago committed by Alinson S. Xavier
parent 978946baab
commit b76882dd1d

@ -16,71 +16,50 @@
* You should have received a copy of the GNU General Public License along
* 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.annotation.MenuRes;
import androidx.annotation.NonNull;
import android.view.*
import androidx.annotation.*
/**
* Base class for all the menus in the application.
* <p>
*
* This class receives from BaseActivity all callbacks related to menus, such as
* menu creation and click events. It also handles some implementation details
* of creating menus in Android, such as inflating the resources.
*/
public abstract class BaseMenu
{
@NonNull
private final BaseActivity activity;
public BaseMenu(@NonNull BaseActivity activity)
{
this.activity = activity;
}
@NonNull
public BaseActivity getActivity()
{
return activity;
}
abstract class BaseMenu(private val activity: BaseActivity) {
/**
* Declare that the menu has changed, and should be recreated.
*/
public void invalidate()
{
activity.invalidateOptionsMenu();
fun invalidate() {
activity.invalidateOptionsMenu()
}
/**
* Called when the menu is first displayed.
* <p>
*
* The given menu is already inflated and ready to receive items. The
* application should override this method and add items to the menu here.
*
* @param menu the menu that is being created.
*/
public void onCreate(@NonNull Menu menu)
{
}
open fun onCreate(menu: Menu) {}
/**
* Called when the menu is first displayed.
* <p>
*
* This method should not be overridden. The application should override
* the methods onCreate(Menu) and getMenuResourceId instead.
*
* @param inflater a menu inflater, for creating the menu
* @param menu the menu that is being created.
*/
public void onCreate(@NonNull MenuInflater inflater, @NonNull Menu menu)
{
menu.clear();
inflater.inflate(getMenuResourceId(), menu);
onCreate(menu);
fun onCreate(inflater: MenuInflater, menu: Menu) {
menu.clear()
inflater.inflate(getMenuResourceId(), menu)
onCreate(menu)
}
/**
@ -89,10 +68,7 @@ public abstract class BaseMenu
* @param item the item that was selected.
* @return true if the event was consumed, or false otherwise
*/
public boolean onItemSelected(@NonNull MenuItem item)
{
return false;
}
open fun onItemSelected(item: MenuItem): Boolean = false
/**
* Returns the id of the resource that should be used to inflate this menu.
@ -100,5 +76,6 @@ public abstract class BaseMenu
* @return id of the menu resource.
*/
@MenuRes
protected abstract int getMenuResourceId();
protected abstract fun getMenuResourceId(): Int
}
Loading…
Cancel
Save