mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-12 10:49:06 +01:00
Remove blog as well when removing RSS feed
This also adds a confirmation dialog to the removal process.
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
package org.briarproject.briar.android.blog;
|
||||
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.support.design.widget.Snackbar;
|
||||
import android.support.v7.app.AlertDialog;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
|
||||
import org.briarproject.bramble.api.db.DbException;
|
||||
import org.briarproject.bramble.api.sync.GroupId;
|
||||
import org.briarproject.briar.R;
|
||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||
import org.briarproject.briar.android.activity.BriarActivity;
|
||||
@@ -34,7 +35,6 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
|
||||
private BriarRecyclerView list;
|
||||
private RssFeedAdapter adapter;
|
||||
private GroupId groupId;
|
||||
|
||||
@Inject
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
@@ -44,12 +44,6 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
// GroupId from Intent
|
||||
Intent i = getIntent();
|
||||
byte[] b = i.getByteArrayExtra(GROUP_ID);
|
||||
if (b == null) throw new IllegalStateException("No Group in intent.");
|
||||
groupId = new GroupId(b);
|
||||
|
||||
setContentView(R.layout.activity_rss_feed_manage);
|
||||
|
||||
adapter = new RssFeedAdapter(this, this);
|
||||
@@ -101,19 +95,22 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
|
||||
@Override
|
||||
public void onDeleteClick(final Feed feed) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
feedManager.removeFeed(feed.getUrl());
|
||||
onFeedDeleted(feed);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
onDeleteError();
|
||||
}
|
||||
}
|
||||
});
|
||||
DialogInterface.OnClickListener okListener =
|
||||
new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialog, int which) {
|
||||
deleteFeed(feed);
|
||||
}
|
||||
};
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
||||
R.style.BriarDialogTheme);
|
||||
builder.setTitle(getString(R.string.blogs_rss_remove_feed));
|
||||
builder.setMessage(
|
||||
getString(R.string.blogs_rss_remove_feed_dialog_message));
|
||||
builder.setPositiveButton(R.string.cancel, null);
|
||||
builder.setNegativeButton(R.string.blogs_rss_remove_feed_ok,
|
||||
okListener);
|
||||
builder.show();
|
||||
}
|
||||
|
||||
private void loadFeeds() {
|
||||
@@ -148,6 +145,22 @@ public class RssFeedManageActivity extends BriarActivity
|
||||
});
|
||||
}
|
||||
|
||||
private void deleteFeed(final Feed feed) {
|
||||
runOnDbThread(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
feedManager.removeFeed(feed);
|
||||
onFeedDeleted(feed);
|
||||
} catch (DbException e) {
|
||||
if (LOG.isLoggable(WARNING))
|
||||
LOG.log(WARNING, e.toString(), e);
|
||||
onDeleteError();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void onLoadError() {
|
||||
runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||
@Override
|
||||
|
||||
@@ -304,6 +304,9 @@
|
||||
<string name="blogs_rss_feeds_manage_imported">Imported:</string>
|
||||
<string name="blogs_rss_feeds_manage_author">Author:</string>
|
||||
<string name="blogs_rss_feeds_manage_updated">Last Updated:</string>
|
||||
<string name="blogs_rss_remove_feed">Remove Feed</string>
|
||||
<string name="blogs_rss_remove_feed_dialog_message">Are you sure that you want to remove this feed and all its posts?\nNote that this will not remove the feed\'s blog from other people\'s devices.</string>
|
||||
<string name="blogs_rss_remove_feed_ok">Remove Feed</string>
|
||||
<string name="blogs_rss_feeds_manage_delete_error">The feed could not be deleted!</string>
|
||||
<string name="blogs_rss_feeds_manage_empty_state">You haven\'t imported any RSS feeds.\n\nWhy don\'t you click the plus in the top right screen corner to add your first?</string>
|
||||
<string name="blogs_rss_feeds_manage_error">There was a problem loading your feeds. Please try again later.</string>
|
||||
|
||||
@@ -41,6 +41,11 @@ public interface BlogManager {
|
||||
*/
|
||||
void removeBlog(Blog b) throws DbException;
|
||||
|
||||
/**
|
||||
* Removes and deletes a blog with the given {@link Transaction}.
|
||||
*/
|
||||
void removeBlog(Transaction txn, Blog b) throws DbException;
|
||||
|
||||
/**
|
||||
* Stores a local blog post.
|
||||
*/
|
||||
|
||||
@@ -23,7 +23,7 @@ public interface FeedManager {
|
||||
/**
|
||||
* Removes an RSS feed.
|
||||
*/
|
||||
void removeFeed(String url) throws DbException;
|
||||
void removeFeed(Feed feed) throws DbException;
|
||||
|
||||
/**
|
||||
* Returns a list of all added RSS feeds
|
||||
|
||||
@@ -224,6 +224,11 @@ class BlogManagerImpl extends BdfIncomingMessageHook implements BlogManager,
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeBlog(Transaction txn, Blog b) throws DbException {
|
||||
removeBlog(txn, b, false);
|
||||
}
|
||||
|
||||
private void removeBlog(Transaction txn, Blog b, boolean forced)
|
||||
throws DbException {
|
||||
if (!forced && !canBeRemoved(txn, b.getId()))
|
||||
|
||||
@@ -203,22 +203,20 @@ class FeedManagerImpl implements FeedManager, Client, EventListener {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeFeed(String url) throws DbException {
|
||||
public void removeFeed(Feed feed) throws DbException {
|
||||
LOG.info("Removing RSS feed...");
|
||||
Transaction txn = db.startTransaction(false);
|
||||
try {
|
||||
List<Feed> feeds = getFeeds(txn);
|
||||
Feed feed = null;
|
||||
for (Feed f : feeds) {
|
||||
if (f.getUrl().equals(url)) {
|
||||
if (f.getBlogId().equals(feed.getBlogId())) {
|
||||
feed = f;
|
||||
feeds.remove(f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (feed == null) throw new DbException();
|
||||
storeFeeds(txn, feeds);
|
||||
// TODO blogManager.removeBlog(txn, feed.getBlog());
|
||||
blogManager.removeBlog(txn, feed.getBlog());
|
||||
db.commitTransaction(txn);
|
||||
} finally {
|
||||
db.endTransaction(txn);
|
||||
|
||||
Reference in New Issue
Block a user