mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-13 19:29:06 +01:00
@@ -22,6 +22,8 @@ public interface BlogController extends ActivityLifecycleController {
|
||||
@Nullable
|
||||
MessageId getBlogPostId(int position);
|
||||
|
||||
void deleteBlog(final UiResultHandler<Boolean> resultHandler);
|
||||
|
||||
interface BlogPostListener {
|
||||
void onBlogPostAdded(final BlogPostItem post, final boolean local);
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@ import android.support.annotation.Nullable;
|
||||
|
||||
import org.briarproject.android.controller.DbControllerImpl;
|
||||
import org.briarproject.android.controller.handler.UiResultHandler;
|
||||
import org.briarproject.api.blogs.Blog;
|
||||
import org.briarproject.api.blogs.BlogManager;
|
||||
import org.briarproject.api.blogs.BlogPostHeader;
|
||||
import org.briarproject.api.db.DbException;
|
||||
@@ -168,4 +169,25 @@ public class BlogControllerImpl extends DbControllerImpl
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void deleteBlog(final UiResultHandler<Boolean> resultHandler) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
if (data.getGroupId() == null) {
|
||||
resultHandler.onResult(false);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
Blog b = blogManager.getBlog(data.getGroupId());
|
||||
blogManager.removeBlog(b);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
resultHandler.onResult(false);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
package org.briarproject.android.blogs;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v4.app.ActivityCompat;
|
||||
import android.support.v4.app.ActivityOptionsCompat;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
@@ -144,6 +146,9 @@ public class BlogFragment extends BaseFragment implements BlogPostListener {
|
||||
ActivityCompat.startActivityForResult(getActivity(), i,
|
||||
REQUEST_WRITE_POST, options.toBundle());
|
||||
return true;
|
||||
case R.id.action_delete_blog:
|
||||
showDeleteDialog();
|
||||
return true;
|
||||
default:
|
||||
return super.onOptionsItemSelected(item);
|
||||
}
|
||||
@@ -188,4 +193,34 @@ public class BlogFragment extends BaseFragment implements BlogPostListener {
|
||||
loadData(true);
|
||||
}
|
||||
|
||||
private void showDeleteDialog() {
|
||||
DialogInterface.OnClickListener okListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
deleteBlog();
|
||||
}
|
||||
};
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getActivity(),
|
||||
R.style.BriarDialogTheme);
|
||||
builder.setTitle(getString(R.string.blogs_delete_blog));
|
||||
builder.setMessage(getString(R.string.blogs_delete_blog_dialog_message));
|
||||
builder.setPositiveButton(R.string.blogs_delete_blog_cancel, null);
|
||||
builder.setNegativeButton(R.string.blogs_delete_blog_ok, okListener);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void deleteBlog() {
|
||||
blogController.deleteBlog(
|
||||
new UiResultHandler<Boolean>(getActivity()) {
|
||||
@Override
|
||||
public void onResultUi(Boolean result) {
|
||||
if (!result) return;
|
||||
Toast.makeText(getActivity(), R.string.forum_left_toast,
|
||||
LENGTH_SHORT).show();
|
||||
getActivity().supportFinishAfterTransition();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user