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