Feed Sort Order DB column: changed from Integer to Text, to allow flexibility of multiple sorts without DB schema change
This commit is contained in:
parent
7687ffb08e
commit
baec984c0f
@ -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
|
||||
);
|
||||
|
||||
|
@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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)});
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user