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 * 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.annotation.*
import android.view.*;
import androidx.annotation.MenuRes;
import androidx.annotation.NonNull;
/** /**
* Base class for all the menus in the application. * Base class for all the menus in the application.
* <p> *
* This class receives from BaseActivity all callbacks related to menus, such as * This class receives from BaseActivity all callbacks related to menus, such as
* menu creation and click events. It also handles some implementation details * menu creation and click events. It also handles some implementation details
* of creating menus in Android, such as inflating the resources. * of creating menus in Android, such as inflating the resources.
*/ */
public abstract class BaseMenu abstract class BaseMenu(private val activity: BaseActivity) {
{
@NonNull
private final BaseActivity activity;
public BaseMenu(@NonNull BaseActivity activity)
{
this.activity = activity;
}
@NonNull
public BaseActivity getActivity()
{
return activity;
}
/** /**
* 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() {
{ activity.invalidateOptionsMenu()
activity.invalidateOptionsMenu();
} }
/** /**
* Called when the menu is first displayed. * Called when the menu is first displayed.
* <p> *
* The given menu is already inflated and ready to receive items. The * The given menu is already inflated and ready to receive items. The
* application should override this method and add items to the menu here. * application should override this method and add items to the menu here.
* *
* @param menu the menu that is being created. * @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. * 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.
* *
* @param inflater a menu inflater, for creating the menu * @param inflater a menu inflater, for creating the menu
* @param menu the menu that is being created. * @param menu the menu that is being created.
*/ */
public void onCreate(@NonNull MenuInflater inflater, @NonNull Menu menu) fun onCreate(inflater: MenuInflater, menu: Menu) {
{ menu.clear()
menu.clear(); inflater.inflate(getMenuResourceId(), menu)
inflater.inflate(getMenuResourceId(), menu); onCreate(menu)
onCreate(menu);
} }
/** /**
@ -89,10 +68,7 @@ public abstract class BaseMenu
* @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 onItemSelected(@NonNull MenuItem item) open fun onItemSelected(item: MenuItem): Boolean = false
{
return false;
}
/** /**
* Returns the id of the resource that should be used to inflate this menu. * 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. * @return id of the menu resource.
*/ */
@MenuRes @MenuRes
protected abstract int getMenuResourceId(); protected abstract fun getMenuResourceId(): Int
} }
Loading…
Cancel
Save