@ -20,6 +20,7 @@ import android.widget.Toast
import com.afollestad.materialdialogs.MaterialDialog
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.load.resource.bitmap.RoundedCorners
import com.bumptech.glide.request.target.CustomTarget
import com.bumptech.glide.request.target.SimpleTarget
import com.bumptech.glide.request.transition.Transition
import com.jakewharton.rxbinding.support.v4.widget.refreshes
@ -46,6 +47,7 @@ import jp.wasabeef.glide.transformations.CropSquareTransformation
import jp.wasabeef.glide.transformations.MaskTransformation
import kotlinx.android.synthetic.main.manga_info_controller.*
import uy.kohesive.injekt.injectLazy
import java.io.File
import java.text.DateFormat
import java.text.DecimalFormat
import java.util.Date
@ -161,7 +163,7 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
when ( item . itemId ) {
R . id . action _open _in _browser -> openInBrowser ( )
R . id . action _open _in _web _view -> openInWebView ( )
R . id . action _share -> s hareManga( )
R . id . action _share -> prepareToS hareManga( )
R . id . action _add _to _home _screen -> addToHomeScreen ( )
else -> return super . onOptionsItemSelected ( item )
}
@ -325,15 +327,40 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
/ * *
* Called to run Intent with [ Intent . ACTION _SEND ] , which show share dialog .
* /
private fun shareManga ( ) {
private fun prepareToShareManga ( ) {
if ( Build . VERSION . SDK _INT >= Build . VERSION_CODES . Q )
GlideApp . with ( activity !! ) . asBitmap ( ) . load ( presenter . manga ) . into ( object :
CustomTarget < Bitmap > ( ) {
override fun onResourceReady ( resource : Bitmap , transition : Transition < in Bitmap > ? ) {
presenter . shareManga ( resource )
}
override fun onLoadCleared ( placeholder : Drawable ? ) { }
override fun onLoadFailed ( errorDrawable : Drawable ? ) {
shareManga ( )
}
} )
else shareManga ( )
}
/ * *
* Called to run Intent with [ Intent . ACTION _SEND ] , which show share dialog .
* /
fun shareManga ( cover : File ? = null ) {
val context = view ?. context ?: return
val source = presenter . source as ? HttpSource ?: return
val stream = cover ?. getUriCompat ( context )
try {
val url = source . mangaDetailsRequest ( presenter . manga ) . url . toString ( )
val intent = Intent ( Intent . ACTION _SEND ) . apply {
type = " text/plain "
type = " text/ * "
putExtra ( Intent . EXTRA _TEXT , url )
putExtra ( Intent . EXTRA _TITLE , presenter . manga . title )
flags = Intent . FLAG _GRANT _READ _URI _PERMISSION
if ( stream != null ) {
clipData = ClipData . newRawUri ( null , stream )
}
}
startActivity ( Intent . createChooser ( intent , context . getString ( R . string . action _share ) ) )
} catch ( e : Exception ) {
@ -523,11 +550,13 @@ class MangaInfoController : NucleusController<MangaInfoPresenter>(),
3 -> centerCrop ( ) . transform ( MaskTransformation ( R . drawable . mask _star ) )
}
}
. into ( object : Simple Target< Bitmap > ( 96 , 96 ) {
. into ( object : Custom Target< Bitmap > ( 96 , 96 ) {
override fun onResourceReady ( resource : Bitmap , transition : Transition < in Bitmap > ? ) {
createShortcut ( resource )
}
override fun onLoadCleared ( placeholder : Drawable ? ) { }
override fun onLoadFailed ( errorDrawable : Drawable ? ) {
activity ?. toast ( R . string . icon _creation _fail )
}