implementing actual search

This commit is contained in:
tibbi
2023-01-14 17:14:43 +01:00
parent ad13fb39b2
commit e8165a574a
2 changed files with 62 additions and 47 deletions

View File

@ -27,7 +27,7 @@ import kotlinx.android.synthetic.main.activity_main.*
class MainActivity : SimpleActivity(), RefreshRecyclerViewListener { class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private val MAX_COLUMN_COUNT = 15 private val MAX_COLUMN_COUNT = 15
private var displayedLaunchers = ArrayList<AppLauncher>() private var launchersIgnoringSearch = ArrayList<AppLauncher>()
private var allLaunchers: ArrayList<AppLauncher>? = null private var allLaunchers: ArrayList<AppLauncher>? = null
private var zoomListener: MyRecyclerView.MyZoomListener? = null private var zoomListener: MyRecyclerView.MyZoomListener? = null
@ -42,8 +42,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
setupOptionsMenu() setupOptionsMenu()
refreshMenuItems() refreshMenuItems()
updateMaterialActivityViews(main_coordinator, launchers_grid, useTransparentNavigation = true, useTopSearchMenu = false) updateMaterialActivityViews(main_coordinator, launchers_grid, useTransparentNavigation = true, useTopSearchMenu = true)
setupMaterialScrollListener(launchers_grid, main_toolbar)
setupEmptyView() setupEmptyView()
setupLaunchers() setupLaunchers()
@ -58,7 +57,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
override fun onResume() { override fun onResume() {
super.onResume() super.onResume()
setupToolbar(main_toolbar) updateMenuColors()
if (mStoredTextColor != getProperTextColor()) { if (mStoredTextColor != getProperTextColor()) {
getGridAdapter()?.updateTextColor(getProperTextColor()) getGridAdapter()?.updateTextColor(getProperTextColor())
} }
@ -72,7 +71,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
updateTextColors(coordinator_layout) updateTextColors(coordinator_layout)
add_icons_placeholder.setTextColor(properPrimaryColor) no_items_placeholder_2.setTextColor(properPrimaryColor)
launchers_fastscroller.updateColors(properPrimaryColor) launchers_fastscroller.updateColors(properPrimaryColor)
(fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt() (fab.layoutParams as CoordinatorLayout.LayoutParams).bottomMargin = navigationBarHeight + resources.getDimension(R.dimen.activity_margin).toInt()
} }
@ -83,13 +82,21 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
private fun refreshMenuItems() { private fun refreshMenuItems() {
main_toolbar.menu.apply { main_menu.getToolbar().menu.apply {
findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations) findItem(R.id.more_apps_from_us).isVisible = !resources.getBoolean(R.bool.hide_google_relations)
} }
} }
private fun setupOptionsMenu() { private fun setupOptionsMenu() {
main_toolbar.setOnMenuItemClickListener { menuItem -> main_menu.getToolbar().inflateMenu(R.menu.menu)
main_menu.toggleHideOnScroll(false)
main_menu.setupMenu()
main_menu.onSearchTextChangedListener = { text ->
searchTextChanged(text)
}
main_menu.getToolbar().setOnMenuItemClickListener { menuItem ->
when (menuItem.itemId) { when (menuItem.itemId) {
R.id.sort -> showSortingDialog() R.id.sort -> showSortingDialog()
R.id.toggle_app_name -> toggleAppName() R.id.toggle_app_name -> toggleAppName()
@ -103,34 +110,23 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
} }
private fun launchSettings() { private fun searchTextChanged(text: String) {
hideKeyboard() val launchers = launchersIgnoringSearch.filter { it.title.contains(text, true) }.toMutableList() as ArrayList<AppLauncher>
startActivity(Intent(applicationContext, SettingsActivity::class.java)) setupAdapter(launchers)
} }
private fun launchAbout() { private fun updateMenuColors() {
val licenses = 0L updateStatusbarColor(getProperBackgroundColor())
main_menu.updateColors()
val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
)
if (!resources.getBoolean(R.bool.hide_google_relations)) {
faqItems.add(FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons))
faqItems.add(FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons))
}
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, false)
} }
private fun getGridAdapter() = launchers_grid.adapter as? LaunchersAdapter private fun getGridAdapter() = launchers_grid.adapter as? LaunchersAdapter
private fun setupLaunchers() { private fun setupLaunchers() {
displayedLaunchers = dbHelper.getLaunchers() launchersIgnoringSearch = dbHelper.getLaunchers()
checkInvalidApps() checkInvalidApps()
initZoomListener() initZoomListener()
setupAdapter(displayedLaunchers) setupAdapter(launchersIgnoringSearch)
maybeShowEmptyView()
} }
private fun setupAdapter(launchers: ArrayList<AppLauncher>) { private fun setupAdapter(launchers: ArrayList<AppLauncher>) {
@ -166,6 +162,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
launchers_grid.adapter = this launchers_grid.adapter = this
} }
maybeShowEmptyView()
ensureBackgroundThread { ensureBackgroundThread {
allLaunchers = getAllLaunchers() allLaunchers = getAllLaunchers()
} }
@ -173,13 +170,13 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun showSortingDialog() { private fun showSortingDialog() {
ChangeSortingDialog(this) { ChangeSortingDialog(this) {
setupAdapter(displayedLaunchers) setupAdapter(launchersIgnoringSearch)
} }
} }
private fun toggleAppName() { private fun toggleAppName() {
config.showAppName = !config.showAppName config.showAppName = !config.showAppName
setupAdapter(displayedLaunchers) setupAdapter(launchersIgnoringSearch)
} }
private fun changeColumnCount() { private fun changeColumnCount() {
@ -261,7 +258,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun checkInvalidApps() { private fun checkInvalidApps() {
val invalidIds = ArrayList<String>() val invalidIds = ArrayList<String>()
for ((id, name, packageName) in displayedLaunchers) { for ((id, name, packageName) in launchersIgnoringSearch) {
val launchIntent = packageManager.getLaunchIntentForPackage(packageName) val launchIntent = packageManager.getLaunchIntentForPackage(packageName)
if (launchIntent == null && !packageName.isAPredefinedApp()) { if (launchIntent == null && !packageName.isAPredefinedApp()) {
invalidIds.add(id.toString()) invalidIds.add(id.toString())
@ -269,7 +266,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
} }
dbHelper.deleteLaunchers(invalidIds) dbHelper.deleteLaunchers(invalidIds)
displayedLaunchers = displayedLaunchers.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher> launchersIgnoringSearch = launchersIgnoringSearch.filter { !invalidIds.contains(it.id.toString()) } as ArrayList<AppLauncher>
} }
private fun storeStateVariables() { private fun storeStateVariables() {
@ -290,7 +287,7 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun fabClicked() { private fun fabClicked() {
if (allLaunchers != null) { if (allLaunchers != null) {
val shownLaunchers = (launchers_grid.adapter as LaunchersAdapter).launchers val shownLaunchers = launchersIgnoringSearch
AddLaunchersDialog(this, allLaunchers!!, shownLaunchers) { AddLaunchersDialog(this, allLaunchers!!, shownLaunchers) {
setupLaunchers() setupLaunchers()
} }
@ -299,21 +296,42 @@ class MainActivity : SimpleActivity(), RefreshRecyclerViewListener {
private fun setupEmptyView() { private fun setupEmptyView() {
val properPrimaryColor = getProperPrimaryColor() val properPrimaryColor = getProperPrimaryColor()
add_icons_placeholder.underlineText() no_items_placeholder_2.underlineText()
add_icons_placeholder.setTextColor(properPrimaryColor) no_items_placeholder_2.setTextColor(properPrimaryColor)
add_icons_placeholder.setOnClickListener { no_items_placeholder_2.setOnClickListener {
fabClicked() fabClicked()
} }
} }
private fun maybeShowEmptyView() { private fun maybeShowEmptyView() {
val emptyViews = arrayOf(add_icons_placeholder, no_items_placeholder) if (getGridAdapter()?.launchers?.isEmpty() == true) {
if (displayedLaunchers.isEmpty()) { launchers_fastscroller.beGone()
launchers_fastscroller.fadeOut() no_items_placeholder_2.beVisibleIf(main_menu.getCurrentQuery().isEmpty())
emptyViews.forEach { it.fadeIn() } no_items_placeholder.beVisible()
} else { } else {
emptyViews.forEach { it.fadeOut() } no_items_placeholder_2.beGone()
launchers_fastscroller.fadeIn() no_items_placeholder.beGone()
launchers_fastscroller.beVisible()
} }
} }
private fun launchSettings() {
hideKeyboard()
startActivity(Intent(applicationContext, SettingsActivity::class.java))
}
private fun launchAbout() {
val licenses = 0L
val faqItems = arrayListOf(
FAQItem(R.string.faq_1_title, R.string.faq_1_text),
)
if (!resources.getBoolean(R.bool.hide_google_relations)) {
faqItems.add(FAQItem(R.string.faq_2_title_commons, R.string.faq_2_text_commons))
faqItems.add(FAQItem(R.string.faq_6_title_commons, R.string.faq_6_text_commons))
}
startAboutActivity(R.string.app_name, licenses, BuildConfig.VERSION_NAME, faqItems, false)
}
} }

View File

@ -6,13 +6,10 @@
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent">
<com.google.android.material.appbar.MaterialToolbar <com.simplemobiletools.commons.views.MySearchMenu
android:id="@+id/main_toolbar" android:id="@+id/main_menu"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" android:layout_height="wrap_content" />
android:background="@color/color_primary"
app:menu="@menu/menu"
app:titleTextAppearance="@style/AppTheme.ActionBar.TitleTextStyle" />
<RelativeLayout <RelativeLayout
android:id="@+id/main_relative_layout" android:id="@+id/main_relative_layout"
@ -49,7 +46,7 @@
tools:visibility="visible" /> tools:visibility="visible" />
<com.simplemobiletools.commons.views.MyTextView <com.simplemobiletools.commons.views.MyTextView
android:id="@+id/add_icons_placeholder" android:id="@+id/no_items_placeholder_2"
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_below="@+id/no_items_placeholder" android:layout_below="@+id/no_items_placeholder"