Skip to content

Commit

Permalink
chore: add detekt
Browse files Browse the repository at this point in the history
  • Loading branch information
abdallahmehiz committed Jun 25, 2024
1 parent 2ea9389 commit c826cf9
Show file tree
Hide file tree
Showing 44 changed files with 335 additions and 182 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,4 @@ jobs:
run: chmod +x ./gradlew

- name: Build with Gradle
run: ./gradlew assembleDebug
run: ./gradlew detekt assembleDebug
26 changes: 26 additions & 0 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import io.gitlab.arturbosch.detekt.Detekt

plugins {
alias(libs.plugins.ksp)
alias(libs.plugins.android.application)
alias(libs.plugins.jetbrains.kotlin.android)
alias(libs.plugins.kotlin.compose.compiler)
alias(libs.plugins.room)
alias(libs.plugins.detekt)
}

android {
Expand Down Expand Up @@ -100,6 +103,7 @@ dependencies {
implementation(libs.androidx.documentfile)
implementation(libs.androidx.compose.animation.graphics)
implementation(libs.material)
implementation(libs.androidx.preferences.ktx)

implementation(libs.aniyomi.mpv.lib)
implementation(libs.aniyomi.ffmpeg.kit)
Expand All @@ -113,4 +117,26 @@ dependencies {
implementation(libs.room.runtime)
ksp(libs.room.compiler)
implementation(libs.room.ktx)

implementation(libs.detekt.gradle.plugin)
detektPlugins(libs.detekt.rules.compose)
detektPlugins(libs.detekt.formatter)

implementation(libs.kotlinx.immutable.collections)
}

detekt {
parallel = true
allRules = false
buildUponDefaultConfig = true
config.setFrom("$rootDir/config/detekt/detekt.yml")
}

tasks.withType<Detekt>().configureEach {
setSource(files(project.projectDir))
exclude("**/build/**")
reports {
html.required.set(true)
md.required.set(true)
}
}
14 changes: 5 additions & 9 deletions app/src/main/java/live/mehiz/mpvkt/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,32 @@ import androidx.activity.compose.setContent
import androidx.activity.enableEdgeToEdge
import androidx.compose.foundation.isSystemInDarkTheme
import androidx.compose.runtime.getValue
import androidx.compose.runtime.internal.enableLiveLiterals
import androidx.compose.ui.graphics.Color
import androidx.compose.ui.graphics.toArgb
import cafe.adriel.voyager.navigator.Navigator
import kotlinx.coroutines.flow.collectLatest
import kotlinx.coroutines.flow.take
import live.mehiz.mpvkt.preferences.AppearancePreferences
import live.mehiz.mpvkt.preferences.preference.collectAsState
import live.mehiz.mpvkt.ui.home.HomeScreen
import live.mehiz.mpvkt.ui.theme.DarkMode
import live.mehiz.mpvkt.ui.theme.MpvKtTheme
import org.koin.android.ext.android.inject
import org.koin.androidx.scope.createScope
import org.koin.compose.koinInject
import org.koin.java.KoinJavaComponent.inject

class MainActivity : ComponentActivity() {
val appearancePreferences by inject<AppearancePreferences>()
override fun onCreate(savedInstanceState: Bundle?) {

super.onCreate(savedInstanceState)
setContent {
val dark by appearancePreferences.darkMode.collectAsState()
val isSystemInDarkTheme = isSystemInDarkTheme()
enableEdgeToEdge(
SystemBarStyle.auto(
0xFFF,
0xFFF
lightScrim = Color.White.toArgb(),
darkScrim = Color.White.toArgb()
) { dark == DarkMode.Dark || (dark == DarkMode.System && isSystemInDarkTheme) },
)
MpvKtTheme {
// TODO: add transitions back once these two issues get fixed, thanks Google, very cool!
// add transitions back once these two issues get fixed, thanks Google, very cool!
// https://github.com/adrielcafe/voyager/issues/410
// https://github.com/adrielcafe/voyager/issues/431
Navigator(HomeScreen)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ import live.mehiz.mpvkt.database.dao.PlaybackStateDao
import live.mehiz.mpvkt.database.entities.PlaybackStateEntity

@Database(entities = [PlaybackStateEntity::class], version = 1)
abstract class MpvKtDatabase: RoomDatabase() {
abstract class MpvKtDatabase : RoomDatabase() {
abstract fun videoDataDao(): PlaybackStateDao
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@ class PlayerPreferences(
val invertDuration = preferenceStore.getBoolean("invert_duration", false)
val drawOverDisplayCutout = preferenceStore.getBoolean("draw_over_cutout", true)

val doubleTapToPause = preferenceStore.getBoolean("double_tap_to_pause", false)
val doubleTapToPause = preferenceStore.getBoolean("double_tap_to_pause", true)
val doubleTapToSeek = preferenceStore.getBoolean("double_tap_to_seek", true)
val doubleTapToSeekDuration = preferenceStore.getInt("double_tap_to_seek_duration", 10)
val holdForDoubleSpeed = preferenceStore.getBoolean("hold_for_double_speed", true)

val horizontalSeekGesture = preferenceStore.getBoolean("horizontal_seek_gesture", true)
val brightnessGesture = preferenceStore.getBoolean("gestures_brightness", true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,3 @@ sealed class AndroidPreference<T>(
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,17 @@ package live.mehiz.mpvkt.preferences.preference

import android.content.Context
import android.content.SharedPreferences
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager
import kotlinx.coroutines.channels.awaitClose
import kotlinx.coroutines.flow.callbackFlow
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.Object
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.LongPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.BooleanPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.FloatPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.IntPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.BooleanPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.LongPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.Object
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.StringPrimitive
import live.mehiz.mpvkt.preferences.preference.AndroidPreference.StringSetPrimitive


class AndroidPreferenceStore(
context: Context,
private val sharedPreferences: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(context),
Expand Down
24 changes: 15 additions & 9 deletions app/src/main/java/live/mehiz/mpvkt/presentation/OvalBox.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,20 @@ object RightSideOvalShape : Shape {
lineTo(size.width, 0f)
lineTo(size.width / 10, 0f)
cubicTo(
size.width / 10, 0f,
-30f, size.height / 2,
size.width / 10, size.height
size.width / 10,
0f,
-30f,
size.height / 2,
size.width / 10,
size.height
)
close()
}
return Outline.Generic(path)
}
}

object LeftSideOvalShape: Shape {
object LeftSideOvalShape : Shape {
override fun createOutline(
size: Size,
layoutDirection: LayoutDirection,
Expand All @@ -47,9 +50,12 @@ object LeftSideOvalShape: Shape {
lineTo(0f, size.height)
lineTo(size.width - size.width / 10, size.height)
cubicTo(
size.width - size.width / 10, size.height,
size.width, size.height / 2,
size.width - size.width / 10, 0f
size.width - size.width / 10,
size.height,
size.width,
size.height / 2,
size.width - size.width / 10,
0f
)
close()
}
Expand All @@ -59,7 +65,7 @@ object LeftSideOvalShape: Shape {

@Preview
@Composable
fun PreviewRightSideOvalBox() {
private fun PreviewRightSideOvalBox() {
Box(
modifier = Modifier
.fillMaxSize()
Expand All @@ -70,7 +76,7 @@ fun PreviewRightSideOvalBox() {

@Preview
@Composable
fun PreviewLeftSideOvalBox() {
private fun PreviewLeftSideOvalBox() {
Box(
modifier = Modifier
.fillMaxSize()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,4 +216,3 @@ private fun <T> AnchoredDraggableState<T>.preUpPostDownNestedScrollConnection()

private fun Offset.toFloat(): Float = y
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,18 @@ import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import kotlinx.collections.immutable.ImmutableList

@OptIn(ExperimentalMaterial3Api::class)
@Composable
fun MultiChoiceSegmentedButton(
choices: List<String>,
selectedIndices: List<Int>,
choices: ImmutableList<String>,
selectedIndices: ImmutableList<Int>,
onClick: (Int) -> Unit,
modifier: Modifier = Modifier,
) {
MultiChoiceSegmentedButtonRow(
modifier = Modifier
modifier = modifier
.fillMaxWidth()
.padding(16.dp),
) {
Expand Down
18 changes: 9 additions & 9 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import live.mehiz.mpvkt.ui.theme.MpvKtTheme
import org.koin.android.ext.android.inject
import java.io.File

@Suppress("TooManyFunctions")
class PlayerActivity : AppCompatActivity() {

private val viewModel: PlayerViewModel by lazy { PlayerViewModel(this) }
Expand Down Expand Up @@ -86,7 +87,6 @@ class PlayerActivity : AppCompatActivity() {
}

private fun setupMPV() {

Utils.copyAssets(this)
copyMPVConfigFiles()

Expand Down Expand Up @@ -182,6 +182,7 @@ class PlayerActivity : AppCompatActivity() {
return filepath
}

@Suppress("ReturnCount")
fun openContentFd(uri: Uri): String? {
if (uri.scheme != "content") return null
val resolver = applicationContext.contentResolver
Expand All @@ -201,7 +202,6 @@ class PlayerActivity : AppCompatActivity() {
return path
}
} catch (_: Exception) {

}
// Else, pass the fd to mpv
return "fdclose://$fd"
Expand All @@ -217,7 +217,9 @@ class PlayerActivity : AppCompatActivity() {
}

internal fun onObserverEvent(property: String) {

when (property) {
"chapter-list" -> viewModel.loadChapters()
}
}

internal fun onObserverEvent(property: String, value: Boolean) {
Expand All @@ -232,9 +234,8 @@ class PlayerActivity : AppCompatActivity() {
}
}

internal fun onObserverEvent(property: String, value: String) {

}
@Suppress("EmptyFunctionBlock", "UnusedParameter")
internal fun onObserverEvent(property: String, value: String) {}

internal fun event(eventId: Int) {
when (eventId) {
Expand Down Expand Up @@ -303,9 +304,8 @@ class PlayerActivity : AppCompatActivity() {
super.finish()
}

internal fun efEvent(err: String?) {

}
@Suppress("EmptyFunctionBlock", "UnusedParameter")
internal fun efEvent(err: String?) {}

private fun setOrientation() {
this.requestedOrientation = when (playerPreferences.orientation.get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import `is`.xyz.mpv.MPVLib

class PlayerObserver(
private val activity: PlayerActivity
): MPVLib.EventObserver {
) : MPVLib.EventObserver {
override fun eventProperty(property: String) {
activity.runOnUiThread { activity.onObserverEvent(property) }
}
Expand Down
43 changes: 29 additions & 14 deletions app/src/main/java/live/mehiz/mpvkt/ui/player/PlayerViewModel.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import live.mehiz.mpvkt.R
import live.mehiz.mpvkt.preferences.PlayerPreferences
import org.koin.java.KoinJavaComponent.inject

@Suppress("TooManyFunctions")
class PlayerViewModel(
private val activity: PlayerActivity,
) : ViewModel() {
Expand Down Expand Up @@ -102,16 +103,25 @@ class PlayerViewModel(
}

val getTrackLanguage: (Int) -> String = {
if (it != -1) MPVLib.getPropertyString("track-list/$it/lang") ?: ""
else activity.getString(R.string.player_sheets_tracks_off)
if (it != -1) {
MPVLib.getPropertyString("track-list/$it/lang") ?: ""
} else {
activity.getString(R.string.player_sheets_tracks_off)
}
}
val getTrackTitle: (Int) -> String = {
if (it != -1) MPVLib.getPropertyString("track-list/$it/title") ?: ""
else activity.getString(R.string.player_sheets_tracks_off)
if (it != -1) {
MPVLib.getPropertyString("track-list/$it/title") ?: ""
} else {
activity.getString(R.string.player_sheets_tracks_off)
}
}
val getTrackMPVId: (Int) -> Int = {
if (it != -1) MPVLib.getPropertyInt("track-list/$it/id")
else -1
if (it != -1) {
MPVLib.getPropertyInt("track-list/$it/id")
} else {
-1
}
}
val getTrackType: (Int) -> String? = {
MPVLib.getPropertyString("track-list/$it/type")
Expand All @@ -126,13 +136,13 @@ class PlayerViewModel(
val subTracks = mutableListOf<Track>()
val audioTracks = mutableListOf(Track(-1, activity.getString(R.string.player_sheets_tracks_off), null))
for (i in 0..<tracksCount) {
val type = getTrackType(i) ?: continue
if (!possibleTrackTypes.contains(type)) continue
val type = getTrackType(i)
if (!possibleTrackTypes.contains(type) || type == null) continue
when (type) {
"sub" -> subTracks.add(Track(getTrackMPVId(i), getTrackTitle(i), getTrackLanguage(i)))
"audio" -> audioTracks.add(Track(getTrackMPVId(i), getTrackTitle(i), getTrackLanguage(i)))
"video" -> vidTracks.add(Track(getTrackMPVId(i), getTrackTitle(i), getTrackLanguage(i)))
else -> throw IllegalStateException()
else -> error("Unrecognized track type")
}
}
_subtitleTracks.update { subTracks }
Expand All @@ -142,7 +152,6 @@ class PlayerViewModel(
}
}


fun selectSub(id: Int) {
val selectedSubs = selectedSubtitles.value
_selectedSubtitles.update {
Expand Down Expand Up @@ -219,8 +228,11 @@ class PlayerViewModel(
}

fun pauseUnpause() {
if (paused.value) unpause()
else pause()
if (paused.value) {
unpause()
} else {
pause()
}
}

fun pause() {
Expand All @@ -244,8 +256,11 @@ class PlayerViewModel(

fun toggleControls() {
if (controlsShown.value) hideControls()
if (seekBarShown.value) hideSeekBar()
else showControls()
if (seekBarShown.value) {
hideSeekBar()
} else {
showControls()
}
}

fun toggleSeekBar() {
Expand Down
Loading

0 comments on commit c826cf9

Please sign in to comment.