summaryrefslogtreecommitdiff
path: root/core/src/main/java
diff options
context:
space:
mode:
authorMartin Fietz <Martin.Fietz@gmail.com>2016-11-01 19:35:43 +0100
committerMartin Fietz <Martin.Fietz@gmail.com>2016-11-01 19:43:23 +0100
commit8a626faf73070085e2f520247a5f701c4f125c10 (patch)
treef40d66b1e86550159f4e1bfd3ceacb78fabed9de /core/src/main/java
parentcfef273eba571d1f781e256a8521ea176b7b2797 (diff)
downloadAntennaPod-8a626faf73070085e2f520247a5f701c4f125c10.zip
Add ability to rename feeds
Diffstat (limited to 'core/src/main/java')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java52
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java11
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java18
3 files changed, 64 insertions, 17 deletions
diff --git a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
index bb0724d66..ac23f3d3d 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/feed/Feed.java
@@ -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() {
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
index 8e007019f..563d80da0 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBWriter.java
@@ -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)
diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
index b0d053f5a..ff003550c 100644
--- a/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
+++ b/core/src/main/java/de/danoeh/antennapod/core/storage/PodDBAdapter.java
@@ -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());
}