Add ability to rename feeds

This commit is contained in:
Martin Fietz 2016-11-01 19:35:43 +01:00
parent cfef273eba
commit 8a626faf73
13 changed files with 144 additions and 21 deletions

View File

@ -44,7 +44,7 @@ public class DBTestUtils {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
for (int i = 0; i < numFeeds; i++) {
Feed f = new Feed(0, null, "feed " + i, "link" + i, "descr", null, null,
Feed f = new Feed(0, null, "feed " + i, null, "link" + i, "descr", null, null,
null, null, "id" + i, null, null, "url" + i, false, new FlattrStatus(), false, null, null, false);
f.setItems(new ArrayList<>());
for (int j = 0; j < numItems; j++) {

View File

@ -54,6 +54,7 @@ import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.Flavors;
import de.danoeh.antennapod.core.util.StorageUtils;
import de.danoeh.antennapod.dialog.RatingDialog;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.fragment.AddFeedFragment;
import de.danoeh.antennapod.fragment.DownloadsFragment;
import de.danoeh.antennapod.fragment.EpisodesFragment;
@ -577,6 +578,9 @@ public class MainActivity extends CastEnabledActivity implements NavDrawerActivi
case R.id.mark_all_read_item:
DBWriter.markFeedRead(feed.getId());
return true;
case R.id.rename_item:
new RenameFeedDialog(this, feed).show();
return true;
case R.id.remove_item:
final FeedRemover remover = new FeedRemover(this, feed) {
@Override

View File

@ -49,6 +49,7 @@ import de.danoeh.antennapod.core.storage.DBTasks;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.playback.Playable;
import de.danoeh.antennapod.core.util.playback.PlaybackController;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.fragment.AddFeedFragment;
import de.danoeh.antennapod.fragment.ChaptersFragment;
import de.danoeh.antennapod.fragment.CoverFragment;
@ -374,6 +375,9 @@ public abstract class MediaplayerInfoActivity extends MediaplayerActivity implem
case R.id.mark_all_read_item:
DBWriter.markFeedRead(feed.getId());
return true;
case R.id.rename_item:
new RenameFeedDialog(this, feed).show();
return true;
case R.id.remove_item:
final FeedRemover remover = new FeedRemover(this, feed) {
@Override

View File

@ -0,0 +1,44 @@
package de.danoeh.antennapod.dialog;
import android.app.Activity;
import android.text.InputType;
import com.afollestad.materialdialogs.MaterialDialog;
import java.lang.ref.WeakReference;
import de.danoeh.antennapod.core.feed.Feed;
import de.danoeh.antennapod.core.storage.DBWriter;
public class RenameFeedDialog {
private final WeakReference<Activity> activityRef;
private final Feed feed;
public RenameFeedDialog(Activity activity, Feed feed) {
this.activityRef = new WeakReference<>(activity);
this.feed = feed;
}
public void show() {
Activity activity = activityRef.get();
if(activity == null) {
return;
}
new MaterialDialog.Builder(activity)
.title(de.danoeh.antennapod.core.R.string.rename_feed_label)
.inputType(InputType.TYPE_CLASS_TEXT)
.input(feed.getTitle(), feed.getTitle(), true, (dialog, input) -> {
feed.setCustomTitle(input.toString());
DBWriter.setFeedCustomTitle(feed);
dialog.dismiss();
})
.neutralText(de.danoeh.antennapod.core.R.string.reset)
.onNeutral((dialog, which) -> dialog.getInputEditText().setText(feed.getFeedTitle()))
.negativeText(de.danoeh.antennapod.core.R.string.cancel_label)
.onNegative((dialog, which) -> dialog.dismiss())
.autoDismiss(false)
.show();
}
}

View File

@ -67,6 +67,7 @@ import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.core.util.LongList;
import de.danoeh.antennapod.core.util.gui.MoreContentListFooterUtil;
import de.danoeh.antennapod.dialog.EpisodesApplyActionFragment;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import de.danoeh.antennapod.menuhandler.FeedItemMenuHandler;
import de.danoeh.antennapod.menuhandler.FeedMenuHandler;
import de.danoeh.antennapod.menuhandler.MenuItemUtils;
@ -106,6 +107,7 @@ public class ItemlistFragment extends ListFragment {
private boolean isUpdatingFeed;
private TextView txtvTitle;
private IconTextView txtvFailure;
private TextView txtvInformation;
@ -248,6 +250,9 @@ public class ItemlistFragment extends ListFragment {
.newInstance(feed.getItems());
((MainActivity)getActivity()).loadChildFragment(fragment);
return true;
case R.id.rename_item:
new RenameFeedDialog(getActivity(), feed).show();
return true;
case R.id.remove_item:
final FeedRemover remover = new FeedRemover(
getActivity(), feed) {
@ -415,6 +420,7 @@ public class ItemlistFragment extends ListFragment {
public void update(EventDistributor eventDistributor, Integer arg) {
if ((EVENTS & arg) != 0) {
Log.d(TAG, "Received contentUpdate Intent. arg " + arg);
refreshHeaderView();
loadItems();
updateProgressBarVisibility();
}
@ -469,6 +475,7 @@ public class ItemlistFragment extends ListFragment {
} else {
txtvFailure.setVisibility(View.GONE);
}
txtvTitle.setText(feed.getTitle());
if(feed.getItemFilter() != null) {
FeedItemFilter filter = feed.getItemFilter();
if(filter.getValues().length > 0) {
@ -498,7 +505,7 @@ public class ItemlistFragment extends ListFragment {
View header = inflater.inflate(R.layout.feeditemlist_header, lv, false);
lv.addHeaderView(header);
TextView txtvTitle = (TextView) header.findViewById(R.id.txtvTitle);
txtvTitle = (TextView) header.findViewById(R.id.txtvTitle);
TextView txtvAuthor = (TextView) header.findViewById(R.id.txtvAuthor);
ImageView imgvBackground = (ImageView) header.findViewById(R.id.imgvBackground);
ImageView imgvCover = (ImageView) header.findViewById(R.id.imgvCover);

View File

@ -26,6 +26,7 @@ import de.danoeh.antennapod.core.service.playback.PlaybackService;
import de.danoeh.antennapod.core.storage.DBReader;
import de.danoeh.antennapod.core.storage.DBWriter;
import de.danoeh.antennapod.core.util.FeedItemUtil;
import de.danoeh.antennapod.dialog.RenameFeedDialog;
import rx.Observable;
import rx.Subscription;
import rx.android.schedulers.AndroidSchedulers;
@ -102,7 +103,7 @@ public class SubscriptionFragment extends Fragment {
if(subscription != null) {
subscription.unsubscribe();
}
subscription = Observable.fromCallable(() -> DBReader.getNavDrawerData())
subscription = Observable.fromCallable(DBReader::getNavDrawerData)
.subscribeOn(Schedulers.newThread())
.observeOn(AndroidSchedulers.mainThread())
.subscribe(result -> {
@ -164,6 +165,9 @@ public class SubscriptionFragment extends Fragment {
.subscribe(result -> loadSubscriptions(),
error -> Log.e(TAG, Log.getStackTraceString(error)));
return true;
case R.id.rename_item:
new RenameFeedDialog(getActivity(), feed).show();
return true;
case R.id.remove_item:
final FeedRemover remover = new FeedRemover(getContext(), feed) {
@Override

View File

@ -65,6 +65,12 @@
android:title="@string/share_feed_url_label">
</item>
<item
android:id="@+id/rename_item"
android:menuCategory="container"
android:title="@string/rename_feed_label"
custom:showAsAction="never" />
<item
android:id="@+id/remove_item"
android:icon="?attr/content_discard"

View File

@ -11,6 +11,11 @@
android:menuCategory="container"
android:title="@string/mark_all_read_label" />
<item
android:id="@+id/rename_item"
android:menuCategory="container"
android:title="@string/rename_feed_label" />
<item
android:id="@+id/remove_item"
android:menuCategory="container"

View File

@ -51,7 +51,7 @@ project.ext {
glideOkhttpIntegrationVersion = "1.4.0"
iconifyVersion = "2.2.2"
jsoupVersion = "1.9.2"
materialDialogsVersion = "0.8.5.6@aar"
materialDialogsVersion = "0.8.5.8@aar"
okhttpVersion = "2.7.5"
okioVersion = "1.9.0"
recyclerviewFlexibledividerVersion = "1.2.6"

View File

@ -26,7 +26,11 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
public static final String TYPE_RSS091 = "rss";
public static final String TYPE_ATOM1 = "atom";
private String title;
/* title as defined by the feed */
private String feedTitle;
/* custom title set by the user */
private String customTitle;
/**
* Contains 'id'-element in Atom feed.
*/
@ -92,13 +96,14 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
/**
* This constructor is used for restoring a feed from the database.
*/
public Feed(long id, String lastUpdate, String title, String link, String description, String paymentLink,
public Feed(long id, String lastUpdate, String title, String customTitle, String link, String description, String paymentLink,
String author, String language, String type, String feedIdentifier, FeedImage image, String fileUrl,
String downloadUrl, boolean downloaded, FlattrStatus status, boolean paged, String nextPageLink,
String filter, boolean lastUpdateFailed) {
super(fileUrl, downloadUrl, downloaded);
this.id = id;
this.title = title;
this.feedTitle = title;
this.customTitle = customTitle;
this.lastUpdate = lastUpdate;
this.link = link;
this.description = description;
@ -126,7 +131,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
public Feed(long id, String lastUpdate, String title, String link, String description, String paymentLink,
String author, String language, String type, String feedIdentifier, FeedImage image, String fileUrl,
String downloadUrl, boolean downloaded) {
this(id, lastUpdate, title, link, description, paymentLink, author, language, type, feedIdentifier, image,
this(id, lastUpdate, title, null, link, description, paymentLink, author, language, type, feedIdentifier, image,
fileUrl, downloadUrl, downloaded, new FlattrStatus(), false, null, null, false);
}
@ -154,7 +159,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
*/
public Feed(String url, String lastUpdate, String title) {
this(url, lastUpdate);
this.title = title;
this.feedTitle = title;
this.flattrStatus = new FlattrStatus();
}
@ -171,6 +176,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
int indexId = cursor.getColumnIndex(PodDBAdapter.KEY_ID);
int indexLastUpdate = cursor.getColumnIndex(PodDBAdapter.KEY_LASTUPDATE);
int indexTitle = cursor.getColumnIndex(PodDBAdapter.KEY_TITLE);
int indexCustomTitle = cursor.getColumnIndex(PodDBAdapter.KEY_CUSTOM_TITLE);
int indexLink = cursor.getColumnIndex(PodDBAdapter.KEY_LINK);
int indexDescription = cursor.getColumnIndex(PodDBAdapter.KEY_DESCRIPTION);
int indexPaymentLink = cursor.getColumnIndex(PodDBAdapter.KEY_PAYMENT_LINK);
@ -191,6 +197,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
cursor.getLong(indexId),
cursor.getString(indexLastUpdate),
cursor.getString(indexTitle),
cursor.getString(indexCustomTitle),
cursor.getString(indexLink),
cursor.getString(indexDescription),
cursor.getString(indexPaymentLink),
@ -268,8 +275,8 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
return feedIdentifier;
} else if (download_url != null && !download_url.isEmpty()) {
return download_url;
} else if (title != null && !title.isEmpty()) {
return title;
} else if (feedTitle != null && !feedTitle.isEmpty()) {
return feedTitle;
} else {
return link;
}
@ -277,8 +284,8 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
@Override
public String getHumanReadableIdentifier() {
if (title != null) {
return title;
if (feedTitle != null) {
return feedTitle;
} else {
return download_url;
}
@ -287,8 +294,8 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
public void updateFromOther(Feed other) {
// don't update feed's download_url, we do that manually if redirected
// see AntennapodHttpClient
if (other.title != null) {
title = other.title;
if (other.feedTitle != null) {
feedTitle = other.feedTitle;
}
if (other.feedIdentifier != null) {
feedIdentifier = other.feedIdentifier;
@ -323,7 +330,7 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
if (super.compareWithOther(other)) {
return true;
}
if (!TextUtils.equals(title, other.title)) {
if (!TextUtils.equals(feedTitle, other.feedTitle)) {
return true;
}
if (other.feedIdentifier != null) {
@ -384,11 +391,28 @@ public class Feed extends FeedFile implements FlattrThing, ImageResource {
}
public String getTitle() {
return title;
return !TextUtils.isEmpty(customTitle) ? customTitle : feedTitle;
}
public void setTitle(String title) {
this.title = title;
this.feedTitle = title;
}
public String getFeedTitle() {
return this.feedTitle;
}
@Nullable
public String getCustomTitle() {
return this.customTitle;
}
public void setCustomTitle(String customTitle) {
if(customTitle == null || customTitle.equals(feedTitle)) {
this.customTitle = null;
} else {
this.customTitle = customTitle;
}
}
public String getLink() {

View File

@ -884,6 +884,17 @@ public class DBWriter {
});
}
public static Future<?> setFeedCustomTitle(Feed feed) {
return dbExec.submit(() -> {
PodDBAdapter adapter = PodDBAdapter.getInstance();
adapter.open();
adapter.setFeedCustomTitle(feed.getId(), feed.getCustomTitle());
adapter.close();
EventDistributor.getInstance().sendFeedUpdateBroadcast();
});
}
/**
* format an url for querying the database
* (postfix a / and apply percent-encoding)

View File

@ -57,6 +57,7 @@ public class PodDBAdapter {
// Key-constants
public static final String KEY_ID = "id";
public static final String KEY_TITLE = "title";
public static final String KEY_CUSTOM_TITLE = "custom_title";
public static final String KEY_NAME = "name";
public static final String KEY_LINK = "link";
public static final String KEY_DESCRIPTION = "description";
@ -124,7 +125,7 @@ public class PodDBAdapter {
public static final String CREATE_TABLE_FEEDS = "CREATE TABLE "
+ TABLE_NAME_FEEDS + " (" + TABLE_PRIMARY_KEY + KEY_TITLE
+ " TEXT," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ " TEXT," + KEY_CUSTOM_TITLE + " TEXT," + KEY_FILE_URL + " TEXT," + KEY_DOWNLOAD_URL + " TEXT,"
+ KEY_DOWNLOADED + " INTEGER," + KEY_LINK + " TEXT,"
+ KEY_DESCRIPTION + " TEXT," + KEY_PAYMENT_LINK + " TEXT,"
+ KEY_LASTUPDATE + " TEXT," + KEY_LANGUAGE + " TEXT," + KEY_AUTHOR
@ -225,6 +226,7 @@ public class PodDBAdapter {
private static final String[] FEED_SEL_STD = {
TABLE_NAME_FEEDS + "." + KEY_ID,
TABLE_NAME_FEEDS + "." + KEY_TITLE,
TABLE_NAME_FEEDS + "." + KEY_CUSTOM_TITLE,
TABLE_NAME_FEEDS + "." + KEY_FILE_URL,
TABLE_NAME_FEEDS + "." + KEY_DOWNLOAD_URL,
TABLE_NAME_FEEDS + "." + KEY_DOWNLOADED,
@ -363,7 +365,7 @@ public class PodDBAdapter {
*/
public long setFeed(Feed feed) {
ContentValues values = new ContentValues();
values.put(KEY_TITLE, feed.getTitle());
values.put(KEY_TITLE, feed.getFeedTitle());
values.put(KEY_LINK, feed.getLink());
values.put(KEY_DESCRIPTION, feed.getDescription());
values.put(KEY_PAYMENT_LINK, feed.getPaymentLink());
@ -854,6 +856,12 @@ public class PodDBAdapter {
db.execSQL(sql);
}
void setFeedCustomTitle(long feedId, String customTitle) {
ContentValues values = new ContentValues();
values.put(KEY_CUSTOM_TITLE, customTitle);
db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(feedId)});
}
/**
* Inserts or updates a download status.
*/
@ -1628,7 +1636,7 @@ public class PodDBAdapter {
*/
private static class PodDBHelper extends SQLiteOpenHelper {
private static final int VERSION = 1050004;
private static final int VERSION = 1060200;
private Context context;
@ -1924,6 +1932,10 @@ public class PodDBAdapter {
db.execSQL("UPDATE " + PodDBAdapter.TABLE_NAME_FEEDS
+" SET " + PodDBAdapter.KEY_LASTUPDATE + "=NULL");
}
if(oldVersion < 1060200) {
db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS
+ " ADD COLUMN " + PodDBAdapter.KEY_CUSTOM_TITLE + " TEXT");
}
EventBus.getDefault().post(ProgressEvent.end());
}

View File

@ -60,6 +60,7 @@
<string name="cancel_label">Cancel</string>
<string name="yes">Yes</string>
<string name="no">No</string>
<string name="reset">Reset</string>
<string name="author_label">Author</string>
<string name="language_label">Language</string>
<string name="url_label">URL</string>
@ -115,6 +116,7 @@
<string name="mark_all_seen_msg">Marked all Episodes as seen</string>
<string name="mark_all_seen_confirmation_msg">Please confirm that you want to mark all episodes as seen.</string>
<string name="show_info_label">Show information</string>
<string name="rename_feed_label">Rename Podcast</string>
<string name="remove_feed_label">Remove Podcast</string>
<string name="share_label">Share&#8230;</string>
<string name="share_link_label">Share Link</string>