remove servers from database
This commit is contained in:
parent
ca84276165
commit
8a73fcf6a4
7 changed files with 25 additions and 86 deletions
|
|
@ -55,6 +55,7 @@ public class App extends Application {
|
||||||
.allowMainThreadQueries()
|
.allowMainThreadQueries()
|
||||||
.addMigrations(JellyDatabase.Migration2)
|
.addMigrations(JellyDatabase.Migration2)
|
||||||
.addMigrations(JellyDatabase.Migration3)
|
.addMigrations(JellyDatabase.Migration3)
|
||||||
|
.addMigrations(JellyDatabase.Migration4)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -14,7 +14,6 @@ import com.dkanada.gramophone.App;
|
||||||
import com.dkanada.gramophone.R;
|
import com.dkanada.gramophone.R;
|
||||||
import com.dkanada.gramophone.databinding.ActivityLoginBinding;
|
import com.dkanada.gramophone.databinding.ActivityLoginBinding;
|
||||||
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
||||||
import com.dkanada.gramophone.model.Server;
|
|
||||||
import com.dkanada.gramophone.model.User;
|
import com.dkanada.gramophone.model.User;
|
||||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||||
|
|
@ -102,7 +101,7 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(AuthenticationResult authenticationResult) {
|
public void onResponse(AuthenticationResult authenticationResult) {
|
||||||
if (authenticationResult.getAccessToken() != null) {
|
if (authenticationResult.getAccessToken() != null) {
|
||||||
check(authenticationResult);
|
check(authenticationResult, server);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -120,17 +119,15 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void check(AuthenticationResult authenticationResult) {
|
private void check(AuthenticationResult authenticationResult, String server) {
|
||||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(SystemInfo result) {
|
public void onResponse(SystemInfo result) {
|
||||||
if (result.getVersion().charAt(0) == '1') {
|
if (result.getVersion().charAt(0) == '1') {
|
||||||
Server server = new Server(result);
|
User user = new User(authenticationResult, server);
|
||||||
User user = new User(authenticationResult);
|
|
||||||
|
|
||||||
App.getDatabase().serverDao().insertServer(server);
|
|
||||||
App.getDatabase().userDao().insertUser(user);
|
App.getDatabase().userDao().insertUser(user);
|
||||||
PreferenceUtil.getInstance(LoginActivity.this).setServer(server.id);
|
PreferenceUtil.getInstance(LoginActivity.this).setServer(user.server);
|
||||||
PreferenceUtil.getInstance(LoginActivity.this).setUser(user.id);
|
PreferenceUtil.getInstance(LoginActivity.this).setUser(user.id);
|
||||||
|
|
||||||
Intent intent = new Intent(LoginActivity.this, SplashActivity.class);
|
Intent intent = new Intent(LoginActivity.this, SplashActivity.class);
|
||||||
|
|
|
||||||
|
|
@ -13,7 +13,6 @@ import androidx.annotation.RequiresApi;
|
||||||
import com.dkanada.gramophone.App;
|
import com.dkanada.gramophone.App;
|
||||||
import com.dkanada.gramophone.R;
|
import com.dkanada.gramophone.R;
|
||||||
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
||||||
import com.dkanada.gramophone.model.Server;
|
|
||||||
import com.dkanada.gramophone.model.User;
|
import com.dkanada.gramophone.model.User;
|
||||||
import com.dkanada.gramophone.util.NavigationUtil;
|
import com.dkanada.gramophone.util.NavigationUtil;
|
||||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||||
|
|
@ -80,16 +79,15 @@ public class SplashActivity extends AbsBaseActivity {
|
||||||
|
|
||||||
public void login() {
|
public void login() {
|
||||||
Context context = this;
|
Context context = this;
|
||||||
Server server = App.getDatabase().serverDao().getServer(PreferenceUtil.getInstance(this).getServer());
|
|
||||||
User user = App.getDatabase().userDao().getUser(PreferenceUtil.getInstance(this).getUser());
|
User user = App.getDatabase().userDao().getUser(PreferenceUtil.getInstance(this).getUser());
|
||||||
|
|
||||||
if (server == null || user == null) {
|
if (user == null) {
|
||||||
NavigationUtil.goToLogin(this);
|
NavigationUtil.goToLogin(this);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
App.getApiClient().ChangeServerLocation(server.url);
|
App.getApiClient().ChangeServerLocation(user.server);
|
||||||
App.getApiClient().SetAuthenticationInfo(user.token, user.name);
|
App.getApiClient().SetAuthenticationInfo(user.token, user.id);
|
||||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||||
@Override
|
@Override
|
||||||
public void onResponse(SystemInfo result) {
|
public void onResponse(SystemInfo result) {
|
||||||
|
|
|
||||||
|
|
@ -5,22 +5,19 @@ import androidx.room.RoomDatabase;
|
||||||
import androidx.room.migration.Migration;
|
import androidx.room.migration.Migration;
|
||||||
import androidx.sqlite.db.SupportSQLiteDatabase;
|
import androidx.sqlite.db.SupportSQLiteDatabase;
|
||||||
|
|
||||||
import com.dkanada.gramophone.model.Server;
|
|
||||||
import com.dkanada.gramophone.model.Song;
|
import com.dkanada.gramophone.model.Song;
|
||||||
import com.dkanada.gramophone.model.User;
|
import com.dkanada.gramophone.model.User;
|
||||||
|
|
||||||
@androidx.room.Database(
|
@androidx.room.Database(
|
||||||
entities = {
|
entities = {
|
||||||
Server.class,
|
|
||||||
Song.class,
|
Song.class,
|
||||||
QueueSong.class,
|
QueueSong.class,
|
||||||
User.class
|
User.class
|
||||||
},
|
},
|
||||||
version = 3,
|
version = 4,
|
||||||
exportSchema = false
|
exportSchema = false
|
||||||
)
|
)
|
||||||
public abstract class JellyDatabase extends RoomDatabase {
|
public abstract class JellyDatabase extends RoomDatabase {
|
||||||
public abstract ServerDao serverDao();
|
|
||||||
public abstract SongDao songDao();
|
public abstract SongDao songDao();
|
||||||
public abstract QueueSongDao queueSongDao();
|
public abstract QueueSongDao queueSongDao();
|
||||||
public abstract UserDao userDao();
|
public abstract UserDao userDao();
|
||||||
|
|
@ -44,4 +41,15 @@ public abstract class JellyDatabase extends RoomDatabase {
|
||||||
+ "serverId TEXT, name TEXT, token TEXT)");
|
+ "serverId TEXT, name TEXT, token TEXT)");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
public static final Migration Migration4 = new Migration(3, 4) {
|
||||||
|
@Override
|
||||||
|
public void migrate(@NonNull SupportSQLiteDatabase database) {
|
||||||
|
database.execSQL("DROP TABLE servers");
|
||||||
|
database.execSQL("DROP TABLE users");
|
||||||
|
|
||||||
|
database.execSQL("CREATE TABLE users (id TEXT NOT NULL PRIMARY KEY,"
|
||||||
|
+ "name TEXT, server TEXT, token TEXT)");
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,26 +0,0 @@
|
||||||
package com.dkanada.gramophone.database;
|
|
||||||
|
|
||||||
import androidx.room.Dao;
|
|
||||||
import androidx.room.Delete;
|
|
||||||
import androidx.room.Insert;
|
|
||||||
import androidx.room.OnConflictStrategy;
|
|
||||||
import androidx.room.Query;
|
|
||||||
|
|
||||||
import com.dkanada.gramophone.model.Server;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@Dao
|
|
||||||
public interface ServerDao {
|
|
||||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
|
||||||
void insertServer(Server server);
|
|
||||||
|
|
||||||
@Delete
|
|
||||||
void deleteServer(Server server);
|
|
||||||
|
|
||||||
@Query("SELECT * FROM servers")
|
|
||||||
List<Server> getServers();
|
|
||||||
|
|
||||||
@Query("SELECT * FROM servers WHERE id = :id")
|
|
||||||
Server getServer(String id);
|
|
||||||
}
|
|
||||||
|
|
@ -1,30 +0,0 @@
|
||||||
package com.dkanada.gramophone.model;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.room.Entity;
|
|
||||||
import androidx.room.PrimaryKey;
|
|
||||||
|
|
||||||
import org.jellyfin.apiclient.model.system.SystemInfo;
|
|
||||||
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
@Entity(tableName = "servers")
|
|
||||||
public class Server {
|
|
||||||
@NonNull
|
|
||||||
@PrimaryKey
|
|
||||||
public String id;
|
|
||||||
|
|
||||||
public String name;
|
|
||||||
public String url;
|
|
||||||
|
|
||||||
public Server() {
|
|
||||||
this.id = UUID.randomUUID().toString();
|
|
||||||
}
|
|
||||||
|
|
||||||
public Server(SystemInfo systemInfo) {
|
|
||||||
this.id = systemInfo.getId();
|
|
||||||
|
|
||||||
this.name = systemInfo.getServerName();
|
|
||||||
this.url = systemInfo.getWanAddress();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
@ -2,7 +2,6 @@ package com.dkanada.gramophone.model;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.room.Entity;
|
import androidx.room.Entity;
|
||||||
import androidx.room.ForeignKey;
|
|
||||||
import androidx.room.PrimaryKey;
|
import androidx.room.PrimaryKey;
|
||||||
|
|
||||||
import org.jellyfin.apiclient.model.users.AuthenticationResult;
|
import org.jellyfin.apiclient.model.users.AuthenticationResult;
|
||||||
|
|
@ -14,28 +13,20 @@ public class User {
|
||||||
@NonNull
|
@NonNull
|
||||||
@PrimaryKey
|
@PrimaryKey
|
||||||
public String id;
|
public String id;
|
||||||
|
|
||||||
@ForeignKey(
|
|
||||||
entity = Server.class,
|
|
||||||
parentColumns = {"id"},
|
|
||||||
childColumns = {"serverId"},
|
|
||||||
onDelete = ForeignKey.CASCADE
|
|
||||||
)
|
|
||||||
public String serverId;
|
|
||||||
|
|
||||||
public String name;
|
public String name;
|
||||||
|
|
||||||
|
public String server;
|
||||||
public String token;
|
public String token;
|
||||||
|
|
||||||
public User() {
|
public User() {
|
||||||
this.id = UUID.randomUUID().toString();
|
this.id = UUID.randomUUID().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public User(AuthenticationResult result) {
|
public User(AuthenticationResult result, String server) {
|
||||||
this.id = result.getUser().getId();
|
this.id = result.getUser().getId();
|
||||||
|
|
||||||
this.serverId = result.getServerId();
|
|
||||||
|
|
||||||
this.name = result.getUser().getName();
|
this.name = result.getUser().getName();
|
||||||
|
|
||||||
|
this.server = server;
|
||||||
this.token = result.getAccessToken();
|
this.token = result.getAccessToken();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue