Commit 4987554a authored by Amit Kumar's avatar Amit Kumar 💻
Browse files

Fix search suggestion and layout in widget page

parent a085c1c7
Pipeline #147951 passed with stage
in 2 minutes and 34 seconds
...@@ -214,10 +214,6 @@ open class CellLayout @JvmOverloads constructor( ...@@ -214,10 +214,6 @@ open class CellLayout @JvmOverloads constructor(
requestLayout() requestLayout()
} }
override fun onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int) {
super.onLayout(changed, left, top, right, bottom)
}
fun measureChild(child: View) { fun measureChild(child: View) {
val lp = child.layoutParams as LayoutParams val lp = child.layoutParams as LayoutParams
lp.rowSpec = spec(UNDEFINED) lp.rowSpec = spec(UNDEFINED)
......
...@@ -477,10 +477,11 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -477,10 +477,11 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
} }
// divided by 2 because of left and right padding. // divided by 2 because of left and right padding.
val padding = (mDeviceProfile.availableWidthPx / 2 - Utilities.pxFromDp(8, this) - val emptySpace = mDeviceProfile.availableWidthPx - 2 * Utilities.pxFromDp(16, this) - 4 *
(2 * mDeviceProfile.cellWidthPx
mDeviceProfile.cellWidthPx)).toInt() val padding = emptySpace / 10
widgetPage.findViewById<View>(R.id.suggestedAppGrid).setPadding(padding, 0, padding, 0) widgetPage.findViewById<View>(R.id.suggestedAppGrid)
.setPadding(padding.toInt(), 0, padding.toInt(), 0)
// [[END]] // [[END]]
// Prepare search suggestion view // Prepare search suggestion view
...@@ -539,7 +540,7 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -539,7 +540,7 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
) )
mSearchInput.onFocusChangeListener = mSearchInput.onFocusChangeListener =
View.OnFocusChangeListener { v: View, hasFocus: Boolean -> OnFocusChangeListener { v: View, hasFocus: Boolean ->
if (!hasFocus) { if (!hasFocus) {
hideKeyboard(v) hideKeyboard(v)
} }
...@@ -742,52 +743,30 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -742,52 +743,30 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
private fun searchForLauncherItems( private fun searchForLauncherItems(
charSequence: CharSequence charSequence: CharSequence
): Observable<SuggestionsResult?> { ): Observable<SuggestionsResult?> {
val query = charSequence.toString().toLowerCase() val query = charSequence.toString().lowercase(Locale.getDefault())
val suggestionsResult = SuggestionsResult( val suggestionsResult = SuggestionsResult(
query query
) )
val launcherItems: MutableList<LauncherItem> = ArrayList() val launcherItems: MutableList<LauncherItem> = ArrayList()
workspace.mWorkspaceScreens.forEach { gridLayout: GridLayout -> workspace.mapOverItems(true) { item, _, _ ->
for (i in 0 until gridLayout.childCount) { Log.i(TAG, "searchForLauncherItems: ${item.title}")
val blissFrameLayout = gridLayout.getChildAt(i) as BlissFrameLayout if (item.title.toString().lowercase(Locale.getDefault()).contains(query)) {
val launcherItem = blissFrameLayout.launcherItem launcherItems.add(item)
if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) {
val folderItem = launcherItem as FolderItem
for (item in folderItem.items) {
if (item.title.toString().toLowerCase().contains(query)) {
launcherItems.add(item)
}
}
} else if (launcherItem.title.toString().toLowerCase().contains(query)) {
launcherItems.add(launcherItem)
}
}
}
val hotseat = getHotseat()
for (i in 0 until hotseat.childCount) {
val blissFrameLayout = hotseat.getChildAt(i) as BlissFrameLayout
val launcherItem = blissFrameLayout.launcherItem
if (launcherItem.itemType == Constants.ITEM_TYPE_FOLDER) {
val folderItem = launcherItem as FolderItem
for (item in folderItem.items) {
if (item.title.toString().toLowerCase().contains(query)) {
launcherItems.add(item)
}
}
} else if (launcherItem.title.toString().toLowerCase().contains(query)) {
launcherItems.add(launcherItem)
} }
false
} }
launcherItems.sortWith(Comparator.comparing { launcherItem: LauncherItem -> launcherItems.sortWith(Comparator.comparing { launcherItem: LauncherItem ->
launcherItem.title.toString().toLowerCase().indexOf(query) launcherItem.title.toString().lowercase(Locale.getDefault()).indexOf(query)
}) })
if (launcherItems.size > 4) { if (launcherItems.size > 4) {
suggestionsResult.launcherItems = launcherItems.subList(0, 4) suggestionsResult.launcherItems = launcherItems.subList(0, 4)
} else { } else {
suggestionsResult.launcherItems = launcherItems suggestionsResult.launcherItems = launcherItems
} }
Log.i(TAG, "searchForLauncherItems: $suggestionsResult")
return Observable.just(suggestionsResult) return Observable.just(suggestionsResult)
.onErrorReturn { throwable: Throwable? -> .onErrorReturn {
it.printStackTrace()
suggestionsResult.launcherItems = ArrayList() suggestionsResult.launcherItems = ArrayList()
suggestionsResult suggestionsResult
} }
...@@ -1256,8 +1235,15 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli ...@@ -1256,8 +1235,15 @@ class TestActivity : BaseDraggingActivity(), AutoCompleteAdapter.OnSuggestionCli
val rowSpec = GridLayout.spec(GridLayout.UNDEFINED) val rowSpec = GridLayout.spec(GridLayout.UNDEFINED)
val colSpec = GridLayout.spec(GridLayout.UNDEFINED) val colSpec = GridLayout.spec(GridLayout.UNDEFINED)
val iconLayoutParams = GridLayout.LayoutParams(rowSpec, colSpec) val iconLayoutParams = GridLayout.LayoutParams(rowSpec, colSpec)
iconLayoutParams.height = mDeviceProfile.cellHeightPx val emptySpace = mDeviceProfile.availableWidthPx - 2 * Utilities.pxFromDp(16, this) - 4 *
iconLayoutParams.width = mDeviceProfile.cellWidthPx mDeviceProfile.cellWidthPx
val padding = emptySpace / 10
val topBottomPadding = Utilities.pxFromDp(8, this).toInt()
iconLayoutParams.height = (mDeviceProfile.cellHeightPx + topBottomPadding)
iconLayoutParams.width = (mDeviceProfile.cellWidthPx + padding * 2).toInt()
view.setPadding(padding.toInt(),
(topBottomPadding / 2), padding.toInt(), topBottomPadding / 2)
view.findViewById<View>(R.id.app_label).visibility = View.VISIBLE view.findViewById<View>(R.id.app_label).visibility = View.VISIBLE
view.layoutParams = iconLayoutParams view.layoutParams = iconLayoutParams
view.setWithText(true) view.setWithText(true)
......
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:background="@drawable/search_widget" android:background="@drawable/search_widget"
android:focusableInTouchMode="true" android:focusableInTouchMode="true"
android:paddingRight="8dp"
android:paddingTop="8dp" android:paddingTop="8dp"
android:paddingBottom="8dp"> android:paddingBottom="8dp">
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment