Skip to content

Commit

Permalink
Update spotless and ktling configuration
Browse files Browse the repository at this point in the history
* Update spotless to the latest version
* Update editorconfig to define max line length and imports layout
* Update ktling to disable and configure certain rules
* Fix code violations
  • Loading branch information
fibelatti committed Jan 10, 2025
1 parent 7d0f2ca commit 9135c39
Show file tree
Hide file tree
Showing 44 changed files with 136 additions and 75 deletions.
2 changes: 2 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,10 @@ insert_final_newline = true
end_of_line = crlf

[*.{kt,kts}]
max_line_length = 120
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_imports_layout = * # alphabetical with capital letters before lower case letters (e.g. Z before a), no blank lines

[*.yml]
indent_size = 2
15 changes: 7 additions & 8 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ plugins {
}

object AppInfo {

const val APP_NAME = "Pinkt"
const val APPLICATION_ID = "com.fibelatti.pinboard"

Expand All @@ -20,16 +21,14 @@ object AppInfo {
private const val VERSION_PATCH = 0
private const val VERSION_BUILD = 0

val versionCode: Int =
(VERSION_MAJOR * 1_000_000 + VERSION_MINOR * 10_000 + VERSION_PATCH * 100 + VERSION_BUILD)
.also { println("versionCode: $it") }
val versionCode: Int = (VERSION_MAJOR * 1_000_000 + VERSION_MINOR * 10_000 + VERSION_PATCH * 100 + VERSION_BUILD)
.also { println("versionCode: $it") }

@Suppress("KotlinConstantConditions")
val versionName: String =
StringBuilder("$VERSION_MAJOR.$VERSION_MINOR")
.apply { if (VERSION_PATCH != 0) append(".$VERSION_PATCH") }
.toString()
.also { println("versionName: $it") }
val versionName: String = StringBuilder("$VERSION_MAJOR.$VERSION_MINOR")
.apply { if (VERSION_PATCH != 0) append(".$VERSION_PATCH") }
.toString()
.also { println("versionName: $it") }
}

android {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ import com.fibelatti.pinboard.features.posts.presentation.EditPostFragment
import com.fibelatti.pinboard.features.posts.presentation.PostListFragment
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import javax.inject.Inject

@HiltAndroidTest
@OptIn(ExperimentalTestApi::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ import com.fibelatti.pinboard.features.posts.presentation.EditPostFragment
import com.fibelatti.pinboard.features.posts.presentation.PostListFragment
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import javax.inject.Inject
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import javax.inject.Inject

@HiltAndroidTest
@OptIn(ExperimentalTestApi::class)
Expand Down Expand Up @@ -86,7 +86,8 @@ class PinboardEndToEndTests {

with(composeRule) {
// Act
onNodeWithText(context.getString(R.string.auth_token_hint)).performTextInput(PinboardMockServer.TestData.TOKEN)
onNodeWithText(context.getString(R.string.auth_token_hint))
.performTextInput(PinboardMockServer.TestData.TOKEN)
onNodeWithText(context.getString(R.string.auth_button)).performClick()

// Assert
Expand Down Expand Up @@ -119,7 +120,8 @@ class PinboardEndToEndTests {

with(composeRule) {
// Login
onNodeWithText(context.getString(R.string.auth_token_hint)).performTextInput(PinboardMockServer.TestData.TOKEN)
onNodeWithText(context.getString(R.string.auth_token_hint))
.performTextInput(PinboardMockServer.TestData.TOKEN)
onNodeWithText(context.getString(R.string.auth_button)).performClick()
waitUntilAtLeastOneExists(
matcher = hasText(context.getString(R.string.posts_title_all)),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("ktlint:standard:max-line-length")

package com.fibelatti.pinboard.features.linkding.data

import com.fibelatti.pinboard.tooling.BaseDbTest
import com.fibelatti.pinboard.MockDataProvider.createBookmarkLocal
import com.fibelatti.pinboard.MockDataProvider.mockHash
import com.fibelatti.pinboard.MockDataProvider.mockTagString1
Expand All @@ -12,10 +13,11 @@ import com.fibelatti.pinboard.MockDataProvider.mockTime3
import com.fibelatti.pinboard.MockDataProvider.mockTime4
import com.fibelatti.pinboard.MockDataProvider.mockTime5
import com.fibelatti.pinboard.features.posts.data.model.PendingSyncDto
import com.fibelatti.pinboard.tooling.BaseDbTest
import com.google.common.truth.Truth.assertThat
import java.util.UUID
import kotlinx.coroutines.test.runTest
import org.junit.Test
import java.util.UUID

class BookmarksDaoTest : BaseDbTest() {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
@file:Suppress("ktlint:standard:max-line-length")

package com.fibelatti.pinboard.features.posts.data

import com.fibelatti.pinboard.tooling.BaseDbTest
import com.fibelatti.pinboard.MockDataProvider.createPostDto
import com.fibelatti.pinboard.MockDataProvider.mockHash
import com.fibelatti.pinboard.MockDataProvider.mockTagString1
Expand All @@ -13,10 +14,11 @@ import com.fibelatti.pinboard.MockDataProvider.mockTime4
import com.fibelatti.pinboard.MockDataProvider.mockTime5
import com.fibelatti.pinboard.core.AppConfig
import com.fibelatti.pinboard.features.posts.data.model.PendingSyncDto
import com.fibelatti.pinboard.tooling.BaseDbTest
import com.google.common.truth.Truth.assertThat
import java.util.UUID
import kotlinx.coroutines.test.runTest
import org.junit.Test
import java.util.UUID

class PostsDaoTest : BaseDbTest() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@ package com.fibelatti.pinboard.core.android.base

import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import kotlin.coroutines.CoroutineContext
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlin.coroutines.CoroutineContext

/**
* [ViewModel] that also implements [CoroutineScope], allowing coroutines to be launched from it.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ import com.fibelatti.pinboard.core.di.Scope
import com.fibelatti.pinboard.features.user.domain.UserRepository
import com.fibelatti.ui.theme.ExtendedTheme
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.stateIn
import javax.inject.Inject

@Composable
fun AppTheme(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ import kotlinx.coroutines.delay
import kotlinx.coroutines.flow.mapLatest

enum class ScrollDirection {
IDLE, UP, DOWN,
IDLE,
UP,
DOWN,
}

@Composable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.fibelatti.pinboard.features
import com.fibelatti.pinboard.core.android.base.BaseViewModel
import com.fibelatti.pinboard.core.extension.ScrollDirection
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -12,7 +13,6 @@ import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class MainViewModel @Inject constructor() : BaseViewModel() {
Expand All @@ -23,10 +23,10 @@ class MainViewModel @Inject constructor() : BaseViewModel() {
private val _currentScrollDirection: MutableStateFlow<ScrollDirection> = MutableStateFlow(ScrollDirection.IDLE)
val currentScrollDirection: StateFlow<ScrollDirection> = _currentScrollDirection.asStateFlow()

private val _navigationClicks = MutableSharedFlow<String>()
private val _actionButtonClicks = MutableSharedFlow<Pair<String, Any?>>()
private val _menuItemClicks = MutableSharedFlow<Triple<String, MainState.MenuItemComponent, Any?>>()
private val _fabClicks = MutableSharedFlow<Pair<String, Any?>>()
private val navigationClicks = MutableSharedFlow<String>()
private val actionButtonClicks = MutableSharedFlow<Pair<String, Any?>>()
private val menuItemClicks = MutableSharedFlow<Triple<String, MainState.MenuItemComponent, Any?>>()
private val fabClicks = MutableSharedFlow<Pair<String, Any?>>()

fun updateState(body: (MainState) -> MainState) {
_state.update(body)
Expand All @@ -38,40 +38,40 @@ class MainViewModel @Inject constructor() : BaseViewModel() {

fun navigationClicked(id: String) {
launch {
_navigationClicks.emit(id)
navigationClicks.emit(id)
}
}

fun navigationClicks(id: String): Flow<String> = _navigationClicks
fun navigationClicks(id: String): Flow<String> = navigationClicks
.filter { eventId -> eventId == id }

fun actionButtonClicked(id: String, data: Any? = null) {
launch {
_actionButtonClicks.emit(id to data)
actionButtonClicks.emit(id to data)
}
}

fun actionButtonClicks(id: String): Flow<Any?> = _actionButtonClicks
fun actionButtonClicks(id: String): Flow<Any?> = actionButtonClicks
.filter { (eventId, _) -> eventId == id }
.map { (_, data) -> data }

fun menuItemClicked(id: String, menuItem: MainState.MenuItemComponent, data: Any? = null) {
launch {
_menuItemClicks.emit(Triple(id, menuItem, data))
menuItemClicks.emit(Triple(id, menuItem, data))
}
}

fun menuItemClicks(id: String): Flow<Pair<MainState.MenuItemComponent, Any?>> = _menuItemClicks
fun menuItemClicks(id: String): Flow<Pair<MainState.MenuItemComponent, Any?>> = menuItemClicks
.filter { (eventId, _, _) -> eventId == id }
.map { (_, menuItem, data) -> menuItem to data }

fun fabClicked(id: String, data: Any? = null) {
launch {
_fabClicks.emit(id to data)
fabClicks.emit(id to data)
}
}

fun fabClicks(id: String): Flow<Any?> = _fabClicks
fun fabClicks(id: String): Flow<Any?> = fabClicks
.filter { (eventId, _) -> eventId == id }
.map { (_, data) -> data }
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,9 @@ class NavigationActionHandler @Inject constructor(
}

is PopularPostsContent -> {
if (preferredDetailsView is PreferredDetailsView.ExternalBrowser && !userRepository.alwaysUseSidePanel) {
if (preferredDetailsView is PreferredDetailsView.ExternalBrowser &&
!userRepository.alwaysUseSidePanel
) {
ExternalBrowserContent(action.post, previousContent = currentContent)
} else {
PopularPostDetailContent(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ package com.fibelatti.pinboard.features.filters.data

import com.fibelatti.pinboard.features.filters.domain.SavedFiltersRepository
import com.fibelatti.pinboard.features.filters.domain.model.SavedFilter
import javax.inject.Inject
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.map
import javax.inject.Inject

class SavedFiltersDataSource @Inject constructor(
private val savedFiltersDao: SavedFiltersDao,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import com.fibelatti.pinboard.core.di.Scope
import com.fibelatti.pinboard.features.filters.domain.SavedFiltersRepository
import com.fibelatti.pinboard.features.filters.domain.model.SavedFilter
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.flow.SharingStarted
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.stateIn
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class SavedFiltersViewModel @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import com.fibelatti.pinboard.features.appstate.AppStateRepository
import com.fibelatti.pinboard.features.appstate.SetNote
import com.fibelatti.pinboard.features.notes.domain.NotesRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlinx.coroutines.launch

@HiltViewModel
class NoteDetailsViewModel @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,6 @@ object NoteList {
ByDateUpdatedDesc(label = R.string.note_sorting_date_updated_desc),
ByDateUpdatedAsc(label = R.string.note_sorting_date_updated_asc),
AtoZ(label = R.string.note_sorting_a_to_z),
;
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import com.fibelatti.pinboard.features.notes.domain.NotesRepository
import com.fibelatti.pinboard.features.notes.domain.model.Note
import com.fibelatti.pinboard.features.notes.domain.model.NoteSorting
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.launch
import javax.inject.Inject
import kotlinx.coroutines.launch

@HiltViewModel
class NoteListViewModel @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,17 @@ class PostsDataSourceNoApi @Inject constructor(
extended = post.description,
hash = existingPost?.hash ?: post.id.ifEmpty { UUID.randomUUID().toString() },
time = existingPost?.time ?: post.dateAdded.ifEmpty { dateFormatter.nowAsDataFormat() },
shared = if (post.private == true) AppConfig.PinboardApiLiterals.NO else AppConfig.PinboardApiLiterals.YES,
toread = if (post.readLater == true) AppConfig.PinboardApiLiterals.YES else AppConfig.PinboardApiLiterals.NO,
tags = post.tags?.joinToString(AppConfig.PinboardApiLiterals.TAG_SEPARATOR) { it.name }
.orEmpty(),
shared = if (post.private == true) {
AppConfig.PinboardApiLiterals.NO
} else {
AppConfig.PinboardApiLiterals.YES
},
toread = if (post.readLater == true) {
AppConfig.PinboardApiLiterals.YES
} else {
AppConfig.PinboardApiLiterals.NO
},
tags = post.tags?.joinToString(AppConfig.PinboardApiLiterals.TAG_SEPARATOR) { it.name }.orEmpty(),
)

return resultFrom {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.fibelatti.pinboard.features.posts.data.model

import com.fibelatti.core.functional.Mapper
import kotlinx.serialization.Serializable
import javax.inject.Inject
import kotlinx.serialization.Serializable

@Serializable
data class PostRemoteDto(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import kotlinx.coroutines.flow.Flow

class GetAllPosts @Inject constructor(
private val postsRepository: PostsRepository,
): ObservableUseCaseWithParams<GetPostParams, Result<PostListResult>> {
) : ObservableUseCaseWithParams<GetPostParams, Result<PostListResult>> {

override operator fun invoke(params: GetPostParams): Flow<Result<PostListResult>> = postsRepository.getAllPosts(
sortType = params.sorting,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import kotlinx.coroutines.flow.Flow

class GetRecentPosts @Inject constructor(
private val postsRepository: PostsRepository,
): ObservableUseCaseWithParams<GetPostParams, Result<PostListResult>> {
) : ObservableUseCaseWithParams<GetPostParams, Result<PostListResult>> {

override operator fun invoke(params: GetPostParams): Flow<Result<PostListResult>> = postsRepository.getAllPosts(
sortType = ByDateAddedNewestFirst,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ import com.fibelatti.pinboard.features.posts.domain.usecase.AddPost
import com.fibelatti.pinboard.features.posts.domain.usecase.GetPopularPosts
import com.fibelatti.pinboard.features.user.domain.UserRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.StateFlow
import kotlinx.coroutines.flow.asStateFlow
import kotlinx.coroutines.flow.update
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PopularPostsViewModel @Inject constructor(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ import com.fibelatti.pinboard.features.posts.domain.usecase.GetPostParams
import com.fibelatti.pinboard.features.posts.domain.usecase.GetRecentPosts
import com.fibelatti.pinboard.features.tags.domain.model.Tag
import dagger.hilt.android.lifecycle.HiltViewModel
import javax.inject.Inject
import kotlinx.coroutines.cancelChildren
import kotlinx.coroutines.flow.launchIn
import kotlinx.coroutines.flow.onEach
import kotlinx.coroutines.launch
import javax.inject.Inject

@HiltViewModel
class PostListViewModel @Inject constructor(
Expand Down
Loading

0 comments on commit 9135c39

Please sign in to comment.