upgrade ktlint plugin to 12.0.3 (#4169)

There are some new rules, I think they mostly make sense, except for the
max line length which I had to disable because we are over it in a lot
of places.

---------

Co-authored-by: Goooler <wangzongler@gmail.com>
This commit is contained in:
Konrad Pozniak 2024-01-04 17:00:55 +01:00 committed by GitHub
commit 5192fb08a5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
215 changed files with 2813 additions and 1177 deletions

View file

@ -26,12 +26,15 @@ import com.keylesspalace.tusky.util.Either
import com.keylesspalace.tusky.util.Either.Left
import com.keylesspalace.tusky.util.Either.Right
import com.keylesspalace.tusky.util.withoutFirstWhich
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import javax.inject.Inject
data class State(val accounts: Either<Throwable, List<TimelineAccount>>, val searchResult: List<TimelineAccount>?)
data class State(
val accounts: Either<Throwable, List<TimelineAccount>>,
val searchResult: List<TimelineAccount>?
)
class AccountsInListViewModel @Inject constructor(private val api: MastodonApi) : ViewModel() {

View file

@ -35,6 +35,8 @@ import com.keylesspalace.tusky.util.Resource
import com.keylesspalace.tusky.util.Success
import com.keylesspalace.tusky.util.getServerErrorMessage
import com.keylesspalace.tusky.util.randomAlphanumericString
import java.io.File
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.asFlow
@ -44,8 +46,6 @@ import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.MultipartBody
import okhttp3.RequestBody.Companion.asRequestBody
import okhttp3.RequestBody.Companion.toRequestBody
import java.io.File
import javax.inject.Inject
private const val HEADER_FILE_NAME = "header.png"
private const val AVATAR_FILE_NAME = "avatar.png"
@ -119,12 +119,20 @@ class EditProfileViewModel @Inject constructor(
viewModelScope.launch {
var avatarFileBody: MultipartBody.Part? = null
diff.avatarFile?.let {
avatarFileBody = MultipartBody.Part.createFormData("avatar", randomAlphanumericString(12), it.asRequestBody("image/png".toMediaTypeOrNull()))
avatarFileBody = MultipartBody.Part.createFormData(
"avatar",
randomAlphanumericString(12),
it.asRequestBody("image/png".toMediaTypeOrNull())
)
}
var headerFileBody: MultipartBody.Part? = null
diff.headerFile?.let {
headerFileBody = MultipartBody.Part.createFormData("header", randomAlphanumericString(12), it.asRequestBody("image/png".toMediaTypeOrNull()))
headerFileBody = MultipartBody.Part.createFormData(
"header",
randomAlphanumericString(12),
it.asRequestBody("image/png".toMediaTypeOrNull())
)
}
mastodonApi.accountUpdateCredentials(
@ -156,7 +164,10 @@ class EditProfileViewModel @Inject constructor(
// cache activity state for rotation change
internal fun updateProfile(newProfileData: ProfileDataInUi) {
if (profileData.value is Success) {
val newProfileSource = profileData.value?.data?.source?.copy(note = newProfileData.note, fields = newProfileData.fields)
val newProfileSource = profileData.value?.data?.source?.copy(
note = newProfileData.note,
fields = newProfileData.fields
)
val newProfile = profileData.value?.data?.copy(
displayName = newProfileData.displayName,
locked = newProfileData.locked,
@ -173,7 +184,10 @@ class EditProfileViewModel @Inject constructor(
return diff.hasChanges()
}
private fun getProfileDiff(oldProfileAccount: Account?, newProfileData: ProfileDataInUi): DiffProfileData {
private fun getProfileDiff(
oldProfileAccount: Account?,
newProfileData: ProfileDataInUi
): DiffProfileData {
val displayName = if (oldProfileAccount?.displayName == newProfileData.displayName) {
null
} else {
@ -216,7 +230,10 @@ class EditProfileViewModel @Inject constructor(
)
}
private fun calculateFieldToUpdate(newField: StringField?, fieldsUnchanged: Boolean): Pair<String, String>? {
private fun calculateFieldToUpdate(
newField: StringField?,
fieldsUnchanged: Boolean
): Pair<String, String>? {
if (fieldsUnchanged || newField == null) {
return null
}

View file

@ -23,22 +23,28 @@ import com.keylesspalace.tusky.entity.MastoList
import com.keylesspalace.tusky.network.MastodonApi
import com.keylesspalace.tusky.util.replacedFirstWhich
import com.keylesspalace.tusky.util.withoutFirstWhich
import java.io.IOException
import java.net.ConnectException
import javax.inject.Inject
import kotlinx.coroutines.channels.BufferOverflow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.launch
import java.io.IOException
import java.net.ConnectException
import javax.inject.Inject
internal class ListsViewModel @Inject constructor(private val api: MastodonApi) : ViewModel() {
enum class LoadingState {
INITIAL, LOADING, LOADED, ERROR_NETWORK, ERROR_OTHER
INITIAL,
LOADING,
LOADED,
ERROR_NETWORK,
ERROR_OTHER
}
enum class Event {
CREATE_ERROR, DELETE_ERROR, UPDATE_ERROR
CREATE_ERROR,
DELETE_ERROR,
UPDATE_ERROR
}
data class State(val lists: List<MastoList>, val loadingState: LoadingState)
@ -46,7 +52,12 @@ internal class ListsViewModel @Inject constructor(private val api: MastodonApi)
val state: Flow<State> get() = _state
val events: Flow<Event> get() = _events
private val _state = MutableStateFlow(State(listOf(), LoadingState.INITIAL))
private val _events = MutableSharedFlow<Event>(replay = 0, extraBufferCapacity = 1, onBufferOverflow = BufferOverflow.DROP_OLDEST)
private val _events =
MutableSharedFlow<Event>(
replay = 0,
extraBufferCapacity = 1,
onBufferOverflow = BufferOverflow.DROP_OLDEST
)
fun retryLoading() {
loadIfNeeded()