Skip to content

Commit

Permalink
pre-alpha 5.0.1
Browse files Browse the repository at this point in the history
  • Loading branch information
queuejw committed Jun 26, 2024
1 parent f391179 commit 192a378
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
48 changes: 31 additions & 17 deletions app/src/main/java/ru/dimon6018/metrolauncher/Main.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.WindowManager
import android.view.inputmethod.EditorInfo
import android.widget.AutoCompleteTextView
import android.widget.FrameLayout
import android.widget.ImageView
import android.widget.LinearLayout
import android.widget.TextView.OnEditorActionListener
import androidx.activity.OnBackPressedCallback
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.app.AppCompatDelegate
Expand Down Expand Up @@ -87,6 +89,7 @@ class Main : AppCompatActivity() {
private var appList: MutableList<App>? = null
private val hashCache = ArrayMap<String, Icon?>()
private var searchAdapter: SearchAdapter? = null
private var filteredList: ArrayList<App>? = null

private val packageReceiver = PackageChangesReceiver()

Expand Down Expand Up @@ -302,14 +305,25 @@ class Main : AppCompatActivity() {
layoutManager = LinearLayoutManager(this@Main, LinearLayoutManager.VERTICAL, false)
adapter = searchAdapter
}
(bottomViewSearchBar!!.editText as? AutoCompleteTextView)?.addTextChangedListener(object :
val text = (bottomViewSearchBar!!.editText as? AutoCompleteTextView)
text?.addTextChangedListener(object :
TextWatcher {
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
filterSearchText(s.toString())
}
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
override fun afterTextChanged(s: Editable) {}
})
text?.setOnEditorActionListener(OnEditorActionListener { _, actionId, _ ->
if (actionId == EditorInfo.IME_ACTION_GO) {
if(filteredList != null) {
runApp( filteredList!![0].appPackage!!)
hideSearchResults()
}
return@OnEditorActionListener true
}
false
})
}
}
private fun hideSearchResults() {
Expand Down Expand Up @@ -352,7 +366,7 @@ class Main : AppCompatActivity() {
if(appList == null) {
return
}
val filteredList: ArrayList<App> = ArrayList()
filteredList = ArrayList()
val locale = Locale.getDefault()
if(text.isEmpty()) {
hideSearchResults()
Expand All @@ -363,14 +377,14 @@ class Main : AppCompatActivity() {
for(i in 0..<appList!!.size) {
val item = appList!![i]
if (item.appLabel!!.lowercase(locale).contains(text.lowercase(locale))) {
if(filteredList.size >= max) {
if(filteredList!!.size >= max) {
break
}
filteredList.add(item)
filteredList!!.add(item)
}
}
if (filteredList.isNotEmpty()) {
searchAdapter?.setData(filteredList)
if (filteredList!!.isNotEmpty()) {
searchAdapter?.setData(filteredList!!)
}
}
private fun setAppTheme() {
Expand All @@ -395,6 +409,17 @@ class Main : AppCompatActivity() {
super.onDestroy()
unregisterPackageReceiver(this, packageReceiver)
}
private fun runApp(app: String) {
isAppOpened = true
when (app) {
"ru.dimon6018.metrolauncher" -> {
startActivity(Intent(this@Main, SettingsActivity::class.java))
}
else -> {
startActivity(Intent(this@Main.packageManager.getLaunchIntentForPackage(app)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
}
}
}
companion object {
var isLandscape: Boolean = false
}
Expand Down Expand Up @@ -453,16 +478,5 @@ class Main : AppCompatActivity() {
}
}
}
private fun runApp(app: String) {
isAppOpened = true
when (app) {
"ru.dimon6018.metrolauncher" -> {
startActivity(Intent(this@Main, SettingsActivity::class.java))
}
else -> {
startActivity(Intent(this@Main.packageManager.getLaunchIntentForPackage(app)).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK))
}
}
}
}
}
1 change: 1 addition & 0 deletions app/src/main/res/layout/main_screen_laucnher.xml
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@
android:layout_height="match_parent"
android:fontFamily="@font/roboto_regular"
android:inputType="text"
android:imeOptions="actionGo"
android:paddingStart="8dp"
android:paddingEnd="8dp"
android:textColor="?attr/colorOnBackground"
Expand Down

0 comments on commit 192a378

Please sign in to comment.