From 4053500080bc7bd49344fe6889d01d765b7de8e7 Mon Sep 17 00:00:00 2001 From: CappielloAntonio Date: Sat, 24 Jul 2021 14:49:13 +0200 Subject: [PATCH] Added Subsonic client singleton --- .../java/com/cappielloantonio/play/App.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/app/src/main/java/com/cappielloantonio/play/App.java b/app/src/main/java/com/cappielloantonio/play/App.java index 398aacbb..ba02d9eb 100644 --- a/app/src/main/java/com/cappielloantonio/play/App.java +++ b/app/src/main/java/com/cappielloantonio/play/App.java @@ -7,6 +7,8 @@ import android.content.SharedPreferences; import androidx.preference.PreferenceManager; import com.cappielloantonio.play.helper.ThemeHelper; +import com.cappielloantonio.play.subsonic.Subsonic; +import com.cappielloantonio.play.subsonic.SubsonicPreferences; import com.cappielloantonio.play.util.PreferenceUtil; import org.jellyfin.apiclient.AppInfo; @@ -23,6 +25,7 @@ public class App extends Application { private static final String TAG = "App"; private static App instance; private static ApiClient apiClient; + private static Subsonic subsonic; @Override public void onCreate() { @@ -60,4 +63,21 @@ public class App extends Application { return jellyfin.createApi(server, null, AndroidDevice.fromContext(context), new ApiEventListener()); } + + public static Subsonic getSubsonicClientInstance(Context context) { + if (subsonic == null) { + 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(); + + SubsonicPreferences preferences = new SubsonicPreferences(server, username, password); + + return new Subsonic(preferences); + } }