update the api client and several other dependencies
This commit is contained in:
parent
85952d670d
commit
9f973bb1c6
6 changed files with 94 additions and 122 deletions
|
|
@ -10,6 +10,7 @@ android {
|
|||
versionCode 5
|
||||
versionName '1.1.0'
|
||||
|
||||
multiDexEnabled true
|
||||
vectorDrawables {
|
||||
useSupportLibrary = true
|
||||
}
|
||||
|
|
@ -44,16 +45,16 @@ android {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'com.github.jellyfin.jellyfin-apiclient-java:android:0.6.3'
|
||||
implementation 'com.github.jellyfin.jellyfin-apiclient-java:android:0.7.3'
|
||||
|
||||
implementation 'com.google.android.exoplayer:exoplayer:2.11.4'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation 'com.google.android.material:material:1.2.0'
|
||||
|
||||
implementation 'androidx.core:core:1.3.1'
|
||||
implementation 'androidx.media:media:1.1.0'
|
||||
implementation 'androidx.fragment:fragment:1.2.5'
|
||||
implementation 'androidx.legacy:legacy-support-v13:1.0.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0'
|
||||
implementation 'androidx.recyclerview:recyclerview:1.1.0'
|
||||
implementation 'androidx.gridlayout:gridlayout:1.0.0'
|
||||
implementation 'androidx.cardview:cardview:1.0.0'
|
||||
|
|
@ -61,7 +62,7 @@ dependencies {
|
|||
implementation 'androidx.annotation:annotation:1.1.0'
|
||||
implementation 'androidx.percentlayout:percentlayout:1.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
|
||||
|
||||
implementation 'com.github.kabouzeid:app-theme-helper:1.3.10'
|
||||
implementation 'com.github.kabouzeid:RecyclerView-FastScroll:1.0.16-kmod'
|
||||
|
|
@ -74,11 +75,12 @@ dependencies {
|
|||
|
||||
implementation 'com.heinrichreimersoftware:material-intro:1.6'
|
||||
implementation 'com.h6ah4i.android.widget.advrecyclerview:advrecyclerview:0.11.0'
|
||||
implementation 'com.android.support:multidex:1.0.3'
|
||||
|
||||
implementation 'com.jakewharton:butterknife:10.1.0'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.1.0'
|
||||
implementation 'com.jakewharton:butterknife:10.2.0'
|
||||
annotationProcessor 'com.jakewharton:butterknife-compiler:10.2.0'
|
||||
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.5.0'
|
||||
implementation 'com.squareup.retrofit2:retrofit:2.6.2'
|
||||
implementation 'com.squareup.retrofit2:converter-gson:2.5.0'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:3.8.0'
|
||||
|
|
|
|||
|
|
@ -1,22 +1,23 @@
|
|||
package com.dkanada.gramophone;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.Application;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.provider.Settings;
|
||||
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
import com.dkanada.gramophone.shortcuts.DynamicShortcutManager;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.AndroidConnectionManager;
|
||||
import org.jellyfin.apiclient.interaction.AndroidDevice;
|
||||
import org.jellyfin.apiclient.interaction.ApiClient;
|
||||
import org.jellyfin.apiclient.interaction.ApiEventListener;
|
||||
import org.jellyfin.apiclient.interaction.connectionmanager.ConnectionManager;
|
||||
import org.jellyfin.apiclient.interaction.VolleyHttpClient;
|
||||
import org.jellyfin.apiclient.interaction.device.IDevice;
|
||||
import org.jellyfin.apiclient.interaction.http.IAsyncHttpClient;
|
||||
import org.jellyfin.apiclient.model.logging.ILogger;
|
||||
import org.jellyfin.apiclient.model.serialization.IJsonSerializer;
|
||||
import org.jellyfin.apiclient.model.session.ClientCapabilities;
|
||||
import org.jellyfin.apiclient.logging.AndroidLogger;
|
||||
import org.jellyfin.apiclient.logging.ILogger;
|
||||
|
||||
public class App extends Application {
|
||||
private static App app;
|
||||
|
|
@ -26,7 +27,9 @@ public class App extends Application {
|
|||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
|
||||
app = this;
|
||||
apiClient = createApiClient(this);
|
||||
|
||||
// default theme
|
||||
if (!ThemeStore.isConfigured(this, 1)) {
|
||||
|
|
@ -39,25 +42,27 @@ public class App extends Application {
|
|||
}
|
||||
}
|
||||
|
||||
public static ConnectionManager getConnectionManager(Context context, IJsonSerializer jsonSerializer, ILogger logger, IAsyncHttpClient httpClient) {
|
||||
public static ApiClient createApiClient(Context context) {
|
||||
String appName = context.getString(R.string.app_name);
|
||||
String appVersion = BuildConfig.VERSION_NAME;
|
||||
|
||||
IDevice device = new AndroidDevice(context);
|
||||
ClientCapabilities capabilities = new ClientCapabilities();
|
||||
@SuppressLint("HardwareIds")
|
||||
String deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
|
||||
String deviceName = android.os.Build.MODEL;
|
||||
String server = PreferenceUtil.getInstance(context).getServer();
|
||||
|
||||
ILogger logger = new AndroidLogger(context.getClass().getName());
|
||||
IAsyncHttpClient httpClient = new VolleyHttpClient(logger, context);
|
||||
IDevice device = new AndroidDevice(deviceId, deviceName);
|
||||
ApiEventListener eventListener = new ApiEventListener();
|
||||
|
||||
return new AndroidConnectionManager(context, jsonSerializer, logger, httpClient, appName, appVersion, device, capabilities, eventListener);
|
||||
return new ApiClient(httpClient, logger, server, appName, appVersion, device, eventListener);
|
||||
}
|
||||
|
||||
public static ApiClient getApiClient() {
|
||||
return apiClient;
|
||||
}
|
||||
|
||||
public static void setApiClient(ApiClient client) {
|
||||
apiClient = client;
|
||||
}
|
||||
|
||||
public static App getInstance() {
|
||||
return app;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,12 +13,6 @@ import com.dkanada.gramophone.R;
|
|||
import com.dkanada.gramophone.ui.activities.LoginActivity;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
||||
import org.jellyfin.apiclient.interaction.VolleyHttpClient;
|
||||
import org.jellyfin.apiclient.interaction.http.IAsyncHttpClient;
|
||||
import org.jellyfin.apiclient.logging.AndroidLogger;
|
||||
import org.jellyfin.apiclient.model.logging.ILogger;
|
||||
import org.jellyfin.apiclient.model.serialization.GsonJsonSerializer;
|
||||
import org.jellyfin.apiclient.model.serialization.IJsonSerializer;
|
||||
|
||||
public class ConfirmLogoutDialog extends DialogFragment {
|
||||
@NonNull
|
||||
|
|
@ -36,12 +30,8 @@ public class ConfirmLogoutDialog extends DialogFragment {
|
|||
.negativeText(android.R.string.cancel)
|
||||
.onPositive((dialog, which) -> {
|
||||
if (getActivity() == null) return;
|
||||
App.getApiClient().Logout(new EmptyResponse());
|
||||
|
||||
IJsonSerializer jsonSerializer = new GsonJsonSerializer();
|
||||
ILogger logger = new AndroidLogger(getActivity().getClass().getName());
|
||||
IAsyncHttpClient httpClient = new VolleyHttpClient(logger, getActivity());
|
||||
|
||||
App.getConnectionManager(getActivity(), jsonSerializer, logger, httpClient).Logout(new EmptyResponse());
|
||||
Intent intent = new Intent(getActivity(), LoginActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
this.startActivity(intent);
|
||||
|
|
|
|||
|
|
@ -15,32 +15,17 @@ import androidx.appcompat.widget.Toolbar;
|
|||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
import com.kabouzeid.appthemehelper.ThemeStore;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.AndroidCredentialProvider;
|
||||
import org.jellyfin.apiclient.interaction.ConnectionResult;
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.interaction.VolleyHttpClient;
|
||||
import org.jellyfin.apiclient.interaction.connectionmanager.ConnectionManager;
|
||||
import org.jellyfin.apiclient.interaction.http.IAsyncHttpClient;
|
||||
import org.jellyfin.apiclient.logging.AndroidLogger;
|
||||
import org.jellyfin.apiclient.model.apiclient.ServerCredentials;
|
||||
import org.jellyfin.apiclient.model.apiclient.ServerInfo;
|
||||
import org.jellyfin.apiclient.model.logging.ILogger;
|
||||
import org.jellyfin.apiclient.model.serialization.GsonJsonSerializer;
|
||||
import org.jellyfin.apiclient.model.serialization.IJsonSerializer;
|
||||
import org.jellyfin.apiclient.model.system.SystemInfo;
|
||||
import org.jellyfin.apiclient.model.users.AuthenticationResult;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
|
||||
public class LoginActivity extends AbsBaseActivity implements View.OnClickListener {
|
||||
public String TAG = SplashActivity.class.getSimpleName();
|
||||
public AndroidCredentialProvider credentialProvider;
|
||||
|
||||
@BindView(R.id.toolbar)
|
||||
Toolbar toolbar;
|
||||
@BindView(R.id.username)
|
||||
|
|
@ -95,13 +80,6 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
public void onClick(View v) {
|
||||
if (v == login) {
|
||||
final Context context = this;
|
||||
IJsonSerializer jsonSerializer = new GsonJsonSerializer();
|
||||
ILogger logger = new AndroidLogger(TAG);
|
||||
IAsyncHttpClient httpClient = new VolleyHttpClient(logger, this);
|
||||
|
||||
credentialProvider = new AndroidCredentialProvider(jsonSerializer, this, logger);
|
||||
ConnectionManager connectionManager = App.getConnectionManager(context, jsonSerializer, logger, httpClient);
|
||||
|
||||
if (server.getText().toString().trim().length() == 0) {
|
||||
Toast.makeText(context, context.getResources().getString(R.string.error_login_empty_addr), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
|
|
@ -112,24 +90,12 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
return;
|
||||
}
|
||||
|
||||
connectionManager.Connect(server.getText().toString(), new Response<ConnectionResult>() {
|
||||
@Override
|
||||
public void onResponse(ConnectionResult result) {
|
||||
App.setApiClient(result.getApiClient());
|
||||
ServerCredentials serverCredentials = new ServerCredentials();
|
||||
List<ServerInfo> servers = result.getServers();
|
||||
|
||||
if (servers.size() < 1) {
|
||||
Toast.makeText(context, context.getResources().getString(R.string.error_unreachable_server), Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
|
||||
serverCredentials.AddOrUpdateServer(servers.get(0));
|
||||
App.getApiClient().ChangeServerLocation(server.getText().toString());
|
||||
App.getApiClient().AuthenticateUserAsync(username.getText().toString(), password.getText().toString(), new Response<AuthenticationResult>() {
|
||||
@Override
|
||||
public void onResponse(AuthenticationResult result) {
|
||||
if (result.getAccessToken() == null) return;
|
||||
check(context, serverCredentials, result);
|
||||
check(context, server.getText().toString(), result.getUser().getId(), result.getAccessToken());
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -138,17 +104,16 @@ public class LoginActivity extends AbsBaseActivity implements View.OnClickListen
|
|||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public void check(Context context, ServerCredentials serverCredentials, AuthenticationResult authenticationResult) {
|
||||
public void check(Context context, String server, String user, String token) {
|
||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||
@Override
|
||||
public void onResponse(SystemInfo result) {
|
||||
if (Integer.parseInt(result.getVersion().substring(0, 1)) == 1) {
|
||||
serverCredentials.GetServer(authenticationResult.getServerId()).setAccessToken(authenticationResult.getAccessToken());
|
||||
credentialProvider.SaveCredentials(serverCredentials);
|
||||
PreferenceUtil.getInstance(context).setServer(server);
|
||||
PreferenceUtil.getInstance(context).setUser(user);
|
||||
PreferenceUtil.getInstance(context).setToken(token);
|
||||
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
|
|
|
|||
|
|
@ -12,26 +12,12 @@ import android.provider.Settings;
|
|||
import com.dkanada.gramophone.App;
|
||||
import com.dkanada.gramophone.R;
|
||||
import com.dkanada.gramophone.ui.activities.base.AbsBaseActivity;
|
||||
import com.dkanada.gramophone.util.PreferenceUtil;
|
||||
|
||||
import org.jellyfin.apiclient.interaction.AndroidCredentialProvider;
|
||||
import org.jellyfin.apiclient.interaction.ConnectionResult;
|
||||
import org.jellyfin.apiclient.interaction.EmptyResponse;
|
||||
import org.jellyfin.apiclient.interaction.Response;
|
||||
import org.jellyfin.apiclient.interaction.VolleyHttpClient;
|
||||
import org.jellyfin.apiclient.interaction.connectionmanager.ConnectionManager;
|
||||
import org.jellyfin.apiclient.interaction.http.IAsyncHttpClient;
|
||||
import org.jellyfin.apiclient.logging.AndroidLogger;
|
||||
import org.jellyfin.apiclient.model.apiclient.ConnectionState;
|
||||
import org.jellyfin.apiclient.model.logging.ILogger;
|
||||
import org.jellyfin.apiclient.model.serialization.GsonJsonSerializer;
|
||||
import org.jellyfin.apiclient.model.serialization.IJsonSerializer;
|
||||
import org.jellyfin.apiclient.model.system.SystemInfo;
|
||||
|
||||
public class SplashActivity extends AbsBaseActivity {
|
||||
public static final String TAG = SplashActivity.class.getSimpleName();
|
||||
|
||||
public AndroidCredentialProvider credentialProvider;
|
||||
public ConnectionManager connectionManager;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
|
@ -41,13 +27,6 @@ public class SplashActivity extends AbsBaseActivity {
|
|||
setStatusbarColorAuto();
|
||||
setNavigationbarColorAuto();
|
||||
setTaskDescriptionColorAuto();
|
||||
|
||||
IJsonSerializer jsonSerializer = new GsonJsonSerializer();
|
||||
ILogger logger = new AndroidLogger(TAG);
|
||||
IAsyncHttpClient httpClient = new VolleyHttpClient(logger, this);
|
||||
|
||||
credentialProvider = new AndroidCredentialProvider(jsonSerializer, this, logger);
|
||||
connectionManager = App.getConnectionManager(this, jsonSerializer, logger, httpClient);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -95,28 +74,28 @@ public class SplashActivity extends AbsBaseActivity {
|
|||
}
|
||||
|
||||
public void login() {
|
||||
if (credentialProvider.GetCredentials().getServers().size() == 0) {
|
||||
if (PreferenceUtil.getInstance(this).getToken() == null) {
|
||||
Intent intent = new Intent(this, LoginActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
} else {
|
||||
final Context context = this;
|
||||
connectionManager.Connect(credentialProvider.GetCredentials().getServers().get(0), new Response<ConnectionResult>() {
|
||||
|
||||
App.getApiClient().ChangeServerLocation(PreferenceUtil.getInstance(this).getServer());
|
||||
App.getApiClient().SetAuthenticationInfo(PreferenceUtil.getInstance(this).getToken(), PreferenceUtil.getInstance(this).getUser());
|
||||
App.getApiClient().GetSystemInfoAsync(new Response<SystemInfo>() {
|
||||
@Override
|
||||
public void onResponse(ConnectionResult result) {
|
||||
if (result.getState() != ConnectionState.SignedIn) {
|
||||
connectionManager.DeleteServer(credentialProvider.GetCredentials().getServers().get(0).getId(), new EmptyResponse());
|
||||
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
context.startActivity(intent);
|
||||
} else {
|
||||
App.setApiClient(result.getApiClient());
|
||||
|
||||
public void onResponse(SystemInfo result) {
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
context.startActivity(intent);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception exception) {
|
||||
Intent intent = new Intent(context, LoginActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,8 +18,6 @@ import com.dkanada.gramophone.model.CategoryInfo;
|
|||
import com.dkanada.gramophone.model.DirectPlayCodec;
|
||||
import com.dkanada.gramophone.ui.fragments.player.NowPlayingScreen;
|
||||
|
||||
import org.jellyfin.apiclient.model.dto.BaseItemDto;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
|
|
@ -27,7 +25,10 @@ import java.util.List;
|
|||
import java.util.Set;
|
||||
|
||||
public final class PreferenceUtil {
|
||||
public static final String LIBRARIES = "libraries";
|
||||
public static final String SERVER = "server";
|
||||
public static final String USER = "user";
|
||||
public static final String TOKEN = "token";
|
||||
|
||||
public static final String CATEGORIES = "categories";
|
||||
public static final String PAGE_SIZE = "page_size";
|
||||
public static final String REMEMBER_LAST_TAB = "remember_last_tab";
|
||||
|
|
@ -460,4 +461,34 @@ public final class PreferenceUtil {
|
|||
editor.putStringSet(DIRECT_PLAY_CODECS, codecNames);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getServer() {
|
||||
return mPreferences.getString(SERVER, "https://jellyfin.org");
|
||||
}
|
||||
|
||||
public void setServer(String server) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(SERVER, server);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getUser() {
|
||||
return mPreferences.getString(USER, "");
|
||||
}
|
||||
|
||||
public void setUser(String user) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(USER, user);
|
||||
editor.apply();
|
||||
}
|
||||
|
||||
public String getToken() {
|
||||
return mPreferences.getString(TOKEN, "");
|
||||
}
|
||||
|
||||
public void setToken(String token) {
|
||||
final SharedPreferences.Editor editor = mPreferences.edit();
|
||||
editor.putString(TOKEN, token);
|
||||
editor.apply();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue