Skip to content

Commit

Permalink
add filter dialog
Browse files Browse the repository at this point in the history
  • Loading branch information
sdex committed Jan 15, 2024
1 parent daa91b2 commit 3b3d0d3
Show file tree
Hide file tree
Showing 46 changed files with 723 additions and 187 deletions.
18 changes: 16 additions & 2 deletions app/src/main/java/com/sdex/activityrunner/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import com.sdex.activityrunner.app.ActivitiesListActivity
import com.sdex.activityrunner.app.ApplicationsListAdapter
import com.sdex.activityrunner.app.MainViewModel
import com.sdex.activityrunner.app.dialog.ApplicationOptionsDialog
import com.sdex.activityrunner.app.dialog.FilterBottomSheetDialogFragment
import com.sdex.activityrunner.commons.BaseActivity
import com.sdex.activityrunner.databinding.ActivityMainBinding
import com.sdex.activityrunner.db.cache.ApplicationModel
Expand Down Expand Up @@ -51,6 +52,13 @@ class MainActivity : BaseActivity() {

override fun onMenuItemSelected(menuItem: MenuItem): Boolean {
return when (menuItem.itemId) {
R.id.action_filter -> {
FilterBottomSheetDialogFragment().show(
supportFragmentManager,
FilterBottomSheetDialogFragment.TAG
)
true
}
R.id.action_launch_intent -> {
IntentBuilderActivity.start(this@MainActivity, null)
true
Expand Down Expand Up @@ -91,6 +99,9 @@ class MainActivity : BaseActivity() {
if (it.isNotEmpty()) {
binding.progress.hide()
}
if (supportFragmentManager.findFragmentByTag(FilterBottomSheetDialogFragment.TAG) != null) {
binding.list.scrollToPosition(0)
}
}
}

Expand All @@ -108,8 +119,11 @@ class MainActivity : BaseActivity() {
}
}

override fun onStart() {
super.onStart()
fun refresh() {
viewModel.search(viewModel.searchQuery.value)
}

fun update() {
adapter.update()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
package com.sdex.activityrunner.app.dialog

import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import com.sdex.activityrunner.MainActivity
import com.sdex.activityrunner.databinding.DialogFilterBinding
import com.sdex.activityrunner.db.cache.ApplicationModel
import com.sdex.activityrunner.db.cache.query.GetApplicationsQuery
import com.sdex.activityrunner.preferences.AppPreferences
import dagger.hilt.android.AndroidEntryPoint
import javax.inject.Inject

@AndroidEntryPoint
class FilterBottomSheetDialogFragment : BottomSheetDialogFragment() {

@Inject
lateinit var appPreferences: AppPreferences
private var _binding: DialogFilterBinding? = null
private val binding get() = _binding!!

override fun onCreateView(
inflater: LayoutInflater, container: ViewGroup?,
savedInstanceState: Bundle?
): View {
_binding = DialogFilterBinding.inflate(inflater, container, false)
return binding.root
}

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

when (appPreferences.sortBy) {
ApplicationModel.NAME -> binding.sortByName.isChecked = true
ApplicationModel.UPDATE_TIME -> binding.sortByUpdateTime.isChecked = true
ApplicationModel.INSTALL_TIME -> binding.sortByInstallTime.isChecked = true
}
when (appPreferences.sortOrder) {
GetApplicationsQuery.ASC -> binding.orderByAsc.isChecked = true
GetApplicationsQuery.DESC -> binding.orderByDesc.isChecked = true
}
binding.showSystemApps.isChecked = appPreferences.isShowSystemApps
binding.showSystemAppIndicator.isEnabled = appPreferences.isShowSystemApps
binding.showSystemAppIndicator.isChecked = appPreferences.isShowSystemAppIndicator
binding.showDisabledApps.isChecked = appPreferences.isShowDisabledApps
binding.showDisabledAppIndicator.isEnabled = appPreferences.isShowDisabledApps
binding.showDisabledAppIndicator.isChecked = appPreferences.isShowDisabledAppIndicator

binding.sortByName.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
appPreferences.sortBy = ApplicationModel.NAME
refresh()
}
}
binding.sortByUpdateTime.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
appPreferences.sortBy = ApplicationModel.UPDATE_TIME
refresh()
}
}
binding.sortByInstallTime.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
appPreferences.sortBy = ApplicationModel.INSTALL_TIME
refresh()
}
}
binding.orderByAsc.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
appPreferences.sortOrder = GetApplicationsQuery.ASC
refresh()
}
}
binding.orderByDesc.setOnCheckedChangeListener { _, isChecked ->
if (isChecked) {
appPreferences.sortOrder = GetApplicationsQuery.DESC
refresh()
}
}
binding.showSystemApps.setOnCheckedChangeListener { _, isChecked ->
appPreferences.isShowSystemApps = isChecked
binding.showSystemAppIndicator.isEnabled = isChecked
refresh()
}
binding.showSystemAppIndicator.setOnCheckedChangeListener { _, isChecked ->
appPreferences.isShowSystemAppIndicator = isChecked
update()
}
binding.showDisabledApps.setOnCheckedChangeListener { _, isChecked ->
appPreferences.isShowDisabledApps = isChecked
binding.showDisabledAppIndicator.isEnabled = isChecked
refresh()
}
binding.showDisabledAppIndicator.setOnCheckedChangeListener { _, isChecked ->
appPreferences.isShowDisabledAppIndicator = isChecked
update()
}
}

private fun refresh() {
(activity as MainActivity?)?.refresh()
}

private fun update() {
(activity as MainActivity?)?.update()
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
}

companion object {

const val TAG = "FilterBottomSheetDialogFragment"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ class GetApplicationsQuery(
private val searchText: String? = null,
) {

private val sortBy = ApplicationModel.NAME
private val sortOrder = "ASC"
private val sortCaseSensitive = "COLLATE NOCASE"

val sqLiteQuery get() = SimpleSQLiteQuery(toString())
Expand Down Expand Up @@ -40,8 +38,18 @@ class GetApplicationsQuery(
.append(" LIKE '%").append(escapedSearchText).append("%'")
.append(") ")
}
queryStringBuilder.append("ORDER BY ").append(sortBy).append(" ")
.append(sortCaseSensitive).append(" ").append(sortOrder)
queryStringBuilder.append("ORDER BY ").append(getSortBy()).append(" ")
.append(sortCaseSensitive).append(" ").append(getSortOrder())
return queryStringBuilder.toString()
}

private fun getSortBy(): String = appPreferences.sortBy

private fun getSortOrder(): String = appPreferences.sortOrder

companion object {

const val ASC = "ASC"
const val DESC = "DESC"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import android.content.Context
import androidx.appcompat.app.AppCompatDelegate
import androidx.core.content.edit
import androidx.preference.PreferenceManager
import com.sdex.activityrunner.db.cache.ApplicationModel
import com.sdex.activityrunner.db.cache.query.GetApplicationsQuery

class AppPreferences(context: Context) {

Expand All @@ -12,16 +14,11 @@ class AppPreferences(context: Context) {

var isNotExportedDialogShown: Boolean
get() = preferences.getBoolean(KEY_NOT_EXPORTED_DIALOG_SHOWN, false)
set(value) = preferences.edit()
.putBoolean(KEY_NOT_EXPORTED_DIALOG_SHOWN, value)
.apply()
set(value) = preferences.edit {
putBoolean(KEY_NOT_EXPORTED_DIALOG_SHOWN, value)
}
val appOpenCounter: Int
get() = preferences.getInt(KEY_OPEN_APP_COUNTER, 0)
var showLineNumbers: Boolean
get() = preferences.getBoolean(KEY_SHOW_LINE_NUMBERS, true)
set(value) = preferences.edit()
.putBoolean(KEY_SHOW_LINE_NUMBERS, value)
.apply()

fun onAppOpened() {
preferences.edit {
Expand All @@ -31,31 +28,73 @@ class AppPreferences(context: Context) {

/* user preferences */

val isShowSystemApps: Boolean
var isShowSystemApps: Boolean
get() = userPreferences.getBoolean(KEY_SHOW_SYSTEM_APPS, true)
set(value) {
userPreferences.edit {
putBoolean(KEY_SHOW_SYSTEM_APPS, value)
}
}

val isShowSystemAppIndicator: Boolean
var isShowSystemAppIndicator: Boolean
get() = userPreferences.getBoolean(KEY_SHOW_SYSTEM_APP_LABEL, false)
set(value) {
userPreferences.edit {
putBoolean(KEY_SHOW_SYSTEM_APP_LABEL, value)
}
}

val isShowDisabledApps: Boolean
var isShowDisabledApps: Boolean
get() = userPreferences.getBoolean(KEY_SHOW_DISABLED_APPS, true)
set(value) {
userPreferences.edit {
putBoolean(KEY_SHOW_DISABLED_APPS, value)
}
}

val isShowDisabledAppIndicator: Boolean
var isShowDisabledAppIndicator: Boolean
get() = userPreferences.getBoolean(KEY_SHOW_DISABLED_APP_LABEL, false)
set(value) {
userPreferences.edit {
putBoolean(KEY_SHOW_DISABLED_APP_LABEL, value)
}
}

var showNotExported: Boolean
get() = userPreferences.getBoolean(KEY_SHOW_NOT_EXPORTED, false)
set(value) {
userPreferences.edit()
.putBoolean(KEY_SHOW_NOT_EXPORTED, value)
.apply()
userPreferences.edit {
putBoolean(KEY_SHOW_NOT_EXPORTED, value)
}
}

var showLineNumbers: Boolean
get() = preferences.getBoolean(KEY_SHOW_LINE_NUMBERS, true)
set(value) = preferences.edit {
putBoolean(KEY_SHOW_LINE_NUMBERS, value)
}

@AppCompatDelegate.NightMode
val theme: Int
get() = userPreferences.getString(KEY_THEME, null)?.toInt()
?: AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM

var sortBy: String
get() = userPreferences.getString(KEY_SORT_BY, ApplicationModel.NAME)!!
set(value) {
userPreferences.edit {
putString(KEY_SORT_BY, value)
}
}

var sortOrder: String
get() = userPreferences.getString(KEY_ORDER_BY, GetApplicationsQuery.ASC)!!
set(value) {
userPreferences.edit {
putString(KEY_ORDER_BY, value)
}
}

companion object {

private const val PREFERENCES_NAME = "ads_preferences"
Expand All @@ -69,5 +108,8 @@ class AppPreferences(context: Context) {
const val KEY_SHOW_DISABLED_APPS = "show_disabled_apps"
private const val KEY_SHOW_DISABLED_APP_LABEL = "advanced_disabled_app"
const val KEY_THEME = "appearance_theme"

const val KEY_SORT_BY = "sort_by"
const val KEY_ORDER_BY = "order_by"
}
}
9 changes: 0 additions & 9 deletions app/src/main/res/drawable/background_bottom_dialog.xml

This file was deleted.

10 changes: 10 additions & 0 deletions app/src/main/res/drawable/ic_filter.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:tint="?attr/colorControlNormal"
android:viewportWidth="960"
android:viewportHeight="960">
<path
android:fillColor="@android:color/white"
android:pathData="M400,720L400,640L560,640L560,720L400,720ZM240,520L240,440L720,440L720,520L240,520ZM120,320L120,240L840,240L840,320L120,320Z" />
</vector>
12 changes: 6 additions & 6 deletions app/src/main/res/layout/dialog_activity_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/background_bottom_dialog"
android:orientation="vertical">

<TextView
Expand All @@ -13,13 +12,11 @@
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"
android:paddingStart="50dp"
android:paddingTop="16dp"
android:paddingEnd="50dp"
android:paddingBottom="16dp"
android:paddingHorizontal="50dp"
android:paddingVertical="24dp"
android:textAppearance="?attr/textAppearanceTitleMedium"
android:textColor="@color/blue_light"
tools:text="Application name" />
tools:text="Activity name" />

<View
android:layout_width="match_parent"
Expand All @@ -31,6 +28,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
Expand All @@ -51,6 +49,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
Expand All @@ -71,6 +70,7 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?attr/selectableItemBackground"
android:gravity="center_vertical"
android:orientation="horizontal">

<ImageView
Expand Down
Loading

0 comments on commit 3b3d0d3

Please sign in to comment.