mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-11 18:29:05 +01:00
Allow forums to be removed without opening them.
This commit is contained in:
@@ -13,15 +13,18 @@ import androidx.recyclerview.widget.ListAdapter;
|
||||
@NotNullByDefault
|
||||
class ForumListAdapter extends ListAdapter<ForumListItem, ForumViewHolder> {
|
||||
|
||||
ForumListAdapter() {
|
||||
private final ForumListViewModel viewModel;
|
||||
|
||||
ForumListAdapter(ForumListViewModel viewModel) {
|
||||
super(new ForumListCallback());
|
||||
this.viewModel = viewModel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ForumViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(parent.getContext()).inflate(
|
||||
R.layout.list_item_forum, parent, false);
|
||||
return new ForumViewHolder(v);
|
||||
return new ForumViewHolder(v, viewModel);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -40,7 +40,7 @@ public class ForumListFragment extends BaseFragment implements
|
||||
private ForumListViewModel viewModel;
|
||||
private BriarRecyclerView list;
|
||||
private Snackbar snackbar;
|
||||
private final ForumListAdapter adapter = new ForumListAdapter();
|
||||
private ForumListAdapter adapter;
|
||||
|
||||
@Inject
|
||||
ViewModelProvider.Factory viewModelFactory;
|
||||
@@ -54,6 +54,7 @@ public class ForumListFragment extends BaseFragment implements
|
||||
component.inject(this);
|
||||
viewModel = new ViewModelProvider(this, viewModelFactory)
|
||||
.get(ForumListViewModel.class);
|
||||
adapter = new ForumListAdapter(viewModel);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package org.briarproject.briar.android.forum;
|
||||
|
||||
import android.app.Application;
|
||||
import android.widget.Toast;
|
||||
|
||||
import org.briarproject.bramble.api.contact.event.ContactRemovedEvent;
|
||||
import org.briarproject.bramble.api.db.DatabaseExecutor;
|
||||
@@ -15,6 +16,7 @@ import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.bramble.api.sync.event.GroupAddedEvent;
|
||||
import org.briarproject.bramble.api.sync.event.GroupRemovedEvent;
|
||||
import org.briarproject.bramble.api.system.AndroidExecutor;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.viewmodel.DbViewModel;
|
||||
import org.briarproject.briar.android.viewmodel.LiveResult;
|
||||
import org.briarproject.briar.api.android.AndroidNotificationManager;
|
||||
@@ -40,6 +42,7 @@ import androidx.annotation.UiThread;
|
||||
import androidx.lifecycle.LiveData;
|
||||
import androidx.lifecycle.MutableLiveData;
|
||||
|
||||
import static android.widget.Toast.LENGTH_SHORT;
|
||||
import static java.util.logging.Logger.getLogger;
|
||||
import static org.briarproject.bramble.util.LogUtils.logDuration;
|
||||
import static org.briarproject.bramble.util.LogUtils.now;
|
||||
@@ -180,4 +183,17 @@ class ForumListViewModel extends DbViewModel implements EventListener {
|
||||
return numInvitations;
|
||||
}
|
||||
|
||||
void deleteForum(GroupId groupId) {
|
||||
runOnDbThread(() -> {
|
||||
try {
|
||||
Forum f = forumManager.getForum(groupId);
|
||||
forumManager.removeForum(f);
|
||||
androidExecutor.runOnUiThread(() -> Toast
|
||||
.makeText(getApplication(), R.string.forum_left_toast,
|
||||
LENGTH_SHORT).show());
|
||||
} catch (DbException e) {
|
||||
handleException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,8 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageButton;
|
||||
import android.widget.PopupMenu;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.briarproject.briar.R;
|
||||
@@ -11,30 +13,40 @@ import org.briarproject.briar.android.util.UiUtils;
|
||||
import org.briarproject.briar.android.view.TextAvatarView;
|
||||
import org.briarproject.briar.api.forum.Forum;
|
||||
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import static android.view.View.GONE;
|
||||
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_NAME;
|
||||
|
||||
class ForumViewHolder extends RecyclerView.ViewHolder {
|
||||
|
||||
private static final Logger LOG =
|
||||
getLogger(ForumViewHolder.class.getName());
|
||||
|
||||
private final ForumListViewModel viewModel;
|
||||
private final Context ctx;
|
||||
private final ViewGroup layout;
|
||||
private final TextAvatarView avatar;
|
||||
private final TextView name;
|
||||
private final TextView postCount;
|
||||
private final TextView date;
|
||||
private final ImageButton menuButton;
|
||||
|
||||
ForumViewHolder(View v) {
|
||||
ForumViewHolder(View v, ForumListViewModel viewModel) {
|
||||
super(v);
|
||||
this.viewModel = viewModel;
|
||||
ctx = v.getContext();
|
||||
layout = (ViewGroup) v;
|
||||
avatar = v.findViewById(R.id.avatarView);
|
||||
name = v.findViewById(R.id.forumNameView);
|
||||
postCount = v.findViewById(R.id.postCountView);
|
||||
date = v.findViewById(R.id.dateView);
|
||||
menuButton = v.findViewById(R.id.menuButton);
|
||||
}
|
||||
|
||||
void bind(ForumListItem item) {
|
||||
@@ -64,6 +76,22 @@ class ForumViewHolder extends RecyclerView.ViewHolder {
|
||||
date.setVisibility(VISIBLE);
|
||||
}
|
||||
|
||||
// Open popup menu
|
||||
menuButton.setOnClickListener(v -> {
|
||||
LOG.info("Menu click");
|
||||
PopupMenu pm = new PopupMenu(ctx, menuButton);
|
||||
pm.getMenuInflater().inflate(R.menu.forum_list_item_actions,
|
||||
pm.getMenu());
|
||||
pm.setOnMenuItemClickListener(it -> {
|
||||
LOG.info("Menu item click");
|
||||
if (it.getItemId() == R.id.action_forum_delete) {
|
||||
viewModel.deleteForum(item.getForum().getId());
|
||||
}
|
||||
return true;
|
||||
});
|
||||
pm.show();
|
||||
});
|
||||
|
||||
// Open Forum on Click
|
||||
layout.setOnClickListener(v -> {
|
||||
Intent i = new Intent(ctx, ForumActivity.class);
|
||||
|
||||
@@ -11,7 +11,6 @@
|
||||
android:layout_width="@dimen/listitem_picture_frame_size"
|
||||
android:layout_height="@dimen/listitem_picture_frame_size"
|
||||
android:layout_marginStart="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginLeft="@dimen/listitem_horizontal_margin"
|
||||
app:layout_constraintBottom_toTopOf="@+id/divider"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintTop_toTopOf="parent" />
|
||||
@@ -27,7 +26,7 @@
|
||||
android:layout_marginRight="@dimen/listitem_horizontal_margin"
|
||||
android:textColor="?android:attr/textColorPrimary"
|
||||
android:textSize="@dimen/text_size_medium"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintEnd_toStartOf="@id/menuButton"
|
||||
app:layout_constraintStart_toEndOf="@+id/avatarView"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
tools:text="This is a name of a forum which can be long" />
|
||||
@@ -38,7 +37,6 @@
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="@dimen/margin_medium"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginRight="8dp"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/text_size_small"
|
||||
app:layout_constraintEnd_toStartOf="@+id/dateView"
|
||||
@@ -46,16 +44,29 @@
|
||||
app:layout_constraintTop_toBottomOf="@+id/forumNameView"
|
||||
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
|
||||
android:id="@+id/dateView"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginEnd="@dimen/listitem_horizontal_margin"
|
||||
android:layout_marginRight="@dimen/listitem_horizontal_margin"
|
||||
android:textColor="?android:attr/textColorSecondary"
|
||||
android:textSize="@dimen/text_size_small"
|
||||
app:layout_constraintBaseline_toBaselineOf="@+id/postCountView"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/menuButton"
|
||||
tools:text="Dec 24" />
|
||||
|
||||
<View
|
||||
@@ -63,7 +74,6 @@
|
||||
style="@style/Divider.ThreadItem"
|
||||
android:layout_width="0dp"
|
||||
android:layout_marginStart="@dimen/margin_medium"
|
||||
android:layout_marginLeft="@dimen/margin_medium"
|
||||
android:layout_marginTop="@dimen/listitem_horizontal_margin"
|
||||
app:layout_constraintBottom_toBottomOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<item
|
||||
android:id="@+id/action_forum_delete"
|
||||
android:title="@string/forum_leave" />
|
||||
|
||||
</menu>
|
||||
@@ -936,5 +936,6 @@
|
||||
<string name="screenshot_message_2">Hi Alice! Thanks for telling me about Briar!</string>
|
||||
<!-- This is a message to be used in screenshots. -->
|
||||
<string name="screenshot_message_3">No problem, hope you like it 😀</string>
|
||||
<string name="menu">Menu</string>
|
||||
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user