Fix intercept activity theme

This commit is contained in:
Jobobby04 2020-05-29 18:17:40 -04:00
parent 69121d3958
commit a03e668c8f
4 changed files with 47 additions and 57 deletions

View File

@ -181,7 +181,7 @@
android:exported="true" />
<activity
android:name="exh.ui.intercept.InterceptActivity"
android:label="TachiyomiEH"
android:label="@string/app_name"
android:theme="@style/Theme.EHActivity">
<intent-filter>
<action android:name="android.intent.action.VIEW" />

View File

@ -8,17 +8,19 @@ import com.afollestad.materialdialogs.callbacks.onCancel
import com.afollestad.materialdialogs.callbacks.onDismiss
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.databinding.EhActivityInterceptBinding
import eu.kanade.tachiyomi.ui.base.activity.BaseRxActivity
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController
import eu.kanade.tachiyomi.util.view.gone
import eu.kanade.tachiyomi.util.view.visible
import nucleus.factory.RequiresPresenter
import exh.GalleryAddEvent
import exh.GalleryAdder
import kotlin.concurrent.thread
import rx.Subscription
import rx.android.schedulers.AndroidSchedulers
import rx.subjects.BehaviorSubject
@RequiresPresenter(InterceptActivityPresenter::class)
class InterceptActivity : BaseRxActivity<EhActivityInterceptBinding, InterceptActivityPresenter>() {
class InterceptActivity : BaseActivity<EhActivityInterceptBinding>() {
private var statusSubscription: Subscription? = null
override fun onCreate(savedInstanceState: Bundle?) {
@ -38,7 +40,7 @@ class InterceptActivity : BaseRxActivity<EhActivityInterceptBinding, InterceptAc
if (Intent.ACTION_VIEW == intent.action) {
binding.interceptProgress.visible()
binding.interceptStatus.text = "Loading gallery..."
presenter.loadGallery(intent.dataString!!)
loadGallery(intent.dataString!!)
}
}
@ -53,7 +55,7 @@ class InterceptActivity : BaseRxActivity<EhActivityInterceptBinding, InterceptAc
override fun onStart() {
super.onStart()
statusSubscription?.unsubscribe()
statusSubscription = presenter.status
statusSubscription = status
.observeOn(AndroidSchedulers.mainThread())
.subscribe {
when (it) {
@ -89,4 +91,37 @@ class InterceptActivity : BaseRxActivity<EhActivityInterceptBinding, InterceptAc
super.onStop()
statusSubscription?.unsubscribe()
}
private val galleryAdder = GalleryAdder()
val status = BehaviorSubject.create<InterceptResult>(InterceptResult.Idle())
@Synchronized
fun loadGallery(gallery: String) {
// Do not load gallery if already loading
if (status.value is InterceptResult.Idle) {
status.onNext(InterceptResult.Loading())
// Load gallery async
thread {
val result = galleryAdder.addGallery(gallery)
status.onNext(
when (result) {
is GalleryAddEvent.Success -> result.manga.id?.let {
InterceptResult.Success(it)
} ?: InterceptResult.Failure("Manga ID is null!")
is GalleryAddEvent.Fail -> InterceptResult.Failure(result.logMessage)
}
)
}
}
}
}
sealed class InterceptResult {
class Idle : InterceptResult()
class Loading : InterceptResult()
data class Success(val mangaId: Long) : InterceptResult()
data class Failure(val reason: String) : InterceptResult()
}

View File

@ -1,42 +0,0 @@
package exh.ui.intercept
import eu.kanade.tachiyomi.ui.base.presenter.BasePresenter
import exh.GalleryAddEvent
import exh.GalleryAdder
import kotlin.concurrent.thread
import rx.subjects.BehaviorSubject
class InterceptActivityPresenter : BasePresenter<InterceptActivity>() {
private val galleryAdder = GalleryAdder()
val status = BehaviorSubject.create<InterceptResult>(InterceptResult.Idle())
@Synchronized
fun loadGallery(gallery: String) {
// Do not load gallery if already loading
if (status.value is InterceptResult.Idle) {
status.onNext(InterceptResult.Loading())
// Load gallery async
thread {
val result = galleryAdder.addGallery(gallery)
status.onNext(
when (result) {
is GalleryAddEvent.Success -> result.manga.id?.let {
InterceptResult.Success(it)
} ?: InterceptResult.Failure("Manga ID is null!")
is GalleryAddEvent.Fail -> InterceptResult.Failure(result.logMessage)
}
)
}
}
}
}
sealed class InterceptResult {
class Idle : InterceptResult()
class Loading : InterceptResult()
data class Success(val mangaId: Long) : InterceptResult()
data class Failure(val reason: String) : InterceptResult()
}

View File

@ -10,26 +10,25 @@
android:layout_height="match_parent"
android:orientation="vertical">
<com.google.android.material.appbar.AppBarLayout
<eu.kanade.tachiyomi.widget.ElevationAppBarLayout
android:id="@+id/appbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:elevation="0dp">
<androidx.appcompat.widget.Toolbar
<com.google.android.material.appbar.MaterialToolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"/>
</com.google.android.material.appbar.AppBarLayout>
</eu.kanade.tachiyomi.widget.ElevationAppBarLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:background="?attr/colorPrimary"
android:gravity="center"
android:orientation="vertical">
@ -39,16 +38,14 @@
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:text="Loading gallery..."
android:textAppearance="@style/TextAppearance.Medium.Title"
android:textColor="@color/white" />
android:textAppearance="@style/TextAppearance.Medium.Title" />
<ProgressBar
android:id="@+id/intercept_progress"
style="?android:attr/progressBarStyleLarge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:indeterminateTint="@color/white" />
android:layout_gravity="center" />
</LinearLayout>
</LinearLayout>