Skip to content
Snippets Groups Projects
Verified Commit 684898ef authored by Torsten Grote's avatar Torsten Grote
Browse files

Move forum removal action from long press menu to action bar

part of UI changes for #305
parent a655df73
No related branches found
No related tags found
No related merge requests found
......@@ -15,4 +15,10 @@
android:title="@string/forum_share_button"
app:showAsAction="ifRoom"/>
<item
android:id="@+id/action_forum_delete"
android:icon="@drawable/social_remove_person"
android:title="@string/forum_leave"
app:showAsAction="never"/>
</menu>
\ No newline at end of file
......@@ -78,8 +78,8 @@
<item quantity="other">%d forums shared by contacts</item>
</plurals>
<string name="show_forums">Show</string>
<string name="unsubscribe">Unsubscribe</string>
<string name="unsubscribed_toast">Unsubscribed</string>
<string name="forum_leave">Leave Forum</string>
<string name="forum_left_toast">Forum Left</string>
<string name="no_forum_posts">No posts</string>
<string name="create_forum_title">New Forum</string>
<string name="choose_forum_name">Choose a name for your forum:</string>
......@@ -194,7 +194,10 @@
<string name="dialog_welcome_message">Add a contact to start communicating securely or press the icon in the upper left corner of the screen for more options.</string>
<string name="dialog_title_share_crash_report">Briar has crashed</string>
<string name="dialog_message_share_crash_report">Would you like to review the crash report and send it to the developers? It will be stored encrypted on your device until the next time you log into Briar, and then sent securely to the developers.</string>
<string name="dialog_title_remove_forum">Confirm Leaving Forum</string>
<string name="dialog_message_remove_forum">Are you sure that you want to remove this forum? Contacts you have shared this forum with might get cut off from receiving updates for this forum.</string>
<string name="dialog_button_ok">OK</string>
<string name="dialog_button_remove">Remove</string>
<string name="dialog_button_introduce">Introduce</string>
<string name="dialog_button_accept">Accept</string>
<string name="dialog_button_decline">Decline</string>
......
package org.briarproject.android.forum;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.ActivityCompat;
import android.support.v4.app.ActivityOptionsCompat;
import android.support.v7.app.AlertDialog;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
......@@ -13,6 +15,7 @@ import android.widget.AdapterView.OnItemClickListener;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.AndroidComponent;
......@@ -51,6 +54,7 @@ import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.forum.ReadForumPostActivity.RESULT_PREV_NEXT;
......@@ -163,6 +167,9 @@ public class ForumActivity extends BriarActivity implements EventListener,
android.R.anim.slide_out_right);
ActivityCompat.startActivity(this, i2, options.toBundle());
return true;
case R.id.action_forum_delete:
showUnsubscribeDialog();
return true;
default:
return super.onOptionsItemSelected(item);
}
......@@ -381,4 +388,43 @@ public class ForumActivity extends BriarActivity implements EventListener,
i.putExtra("briar.POSITION", position);
startActivityForResult(i, REQUEST_READ);
}
private void showUnsubscribeDialog() {
DialogInterface.OnClickListener okListener =
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
unsubscribe(forum);
Toast.makeText(ForumActivity.this,
R.string.forum_left_toast, LENGTH_SHORT)
.show();
}
};
AlertDialog.Builder builder =
new AlertDialog.Builder(ForumActivity.this,
R.style.BriarDialogTheme);
builder.setTitle(getString(R.string.dialog_title_remove_forum));
builder.setMessage(getString(R.string.dialog_message_remove_forum));
builder.setPositiveButton(R.string.dialog_button_remove, okListener);
builder.setNegativeButton(android.R.string.cancel, null);
builder.show();
}
private void unsubscribe(final Forum f) {
runOnDbThread(new Runnable() {
public void run() {
try {
long now = System.currentTimeMillis();
forumManager.removeForum(f);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Removing forum took " + duration + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
}
}
});
}
}
......@@ -5,8 +5,6 @@ import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.design.widget.Snackbar;
import android.support.v4.content.ContextCompat;
import android.view.ContextMenu;
import android.view.ContextMenu.ContextMenuInfo;
import android.view.LayoutInflater;
import android.view.Menu;
import android.view.MenuInflater;
......@@ -14,11 +12,9 @@ import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;
import org.briarproject.R;
import org.briarproject.android.AndroidComponent;
......@@ -46,11 +42,9 @@ import javax.inject.Inject;
import static android.support.design.widget.Snackbar.LENGTH_INDEFINITE;
import static android.view.Gravity.CENTER;
import static android.view.Gravity.CENTER_HORIZONTAL;
import static android.view.Menu.NONE;
import static android.view.View.GONE;
import static android.view.View.VISIBLE;
import static android.widget.LinearLayout.VERTICAL;
import static android.widget.Toast.LENGTH_SHORT;
import static java.util.logging.Level.INFO;
import static java.util.logging.Level.WARNING;
import static org.briarproject.android.BriarActivity.GROUP_ID;
......@@ -75,8 +69,6 @@ public class ForumListFragment extends BaseEventFragment implements
return fragment;
}
private static final int MENU_ITEM_UNSUBSCRIBE = 1;
private TextView empty = null;
private ForumListAdapter adapter = null;
private ListView list = null;
......@@ -112,7 +104,6 @@ public class ForumListFragment extends BaseEventFragment implements
list.setLayoutParams(MATCH_WRAP_1);
list.setAdapter(adapter);
list.setOnItemClickListener(this);
list.setOnCreateContextMenuListener(this);
list.setVisibility(GONE);
layout.addView(list);
......@@ -376,40 +367,4 @@ public class ForumListFragment extends BaseEventFragment implements
startActivity(i);
}
@Override
public void onCreateContextMenu(ContextMenu menu, View view,
ContextMenuInfo info) {
String delete = getString(R.string.unsubscribe);
menu.add(NONE, MENU_ITEM_UNSUBSCRIBE, NONE, delete);
}
@Override
public boolean onContextItemSelected(MenuItem menuItem) {
if (menuItem.getItemId() == MENU_ITEM_UNSUBSCRIBE) {
ContextMenuInfo info = menuItem.getMenuInfo();
int position = ((AdapterContextMenuInfo) info).position;
ForumListItem item = adapter.getItem(position);
unsubscribe(item.getForum());
String unsubscribed = getString(R.string.unsubscribed_toast);
Toast.makeText(getContext(), unsubscribed, LENGTH_SHORT).show();
}
return true;
}
private void unsubscribe(final Forum f) {
listener.runOnDbThread(new Runnable() {
public void run() {
try {
long now = System.currentTimeMillis();
forumManager.removeForum(f);
long duration = System.currentTimeMillis() - now;
if (LOG.isLoggable(INFO))
LOG.info("Removing forum took " + duration + " ms");
} catch (DbException e) {
if (LOG.isLoggable(WARNING))
LOG.log(WARNING, e.toString(), e);
}
}
});
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment