diff --git a/emby-lib/build.gradle.kts b/emby-lib/build.gradle.kts index 0bb6fcd68..a48c9e292 100644 --- a/emby-lib/build.gradle.kts +++ b/emby-lib/build.gradle.kts @@ -66,7 +66,6 @@ dependencies { releaseApi(libs.toothpick.javax.annotations) ksp(libs.toothpick.ksp.compiler) - implementation(libs.android.priority.jobqueue) implementation(libs.eventbus) implementation(libs.moshi) implementation(libs.retrofit.moshi) @@ -75,8 +74,6 @@ dependencies { implementation(libs.okhttp) implementation(libs.okhttp.logging.interceptor) implementation(libs.timber) - implementation(libs.easydeviceinfo.base) - implementation(libs.easydeviceinfo.common) testImplementation(libs.junit) testImplementation(libs.assertj.core) diff --git a/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/EmbyServerJob.kt b/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/EmbyServerJob.kt deleted file mode 100644 index 8b9119571..000000000 --- a/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/EmbyServerJob.kt +++ /dev/null @@ -1,35 +0,0 @@ -package us.nineworlds.serenity.emby.server - -import android.content.Context -import com.birbit.android.jobqueue.RetryConstraint -import kotlinx.coroutines.launch -import kotlinx.coroutines.runBlocking -import us.nineworlds.serenity.common.android.injection.ApplicationContext -import us.nineworlds.serenity.common.android.injection.InjectingJob -import javax.inject.Inject - -@Deprecated("Use Coroutine enabled EmbyServerDiscover class as pat of an async coroutine") -class EmbyServerJob : InjectingJob() { - - @field:[Inject ApplicationContext] - lateinit var context: Context - - override fun shouldReRunOnThrowable(throwable: Throwable, runCount: Int, maxRunCount: Int): RetryConstraint? { - return null - } - - override fun onAdded() { - } - - override fun onCancel(cancelReason: Int, throwable: Throwable?) { - } - - override fun onRun() { - runBlocking { - launch { - EmbyServerDiscover().findServers() - } - } - } - -} \ No newline at end of file diff --git a/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/api/EmbyAPIClient.kt b/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/api/EmbyAPIClient.kt index 9522ae819..e6178ce07 100644 --- a/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/api/EmbyAPIClient.kt +++ b/emby-lib/src/main/kotlin/us/nineworlds/serenity/emby/server/api/EmbyAPIClient.kt @@ -1,12 +1,10 @@ package us.nineworlds.serenity.emby.server.api import android.content.Context +import android.os.Build import android.preference.PreferenceManager -import android.util.Log import com.squareup.moshi.Moshi import com.squareup.moshi.kotlin.reflect.KotlinJsonAdapterFactory -import github.nisrulz.easydeviceinfo.base.EasyDeviceMod -import github.nisrulz.easydeviceinfo.base.EasyIdMod import me.jessyan.retrofiturlmanager.RetrofitUrlManager import okhttp3.Cache import okhttp3.OkHttpClient @@ -14,6 +12,7 @@ import okhttp3.logging.HttpLoggingInterceptor import org.joda.time.LocalDateTime import retrofit2.Retrofit import retrofit2.converter.moshi.MoshiConverterFactory +import timber.log.Timber import us.nineworlds.serenity.common.media.model.IMediaContainer import us.nineworlds.serenity.common.rest.SerenityClient import us.nineworlds.serenity.common.rest.SerenityUser @@ -21,11 +20,14 @@ import us.nineworlds.serenity.common.rest.Types import us.nineworlds.serenity.emby.BuildConfig import us.nineworlds.serenity.emby.adapters.MediaContainerAdaptor import us.nineworlds.serenity.emby.moshi.LocalDateJsonAdapter -import us.nineworlds.serenity.emby.server.model.* +import us.nineworlds.serenity.emby.server.model.AuthenticateUserByName +import us.nineworlds.serenity.emby.server.model.AuthenticationResult +import us.nineworlds.serenity.emby.server.model.Item +import us.nineworlds.serenity.emby.server.model.PublicUserInfo +import us.nineworlds.serenity.emby.server.model.QueryFilters +import us.nineworlds.serenity.emby.server.model.QueryResult import java.io.File -import java.util.* -import kotlin.collections.ArrayList -import kotlin.collections.HashMap +import java.util.UUID class EmbyAPIClient(val context: Context, baseUrl: String = "http://localhost:8096") : SerenityClient { @@ -66,12 +68,11 @@ class EmbyAPIClient(val context: Context, baseUrl: String = "http://localhost:80 usersService = embyRetrofit.create(UsersService::class.java) filterService = embyRetrofit.create(FilterService::class.java) - val easyDeviceMod = EasyDeviceMod(context) - deviceId = EasyIdMod(context).pseudoUniqueID - deviceName = "${easyDeviceMod.manufacturer} ${easyDeviceMod.model}" - Log.d(this::class.java.simpleName, "Device Id: $deviceId") - Log.d(this::class.java.simpleName, "Device Name : $deviceName") + deviceId = pseudoUniqueID() + deviceName = "${Build.MANUFACTURER} ${Build.MODEL} " + Timber.d(this::class.java.simpleName, "Device Id: $deviceId") + Timber.d(this::class.java.simpleName, "Device Name : $deviceName") } fun fetchAllPublicUsers(): List { @@ -535,4 +536,44 @@ class EmbyAPIClient(val context: Context, baseUrl: String = "http://localhost:80 fun fetchAccessToken() = prefs.getString("embyAccessToken", "") override fun supportsMultipleUsers(): Boolean = true + + private fun pseudoUniqueID(): String { + // If all else fails, if the user does have lower than API 9 (lower + // than Gingerbread), has reset their phone or 'Secure.ANDROID_ID' + // returns 'null', then simply the ID returned will be solely based + // off their Android device information. This is where the collisions + // can happen. + // Try not to use DISPLAY, HOST or ID - these items could change. + // If there are collisions, there will be overlapping data + var devIDShort = "35" + (Build.BOARD.length % 10) + (Build.BRAND.length % 10) + + devIDShort += if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + (Build.SUPPORTED_ABIS[0].length % 10) + } else { + (Build.CPU_ABI.length % 10) + } + + devIDShort += + (Build.DEVICE.length % 10) + (Build.MANUFACTURER.length % 10) + (Build.MODEL.length + % 10) + (Build.PRODUCT.length % 10) + + // Only devices with API >= 9 have android.os.Build.SERIAL + // http://developer.android.com/reference/android/os/Build.html#SERIAL + // If a user upgrades software or roots their phone, there will be a duplicate entry + var serial: String + try { + serial = Build::class.java.getField("SERIAL")[null]?.toString() ?: "" + + // Go ahead and return the serial for api => 9 + return UUID(devIDShort.hashCode().toLong(), serial.hashCode().toLong()).toString() + } catch (e: java.lang.Exception) { + // String needs to be initialized + Timber.e(EmbyAPIClient::class.java.simpleName, "getPseudoUniqueID: ", e) + serial = "ESYDV000" // some value + } + + // Finally, combine the values we have found by using the UUID class to create a unique identifier + return UUID(devIDShort.hashCode().toLong(), serial.hashCode().toLong()).toString() + } + } \ No newline at end of file diff --git a/emby-lib/src/test/kotlin/us/nineworlds/serenity/emby/server/EmbyServerJobTest.kt b/emby-lib/src/test/kotlin/us/nineworlds/serenity/emby/server/EmbyServerJobTest.kt deleted file mode 100644 index fef12dea0..000000000 --- a/emby-lib/src/test/kotlin/us/nineworlds/serenity/emby/server/EmbyServerJobTest.kt +++ /dev/null @@ -1,50 +0,0 @@ -package us.nineworlds.serenity.emby.server - -import android.content.Context -import io.mockk.mockk -import org.greenrobot.eventbus.EventBus -import org.junit.Before -import org.junit.Test -import org.junit.runner.RunWith -import org.mockito.Mock -import org.mockito.MockitoAnnotations.initMocks -import org.robolectric.RobolectricTestRunner -import org.robolectric.RuntimeEnvironment -import org.robolectric.annotation.Config -import org.robolectric.shadows.ShadowLog -import toothpick.config.Module -import us.nineworlds.serenity.common.android.injection.ApplicationContext -import us.nineworlds.serenity.emby.test.InjectingTest - -@RunWith(RobolectricTestRunner::class) -@Config(sdk = [28]) -class EmbyServerJobTest : InjectingTest() { - - override val modules: List - get() = mutableListOf(TestModule()) - - private lateinit var job: EmbyServerJob - - @Before - override fun setUp() { - ShadowLog.stream = System.out - - super.setUp() - job = EmbyServerJob() - } - - @Test - fun locateEmbyServers() { - job.onRun() - } - - override fun installModules() { - scope.installTestModules(TestModule()) - } - - inner class TestModule : Module() { - init { - bind(Context::class.java).withName(ApplicationContext::class.java).toInstance(RuntimeEnvironment.application) - } - } -} \ No newline at end of file diff --git a/gradle.properties b/gradle.properties index 1c5a416df..611702d6f 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,11 +1,9 @@ org.gradle.daemon=false -org.gradle.jvmargs=-Xms1024m -Xmx1024m -XX:+UseStringDeduplication +org.gradle.jvmargs=-Xms1024m -Xmx2048m -XX:+UseStringDeduplication kotlin.incremental=true org.gradle.configureondemand=true android.useAndroidX=true -android.enableJetifier=true -android.jetifier.ignorelist=bcprov,robolectric +android.enableJetifier=false org.gradle.caching=true org.gradle.parallel=true org.gradle.configuration-cache=true - diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml index 533664c45..4a3402e70 100644 --- a/gradle/libs.versions.toml +++ b/gradle/libs.versions.toml @@ -21,6 +21,7 @@ androidPluginVersion = "8.6.1" leanbackPreferenceVersion = "1.1.0-rc01" leanbackVersion = "1.1.0-rc02" legacySupportV4Version = "1.0.0" +lifecycleVersion = "2.8.7" materialVersion = "1.12.0" minSdkVersion = "27" mockwebserverVersion = "4.9.1" @@ -50,7 +51,6 @@ openglApiVersion = "gl1.1-android-2.1_r1" assertJAndroidVersion = "1.1.1" toothPickVersion = "3.1.0" toothPickKspVersion = "1.1.0" -easydeviceInfoVersion = "2.4.1" androidxTestCoreVersion = "1.6.1" androidxRecyclerViewVersion = "1.3.2" @@ -68,6 +68,7 @@ androidx-junit = { module = "androidx.test.ext:junit", version.ref = "junit" } androidx-leanback = { module = "androidx.leanback:leanback", version.ref = "leanbackVersion" } androidx-leanback-preference = { module = "androidx.leanback:leanback-preference", version.ref = "leanbackPreferenceVersion" } androidx-legacy-support-v4 = { module = "androidx.legacy:legacy-support-v4", version.ref = "legacySupportV4Version" } +androidx-lifecycle-runtime = { module = "androidx.lifecycle:lifecycle-runtime-ktx", version.ref="lifecycleVersion"} androidx-percentlayout = { module = "androidx.percentlayout:percentlayout", version.ref = "percentlayoutVersion" } androidx-recycler-view = { module = "androidx.recyclerview:recyclerview", version.ref = "androidxRecyclerViewVersion"} commons-io = { module = "commons-io:commons-io", version.ref = "commonsIo" } @@ -87,7 +88,6 @@ kotlin = { group = "org.jetbrains.kotlin", name = "kotlin-stdlib", version.ref=" kotlin-coroutines-android = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-android", version.ref="kotlinCoroutinesVersion" } kotlin-coroutines-core = { group = "org.jetbrains.kotlinx", name = "kotlinx-coroutines-core", version.ref="kotlinCoroutinesVersion" } -android-priority-jobqueue = { group = "com.birbit", name = "android-priority-jobqueue", version.ref="androidPriorityJobQueueVersion" } eventbus = { group = "org.greenrobot", name = "eventbus", version.ref = "eventBus"} material = { module = "com.google.android.material:material", version.ref = "materialVersion" } moxy-compiler = { module = "com.github.moxy-community:moxy-compiler", version.ref = "moxyCompilerVersion" } @@ -104,8 +104,6 @@ joda-time = { group = "net.danlew", name = "android.joda", version.ref = "jodaTi okhttp = { group = "com.squareup.okhttp3", name = "okhttp", version.ref = "okhttpVersion" } okhttp-logging-interceptor = { group = "com.squareup.okhttp3", name = "logging-interceptor", version.ref = "okhttpVersion" } timber = { group = "com.jakewharton.timber", name = "timber", version.ref = "timberVersion" } -easydeviceinfo-base = { group = "com.github.nisrulz", name = "easydeviceinfo-base", version.ref = "easydeviceInfoVersion" } -easydeviceinfo-common = { group = "com.github.nisrulz", name = "easydeviceinfo-common", version.ref = "easydeviceInfoVersion" } resourceful = { group = "com.github.rstanic12", name = "Resourceful", version.ref = "resourcefulVersion"} simple-xml = { group = "org.simpleframework", name = "simple-xml", version.ref = "simpleXmlVersion" } diff --git a/serenity-android-common/build.gradle.kts b/serenity-android-common/build.gradle.kts index b84e3b9ae..957ae4a66 100644 --- a/serenity-android-common/build.gradle.kts +++ b/serenity-android-common/build.gradle.kts @@ -43,7 +43,6 @@ dependencies { api(project(":serenity-common")) api(libs.eventbus) implementation(libs.kotlin) - api(libs.android.priority.jobqueue) releaseApi(libs.toothpick.runtime) { exclude(group = "javax.inject") diff --git a/serenity-android-common/src/main/kotlin/us/nineworlds/serenity/common/android/injection/InjectingJob.kt b/serenity-android-common/src/main/kotlin/us/nineworlds/serenity/common/android/injection/InjectingJob.kt deleted file mode 100644 index 90c14ae69..000000000 --- a/serenity-android-common/src/main/kotlin/us/nineworlds/serenity/common/android/injection/InjectingJob.kt +++ /dev/null @@ -1,15 +0,0 @@ -package us.nineworlds.serenity.common.android.injection - -import com.birbit.android.jobqueue.Job -import com.birbit.android.jobqueue.Params -import toothpick.Toothpick -import us.nineworlds.serenity.common.annotations.InjectionConstants - -@Suppress("LeakingThis") -abstract class InjectingJob : Job(Params(500).requireNetwork()) { - init { - val jobScope = Toothpick.openScope(InjectionConstants.APPLICATION_SCOPE) - Toothpick.inject(this, jobScope) - } - -} diff --git a/serenity-app/build.gradle.kts b/serenity-app/build.gradle.kts index 4d485890f..960a76304 100644 --- a/serenity-app/build.gradle.kts +++ b/serenity-app/build.gradle.kts @@ -137,16 +137,15 @@ dependencies { exclude(group = "com.android.support") } + implementation(libs.androidx.lifecycle.runtime) implementation(libs.androidx.fragment.ktx) implementation(libs.material) implementation(libs.kotlin) implementation(libs.kotlin.coroutines.android) implementation(libs.moxy.community.moxy) - implementation(libs.moxy.community.moxy.app.compat) implementation(libs.moxy.ktx) implementation(libs.github.glide) ksp(libs.glide.compiler) - implementation(libs.android.priority.jobqueue) implementation(libs.androidx.appcompat) implementation(libs.androidx.leanback) implementation(libs.androidx.leanback.preference) diff --git a/serenity-app/src/main/java/moxy/MvpAppCompatActivity.java b/serenity-app/src/main/java/moxy/MvpAppCompatActivity.java new file mode 100644 index 000000000..2181a6e41 --- /dev/null +++ b/serenity-app/src/main/java/moxy/MvpAppCompatActivity.java @@ -0,0 +1,69 @@ +package moxy; + +import android.os.Bundle; + +import androidx.appcompat.app.AppCompatActivity; + +@SuppressWarnings("unused") +public class MvpAppCompatActivity extends AppCompatActivity implements MvpDelegateHolder { + + private MvpDelegate mvpDelegate; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getMvpDelegate().onCreate(savedInstanceState); + } + + @Override + protected void onStart() { + super.onStart(); + + getMvpDelegate().onAttach(); + } + + @Override + protected void onResume() { + super.onResume(); + + getMvpDelegate().onAttach(); + } + + @Override + protected void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + getMvpDelegate().onSaveInstanceState(outState); + getMvpDelegate().onDetach(); + } + + @Override + protected void onStop() { + super.onStop(); + + getMvpDelegate().onDetach(); + } + + @Override + protected void onDestroy() { + super.onDestroy(); + + getMvpDelegate().onDestroyView(); + + if (isFinishing()) { + getMvpDelegate().onDestroy(); + } + } + + /** + * @return The {@link MvpDelegate} being used by this Activity. + */ + @Override + public MvpDelegate getMvpDelegate() { + if (mvpDelegate == null) { + mvpDelegate = new MvpDelegate<>(this); + } + return mvpDelegate; + } +} diff --git a/serenity-app/src/main/java/moxy/MvpAppCompatFragment.java b/serenity-app/src/main/java/moxy/MvpAppCompatFragment.java new file mode 100644 index 000000000..c2c2289a8 --- /dev/null +++ b/serenity-app/src/main/java/moxy/MvpAppCompatFragment.java @@ -0,0 +1,101 @@ +package moxy; + +import android.os.Bundle; + +import androidx.fragment.app.Fragment; + +@SuppressWarnings({ "ConstantConditions", "unused" }) +public class MvpAppCompatFragment extends Fragment implements MvpDelegateHolder { + + private boolean isStateSaved; + + private MvpDelegate mvpDelegate; + + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + + getMvpDelegate().onCreate(savedInstanceState); + } + + @Override + public void onStart() { + super.onStart(); + + isStateSaved = false; + + getMvpDelegate().onAttach(); + } + + public void onResume() { + super.onResume(); + + isStateSaved = false; + + getMvpDelegate().onAttach(); + } + + public void onSaveInstanceState(Bundle outState) { + super.onSaveInstanceState(outState); + + isStateSaved = true; + + getMvpDelegate().onSaveInstanceState(outState); + getMvpDelegate().onDetach(); + } + + @Override + public void onStop() { + super.onStop(); + + getMvpDelegate().onDetach(); + } + + @Override + public void onDestroyView() { + super.onDestroyView(); + + getMvpDelegate().onDetach(); + getMvpDelegate().onDestroyView(); + } + + @Override + public void onDestroy() { + super.onDestroy(); + + //We leave the screen and respectively all fragments will be destroyed + if (getActivity().isFinishing()) { + getMvpDelegate().onDestroy(); + return; + } + + // When we rotate device isRemoving() return true for fragment placed in backstack + // http://stackoverflow.com/questions/34649126/fragment-back-stack-and-isremoving + if (isStateSaved) { + isStateSaved = false; + return; + } + + boolean anyParentIsRemoving = false; + Fragment parent = getParentFragment(); + while (!anyParentIsRemoving && parent != null) { + anyParentIsRemoving = parent.isRemoving(); + parent = parent.getParentFragment(); + } + + if (isRemoving() || anyParentIsRemoving) { + getMvpDelegate().onDestroy(); + } + } + + /** + * @return The {@link MvpDelegate} being used by this Fragment. + */ + @Override + public MvpDelegate getMvpDelegate() { + if (mvpDelegate == null) { + mvpDelegate = new MvpDelegate<>(this); + } + + return mvpDelegate; + } +} diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/SerenityApplication.kt b/serenity-app/src/main/java/us/nineworlds/serenity/SerenityApplication.kt index 0373b79c3..994032286 100644 --- a/serenity-app/src/main/java/us/nineworlds/serenity/SerenityApplication.kt +++ b/serenity-app/src/main/java/us/nineworlds/serenity/SerenityApplication.kt @@ -30,11 +30,12 @@ import android.os.Build import android.os.Bundle import android.preference.PreferenceManager import androidx.localbroadcastmanager.content.LocalBroadcastManager -import com.birbit.android.jobqueue.JobManager import com.google.android.exoplayer2.database.ExoDatabaseProvider import com.google.android.exoplayer2.upstream.cache.LeastRecentlyUsedCacheEvictor import com.google.android.exoplayer2.upstream.cache.SimpleCache import com.google.firebase.analytics.FirebaseAnalytics +import kotlinx.coroutines.MainScope +import kotlinx.coroutines.launch import net.danlew.android.joda.JodaTimeAndroid import org.greenrobot.eventbus.EventBus import org.greenrobot.eventbus.Subscribe @@ -46,7 +47,7 @@ import us.nineworlds.serenity.common.annotations.InjectionConstants import us.nineworlds.serenity.core.logger.Logger import us.nineworlds.serenity.core.util.AndroidHelper import us.nineworlds.serenity.emby.server.EmbyServer -import us.nineworlds.serenity.emby.server.EmbyServerJob +import us.nineworlds.serenity.emby.server.EmbyServerDiscover import us.nineworlds.serenity.injection.ForMediaServers import us.nineworlds.serenity.injection.modules.AndroidModule import us.nineworlds.serenity.injection.modules.LoginModule @@ -69,9 +70,6 @@ open class SerenityApplication : Application() { @Inject lateinit var preferences: SharedPreferences - @Inject - lateinit var jobManager: JobManager - @Inject lateinit var logger: Logger @@ -85,7 +83,6 @@ open class SerenityApplication : Application() { sendStartedApplicationEvent() eventBus = EventBus.getDefault() eventBus.register(this) - jobManager.start() logger.initialize() } @@ -132,12 +129,13 @@ open class SerenityApplication : Application() { override fun onTerminate() { eventBus.unregister(this) - jobManager.stop() super.onTerminate() } protected open fun discoverServers() { - jobManager.addJobInBackground(EmbyServerJob()) + MainScope().launch { + EmbyServerDiscover().findServers() + } } @Subscribe(threadMode = ThreadMode.BACKGROUND) diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/injection/InjectingActivity.java b/serenity-app/src/main/java/us/nineworlds/serenity/injection/InjectingActivity.java index 04648ba40..104fb6190 100644 --- a/serenity-app/src/main/java/us/nineworlds/serenity/injection/InjectingActivity.java +++ b/serenity-app/src/main/java/us/nineworlds/serenity/injection/InjectingActivity.java @@ -23,16 +23,16 @@ package us.nineworlds.serenity.injection; -import android.app.Activity; import android.os.Bundle; import androidx.annotation.Nullable; +import androidx.appcompat.app.AppCompatActivity; import toothpick.Scope; import toothpick.Toothpick; import us.nineworlds.serenity.common.annotations.InjectionConstants; -public abstract class InjectingActivity extends Activity { +public abstract class InjectingActivity extends AppCompatActivity { protected Scope scope; diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/injection/modules/AndroidModule.java b/serenity-app/src/main/java/us/nineworlds/serenity/injection/modules/AndroidModule.java index c8090f458..2ad246dd4 100644 --- a/serenity-app/src/main/java/us/nineworlds/serenity/injection/modules/AndroidModule.java +++ b/serenity-app/src/main/java/us/nineworlds/serenity/injection/modules/AndroidModule.java @@ -31,9 +31,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.birbit.android.jobqueue.JobManager; -import com.birbit.android.jobqueue.config.Configuration; - import org.greenrobot.eventbus.EventBus; import javax.inject.Inject; @@ -66,7 +63,6 @@ public AndroidModule(Application application) { bind(SharedPreferences.class).toInstance(PreferenceManager.getDefaultSharedPreferences(applicationContext)); bind(AndroidHelper.class).toInstance(new AndroidHelper(applicationContext)); bind(Resources.class).toInstance(application.getResources()); - bind(JobManager.class).toProvider(JobManagerProvider.class).providesSingleton(); bind(LocalBroadcastManager.class).toInstance(providesLocalBroadcastManager()); } @@ -75,20 +71,6 @@ private LocalBroadcastManager providesLocalBroadcastManager() { return LocalBroadcastManager.getInstance(applicationContext); } - public static class JobManagerProvider implements Provider { - - @Inject @ApplicationContext Context context; - - @Override public JobManager get() { - Configuration configuration = new Configuration.Builder(context).minConsumerCount(1) - .maxConsumerCount(5) - .loadFactor(3) - .consumerKeepAlive(120) - .build(); - return new JobManager(configuration); - } - } - public static class EventBusProvider implements Provider { @Override public EventBus get() { diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/jobs/GlideClearCacheJob.java b/serenity-app/src/main/java/us/nineworlds/serenity/jobs/GlideClearCacheJob.java deleted file mode 100644 index d016f43d5..000000000 --- a/serenity-app/src/main/java/us/nineworlds/serenity/jobs/GlideClearCacheJob.java +++ /dev/null @@ -1,45 +0,0 @@ -package us.nineworlds.serenity.jobs; - -import android.content.Context; - -import androidx.annotation.NonNull; -import androidx.annotation.Nullable; - -import com.birbit.android.jobqueue.Job; -import com.birbit.android.jobqueue.Params; -import com.birbit.android.jobqueue.RetryConstraint; -import com.bumptech.glide.Glide; - - -/** - * Created by dcarver on 7/2/17. - */ - -public class GlideClearCacheJob extends Job { - - Context context; - - public GlideClearCacheJob(Context context) { - super(new Params(500)); - this.context = context; - } - - @Override public void onAdded() { - - } - - @Override public void onRun() throws Throwable { - Glide.get(context).clearDiskCache(); - Glide.get(context).clearMemory(); - } - - @Override protected void onCancel(int cancelReason, @Nullable Throwable throwable) { - - } - - @Override - protected RetryConstraint shouldReRunOnThrowable(@NonNull Throwable throwable, int runCount, - int maxRunCount) { - return null; - } -} diff --git a/serenity-app/src/main/java/us/nineworlds/serenity/ui/listeners/AbstractVideoOnItemSelectedListener.java b/serenity-app/src/main/java/us/nineworlds/serenity/ui/listeners/AbstractVideoOnItemSelectedListener.java index 447561c55..2b395aacc 100644 --- a/serenity-app/src/main/java/us/nineworlds/serenity/ui/listeners/AbstractVideoOnItemSelectedListener.java +++ b/serenity-app/src/main/java/us/nineworlds/serenity/ui/listeners/AbstractVideoOnItemSelectedListener.java @@ -35,7 +35,6 @@ import androidx.annotation.NonNull; import androidx.annotation.Nullable; -import com.birbit.android.jobqueue.JobManager; import com.bumptech.glide.Glide; import com.bumptech.glide.request.target.SimpleTarget; import com.bumptech.glide.request.transition.Transition; @@ -64,8 +63,6 @@ public abstract class AbstractVideoOnItemSelectedListener extends BaseInjector { @Inject protected SharedPreferences preferences; - @Inject - JobManager jobManager; @Inject Logger logger; diff --git a/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/activity/ServerSelectionActivity.kt b/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/activity/ServerSelectionActivity.kt index 37a7d95d2..9fe754d88 100644 --- a/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/activity/ServerSelectionActivity.kt +++ b/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/activity/ServerSelectionActivity.kt @@ -9,18 +9,18 @@ import android.view.View.GONE import android.view.View.VISIBLE import android.widget.TextView import android.widget.Toast -import com.birbit.android.jobqueue.JobManager +import androidx.lifecycle.lifecycleScope import com.google.firebase.analytics.FirebaseAnalytics +import kotlinx.coroutines.launch import us.nineworlds.serenity.AndroidTV import us.nineworlds.serenity.MainActivity import us.nineworlds.serenity.R import us.nineworlds.serenity.common.Server -import us.nineworlds.serenity.common.channels.ServerChannel import us.nineworlds.serenity.core.util.StringPreference import us.nineworlds.serenity.databinding.ActivityServerSelectionBinding import us.nineworlds.serenity.databinding.IncludeLoadingProgressBinding import us.nineworlds.serenity.emby.server.EmbyServer -import us.nineworlds.serenity.emby.server.EmbyServerJob +import us.nineworlds.serenity.emby.server.EmbyServerDiscover import us.nineworlds.serenity.injection.ForMediaServers import us.nineworlds.serenity.injection.InjectingActivity import us.nineworlds.serenity.injection.ServerClientPreference @@ -50,9 +50,6 @@ class ServerSelectionActivity : InjectingActivity() { @field:[ServerPortPreference] lateinit var serverPortPreference: StringPreference - @Inject - lateinit var jobManager: JobManager - private lateinit var refreshButton: View private lateinit var manualEntryButton: View @@ -101,8 +98,11 @@ class ServerSelectionActivity : InjectingActivity() { refreshButton = LayoutInflater.from(this).inflate(R.layout.button_server_refresh, binding.serverContainer, false) refreshButton.setOnClickListener { - jobManager.addJobInBackground(EmbyServerJob()) - recreate() + + lifecycleScope.launch { + EmbyServerDiscover().findServers() + recreate() + } } binding.serverContainer.addView(refreshButton) diff --git a/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenter.kt b/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenter.kt index 5e7f64333..6b93b787a 100644 --- a/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenter.kt +++ b/serenity-app/src/main/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenter.kt @@ -1,7 +1,6 @@ package us.nineworlds.serenity.ui.video.player import android.view.View -import com.birbit.android.jobqueue.JobManager import com.google.android.exoplayer2.Player import com.google.android.exoplayer2.ui.PlayerControlView import kotlinx.coroutines.launch @@ -46,9 +45,6 @@ class ExoplayerPresenter : MvpPresenter(), ExoplayerPresenter, @Inject internal lateinit var eventBus: EventBus - @Inject - internal lateinit var jobManager: JobManager - @Inject internal lateinit var androidHelper: AndroidHelper diff --git a/serenity-app/src/test/java/us/nineworlds/serenity/TestSerenityApplication.java b/serenity-app/src/test/java/us/nineworlds/serenity/TestSerenityApplication.java index 14f4ec383..ff4827c33 100644 --- a/serenity-app/src/test/java/us/nineworlds/serenity/TestSerenityApplication.java +++ b/serenity-app/src/test/java/us/nineworlds/serenity/TestSerenityApplication.java @@ -29,7 +29,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.birbit.android.jobqueue.JobManager; import com.google.firebase.analytics.FirebaseAnalytics; import org.greenrobot.eventbus.EventBus; @@ -56,7 +55,6 @@ public TestSerenityApplication() { protected void inject() { Scope scope = Toothpick.openScope(InjectionConstants.APPLICATION_SCOPE); scope.installModules(new AndroidModule(this), new SerenityModule(), new LoginModule(), new ExoplayerVideoModule() ); - jobManager = mock(JobManager.class); androidHelper = mock(AndroidHelper.class); preferences = scope.getInstance(SharedPreferences.class); localBroadcastManager = scope.getInstance(LocalBroadcastManager.class); diff --git a/serenity-app/src/test/java/us/nineworlds/serenity/TestingModule.java b/serenity-app/src/test/java/us/nineworlds/serenity/TestingModule.java index ed5d8e783..023d15872 100644 --- a/serenity-app/src/test/java/us/nineworlds/serenity/TestingModule.java +++ b/serenity-app/src/test/java/us/nineworlds/serenity/TestingModule.java @@ -27,8 +27,6 @@ import androidx.localbroadcastmanager.content.LocalBroadcastManager; -import com.birbit.android.jobqueue.JobManager; - import org.mockito.Mock; import org.mockito.MockitoAnnotations; @@ -39,7 +37,6 @@ public class TestingModule extends Module { - @Mock JobManager mockJobManager; @Mock SerenityClient mockPlexAppFactory; @Mock LocalBroadcastManager mockLocalBroadcastManager; @Mock Logger mockLogger; @@ -48,7 +45,6 @@ public class TestingModule extends Module { public TestingModule() { MockitoAnnotations.initMocks(this); - bind(JobManager.class).toInstance(mockJobManager); bind(SerenityClient.class).toInstance(mockPlexAppFactory); bind(LocalBroadcastManager.class).toInstance(mockLocalBroadcastManager); bind(Logger.class).toInstance(mockLogger); diff --git a/serenity-app/src/test/kotlin/us/nineworlds/serenity/MockkTestingModule.kt b/serenity-app/src/test/kotlin/us/nineworlds/serenity/MockkTestingModule.kt index b903586a4..73aded7b6 100644 --- a/serenity-app/src/test/kotlin/us/nineworlds/serenity/MockkTestingModule.kt +++ b/serenity-app/src/test/kotlin/us/nineworlds/serenity/MockkTestingModule.kt @@ -2,7 +2,6 @@ package us.nineworlds.serenity import android.content.Context import androidx.localbroadcastmanager.content.LocalBroadcastManager -import com.birbit.android.jobqueue.JobManager import io.mockk.mockk import toothpick.config.Module import us.nineworlds.serenity.common.rest.SerenityClient @@ -11,7 +10,6 @@ import us.nineworlds.serenity.core.util.AndroidHelper class MockkTestingModule : Module() { companion object { - val mockJobManager: JobManager = mockk(relaxed = true) val mockPlexAppFactory: SerenityClient = mockk(relaxed = true) val mockLocalBroadcastManager: LocalBroadcastManager = mockk(relaxed = true) var mockLogger: Logger = mockk(relaxed = true) @@ -19,7 +17,6 @@ class MockkTestingModule : Module() { } init { - bind(JobManager::class.java).toInstance(mockJobManager) bind(SerenityClient::class.java).toInstance(mockPlexAppFactory) bind(LocalBroadcastManager::class.java).toInstance(mockLocalBroadcastManager) bind(Logger::class.java).toInstance(mockLogger) diff --git a/serenity-app/src/test/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenterTest.kt b/serenity-app/src/test/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenterTest.kt index 342d56e96..6480e82ac 100644 --- a/serenity-app/src/test/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenterTest.kt +++ b/serenity-app/src/test/kotlin/us/nineworlds/serenity/ui/video/player/ExoplayerPresenterTest.kt @@ -10,7 +10,6 @@ import assertk.assertions.isEqualTo import assertk.assertions.isFalse import assertk.assertions.isNotNull import assertk.assertions.isTrue -import com.birbit.android.jobqueue.JobManager import io.mockk.clearAllMocks import io.mockk.coVerify @@ -189,7 +188,6 @@ class ExoplayerPresenterTest : InjectingTest() { bind(LinkedList::class.java).withName(ForVideoQueue::class.java).toInstance(mockVideoQueue) bind(EventBus::class.java).toInstance(mockEventBus) bind(AndroidHelper::class.java).toInstance(mockAndroidHelper) - bind(JobManager::class.java).toInstance(mockk(relaxed = true)) bind(PlaybackRepository::class.java).toInstance(mockPlaybackRepository) } }