Option to edit manga in details screen
This commit is contained in:
@@ -246,8 +246,7 @@ class AppRouter private constructor(
|
||||
}
|
||||
|
||||
fun openMangaOverrideConfig(manga: Manga) {
|
||||
val intent = Intent(contextOrNull() ?: return, OverrideConfigActivity::class.java)
|
||||
.putExtra(KEY_MANGA, ParcelableManga(manga, withDescription = false))
|
||||
val intent = overrideEditIntent(contextOrNull() ?: return, manga)
|
||||
startActivity(intent)
|
||||
}
|
||||
|
||||
@@ -768,6 +767,10 @@ class AppRouter private constructor(
|
||||
.putExtra(KEY_SOURCE, source.name)
|
||||
}
|
||||
|
||||
fun overrideEditIntent(context: Context, manga: Manga): Intent =
|
||||
Intent(context, OverrideConfigActivity::class.java)
|
||||
.putExtra(KEY_MANGA, ParcelableManga(manga, withDescription = false))
|
||||
|
||||
fun isShareSupported(manga: Manga): Boolean = when {
|
||||
manga.isBroken -> false
|
||||
manga.isLocal -> manga.url.toUri().toFileOrNull() != null
|
||||
|
||||
@@ -1,9 +1,13 @@
|
||||
package org.koitharu.kotatsu.details.ui
|
||||
|
||||
import android.app.Activity
|
||||
import android.view.Menu
|
||||
import android.view.MenuInflater
|
||||
import android.view.MenuItem
|
||||
import android.view.View
|
||||
import androidx.activity.result.ActivityResult
|
||||
import androidx.activity.result.ActivityResultCallback
|
||||
import androidx.activity.result.contract.ActivityResultContracts
|
||||
import androidx.core.content.pm.ShortcutManagerCompat
|
||||
import androidx.core.view.MenuProvider
|
||||
import androidx.fragment.app.FragmentActivity
|
||||
@@ -23,7 +27,12 @@ class DetailsMenuProvider(
|
||||
private val viewModel: DetailsViewModel,
|
||||
private val snackbarHost: View,
|
||||
private val appShortcutManager: AppShortcutManager,
|
||||
) : MenuProvider {
|
||||
) : MenuProvider, ActivityResultCallback<ActivityResult> {
|
||||
|
||||
private val activityForResultLauncher = activity.registerForActivityResult(
|
||||
ActivityResultContracts.StartActivityForResult(),
|
||||
this,
|
||||
)
|
||||
|
||||
private val router: AppRouter
|
||||
get() = activity.router
|
||||
@@ -98,8 +107,19 @@ class DetailsMenuProvider(
|
||||
}
|
||||
}
|
||||
|
||||
R.id.action_edit_override -> {
|
||||
val intent = AppRouter.overrideEditIntent(activity, manga)
|
||||
activityForResultLauncher.launch(intent)
|
||||
}
|
||||
|
||||
else -> return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
override fun onActivityResult(result: ActivityResult) {
|
||||
if (result.resultCode == Activity.RESULT_OK) {
|
||||
viewModel.reload()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -45,7 +45,7 @@ class OverrideConfigActivity : BaseActivity<ActivityOverrideEditBinding>(), View
|
||||
viewBinding.buttonResetCover.setOnClickListener(this)
|
||||
viewBinding.layoutName.setEndIconOnClickListener(this)
|
||||
viewModel.data.filterNotNull().observe(this, ::onDataChanged)
|
||||
viewModel.onSaved.observeEvent(this) { finishAfterTransition() }
|
||||
viewModel.onSaved.observeEvent(this) { onDataSaved() }
|
||||
viewModel.isLoading.observe(this, ::onLoadingStateChanged)
|
||||
viewModel.onError.observeEvent(this, ::onError)
|
||||
}
|
||||
@@ -120,4 +120,9 @@ class OverrideConfigActivity : BaseActivity<ActivityOverrideEditBinding>(), View
|
||||
viewBinding.textViewError.isVisible = false
|
||||
}
|
||||
}
|
||||
|
||||
private fun onDataSaved() {
|
||||
setResult(RESULT_OK)
|
||||
finish()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,6 +25,12 @@
|
||||
android:visible="false"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_edit_override"
|
||||
android:orderInCategory="40"
|
||||
android:title="@string/edit"
|
||||
app:showAsAction="never" />
|
||||
|
||||
<item
|
||||
android:id="@+id/action_scrobbling"
|
||||
android:orderInCategory="50"
|
||||
|
||||
Reference in New Issue
Block a user