Skip to content

Commit

Permalink
[optimize|build] Use Modifier.pullToRefresh in compose material3, Bum…
Browse files Browse the repository at this point in the history
…p dependencies (#94)

* [optimize] Use `context.display` when `Build.VERSION.SDK_INT >= Build.VERSION_CODES.R` in MPVView

* [build] OptIn for `kotlinx.coroutines.ExperimentalForInheritanceCoroutinesApi`

* [optimize] Use material3 Modifier.pullToRefresh instead of Modifier.pullRefresh in material

* [build] Bump dependencies
Work around https://issuetracker.google.com/issues/359949836
  • Loading branch information
lightsummer233 authored Oct 19, 2024
1 parent 4347730 commit a9d746e
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 49 deletions.
15 changes: 8 additions & 7 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {
alias(libs.plugins.android.application)
alias(libs.plugins.kotlin.android)
alias(libs.plugins.kotlin.parcelize)
alias(libs.plugins.kotlin.plugin.compose)
alias(libs.plugins.kotlin.plugin.serialization)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.hilt)
alias(libs.plugins.ksp)
}
Expand Down Expand Up @@ -137,22 +137,23 @@ composeCompiler {
// stabilityConfigurationFile = rootProject.layout.projectDirectory.file("stability_config.conf")
}

tasks.withType(KotlinCompile::class.java).configureEach {
tasks.withType(KotlinCompile::class).configureEach {
compilerOptions {
freeCompilerArgs.addAll(
"-opt-in=androidx.compose.material3.ExperimentalMaterial3Api",
"-opt-in=androidx.compose.material3.adaptive.ExperimentalMaterial3AdaptiveApi",
"-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi",
"-opt-in=androidx.compose.material.ExperimentalMaterialApi",
"-opt-in=androidx.compose.animation.ExperimentalAnimationApi",
"-opt-in=androidx.compose.foundation.ExperimentalFoundationApi",
"-opt-in=coil.annotation.ExperimentalCoilApi",
"-opt-in=androidx.compose.material3.windowsizeclass.ExperimentalMaterial3WindowSizeClassApi",
"-opt-in=androidx.compose.foundation.layout.ExperimentalLayoutApi",
"-opt-in=androidx.compose.ui.ExperimentalComposeUiApi",
"-opt-in=coil.annotation.ExperimentalCoilApi",
"-opt-in=kotlinx.coroutines.FlowPreview",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=kotlinx.coroutines.ExperimentalCoroutinesApi",
"-opt-in=com.google.accompanist.permissions.ExperimentalPermissionsApi",
"-opt-in=kotlinx.coroutines.ExperimentalForInheritanceCoroutinesApi",
"-opt-in=kotlinx.serialization.ExperimentalSerializationApi",
"-opt-in=com.google.accompanist.permissions.ExperimentalPermissionsApi"
)
}
}
Expand Down
9 changes: 7 additions & 2 deletions app/src/main/java/com/skyd/anivu/ui/mpv/MPVView.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.skyd.anivu.ui.mpv

import android.content.Context
import android.os.Build
import android.util.AttributeSet
import android.util.Log
import android.view.KeyCharacterMap
Expand Down Expand Up @@ -91,8 +92,12 @@ class MPVView(context: Context, attrs: AttributeSet?) : SurfaceView(context, att
voInUse = vo

// vo: set display fps as reported by android
val wm = context.getSystemService(Context.WINDOW_SERVICE) as WindowManager
val disp = wm.defaultDisplay
val disp = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
context.display
} else {
@Suppress("DEPRECATION")
(context.getSystemService(Context.WINDOW_SERVICE) as WindowManager).defaultDisplay
}
val refreshRate = disp.mode.refreshRate

val dataStore = context.dataStore
Expand Down
24 changes: 13 additions & 11 deletions app/src/main/java/com/skyd/anivu/ui/screen/article/ArticleScreen.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,6 @@ import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.outlined.ArrowUpward
import androidx.compose.material.icons.outlined.Refresh
import androidx.compose.material.icons.outlined.Search
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.HorizontalDivider
import androidx.compose.material3.Icon
import androidx.compose.material3.LocalAbsoluteTonalElevation
Expand All @@ -40,6 +37,9 @@ import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBarDefaults
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator
import androidx.compose.material3.pulltorefresh.pullToRefresh
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.material3.rememberTopAppBarState
import androidx.compose.material3.surfaceColorAtElevation
import androidx.compose.runtime.Composable
Expand Down Expand Up @@ -298,14 +298,16 @@ private fun Content(
onRead: (ArticleWithFeed, Boolean) -> Unit,
contentPadding: PaddingValues,
) {
val state = rememberPullRefreshState(
refreshing = uiState.articleListState.loading,
onRefresh = onRefresh,
)
val state = rememberPullToRefreshState()
Box(
modifier = Modifier
.pullRefresh(state = state, enabled = LocalShowArticlePullRefresh.current)
.padding(top = contentPadding.calculateTopPadding()),
.pullToRefresh(
state = state,
enabled = LocalShowArticlePullRefresh.current,
onRefresh = onRefresh,
isRefreshing = uiState.articleListState.loading
)
.padding(top = contentPadding.calculateTopPadding())
) {
Column {
AnimatedVisibility(visible = showFilterBar) {
Expand Down Expand Up @@ -345,8 +347,8 @@ private fun Content(
}

if (LocalShowArticlePullRefresh.current) {
PullRefreshIndicator(
refreshing = uiState.articleListState.loading,
Indicator(
isRefreshing = uiState.articleListState.loading,
state = state,
modifier = Modifier.align(Alignment.TopCenter),
)
Expand Down
29 changes: 16 additions & 13 deletions app/src/main/java/com/skyd/anivu/ui/screen/media/list/MediaList.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import androidx.compose.foundation.lazy.grid.LazyVerticalGrid
import androidx.compose.foundation.lazy.grid.items
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.pullrefresh.PullRefreshIndicator
import androidx.compose.material.pullrefresh.pullRefresh
import androidx.compose.material.pullrefresh.rememberPullRefreshState
import androidx.compose.material3.Scaffold
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.pulltorefresh.PullToRefreshDefaults.Indicator
import androidx.compose.material3.pulltorefresh.pullToRefresh
import androidx.compose.material3.pulltorefresh.rememberPullToRefreshState
import androidx.compose.runtime.Composable
import androidx.compose.runtime.getValue
import androidx.compose.runtime.mutableStateOf
Expand Down Expand Up @@ -78,13 +78,16 @@ internal fun MediaList(
version = groupInfo?.version,
)
)
val state = rememberPullRefreshState(
refreshing = uiState.listState.loading,
onRefresh = {
dispatch(MediaListIntent.Refresh(path = path, group = groupInfo?.group))
},
)
Box(modifier = Modifier.pullRefresh(state)) {
val state = rememberPullToRefreshState()
Box(
modifier = Modifier.pullToRefresh(
isRefreshing = uiState.listState.loading,
onRefresh = {
dispatch(MediaListIntent.Refresh(path = path, group = groupInfo?.group))
},
state = state
)
) {
when (val listState = uiState.listState) {
is ListState.Failed -> Unit
is ListState.Init -> CircularProgressPlaceholder(contentPadding = innerPadding + contentPadding)
Expand Down Expand Up @@ -120,12 +123,12 @@ internal fun MediaList(
}
}

PullRefreshIndicator(
refreshing = uiState.listState.loading,
state = state,
Indicator(
modifier = Modifier
.padding(contentPadding + fabPadding)
.align(Alignment.TopCenter),
isRefreshing = uiState.listState.loading,
state = state
)
}

Expand Down
4 changes: 2 additions & 2 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ plugins {
alias(libs.plugins.android.application) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.parcelize) apply false
alias(libs.plugins.kotlin.plugin.compose)
alias(libs.plugins.kotlin.plugin.serialization)
alias(libs.plugins.kotlin.compose)
alias(libs.plugins.kotlin.serialization)
alias(libs.plugins.hilt) apply false
alias(libs.plugins.ksp) apply false
}
22 changes: 11 additions & 11 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,22 +3,22 @@ adaptive = "1.0.0"
coil = "2.7.0"
hilt = "2.52"
libtorrent4j = "2.1.0-31"
composeMaterial = "1.7.3"
composeMaterial3 = "1.3.0"
composeMaterial = "1.7.4"
composeMaterial3 = "1.4.0-alpha02"
okhttp3 = "4.12.0"
rome = "2.1.0"
room = "2.6.1"

kotlin = "2.0.20"
kotlin = "2.0.21"

[libraries]
androidx-core-ktx = { module = "androidx.core:core-ktx", version = "1.13.1" }
androidx-appcompat = { module = "androidx.appcompat:appcompat", version = "1.7.0" }
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version = "1.9.2" }
androidx-constraintlayout-compose = { module = "androidx.constraintlayout:constraintlayout-compose", version = "1.1.0-beta01" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version = "2.8.2" }
androidx-activity-ktx = { module = "androidx.activity:activity-ktx", version = "1.9.3" }
androidx-constraintlayout-compose = { module = "androidx.constraintlayout:constraintlayout-compose", version = "1.1.0-rc01" }
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version = "2.8.3" }
androidx-lifecycle-runtime-compose = { module = "androidx.lifecycle:lifecycle-runtime-compose", version = "2.8.6" }
androidx-compose-ui = { module = "androidx.compose.ui:ui", version = "1.7.3" }
androidx-compose-ui = { module = "androidx.compose.ui:ui", version.ref = "composeMaterial" }
androidx-compose-material = { module = "androidx.compose.material:material", version.ref = "composeMaterial" }
androidx-compose-icons = { module = "androidx.compose.material:material-icons-extended", version.ref = "composeMaterial" }
androidx-compose-material3 = { module = "androidx.compose.material3:material3", version.ref = "composeMaterial3" }
Expand Down Expand Up @@ -80,10 +80,10 @@ androidx-junit = { module = "androidx.test.ext:junit", version = "1.2.1" }
androidx-espresso-core = { module = "androidx.test.espresso:espresso-core", version = "3.6.1" }

[plugins]
android-application = { id = "com.android.application", version = "8.5.2" }
android-application = { id = "com.android.application", version = "8.7.1" }
kotlin-android = { id = "org.jetbrains.kotlin.android", version.ref = "kotlin" }
kotlin-parcelize = { id = "org.jetbrains.kotlin.plugin.parcelize", version.ref = "kotlin" }
kotlin-plugin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-plugin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
kotlin-compose = { id = "org.jetbrains.kotlin.plugin.compose", version.ref = "kotlin" }
kotlin-serialization = { id = "org.jetbrains.kotlin.plugin.serialization", version.ref = "kotlin" }
hilt = { id = "com.google.dagger.hilt.android", version = "2.51.1" }
ksp = { id = "com.google.devtools.ksp", version = "2.0.20-1.0.24" }
ksp = { id = "com.google.devtools.ksp", version = "2.0.21-1.0.25" }
Binary file modified gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.10.2-bin.zip
networkTimeout=10000
validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME
Expand Down
7 changes: 5 additions & 2 deletions gradlew
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@
# See the License for the specific language governing permissions and
# limitations under the License.
#
# SPDX-License-Identifier: Apache-2.0
#

##############################################################################
#
Expand Down Expand Up @@ -55,7 +57,7 @@
# Darwin, MinGW, and NonStop.
#
# (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project.
#
# You can find Gradle at https://github.com/gradle/gradle/.
Expand Down Expand Up @@ -84,7 +86,8 @@ done
# shellcheck disable=SC2034
APP_BASE_NAME=${0##*/}
# Discard cd standard output in case $CDPATH is set (https://github.com/gradle/gradle/issues/25036)
APP_HOME=$( cd "${APP_HOME:-./}" > /dev/null && pwd -P ) || exit
APP_HOME=$( cd -P "${APP_HOME:-./}" > /dev/null && printf '%s
' "$PWD" ) || exit

# Use the maximum available, or set MAX_FD != -1 to use that value.
MAX_FD=maximum
Expand Down
2 changes: 2 additions & 0 deletions gradlew.bat
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@
@rem See the License for the specific language governing permissions and
@rem limitations under the License.
@rem
@rem SPDX-License-Identifier: Apache-2.0
@rem

@if "%DEBUG%"=="" @echo off
@rem ##########################################################################
Expand Down

0 comments on commit a9d746e

Please sign in to comment.