add ktlint plugin to project and apply default code style (#2209)
* add ktlint plugin to project and apply default code style * some manual adjustments, fix wildcard imports * update CONTRIBUTING.md * fix formatting
This commit is contained in:
parent
955267199e
commit
16ffcca748
227 changed files with 3933 additions and 3371 deletions
|
|
@ -33,9 +33,14 @@ import com.keylesspalace.tusky.AccountActivity
|
|||
import com.keylesspalace.tusky.AccountListActivity.Type
|
||||
import com.keylesspalace.tusky.BaseActivity
|
||||
import com.keylesspalace.tusky.R
|
||||
import com.keylesspalace.tusky.adapter.*
|
||||
import com.keylesspalace.tusky.db.AccountManager
|
||||
import com.keylesspalace.tusky.adapter.AccountAdapter
|
||||
import com.keylesspalace.tusky.adapter.BlocksAdapter
|
||||
import com.keylesspalace.tusky.adapter.FollowAdapter
|
||||
import com.keylesspalace.tusky.adapter.FollowRequestsAdapter
|
||||
import com.keylesspalace.tusky.adapter.FollowRequestsHeaderAdapter
|
||||
import com.keylesspalace.tusky.adapter.MutesAdapter
|
||||
import com.keylesspalace.tusky.databinding.FragmentAccountListBinding
|
||||
import com.keylesspalace.tusky.db.AccountManager
|
||||
import com.keylesspalace.tusky.di.Injectable
|
||||
import com.keylesspalace.tusky.entity.Account
|
||||
import com.keylesspalace.tusky.entity.Relationship
|
||||
|
|
@ -51,7 +56,7 @@ import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
|
|||
import io.reactivex.rxjava3.core.Single
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.HashMap
|
||||
import javax.inject.Inject
|
||||
|
||||
class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountActionListener, Injectable {
|
||||
|
|
@ -133,12 +138,15 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
} else {
|
||||
api.muteAccount(id, notifications)
|
||||
}
|
||||
.autoDispose(from(this))
|
||||
.subscribe({
|
||||
.autoDispose(from(this))
|
||||
.subscribe(
|
||||
{
|
||||
onMuteSuccess(mute, id, position, notifications)
|
||||
}, {
|
||||
},
|
||||
{
|
||||
onMuteFailure(mute, id, notifications)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun onMuteSuccess(muted: Boolean, id: String, position: Int, notifications: Boolean) {
|
||||
|
|
@ -151,11 +159,11 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
|
||||
if (unmutedUser != null) {
|
||||
Snackbar.make(binding.recyclerView, R.string.confirmation_unmuted, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.action_undo) {
|
||||
mutesAdapter.addItem(unmutedUser, position)
|
||||
onMute(true, id, position, notifications)
|
||||
}
|
||||
.show()
|
||||
.setAction(R.string.action_undo) {
|
||||
mutesAdapter.addItem(unmutedUser, position)
|
||||
onMute(true, id, position, notifications)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -178,12 +186,15 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
} else {
|
||||
api.blockAccount(id)
|
||||
}
|
||||
.autoDispose(from(this))
|
||||
.subscribe({
|
||||
.autoDispose(from(this))
|
||||
.subscribe(
|
||||
{
|
||||
onBlockSuccess(block, id, position)
|
||||
}, {
|
||||
},
|
||||
{
|
||||
onBlockFailure(block, id)
|
||||
})
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun onBlockSuccess(blocked: Boolean, id: String, position: Int) {
|
||||
|
|
@ -195,11 +206,11 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
|
||||
if (unblockedUser != null) {
|
||||
Snackbar.make(binding.recyclerView, R.string.confirmation_unblocked, Snackbar.LENGTH_LONG)
|
||||
.setAction(R.string.action_undo) {
|
||||
blocksAdapter.addItem(unblockedUser, position)
|
||||
onBlock(true, id, position)
|
||||
}
|
||||
.show()
|
||||
.setAction(R.string.action_undo) {
|
||||
blocksAdapter.addItem(unblockedUser, position)
|
||||
onBlock(true, id, position)
|
||||
}
|
||||
.show()
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -212,26 +223,31 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
Log.e(TAG, "Failed to $verb account accountId $accountId")
|
||||
}
|
||||
|
||||
override fun onRespondToFollowRequest(accept: Boolean, accountId: String,
|
||||
position: Int) {
|
||||
override fun onRespondToFollowRequest(
|
||||
accept: Boolean,
|
||||
accountId: String,
|
||||
position: Int
|
||||
) {
|
||||
|
||||
if (accept) {
|
||||
api.authorizeFollowRequest(accountId)
|
||||
} else {
|
||||
api.rejectFollowRequest(accountId)
|
||||
}.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(from(this, Lifecycle.Event.ON_DESTROY))
|
||||
.subscribe({
|
||||
.autoDispose(from(this, Lifecycle.Event.ON_DESTROY))
|
||||
.subscribe(
|
||||
{
|
||||
onRespondToFollowRequestSuccess(position)
|
||||
}, { throwable ->
|
||||
},
|
||||
{ throwable ->
|
||||
val verb = if (accept) {
|
||||
"accept"
|
||||
} else {
|
||||
"reject"
|
||||
}
|
||||
Log.e(TAG, "Failed to $verb account id $accountId.", throwable)
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun onRespondToFollowRequestSuccess(position: Int) {
|
||||
|
|
@ -264,7 +280,7 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
}
|
||||
|
||||
private fun requireId(type: Type, id: String?): String {
|
||||
return requireNotNull(id) { "id must not be null for type "+type.name }
|
||||
return requireNotNull(id) { "id must not be null for type " + type.name }
|
||||
}
|
||||
|
||||
private fun fetchAccounts(fromId: String? = null) {
|
||||
|
|
@ -278,9 +294,10 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
}
|
||||
|
||||
getFetchCallByListType(fromId)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(from(this, Lifecycle.Event.ON_DESTROY))
|
||||
.subscribe({ response ->
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(from(this, Lifecycle.Event.ON_DESTROY))
|
||||
.subscribe(
|
||||
{ response ->
|
||||
val accountList = response.body()
|
||||
|
||||
if (response.isSuccessful && accountList != null) {
|
||||
|
|
@ -289,10 +306,11 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
} else {
|
||||
onFetchAccountsFailure(Exception(response.message()))
|
||||
}
|
||||
}, {throwable ->
|
||||
},
|
||||
{ throwable ->
|
||||
onFetchAccountsFailure(throwable)
|
||||
})
|
||||
|
||||
}
|
||||
)
|
||||
}
|
||||
|
||||
private fun onFetchAccountsSuccess(accounts: List<Account>, linkHeader: String?) {
|
||||
|
|
@ -319,9 +337,9 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
if (adapter.itemCount == 0) {
|
||||
binding.messageView.show()
|
||||
binding.messageView.setup(
|
||||
R.drawable.elephant_friend_empty,
|
||||
R.string.message_empty,
|
||||
null
|
||||
R.drawable.elephant_friend_empty,
|
||||
R.string.message_empty,
|
||||
null
|
||||
)
|
||||
} else {
|
||||
binding.messageView.hide()
|
||||
|
|
@ -330,11 +348,11 @@ class AccountListFragment : Fragment(R.layout.fragment_account_list), AccountAct
|
|||
|
||||
private fun fetchRelationships(ids: List<String>) {
|
||||
api.relationships(ids)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(from(this))
|
||||
.subscribe(::onFetchRelationshipsSuccess) {
|
||||
onFetchRelationshipsFailure(ids)
|
||||
}
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(from(this))
|
||||
.subscribe(::onFetchRelationshipsSuccess) {
|
||||
onFetchRelationshipsFailure(ids)
|
||||
}
|
||||
}
|
||||
|
||||
private fun onFetchRelationshipsSuccess(relationships: List<Relationship>) {
|
||||
|
|
|
|||
|
|
@ -49,7 +49,7 @@ import io.reactivex.rxjava3.core.SingleObserver
|
|||
import io.reactivex.rxjava3.disposables.Disposable
|
||||
import retrofit2.Response
|
||||
import java.io.IOException
|
||||
import java.util.*
|
||||
import java.util.Random
|
||||
import javax.inject.Inject
|
||||
|
||||
/**
|
||||
|
|
@ -156,18 +156,17 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
isSwipeToRefreshEnabled = arguments?.getBoolean(ARG_ENABLE_SWIPE_TO_REFRESH,true) == true
|
||||
accountId = arguments?.getString(ACCOUNT_ID_ARG)!!
|
||||
isSwipeToRefreshEnabled = arguments?.getBoolean(ARG_ENABLE_SWIPE_TO_REFRESH, true) == true
|
||||
accountId = arguments?.getString(ACCOUNT_ID_ARG)!!
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
|
||||
val columnCount = view.context.resources.getInteger(R.integer.profile_media_column_count)
|
||||
val layoutManager = GridLayoutManager(view.context, columnCount)
|
||||
|
||||
adapter.baseItemColor = ThemeUtils.getColor(view.context, android.R.attr.windowBackground)
|
||||
adapter.baseItemColor = ThemeUtils.getColor(view.context, android.R.attr.windowBackground)
|
||||
|
||||
binding.recyclerView.layoutManager = layoutManager
|
||||
binding.recyclerView.adapter = adapter
|
||||
|
|
@ -188,12 +187,12 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
val lastItem = layoutManager.findLastCompletelyVisibleItemPosition()
|
||||
if (itemCount <= lastItem + 3 && fetchingStatus == FetchingStatus.NOT_FETCHING) {
|
||||
statuses.lastOrNull()?.let { (id) ->
|
||||
Log.d(TAG, "Requesting statuses with max_id: ${id}, (bottom)")
|
||||
Log.d(TAG, "Requesting statuses with max_id: $id, (bottom)")
|
||||
fetchingStatus = FetchingStatus.FETCHING_BOTTOM
|
||||
api.accountStatuses(accountId, id, null, null, null, true, null)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(this@AccountMediaFragment, Lifecycle.Event.ON_DESTROY)
|
||||
.subscribe(bottomCallback)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(this@AccountMediaFragment, Lifecycle.Event.ON_DESTROY)
|
||||
.subscribe(bottomCallback)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -213,8 +212,8 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
fetchingStatus = FetchingStatus.REFRESHING
|
||||
api.accountStatuses(accountId, null, statuses[0].id, null, null, true, null)
|
||||
}.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
|
||||
.subscribe(callback)
|
||||
.autoDispose(this, Lifecycle.Event.ON_DESTROY)
|
||||
.subscribe(callback)
|
||||
|
||||
if (!isSwipeToRefreshEnabled)
|
||||
binding.topProgressBar.show()
|
||||
|
|
@ -227,11 +226,10 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
if (fetchingStatus == FetchingStatus.NOT_FETCHING && statuses.isEmpty()) {
|
||||
fetchingStatus = FetchingStatus.INITIAL_FETCHING
|
||||
api.accountStatuses(accountId, null, null, null, null, true, null)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(this@AccountMediaFragment, Lifecycle.Event.ON_DESTROY)
|
||||
.subscribe(callback)
|
||||
}
|
||||
else if (needToRefresh)
|
||||
.observeOn(AndroidSchedulers.mainThread())
|
||||
.autoDispose(this@AccountMediaFragment, Lifecycle.Event.ON_DESTROY)
|
||||
.subscribe(callback)
|
||||
} else if (needToRefresh)
|
||||
refresh()
|
||||
needToRefresh = false
|
||||
}
|
||||
|
|
@ -264,7 +262,7 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
}
|
||||
|
||||
inner class MediaGridAdapter :
|
||||
RecyclerView.Adapter<MediaGridAdapter.MediaViewHolder>() {
|
||||
RecyclerView.Adapter<MediaGridAdapter.MediaViewHolder>() {
|
||||
|
||||
var baseItemColor = Color.BLACK
|
||||
|
||||
|
|
@ -305,15 +303,14 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
val item = items[position]
|
||||
|
||||
Glide.with(holder.imageView)
|
||||
.load(item.attachment.previewUrl)
|
||||
.centerInside()
|
||||
.into(holder.imageView)
|
||||
.load(item.attachment.previewUrl)
|
||||
.centerInside()
|
||||
.into(holder.imageView)
|
||||
}
|
||||
|
||||
|
||||
inner class MediaViewHolder(val imageView: ImageView)
|
||||
: RecyclerView.ViewHolder(imageView),
|
||||
View.OnClickListener {
|
||||
inner class MediaViewHolder(val imageView: ImageView) :
|
||||
RecyclerView.ViewHolder(imageView),
|
||||
View.OnClickListener {
|
||||
init {
|
||||
itemView.setOnClickListener(this)
|
||||
}
|
||||
|
|
@ -334,11 +331,11 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
|
||||
companion object {
|
||||
@JvmStatic
|
||||
fun newInstance(accountId: String, enableSwipeToRefresh:Boolean=true): AccountMediaFragment {
|
||||
fun newInstance(accountId: String, enableSwipeToRefresh: Boolean = true): AccountMediaFragment {
|
||||
val fragment = AccountMediaFragment()
|
||||
val args = Bundle()
|
||||
args.putString(ACCOUNT_ID_ARG, accountId)
|
||||
args.putBoolean(ARG_ENABLE_SWIPE_TO_REFRESH,enableSwipeToRefresh)
|
||||
args.putBoolean(ARG_ENABLE_SWIPE_TO_REFRESH, enableSwipeToRefresh)
|
||||
fragment.arguments = args
|
||||
return fragment
|
||||
}
|
||||
|
|
@ -347,4 +344,4 @@ class AccountMediaFragment : Fragment(R.layout.fragment_timeline), RefreshableFr
|
|||
private const val TAG = "AccountMediaFragment"
|
||||
private const val ARG_ENABLE_SWIPE_TO_REFRESH = "arg.enable.swipe.to.refresh"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -66,12 +66,11 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
photoActionsListener = context as PhotoActionsListener
|
||||
}
|
||||
|
||||
|
||||
override fun setupMediaView(
|
||||
url: String,
|
||||
previewUrl: String?,
|
||||
description: String?,
|
||||
showingDescription: Boolean
|
||||
url: String,
|
||||
previewUrl: String?,
|
||||
description: String?,
|
||||
showingDescription: Boolean
|
||||
) {
|
||||
binding.photoView.transitionName = url
|
||||
binding.mediaDescription.text = description
|
||||
|
|
@ -136,9 +135,9 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
|
||||
if (event.action == MotionEvent.ACTION_DOWN) {
|
||||
lastY = event.rawY
|
||||
} else if (event.pointerCount == 1
|
||||
&& attacher.scale == 1f
|
||||
&& event.action == MotionEvent.ACTION_MOVE
|
||||
} else if (event.pointerCount == 1 &&
|
||||
attacher.scale == 1f &&
|
||||
event.action == MotionEvent.ACTION_MOVE
|
||||
) {
|
||||
val diff = event.rawY - lastY
|
||||
// This code is to prevent transformations during page scrolling
|
||||
|
|
@ -176,21 +175,21 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
}
|
||||
|
||||
override fun onToolbarVisibilityChange(visible: Boolean) {
|
||||
if (_binding == null || !userVisibleHint ) {
|
||||
if (_binding == null || !userVisibleHint) {
|
||||
return
|
||||
}
|
||||
isDescriptionVisible = showingDescription && visible
|
||||
val alpha = if (isDescriptionVisible) 1.0f else 0.0f
|
||||
binding.captionSheet.animate().alpha(alpha)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
if (_binding != null) {
|
||||
binding.captionSheet.visible(isDescriptionVisible)
|
||||
}
|
||||
animation.removeListener(this)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
if (_binding != null) {
|
||||
binding.captionSheet.visible(isDescriptionVisible)
|
||||
}
|
||||
})
|
||||
.start()
|
||||
animation.removeListener(this)
|
||||
}
|
||||
})
|
||||
.start()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
|
@ -204,27 +203,30 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
val glide = Glide.with(this)
|
||||
// Request image from the any cache
|
||||
glide
|
||||
.load(url)
|
||||
.dontAnimate()
|
||||
.onlyRetrieveFromCache(true)
|
||||
.let {
|
||||
if (previewUrl != null)
|
||||
it.thumbnail(glide
|
||||
.load(previewUrl)
|
||||
.dontAnimate()
|
||||
.onlyRetrieveFromCache(true)
|
||||
.centerInside()
|
||||
.addListener(ImageRequestListener(true, isThumnailRequest = true)))
|
||||
else it
|
||||
}
|
||||
//Request image from the network on fail load image from cache
|
||||
.error(glide.load(url)
|
||||
.centerInside()
|
||||
.addListener(ImageRequestListener(false, isThumnailRequest = false))
|
||||
)
|
||||
.centerInside()
|
||||
.addListener(ImageRequestListener(true, isThumnailRequest = false))
|
||||
.into(photoView)
|
||||
.load(url)
|
||||
.dontAnimate()
|
||||
.onlyRetrieveFromCache(true)
|
||||
.let {
|
||||
if (previewUrl != null)
|
||||
it.thumbnail(
|
||||
glide
|
||||
.load(previewUrl)
|
||||
.dontAnimate()
|
||||
.onlyRetrieveFromCache(true)
|
||||
.centerInside()
|
||||
.addListener(ImageRequestListener(true, isThumnailRequest = true))
|
||||
)
|
||||
else it
|
||||
}
|
||||
// Request image from the network on fail load image from cache
|
||||
.error(
|
||||
glide.load(url)
|
||||
.centerInside()
|
||||
.addListener(ImageRequestListener(false, isThumnailRequest = false))
|
||||
)
|
||||
.centerInside()
|
||||
.addListener(ImageRequestListener(true, isThumnailRequest = false))
|
||||
.into(photoView)
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -248,14 +250,20 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
* @param isCacheRequest - is this listener for request image from cache or from the network
|
||||
*/
|
||||
private inner class ImageRequestListener(
|
||||
private val isCacheRequest: Boolean,
|
||||
private val isThumnailRequest: Boolean) : RequestListener<Drawable> {
|
||||
private val isCacheRequest: Boolean,
|
||||
private val isThumnailRequest: Boolean
|
||||
) : RequestListener<Drawable> {
|
||||
|
||||
override fun onLoadFailed(e: GlideException?, model: Any, target: Target<Drawable>,
|
||||
isFirstResource: Boolean): Boolean {
|
||||
override fun onLoadFailed(
|
||||
e: GlideException?,
|
||||
model: Any,
|
||||
target: Target<Drawable>,
|
||||
isFirstResource: Boolean
|
||||
): Boolean {
|
||||
// If cache for full image failed complete transition
|
||||
if (isCacheRequest && !isThumnailRequest && shouldStartTransition
|
||||
&& !startedTransition) {
|
||||
if (isCacheRequest && !isThumnailRequest && shouldStartTransition &&
|
||||
!startedTransition
|
||||
) {
|
||||
photoActionsListener.onBringUp()
|
||||
}
|
||||
// Hide progress bar only on fail request from internet
|
||||
|
|
@ -265,8 +273,13 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
}
|
||||
|
||||
@SuppressLint("CheckResult")
|
||||
override fun onResourceReady(resource: Drawable, model: Any, target: Target<Drawable>,
|
||||
dataSource: DataSource, isFirstResource: Boolean): Boolean {
|
||||
override fun onResourceReady(
|
||||
resource: Drawable,
|
||||
model: Any,
|
||||
target: Target<Drawable>,
|
||||
dataSource: DataSource,
|
||||
isFirstResource: Boolean
|
||||
): Boolean {
|
||||
if (_binding != null) {
|
||||
binding.progressBar.hide() // Always hide the progress bar on success
|
||||
}
|
||||
|
|
@ -284,14 +297,14 @@ class ViewImageFragment : ViewMediaFragment() {
|
|||
// This wait for transition. If there's no transition then we should hit
|
||||
// another branch. take() will unsubscribe after we have it to not leak menmory
|
||||
transition
|
||||
.take(1)
|
||||
.subscribe {
|
||||
target.onResourceReady(resource, null)
|
||||
// It's needed. Don't ask why, I don't know, setImageDrawable() should
|
||||
// do it by itself but somehow it doesn't work automatically.
|
||||
// Just do it. If you don't, image will jump around when touched.
|
||||
attacher.update()
|
||||
}
|
||||
.take(1)
|
||||
.subscribe {
|
||||
target.onResourceReady(resource, null)
|
||||
// It's needed. Don't ask why, I don't know, setImageDrawable() should
|
||||
// do it by itself but somehow it doesn't work automatically.
|
||||
// Just do it. If you don't, image will jump around when touched.
|
||||
attacher.update()
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,10 +25,10 @@ abstract class ViewMediaFragment : Fragment() {
|
|||
private var toolbarVisibiltyDisposable: Function0<Boolean>? = null
|
||||
|
||||
abstract fun setupMediaView(
|
||||
url: String,
|
||||
previewUrl: String?,
|
||||
description: String?,
|
||||
showingDescription: Boolean
|
||||
url: String,
|
||||
previewUrl: String?,
|
||||
description: String?,
|
||||
showingDescription: Boolean
|
||||
)
|
||||
|
||||
abstract fun onToolbarVisibilityChange(visible: Boolean)
|
||||
|
|
@ -56,7 +56,7 @@ abstract class ViewMediaFragment : Fragment() {
|
|||
Attachment.Type.VIDEO,
|
||||
Attachment.Type.GIFV,
|
||||
Attachment.Type.AUDIO -> ViewVideoFragment()
|
||||
else -> ViewImageFragment() // it probably won't show anything, but its better than crashing
|
||||
else -> ViewImageFragment() // it probably won't show anything, but its better than crashing
|
||||
}
|
||||
fragment.arguments = arguments
|
||||
return fragment
|
||||
|
|
@ -84,9 +84,9 @@ abstract class ViewMediaFragment : Fragment() {
|
|||
setupMediaView(url, previewUrl, description, showingDescription && mediaActivity.isToolbarVisible)
|
||||
|
||||
toolbarVisibiltyDisposable = (activity as ViewMediaActivity)
|
||||
.addToolbarVisibilityListener { isVisible ->
|
||||
onToolbarVisibilityChange(isVisible)
|
||||
}
|
||||
.addToolbarVisibilityListener { isVisible ->
|
||||
onToolbarVisibilityChange(isVisible)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||
}
|
||||
private lateinit var mediaActivity: ViewMediaActivity
|
||||
private val TOOLBAR_HIDE_DELAY_MS = 3000L
|
||||
private lateinit var mediaController : MediaController
|
||||
private lateinit var mediaController: MediaController
|
||||
private var isAudio = false
|
||||
|
||||
override fun setUserVisibleHint(isVisibleToUser: Boolean) {
|
||||
|
|
@ -72,10 +72,10 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||
|
||||
@SuppressLint("ClickableViewAccessibility")
|
||||
override fun setupMediaView(
|
||||
url: String,
|
||||
previewUrl: String?,
|
||||
description: String?,
|
||||
showingDescription: Boolean
|
||||
url: String,
|
||||
previewUrl: String?,
|
||||
description: String?,
|
||||
showingDescription: Boolean
|
||||
) {
|
||||
binding.mediaDescription.text = description
|
||||
binding.mediaDescription.visible(showingDescription)
|
||||
|
|
@ -105,7 +105,7 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||
mediaController.setMediaPlayer(binding.videoView)
|
||||
binding.videoView.setMediaController(mediaController)
|
||||
binding.videoView.requestFocus()
|
||||
binding.videoView.setPlayPauseListener(object: ExposedPlayPauseVideoView.PlayPauseListener {
|
||||
binding.videoView.setPlayPauseListener(object : ExposedPlayPauseVideoView.PlayPauseListener {
|
||||
override fun onPause() {
|
||||
handler.removeCallbacks(hideToolbar)
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||
val videoWidth = mp.videoWidth.toFloat()
|
||||
val videoHeight = mp.videoHeight.toFloat()
|
||||
|
||||
if(containerWidth/containerHeight > videoWidth/videoHeight) {
|
||||
if (containerWidth / containerHeight > videoWidth / videoHeight) {
|
||||
binding.videoView.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
binding.videoView.layoutParams.width = ViewGroup.LayoutParams.WRAP_CONTENT
|
||||
} else {
|
||||
|
|
@ -190,15 +190,15 @@ class ViewVideoFragment : ViewMediaFragment() {
|
|||
}
|
||||
|
||||
binding.mediaDescription.animate().alpha(alpha)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
if (_binding != null) {
|
||||
binding.mediaDescription.visible(isDescriptionVisible)
|
||||
}
|
||||
animation.removeListener(this)
|
||||
.setListener(object : AnimatorListenerAdapter() {
|
||||
override fun onAnimationEnd(animation: Animator) {
|
||||
if (_binding != null) {
|
||||
binding.mediaDescription.visible(isDescriptionVisible)
|
||||
}
|
||||
})
|
||||
.start()
|
||||
animation.removeListener(this)
|
||||
}
|
||||
})
|
||||
.start()
|
||||
|
||||
if (visible && binding.videoView.isPlaying && !isAudio) {
|
||||
hideToolbarAfterDelay(TOOLBAR_HIDE_DELAY_MS)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue