mirror of
https://codeberg.org/Bazsalanszky/Infinity-For-Lemmy.git
synced 2024-11-10 04:37:25 +01:00
Fixed a bug that if multiple accounts have the same subscribed subreddits and users, only one account's subscribed subreddits and users will be properly saved.
This commit is contained in:
parent
c9cbc6b5ff
commit
518b6f8471
@ -2,6 +2,7 @@ package ml.docilealligator.infinityforreddit;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.room.Database;
|
||||
import androidx.room.Room;
|
||||
import androidx.room.RoomDatabase;
|
||||
@ -19,7 +20,7 @@ import ml.docilealligator.infinityforreddit.SubscribedUserDatabase.SubscribedUse
|
||||
import ml.docilealligator.infinityforreddit.User.UserDao;
|
||||
import ml.docilealligator.infinityforreddit.User.UserData;
|
||||
|
||||
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, SubscribedUserData.class}, version = 2)
|
||||
@Database(entities = {Account.class, SubredditData.class, SubscribedSubredditData.class, UserData.class, SubscribedUserData.class}, version = 3)
|
||||
public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
private static RedditDataRoomDatabase INSTANCE;
|
||||
|
||||
@ -29,7 +30,7 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
if (INSTANCE == null) {
|
||||
INSTANCE = Room.databaseBuilder(context.getApplicationContext(),
|
||||
RedditDataRoomDatabase.class, "reddit_data")
|
||||
.addMigrations(MIGRATION_1_2)
|
||||
.addMigrations(MIGRATION_1_2, MIGRATION_2_3)
|
||||
.build();
|
||||
}
|
||||
}
|
||||
@ -56,4 +57,27 @@ public abstract class RedditDataRoomDatabase extends RoomDatabase {
|
||||
+ " ADD COLUMN is_favorite INTEGER DEFAULT 0 NOT NULL");
|
||||
}
|
||||
};
|
||||
|
||||
private static final Migration MIGRATION_2_3 = new Migration(2, 3) {
|
||||
@Override
|
||||
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||
database.execSQL("CREATE TABLE subscribed_subreddits_temp " +
|
||||
"(id TEXT NOT NULL, name TEXT, icon TEXT, username TEXT NOT NULL, " +
|
||||
"is_favorite INTEGER NOT NULL, PRIMARY KEY(id, username), " +
|
||||
"FOREIGN KEY(username) REFERENCES accounts(username) ON DELETE CASCADE)");
|
||||
database.execSQL(
|
||||
"INSERT INTO subscribed_subreddits_temp SELECT * FROM subscribed_subreddits");
|
||||
database.execSQL("DROP TABLE subscribed_subreddits");
|
||||
database.execSQL("ALTER TABLE subscribed_subreddits_temp RENAME TO subscribed_subreddits");
|
||||
|
||||
database.execSQL("CREATE TABLE subscribed_users_temp " +
|
||||
"(name TEXT NOT NULL, icon TEXT, username TEXT NOT NULL, " +
|
||||
"is_favorite INTEGER NOT NULL, PRIMARY KEY(name, username), " +
|
||||
"FOREIGN KEY(username) REFERENCES accounts(username) ON DELETE CASCADE)");
|
||||
database.execSQL(
|
||||
"INSERT INTO subscribed_users_temp SELECT * FROM subscribed_users");
|
||||
database.execSQL("DROP TABLE subscribed_users");
|
||||
database.execSQL("ALTER TABLE subscribed_users_temp RENAME TO subscribed_users");
|
||||
}
|
||||
};
|
||||
}
|
||||
|
@ -4,15 +4,13 @@ import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Account.Account;
|
||||
|
||||
@Entity(tableName = "subscribed_subreddits", foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||
@Entity(tableName = "subscribed_subreddits", primaryKeys = {"id", "username"},
|
||||
foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||
public class SubscribedSubredditData {
|
||||
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
@ColumnInfo(name = "id")
|
||||
private String id;
|
||||
@ -20,12 +18,13 @@ public class SubscribedSubredditData {
|
||||
private String name;
|
||||
@ColumnInfo(name = "icon")
|
||||
private String iconUrl;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "username")
|
||||
private String username;
|
||||
@ColumnInfo(name = "is_favorite")
|
||||
private boolean favorite;
|
||||
|
||||
public SubscribedSubredditData(@NonNull String id, String name, String iconUrl, String username,
|
||||
public SubscribedSubredditData(@NonNull String id, String name, String iconUrl, @NonNull String username,
|
||||
boolean favorite) {
|
||||
this.id = id;
|
||||
this.name = name;
|
||||
@ -47,11 +46,12 @@ public class SubscribedSubredditData {
|
||||
return iconUrl;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
public void setUsername(@NonNull String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
@ -4,25 +4,25 @@ import androidx.annotation.NonNull;
|
||||
import androidx.room.ColumnInfo;
|
||||
import androidx.room.Entity;
|
||||
import androidx.room.ForeignKey;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import ml.docilealligator.infinityforreddit.Account.Account;
|
||||
|
||||
@Entity(tableName = "subscribed_users", foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||
@Entity(tableName = "subscribed_users", primaryKeys = {"name", "username"},
|
||||
foreignKeys = @ForeignKey(entity = Account.class, parentColumns = "username",
|
||||
childColumns = "username", onDelete = ForeignKey.CASCADE))
|
||||
public class SubscribedUserData {
|
||||
@PrimaryKey
|
||||
@NonNull
|
||||
@ColumnInfo(name = "name")
|
||||
private String name;
|
||||
@ColumnInfo(name = "icon")
|
||||
private String iconUrl;
|
||||
@NonNull
|
||||
@ColumnInfo(name = "username")
|
||||
private String username;
|
||||
@ColumnInfo(name = "is_favorite")
|
||||
private boolean favorite;
|
||||
|
||||
public SubscribedUserData(@NonNull String name, String iconUrl, String username, boolean favorite) {
|
||||
public SubscribedUserData(@NonNull String name, String iconUrl, @NonNull String username, boolean favorite) {
|
||||
this.name = name;
|
||||
this.iconUrl = iconUrl;
|
||||
this.username = username;
|
||||
@ -38,11 +38,12 @@ public class SubscribedUserData {
|
||||
return iconUrl;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public void setUsername(String username) {
|
||||
public void setUsername(@NonNull String username) {
|
||||
this.username = username;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user