Skip to content

Commit

Permalink
Merge pull request #986 from anilbeesetti/kotlin-2.0
Browse files Browse the repository at this point in the history
Chore: Update Kotlin to 2.0
  • Loading branch information
anilbeesetti authored Jul 6, 2024
2 parents d02df0e + 7ff6591 commit 5df32fd
Show file tree
Hide file tree
Showing 133 changed files with 796 additions and 801 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
[*.{kt,kts}]
max_line_length = off
ij_kotlin_allow_trailing_comma = true
ij_kotlin_allow_trailing_comma_on_call_site = true
ktlint_code_style = android_studio
ktlint_standard_property-naming = disabled
ktlint_function_naming_ignore_when_annotated_with = Composable
ktlint_function_naming_ignore_when_annotated_with = Composable
7 changes: 2 additions & 5 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
alias(libs.plugins.androidApplication)
alias(libs.plugins.kotlinAndroid)
alias(libs.plugins.composeCompiler)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
}
Expand All @@ -22,10 +23,6 @@ android {
buildConfig = true
}

composeOptions {
kotlinCompilerExtensionVersion = libs.versions.androidxComposeCompiler.get()
}

compileOptions {
sourceCompatibility = JavaVersion.toVersion(libs.versions.android.jvm.get().toInt())
targetCompatibility = JavaVersion.toVersion(libs.versions.android.jvm.get().toInt())
Expand All @@ -41,7 +38,7 @@ android {
isShrinkResources = true
proguardFiles(
getDefaultProguardFile("proguard-android-optimize.txt"),
"proguard-rules.pro"
"proguard-rules.pro",
)
}

Expand Down
16 changes: 8 additions & 8 deletions app/src/main/java/dev/anilbeesetti/nextplayer/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,18 +68,18 @@ class MainActivity : ComponentActivity() {
installSplashScreen()
enableEdgeToEdge(
statusBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT)
navigationBarStyle = SystemBarStyle.light(Color.TRANSPARENT, Color.TRANSPARENT),
)

setContent {
NextPlayerTheme(
darkTheme = shouldUseDarkTheme(uiState = uiState),
highContrastDarkTheme = shouldUseHighContrastDarkTheme(uiState = uiState),
dynamicColor = shouldUseDynamicTheming(uiState = uiState)
dynamicColor = shouldUseDynamicTheming(uiState = uiState),
) {
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.surface
color = MaterialTheme.colorScheme.surface,
) {
val storagePermissionState = rememberPermissionState(permission = storagePermission)

Expand All @@ -97,11 +97,11 @@ class MainActivity : ComponentActivity() {

NavHost(
navController = mainNavController,
startDestination = MEDIA_ROUTE
startDestination = MEDIA_ROUTE,
) {
mediaNavGraph(
context = this@MainActivity,
navController = mainNavController
navController = mainNavController,
)
settingsNavGraph(navController = mainNavController)
}
Expand All @@ -117,7 +117,7 @@ class MainActivity : ComponentActivity() {
*/
@Composable
private fun shouldUseDarkTheme(
uiState: MainActivityUiState
uiState: MainActivityUiState,
): Boolean = when (uiState) {
MainActivityUiState.Loading -> isSystemInDarkTheme()
is MainActivityUiState.Success -> when (uiState.preferences.themeConfig) {
Expand All @@ -129,7 +129,7 @@ private fun shouldUseDarkTheme(

@Composable
fun shouldUseHighContrastDarkTheme(
uiState: MainActivityUiState
uiState: MainActivityUiState,
): Boolean = when (uiState) {
MainActivityUiState.Loading -> false
is MainActivityUiState.Success -> uiState.preferences.useHighContrastDarkTheme
Expand All @@ -140,7 +140,7 @@ fun shouldUseHighContrastDarkTheme(
*/
@Composable
private fun shouldUseDynamicTheming(
uiState: MainActivityUiState
uiState: MainActivityUiState,
): Boolean = when (uiState) {
MainActivityUiState.Loading -> false
is MainActivityUiState.Success -> uiState.preferences.useDynamicColors
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ import kotlinx.coroutines.flow.stateIn

@HiltViewModel
class MainActivityViewModel @Inject constructor(
private val preferencesRepository: PreferencesRepository
private val preferencesRepository: PreferencesRepository,
) : ViewModel() {

val uiState = preferencesRepository.applicationPreferences.map { preferences ->
MainActivityUiState.Success(preferences)
}.stateIn(
scope = viewModelScope,
started = SharingStarted.WhileSubscribed(5000),
initialValue = MainActivityUiState.Loading
initialValue = MainActivityUiState.Loading,
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,20 @@ const val MEDIA_ROUTE = "media_nav_route"

fun NavGraphBuilder.mediaNavGraph(
context: Context,
navController: NavHostController
navController: NavHostController,
) {
navigation(
startDestination = mediaPickerNavigationRoute,
route = MEDIA_ROUTE
route = MEDIA_ROUTE,
) {
mediaPickerScreen(
onPlayVideo = context::startPlayerActivity,
onFolderClick = navController::navigateToMediaPickerFolderScreen,
onSettingsClick = navController::navigateToSettings
onSettingsClick = navController::navigateToSettings,
)
mediaPickerFolderScreen(
onNavigateUp = navController::navigateUp,
onVideoClick = context::startPlayerActivity
onVideoClick = context::startPlayerActivity,
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,11 @@ import dev.anilbeesetti.nextplayer.settings.navigation.subtitlePreferencesScreen
const val SETTINGS_ROUTE = "settings_nav_route"

fun NavGraphBuilder.settingsNavGraph(
navController: NavHostController
navController: NavHostController,
) {
navigation(
startDestination = settingsNavigationRoute,
route = SETTINGS_ROUTE
route = SETTINGS_ROUTE,
) {
settingsScreen(
onNavigateUp = navController::navigateUp,
Expand All @@ -44,32 +44,32 @@ fun NavGraphBuilder.settingsNavGraph(
Setting.SUBTITLE -> navController.navigateToSubtitlePreferences()
Setting.ABOUT -> navController.navigateToAboutPreferences()
}
}
},
)
appearancePreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
mediaLibraryPreferencesScreen(
onNavigateUp = navController::navigateUp,
onFolderSettingClick = navController::navigateToFolderPreferencesScreen
onFolderSettingClick = navController::navigateToFolderPreferencesScreen,
)
folderPreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
playerPreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
decoderPreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
audioPreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
subtitlePreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
aboutPreferencesScreen(
onNavigateUp = navController::navigateUp
onNavigateUp = navController::navigateUp,
)
}
}
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ plugins {
alias(libs.plugins.aboutLibraries) apply false
alias(libs.plugins.androidApplication) apply false
alias(libs.plugins.androidLibrary) apply false
alias(libs.plugins.composeCompiler) apply false
alias(libs.plugins.hilt) apply false
alias(libs.plugins.kotlinAndroid) apply false
alias(libs.plugins.kotlinJvm) apply false
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ annotation class Dispatcher(val niaDispatcher: NextDispatchers)

enum class NextDispatchers {
Default,
IO
IO,
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ object CoroutineScopesModule {
@Singleton
@ApplicationScope
fun providesCoroutineScope(
@Dispatcher(NextDispatchers.Default) dispatcher: CoroutineDispatcher
@Dispatcher(NextDispatchers.Default) dispatcher: CoroutineDispatcher,
): CoroutineScope = CoroutineScope(SupervisorJob() + dispatcher)
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ fun Context.getPath(uri: Uri): String? {
return try {
val contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"),
docId.toLong()
docId.toLong(),
)
getDataColumn(contentUri, null, null)
} catch (e: Exception) {
Expand All @@ -91,7 +91,7 @@ fun Context.getPath(uri: Uri): String? {
}
val selection = "_id=?"
val selectionArgs = arrayOf(
split[1]
split[1],
)
return contentUri?.let { getDataColumn(it, selection, selectionArgs) }
}
Expand All @@ -118,7 +118,7 @@ fun Context.getPath(uri: Uri): String? {
private fun Context.getDataColumn(
uri: Uri,
selection: String? = null,
selectionArgs: Array<String>? = null
selectionArgs: Array<String>? = null,
): String? {
var cursor: Cursor? = null
val column = MediaStore.Images.Media.DATA
Expand Down Expand Up @@ -157,7 +157,7 @@ fun Context.getFilenameFromUri(uri: Uri): String {
*/
fun Context.getFilenameFromContentUri(uri: Uri): String? {
val projection = arrayOf(
OpenableColumns.DISPLAY_NAME
OpenableColumns.DISPLAY_NAME,
)

try {
Expand Down Expand Up @@ -185,7 +185,7 @@ fun Context.getMediaContentUri(uri: Uri): Uri? {
projection,
"${MediaStore.Images.Media.DATA} = ?",
arrayOf(path),
null
null,
)
if (cursor != null && cursor.moveToFirst()) {
val index = cursor.getColumnIndexOrThrow(column)
Expand All @@ -206,13 +206,13 @@ fun Context.showToast(string: String, duration: Int = Toast.LENGTH_SHORT) {

suspend fun Context.scanPaths(
paths: List<String>,
callback: ((String?, Uri?) -> Unit)? = null
callback: ((String?, Uri?) -> Unit)? = null,
) = withContext(Dispatchers.IO) {
MediaScannerConnection.scanFile(
this@scanPaths,
paths.toTypedArray(),
arrayOf("video/*"),
callback
callback,
)
}

Expand Down Expand Up @@ -382,14 +382,14 @@ val Context.thumbnailCacheDir: File

suspend fun ContentResolver.updateMedia(
uri: Uri,
contentValues: ContentValues
contentValues: ContentValues,
): Boolean = withContext(Dispatchers.IO) {
return@withContext try {
update(
uri,
contentValues,
null,
null
null,
) > 0
} catch (e: Exception) {
e.printStackTrace()
Expand All @@ -398,7 +398,7 @@ suspend fun ContentResolver.updateMedia(
}

suspend fun ContentResolver.deleteMedia(
uri: Uri
uri: Uri,
): Boolean = withContext(Dispatchers.IO) {
return@withContext try {
delete(uri, null, null) > 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ interface DataModule {

@Binds
fun bindsMediaRepository(
videoRepository: LocalMediaRepository
videoRepository: LocalMediaRepository,
): MediaRepository

@Binds
fun bindsPreferencesRepository(
preferencesRepository: LocalPreferencesRepository
preferencesRepository: LocalPreferencesRepository,
): PreferencesRepository
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,5 @@ fun AudioStreamInfoEntity.toAudioStreamInfo() = AudioStreamInfo(
sampleFormat = sampleFormat,
sampleRate = sampleRate,
channels = channels,
channelLayout = channelLayout
channelLayout = channelLayout,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ fun DirectoryWithMedia.toFolder() = Folder(
mediaCount = media.size,
dateModified = directory.modified,
formattedMediaSize = Utils.formatFileSize(media.sumOf { it.size }),
mediaList = media.map { it.toVideo() }
mediaList = media.map { it.toVideo() },
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ fun SubtitleStreamInfoEntity.toSubtitleStreamInfo() = SubtitleStreamInfo(
title = title,
codecName = codecName,
language = language,
disposition = disposition
disposition = disposition,
)
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ fun MediumEntity.toVideo() = Video(
thumbnailPath = thumbnailPath,
lastPlayedAt = lastPlayedTime?.let { Date(it) },
formattedDuration = Utils.formatDurationMillis(duration),
formattedFileSize = Utils.formatFileSize(size)
formattedFileSize = Utils.formatFileSize(size),
)

fun MediumWithInfo.toVideo() = Video(
Expand All @@ -46,5 +46,5 @@ fun MediumWithInfo.toVideo() = Video(
formattedFileSize = Utils.formatFileSize(mediumEntity.size),
videoStream = videoStreamInfo?.toVideoStreamInfo(),
audioStreams = audioStreamsInfo.map(AudioStreamInfoEntity::toAudioStreamInfo),
subtitleStreams = subtitleStreamsInfo.map(SubtitleStreamInfoEntity::toSubtitleStreamInfo)
subtitleStreams = subtitleStreamsInfo.map(SubtitleStreamInfoEntity::toSubtitleStreamInfo),
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,6 @@ fun MediumEntity.toVideoState(): VideoState {
audioTrackIndex = audioTrackIndex,
subtitleTrackIndex = subtitleTrackIndex,
playbackSpeed = playbackSpeed,
externalSubs = UriListConverter.fromStringToList(externalSubs)
externalSubs = UriListConverter.fromStringToList(externalSubs),
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@ fun VideoStreamInfoEntity.toVideoStreamInfo() = VideoStreamInfo(
bitRate = bitRate,
frameRate = frameRate,
frameWidth = frameWidth,
frameHeight = frameHeight
frameHeight = frameHeight,
)
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ data class VideoState(
val audioTrackIndex: Int?,
val subtitleTrackIndex: Int?,
val playbackSpeed: Float?,
val externalSubs: List<Uri>
val externalSubs: List<Uri>,
)
Loading

0 comments on commit 5df32fd

Please sign in to comment.