Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 19 additions & 1 deletion app/src/main/kotlin/app/floatdeck/data/SettingsRepository.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app.floatdeck.data
import android.content.Context
import androidx.datastore.core.DataStore
import androidx.datastore.preferences.core.Preferences
import androidx.datastore.preferences.core.booleanPreferencesKey
import androidx.datastore.preferences.core.edit
import androidx.datastore.preferences.core.stringPreferencesKey
import androidx.datastore.preferences.preferencesDataStore
Expand All @@ -26,6 +27,7 @@ class SettingsRepository(
private val KEY_TEMPLATE = stringPreferencesKey("template_id")
private val KEY_WALLPAPER_URI = stringPreferencesKey("wallpaper_uri")
private val KEY_PORTRAIT_EFFECT = stringPreferencesKey("portrait_effect")
private val KEY_DRAG_ENABLED = booleanPreferencesKey("drag_enabled")
}

/** 当前选中的模板 ID。 */
Expand Down Expand Up @@ -67,7 +69,23 @@ class SettingsRepository(
.apply()
}

/** 保存壁纸 URI(传 null 则移除,恢复使用内置壁纸)。 */
/** Whether portrait drag is enabled, default true. */
val dragEnabled: Flow<Boolean> =
context.dataStore.data.map { prefs ->
prefs[KEY_DRAG_ENABLED] ?: true
}

/** Save portrait drag enabled state. */
suspend fun setDragEnabled(enabled: Boolean) {
context.dataStore.edit { it[KEY_DRAG_ENABLED] = enabled }
context
.getSharedPreferences("settings_prefs", Context.MODE_PRIVATE)
.edit()
.putBoolean("drag_enabled", enabled)
.apply()
}

/** Save wallpaper URI (null removes it, reverting to the built-in wallpaper). */
suspend fun setWallpaperUri(uri: String?) {
context.dataStore.edit { prefs ->
if (uri != null) {
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/kotlin/app/floatdeck/gl/FloatDeckRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -732,6 +732,17 @@ class FloatDeckRenderer(
draggedPortraitIndex = -1
}

/** Reset all portrait drag offsets and velocities to their default positions. */
fun resetDragOffsets() {
portraitStates.forEach { state ->
state.offsetX = 0f
state.offsetY = 0f
state.velocityX = 0f
state.velocityY = 0f
}
draggedPortraitIndex = -1
}

fun onDoubleTap(
touchX: Float,
touchY: Float,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ private const val TAG = "FloatDeckWallpaper"
private const val PREFS_NAME = "settings_prefs"
private const val KEY_TEMPLATE_ID = "template_id"
private const val KEY_PORTRAIT_EFFECT = "portrait_effect"
private const val KEY_DRAG_ENABLED = "drag_enabled"

/**
* FloatDeck 动态壁纸服务入口。
Expand All @@ -46,8 +47,13 @@ class FloatDeckWallpaperService : WallpaperService() {
* 使用强引用字段,避免 SharedPreferences 内部弱引用导致被 GC。
*/
private val prefsListener = SharedPreferences.OnSharedPreferenceChangeListener { _, key ->
if (key == KEY_TEMPLATE_ID || key == KEY_PORTRAIT_EFFECT) {
glThread?.requestReload()
when (key) {
KEY_TEMPLATE_ID, KEY_PORTRAIT_EFFECT -> glThread?.requestReload()
KEY_DRAG_ENABLED -> {
val enabled = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
.getBoolean(KEY_DRAG_ENABLED, true)
if (!enabled) renderer.resetDragOffsets()
}
}
}

Expand Down Expand Up @@ -142,15 +148,19 @@ class FloatDeckWallpaperService : WallpaperService() {
}

override fun onTouchEvent(event: MotionEvent) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
renderer.onTouchDown(event.x, event.y)
}
MotionEvent.ACTION_MOVE -> {
renderer.onTouchMove(event.x, event.y)
}
MotionEvent.ACTION_UP -> {
renderer.onTouchUp()
val dragEnabled = getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE)
.getBoolean(KEY_DRAG_ENABLED, true)
if (dragEnabled) {
when (event.action) {
MotionEvent.ACTION_DOWN -> {
renderer.onTouchDown(event.x, event.y)
}
MotionEvent.ACTION_MOVE -> {
renderer.onTouchMove(event.x, event.y)
}
MotionEvent.ACTION_UP -> {
renderer.onTouchUp()
}
}
}
super.onTouchEvent(event)
Expand Down
24 changes: 24 additions & 0 deletions app/src/main/kotlin/app/floatdeck/settings/SettingsActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ import androidx.compose.material3.Snackbar
import androidx.compose.material3.SnackbarHost
import androidx.compose.material3.SnackbarHostState
import androidx.compose.material3.Surface
import androidx.compose.material3.Switch
import androidx.compose.material3.Text
import androidx.compose.material3.TextButton
import androidx.compose.material3.TopAppBar
Expand Down Expand Up @@ -112,6 +113,7 @@ fun SettingsScreen(
val context = LocalContext.current
var templateId by remember { mutableStateOf("") }
var selectedEffect by remember { mutableStateOf(PortraitEffect.NONE) }
var dragEnabled by remember { mutableStateOf(true) }
var remoteTemplates by remember { mutableStateOf<List<TemplateDef>>(emptyList()) }
var urlText by remember { mutableStateOf("") }
var isLoading by remember { mutableStateOf(false) }
Expand All @@ -136,6 +138,11 @@ fun SettingsScreen(
repo.portraitEffect.collect { selectedEffect = it }
}
}
remember {
scope.launch {
repo.dragEnabled.collect { dragEnabled = it }
}
}

// 加载已导入的远程模板
fun refreshRemoteTemplates() {
Expand Down Expand Up @@ -371,6 +378,23 @@ fun SettingsScreen(
}
}

// Portrait drag toggle
item {
Row(
verticalAlignment = Alignment.CenterVertically,
modifier = Modifier.fillMaxWidth(),
) {
Text(
stringResource(R.string.drag_enabled),
modifier = Modifier.weight(1f),
)
Switch(
checked = dragEnabled,
onCheckedChange = { scope.launch { repo.setDragEnabled(it) } },
)
}
}

item {
HorizontalDivider()
Text(stringResource(R.string.import_remote_template), style = MaterialTheme.typography.titleSmall)
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ja/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="effect_none">なし</string>
<string name="effect_ice">氷</string>
<string name="effect_holo">ホログラム</string>
<string name="drag_enabled">ドラッグを許可</string>
<string name="import_remote_template">リモートテンプレートをインポート</string>
<string name="import_remote_desc">ZIPのURLを入力してテンプレートをダウンロード・インポート</string>
<string name="zip_url_label">ZIPのURL</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-ko/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="effect_none">없음</string>
<string name="effect_ice">얼음</string>
<string name="effect_holo">홀로그램</string>
<string name="drag_enabled">드래그 허용</string>
<string name="import_remote_template">원격 템플릿 가져오기</string>
<string name="import_remote_desc">ZIP URL을 입력해 템플릿을 다운로드하고 가져옵니다</string>
<string name="zip_url_label">ZIP URL</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-zh/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="effect_none">无</string>
<string name="effect_ice">碎碎冰</string>
<string name="effect_holo">炫彩</string>
<string name="drag_enabled">允许拖拽</string>
<string name="import_remote_template">导入远程模板</string>
<string name="import_remote_desc">输入 ZIP 包 URL,从远程下载并导入模板</string>
<string name="zip_url_label">ZIP 包 URL</string>
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<string name="effect_none">None</string>
<string name="effect_ice">Ice</string>
<string name="effect_holo">Holographic</string>
<string name="drag_enabled">Allow Drag</string>
<string name="import_remote_template">Import Remote Template</string>
<string name="import_remote_desc">Enter ZIP URL to download and import template</string>
<string name="zip_url_label">ZIP URL</string>
Expand Down