@ -46,7 +46,7 @@ import com.bumptech.glide.request.FutureTarget
import com.keylesspalace.tusky.BuildConfig.APPLICATION_ID
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.fragment.ViewImageFragment
import com.keylesspalace.tusky.pager.Avatar ImagePagerAdapter
import com.keylesspalace.tusky.pager.Single ImagePagerAdapter
import com.keylesspalace.tusky.pager.ImagePagerAdapter
import com.keylesspalace.tusky.util.getTemporaryMediaFilename
import com.keylesspalace.tusky.viewdata.AttachmentViewData
@ -68,7 +68,7 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
companion object {
private const val EXTRA _ATTACHMENTS = " attachments "
private const val EXTRA _ATTACHMENT _INDEX = " index "
private const val EXTRA _AVATAR _URL = " avatar "
private const val EXTRA _SINGLE _IMAGE _URL = " single_image "
private const val TAG = " ViewMediaActivity "
@JvmStatic
@ -79,9 +79,10 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
return intent
}
fun newAvatarIntent ( context : Context , url : String ) : Intent {
@JvmStatic
fun newSingleImageIntent ( context : Context , url : String ) : Intent {
val intent = Intent ( context , ViewMediaActivity :: class . java )
intent . putExtra ( EXTRA _AVATAR _URL , url )
intent . putExtra ( EXTRA _SINGLE _IMAGE _URL , url )
return intent
}
}
@ -91,6 +92,7 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
private var attachments : ArrayList < AttachmentViewData > ? = null
private val toolbarVisibilityListeners = mutableListOf < ToolbarVisibilityListener > ( )
private var imageUrl : String ? = null
fun addToolbarVisibilityListener ( listener : ToolbarVisibilityListener ) : Function0 < Boolean > {
this . toolbarVisibilityListeners . add ( listener )
@ -117,10 +119,10 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
ImagePagerAdapter ( this , realAttachs , initialPosition )
} else {
val avatar Url = intent . getStringExtra ( EXTRA _AVATAR _URL )
?: throw IllegalArgumentException ( " attachment list or avatar url has to be set " )
image Url = intent . getStringExtra ( EXTRA _SINGLE _IMAGE _URL )
?: throw IllegalArgumentException ( " attachment list or image url has to be set " )
Avatar ImagePagerAdapter( this , avatarUrl )
Single ImagePagerAdapter( this , imageUrl !! )
}
viewPager . adapter = adapter
@ -161,11 +163,10 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
}
override fun onCreateOptionsMenu ( menu : Menu ) : Boolean {
if ( attachments != null ) {
menuInflater . inflate ( R . menu . view _media _toolbar , menu )
return true
}
return false
menuInflater . inflate ( R . menu . view _media _toolbar , menu )
// We don't support 'open status' from single image views
menu ?. findItem ( R . id . action _open _status ) ?. isVisible = ( attachments != null )
return true
}
override fun onPrepareOptionsMenu ( menu : Menu ? ) : Boolean {
@ -213,7 +214,7 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
}
private fun downloadMedia ( ) {
val url = attachments !! [ viewPager . currentItem ] . attachment . url
val url = imageUrl ?: attachments !! [ viewPager . currentItem ] . attachment . url
val filename = Uri . parse ( url ) . lastPathSegment
Toast . makeText ( applicationContext , resources . getString ( R . string . download _image , filename ) , Toast . LENGTH _SHORT ) . show ( )
@ -240,8 +241,9 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
}
private fun copyLink ( ) {
val url = imageUrl ?: attachments !! [ viewPager . currentItem ] . attachment . url
val clipboard = getSystemService ( Context . CLIPBOARD _SERVICE ) as ClipboardManager
clipboard . setPrimaryClip ( ClipData . newPlainText ( null , attachments !! [ viewPager . currentItem ] . attachment . url ) )
clipboard . setPrimaryClip ( ClipData . newPlainText ( null , url ) )
}
private fun shareMedia ( ) {
@ -251,13 +253,17 @@ class ViewMediaActivity : BaseActivity(), ViewImageFragment.PhotoActionsListener
return
}
val attachment = attachments !! [ viewPager . currentItem ] . attachment
when ( attachment . type ) {
Attachment . Type . IMAGE -> shareImage ( directory , attachment . url )
Attachment . Type . AUDIO ,
Attachment . Type . VIDEO ,
Attachment . Type . GIFV -> shareMediaFile ( directory , attachment . url )
else -> Log . e ( TAG , " Unknown media format for sharing. " )
if ( imageUrl != null ) {
shareImage ( directory , imageUrl !! )
} else {
val attachment = attachments !! [ viewPager . currentItem ] . attachment
when ( attachment . type ) {
Attachment . Type . IMAGE -> shareImage ( directory , attachment . url )
Attachment . Type . AUDIO ,
Attachment . Type . VIDEO ,
Attachment . Type . GIFV -> shareMediaFile ( directory , attachment . url )
else -> Log . e ( TAG , " Unknown media format for sharing. " )
}
}
}