@@ -41,24 +41,31 @@ class ParamsAppChooserRender(private var actionParamInfo: ActionParamInfo, priva
4141
4242 return layout
4343 }
44-
44+
4545 private fun openAppChooser () {
4646 packages = loadPackages(actionParamInfo.type == " packages" )
47+
48+ val collator = Collator .getInstance(Locale .getDefault())
49+ packages.sortWith { a, b ->
50+ collator.compare(a.appName ? : " " , b.appName ? : " " )
51+ }
52+
4753 setSelectStatus()
54+
4855 DialogAppChooser (darkMode, packages, actionParamInfo.multiple, this )
4956 .show(context.supportFragmentManager, " app-chooser" )
5057 }
5158
52- private fun loadPackages (includeMissing : Boolean = false): ArrayList <AdapterAppChooser .AppInfo > {
53- val pm = context.packageManager
54-
55- val filterSet = actionParamInfo.optionsFromShell
56- ?.map { it.value }
57- ?.toHashSet()
58-
59- val result = HashMap <String , AdapterAppChooser .AppInfo >(128 )
60-
61- pm.getInstalledApplications(PackageManager .MATCH_ALL ).forEach { app ->
59+ private fun loadPackages (includeMissing : Boolean = false): ArrayList <AdapterAppChooser .AppInfo > {
60+ val pm = context.packageManager
61+
62+ val filterSet = actionParamInfo.optionsFromShell
63+ ?.map { it.value }
64+ ?.toHashSet()
65+
66+ val result = HashMap <String , AdapterAppChooser .AppInfo >(128 )
67+
68+ pm.getInstalledApplications(PackageManager .MATCH_ALL ).forEach { app ->
6269 val pkg = app.packageName
6370 if (filterSet == null || filterSet.contains(pkg)) {
6471 result[pkg] = AdapterAppChooser .AppInfo ().apply {
@@ -109,56 +116,50 @@ private fun loadPackages(includeMissing: Boolean = false): ArrayList<AdapterAppC
109116 }
110117
111118 // 设置界面显示和元素赋值
112- private fun setTextView () {
113- packages = loadPackages(actionParamInfo.type == " packages" )
114-
115- // sort theo locale
116- val collator = Collator .getInstance(Locale .getDefault())
117- packages.sortWith { a, b ->
118- collator.compare(a.appName ? : " " , b.appName ? : " " )
119- }
120-
121- // map nhanh theo packageName
122- val packageMap = packages
123- .filter { it.packageName != null }
124- .associateBy { it.packageName!! }
125-
126- if (actionParamInfo.multiple) {
127- ActionParamsLayoutRender .getParamValues(actionParamInfo)
128- ?.forEach { value ->
129- packageMap[value]?.selected = true
130- }
131-
132- // giữ hành vi cũ: hiển thị ngay
133- onConfirm(packages.filter { it.selected })
119+ private fun setTextView () {
120+ packages = loadPackages(actionParamInfo.type == " packages" )
134121
135- } else {
136- val validOptions = ArrayList <SelectItem >(packages.size)
137- packages.forEach {
138- validOptions.add(
139- SelectItem ().apply {
140- title = it.appName ? : " "
141- value = it.packageName ? : " "
122+ // map nhanh theo packageName
123+ val packageMap = packages
124+ .filter { it.packageName != null }
125+ .associateBy { it.packageName!! }
126+
127+ if (actionParamInfo.multiple) {
128+ ActionParamsLayoutRender .getParamValues(actionParamInfo)
129+ ?.forEach { value ->
130+ packageMap[value]?.selected = true
142131 }
143- )
144- }
145-
146- val currentIndex =
147- ActionParamsLayoutRender .getParamOptionsCurrentIndex(
148- actionParamInfo,
149- validOptions
150- )
151-
152- if (currentIndex >= 0 ) {
153- val item = packages[currentIndex]
154- valueView.text = item.packageName.orEmpty()
155- nameView.text = item.appName.orEmpty()
132+
133+ // giữ hành vi cũ: hiển thị ngay
134+ onConfirm(packages.filter { it.selected })
135+
156136 } else {
157- valueView.text = " "
158- nameView.text = " "
137+ val validOptions = ArrayList <SelectItem >(packages.size)
138+ packages.forEach {
139+ validOptions.add(
140+ SelectItem ().apply {
141+ title = it.appName ? : " "
142+ value = it.packageName ? : " "
143+ }
144+ )
145+ }
146+
147+ val currentIndex =
148+ ActionParamsLayoutRender .getParamOptionsCurrentIndex(
149+ actionParamInfo,
150+ validOptions
151+ )
152+
153+ if (currentIndex >= 0 ) {
154+ val item = packages[currentIndex]
155+ valueView.text = item.packageName.orEmpty()
156+ nameView.text = item.appName.orEmpty()
157+ } else {
158+ valueView.text = " "
159+ nameView.text = " "
160+ }
159161 }
160162 }
161- }
162163
163164 override fun onConfirm (apps : List <AdapterAppChooser .AppInfo >) {
164165 if (actionParamInfo.multiple) {
0 commit comments