mirror of
https://code.briarproject.org/briar/briar.git
synced 2026-02-16 20:59:54 +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;
|
package org.briarproject.briar.android.blog;
|
||||||
|
|
||||||
|
import android.content.DialogInterface;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.design.widget.Snackbar;
|
import android.support.design.widget.Snackbar;
|
||||||
|
import android.support.v7.app.AlertDialog;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuInflater;
|
import android.view.MenuInflater;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
|
|
||||||
import org.briarproject.bramble.api.db.DbException;
|
import org.briarproject.bramble.api.db.DbException;
|
||||||
import org.briarproject.bramble.api.sync.GroupId;
|
|
||||||
import org.briarproject.briar.R;
|
import org.briarproject.briar.R;
|
||||||
import org.briarproject.briar.android.activity.ActivityComponent;
|
import org.briarproject.briar.android.activity.ActivityComponent;
|
||||||
import org.briarproject.briar.android.activity.BriarActivity;
|
import org.briarproject.briar.android.activity.BriarActivity;
|
||||||
@@ -34,7 +35,6 @@ public class RssFeedManageActivity extends BriarActivity
|
|||||||
|
|
||||||
private BriarRecyclerView list;
|
private BriarRecyclerView list;
|
||||||
private RssFeedAdapter adapter;
|
private RssFeedAdapter adapter;
|
||||||
private GroupId groupId;
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@SuppressWarnings("WeakerAccess")
|
@SuppressWarnings("WeakerAccess")
|
||||||
@@ -44,12 +44,6 @@ public class RssFeedManageActivity extends BriarActivity
|
|||||||
public void onCreate(Bundle savedInstanceState) {
|
public void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(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);
|
setContentView(R.layout.activity_rss_feed_manage);
|
||||||
|
|
||||||
adapter = new RssFeedAdapter(this, this);
|
adapter = new RssFeedAdapter(this, this);
|
||||||
@@ -101,19 +95,22 @@ public class RssFeedManageActivity extends BriarActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onDeleteClick(final Feed feed) {
|
public void onDeleteClick(final Feed feed) {
|
||||||
runOnDbThread(new Runnable() {
|
DialogInterface.OnClickListener okListener =
|
||||||
@Override
|
new DialogInterface.OnClickListener() {
|
||||||
public void run() {
|
@Override
|
||||||
try {
|
public void onClick(DialogInterface dialog, int which) {
|
||||||
feedManager.removeFeed(feed.getUrl());
|
deleteFeed(feed);
|
||||||
onFeedDeleted(feed);
|
}
|
||||||
} catch (DbException e) {
|
};
|
||||||
if (LOG.isLoggable(WARNING))
|
AlertDialog.Builder builder = new AlertDialog.Builder(this,
|
||||||
LOG.log(WARNING, e.toString(), e);
|
R.style.BriarDialogTheme);
|
||||||
onDeleteError();
|
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() {
|
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() {
|
private void onLoadError() {
|
||||||
runOnUiThreadUnlessDestroyed(new Runnable() {
|
runOnUiThreadUnlessDestroyed(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -304,6 +304,9 @@
|
|||||||
<string name="blogs_rss_feeds_manage_imported">Imported:</string>
|
<string name="blogs_rss_feeds_manage_imported">Imported:</string>
|
||||||
<string name="blogs_rss_feeds_manage_author">Author:</string>
|
<string name="blogs_rss_feeds_manage_author">Author:</string>
|
||||||
<string name="blogs_rss_feeds_manage_updated">Last Updated:</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_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_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>
|
<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;
|
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.
|
* Stores a local blog post.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public interface FeedManager {
|
|||||||
/**
|
/**
|
||||||
* Removes an RSS feed.
|
* Removes an RSS feed.
|
||||||
*/
|
*/
|
||||||
void removeFeed(String url) throws DbException;
|
void removeFeed(Feed feed) throws DbException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns a list of all added RSS feeds
|
* 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)
|
private void removeBlog(Transaction txn, Blog b, boolean forced)
|
||||||
throws DbException {
|
throws DbException {
|
||||||
if (!forced && !canBeRemoved(txn, b.getId()))
|
if (!forced && !canBeRemoved(txn, b.getId()))
|
||||||
|
|||||||
@@ -203,22 +203,20 @@ class FeedManagerImpl implements FeedManager, Client, EventListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void removeFeed(String url) throws DbException {
|
public void removeFeed(Feed feed) throws DbException {
|
||||||
LOG.info("Removing RSS feed...");
|
LOG.info("Removing RSS feed...");
|
||||||
Transaction txn = db.startTransaction(false);
|
Transaction txn = db.startTransaction(false);
|
||||||
try {
|
try {
|
||||||
List<Feed> feeds = getFeeds(txn);
|
List<Feed> feeds = getFeeds(txn);
|
||||||
Feed feed = null;
|
|
||||||
for (Feed f : feeds) {
|
for (Feed f : feeds) {
|
||||||
if (f.getUrl().equals(url)) {
|
if (f.getBlogId().equals(feed.getBlogId())) {
|
||||||
feed = f;
|
feed = f;
|
||||||
feeds.remove(f);
|
feeds.remove(f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (feed == null) throw new DbException();
|
|
||||||
storeFeeds(txn, feeds);
|
storeFeeds(txn, feeds);
|
||||||
// TODO blogManager.removeBlog(txn, feed.getBlog());
|
blogManager.removeBlog(txn, feed.getBlog());
|
||||||
db.commitTransaction(txn);
|
db.commitTransaction(txn);
|
||||||
} finally {
|
} finally {
|
||||||
db.endTransaction(txn);
|
db.endTransaction(txn);
|
||||||
|
|||||||
Reference in New Issue
Block a user