Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue/14004 menu item order #14183

Merged
merged 17 commits into from
Mar 4, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -93,8 +93,8 @@ import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.OpenEdito
import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowBlogPreview
import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowBookmarkedSavedOnlyLocallyDialog
import org.wordpress.android.ui.reader.discover.ReaderNavigationEvents.ShowBookmarkedTab
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction.PrimaryAction
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction.SecondaryAction
import org.wordpress.android.ui.reader.discover.ReaderPostCardActionType
import org.wordpress.android.ui.reader.utils.FeaturedImageUtils
import org.wordpress.android.ui.reader.utils.ReaderUtils
Expand Down Expand Up @@ -490,7 +490,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
}
}

private fun createMoreMenuPopup(actions: List<SecondaryAction>, v: View) {
private fun createMoreMenuPopup(actions: List<ReaderPostCardAction>, v: View) {
AnalyticsTracker.track(Stat.READER_ARTICLE_DETAIL_MORE_TAPPED)
moreMenuPopup = ListPopupWindow(v.context)
moreMenuPopup?.let {
Expand Down Expand Up @@ -1002,9 +1002,7 @@ class ReaderPostDetailFragment : ViewPagerFragment(),
ReaderPostTable.getFeedPost(blogId, postId, false)
else
ReaderPostTable.getBlogPost(blogId, postId, false)
if (post == null) {
return false
}
if (post == null) return false

// "discover" Editor Pick posts should open the original (source) post
if (post!!.isDiscoverPost) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,17 @@
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.Space;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.appcompat.content.res.AppCompatResources;

import org.wordpress.android.R;
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction;
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction.SecondaryAction;
import org.wordpress.android.ui.reader.discover.ReaderPostCardActionType;
import org.wordpress.android.ui.utils.UiHelpers;
import org.wordpress.android.util.ColorUtils;
import org.wordpress.android.util.ContextExtensionsKt;
Expand All @@ -25,10 +29,14 @@
*/
public class ReaderMenuAdapter extends BaseAdapter {
private final LayoutInflater mInflater;
private final List<SecondaryAction> mMenuItems = new ArrayList<>();
private final List<ReaderPostCardAction> mMenuItems = new ArrayList<>();
private final UiHelpers mUiHelpers;

public ReaderMenuAdapter(Context context, @NonNull UiHelpers uiHelpers, @NonNull List<SecondaryAction> menuItems) {
private static final int TYPE_SPACER = 0;
private static final int TYPE_CONTENT = 1;

public ReaderMenuAdapter(Context context, @NonNull UiHelpers uiHelpers,
@NonNull List<ReaderPostCardAction> menuItems) {
super();
mInflater = LayoutInflater.from(context);
mMenuItems.addAll(menuItems);
Expand All @@ -50,8 +58,43 @@ public long getItemId(int position) {
return mMenuItems.get(position).getType().ordinal();
}

@Override
public int getViewTypeCount() {
return 2;
}

@Override
public int getItemViewType(int position) {
return (mMenuItems.get(position).getType() == ReaderPostCardActionType.SPACER_NO_ACTION)
? TYPE_SPACER : TYPE_CONTENT;
}

@Override
public View getView(int position, View convertView, ViewGroup parent) {
ReaderPostCardAction cardAction = mMenuItems.get(position);
if (getItemViewType(position) == TYPE_SPACER) {
return handleSpacer(convertView, parent);
} else {
return handleSecondaryAction((SecondaryAction) cardAction, convertView, parent);
}
}

private View handleSpacer(View convertView, ViewGroup parent) {
ReaderMenuSpacerHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.reader_popup_menu_spacer_item, parent, false);
holder = new ReaderMenuSpacerHolder(convertView);
convertView.setTag(holder);
} else {
holder = (ReaderMenuSpacerHolder) convertView.getTag();
}
holder.mSpacer.setVisibility(View.VISIBLE);
holder.mContainer.setEnabled(false);
holder.mContainer.setClickable(false);
return convertView;
}

private View handleSecondaryAction(SecondaryAction item, View convertView, ViewGroup parent) {
ReaderMenuHolder holder;
if (convertView == null) {
convertView = mInflater.inflate(R.layout.reader_popup_menu_item, parent, false);
Expand All @@ -61,7 +104,6 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder = (ReaderMenuHolder) convertView.getTag();
}

SecondaryAction item = mMenuItems.get(position);
CharSequence textRes = mUiHelpers.getTextOfUiString(convertView.getContext(), item.getLabel());
int textColorRes =
ContextExtensionsKt.getColorResIdFromAttribute(convertView.getContext(), item.getLabelColor());
Expand All @@ -71,12 +113,11 @@ public View getView(int position, View convertView, ViewGroup parent) {

holder.mText.setText(textRes);
holder.mText.setTextColor(AppCompatResources.getColorStateList(convertView.getContext(), textColorRes));
ColorUtils.INSTANCE.setImageResourceWithTint(holder.mIcon, iconRes, iconColorRes);

ColorUtils.setImageResourceWithTint(holder.mIcon, iconRes, iconColorRes);
return convertView;
}

ParaskP7 marked this conversation as resolved.
Show resolved Hide resolved
class ReaderMenuHolder {
static class ReaderMenuHolder {
private final TextView mText;
private final ImageView mIcon;

Expand All @@ -85,4 +126,13 @@ class ReaderMenuHolder {
mIcon = view.findViewById(R.id.image);
}
}

static class ReaderMenuSpacerHolder {
private final Space mSpacer;
private final LinearLayout mContainer;
ReaderMenuSpacerHolder(View view) {
mSpacer = view.findViewById(R.id.reader_popup_menu_item_spacer);
mContainer = view.findViewById(R.id.reader_popup_menu_item_spacer_container);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import androidx.annotation.DrawableRes
import androidx.annotation.StringRes
import org.wordpress.android.R
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction.PrimaryAction
import org.wordpress.android.ui.reader.discover.ReaderPostCardAction.SecondaryAction
import org.wordpress.android.ui.reader.discover.ReaderPostCardActionType.SPACER_NO_ACTION
import org.wordpress.android.ui.reader.discover.interests.TagUiState
import org.wordpress.android.ui.reader.models.ReaderImageList
import org.wordpress.android.ui.reader.views.uistates.ReaderBlogSectionUiState
Expand Down Expand Up @@ -40,7 +40,7 @@ sealed class ReaderCardUiState {
val likeAction: PrimaryAction,
val reblogAction: PrimaryAction,
val commentsAction: PrimaryAction,
val moreMenuItems: List<SecondaryAction>? = null,
val moreMenuItems: List<ReaderPostCardAction>? = null,
val onItemClicked: (Long, Long) -> Unit,
val onItemRendered: (ReaderCardUiState) -> Unit,
val onMoreButtonClicked: (ReaderPostUiState) -> Unit,
Expand Down Expand Up @@ -123,6 +123,12 @@ sealed class ReaderPostCardAction {
override val type: ReaderPostCardActionType,
override val onClicked: (Long, Long, ReaderPostCardActionType) -> Unit
) : ReaderPostCardAction()

data class SpacerNoAction(
override val isSelected: Boolean = false,
override val type: ReaderPostCardActionType = SPACER_NO_ACTION,
override val onClicked: ((Long, Long, ReaderPostCardActionType) -> Unit)? = null
) : ReaderPostCardAction()
}

enum class ReaderPostCardActionType {
Expand All @@ -136,5 +142,6 @@ enum class ReaderPostCardActionType {
REBLOG,
COMMENTS,
REPORT_POST,
TOGGLE_SEEN_STATUS
TOGGLE_SEEN_STATUS,
SPACER_NO_ACTION
}
Loading