Use long click to open menu, clean up some cruft.

This commit is contained in:
akwizgran
2025-04-30 15:25:14 +01:00
parent 138fa6f39d
commit d83ae3a3b4
3 changed files with 5 additions and 30 deletions

View File

@@ -4,7 +4,6 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import android.widget.ImageButton;
import android.widget.PopupMenu; import android.widget.PopupMenu;
import android.widget.TextView; import android.widget.TextView;
@@ -13,21 +12,15 @@ import org.briarproject.briar.android.util.UiUtils;
import org.briarproject.briar.android.view.TextAvatarView; import org.briarproject.briar.android.view.TextAvatarView;
import org.briarproject.briar.api.forum.Forum; import org.briarproject.briar.api.forum.Forum;
import java.util.logging.Logger;
import androidx.recyclerview.widget.RecyclerView; import androidx.recyclerview.widget.RecyclerView;
import static android.view.View.GONE; import static android.view.View.GONE;
import static android.view.View.VISIBLE; import static android.view.View.VISIBLE;
import static java.util.logging.Logger.getLogger;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID; import static org.briarproject.briar.android.activity.BriarActivity.GROUP_ID;
import static org.briarproject.briar.android.activity.BriarActivity.GROUP_NAME; import static org.briarproject.briar.android.activity.BriarActivity.GROUP_NAME;
class ForumViewHolder extends RecyclerView.ViewHolder { class ForumViewHolder extends RecyclerView.ViewHolder {
private static final Logger LOG =
getLogger(ForumViewHolder.class.getName());
private final ForumListViewModel viewModel; private final ForumListViewModel viewModel;
private final Context ctx; private final Context ctx;
private final ViewGroup layout; private final ViewGroup layout;
@@ -35,7 +28,6 @@ class ForumViewHolder extends RecyclerView.ViewHolder {
private final TextView name; private final TextView name;
private final TextView postCount; private final TextView postCount;
private final TextView date; private final TextView date;
private final ImageButton menuButton;
ForumViewHolder(View v, ForumListViewModel viewModel) { ForumViewHolder(View v, ForumListViewModel viewModel) {
super(v); super(v);
@@ -46,7 +38,6 @@ class ForumViewHolder extends RecyclerView.ViewHolder {
name = v.findViewById(R.id.forumNameView); name = v.findViewById(R.id.forumNameView);
postCount = v.findViewById(R.id.postCountView); postCount = v.findViewById(R.id.postCountView);
date = v.findViewById(R.id.dateView); date = v.findViewById(R.id.dateView);
menuButton = v.findViewById(R.id.menuButton);
} }
void bind(ForumListItem item) { void bind(ForumListItem item) {
@@ -76,20 +67,19 @@ class ForumViewHolder extends RecyclerView.ViewHolder {
date.setVisibility(VISIBLE); date.setVisibility(VISIBLE);
} }
// Open popup menu // Open popup menu on long click
menuButton.setOnClickListener(v -> { layout.setOnLongClickListener(v -> {
LOG.info("Menu click"); PopupMenu pm = new PopupMenu(ctx, v);
PopupMenu pm = new PopupMenu(ctx, menuButton);
pm.getMenuInflater().inflate(R.menu.forum_list_item_actions, pm.getMenuInflater().inflate(R.menu.forum_list_item_actions,
pm.getMenu()); pm.getMenu());
pm.setOnMenuItemClickListener(it -> { pm.setOnMenuItemClickListener(it -> {
LOG.info("Menu item click");
if (it.getItemId() == R.id.action_forum_delete) { if (it.getItemId() == R.id.action_forum_delete) {
viewModel.deleteForum(item.getForum().getId()); viewModel.deleteForum(item.getForum().getId());
} }
return true; return true;
}); });
pm.show(); pm.show();
return true;
}); });
// Open Forum on Click // Open Forum on Click

View File

@@ -26,7 +26,7 @@
android:layout_marginRight="@dimen/listitem_horizontal_margin" android:layout_marginRight="@dimen/listitem_horizontal_margin"
android:textColor="?android:attr/textColorPrimary" android:textColor="?android:attr/textColorPrimary"
android:textSize="@dimen/text_size_medium" android:textSize="@dimen/text_size_medium"
app:layout_constraintEnd_toStartOf="@id/menuButton" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/avatarView" app:layout_constraintStart_toEndOf="@+id/avatarView"
app:layout_constraintTop_toTopOf="parent" app:layout_constraintTop_toTopOf="parent"
tools:text="This is a name of a forum which can be long" /> tools:text="This is a name of a forum which can be long" />
@@ -44,19 +44,6 @@
app:layout_constraintTop_toBottomOf="@+id/forumNameView" app:layout_constraintTop_toBottomOf="@+id/forumNameView"
tools:text="@string/no_forum_posts" /> tools:text="@string/no_forum_posts" />
<ImageButton
android:id="@+id/menuButton"
style="@style/Widget.AppCompat.ActionButton.Overflow"
android:layout_width="48dp"
android:layout_height="48dp"
android:layout_margin="@dimen/listitem_horizontal_margin"
android:contentDescription="@string/menu"
app:icon="@drawable/ic_more_vert_accent"
app:layout_constraintBottom_toTopOf="@id/dateView"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/forumNameView"
app:layout_constraintTop_toTopOf="parent" />
<TextView <TextView
android:id="@+id/dateView" android:id="@+id/dateView"
android:layout_width="wrap_content" android:layout_width="wrap_content"
@@ -66,7 +53,6 @@
android:textSize="@dimen/text_size_small" android:textSize="@dimen/text_size_small"
app:layout_constraintBaseline_toBaselineOf="@+id/postCountView" app:layout_constraintBaseline_toBaselineOf="@+id/postCountView"
app:layout_constraintEnd_toEndOf="parent" app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toBottomOf="@id/menuButton"
tools:text="Dec 24" /> tools:text="Dec 24" />
<View <View

View File

@@ -936,6 +936,5 @@
<string name="screenshot_message_2">Hi Alice! Thanks for telling me about Briar!</string> <string name="screenshot_message_2">Hi Alice! Thanks for telling me about Briar!</string>
<!-- This is a message to be used in screenshots. --> <!-- This is a message to be used in screenshots. -->
<string name="screenshot_message_3">No problem, hope you like it 😀</string> <string name="screenshot_message_3">No problem, hope you like it 😀</string>
<string name="menu">Menu</string>
</resources> </resources>