From 6d3cc16ab1e9e1ebc137efe302efdb944b4998db Mon Sep 17 00:00:00 2001 From: inorichi Date: Tue, 9 Jan 2018 12:27:45 +0100 Subject: [PATCH] Include minor changes from extensions PR --- app/src/main/java/eu/kanade/tachiyomi/App.kt | 4 +-- .../kanade/tachiyomi/network/NetworkHelper.kt | 10 ------- .../ui/base/presenter/BasePresenter.kt | 26 +++++++++++++++++++ .../ui/catalogue/CatalogueController.kt | 2 +- .../catalogue/SourceDividerItemDecoration.kt | 5 +--- .../tachiyomi/ui/setting/PreferenceDSL.kt | 3 +-- .../ui/setting/SettingsController.kt | 21 +++++++++++++-- 7 files changed, 50 insertions(+), 21 deletions(-) diff --git a/app/src/main/java/eu/kanade/tachiyomi/App.kt b/app/src/main/java/eu/kanade/tachiyomi/App.kt index 9fe1a90d01..0219f98d9c 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/App.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/App.kt @@ -28,11 +28,11 @@ open class App : Application() { override fun onCreate() { super.onCreate() + if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) + Injekt = InjektScope(DefaultRegistrar()) Injekt.importModule(AppModule(this)) - if (BuildConfig.DEBUG) Timber.plant(Timber.DebugTree()) - setupAcra() setupJobManager() setupNotificationChannels() diff --git a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt index e48174de4e..b8f5d756ab 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/network/NetworkHelper.kt @@ -18,16 +18,6 @@ class NetworkHelper(context: Context) { .cache(Cache(cacheDir, cacheSize)) .build() - val forceCacheClient = client.newBuilder() - .addNetworkInterceptor { chain -> - val originalResponse = chain.proceed(chain.request()) - originalResponse.newBuilder() - .removeHeader("Pragma") - .header("Cache-Control", "max-age=600") - .build() - } - .build() - val cloudflareClient = client.newBuilder() .addInterceptor(CloudflareInterceptor()) .build() diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/BasePresenter.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/BasePresenter.kt index 1d365b43d9..cfe4191d95 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/BasePresenter.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/base/presenter/BasePresenter.kt @@ -1,6 +1,7 @@ package eu.kanade.tachiyomi.ui.base.presenter import nucleus.presenter.RxPresenter +import nucleus.presenter.delivery.Delivery import rx.Observable open class BasePresenter : RxPresenter() { @@ -35,4 +36,29 @@ open class BasePresenter : RxPresenter() { fun Observable.subscribeReplay(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null) = compose(deliverReplay()).subscribe(split(onNext, onError)).apply { add(this) } + /** + * Subscribes an observable with [DeliverWithView] and adds it to the presenter's lifecycle + * subscription list. + * + * @param onNext function to execute when the observable emits an item. + * @param onError function to execute when the observable throws an error. + */ + fun Observable.subscribeWithView(onNext: (V, T) -> Unit, onError: ((V, Throwable) -> Unit)? = null) + = compose(DeliverWithView(view())).subscribe(split(onNext, onError)).apply { add(this) } + + /** + * A deliverable that only emits to the view if attached, otherwise the event is ignored. + */ + class DeliverWithView(private val view: Observable) : Observable.Transformer> { + + override fun call(observable: Observable): Observable> { + return observable + .materialize() + .filter { notification -> !notification.isOnCompleted } + .flatMap { notification -> + view.take(1).filter { it != null }.map { Delivery(it, notification) } + } + } + } + } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt index 59d0293b48..f919b84033 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/CatalogueController.kt @@ -46,7 +46,7 @@ class CatalogueController : NucleusController(), /** * Adapter containing sources. */ - private var adapter : CatalogueAdapter? = null + private var adapter: CatalogueAdapter? = null /** * Called when controller is initialized. diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt index 4caa720537..d60106cbe4 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/catalogue/SourceDividerItemDecoration.kt @@ -12,7 +12,7 @@ class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoratio private val divider: Drawable init { - val a = context.obtainStyledAttributes(ATTRS) + val a = context.obtainStyledAttributes(intArrayOf(android.R.attr.listDivider)) divider = a.getDrawable(0) a.recycle() } @@ -41,7 +41,4 @@ class SourceDividerItemDecoration(context: Context) : RecyclerView.ItemDecoratio outRect.set(0, 0, 0, divider.intrinsicHeight) } - companion object { - private val ATTRS = intArrayOf(android.R.attr.listDivider) - } } \ No newline at end of file diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt index df1e41cbab..6fc05d1af7 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/PreferenceDSL.kt @@ -1,6 +1,5 @@ package eu.kanade.tachiyomi.ui.setting -import android.content.Context import android.support.graphics.drawable.VectorDrawableCompat import android.support.v4.graphics.drawable.DrawableCompat import android.support.v7.preference.* @@ -10,7 +9,7 @@ import eu.kanade.tachiyomi.widget.preference.IntListPreference @Target(AnnotationTarget.TYPE) annotation class DSL -inline fun PreferenceManager.newScreen(context: Context, block: (@DSL PreferenceScreen).() -> Unit): PreferenceScreen { +inline fun PreferenceManager.newScreen(block: (@DSL PreferenceScreen).() -> Unit): PreferenceScreen { return createPreferenceScreen(context).also { it.block() } } diff --git a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt index f78a4c98cd..21af01ca55 100644 --- a/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt +++ b/app/src/main/java/eu/kanade/tachiyomi/ui/setting/SettingsController.kt @@ -10,8 +10,11 @@ import android.view.ContextThemeWrapper import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import com.bluelinelabs.conductor.ControllerChangeHandler +import com.bluelinelabs.conductor.ControllerChangeType import eu.kanade.tachiyomi.R import eu.kanade.tachiyomi.data.preference.PreferencesHelper +import eu.kanade.tachiyomi.ui.base.controller.BaseController import rx.Observable import rx.Subscription import rx.subscriptions.CompositeSubscription @@ -55,9 +58,23 @@ abstract class SettingsController : PreferenceController() { return preferenceScreen?.title?.toString() } - override fun onAttach(view: View) { + fun setTitle() { + var parentController = parentController + while (parentController != null) { + if (parentController is BaseController && parentController.getTitle() != null) { + return + } + parentController = parentController.parentController + } + (activity as? AppCompatActivity)?.supportActionBar?.title = getTitle() - super.onAttach(view) + } + + override fun onChangeStarted(handler: ControllerChangeHandler, type: ControllerChangeType) { + if (type.isEnter) { + setTitle() + } + super.onChangeStarted(handler, type) } fun Observable.subscribeUntilDestroy(): Subscription {