Skip to content

Commit

Permalink
Merge pull request #99 from skydoves/item/data-class
Browse files Browse the repository at this point in the history
Convert PowerMenuItem to kotlin file and add iconContentDescription property
  • Loading branch information
skydoves authored Dec 19, 2022
2 parents 833848e + a33d7d9 commit d602991
Show file tree
Hide file tree
Showing 6 changed files with 70 additions and 234 deletions.
16 changes: 8 additions & 8 deletions app/src/main/java/com/skydoves/powermenudemo/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -42,44 +42,44 @@ public class MainActivity extends AppCompatActivity {
private CustomPowerMenu<NameCardMenuItem, CustomDialogMenuAdapter> customDialogMenu;
private PowerMenu iconMenu;
private final OnMenuItemClickListener<PowerMenuItem> onHamburgerItemClickListener =
new OnMenuItemClickListener<PowerMenuItem>() {
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, PowerMenuItem item) {
Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), item.title, Toast.LENGTH_SHORT).show();
hamburgerMenu.setSelectedPosition(position);
}
};
private final OnDismissedListener onHamburgerMenuDismissedListener =
() -> Log.d("Test", "onDismissed hamburger menu");
private final OnMenuItemClickListener<PowerMenuItem> onProfileItemClickListener =
new OnMenuItemClickListener<PowerMenuItem>() {
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, PowerMenuItem item) {
Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), item.title, Toast.LENGTH_SHORT).show();
profileMenu.dismiss();
}
};
private final OnMenuItemClickListener<String> onWriteItemClickListener =
new OnMenuItemClickListener<String>() {
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, String title) {
Toast.makeText(getBaseContext(), title, Toast.LENGTH_SHORT).show();
writeMenu.dismiss();
}
};
private final OnMenuItemClickListener<String> onAlertItemClickListener =
new OnMenuItemClickListener<String>() {
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, String title) {
Toast.makeText(getBaseContext(), title, Toast.LENGTH_SHORT).show();
alertMenu.dismiss();
}
};
private final OnMenuItemClickListener<PowerMenuItem> onIconMenuItemClickListener =
new OnMenuItemClickListener<PowerMenuItem>() {
new OnMenuItemClickListener<>() {
@Override
public void onItemClick(int position, PowerMenuItem item) {
Toast.makeText(getBaseContext(), item.getTitle(), Toast.LENGTH_SHORT).show();
Toast.makeText(getBaseContext(), item.title, Toast.LENGTH_SHORT).show();
iconMenu.dismiss();
}
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,10 @@ public static PowerMenu getIconPowerMenu(
Context styledContext = new ContextThemeWrapper(context, R.style.PopupCardThemeOverlay);

return new PowerMenu.Builder(styledContext)
.addItem(new PowerMenuItem("WeChat", R.drawable.ic_wechat))
.addItem(new PowerMenuItem("Facebook", R.drawable.ic_facebook))
.addItem(new PowerMenuItem("Twitter", R.drawable.ic_twitter))
.addItem(new PowerMenuItem("Line", R.drawable.ic_line))
.addItem(new PowerMenuItem("WeChat", false, R.drawable.ic_wechat))
.addItem(new PowerMenuItem("Facebook", false, R.drawable.ic_facebook))
.addItem(new PowerMenuItem("Twitter", false, R.drawable.ic_twitter))
.addItem(new PowerMenuItem("Line", false, R.drawable.ic_line))
.addItem(new PowerMenuItem("Other"))
.setLifecycleOwner(lifecycleOwner)
.setOnMenuItemClickListener(onMenuItemClickListener)
Expand Down
50 changes: 24 additions & 26 deletions powermenu/api/powermenu.api
Original file line number Diff line number Diff line change
Expand Up @@ -338,34 +338,32 @@ public abstract class com/skydoves/powermenu/PowerMenu$Factory {
public abstract fun create (Landroid/content/Context;Landroidx/lifecycle/LifecycleOwner;)Lcom/skydoves/powermenu/PowerMenu;
}

public class com/skydoves/powermenu/PowerMenuItem {
protected field icon Landroid/graphics/drawable/Drawable;
protected field iconRes I
protected field isSelected Z
protected field tag Ljava/lang/Object;
protected field title Ljava/lang/CharSequence;
public final class com/skydoves/powermenu/PowerMenuItem {
public field icon Landroid/graphics/drawable/Drawable;
public final field iconContentDescription Ljava/lang/CharSequence;
public field iconRes I
public field isSelected Z
public field tag Ljava/lang/Object;
public field title Ljava/lang/CharSequence;
public fun <init> ()V
public fun <init> (Ljava/lang/CharSequence;)V
public fun <init> (Ljava/lang/CharSequence;I)V
public fun <init> (Ljava/lang/CharSequence;ILjava/lang/Object;)V
public fun <init> (Ljava/lang/CharSequence;IZ)V
public fun <init> (Ljava/lang/CharSequence;IZLjava/lang/Object;)V
public fun <init> (Ljava/lang/CharSequence;Landroid/graphics/drawable/Drawable;)V
public fun <init> (Ljava/lang/CharSequence;Landroid/graphics/drawable/Drawable;Ljava/lang/Object;)V
public fun <init> (Ljava/lang/CharSequence;Landroid/graphics/drawable/Drawable;Z)V
public fun <init> (Ljava/lang/CharSequence;Landroid/graphics/drawable/Drawable;ZLjava/lang/Object;)V
public fun <init> (Ljava/lang/CharSequence;Ljava/lang/Object;)V
public fun <init> (Ljava/lang/CharSequence;Z)V
public fun <init> (Ljava/lang/CharSequence;ZLjava/lang/Object;)V
public fun getIcon ()Landroid/graphics/drawable/Drawable;
public fun getIconRes ()I
public fun getTag ()Ljava/lang/Object;
public fun getTitle ()Ljava/lang/CharSequence;
public fun isSelected ()Z
public fun setIconRes (I)V
public fun setIconRes (Landroid/graphics/drawable/Drawable;)V
public fun setIsSelected (Z)V
public fun setTag (Ljava/lang/Object;)V
public fun setTitle (Ljava/lang/CharSequence;)V
public fun <init> (Ljava/lang/CharSequence;ZI)V
public fun <init> (Ljava/lang/CharSequence;ZILandroid/graphics/drawable/Drawable;)V
public fun <init> (Ljava/lang/CharSequence;ZILandroid/graphics/drawable/Drawable;Ljava/lang/CharSequence;)V
public fun <init> (Ljava/lang/CharSequence;ZILandroid/graphics/drawable/Drawable;Ljava/lang/CharSequence;Ljava/lang/Object;)V
public synthetic fun <init> (Ljava/lang/CharSequence;ZILandroid/graphics/drawable/Drawable;Ljava/lang/CharSequence;Ljava/lang/Object;ILkotlin/jvm/internal/DefaultConstructorMarker;)V
public final fun component1 ()Ljava/lang/CharSequence;
public final fun component2 ()Z
public final fun component3 ()I
public final fun component4 ()Landroid/graphics/drawable/Drawable;
public final fun component5 ()Ljava/lang/CharSequence;
public final fun component6 ()Ljava/lang/Object;
public final fun copy (Ljava/lang/CharSequence;ZILandroid/graphics/drawable/Drawable;Ljava/lang/CharSequence;Ljava/lang/Object;)Lcom/skydoves/powermenu/PowerMenuItem;
public static synthetic fun copy$default (Lcom/skydoves/powermenu/PowerMenuItem;Ljava/lang/CharSequence;ZILandroid/graphics/drawable/Drawable;Ljava/lang/CharSequence;Ljava/lang/Object;ILjava/lang/Object;)Lcom/skydoves/powermenu/PowerMenuItem;
public fun equals (Ljava/lang/Object;)Z
public fun hashCode ()I
public fun toString ()Ljava/lang/String;
}

public final class com/skydoves/powermenu/databinding/ItemPowerMenuLibrarySkydovesBinding : androidx/viewbinding/ViewBinding {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ public View getView(final int index, View view, ViewGroup viewGroup) {
ConvertUtil.convertDpToPixel(iconPadding, context);
}
icon.setVisibility(View.VISIBLE);
} else if (powerMenuItem.iconContentDescription != null) {
icon.setContentDescription(powerMenuItem.iconContentDescription);
} else {
icon.setVisibility(View.GONE);
}
Expand Down Expand Up @@ -138,11 +140,7 @@ public void setSelectedPosition(int position) {
if (selectedEffect) {
for (int i = 0; i < getItemList().size(); i++) {
PowerMenuItem item = (PowerMenuItem) getItem(i);

item.setIsSelected(false);
if (i == position) {
item.setIsSelected(true);
}
item.isSelected = i == position;
}
notifyDataSetChanged();
}
Expand Down
191 changes: 0 additions & 191 deletions powermenu/src/main/java/com/skydoves/powermenu/PowerMenuItem.java

This file was deleted.

31 changes: 31 additions & 0 deletions powermenu/src/main/java/com/skydoves/powermenu/PowerMenuItem.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
/*
* Copyright (C) 2017 skydoves (Jaewoong Eum)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package com.skydoves.powermenu

import android.graphics.drawable.Drawable
import androidx.annotation.DrawableRes

/** PowerMenuItem is the item class for constructing the [PowerMenu]'s list. */
public data class PowerMenuItem @JvmOverloads constructor(
@JvmField public var title: CharSequence? = null,
@JvmField public var isSelected: Boolean = false,
@JvmField @DrawableRes
public var iconRes: Int = 0,
@JvmField public var icon: Drawable? = null,
@JvmField public val iconContentDescription: CharSequence? = null,
@JvmField public var tag: Any? = null
)

0 comments on commit d602991

Please sign in to comment.