Skip to content

Commit

Permalink
feat: Added app widget option in the Settings page.
Browse files Browse the repository at this point in the history
  • Loading branch information
Yubyf committed Jul 27, 2023
1 parent 719514c commit 68e33b9
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@

package com.crossbowffs.quotelock.app.settings

import android.appwidget.AppWidgetManager
import android.content.ComponentName
import android.content.res.Configuration
import android.os.Build
import androidx.appcompat.app.AppCompatDelegate
import androidx.compose.foundation.background
import androidx.compose.foundation.layout.Box
Expand Down Expand Up @@ -48,6 +51,7 @@ import androidx.compose.ui.unit.dp
import androidx.hilt.navigation.compose.hiltViewModel
import com.crossbowffs.quotelock.app.SnackBarEvent
import com.crossbowffs.quotelock.app.emptySnackBarEvent
import com.crossbowffs.quotelock.app.widget.QuoteGlanceWidgetReceiver
import com.crossbowffs.quotelock.data.api.AndroidString
import com.crossbowffs.quotelock.data.api.QuoteModuleData
import com.crossbowffs.quotelock.data.api.contextString
Expand Down Expand Up @@ -250,6 +254,22 @@ fun SettingsScreen(
summaryRes = R.string.pref_debug_restart_system_ui_summary,
onClick = onRestartSystemUiItemClicked
)
val appWidgetManager = AppWidgetManager.getInstance(context)
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
PreferenceItem(
titleRes = R.string.pref_pin_widget_title,
summaryRes = if (appWidgetManager.isRequestPinAppWidgetSupported)
R.string.pref_pin_widget_summary else R.string.pref_pin_widget_summary_alt,
enabled = appWidgetManager.isRequestPinAppWidgetSupported,
onClick = {
appWidgetManager.requestPinAppWidget(
ComponentName(context, QuoteGlanceWidgetReceiver::class.java),
null,
null
)
}
)
}
PreferenceItem(
title = stringResource(id = R.string.pref_clear_cache),
info = {
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<string name="preview">预览</string>
<string name="lockscreen_styles">锁屏样式</string>
<string name="style">样式</string>
<string name="pin_widget">应用微件</string>
<string name="about">关于</string>
<string name="close">关闭</string>
<string name="search">搜索</string>
Expand Down Expand Up @@ -85,6 +86,9 @@
<string name="pref_detail_title">详情</string>
<string name="pref_restart_system_ui_title">重启 System UI</string>
<string name="pref_debug_restart_system_ui_summary">[ROOT] 重新挂钩锁屏界面</string>
<string name="pref_pin_widget_title">应用小部件</string>
<string name="pref_pin_widget_summary">固定应用小部件到主屏幕</string>
<string name="pref_pin_widget_summary_alt">默认启动器不支持固定应用小部件</string>
<string name="pref_clear_cache">清除缓存</string>
<string name="refresh_quote">刷新</string>
<string name="quote_download_failed">格言下载失败</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values-zh-rTW/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,9 @@
<string name="pref_detail_title">詳情</string>
<string name="pref_restart_system_ui_title">重啟 System UI</string>
<string name="pref_debug_restart_system_ui_summary">[ROOT] 重新掛鉤鎖屏介面</string>
<string name="pref_pin_widget_title">應用小部件</string>
<string name="pref_pin_widget_summary">固定應用小部件到主屏幕</string>
<string name="pref_pin_widget_summary_alt">默認啟動器不支持固定應用程序小部件</string>
<string name="pref_clear_cache">清除緩存</string>
<string name="refresh_quote">刷新</string>
<string name="quote_download_failed">格言下載失敗</string>
Expand Down
3 changes: 3 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@
<string name="pref_detail_title">Detail</string>
<string name="pref_restart_system_ui_title">Restart System UI</string>
<string name="pref_debug_restart_system_ui_summary">[ROOT] Re-hook lockscreen</string>
<string name="pref_pin_widget_title">App widget</string>
<string name="pref_pin_widget_summary">Pin a widget onto home screen</string>
<string name="pref_pin_widget_summary_alt">The default launcher does not support pinning app widgets</string>
<string name="pref_clear_cache">Clear Cache</string>
<string name="refresh_quote">Refresh</string>
<string name="quote_download_failed">Failed to download quote</string>
Expand Down

0 comments on commit 68e33b9

Please sign in to comment.