Skip to content

Commit

Permalink
Automatic Lint
Browse files Browse the repository at this point in the history
  • Loading branch information
Syer10 committed Mar 29, 2024
1 parent 253095f commit b93c96a
Show file tree
Hide file tree
Showing 48 changed files with 204 additions and 145 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ class ReaderActivity : AppCompatActivity() {
context: Context,
mangaId: Long,
chapterIndex: Int,
): Intent {
return Intent(context, ReaderActivity::class.java).apply {
): Intent =
Intent(context, ReaderActivity::class.java).apply {
putExtra("manga", mangaId)
putExtra("chapter", chapterIndex)
addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
}
}
}

override fun onCreate(savedInstanceState: Bundle?) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,9 +74,7 @@ class AndroidDownloadService : Service() {
context.stopService(Intent(context, AndroidDownloadService::class.java))
}

fun isRunning(): Boolean {
return instance != null
}
fun isRunning(): Boolean = instance != null

private val json = Json {
ignoreUnknownKeys = true
Expand All @@ -87,9 +85,7 @@ class AndroidDownloadService : Service() {

private lateinit var ioScope: CoroutineScope

override fun onBind(intent: Intent): IBinder? {
return null
}
override fun onBind(intent: Intent): IBinder? = null

override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -123,7 +119,9 @@ class AndroidDownloadService : Service() {
Actions.START.name,
Actions.RESTART.name,
-> startWebsocket()

Actions.STOP.name -> stopSelf()

else -> log.info { "This should never happen. No action in the received intent" }
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,7 @@ class AndroidLibraryService : Service() {
context.stopService(Intent(context, AndroidLibraryService::class.java))
}

fun isRunning(): Boolean {
return instance != null
}
fun isRunning(): Boolean = instance != null

private val json = Json {
ignoreUnknownKeys = true
Expand All @@ -86,9 +84,7 @@ class AndroidLibraryService : Service() {

private lateinit var ioScope: CoroutineScope

override fun onBind(intent: Intent): IBinder? {
return null
}
override fun onBind(intent: Intent): IBinder? = null

override fun onCreate() {
super.onCreate()
Expand Down Expand Up @@ -122,7 +118,9 @@ class AndroidLibraryService : Service() {
Actions.START.name,
Actions.RESTART.name,
-> startWebsocket()

Actions.STOP.name -> stopSelf()

else -> log.info { "This should never happen. No action in the received intent" }
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,9 +152,11 @@ internal class PriorityChannelImpl<T>(
yield()
buffer.add(inChannel.receive())
}

buffer.isFull() -> {
outChannel.send(buffer.removeHead())
}

else -> {
while (buffer.isNotEmpty() && outChannel.trySend(buffer.head).isSuccess) {
buffer.removeHead()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,18 +60,14 @@ internal object StringAdapter : Adapter<String> {
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addStringOrNullListener(key) { callback() }
}
): SettingsListener = preferences.addStringOrNullListener(key) { callback() }
}

internal object LongAdapter : Adapter<Long> {
override fun get(
key: String,
preferences: ObservableSettings,
): Long {
return preferences.getLong(key, 0)
}
): Long = preferences.getLong(key, 0)

override fun set(
key: String,
Expand All @@ -85,18 +81,14 @@ internal object LongAdapter : Adapter<Long> {
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addLongOrNullListener(key) { callback() }
}
): SettingsListener = preferences.addLongOrNullListener(key) { callback() }
}

internal object IntAdapter : Adapter<Int> {
override fun get(
key: String,
preferences: ObservableSettings,
): Int {
return preferences.getInt(key, 0)
}
): Int = preferences.getInt(key, 0)

override fun set(
key: String,
Expand All @@ -110,18 +102,14 @@ internal object IntAdapter : Adapter<Int> {
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addIntOrNullListener(key) { callback() }
}
): SettingsListener = preferences.addIntOrNullListener(key) { callback() }
}

internal object FloatAdapter : Adapter<Float> {
override fun get(
key: String,
preferences: ObservableSettings,
): Float {
return preferences.getFloat(key, 0f)
}
): Float = preferences.getFloat(key, 0f)

override fun set(
key: String,
Expand All @@ -135,18 +123,14 @@ internal object FloatAdapter : Adapter<Float> {
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addFloatOrNullListener(key) { callback() }
}
): SettingsListener = preferences.addFloatOrNullListener(key) { callback() }
}

internal object BooleanAdapter : Adapter<Boolean> {
override fun get(
key: String,
preferences: ObservableSettings,
): Boolean {
return preferences.getBoolean(key, false)
}
): Boolean = preferences.getBoolean(key, false)

override fun set(
key: String,
Expand All @@ -160,9 +144,7 @@ internal object BooleanAdapter : Adapter<Boolean> {
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addBooleanOrNullListener(key) { callback() }
}
): SettingsListener = preferences.addBooleanOrNullListener(key) { callback() }
}

internal object StringSetAdapter : Adapter<Set<String>> {
Expand All @@ -189,9 +171,7 @@ internal object StringSetAdapter : Adapter<Set<String>> {
override fun isSet(
keys: Set<String>,
key: String,
): Boolean {
return keys.contains("$key.size")
}
): Boolean = keys.contains("$key.size")

/**
* Watching the regular key doesn't produce updates for a string set for some reason
Expand All @@ -201,9 +181,7 @@ internal object StringSetAdapter : Adapter<Set<String>> {
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addIntOrNullListener("$key.size") { callback() }
}
): SettingsListener = preferences.addIntOrNullListener("$key.size") { callback() }
}

internal class ObjectAdapter<T>(
Expand All @@ -229,9 +207,7 @@ internal class ObjectAdapter<T>(
key: String,
preferences: ObservableSettings,
callback: () -> Unit,
): SettingsListener {
return preferences.addStringOrNullListener(key) { callback() }
}
): SettingsListener = preferences.addStringOrNullListener(key) { callback() }
}

internal class JsonObjectAdapter<T>(
Expand Down Expand Up @@ -261,9 +237,7 @@ internal class JsonObjectAdapter<T>(
override fun isSet(
keys: Set<String>,
key: String,
): Boolean {
return keys.any { it.startsWith(key) }
}
): Boolean = keys.any { it.startsWith(key) }

/**
* Todo doesn't work
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,59 +19,47 @@ class StandardPreferenceStore(
override fun getString(
key: String,
defaultValue: String,
): Preference<String> {
return StandardPreference(preferences, key, defaultValue, StringAdapter)
}
): Preference<String> = StandardPreference(preferences, key, defaultValue, StringAdapter)

/**
* Returns a [Long] preference for this [key].
*/
override fun getLong(
key: String,
defaultValue: Long,
): Preference<Long> {
return StandardPreference(preferences, key, defaultValue, LongAdapter)
}
): Preference<Long> = StandardPreference(preferences, key, defaultValue, LongAdapter)

/**
* Returns an [Int] preference for this [key].
*/
override fun getInt(
key: String,
defaultValue: Int,
): Preference<Int> {
return StandardPreference(preferences, key, defaultValue, IntAdapter)
}
): Preference<Int> = StandardPreference(preferences, key, defaultValue, IntAdapter)

/**
* Returns a [Float] preference for this [key].
*/
override fun getFloat(
key: String,
defaultValue: Float,
): Preference<Float> {
return StandardPreference(preferences, key, defaultValue, FloatAdapter)
}
): Preference<Float> = StandardPreference(preferences, key, defaultValue, FloatAdapter)

/**
* Returns a [Boolean] preference for this [key].
*/
override fun getBoolean(
key: String,
defaultValue: Boolean,
): Preference<Boolean> {
return StandardPreference(preferences, key, defaultValue, BooleanAdapter)
}
): Preference<Boolean> = StandardPreference(preferences, key, defaultValue, BooleanAdapter)

/**
* Returns a [Set<String>] preference for this [key].
*/
override fun getStringSet(
key: String,
defaultValue: Set<String>,
): Preference<Set<String>> {
return StandardPreference(preferences, key, defaultValue, StringSetAdapter)
}
): Preference<Set<String>> = StandardPreference(preferences, key, defaultValue, StringSetAdapter)

/**
* Returns preference of type [T] for this [key]. The [serializer] and [deserializer] function
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,14 @@ object ImageUtil {
private val gifMagic = "GIF8".toByteArray()
private val webpMagic = "RIFF".toByteArray()

fun findType(bytes: ByteArray): ImageType? {
return when {
fun findType(bytes: ByteArray): ImageType? =
when {
bytes.compareWith(jpgMagic) -> ImageType.JPG
bytes.compareWith(pngMagic) -> ImageType.PNG
bytes.compareWith(gifMagic) -> ImageType.GIF
bytes.compareWith(webpMagic) -> ImageType.WEBP
else -> null
}
}

private fun ByteArray.compareWith(magic: ByteArray): Boolean {
for (i in magic.indices) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ class FlowConverterFactory : Converter.Factory {
val typeData: TypeData,
val ktorfit: Ktorfit,
) : Converter.ResponseConverter<HttpResponse, Flow<Any?>> {
override fun convert(getResponse: suspend () -> HttpResponse): Flow<Any?> {
return flow {
override fun convert(getResponse: suspend () -> HttpResponse): Flow<Any?> =
flow {
val response = getResponse()

val convertedBody = ktorfit.nextSuspendResponseConverter(
Expand All @@ -33,7 +33,6 @@ class FlowConverterFactory : Converter.Factory {
?: response.body(typeData.typeArgs.first().typeInfo)
emit(convertedBody)
}.flowOn(Dispatchers.IO)
}
}

override fun responseConverter(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ actual class DateHandler
setTimeStyle(NSDateFormatterNoStyle)
setLocale(Locale.current.toPlatform())
}

else -> NSDateFormatter()
.apply {
setDateFormat(format)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ actual class DateHandler
"" -> DateTimeFormatter.ofLocalizedDate(FormatStyle.SHORT)
.withLocale(Locale.current.toPlatform())
.withZone(ZoneId.systemDefault())

else -> DateTimeFormatter.ofPattern(format)
.withZone(ZoneId.systemDefault())
}.let { formatter ->
Expand Down
5 changes: 5 additions & 0 deletions desktop/src/main/kotlin/ca/gosyer/jui/desktop/main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,9 @@ suspend fun main() {
SystemTheme.LIGHT, SystemTheme.UNKNOWN -> IntelliJTheme()
SystemTheme.DARK -> DarculaTheme()
}

ThemeMode.Light -> IntelliJTheme()

ThemeMode.Dark -> DarculaTheme()
}
withUIContext {
Expand Down Expand Up @@ -188,10 +190,12 @@ suspend fun main() {
// backPressHandler.handle()
false
}

Key.F3 -> {
displayDebugInfoFlow.value = !displayDebugInfoFlow.value
true
}

else -> false
}
} else {
Expand Down Expand Up @@ -220,6 +224,7 @@ suspend fun main() {
)
}
}

ServerResult.STARTING, ServerResult.FAILED -> {
Surface {
LoadingScreen(
Expand Down
Loading

0 comments on commit b93c96a

Please sign in to comment.