@ -6,6 +6,7 @@ import android.net.Uri
import android.os.Bundle
import android.os.Bundle
import android.view.Menu
import android.view.Menu
import android.view.MenuItem
import android.view.MenuItem
import android.widget.Toast
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.content.pm.ShortcutManagerCompat
import androidx.core.net.toFile
import androidx.core.net.toFile
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.lifecycleScope
@ -25,6 +26,7 @@ import org.koitharu.kotatsu.ui.download.DownloadService
import org.koitharu.kotatsu.utils.ShareHelper
import org.koitharu.kotatsu.utils.ShareHelper
import org.koitharu.kotatsu.utils.ShortcutUtils
import org.koitharu.kotatsu.utils.ShortcutUtils
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
import org.koitharu.kotatsu.utils.ext.getDisplayMessage
import org.koitharu.kotatsu.utils.ext.showDialog
class MangaDetailsActivity : BaseActivity ( ) , MangaDetailsView {
class MangaDetailsActivity : BaseActivity ( ) , MangaDetailsView {
@ -58,6 +60,14 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
override fun onLoadingStateChanged ( isLoading : Boolean ) = Unit
override fun onLoadingStateChanged ( isLoading : Boolean ) = Unit
override fun onMangaRemoved ( manga : Manga ) {
Toast . makeText (
this , getString ( R . string . _s _deleted _from _local _storage , manga . title ) ,
Toast . LENGTH _SHORT
) . show ( )
finish ( )
}
override fun onError ( e : Exception ) {
override fun onError ( e : Exception ) {
Snackbar . make ( pager , e . getDisplayMessage ( resources ) , Snackbar . LENGTH _LONG ) . show ( )
Snackbar . make ( pager , e . getDisplayMessage ( resources ) , Snackbar . LENGTH _LONG ) . show ( )
}
}
@ -68,9 +78,11 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
}
}
override fun onPrepareOptionsMenu ( menu : Menu ) : Boolean {
override fun onPrepareOptionsMenu ( menu : Menu ) : Boolean {
menu . findItem ( R . id . action _save ) . is Enabled =
menu . findItem ( R . id . action _save ) . is Visible =
manga ?. source != null && manga ?. source != MangaSource . LOCAL
manga ?. source != null && manga ?. source != MangaSource . LOCAL
menu . findItem ( R . id . action _shortcut ) . isVisible = BuildConfig . DEBUG ||
menu . findItem ( R . id . action _delete ) . isVisible =
manga ?. source == MangaSource . LOCAL
menu . findItem ( R . id . action _shortcut ) . isVisible = BuildConfig . DEBUG &&
ShortcutManagerCompat . isRequestPinShortcutSupported ( this )
ShortcutManagerCompat . isRequestPinShortcutSupported ( this )
return super . onPrepareOptionsMenu ( menu )
return super . onPrepareOptionsMenu ( menu )
}
}
@ -86,6 +98,19 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
}
}
true
true
}
}
R . id . action _delete -> {
manga ?. let { m ->
showDialog {
setTitle ( R . string . delete _manga )
setMessage ( getString ( R . string . text _delete _local _manga , m . title ) )
setPositiveButton ( R . string . delete ) { _ , _ ->
presenter . deleteLocal ( m )
}
setNegativeButton ( android . R . string . cancel , null )
}
}
true
}
R . id . action _save -> {
R . id . action _save -> {
manga ?. let {
manga ?. let {
DownloadService . start ( this , it )
DownloadService . start ( this , it )
@ -118,6 +143,8 @@ class MangaDetailsActivity : BaseActivity(), MangaDetailsView {
private const val EXTRA _MANGA = " manga "
private const val EXTRA _MANGA = " manga "
const val ACTION _MANGA _VIEW = " ${BuildConfig.APPLICATION_ID} .action.VIEW_MANGA "
fun newIntent ( context : Context , manga : Manga ) =
fun newIntent ( context : Context , manga : Manga ) =
Intent ( context , MangaDetailsActivity :: class . java )
Intent ( context , MangaDetailsActivity :: class . java )
. putExtra ( EXTRA _MANGA , manga )
. putExtra ( EXTRA _MANGA , manga )