Fix intercept activity

This commit is contained in:
NerdNumber9 2017-08-24 17:33:03 -04:00
parent 5ed365cf0d
commit dcb6ae44dd
4 changed files with 59 additions and 35 deletions

View File

@ -149,19 +149,17 @@ sealed class GalleryAddEvent {
class Success(override val galleryUrl: String,
val manga: Manga): GalleryAddEvent() {
override val logMessage = "[OK] Added gallery: $galleryTitle"
override val logMessage = "Added gallery: $galleryTitle"
override val galleryTitle: String
get() = manga.title
}
sealed class Fail: GalleryAddEvent() {
class UnknownType(override val galleryUrl: String): Fail() {
override val logMessage = "[ERROR] Unknown gallery type for gallery: $galleryUrl"
override val logMessage = "Unknown gallery type for gallery: $galleryUrl"
}
class Error(override val galleryUrl: String,
val message: String): Fail() {
override val logMessage = "[ERROR] $message"
}
override val logMessage: String): Fail()
}
}

View File

@ -40,7 +40,11 @@ class BatchAddPresenter: BasePresenter<BatchAddController>() {
failed.add(s)
}
progressRelay.call(i + 1)
eventRelay?.call(result.logMessage)
eventRelay?.call((when (result) {
is GalleryAddEvent.Success -> "[OK]"
is GalleryAddEvent.Fail -> "[ERROR]"
else -> "[???]"
}) + " " + result.logMessage)
}
//Show report

View File

@ -5,36 +5,59 @@ import android.os.Bundle
import android.view.MenuItem
import com.afollestad.materialdialogs.MaterialDialog
import eu.kanade.tachiyomi.R
import eu.kanade.tachiyomi.data.preference.PreferencesHelper
import eu.kanade.tachiyomi.ui.base.activity.BaseActivity
import eu.kanade.tachiyomi.ui.main.MainActivity
import eu.kanade.tachiyomi.ui.manga.MangaController
import exh.GalleryAddEvent
import exh.GalleryAdder
import timber.log.Timber
import kotlinx.android.synthetic.main.eh_activity_intercept.*
import uy.kohesive.injekt.injectLazy
import kotlin.concurrent.thread
//TODO :(
class InterceptActivity : BaseActivity() {
private val preferences: PreferencesHelper by injectLazy()
private val galleryAdder = GalleryAdder()
var finished = false
override fun onCreate(savedInstanceState: Bundle?) {
//Set theme
setTheme(when (preferences.theme()) {
2 -> R.style.Theme_Tachiyomi_Dark
3 -> R.style.Theme_Tachiyomi_Amoled
else -> R.style.Theme_Tachiyomi
})
super.onCreate(savedInstanceState)
setContentView(R.layout.eh_activity_intercept)
//Show back button
setSupportActionBar(toolbar)
supportActionBar?.setDisplayHomeAsUpEnabled(true)
if(savedInstanceState == null)
thread { setup() }
thread { processLink() }
}
fun setup() {
try {
processLink()
} catch(t: Throwable) {
Timber.e(t, "Could not intercept link!")
private fun processLink() {
if(Intent.ACTION_VIEW == intent.action) {
val result = galleryAdder.addGallery(intent.dataString)
when(result) {
is GalleryAddEvent.Success ->
if(!finished)
startActivity(Intent(this, MainActivity::class.java)
.setAction(MainActivity.SHORTCUT_MANGA)
.putExtra(MangaController.MANGA_EXTRA, result.manga.id))
is GalleryAddEvent.Fail ->
if(!finished)
runOnUiThread {
MaterialDialog.Builder(this)
.title("Error")
.content("Could not load this gallery!")
.content("Could not open this gallery:\n\n${result.logMessage}")
.cancelable(true)
.canceledOnTouchOutside(true)
.cancelListener { onBackPressed() }
@ -44,15 +67,6 @@ class InterceptActivity : BaseActivity() {
.show()
}
}
}
fun processLink() {
if(Intent.ACTION_VIEW == intent.action) {
val manga = galleryAdder.addGallery(intent.dataString)
//TODO
// if(!finished)
// startActivity(MangaActivity.newIntent(this, manga, true))
onBackPressed()
}
}

View File

@ -17,6 +17,14 @@
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:theme="?attr/actionBarTheme"/>
</android.support.design.widget.AppBarLayout>
<FrameLayout