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
|
|
@ -34,7 +34,8 @@ import com.keylesspalace.tusky.viewdata.buildDescription
|
|||
import com.keylesspalace.tusky.viewdata.calculatePercent
|
||||
import java.text.NumberFormat
|
||||
import java.text.SimpleDateFormat
|
||||
import java.util.*
|
||||
import java.util.Date
|
||||
import java.util.Locale
|
||||
import kotlin.math.min
|
||||
|
||||
class StatusViewHelper(private val itemView: View) {
|
||||
|
|
@ -47,25 +48,28 @@ class StatusViewHelper(private val itemView: View) {
|
|||
private val longSdf = SimpleDateFormat("MM/dd HH:mm:ss", Locale.getDefault())
|
||||
|
||||
fun setMediasPreview(
|
||||
statusDisplayOptions: StatusDisplayOptions,
|
||||
attachments: List<Attachment>,
|
||||
sensitive: Boolean,
|
||||
previewListener: MediaPreviewListener,
|
||||
showingContent: Boolean,
|
||||
mediaPreviewHeight: Int) {
|
||||
statusDisplayOptions: StatusDisplayOptions,
|
||||
attachments: List<Attachment>,
|
||||
sensitive: Boolean,
|
||||
previewListener: MediaPreviewListener,
|
||||
showingContent: Boolean,
|
||||
mediaPreviewHeight: Int
|
||||
) {
|
||||
|
||||
val context = itemView.context
|
||||
val mediaPreviews = arrayOf<MediaPreviewImageView>(
|
||||
itemView.findViewById(R.id.status_media_preview_0),
|
||||
itemView.findViewById(R.id.status_media_preview_1),
|
||||
itemView.findViewById(R.id.status_media_preview_2),
|
||||
itemView.findViewById(R.id.status_media_preview_3))
|
||||
itemView.findViewById(R.id.status_media_preview_0),
|
||||
itemView.findViewById(R.id.status_media_preview_1),
|
||||
itemView.findViewById(R.id.status_media_preview_2),
|
||||
itemView.findViewById(R.id.status_media_preview_3)
|
||||
)
|
||||
|
||||
val mediaOverlays = arrayOf<ImageView>(
|
||||
itemView.findViewById(R.id.status_media_overlay_0),
|
||||
itemView.findViewById(R.id.status_media_overlay_1),
|
||||
itemView.findViewById(R.id.status_media_overlay_2),
|
||||
itemView.findViewById(R.id.status_media_overlay_3))
|
||||
itemView.findViewById(R.id.status_media_overlay_0),
|
||||
itemView.findViewById(R.id.status_media_overlay_1),
|
||||
itemView.findViewById(R.id.status_media_overlay_2),
|
||||
itemView.findViewById(R.id.status_media_overlay_3)
|
||||
)
|
||||
|
||||
val sensitiveMediaWarning = itemView.findViewById<TextView>(R.id.status_sensitive_media_warning)
|
||||
val sensitiveMediaShow = itemView.findViewById<View>(R.id.status_sensitive_media_button)
|
||||
|
|
@ -85,7 +89,6 @@ class StatusViewHelper(private val itemView: View) {
|
|||
return
|
||||
}
|
||||
|
||||
|
||||
val mediaPreviewUnloaded = ColorDrawable(ThemeUtils.getColor(context, R.attr.colorBackgroundAccent))
|
||||
|
||||
val n = min(attachments.size, Status.MAX_MEDIA_ATTACHMENTS)
|
||||
|
|
@ -105,9 +108,9 @@ class StatusViewHelper(private val itemView: View) {
|
|||
|
||||
if (TextUtils.isEmpty(previewUrl)) {
|
||||
Glide.with(mediaPreviews[i])
|
||||
.load(mediaPreviewUnloaded)
|
||||
.centerInside()
|
||||
.into(mediaPreviews[i])
|
||||
.load(mediaPreviewUnloaded)
|
||||
.centerInside()
|
||||
.into(mediaPreviews[i])
|
||||
} else {
|
||||
val placeholder = if (attachment.blurhash != null)
|
||||
decodeBlurHash(context, attachment.blurhash)
|
||||
|
|
@ -119,19 +122,19 @@ class StatusViewHelper(private val itemView: View) {
|
|||
mediaPreviews[i].setFocalPoint(focus)
|
||||
|
||||
Glide.with(mediaPreviews[i])
|
||||
.load(previewUrl)
|
||||
.placeholder(placeholder)
|
||||
.centerInside()
|
||||
.addListener(mediaPreviews[i])
|
||||
.into(mediaPreviews[i])
|
||||
.load(previewUrl)
|
||||
.placeholder(placeholder)
|
||||
.centerInside()
|
||||
.addListener(mediaPreviews[i])
|
||||
.into(mediaPreviews[i])
|
||||
} else {
|
||||
mediaPreviews[i].removeFocalPoint()
|
||||
|
||||
Glide.with(mediaPreviews[i])
|
||||
.load(previewUrl)
|
||||
.placeholder(placeholder)
|
||||
.centerInside()
|
||||
.into(mediaPreviews[i])
|
||||
.load(previewUrl)
|
||||
.placeholder(placeholder)
|
||||
.centerInside()
|
||||
.into(mediaPreviews[i])
|
||||
}
|
||||
} else {
|
||||
mediaPreviews[i].removeFocalPoint()
|
||||
|
|
@ -145,8 +148,9 @@ class StatusViewHelper(private val itemView: View) {
|
|||
}
|
||||
|
||||
val type = attachment.type
|
||||
if (showingContent
|
||||
&& (type === Attachment.Type.VIDEO) or (type === Attachment.Type.GIFV)) {
|
||||
if (showingContent &&
|
||||
(type === Attachment.Type.VIDEO) or (type === Attachment.Type.GIFV)
|
||||
) {
|
||||
mediaOverlays[i].visibility = View.VISIBLE
|
||||
} else {
|
||||
mediaOverlays[i].visibility = View.GONE
|
||||
|
|
@ -170,7 +174,7 @@ class StatusViewHelper(private val itemView: View) {
|
|||
sensitiveMediaWarning.visibility = View.GONE
|
||||
sensitiveMediaShow.visibility = View.GONE
|
||||
} else {
|
||||
sensitiveMediaWarning.text = if (sensitive) {
|
||||
sensitiveMediaWarning.text = if (sensitive) {
|
||||
context.getString(R.string.status_sensitive_media_title)
|
||||
} else {
|
||||
context.getString(R.string.status_media_hidden_title)
|
||||
|
|
@ -182,15 +186,19 @@ class StatusViewHelper(private val itemView: View) {
|
|||
previewListener.onContentHiddenChange(false)
|
||||
v.visibility = View.GONE
|
||||
sensitiveMediaWarning.visibility = View.VISIBLE
|
||||
setMediasPreview(statusDisplayOptions, attachments, sensitive, previewListener,
|
||||
false, mediaPreviewHeight)
|
||||
setMediasPreview(
|
||||
statusDisplayOptions, attachments, sensitive, previewListener,
|
||||
false, mediaPreviewHeight
|
||||
)
|
||||
}
|
||||
sensitiveMediaWarning.setOnClickListener { v ->
|
||||
previewListener.onContentHiddenChange(true)
|
||||
v.visibility = View.GONE
|
||||
sensitiveMediaShow.visibility = View.VISIBLE
|
||||
setMediasPreview(statusDisplayOptions, attachments, sensitive, previewListener,
|
||||
true, mediaPreviewHeight)
|
||||
setMediasPreview(
|
||||
statusDisplayOptions, attachments, sensitive, previewListener,
|
||||
true, mediaPreviewHeight
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -200,8 +208,12 @@ class StatusViewHelper(private val itemView: View) {
|
|||
}
|
||||
}
|
||||
|
||||
private fun setMediaLabel(mediaLabel: TextView, attachments: List<Attachment>, sensitive: Boolean,
|
||||
listener: MediaPreviewListener) {
|
||||
private fun setMediaLabel(
|
||||
mediaLabel: TextView,
|
||||
attachments: List<Attachment>,
|
||||
sensitive: Boolean,
|
||||
listener: MediaPreviewListener
|
||||
) {
|
||||
if (attachments.isEmpty()) {
|
||||
mediaLabel.visibility = View.GONE
|
||||
return
|
||||
|
|
@ -245,10 +257,11 @@ class StatusViewHelper(private val itemView: View) {
|
|||
|
||||
fun setupPollReadonly(poll: PollViewData?, emojis: List<Emoji>, statusDisplayOptions: StatusDisplayOptions) {
|
||||
val pollResults = listOf<TextView>(
|
||||
itemView.findViewById(R.id.status_poll_option_result_0),
|
||||
itemView.findViewById(R.id.status_poll_option_result_1),
|
||||
itemView.findViewById(R.id.status_poll_option_result_2),
|
||||
itemView.findViewById(R.id.status_poll_option_result_3))
|
||||
itemView.findViewById(R.id.status_poll_option_result_0),
|
||||
itemView.findViewById(R.id.status_poll_option_result_1),
|
||||
itemView.findViewById(R.id.status_poll_option_result_2),
|
||||
itemView.findViewById(R.id.status_poll_option_result_3)
|
||||
)
|
||||
|
||||
val pollDescription = itemView.findViewById<TextView>(R.id.status_poll_description)
|
||||
|
||||
|
|
@ -260,7 +273,6 @@ class StatusViewHelper(private val itemView: View) {
|
|||
} else {
|
||||
val timestamp = System.currentTimeMillis()
|
||||
|
||||
|
||||
setupPollResult(poll, emojis, pollResults, statusDisplayOptions.animateEmojis)
|
||||
|
||||
pollDescription.visibility = View.VISIBLE
|
||||
|
|
@ -271,7 +283,7 @@ class StatusViewHelper(private val itemView: View) {
|
|||
private fun getPollInfoText(timestamp: Long, poll: PollViewData, pollDescription: TextView, useAbsoluteTime: Boolean): CharSequence {
|
||||
val context = pollDescription.context
|
||||
|
||||
val votesText = if(poll.votersCount == null) {
|
||||
val votesText = if (poll.votersCount == null) {
|
||||
val votes = NumberFormat.getNumberInstance().format(poll.votesCount.toLong())
|
||||
context.resources.getQuantityString(R.plurals.poll_info_votes, poll.votesCount, votes)
|
||||
} else {
|
||||
|
|
@ -291,7 +303,6 @@ class StatusViewHelper(private val itemView: View) {
|
|||
return context.getString(R.string.poll_info_format, votesText, pollDurationInfo)
|
||||
}
|
||||
|
||||
|
||||
private fun setupPollResult(poll: PollViewData, emojis: List<Emoji>, pollResults: List<TextView>, animateEmojis: Boolean) {
|
||||
val options = poll.options
|
||||
|
||||
|
|
@ -306,7 +317,6 @@ class StatusViewHelper(private val itemView: View) {
|
|||
val level = percent * 100
|
||||
|
||||
pollResults[i].background.level = level
|
||||
|
||||
} else {
|
||||
pollResults[i].visibility = View.GONE
|
||||
}
|
||||
|
|
@ -329,4 +339,4 @@ class StatusViewHelper(private val itemView: View) {
|
|||
val COLLAPSE_INPUT_FILTER = arrayOf<InputFilter>(SmartLengthInputFilter)
|
||||
val NO_INPUT_FILTER = arrayOfNulls<InputFilter>(0)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue