Skip to content

Commit

Permalink
Update dependency com.pinterest.ktlint:ktlint-cli to v1.0.1 (#3161)
Browse files Browse the repository at this point in the history
* upgrade to ktlint 1.0.1
* disable the function naming rule for Composables
* ktlint fixes

---------

Co-authored-by: renovate[bot] <29139614+renovate[bot]@users.noreply.github.com>
Co-authored-by: Daniel Frett <[email protected]>
  • Loading branch information
renovate[bot] and frett authored Oct 17, 2023
1 parent 62aa4f2 commit ed57751
Show file tree
Hide file tree
Showing 42 changed files with 150 additions and 199 deletions.
1 change: 1 addition & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ ij_kotlin_allow_trailing_comma=true
# ij_kotlin_allow_trailing_comma_on_call_site=true
indent_size=4
ktlint_code_style=android_studio
ktlint_function_naming_ignore_when_annotated_with=Composable
ktlint_standard_filename = disabled
ktlint_standard_spacing-between-declarations-with-annotations = disabled
ktlint_standard_trailing-comma-on-call-site = disabled
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ import androidx.annotation.StringRes
import org.cru.godtools.R

enum class AccountPage(@StringRes val tabLabel: Int) {
ACTIVITY(R.string.profile_tab_activity), GLOBAL_ACTIVITY(R.string.account_tab_global_activity)
ACTIVITY(R.string.profile_tab_activity),
GLOBAL_ACTIVITY(R.string.account_tab_global_activity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ import androidx.compose.ui.text.style.LineBreak
import androidx.compose.ui.text.style.TextAlign
import androidx.compose.ui.unit.dp
import org.ccci.gto.android.common.androidx.compose.foundation.text.minLinesHeight
import org.ccci.gto.android.common.androidx.compose.material3.DisabledAlpha
import org.ccci.gto.android.common.androidx.compose.material3.isLight
import org.ccci.gto.android.common.androidx.compose.ui.text.computeHeightForDefaultText
import org.cru.godtools.R
import org.cru.godtools.base.ui.theme.DisabledAlpha
import org.cru.godtools.shared.common.model.ThemeType
import org.cru.godtools.shared.user.activity.model.Badge
import org.cru.godtools.shared.user.activity.model.Badge.BadgeType
Expand All @@ -42,10 +42,7 @@ private val BADGE_SIZE = 48.dp

@Composable
@OptIn(ExperimentalLayoutApi::class)
internal fun AccountActivityBadges(
activity: UserActivity,
modifier: Modifier = Modifier
) = Column(modifier = modifier) {
internal fun AccountActivityBadges(activity: UserActivity, modifier: Modifier = Modifier) = Column(modifier) {
Text(
stringResource(R.string.account_activity_badges_header),
style = MaterialTheme.typography.titleLarge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ import org.cru.godtools.shared.user.activity.model.UserActivity
import org.cru.godtools.ui.account.ACCOUNT_PAGE_MARGIN_HORIZONTAL

@Composable
fun AccountActivityLayout(
modifier: Modifier = Modifier,
) = Column(modifier = modifier.padding(horizontal = ACCOUNT_PAGE_MARGIN_HORIZONTAL)) {
fun AccountActivityLayout(modifier: Modifier = Modifier) = Column(
modifier = modifier.padding(horizontal = ACCOUNT_PAGE_MARGIN_HORIZONTAL)
) {
val viewModel = viewModel<AccountActivityViewModel>()
val activity by viewModel.userActivity.collectAsState()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,9 @@ fun AccountGlobalActivityLayout() = Column(modifier = Modifier.padding(horizonta
}

@Composable
private fun GlobalActivityCard(
label: String,
count: Int,
modifier: Modifier = Modifier
) = ElevatedCard(modifier = modifier.heightIn(min = 128.dp)) {
private fun GlobalActivityCard(label: String, count: Int, modifier: Modifier = Modifier) = ElevatedCard(
modifier = modifier.heightIn(min = 128.dp)
) {
val labelStyle = MaterialTheme.typography.bodyMedium

Spacer(Modifier.weight(1f))
Expand Down
8 changes: 3 additions & 5 deletions app/src/main/kotlin/org/cru/godtools/ui/banner/Banners.kt
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,13 @@ import androidx.compose.ui.unit.dp

@Composable
@OptIn(ExperimentalAnimationApi::class)
internal fun Banners(
banner: () -> BannerType?,
modifier: Modifier = Modifier
) = Box(modifier = modifier.heightIn(min = 1.dp)) {
internal fun Banners(banner: () -> BannerType?, modifier: Modifier = Modifier) = Box(modifier.heightIn(min = 1.dp)) {
AnimatedContent(
targetState = banner(),
transitionSpec = {
slideInVertically(initialOffsetY = { -it }) with slideOutVertically(targetOffsetY = { -it })
}
},
label = "Banner Visibility",
) {
when (it) {
BannerType.TOOL_LIST_FAVORITES -> FavoriteToolsBanner()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,7 @@ internal sealed interface DashboardEvent {

@Composable
@OptIn(ExperimentalMaterialApi::class, ExperimentalMaterial3Api::class)
internal fun DashboardLayout(
onEvent: (DashboardEvent) -> Unit,
viewModel: DashboardViewModel = viewModel(),
) {
internal fun DashboardLayout(onEvent: (DashboardEvent) -> Unit, viewModel: DashboardViewModel = viewModel()) {
val scope = rememberCoroutineScope()
val drawerState = rememberDrawerState(DrawerValue.Closed)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class DashboardViewModel @Inject constructor(
// region Page Stack
private var pageStack: List<Page>
get() = savedState.get<List<Page>>(KEY_PAGE_STACK)?.toList() ?: listOf(Page.DEFAULT)
set(value) { savedState[KEY_PAGE_STACK] = ArrayList(value) }
set(value) = savedState.set(KEY_PAGE_STACK, ArrayList(value))
private val pageStackFlow = savedState.getStateFlow(KEY_PAGE_STACK, listOf(Page.DEFAULT))

val hasBackStack = pageStackFlow
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,11 @@ internal fun AllFavoritesList(

@Composable
private fun MutableInteractionSource.reorderableDragInteractions(isDragging: Boolean) {
val dragState = remember { object { var start: DragInteraction.Start? = null } }
val dragState = remember {
object {
var start: DragInteraction.Start? = null
}
}
LaunchedEffect(isDragging) {
when (val start = dragState.start) {
null -> if (isDragging) dragState.start = DragInteraction.Start().also { emit(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,7 @@ internal sealed interface DashboardHomeEvent {

@Composable
@OptIn(ExperimentalFoundationApi::class)
internal fun HomeContent(
onEvent: (DashboardHomeEvent) -> Unit,
viewModel: HomeViewModel = viewModel(),
) {
internal fun HomeContent(onEvent: (DashboardHomeEvent) -> Unit, viewModel: HomeViewModel = viewModel()) {
val favoriteTools by viewModel.favoriteTools.collectAsState()
val spotlightLessons by viewModel.spotlightLessons.collectAsState()
val favoriteToolsLoaded by remember { derivedStateOf { favoriteTools != null } }
Expand Down Expand Up @@ -254,10 +251,7 @@ private fun HorizontalFavoriteTools(

@Preview
@Composable
private fun NoFavoriteTools(
modifier: Modifier = Modifier,
onEvent: (DashboardHomeEvent) -> Unit = {},
) = Surface(
private fun NoFavoriteTools(modifier: Modifier = Modifier, onEvent: (DashboardHomeEvent) -> Unit = {}) = Surface(
color = MaterialTheme.colorScheme.surfaceVariant,
shape = RectangleShape,
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,7 @@ internal sealed interface DashboardLessonsEvent {

@Composable
@OptIn(ExperimentalFoundationApi::class)
internal fun LessonsLayout(
viewModel: LessonsViewModel = viewModel(),
onEvent: (DashboardLessonsEvent) -> Unit = {},
) {
internal fun LessonsLayout(viewModel: LessonsViewModel = viewModel(), onEvent: (DashboardLessonsEvent) -> Unit = {}) {
val lessons by viewModel.lessons.collectAsState()
LazyColumn(contentPadding = PaddingValues(16.dp)) {
item("header", "header") { LessonsHeader() }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,7 @@ import org.cru.godtools.ui.languages.LanguageName
private val POPUP_MAX_HEIGHT = 600.dp

@Composable
internal fun ToolFilters(
modifier: Modifier = Modifier,
viewModel: ToolsViewModel = viewModel(),
) = Column(modifier = modifier.fillMaxWidth()) {
internal fun ToolFilters(viewModel: ToolsViewModel, modifier: Modifier = Modifier) = Column(modifier.fillMaxWidth()) {
Text(
stringResource(R.string.dashboard_tools_section_filter_label),
style = MaterialTheme.typography.titleLarge,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ class ToolsViewModel @Inject constructor(
langs.sortedWith(
compareByDescending<Language> { it.code == appLang }
.then(compareByDescending { it.isAdded })
.then(Language.COMPARATOR_DISPLAY_NAME(context))
.then(Language.displayNameComparator(context))
)
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), emptyList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ internal class LanguageSettingsViewModel @Inject constructor(

val pinnedLanguages = languagesRepository.getPinnedLanguagesFlow()
.combine(settings.appLanguageFlow) { pinned, app ->
pinned.sortedWith(Language.COMPARATOR_DISPLAY_NAME(context, app))
pinned.sortedWith(Language.displayNameComparator(context, app))
}
.stateIn(viewModelScope, SharingStarted.WhileSubscribed(5_000), null)
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,7 @@ fun DownloadableLanguagesLayout(
}

@Composable
private fun LanguageListItem(
viewModel: LanguageViewModels.LanguageViewModel,
modifier: Modifier = Modifier,
) {
private fun LanguageListItem(viewModel: LanguageViewModels.LanguageViewModel, modifier: Modifier = Modifier) {
val scope = rememberCoroutineScope()
val language by viewModel.language.collectAsState()
val toolsAvailable by viewModel.numberOfTools.collectAsState()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ class DownloadableLanguagesViewModel @Inject constructor(
?: it.filter { it.isAdded }.map { it.code }.toSet().also { floatedLanguages = it }
it.sortedWith(
compareByDescending<Language> { it.code in floated }
.then(Language.COMPARATOR_DISPLAY_NAME(context))
.then(Language.displayNameComparator(context))
)
}
.flowOn(Dispatchers.Default)
Expand Down
5 changes: 1 addition & 4 deletions app/src/main/kotlin/org/cru/godtools/ui/login/LoginLayout.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,7 @@ private val FACEBOOK_BLUE = Color(red = 0x18, green = 0x77, blue = 0xf2)

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun LoginLayout(
createAccount: Boolean = false,
onEvent: (event: LoginLayoutEvent) -> Unit
) {
fun LoginLayout(createAccount: Boolean = false, onEvent: (event: LoginLayoutEvent) -> Unit = {}) {
Column(
horizontalAlignment = Alignment.CenterHorizontally,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,7 @@ sealed interface ToolDetailsEvent {

@Composable
@OptIn(ExperimentalMaterial3Api::class)
fun ToolDetailsLayout(
viewModel: ToolDetailsViewModel = viewModel(),
onEvent: (ToolDetailsEvent) -> Unit = {},
) = DrawerMenuLayout {
fun ToolDetailsLayout(viewModel: ToolDetailsViewModel, onEvent: (ToolDetailsEvent) -> Unit = {}) = DrawerMenuLayout {
Scaffold(
topBar = {
TopAppBar(
Expand Down Expand Up @@ -251,10 +248,7 @@ private fun ToolDetailsContent(
}

@Composable
private fun ToolDetailsBanner(
toolViewModel: ToolViewModels.ToolViewModel,
modifier: Modifier = Modifier
) {
private fun ToolDetailsBanner(toolViewModel: ToolViewModels.ToolViewModel, modifier: Modifier = Modifier) {
val tool by toolViewModel.tool.collectAsState()
val banner = toolViewModel.detailsBanner.collectAsState().value
val bannerAnimation = toolViewModel.detailsBannerAnimation.collectAsState().value
Expand Down
4 changes: 2 additions & 2 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ gtoSupport = "4.2.0-SNAPSHOT"
kotlin = "1.9.10"
kotlinCoroutines = "1.7.3"
kotlinKover = "0.7.4"
ktlint = "0.50.0"
ktlint = "1.0.1"
ktlintGradle = "11.6.1"
lottie = "6.1.0"
okhttp3 = "4.11.0"
Expand Down Expand Up @@ -206,7 +206,7 @@ youtubePlayer = "com.pierfrancescosoffritti.androidyoutubeplayer:core:12.1.0"

# HACK: dependencies used to trigger renovate upgrades
androidx-compose-compiler = { module = "androidx.compose.compiler:compiler", version.ref = "androidx-compose-compiler" }
ktlint = { module = "com.pinterest:ktlint", version.ref = "ktlint" }
ktlint = { module = "com.pinterest.ktlint:ktlint-cli", version.ref = "ktlint" }

[bundles]
androidx-compose = ["androidx-compose-runtime", "androidx-compose-ui", "androidx-compose-ui-tooling-preview"]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,19 +37,19 @@ internal class FacebookAccountProvider @Inject constructor(
context: Context,
private val loginManager: LoginManager,
) : AccountProvider {
@VisibleForTesting
internal companion object {
fun PREF_USER_ID(accessToken: AccessToken) = "$PREF_USER_ID_PREFIX${accessToken.userId}"
companion object {
@VisibleForTesting
internal val AccessToken.PREF_USER_ID get() = "$PREF_USER_ID_PREFIX$userId"
}

override val type = AccountType.FACEBOOK
@VisibleForTesting
internal val prefs by lazy { context.getSharedPreferences(PREFS_FACEBOOK_ACCOUNT_PROVIDER, Context.MODE_PRIVATE) }

override val userId get() = accessTokenManager.currentAccessToken?.let { prefs.getString(PREF_USER_ID(it), null) }
override val userId get() = accessTokenManager.currentAccessToken?.let { prefs.getString(it.PREF_USER_ID, null) }
override val isAuthenticated get() = accessTokenManager.currentAccessToken?.isExpired == false
override fun userIdFlow() = accessTokenManager.currentAccessTokenFlow()
.flatMapLatest { it?.let { prefs.getStringFlow(PREF_USER_ID(it), null) } ?: flowOf(null) }
.flatMapLatest { it?.let { prefs.getStringFlow(it.PREF_USER_ID, null) } ?: flowOf(null) }
override fun isAuthenticatedFlow() = accessTokenManager.isAuthenticatedFlow()

// region Login/Logout
Expand Down Expand Up @@ -81,7 +81,7 @@ internal class FacebookAccountProvider @Inject constructor(

return resp.takeIf { it.isSuccessful }
?.body()?.takeUnless { it.hasErrors }?.dataSingle
?.also { prefs.edit { putString(PREF_USER_ID(accessToken), it.userId) } }
?.also { prefs.edit { putString(accessToken.PREF_USER_ID, it.userId) } }
}

private suspend fun AccessToken.authenticateWithMobileContentApi() =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,9 @@ internal class GoogleAccountProvider @Inject constructor(
@ApplicationContext private val context: Context,
private val googleSignInClient: GoogleSignInClient,
) : AccountProvider {
@VisibleForTesting
internal companion object {
fun PREF_USER_ID(account: GoogleSignInAccount) = "${PREF_USER_ID_PREFIX}${account.id}"
companion object {
@VisibleForTesting
internal val GoogleSignInAccount.PREF_USER_ID get() = "$PREF_USER_ID_PREFIX$id"
}

@VisibleForTesting
Expand All @@ -46,10 +46,10 @@ internal class GoogleAccountProvider @Inject constructor(

override val isAuthenticated get() = GoogleSignIn.getLastSignedInAccount(context) != null
override val userId get() = GoogleSignIn.getLastSignedInAccount(context)
?.let { prefs.getString(PREF_USER_ID(it), null) }
?.let { prefs.getString(it.PREF_USER_ID, null) }
override fun isAuthenticatedFlow() = GoogleSignInKtx.getLastSignedInAccountFlow(context).map { it != null }
override fun userIdFlow() = GoogleSignInKtx.getLastSignedInAccountFlow(context)
.flatMapLatest { it?.let { prefs.getStringFlow(PREF_USER_ID(it), null) } ?: flowOf(null) }
.flatMapLatest { it?.let { prefs.getStringFlow(it.PREF_USER_ID, null) } ?: flowOf(null) }

// region Login/Logout
override suspend fun login(state: AccountProvider.LoginState) {
Expand Down Expand Up @@ -78,7 +78,7 @@ internal class GoogleAccountProvider @Inject constructor(
}

val token = resp.takeIf { it.isSuccessful }?.body()?.takeUnless { it.hasErrors }?.dataSingle ?: return null
prefs.edit { putString(PREF_USER_ID(account), token.userId) }
prefs.edit { putString(account.PREF_USER_ID, token.userId) }
return token
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,12 @@ internal abstract class GoogleModule {
companion object {
@Provides
@Reusable
fun googleSignInOptions(
config: GoogleBuildConfig
) = GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(config.serverClientId)
.requestEmail()
.requestProfile()
.build()
fun googleSignInOptions(config: GoogleBuildConfig) =
GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN)
.requestIdToken(config.serverClientId)
.requestEmail()
.requestProfile()
.build()

@Provides
@Singleton
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import org.ccci.gto.android.common.facebook.login.currentAccessTokenFlow
import org.ccci.gto.android.common.facebook.login.refreshCurrentAccessToken
import org.ccci.gto.android.common.jsonapi.model.JsonApiError
import org.ccci.gto.android.common.jsonapi.model.JsonApiObject
import org.cru.godtools.account.provider.facebook.FacebookAccountProvider.Companion.PREF_USER_ID
import org.cru.godtools.api.AuthApi
import org.cru.godtools.api.model.AuthToken
import org.junit.runner.RunWith
Expand Down Expand Up @@ -74,7 +75,7 @@ class FacebookAccountProviderTest {
val user = UUID.randomUUID().toString()
val token = accessToken()
currentAccessTokenFlow.value = token
provider.prefs.edit { putString(FacebookAccountProvider.PREF_USER_ID(token), user) }
provider.prefs.edit { putString(token.PREF_USER_ID, user) }
assertEquals(user, provider.userId)
}

Expand All @@ -83,7 +84,7 @@ class FacebookAccountProviderTest {
fun `userIdFlow()`() = runTest {
val user = UUID.randomUUID().toString()
val token = accessToken()
provider.prefs.edit { putString(FacebookAccountProvider.PREF_USER_ID(token), user) }
provider.prefs.edit { putString(token.PREF_USER_ID, user) }

provider.userIdFlow().test {
assertNull(expectMostRecentItem())
Expand All @@ -108,7 +109,7 @@ class FacebookAccountProviderTest {
runCurrent()
assertNull(expectMostRecentItem())

provider.prefs.edit { putString(FacebookAccountProvider.PREF_USER_ID(token), user) }
provider.prefs.edit { putString(token.PREF_USER_ID, user) }
runCurrent()
assertEquals(user, expectMostRecentItem())
}
Expand Down
Loading

0 comments on commit ed57751

Please sign in to comment.