diff options
author | orionlee <orionlee@yahoo.com> | 2019-10-24 15:32:51 -0700 |
---|---|---|
committer | orionlee <orionlee@yahoo.com> | 2019-10-24 15:32:51 -0700 |
commit | baec984c0ffdf65ede4bd425c2f151096a44bc03 (patch) | |
tree | 24f8a696995d7378ad31414f651282893d83f189 | |
parent | 7687ffb08e19968600a58f3994a82995316d27b6 (diff) | |
download | AntennaPod-baec984c0ffdf65ede4bd425c2f151096a44bc03.zip |
Feed Sort Order DB column: changed from Integer to Text, to allow flexibility of multiple sorts without DB schema change
4 files changed, 14 insertions, 14 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 81df6d42a..0d17e3faa 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 @@ -215,7 +215,7 @@ public class Feed extends FeedFile implements ImageResource { cursor.getInt(indexIsPaged) > 0, cursor.getString(indexNextPageLink), cursor.getString(indexHide), - SortOrder.fromCode(cursor.getInt(indexSortOrder)), + SortOrder.fromCodeString(cursor.getString(indexSortOrder)), cursor.getInt(indexLastUpdateFailed) > 0 ); diff --git a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java index 6c15be15d..0c8f89348 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java +++ b/core/src/main/java/de/danoeh/antennapod/core/storage/DBUpgrader.java @@ -9,7 +9,6 @@ import android.util.Log; import de.danoeh.antennapod.core.feed.FeedItem; import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; -import static de.danoeh.antennapod.core.util.SortOrder.CODE_UNSPECIFIED; class DBUpgrader { /** @@ -298,7 +297,7 @@ class DBUpgrader { if (oldVersion < 1070401) { db.execSQL("ALTER TABLE " + PodDBAdapter.TABLE_NAME_FEEDS - + " ADD COLUMN " + PodDBAdapter.KEY_SORT_ORDER + " INTEGER DEFAULT " + CODE_UNSPECIFIED); + + " ADD COLUMN " + PodDBAdapter.KEY_SORT_ORDER + " TEXT"); } } 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 4ae282d8e..a37f357ae 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 @@ -38,7 +38,7 @@ import de.danoeh.antennapod.core.util.LongIntMap; import de.danoeh.antennapod.core.util.SortOrder; import static de.danoeh.antennapod.core.feed.FeedPreferences.SPEED_USE_GLOBAL; -import static de.danoeh.antennapod.core.util.SortOrder.toCode; +import static de.danoeh.antennapod.core.util.SortOrder.toCodeString; // TODO Remove media column from feeditem table @@ -141,7 +141,7 @@ public class PodDBAdapter { + KEY_IS_PAGED + " INTEGER DEFAULT 0," + KEY_NEXT_PAGE_LINK + " TEXT," + KEY_HIDE + " TEXT," - + KEY_SORT_ORDER + " INTEGER DEFAULT " + SortOrder.CODE_UNSPECIFIED + "," + + KEY_SORT_ORDER + " TEXT," + KEY_LAST_UPDATE_FAILED + " INTEGER DEFAULT 0," + KEY_AUTO_DELETE_ACTION + " INTEGER DEFAULT 0," + KEY_FEED_PLAYBACK_SPEED + " REAL DEFAULT " + SPEED_USE_GLOBAL + ")"; @@ -383,7 +383,7 @@ public class PodDBAdapter { } else { values.put(KEY_HIDE, ""); } - values.put(KEY_SORT_ORDER, toCode(feed.getSortOrder())); + values.put(KEY_SORT_ORDER, toCodeString(feed.getSortOrder())); values.put(KEY_LAST_UPDATE_FAILED, feed.hasLastUpdateFailed()); if (feed.getId() == 0) { // Create new entry @@ -424,7 +424,7 @@ public class PodDBAdapter { public void setFeedItemSortOrder(long feedId, @Nullable SortOrder sortOrder) { ContentValues values = new ContentValues(); - values.put(KEY_SORT_ORDER, toCode(sortOrder)); + values.put(KEY_SORT_ORDER, toCodeString(sortOrder)); db.update(TABLE_NAME_FEEDS, values, KEY_ID + "=?", new String[]{String.valueOf(feedId)}); } diff --git a/core/src/main/java/de/danoeh/antennapod/core/util/SortOrder.java b/core/src/main/java/de/danoeh/antennapod/core/util/SortOrder.java index b604e7f8e..96a18506d 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/util/SortOrder.java +++ b/core/src/main/java/de/danoeh/antennapod/core/util/SortOrder.java @@ -1,5 +1,7 @@ package de.danoeh.antennapod.core.util; +import android.text.TextUtils; + import androidx.annotation.NonNull; import androidx.annotation.Nullable; @@ -26,9 +28,6 @@ public enum SortOrder { INTRA_FEED, INTER_FEED; } - // The constant SHOULD NEVER be changed, as it is used in db DDLs - public static final int CODE_UNSPECIFIED = 0; - public final int code; @NonNull @@ -52,10 +51,11 @@ public enum SortOrder { } @Nullable - public static SortOrder fromCode(int code) { - if (code == CODE_UNSPECIFIED) { + public static SortOrder fromCodeString(@Nullable String codeStr) { + if (TextUtils.isEmpty(codeStr)) { return null; } + int code = Integer.parseInt(codeStr); for (SortOrder sortOrder : values()) { if (sortOrder.code == code) { return sortOrder; @@ -64,7 +64,8 @@ public enum SortOrder { throw new IllegalArgumentException("Unsupported code: " + code); } - public static int toCode(@Nullable SortOrder sortOrder) { - return sortOrder != null ? sortOrder.code : CODE_UNSPECIFIED; + @Nullable + public static String toCodeString(@Nullable SortOrder sortOrder) { + return sortOrder != null ? Integer.toString(sortOrder.code) : null; } } |