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:
Konrad Pozniak 2021-06-28 21:13:24 +02:00 committed by GitHub
commit 16ffcca748
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
227 changed files with 3933 additions and 3371 deletions

View file

@ -17,9 +17,9 @@ import com.keylesspalace.tusky.util.visible
* Can show an image, text and button below them.
*/
class BackgroundMessageView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : LinearLayout(context, attrs, defStyleAttr) {
private val binding = ViewBackgroundMessageBinding.inflate(LayoutInflater.from(context), this)
@ -38,13 +38,13 @@ class BackgroundMessageView @JvmOverloads constructor(
* If [clickListener] is `null` then the button will be hidden.
*/
fun setup(
@DrawableRes imageRes: Int,
@StringRes messageRes: Int,
clickListener: ((v: View) -> Unit)? = null
@DrawableRes imageRes: Int,
@StringRes messageRes: Int,
clickListener: ((v: View) -> Unit)? = null
) {
binding.messageTextView.setText(messageRes)
binding.imageView.setImageResource(imageRes)
binding.button.setOnClickListener(clickListener)
binding.button.visible(clickListener != null)
}
}
}

View file

@ -18,10 +18,9 @@ package com.keylesspalace.tusky.view
import android.content.Context
import android.graphics.Canvas
import android.graphics.drawable.Drawable
import androidx.recyclerview.widget.RecyclerView
import android.view.View
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.keylesspalace.tusky.R
import com.keylesspalace.tusky.adapter.ThreadAdapter
@ -54,7 +53,8 @@ class ConversationLineItemDecoration(private val context: Context) : RecyclerVie
}
val below = adapter.getItem(position + 1)
dividerBottom = if (below != null && current.id == below.status.inReplyToId &&
adapter.detailedStatusPosition != position) {
adapter.detailedStatusPosition != position
) {
child.bottom
} else {
child.top + avatarMargin
@ -66,7 +66,6 @@ class ConversationLineItemDecoration(private val context: Context) : RecyclerVie
divider.setBounds(canvas.width - dividerEnd, dividerTop, canvas.width - dividerStart, dividerBottom)
}
divider.draw(canvas)
}
}
}

View file

@ -6,8 +6,8 @@ import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
class EmojiPicker @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null
context: Context,
attrs: AttributeSet? = null
) : RecyclerView(context, attrs) {
init {

View file

@ -5,10 +5,11 @@ import android.util.AttributeSet
import android.widget.VideoView
class ExposedPlayPauseVideoView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0)
: VideoView(context, attrs, defStyleAttr) {
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) :
VideoView(context, attrs, defStyleAttr) {
private var listener: PlayPauseListener? = null
@ -30,4 +31,4 @@ class ExposedPlayPauseVideoView @JvmOverloads constructor(
fun onPlay()
fun onPause()
}
}
}

View file

@ -27,9 +27,9 @@ import com.keylesspalace.tusky.util.hide
class LicenseCard
@JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : MaterialCardView(context, attrs, defStyleAttr) {
init {
@ -46,14 +46,11 @@ class LicenseCard
binding.licenseCardName.text = name
binding.licenseCardLicense.text = license
if(link.isNullOrBlank()) {
if (link.isNullOrBlank()) {
binding.licenseCardLink.hide()
} else {
binding.licenseCardLink.text = link
setOnClickListener { LinkHelper.openLink(link, context) }
}
}
}

View file

@ -24,7 +24,6 @@ import com.bumptech.glide.load.engine.GlideException
import com.bumptech.glide.request.RequestListener
import com.bumptech.glide.request.target.Target
import com.keylesspalace.tusky.entity.Attachment
import com.keylesspalace.tusky.util.FocalPointUtil
/**
@ -40,10 +39,10 @@ import com.keylesspalace.tusky.util.FocalPointUtil
*/
class MediaPreviewImageView
@JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr),RequestListener<Drawable> {
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : AppCompatImageView(context, attrs, defStyleAttr), RequestListener<Drawable> {
private var focus: Attachment.Focus? = null
private var focalMatrix: Matrix? = null
@ -106,7 +105,6 @@ defStyleAttr: Int = 0
return false
}
/**
* Called when the size of the view changes, it calls the FocalPointUtil to update the
* matrix if we have a set focal point. It then reassigns the matrix to this imageView.
@ -120,9 +118,11 @@ defStyleAttr: Int = 0
private fun recalculateMatrix(width: Int, height: Int, drawable: Drawable?) {
if (drawable != null && focus != null && focalMatrix != null) {
scaleType = ScaleType.MATRIX
FocalPointUtil.updateFocalPointMatrix(width.toFloat(), height.toFloat(),
drawable.intrinsicWidth.toFloat(), drawable.intrinsicHeight.toFloat(),
focus as Attachment.Focus, focalMatrix as Matrix)
FocalPointUtil.updateFocalPointMatrix(
width.toFloat(), height.toFloat(),
drawable.intrinsicWidth.toFloat(), drawable.intrinsicHeight.toFloat(),
focus as Attachment.Focus, focalMatrix as Matrix
)
imageMatrix = focalMatrix
}
}

View file

@ -17,20 +17,20 @@ fun showMuteAccountDialog(
binding.checkbox.isChecked = true
AlertDialog.Builder(activity)
.setView(binding.root)
.setPositiveButton(android.R.string.ok) { _, _ ->
val durationValues = activity.resources.getIntArray(R.array.mute_duration_values)
.setView(binding.root)
.setPositiveButton(android.R.string.ok) { _, _ ->
val durationValues = activity.resources.getIntArray(R.array.mute_duration_values)
// workaround to make indefinite muting work with Mastodon 3.3.0
// https://github.com/tuskyapp/Tusky/issues/2107
val duration = if(binding.duration.selectedItemPosition == 0) {
null
} else {
durationValues[binding.duration.selectedItemPosition]
}
onOk(binding.checkbox.isChecked, duration)
// workaround to make indefinite muting work with Mastodon 3.3.0
// https://github.com/tuskyapp/Tusky/issues/2107
val duration = if (binding.duration.selectedItemPosition == 0) {
null
} else {
durationValues[binding.duration.selectedItemPosition]
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}
onOk(binding.checkbox.isChecked, duration)
}
.setNegativeButton(android.R.string.cancel, null)
.show()
}

View file

@ -1,8 +1,8 @@
package com.keylesspalace.tusky.view
import android.content.Context
import androidx.appcompat.widget.AppCompatImageView
import android.util.AttributeSet
import androidx.appcompat.widget.AppCompatImageView
/**
* Created by charlag on 26/10/2017.
@ -13,12 +13,12 @@ class SquareImageView : AppCompatImageView {
constructor(context: Context, attributes: AttributeSet) : super(context, attributes)
constructor(context: Context, attributes: AttributeSet, defStyleAttr: Int)
: super(context, attributes, defStyleAttr)
constructor(context: Context, attributes: AttributeSet, defStyleAttr: Int) :
super(context, attributes, defStyleAttr)
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
val width = measuredWidth
setMeasuredDimension(width, width)
}
}
}