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

@ -18,5 +18,5 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class AccessToken(
@SerializedName("access_token") val accessToken: String
@SerializedName("access_token") val accessToken: String
)

View file

@ -20,23 +20,23 @@ import com.google.gson.annotations.SerializedName
import java.util.Date
data class Account(
val id: String,
@SerializedName("username") val localUsername: String,
@SerializedName("acct") val username: String,
@SerializedName("display_name") val displayName: String?, // should never be null per Api definition, but some servers break the contract
val note: Spanned,
val url: String,
val avatar: String,
val header: String,
val locked: Boolean = false,
@SerializedName("followers_count") val followersCount: Int = 0,
@SerializedName("following_count") val followingCount: Int = 0,
@SerializedName("statuses_count") val statusesCount: Int = 0,
val source: AccountSource? = null,
val bot: Boolean = false,
val emojis: List<Emoji>? = emptyList(), // nullable for backward compatibility
val fields: List<Field>? = emptyList(), //nullable for backward compatibility
val moved: Account? = null
val id: String,
@SerializedName("username") val localUsername: String,
@SerializedName("acct") val username: String,
@SerializedName("display_name") val displayName: String?, // should never be null per Api definition, but some servers break the contract
val note: Spanned,
val url: String,
val avatar: String,
val header: String,
val locked: Boolean = false,
@SerializedName("followers_count") val followersCount: Int = 0,
@SerializedName("following_count") val followingCount: Int = 0,
@SerializedName("statuses_count") val statusesCount: Int = 0,
val source: AccountSource? = null,
val bot: Boolean = false,
val emojis: List<Emoji>? = emptyList(), // nullable for backward compatibility
val fields: List<Field>? = emptyList(), // nullable for backward compatibility
val moved: Account? = null
) {
@ -57,41 +57,41 @@ data class Account(
}
fun deepEquals(other: Account): Boolean {
return id == other.id
&& localUsername == other.localUsername
&& displayName == other.displayName
&& note == other.note
&& url == other.url
&& avatar == other.avatar
&& header == other.header
&& locked == other.locked
&& followersCount == other.followersCount
&& followingCount == other.followingCount
&& statusesCount == other.statusesCount
&& source == other.source
&& bot == other.bot
&& emojis == other.emojis
&& fields == other.fields
&& moved == other.moved
return id == other.id &&
localUsername == other.localUsername &&
displayName == other.displayName &&
note == other.note &&
url == other.url &&
avatar == other.avatar &&
header == other.header &&
locked == other.locked &&
followersCount == other.followersCount &&
followingCount == other.followingCount &&
statusesCount == other.statusesCount &&
source == other.source &&
bot == other.bot &&
emojis == other.emojis &&
fields == other.fields &&
moved == other.moved
}
fun isRemote(): Boolean = this.username != this.localUsername
}
data class AccountSource(
val privacy: Status.Visibility,
val sensitive: Boolean,
val note: String,
val fields: List<StringField>?
val privacy: Status.Visibility,
val sensitive: Boolean,
val note: String,
val fields: List<StringField>?
)
data class Field (
val name: String,
val value: Spanned,
@SerializedName("verified_at") val verifiedAt: Date?
data class Field(
val name: String,
val value: Spanned,
@SerializedName("verified_at") val verifiedAt: Date?
)
data class StringField (
val name: String,
val value: String
data class StringField(
val name: String,
val value: String
)

View file

@ -17,22 +17,22 @@ package com.keylesspalace.tusky.entity
import android.text.Spanned
import com.google.gson.annotations.SerializedName
import java.util.*
import java.util.Date
data class Announcement(
val id: String,
val content: Spanned,
@SerializedName("starts_at") val startsAt: Date?,
@SerializedName("ends_at") val endsAt: Date?,
@SerializedName("all_day") val allDay: Boolean,
@SerializedName("published_at") val publishedAt: Date,
@SerializedName("updated_at") val updatedAt: Date,
val read: Boolean,
val mentions: List<Status.Mention>,
val statuses: List<Status>,
val tags: List<HashTag>,
val emojis: List<Emoji>,
val reactions: List<Reaction>
val id: String,
val content: Spanned,
@SerializedName("starts_at") val startsAt: Date?,
@SerializedName("ends_at") val endsAt: Date?,
@SerializedName("all_day") val allDay: Boolean,
@SerializedName("published_at") val publishedAt: Date,
@SerializedName("updated_at") val updatedAt: Date,
val read: Boolean,
val mentions: List<Status.Mention>,
val statuses: List<Status>,
val tags: List<HashTag>,
val emojis: List<Emoji>,
val reactions: List<Reaction>
) {
override fun equals(other: Any?): Boolean {
@ -48,10 +48,10 @@ data class Announcement(
}
data class Reaction(
val name: String,
var count: Int,
var me: Boolean,
val url: String?,
@SerializedName("static_url") val staticUrl: String?
val name: String,
var count: Int,
var me: Boolean,
val url: String?,
@SerializedName("static_url") val staticUrl: String?
)
}

View file

@ -18,6 +18,6 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class AppCredentials(
@SerializedName("client_id") val clientId: String,
@SerializedName("client_secret") val clientSecret: String
@SerializedName("client_id") val clientId: String,
@SerializedName("client_secret") val clientSecret: String
)

View file

@ -26,13 +26,13 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class Attachment(
val id: String,
val url: String,
@SerializedName("preview_url") val previewUrl: String?, // can be null for e.g. audio attachments
val meta: MetaData?,
val type: Type,
val description: String?,
val blurhash: String?
val id: String,
val url: String,
@SerializedName("preview_url") val previewUrl: String?, // can be null for e.g. audio attachments
val meta: MetaData?,
val type: Type,
val description: String?,
val blurhash: String?
) : Parcelable {
@JsonAdapter(MediaTypeDeserializer::class)
@ -66,9 +66,9 @@ data class Attachment(
* The meta data of an [Attachment].
*/
@Parcelize
data class MetaData (
val focus: Focus?,
val duration: Float?
data class MetaData(
val focus: Focus?,
val duration: Float?
) : Parcelable
/**
@ -78,8 +78,8 @@ data class Attachment(
* https://github.com/jonom/jquery-focuspoint#1-calculate-your-images-focus-point
*/
@Parcelize
data class Focus (
val x: Float,
val y: Float
data class Focus(
val x: Float,
val y: Float
) : Parcelable
}

View file

@ -19,16 +19,16 @@ import android.text.Spanned
import com.google.gson.annotations.SerializedName
data class Card(
val url: String,
val title: Spanned,
val description: Spanned,
@SerializedName("author_name") val authorName: String,
val image: String,
val type: String,
val width: Int,
val height: Int,
val blurhash: String?,
val embed_url: String?
val url: String,
val title: Spanned,
val description: Spanned,
@SerializedName("author_name") val authorName: String,
val image: String,
val type: String,
val width: Int,
val height: Int,
val blurhash: String?,
val embed_url: String?
) {
override fun hashCode(): Int {

View file

@ -18,8 +18,8 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class Conversation(
val id: String,
val accounts: List<Account>,
@SerializedName("last_status") val lastStatus: Status?, // should never be null, but apparently its possible https://github.com/tuskyapp/Tusky/issues/1038
val unread: Boolean
)
val id: String,
val accounts: List<Account>,
@SerializedName("last_status") val lastStatus: Status?, // should never be null, but apparently its possible https://github.com/tuskyapp/Tusky/issues/1038
val unread: Boolean
)

View file

@ -16,19 +16,20 @@
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
import java.util.*
import java.util.ArrayList
import java.util.Date
data class DeletedStatus(
var text: String?,
@SerializedName("in_reply_to_id") var inReplyToId: String?,
@SerializedName("spoiler_text") val spoilerText: String,
val visibility: Status.Visibility,
val sensitive: Boolean,
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>?,
val poll: Poll?,
@SerializedName("created_at") val createdAt: Date
var text: String?,
@SerializedName("in_reply_to_id") var inReplyToId: String?,
@SerializedName("spoiler_text") val spoilerText: String,
val visibility: Status.Visibility,
val sensitive: Boolean,
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>?,
val poll: Poll?,
@SerializedName("created_at") val createdAt: Date
) {
fun isEmpty(): Boolean {
return text == null && attachments == null
}
}
}

View file

@ -21,8 +21,8 @@ import kotlinx.parcelize.Parcelize
@Parcelize
data class Emoji(
val shortcode: String,
val url: String,
@SerializedName("static_url") val staticUrl: String,
@SerializedName("visible_in_picker") val visibleInPicker: Boolean?
val shortcode: String,
val url: String,
@SerializedName("static_url") val staticUrl: String,
@SerializedName("visible_in_picker") val visibleInPicker: Boolean?
) : Parcelable

View file

@ -17,7 +17,7 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class Filter (
data class Filter(
val id: String,
val phrase: String,
val context: List<String>,
@ -45,4 +45,3 @@ data class Filter (
return filter?.id.equals(id)
}
}

View file

@ -1,3 +1,3 @@
package com.keylesspalace.tusky.entity
data class HashTag(val name: String)
data class HashTag(val name: String)

View file

@ -3,7 +3,7 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class IdentityProof(
val provider: String,
@SerializedName("provider_username") val username: String,
@SerializedName("profile_url") val profileUrl: String
val provider: String,
@SerializedName("provider_username") val username: String,
@SerializedName("profile_url") val profileUrl: String
)

View file

@ -17,20 +17,20 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class Instance (
val uri: String,
val title: String,
val description: String,
val email: String,
val version: String,
val urls: Map<String,String>,
val stats: Map<String,Int>?,
val thumbnail: String?,
val languages: List<String>,
@SerializedName("contact_account") val contactAccount: Account,
@SerializedName("max_toot_chars") val maxTootChars: Int?,
@SerializedName("max_bio_chars") val maxBioChars: Int?,
@SerializedName("poll_limits") val pollLimits: PollLimits?
data class Instance(
val uri: String,
val title: String,
val description: String,
val email: String,
val version: String,
val urls: Map<String, String>,
val stats: Map<String, Int>?,
val thumbnail: String?,
val languages: List<String>,
@SerializedName("contact_account") val contactAccount: Account,
@SerializedName("max_toot_chars") val maxTootChars: Int?,
@SerializedName("max_bio_chars") val maxBioChars: Int?,
@SerializedName("poll_limits") val pollLimits: PollLimits?
) {
override fun hashCode(): Int {
return uri.hashCode()
@ -45,7 +45,7 @@ data class Instance (
}
}
data class PollLimits (
@SerializedName("max_options") val maxOptions: Int?,
@SerializedName("max_option_chars") val maxOptionChars: Int?
data class PollLimits(
@SerializedName("max_options") val maxOptions: Int?,
@SerializedName("max_option_chars") val maxOptionChars: Int?
)

View file

@ -1,15 +1,15 @@
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
import java.util.*
import java.util.Date
/**
* API type for saving the scroll position of a timeline.
*/
data class Marker(
@SerializedName("last_read_id")
val lastReadId: String,
val version: Int,
@SerializedName("updated_at")
val updatedAt: Date
)
@SerializedName("last_read_id")
val lastReadId: String,
val version: Int,
@SerializedName("updated_at")
val updatedAt: Date
)

View file

@ -21,6 +21,6 @@ package com.keylesspalace.tusky.entity
*/
data class MastoList(
val id: String,
val title: String
)
val id: String,
val title: String
)

View file

@ -20,19 +20,19 @@ import com.google.gson.annotations.SerializedName
import kotlinx.parcelize.Parcelize
data class NewStatus(
val status: String,
@SerializedName("spoiler_text") val warningText: String,
@SerializedName("in_reply_to_id") val inReplyToId: String?,
val visibility: String,
val sensitive: Boolean,
@SerializedName("media_ids") val mediaIds: List<String>?,
@SerializedName("scheduled_at") val scheduledAt: String?,
val poll: NewPoll?
val status: String,
@SerializedName("spoiler_text") val warningText: String,
@SerializedName("in_reply_to_id") val inReplyToId: String?,
val visibility: String,
val sensitive: Boolean,
@SerializedName("media_ids") val mediaIds: List<String>?,
@SerializedName("scheduled_at") val scheduledAt: String?,
val poll: NewPoll?
)
@Parcelize
data class NewPoll(
val options: List<String>,
@SerializedName("expires_in") val expiresIn: Int,
val multiple: Boolean
): Parcelable
val options: List<String>,
@SerializedName("expires_in") val expiresIn: Int,
val multiple: Boolean
) : Parcelable

View file

@ -79,7 +79,6 @@ data class Notification(
): Type {
return Type.byString(json.asString)
}
}
/** Helper for Java */
@ -89,8 +88,9 @@ data class Notification(
fun rewriteToStatusTypeIfNeeded(accountId: String): Notification {
if (type == Type.MENTION && status != null) {
return if (status.mentions.any {
it.id == accountId
}) this else copy(type = Type.STATUS)
it.id == accountId
}
) this else copy(type = Type.STATUS)
}
return this
}

View file

@ -1,22 +1,22 @@
package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
import java.util.*
import java.util.Date
data class Poll(
val id: String,
@SerializedName("expires_at") val expiresAt: Date?,
val expired: Boolean,
val multiple: Boolean,
@SerializedName("votes_count") val votesCount: Int,
@SerializedName("voters_count") val votersCount: Int?, // nullable for compatibility with Pleroma
val options: List<PollOption>,
val voted: Boolean
val id: String,
@SerializedName("expires_at") val expiresAt: Date?,
val expired: Boolean,
val multiple: Boolean,
@SerializedName("votes_count") val votesCount: Int,
@SerializedName("voters_count") val votersCount: Int?, // nullable for compatibility with Pleroma
val options: List<PollOption>,
val voted: Boolean
) {
fun votedCopy(choices: List<Int>): Poll {
val newOptions = options.mapIndexed { index, option ->
if(choices.contains(index)) {
if (choices.contains(index)) {
option.copy(votesCount = option.votesCount + 1)
} else {
option
@ -24,24 +24,23 @@ data class Poll(
}
return copy(
options = newOptions,
votesCount = votesCount + choices.size,
votersCount = votersCount?.plus(1),
voted = true
options = newOptions,
votesCount = votesCount + choices.size,
votersCount = votersCount?.plus(1),
voted = true
)
}
fun toNewPoll(creationDate: Date) = NewPoll(
options.map { it.title },
expiresAt?.let {
((it.time - creationDate.time) / 1000).toInt() + 1
}?: 3600,
multiple
options.map { it.title },
expiresAt?.let {
((it.time - creationDate.time) / 1000).toInt() + 1
} ?: 3600,
multiple
)
}
data class PollOption(
val title: String,
@SerializedName("votes_count") val votesCount: Int
)
val title: String,
@SerializedName("votes_count") val votesCount: Int
)

View file

@ -17,7 +17,7 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class Relationship (
data class Relationship(
val id: String,
val following: Boolean,
@SerializedName("followed_by") val followedBy: Boolean,

View file

@ -18,8 +18,8 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class ScheduledStatus(
val id: String,
@SerializedName("scheduled_at") val scheduledAt: String,
val params: StatusParams,
@SerializedName("media_attachments") val mediaAttachments: ArrayList<Attachment>
val id: String,
@SerializedName("scheduled_at") val scheduledAt: String,
val params: StatusParams,
@SerializedName("media_attachments") val mediaAttachments: ArrayList<Attachment>
)

View file

@ -15,7 +15,7 @@
package com.keylesspalace.tusky.entity
data class SearchResult (
data class SearchResult(
val accounts: List<Account>,
val statuses: List<Status>,
val hashtags: List<HashTag>

View file

@ -19,33 +19,34 @@ import android.text.SpannableStringBuilder
import android.text.Spanned
import android.text.style.URLSpan
import com.google.gson.annotations.SerializedName
import java.util.*
import java.util.ArrayList
import java.util.Date
data class Status(
val id: String,
val url: String?, // not present if it's reblog
val account: Account,
@SerializedName("in_reply_to_id") var inReplyToId: String?,
@SerializedName("in_reply_to_account_id") val inReplyToAccountId: String?,
val reblog: Status?,
val content: Spanned,
@SerializedName("created_at") val createdAt: Date,
val emojis: List<Emoji>,
@SerializedName("reblogs_count") val reblogsCount: Int,
@SerializedName("favourites_count") val favouritesCount: Int,
var reblogged: Boolean,
var favourited: Boolean,
var bookmarked: Boolean,
var sensitive: Boolean,
@SerializedName("spoiler_text") val spoilerText: String,
val visibility: Visibility,
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>,
val mentions: List<Mention>,
val application: Application?,
val pinned: Boolean?,
val muted: Boolean?,
val poll: Poll?,
val card: Card?
val id: String,
val url: String?, // not present if it's reblog
val account: Account,
@SerializedName("in_reply_to_id") var inReplyToId: String?,
@SerializedName("in_reply_to_account_id") val inReplyToAccountId: String?,
val reblog: Status?,
val content: Spanned,
@SerializedName("created_at") val createdAt: Date,
val emojis: List<Emoji>,
@SerializedName("reblogs_count") val reblogsCount: Int,
@SerializedName("favourites_count") val favouritesCount: Int,
var reblogged: Boolean,
var favourited: Boolean,
var bookmarked: Boolean,
var sensitive: Boolean,
@SerializedName("spoiler_text") val spoilerText: String,
val visibility: Visibility,
@SerializedName("media_attachments") var attachments: ArrayList<Attachment>,
val mentions: List<Mention>,
val application: Application?,
val pinned: Boolean?,
val muted: Boolean?,
val poll: Poll?,
val card: Card?
) {
val actionableId: String
@ -119,14 +120,14 @@ data class Status(
fun toDeletedStatus(): DeletedStatus {
return DeletedStatus(
text = getEditableText(),
inReplyToId = inReplyToId,
spoilerText = spoilerText,
visibility = visibility,
sensitive = sensitive,
attachments = attachments,
poll = poll,
createdAt = createdAt
text = getEditableText(),
inReplyToId = inReplyToId,
spoilerText = spoilerText,
visibility = visibility,
sensitive = sensitive,
attachments = attachments,
poll = poll,
createdAt = createdAt
)
}
@ -158,15 +159,14 @@ data class Status(
return id.hashCode()
}
data class Mention (
data class Mention(
val id: String,
val url: String,
@SerializedName("acct") val username: String,
@SerializedName("username") val localUsername: String
)
data class Application (
data class Application(
val name: String,
val website: String?
)

View file

@ -15,7 +15,7 @@
package com.keylesspalace.tusky.entity
data class StatusContext (
data class StatusContext(
val ancestors: List<Status>,
val descendants: List<Status>
)

View file

@ -18,9 +18,9 @@ package com.keylesspalace.tusky.entity
import com.google.gson.annotations.SerializedName
data class StatusParams(
val text: String,
val sensitive: Boolean,
val visibility: Status.Visibility,
@SerializedName("spoiler_text") val spoilerText: String,
@SerializedName("in_reply_to_id") val inReplyToId: String?
)
val text: String,
val sensitive: Boolean,
val visibility: Status.Visibility,
@SerializedName("spoiler_text") val spoilerText: String,
@SerializedName("in_reply_to_id") val inReplyToId: String?
)