mirror of
https://github.com/jrpie/Launcher.git
synced 2025-02-23 14:31:30 +01:00
better search
This commit is contained in:
parent
cc2e7710c8
commit
aa9077d5db
6 changed files with 57 additions and 8 deletions
|
@ -15,6 +15,7 @@
|
||||||
android:theme="@style/baseTheme">
|
android:theme="@style/baseTheme">
|
||||||
|
|
||||||
<activity android:name=".HomeActivity"
|
<activity android:name=".HomeActivity"
|
||||||
|
android:exported="true"
|
||||||
android:screenOrientation="portrait"
|
android:screenOrientation="portrait"
|
||||||
tools:ignore="LockedOrientationActivity">
|
tools:ignore="LockedOrientationActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
|
|
@ -213,6 +213,17 @@ private fun getIntent(packageName: String, context: Context): Intent? {
|
||||||
return intent
|
return intent
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun canReachSettings(): Boolean {
|
||||||
|
var availableActions = ACTIONS;
|
||||||
|
if(!launcherPreferences.getBoolean(PREF_DOUBLE_ACTIONS_ENABLED, false)){
|
||||||
|
availableActions = listOf(
|
||||||
|
ACTION_UP, ACTION_DOWN, ACTION_RIGHT, ACTION_LEFT, ACTION_VOL_UP,
|
||||||
|
ACTION_VOL_DOWN, ACTION_DOUBLE_CLICK, ACTION_LONG_CLICK, ACTION_DATE, ACTION_TIME
|
||||||
|
)
|
||||||
|
}
|
||||||
|
return availableActions.contains("launcher:settings") || availableActions.contains("launcher:choose")
|
||||||
|
}
|
||||||
|
|
||||||
fun launch(
|
fun launch(
|
||||||
data: String, activity: Activity,
|
data: String, activity: Activity,
|
||||||
animationIn: Int = android.R.anim.fade_in, animationOut: Int = android.R.anim.fade_out
|
animationIn: Int = android.R.anim.fade_in, animationOut: Int = android.R.anim.fade_out
|
||||||
|
|
|
@ -198,18 +198,20 @@ class HomeActivity: UIObject, AppCompatActivity(),
|
||||||
true -> {
|
true -> {
|
||||||
hideSettingsIcon()
|
hideSettingsIcon()
|
||||||
}
|
}
|
||||||
false -> showSettingsIcon()
|
false -> {showSettingsIcon()}
|
||||||
}
|
}
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showSettingsIcon(){
|
private fun showSettingsIcon(){
|
||||||
home_settings_icon.fadeRotateIn()
|
if(!canReachSettings()) {
|
||||||
home_settings_icon.visibility = View.VISIBLE
|
home_settings_icon.fadeRotateIn()
|
||||||
settingsIconShown = true
|
home_settings_icon.visibility = View.VISIBLE
|
||||||
|
settingsIconShown = true
|
||||||
|
|
||||||
tooltipTimer = fixedRateTimer("tooltipTimer", true, 10000, 1000) {
|
tooltipTimer = fixedRateTimer("tooltipTimer", true, 10000, 1000) {
|
||||||
this@HomeActivity.runOnUiThread { hideSettingsIcon() }
|
this@HomeActivity.runOnUiThread { hideSettingsIcon() }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ import androidx.fragment.app.FragmentManager
|
||||||
import androidx.fragment.app.FragmentPagerAdapter
|
import androidx.fragment.app.FragmentPagerAdapter
|
||||||
import com.finnmglas.launcher.list.apps.ListFragmentApps
|
import com.finnmglas.launcher.list.apps.ListFragmentApps
|
||||||
import com.finnmglas.launcher.list.other.ListFragmentOther
|
import com.finnmglas.launcher.list.other.ListFragmentOther
|
||||||
|
import kotlinx.android.synthetic.main.home.*
|
||||||
|
import kotlinx.android.synthetic.main.list_apps.*
|
||||||
|
|
||||||
var intendedChoosePause = false // know when to close
|
var intendedChoosePause = false // know when to close
|
||||||
|
|
||||||
|
@ -38,6 +40,10 @@ class ListActivity : AppCompatActivity(), UIObject {
|
||||||
|
|
||||||
// Initialise layout
|
// Initialise layout
|
||||||
setContentView(R.layout.list)
|
setContentView(R.layout.list)
|
||||||
|
|
||||||
|
list_settings.setOnClickListener() {
|
||||||
|
launch("launcher:settings", this, R.anim.bottom_up)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStart(){
|
override fun onStart(){
|
||||||
|
|
|
@ -156,20 +156,31 @@ class AppsRecyclerAdapter(val activity: Activity,
|
||||||
* The function [filter] is used to search elements within this [RecyclerView].
|
* The function [filter] is used to search elements within this [RecyclerView].
|
||||||
*/
|
*/
|
||||||
fun filter(text: String) {
|
fun filter(text: String) {
|
||||||
|
// normalize text for search
|
||||||
|
fun normalize(text: String): String{
|
||||||
|
return text.toLowerCase(Locale.ROOT).replace("[^a-z0-9]", "")
|
||||||
|
}
|
||||||
appsListDisplayed.clear()
|
appsListDisplayed.clear()
|
||||||
if (text.isEmpty()) {
|
if (text.isEmpty()) {
|
||||||
appsListDisplayed.addAll(appsList)
|
appsListDisplayed.addAll(appsList)
|
||||||
} else {
|
} else {
|
||||||
|
var appsSecondary: MutableList<AppInfo> = ArrayList();
|
||||||
|
var normalizedText: String = normalize(text);
|
||||||
for (item in appsList) {
|
for (item in appsList) {
|
||||||
if (item.label.toString().toLowerCase(Locale.ROOT).contains(text.toLowerCase(Locale.ROOT))) {
|
var itemLabel: String = normalize(item.label.toString());
|
||||||
|
|
||||||
|
if (itemLabel.startsWith(normalizedText)) {
|
||||||
appsListDisplayed.add(item)
|
appsListDisplayed.add(item)
|
||||||
|
}else if(itemLabel.contains(normalizedText)){
|
||||||
|
appsSecondary.add(item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
appsListDisplayed.addAll(appsSecondary);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Launch apps automatically if only one result is found and the user wants it
|
// Launch apps automatically if only one result is found and the user wants it
|
||||||
// Disabled at the moment. The Setting 'PREF_SEARCH_AUTO_LAUNCH' may be
|
// Disabled at the moment. The Setting 'PREF_SEARCH_AUTO_LAUNCH' may be
|
||||||
// modifyable at some later point.
|
// modifiable at some later point.
|
||||||
if (appsListDisplayed.size == 1 && intention == "view"
|
if (appsListDisplayed.size == 1 && intention == "view"
|
||||||
&& launcherPreferences.getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)) {
|
&& launcherPreferences.getBoolean(PREF_SEARCH_AUTO_LAUNCH, false)) {
|
||||||
launch(appsListDisplayed[0].packageName.toString(), activity)
|
launch(appsListDisplayed[0].packageName.toString(), activity)
|
||||||
|
|
|
@ -23,6 +23,24 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent">
|
android:layout_height="match_parent">
|
||||||
|
|
||||||
|
<com.finnmglas.launcher.libraries.FontAwesome
|
||||||
|
android:id="@+id/list_settings"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="8dp"
|
||||||
|
android:layout_marginLeft="8dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:includeFontPadding="true"
|
||||||
|
android:paddingLeft="16sp"
|
||||||
|
android:paddingRight="16sp"
|
||||||
|
android:text="@string/fas_settings"
|
||||||
|
android:textColor="?attr/colorAccent"
|
||||||
|
android:textSize="22sp"
|
||||||
|
custom:layout_constraintBottom_toBottomOf="parent"
|
||||||
|
custom:layout_constraintStart_toStartOf="parent"
|
||||||
|
custom:layout_constraintTop_toTopOf="parent"
|
||||||
|
custom:type="solid" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/list_heading"
|
android:id="@+id/list_heading"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|
Loading…
Add table
Reference in a new issue