From ccff65824b2c7d4b2128c02522ba4f099fab1b83 Mon Sep 17 00:00:00 2001 From: Tornaco Date: Fri, 17 May 2024 15:31:33 +0800 Subject: [PATCH] add search widget --- android/app/src/main/AndroidManifest.xml | 13 +++++- .../thanos/power/SmartFreezeActivity.kt | 14 +++++- .../power/SmartFreezeAppListFragment.java | 8 ++-- .../widget/SmartFreezeAppWidgetProvider.kt | 40 ++++++++++++++++++ .../res/drawable-nodpi/search_preview.png | Bin 0 -> 1086 bytes .../res/drawable/app_widget_search_bg.xml | 23 ++++++++++ .../res/layout/smart_freeze_appwidget.xml | 24 +++++++++++ .../layout/smart_freeze_appwidget_preview.xml | 10 +++++ .../src/main/res/values-night-v31/colors.xml | 6 +++ android/app/src/main/res/values/colors.xml | 4 ++ .../main/res/xml/smart_freeze_widget_info.xml | 17 ++++++++ 11 files changed, 154 insertions(+), 5 deletions(-) create mode 100644 android/app/src/main/java/now/fortuitous/thanos/widget/SmartFreezeAppWidgetProvider.kt create mode 100644 android/app/src/main/res/drawable-nodpi/search_preview.png create mode 100644 android/app/src/main/res/drawable/app_widget_search_bg.xml create mode 100644 android/app/src/main/res/layout/smart_freeze_appwidget.xml create mode 100644 android/app/src/main/res/layout/smart_freeze_appwidget_preview.xml create mode 100644 android/app/src/main/res/values-night-v31/colors.xml create mode 100644 android/app/src/main/res/xml/smart_freeze_widget_info.xml diff --git a/android/app/src/main/AndroidManifest.xml b/android/app/src/main/AndroidManifest.xml index 3bb10ba85..8fdf2f9a6 100644 --- a/android/app/src/main/AndroidManifest.xml +++ b/android/app/src/main/AndroidManifest.xml @@ -155,7 +155,7 @@ android:theme="@style/AppThemeNeedRestart" /> + android:exported="true" /> + + + + + + + diff --git a/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeActivity.kt b/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeActivity.kt index fb049503b..08b2a73e7 100644 --- a/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeActivity.kt +++ b/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeActivity.kt @@ -32,6 +32,7 @@ import androidx.compose.ui.graphics.Color import androidx.compose.ui.platform.LocalContext import androidx.compose.ui.res.painterResource import androidx.fragment.app.Fragment +import com.elvishew.xlog.XLog import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.tabs.TabLayout import github.tornaco.android.thanos.BaseFragment @@ -49,6 +50,8 @@ class SmartFreezeActivity : ThemeActivity() { private val viewModel: SmartFreezeBottomNavViewModel by viewModels() companion object Starter { + const val EXTRA_EXPAND_SEARCH = "expand.search" + fun start(context: Context) { ActivityUtils.startActivity(context, SmartFreezeActivity::class.java) } @@ -67,6 +70,16 @@ class SmartFreezeActivity : ThemeActivity() { setContentView(binding.root) inflateTabs() + + binding.bottomNavigation.post { + val hasExpandSearchIntent = intent?.hasExtra(EXTRA_EXPAND_SEARCH) ?: false + XLog.i("SmartFreezeActivity hasExpandSearchIntent: $hasExpandSearchIntent") + if (hasExpandSearchIntent) { + val fragment = supportFragmentManager.findFragmentByTag("SMART_FREEZE_FRAGMENT") + XLog.i("SmartFreezeActivity fragment: $fragment") + (fragment as? SmartFreezeAppListFragment)?.showSearch() + } + } } private fun inflateTabs() { @@ -94,7 +107,6 @@ class SmartFreezeActivity : ThemeActivity() { binding.bottomNavigation.selectTab(binding.bottomNavigation.getTabAt(0)) binding.composeSort.setContent { - val darkTheme = if (appTheme.shouldApplyDynamic) isSystemInDarkTheme() else !appTheme.isLight ThanoxTheme(darkTheme) { diff --git a/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeAppListFragment.java b/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeAppListFragment.java index 8c2433f0a..c1d6f2381 100644 --- a/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeAppListFragment.java +++ b/android/app/src/main/java/now/fortuitous/thanos/power/SmartFreezeAppListFragment.java @@ -63,7 +63,6 @@ import java.util.List; import java.util.Objects; - import github.tornaco.android.thanos.BaseFragment; import github.tornaco.android.thanos.R; import github.tornaco.android.thanos.common.AppItemActionListener; @@ -118,9 +117,9 @@ public static SmartFreezeAppListFragment newInstance(@Nullable String pkgSetId) public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { binding = ActivitySmartFreezeAppsBinding.inflate(inflater, container, false); createOptionsMenu(); - setupView(); Bundle data = getArguments(); String pkgSetId = Objects.requireNonNull(data, "Missing arg: " + ARG_PKG_SET).getString(ARG_PKG_SET, null); + setupView(); setupViewModel(pkgSetId); onSetupSorter(binding.sortChipContainer.sortChip); return binding.getRoot(); @@ -184,6 +183,10 @@ public void onAppItemSwitchStateChange(AppInfo appInfo, boolean checked) { }); } + public void showSearch() { + binding.searchView.showSearch(true); + } + @SuppressLint("RestrictedApi") protected void onSetupSorter(Chip sorterAnchor) { AppSort[] appSortArray = AppSort.values(); @@ -290,7 +293,6 @@ private void showItemPopMenu(@NonNull View anchor, @NonNull AppListModel model) } - private void setupViewModel(String pkgSetId) { viewModel = obtainViewModel(requireActivity()); viewModel.setPkgSetId(pkgSetId); diff --git a/android/app/src/main/java/now/fortuitous/thanos/widget/SmartFreezeAppWidgetProvider.kt b/android/app/src/main/java/now/fortuitous/thanos/widget/SmartFreezeAppWidgetProvider.kt new file mode 100644 index 000000000..5df54de9e --- /dev/null +++ b/android/app/src/main/java/now/fortuitous/thanos/widget/SmartFreezeAppWidgetProvider.kt @@ -0,0 +1,40 @@ +package now.fortuitous.thanos.widget + +import android.app.PendingIntent +import android.appwidget.AppWidgetManager +import android.appwidget.AppWidgetProvider +import android.content.Context +import android.content.Intent +import android.widget.RemoteViews +import github.tornaco.android.thanos.R +import now.fortuitous.thanos.power.SmartFreezeActivity + +class SmartFreezeAppWidgetProvider : AppWidgetProvider() { + + override fun onUpdate( + context: Context, + appWidgetManager: AppWidgetManager, + appWidgetIds: IntArray + ) { + appWidgetIds.forEach { appWidgetId -> + val pendingIntent: PendingIntent = PendingIntent.getActivity( + /* context = */ context, + /* requestCode = */ 0, + /* intent = */ Intent(context, SmartFreezeActivity::class.java).apply { + putExtra(SmartFreezeActivity.EXTRA_EXPAND_SEARCH, true) + addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK) + }, + /* flags = */ PendingIntent.FLAG_CANCEL_CURRENT or PendingIntent.FLAG_IMMUTABLE + ) + + val views: RemoteViews = RemoteViews( + context.packageName, + R.layout.smart_freeze_appwidget + ).apply { + setOnClickPendingIntent(R.id.search_layout, pendingIntent) + } + + appWidgetManager.updateAppWidget(appWidgetId, views) + } + } +} \ No newline at end of file diff --git a/android/app/src/main/res/drawable-nodpi/search_preview.png b/android/app/src/main/res/drawable-nodpi/search_preview.png new file mode 100644 index 0000000000000000000000000000000000000000..598e353044a48ace927b1871320af846966e7287 GIT binary patch literal 1086 zcmeAS@N?(olHy`uVBq!ia0y~yU{nUOQ#hD`VZ^UfKP}kkp52rc>MVBv17+% zWMnKYEei_^wY0QWty=Z*m9rg9~?(Xgu78Y~n%t=m8 z?(6GYxpJkx@cU$-3q(qS{DK+oE4+6|*e@`D{RD&a0R;;h`tvuGxYg}pU|^2+ba4!+ zhJd`|-r1v+U(s zOWYrcFje$sPFU{4u+T>8!;{786W?^IT$$TDNN!?){*hXx1;VYrT~h4blq9Nqo+z+xnAkieVMfG-?GpSP_xEjd{oua% zT1x5e+gpG4em=a+zxAdu$RZS@&YsiQZ)9=YL$Y!WQ{G_KMvh zmFYPnCEqE;H1Fl&&X7Z%WHkD_so*5 z64z!#o{=y&I{reqKjoQ%VP1+{Ox2NNr*4?t`qE!^+tF%6?v-cvza^K29o-ga{;Gbz zaew`~-c@zU(d}>Zm-UwX%VnQ^Oh;u|@1{E0o8mzycLtih6LvbjCD3+L;PD+7|JCQJ z{C+X{bMe|%(dW;lRt55}IWsHBE`57iZei{g>8)G(*Zhw&4i4%2Rn(BHETX*6UhC}T z{(NQQocZ69zwqtropmZl<#pg{Npq*{-?1sT<(0Sf7S#OteJlLm`kr#-*sl}Wgi9aX z<;cxb$}L!}`T75pGt!CErK5YbBPY(6k-paZ%j13guSEgV=T~0OGyU}3#b}pVHiN_U z+poU(?<&@xq}007%=O>mQ|DzEWPbHN?dq5|V~ypL?o0!2shQoaUuEqD1p?nB&j`5IZQ_ztTOM1H;v%7>^g31wm|E1kWfni|RhhR! z{Gr@LpWWF$>+EA5Pvdy$)Rmp&I6bM=+i9ZVo=GjA>fZXr@B9&=cOlGTqRX`1uZ~_? z?0CwU%Ixb6k@zj0#Sx2WM5=TwnR-183h?dQmtWl + + + + + + + + + + + + + + + diff --git a/android/app/src/main/res/layout/smart_freeze_appwidget.xml b/android/app/src/main/res/layout/smart_freeze_appwidget.xml new file mode 100644 index 000000000..108286aee --- /dev/null +++ b/android/app/src/main/res/layout/smart_freeze_appwidget.xml @@ -0,0 +1,24 @@ + + + + + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/layout/smart_freeze_appwidget_preview.xml b/android/app/src/main/res/layout/smart_freeze_appwidget_preview.xml new file mode 100644 index 000000000..1f70d1863 --- /dev/null +++ b/android/app/src/main/res/layout/smart_freeze_appwidget_preview.xml @@ -0,0 +1,10 @@ + + + + + \ No newline at end of file diff --git a/android/app/src/main/res/values-night-v31/colors.xml b/android/app/src/main/res/values-night-v31/colors.xml new file mode 100644 index 000000000..394fd1c1d --- /dev/null +++ b/android/app/src/main/res/values-night-v31/colors.xml @@ -0,0 +1,6 @@ + + + #ea000000 + #ea000000 + #eaffffff + \ No newline at end of file diff --git a/android/app/src/main/res/values/colors.xml b/android/app/src/main/res/values/colors.xml index 98999ef61..e9a4d61e8 100644 --- a/android/app/src/main/res/values/colors.xml +++ b/android/app/src/main/res/values/colors.xml @@ -24,4 +24,8 @@ #ffb74d #f06292 #a1887f + + #eaffffff + #eaffffff + #66000000 \ No newline at end of file diff --git a/android/app/src/main/res/xml/smart_freeze_widget_info.xml b/android/app/src/main/res/xml/smart_freeze_widget_info.xml new file mode 100644 index 000000000..f3ef57ba1 --- /dev/null +++ b/android/app/src/main/res/xml/smart_freeze_widget_info.xml @@ -0,0 +1,17 @@ + + \ No newline at end of file