播放器首次提交(测试版本)

This commit is contained in:
zhengcs committed 2026-08-25 18:04:56 +08:00
1 parent 27909cb061
commit 668a4f8274
74 files changed
+9836

No files matched your search

@@ -0,0 +1,87 @@
package com.example.myapplication.data;
import android.content.Context;
import androidx.room.Database;
import androidx.room.Room;
import androidx.room.RoomDatabase;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;
@Database(
entities = {IconLibraryEntity.class, ServerEntity.class},
version = 4,
exportSchema = false
)
public abstract class AppDatabase extends RoomDatabase {
public abstract IconLibraryDao iconLibraryDao();
public abstract ServerDao serverDao();
private static volatile AppDatabase instance;
private static final Migration MIGRATION_1_2 = new Migration(1, 2) {
@Override
public void migrate(SupportSQLiteDatabase db) {
db.execSQL(
"CREATE TABLE IF NOT EXISTS servers (" +
"`id` TEXT NOT NULL, " +
"`name` TEXT, " +
"`host` TEXT, " +
"`basePath` TEXT, " +
"`port` TEXT, " +
"`username` TEXT, " +
"`password` TEXT, " +
"`note` TEXT, " +
"PRIMARY KEY(`id`))"
);
db.execSQL("ALTER TABLE icon_libraries RENAME TO icon_libraries_old");
db.execSQL(
"CREATE TABLE icon_libraries (" +
"`id` TEXT NOT NULL, " +
"`name` TEXT, " +
"`sourceUrl` TEXT, " +
"`isDefault` INTEGER NOT NULL, " +
"`iconCount` INTEGER NOT NULL, " +
"PRIMARY KEY(`id`))"
);
db.execSQL(
"INSERT INTO icon_libraries (`id`, `name`, `sourceUrl`, `isDefault`, `iconCount`) " +
"SELECT old.`id`, old.`name`, old.`sourceUrl`, old.`isDefault`, " +
"COALESCE((SELECT COUNT(*) FROM icon_items WHERE libraryId = old.`id`), 0) " +
"FROM icon_libraries_old old"
);
db.execSQL("DROP TABLE IF EXISTS icon_items");
db.execSQL("DROP TABLE icon_libraries_old");
}
};
private static final Migration MIGRATION_2_3 = new Migration(2, 3) {
@Override
public void migrate(SupportSQLiteDatabase db) {
db.execSQL("ALTER TABLE servers ADD COLUMN accessToken TEXT");
db.execSQL("ALTER TABLE servers ADD COLUMN userId TEXT");
}
};
private static final Migration MIGRATION_3_4 = new Migration(3, 4) {
@Override
public void migrate(SupportSQLiteDatabase db) {
db.execSQL("ALTER TABLE servers ADD COLUMN iconUrl TEXT");
}
};
public static AppDatabase getInstance(Context context) {
if (instance == null) {
synchronized (AppDatabase.class) {
if (instance == null) {
instance = Room.databaseBuilder(
context.getApplicationContext(),
AppDatabase.class,
"emby_player.db"
).addMigrations(MIGRATION_1_2, MIGRATION_2_3, MIGRATION_3_4).build();
}
}
}
return instance;
}
}
@@ -0,0 +1,34 @@
package com.example.myapplication.data;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import androidx.room.Transaction;
import java.util.List;
@Dao
public interface IconLibraryDao {
@Query("SELECT * FROM icon_libraries ORDER BY name COLLATE NOCASE")
List<IconLibraryEntity> getLibraries();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertLibrary(IconLibraryEntity library);
@Query("UPDATE icon_libraries SET isDefault = 0 WHERE id != :excludeId")
void clearDefaultFlags(String excludeId);
@Query("UPDATE icon_libraries SET iconCount = :count WHERE id = :libraryId")
void updateIconCount(String libraryId, int count);
@Query("DELETE FROM icon_libraries WHERE id = :libraryId")
void deleteLibrary(String libraryId);
@Transaction
default void saveLibrary(IconLibraryEntity library) {
if (library.isDefault) {
clearDefaultFlags(library.id);
}
insertLibrary(library);
}
}
@@ -0,0 +1,24 @@
package com.example.myapplication.data;
import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.PrimaryKey;
@Entity(tableName = "icon_libraries")
public class IconLibraryEntity {
@PrimaryKey
@NonNull
public String id;
public String name;
public String sourceUrl;
public boolean isDefault;
public int iconCount;
public IconLibraryEntity(String id, String name, String sourceUrl, boolean isDefault, int iconCount) {
this.id = id;
this.name = name;
this.sourceUrl = sourceUrl;
this.isDefault = isDefault;
this.iconCount = iconCount;
}
}
@@ -0,0 +1,25 @@
package com.example.myapplication.data;
import androidx.room.Dao;
import androidx.room.Insert;
import androidx.room.OnConflictStrategy;
import androidx.room.Query;
import java.util.List;
@Dao
public interface ServerDao {
@Query("SELECT * FROM servers ORDER BY rowid")
List<ServerEntity> getServers();
@Query("SELECT COUNT(*) FROM servers")
int getServerCount();
@Insert(onConflict = OnConflictStrategy.REPLACE)
void insertServer(ServerEntity server);
@Query("DELETE FROM servers WHERE (id = 'server_1' AND host = 'xying.local') OR (id = 'server_2' AND host = 'film.example.com')")
void deleteLegacySampleServers();
@Query("DELETE FROM servers WHERE id = :serverId")
void deleteServer(String serverId);
}
@@ -0,0 +1,65 @@
package com.example.myapplication.data;
import androidx.annotation.NonNull;
import androidx.room.Entity;
import androidx.room.Ignore;
import androidx.room.PrimaryKey;
@Entity(tableName = "servers")
public class ServerEntity {
@PrimaryKey
@NonNull
public String id;
public String name;
public String host;
public String basePath;
public String port;
public String username;
public String password;
public String note;
public String accessToken;
public String userId;
public String iconUrl;
@Ignore
public ServerEntity(
String id,
String name,
String host,
String basePath,
String port,
String username,
String password,
String note,
String accessToken,
String userId
) {
this(id, name, host, basePath, port, username, password, note, accessToken, userId, "");
}
public ServerEntity(
String id,
String name,
String host,
String basePath,
String port,
String username,
String password,
String note,
String accessToken,
String userId,
String iconUrl
) {
this.id = id;
this.name = name;
this.host = host;
this.basePath = basePath;
this.port = port;
this.username = username;
this.password = password;
this.note = note;
this.accessToken = accessToken;
this.userId = userId;
this.iconUrl = iconUrl == null ? "" : iconUrl;
}
}