Skip to content

Commit

Permalink
Migrate to ktlint-gradle
Browse files Browse the repository at this point in the history
  • Loading branch information
arkon committed Mar 3, 2024
1 parent 7a33ce6 commit ef97386
Show file tree
Hide file tree
Showing 31 changed files with 95 additions and 116 deletions.
3 changes: 3 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
[*.{kt,kts}]
max_line_length = 120
indent_size = 4
insert_final_newline = true
ktlint_code_style = intellij_idea
ktlint_function_naming_ignore_when_annotated_with = Composable
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ij_kotlin_name_count_to_use_star_import = 2147483647
Expand Down
13 changes: 7 additions & 6 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ plugins {
id("dagger.hilt.android.plugin")
alias(libs.plugins.ksp)
alias(libs.plugins.apollo)
alias(libs.plugins.kotlinter)
alias(libs.plugins.ktlint)
alias(libs.plugins.autoresconfig)
}

Expand Down Expand Up @@ -149,11 +149,12 @@ apollo {
}
}

kotlinter {
experimentalRules = true

// Doesn't play well with Android Studio
disabledRules = arrayOf("experimental:argument-list-wrapping")
ktlint {
filter {
exclude { element ->
element.file.path.contains("generated/")
}
}
}

tasks {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/kotlin/me/echeung/moemoekyun/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,10 @@ class App : Application(), DefaultLifecycleObserver, ServiceConnection, ImageLoa
val notificationManager = NotificationManagerCompat.from(this)
listOf(
// Playing
NotificationChannelCompat.Builder(MusicNotifier.NOTIFICATION_CHANNEL_ID, NotificationManagerCompat.IMPORTANCE_LOW)
NotificationChannelCompat.Builder(
MusicNotifier.NOTIFICATION_CHANNEL_ID,
NotificationManagerCompat.IMPORTANCE_LOW,
)
.setName(MusicNotifier.NOTIFICATION_CHANNEL_NAME)
.build(),
).forEach(notificationManager::createNotificationChannel)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ class ApiClient @Inject constructor(
*/
suspend fun getUserFavorites(): List<Song> {
// TODO: do actual pagination
val response = client.query(FavoritesQuery("@me", 0, 2500, Optional.presentIfNotNull(preferenceUtil.station().get() == Station.KPOP))).execute()
val response = client.query(
FavoritesQuery("@me", 0, 2500, Optional.presentIfNotNull(preferenceUtil.station().get() == Station.KPOP)),
).execute()

return response.data?.user?.favorites?.favorites
?.mapNotNull { it?.transform() }
Expand All @@ -115,7 +117,9 @@ class ApiClient @Inject constructor(
* @param songId Song to request.
*/
suspend fun requestSong(songId: Int) {
val response = client.mutation(RequestSongMutation(songId, Optional.presentIfNotNull(preferenceUtil.station().get() == Station.KPOP))).execute()
val response = client.mutation(
RequestSongMutation(songId, Optional.presentIfNotNull(preferenceUtil.station().get() == Station.KPOP)),
).execute()

if (response.hasErrors()) {
throw Exception(response.errors.toMessage())
Expand All @@ -142,7 +146,9 @@ class ApiClient @Inject constructor(
suspend fun getAllSongs(): List<Song> {
// TODO: do actual pagination
// TODO: maintain an actual DB of song info so we don't need to query as much stuff
val response = client.query(SongsQuery(0, 50000, Optional.presentIfNotNull(preferenceUtil.station().get() == Station.KPOP)))
val response = client.query(
SongsQuery(0, 50000, Optional.presentIfNotNull(preferenceUtil.station().get() == Station.KPOP)),
)
.httpFetchPolicy(HttpFetchPolicy.CacheFirst)
.httpExpireTimeout(TimeUnit.DAYS.toMillis(1))
.execute()
Expand Down
10 changes: 8 additions & 2 deletions app/src/main/kotlin/me/echeung/moemoekyun/client/api/Stream.kt
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,10 @@ class Stream @Inject constructor(

AudioManager.AUDIOFOCUS_LOSS, AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
wasPlayingBeforeLoss = isPlaying
if (wasPlayingBeforeLoss && (preferenceUtil.shouldPauseAudioOnLoss().get() || context.isCarUiMode())) {
if (
wasPlayingBeforeLoss &&
(preferenceUtil.shouldPauseAudioOnLoss().get() || context.isCarUiMode())
) {
pause()
}
}
Expand Down Expand Up @@ -153,7 +156,10 @@ class Stream @Inject constructor(
// Set stream
val streamUrl = preferenceUtil.station().get().streamUrl
if (streamUrl != currentStreamUrl) {
val dataSourceFactory = DefaultDataSource.Factory(context, DefaultHttpDataSource.Factory().setUserAgent(NetworkUtil.userAgent))
val dataSourceFactory = DefaultDataSource.Factory(
context,
DefaultHttpDataSource.Factory().setUserAgent(NetworkUtil.userAgent),
)
val streamSource = ProgressiveMediaSource.Factory(dataSourceFactory, DefaultExtractorsFactory())
.createMediaSource(MediaItem.Builder().setUri(Uri.parse(streamUrl)).build())
with(player!!) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,7 @@ object SingletonModule {

@Provides
@Singleton
fun okhttpClient(
authUtil: AuthUtil,
): OkHttpClient {
fun okhttpClient(authUtil: AuthUtil): OkHttpClient {
val builder = OkHttpClient.Builder()
.addNetworkInterceptor { chain ->
val request = chain.request()
Expand Down Expand Up @@ -72,10 +70,7 @@ object SingletonModule {

@Provides
@Singleton
fun apolloClient(
@ApplicationContext context: Context,
okHttpClient: OkHttpClient,
) = ApolloClient.Builder()
fun apolloClient(@ApplicationContext context: Context, okHttpClient: OkHttpClient) = ApolloClient.Builder()
.serverUrl("https://listen.moe/graphql")
.httpCache(
directory = File(context.externalCacheDir, "apolloCache"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,11 @@ class GetFavoriteSongs @Inject constructor(

fun getAll(): List<DomainSong> {
return userService.state.value.favorites.let {
songsSorter.sort(it, preferenceUtil.favoritesSortType().get(), preferenceUtil.favoritesSortDescending().get())
songsSorter.sort(
it,
preferenceUtil.favoritesSortType().get(),
preferenceUtil.favoritesSortDescending().get(),
)
}
}

Expand Down
28 changes: 22 additions & 6 deletions app/src/main/kotlin/me/echeung/moemoekyun/service/MusicNotifier.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,12 @@ class MusicNotifier @Inject constructor(
flags = Intent.FLAG_ACTIVITY_SINGLE_TOP
}

val clickIntent = PendingIntent.getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
val clickIntent = PendingIntent.getActivity(
service,
0,
action,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
val deleteIntent = getPlaybackActionService(service, AppService.STOP)

val builder = NotificationCompat.Builder(service, NOTIFICATION_CHANNEL_ID)
Expand All @@ -52,7 +57,9 @@ class MusicNotifier @Inject constructor(
.setOnlyAlertOnce(true)

// Needs to be set after setting the color
val style = androidx.media.app.NotificationCompat.MediaStyle().setMediaSession(service.mediaSession!!.sessionToken)
val style = androidx.media.app.NotificationCompat.MediaStyle().setMediaSession(
service.mediaSession!!.sessionToken,
)
builder.setStyle(style.setShowActionsInCompactView(0))

builder.setContentTitle(currentSong.title)
Expand All @@ -64,9 +71,13 @@ class MusicNotifier @Inject constructor(
builder.addAction(
NotificationCompat.Action(
if (currentSong.favorited) R.drawable.ic_star_24dp else R.drawable.ic_star_border_24dp,
if (currentSong.favorited) service.getString(R.string.action_unfavorite) else service.getString(
R.string.action_favorite,
),
if (currentSong.favorited) {
service.getString(R.string.action_unfavorite)
} else {
service.getString(
R.string.action_favorite,
)
},
getPlaybackActionService(service, AppService.TOGGLE_FAVORITE),
),
)
Expand All @@ -90,7 +101,12 @@ class MusicNotifier @Inject constructor(
action = intentAction
}

return PendingIntent.getService(service, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
return PendingIntent.getService(
service,
0,
intent,
PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE,
)
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,7 @@ private val AlbumArtModifier = Modifier
.clip(RoundedCornerShape(8.dp))

@Composable
fun AlbumArt(
albumArtUrl: String?,
modifier: Modifier = Modifier,
openUrlOnClick: Boolean = true,
) {
fun AlbumArt(albumArtUrl: String?, modifier: Modifier = Modifier, openUrlOnClick: Boolean = true) {
val uriHandler = LocalUriHandler.current

if (albumArtUrl == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,7 @@ import androidx.compose.ui.res.painterResource
import me.echeung.moemoekyun.R

@Composable
fun BackgroundBox(
modifier: Modifier = Modifier,
content: @Composable BoxScope.() -> Unit,
) {
fun BackgroundBox(modifier: Modifier = Modifier, content: @Composable BoxScope.() -> Unit) {
Box(
modifier = modifier,
) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package me.echeung.moemoekyun.ui.common
import androidx.compose.ui.Modifier
import androidx.compose.ui.draw.alpha

const val SecondaryItemAlpha = .78f
const val SECONDARY_ITEM_ALPHA = .78f

fun Modifier.secondaryItemAlpha(): Modifier = this.alpha(SecondaryItemAlpha)
fun Modifier.secondaryItemAlpha(): Modifier = this.alpha(SECONDARY_ITEM_ALPHA)
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,7 @@ fun DropdownMenu(
}

@Composable
fun RadioIcon(
checked: Boolean,
modifier: Modifier = Modifier,
) {
fun RadioIcon(checked: Boolean, modifier: Modifier = Modifier) {
if (checked) {
Icon(
Icons.Outlined.RadioButtonChecked,
Expand All @@ -55,10 +52,7 @@ fun RadioIcon(
}

@Composable
fun CheckboxIcon(
checked: Boolean,
modifier: Modifier = Modifier,
) {
fun CheckboxIcon(checked: Boolean, modifier: Modifier = Modifier) {
if (checked) {
Icon(
Icons.Outlined.CheckBox,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,7 @@ import androidx.compose.ui.Alignment
import androidx.compose.ui.Modifier

@Composable
fun LoadingScreen(
modifier: Modifier = Modifier,
) {
fun LoadingScreen(modifier: Modifier = Modifier) {
Box(
modifier = modifier.fillMaxSize(),
contentAlignment = Alignment.Center,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ import kotlinx.collections.immutable.ImmutableList
import me.echeung.moemoekyun.domain.songs.model.DomainSong
import me.echeung.moemoekyun.ui.screen.songs.SongsScreen

fun LazyListScope.songsItems(
songs: ImmutableList<DomainSong>,
showFavoriteIcons: Boolean = false,
) = items(
fun LazyListScope.songsItems(songs: ImmutableList<DomainSong>, showFavoriteIcons: Boolean = false) = items(
items = songs,
key = { it.id },
) {
Expand Down
10 changes: 2 additions & 8 deletions app/src/main/kotlin/me/echeung/moemoekyun/ui/common/Toolbar.kt
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ fun Toolbar(
}

@Composable
fun UpButton(
modifier: Modifier = Modifier,
) {
fun UpButton(modifier: Modifier = Modifier) {
val navigator = LocalNavigator.currentOrThrow

IconButton(
Expand All @@ -88,11 +86,7 @@ fun UpButton(
}

@Composable
fun SearchTextInput(
query: String?,
modifier: Modifier = Modifier,
onQueryChange: (String) -> Unit,
) {
fun SearchTextInput(query: String?, modifier: Modifier = Modifier, onQueryChange: (String) -> Unit) {
val focusManager = LocalFocusManager.current
val focusRequester = remember { FocusRequester() }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,7 @@ fun <T> ListPreference(
}

@Composable
private fun DialogRow(
label: String,
isSelected: Boolean,
onSelected: () -> Unit,
) {
private fun DialogRow(label: String, isSelected: Boolean, onSelected: () -> Unit) {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,7 @@ import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@Composable
fun PreferenceGroupHeader(
title: String,
modifier: Modifier = Modifier,
) {
fun PreferenceGroupHeader(title: String, modifier: Modifier = Modifier) {
Box(
contentAlignment = Alignment.CenterStart,
modifier = modifier
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,9 @@ object AboutScreen : Screen {

if (BuildConfig.FLAVOR == "playstore") {
AboutCardItem(Icons.Default.Star, R.string.rate) {
uriHandler.openUri("https://play.google.com/store/apps/details?id=me.echeung.moemoekyun")
uriHandler.openUri(
"https://play.google.com/store/apps/details?id=me.echeung.moemoekyun",
)
}
}
AboutCardItem(Icons.Default.Language, R.string.translate) {
Expand Down Expand Up @@ -148,10 +150,7 @@ object AboutScreen : Screen {
}

@Composable
private fun AboutCard(
@StringRes headingResId: Int? = null,
content: @Composable () -> Unit,
) {
private fun AboutCard(@StringRes headingResId: Int? = null, content: @Composable () -> Unit) {
Box(modifier = Modifier.padding(vertical = 8.dp)) {
Card(
modifier = Modifier.fillMaxWidth(),
Expand All @@ -178,11 +177,7 @@ private fun AboutCard(
}

@Composable
private fun AboutCardItem(
imageVector: ImageVector,
@StringRes textResId: Int,
onClick: () -> Unit = {},
) {
private fun AboutCardItem(imageVector: ImageVector, @StringRes textResId: Int, onClick: () -> Unit = {}) {
TextButton(
modifier = Modifier
.fillMaxWidth()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,8 @@ object LoginScreen : Screen {

when (state.result) {
is LoginScreenModel.Result.InvalidOtp -> stringResource(R.string.invalid_mfa_token)
is LoginScreenModel.Result.ApiError -> (state.result as LoginScreenModel.Result.ApiError).message
is LoginScreenModel.Result.ApiError ->
(state.result as LoginScreenModel.Result.ApiError).message
else -> null
}?.let {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,8 @@ object RegisterScreen : Screen {
when (state.result) {
is RegisterScreenModel.Result.AllFieldsRequired -> stringResource(R.string.required)
is RegisterScreenModel.Result.MismatchedPasswords -> stringResource(R.string.password_mismatch)
is RegisterScreenModel.Result.ApiError -> (state.result as RegisterScreenModel.Result.ApiError).message
is RegisterScreenModel.Result.ApiError ->
(state.result as RegisterScreenModel.Result.ApiError).message
else -> null
}?.let {
Text(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,7 @@ private val UserAvatarModifier = Modifier
private val BannerScrim = Color.Black.copy(alpha = 0.65f)

@Composable
private fun UserInfo(
user: DomainUser,
onClickLogOut: () -> Unit,
) {
private fun UserInfo(user: DomainUser, onClickLogOut: () -> Unit) {
val uriHandler = LocalUriHandler.current
var showLogoutConfirmation by remember { mutableStateOf(false) }

Expand Down
Loading

0 comments on commit ef97386

Please sign in to comment.