2020-11-20 15:38:08 +01:00
|
|
|
package com.cappielloantonio.play;
|
|
|
|
|
|
|
|
|
|
import android.app.Application;
|
|
|
|
|
import android.content.Context;
|
2021-04-12 17:56:09 +02:00
|
|
|
import android.content.SharedPreferences;
|
|
|
|
|
|
|
|
|
|
import androidx.preference.PreferenceManager;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2021-08-14 16:08:08 +02:00
|
|
|
import com.balsikandar.crashreporter.CrashReporter;
|
2020-11-20 15:38:08 +01:00
|
|
|
import com.cappielloantonio.play.helper.ThemeHelper;
|
2021-07-24 14:49:13 +02:00
|
|
|
import com.cappielloantonio.play.subsonic.Subsonic;
|
|
|
|
|
import com.cappielloantonio.play.subsonic.SubsonicPreferences;
|
2020-11-20 15:38:08 +01:00
|
|
|
import com.cappielloantonio.play.util.PreferenceUtil;
|
|
|
|
|
|
|
|
|
|
public class App extends Application {
|
|
|
|
|
private static final String TAG = "App";
|
|
|
|
|
private static App instance;
|
2021-07-24 14:49:13 +02:00
|
|
|
private static Subsonic subsonic;
|
2020-11-20 15:38:08 +01:00
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
public void onCreate() {
|
|
|
|
|
super.onCreate();
|
2021-12-21 13:09:50 +01:00
|
|
|
|
2021-08-14 16:08:08 +02:00
|
|
|
CrashReporter.initialize(this);
|
2020-11-20 15:38:08 +01:00
|
|
|
|
2021-04-12 17:56:09 +02:00
|
|
|
SharedPreferences sharedPreferences = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
|
2021-12-06 11:10:28 +01:00
|
|
|
String themePref = sharedPreferences.getString(PreferenceUtil.THEME, ThemeHelper.DEFAULT_MODE);
|
2021-04-12 17:56:09 +02:00
|
|
|
ThemeHelper.applyTheme(themePref);
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public static App getInstance() {
|
|
|
|
|
if (instance == null) {
|
|
|
|
|
instance = new App();
|
|
|
|
|
}
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
2021-07-24 19:58:17 +02:00
|
|
|
public static Subsonic getSubsonicClientInstance(Context context, boolean override) {
|
|
|
|
|
if (subsonic == null || override) {
|
2021-07-24 14:49:13 +02:00
|
|
|
subsonic = getSubsonicClient(context);
|
|
|
|
|
}
|
|
|
|
|
return subsonic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static Subsonic getSubsonicClient(Context context) {
|
|
|
|
|
String server = PreferenceUtil.getInstance(context).getServer();
|
|
|
|
|
String username = PreferenceUtil.getInstance(context).getUser();
|
|
|
|
|
String password = PreferenceUtil.getInstance(context).getPassword();
|
2021-07-28 09:20:22 +02:00
|
|
|
String token = PreferenceUtil.getInstance(context).getToken();
|
|
|
|
|
String salt = PreferenceUtil.getInstance(context).getSalt();
|
2021-07-24 14:49:13 +02:00
|
|
|
|
2021-07-28 18:28:47 +02:00
|
|
|
SubsonicPreferences preferences = new SubsonicPreferences();
|
|
|
|
|
preferences.setServerUrl(server);
|
|
|
|
|
preferences.setUsername(username);
|
|
|
|
|
preferences.setAuthentication(password, token, salt);
|
2021-07-24 14:49:13 +02:00
|
|
|
|
2021-08-23 23:00:56 +02:00
|
|
|
return new Subsonic(context, preferences);
|
2021-07-24 14:49:13 +02:00
|
|
|
}
|
2020-11-20 15:38:08 +01:00
|
|
|
}
|