mirror of
https://github.com/mihonapp/mihon.git
synced 2025-03-13 08:10:07 +01:00
Fix intercept activity
This commit is contained in:
parent
5ed365cf0d
commit
dcb6ae44dd
@ -149,19 +149,17 @@ sealed class GalleryAddEvent {
|
|||||||
|
|
||||||
class Success(override val galleryUrl: String,
|
class Success(override val galleryUrl: String,
|
||||||
val manga: Manga): GalleryAddEvent() {
|
val manga: Manga): GalleryAddEvent() {
|
||||||
override val logMessage = "[OK] Added gallery: $galleryTitle"
|
override val logMessage = "Added gallery: $galleryTitle"
|
||||||
override val galleryTitle: String
|
override val galleryTitle: String
|
||||||
get() = manga.title
|
get() = manga.title
|
||||||
}
|
}
|
||||||
|
|
||||||
sealed class Fail: GalleryAddEvent() {
|
sealed class Fail: GalleryAddEvent() {
|
||||||
class UnknownType(override val galleryUrl: String): Fail() {
|
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,
|
class Error(override val galleryUrl: String,
|
||||||
val message: String): Fail() {
|
override val logMessage: String): Fail()
|
||||||
override val logMessage = "[ERROR] $message"
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -40,7 +40,11 @@ class BatchAddPresenter: BasePresenter<BatchAddController>() {
|
|||||||
failed.add(s)
|
failed.add(s)
|
||||||
}
|
}
|
||||||
progressRelay.call(i + 1)
|
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
|
//Show report
|
||||||
|
@ -5,54 +5,68 @@ import android.os.Bundle
|
|||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
import com.afollestad.materialdialogs.MaterialDialog
|
import com.afollestad.materialdialogs.MaterialDialog
|
||||||
import eu.kanade.tachiyomi.R
|
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.base.activity.BaseActivity
|
||||||
|
import eu.kanade.tachiyomi.ui.main.MainActivity
|
||||||
|
import eu.kanade.tachiyomi.ui.manga.MangaController
|
||||||
|
import exh.GalleryAddEvent
|
||||||
import exh.GalleryAdder
|
import exh.GalleryAdder
|
||||||
import timber.log.Timber
|
import kotlinx.android.synthetic.main.eh_activity_intercept.*
|
||||||
|
import uy.kohesive.injekt.injectLazy
|
||||||
import kotlin.concurrent.thread
|
import kotlin.concurrent.thread
|
||||||
|
|
||||||
//TODO :(
|
|
||||||
class InterceptActivity : BaseActivity() {
|
class InterceptActivity : BaseActivity() {
|
||||||
|
|
||||||
|
private val preferences: PreferencesHelper by injectLazy()
|
||||||
|
|
||||||
private val galleryAdder = GalleryAdder()
|
private val galleryAdder = GalleryAdder()
|
||||||
|
|
||||||
var finished = false
|
var finished = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
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)
|
super.onCreate(savedInstanceState)
|
||||||
setContentView(R.layout.eh_activity_intercept)
|
setContentView(R.layout.eh_activity_intercept)
|
||||||
|
|
||||||
|
//Show back button
|
||||||
|
setSupportActionBar(toolbar)
|
||||||
|
supportActionBar?.setDisplayHomeAsUpEnabled(true)
|
||||||
|
|
||||||
if(savedInstanceState == null)
|
if(savedInstanceState == null)
|
||||||
thread { setup() }
|
thread { processLink() }
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setup() {
|
private fun processLink() {
|
||||||
try {
|
|
||||||
processLink()
|
|
||||||
} catch(t: Throwable) {
|
|
||||||
Timber.e(t, "Could not intercept link!")
|
|
||||||
if(!finished)
|
|
||||||
runOnUiThread {
|
|
||||||
MaterialDialog.Builder(this)
|
|
||||||
.title("Error")
|
|
||||||
.content("Could not load this gallery!")
|
|
||||||
.cancelable(true)
|
|
||||||
.canceledOnTouchOutside(true)
|
|
||||||
.cancelListener { onBackPressed() }
|
|
||||||
.positiveText("Ok")
|
|
||||||
.onPositive { _, _ -> onBackPressed() }
|
|
||||||
.dismissListener { onBackPressed() }
|
|
||||||
.show()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
fun processLink() {
|
|
||||||
if(Intent.ACTION_VIEW == intent.action) {
|
if(Intent.ACTION_VIEW == intent.action) {
|
||||||
val manga = galleryAdder.addGallery(intent.dataString)
|
val result = galleryAdder.addGallery(intent.dataString)
|
||||||
|
|
||||||
//TODO
|
when(result) {
|
||||||
// if(!finished)
|
is GalleryAddEvent.Success ->
|
||||||
// startActivity(MangaActivity.newIntent(this, manga, true))
|
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 open this gallery:\n\n${result.logMessage}")
|
||||||
|
.cancelable(true)
|
||||||
|
.canceledOnTouchOutside(true)
|
||||||
|
.cancelListener { onBackPressed() }
|
||||||
|
.positiveText("Ok")
|
||||||
|
.onPositive { _, _ -> onBackPressed() }
|
||||||
|
.dismissListener { onBackPressed() }
|
||||||
|
.show()
|
||||||
|
}
|
||||||
|
}
|
||||||
onBackPressed()
|
onBackPressed()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,14 @@
|
|||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
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>
|
</android.support.design.widget.AppBarLayout>
|
||||||
|
|
||||||
<FrameLayout
|
<FrameLayout
|
||||||
|
Loading…
x
Reference in New Issue
Block a user