add servers to the new database
This commit is contained in:
parent
a45ae46d31
commit
eb5b4787ed
7 changed files with 82 additions and 31 deletions
|
|
@ -14,6 +14,7 @@ import com.dkanada.gramophone.App;
|
|||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.databinding.ActivityLoginBinding;
|
||||
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
||||
import com.dkanada.gramophone.model.Server;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
|
||||
|
|
@ -117,14 +118,14 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
});
|
||||
}
|
||||
|
||||
private void check(String server, String user, String token) {
|
||||
private void check(String url, String user, String token) {
|
||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||
@Override
|
||||
public void onResponse(SystemInfo result) {
|
||||
if (result.getVersion().charAt(0) == '1') {
|
||||
PreferenceUtil.getInstance(LoginActivity.this).setServer(server);
|
||||
PreferenceUtil.getInstance(LoginActivity.this).setUser(user);
|
||||
PreferenceUtil.getInstance(LoginActivity.this).setToken(token);
|
||||
Server server = new Server(result.getServerName(), url, user, token);
|
||||
PreferenceUtil.getInstance(LoginActivity.this).setServer(server.id);
|
||||
App.getDatabase().serverDao().insertServer(server);
|
||||
|
||||
Intent intent = new Intent(LoginActivity.this, SplashActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@ import androidx.annotation.RequiresApi;
|
|||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.activities.base.AbsBaseActivity;
|
||||
import com.dkanada.gramophone.model.Server;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
||||
|
|
@ -75,13 +76,14 @@ public class SplashActivity extends AbsBaseActivity {
|
|||
}
|
||||
|
||||
public void login() {
|
||||
if (PreferenceUtil.getInstance(this).getToken() == null) {
|
||||
if (PreferenceUtil.getInstance(this).getServer().isEmpty()) {
|
||||
launchLoginActivity();
|
||||
} else {
|
||||
final Context context = this;
|
||||
Server server = App.getDatabase().serverDao().getServer(PreferenceUtil.getInstance(this).getServer());
|
||||
|
||||
App.getApiClient().ChangeServerLocation(PreferenceUtil.getInstance(this).getServer());
|
||||
App.getApiClient().SetAuthenticationInfo(PreferenceUtil.getInstance(this).getToken(), PreferenceUtil.getInstance(this).getUser());
|
||||
App.getApiClient().ChangeServerLocation(server.url);
|
||||
App.getApiClient().SetAuthenticationInfo(server.token, server.user);
|
||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||
@Override
|
||||
public void onResponse(SystemInfo result) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue