use the http responses directly for object creation
This commit is contained in:
parent
af37f7b307
commit
420b0dff79
3 changed files with 20 additions and 15 deletions
|
|
@ -100,9 +100,10 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
App.getApiClient().ChangeServerLocation(server);
|
||||
App.getApiClient().AuthenticateUserAsync(username, password, new Response<AuthenticationResult>() {
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
if (result.getAccessToken() == null) return;
|
||||
check(server, result.getUser().getId(), result.getAccessToken());
|
||||
public void onResponse(AuthenticationResult authenticationResult) {
|
||||
if (authenticationResult.getAccessToken() != null) {
|
||||
check(authenticationResult);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -119,13 +120,13 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
});
|
||||
}
|
||||
|
||||
private void check(String url, String name, String token) {
|
||||
private void check(AuthenticationResult authenticationResult) {
|
||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||
@Override
|
||||
public void onResponse(SystemInfo result) {
|
||||
if (result.getVersion().charAt(0) == '1') {
|
||||
Server server = new Server(result.getServerName(), url);
|
||||
User user = new User(server.id, name, token);
|
||||
Server server = new Server(result);
|
||||
User user = new User(authenticationResult);
|
||||
|
||||
App.getDatabase().serverDao().insertServer(server);
|
||||
App.getDatabase().userDao().insertUser(user);
|
||||
|
|
|
|||
|
|
@ -4,6 +4,8 @@ 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")
|
||||
|
|
@ -19,10 +21,10 @@ public class Server {
|
|||
this.id = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public Server(String name, String url) {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
public Server(SystemInfo systemInfo) {
|
||||
this.id = systemInfo.getId();
|
||||
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.name = systemInfo.getServerName();
|
||||
this.url = systemInfo.getWanAddress();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,6 +5,8 @@ import androidx.room.Entity;
|
|||
import androidx.room.ForeignKey;
|
||||
import androidx.room.PrimaryKey;
|
||||
|
||||
import org.jellyfin.apiclient.model.users.AuthenticationResult;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
@Entity(tableName = "users")
|
||||
|
|
@ -28,12 +30,12 @@ public class User {
|
|||
this.id = UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
public User(String serverId, String name, String token) {
|
||||
this.id = UUID.randomUUID().toString();
|
||||
public User(AuthenticationResult result) {
|
||||
this.id = result.getUser().getId();
|
||||
|
||||
this.serverId = serverId;
|
||||
this.serverId = result.getServerId();
|
||||
|
||||
this.name = name;
|
||||
this.token = token;
|
||||
this.name = result.getUser().getName();
|
||||
this.token = result.getAccessToken();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue