Skip to content

Commit

Permalink
Few more improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
iamrasel committed Mar 12, 2024
1 parent 165e0bb commit a8a1d28
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 45 deletions.
29 changes: 13 additions & 16 deletions app/src/main/kotlin/rasel/lunar/launcher/apps/AppDrawer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -80,25 +80,28 @@ internal class AppDrawer : Fragment() {
@JvmStatic var alphabetList = mutableListOf<String>()
@JvmStatic var letterPreview: MaterialTextView? = null

private fun appName(resolver: ResolveInfo): String {
return appNamesPrefs?.getString(resolver.activityInfo.packageName, resolver.loadLabel(packageManager).toString())!!
}

fun listenScroll(letter: String) {
packageList.clear()
for (resolver in packageInfoList) {
val appName = appNamesPrefs?.getString(resolver.activityInfo.packageName, resolver.loadLabel(packageManager).toString())!!
when {
letter == "#" -> {
if (numberPattern.matcher(appName.first().uppercase()).matches()) {
packageList.add(Packages(resolver.activityInfo.packageName, appName))
if (numberPattern.matcher(appName(resolver).first().uppercase()).matches()) {
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
}
}
alphabetPattern.matcher(letter).matches() -> {
if (appName.first().uppercase() == letter) {
packageList.add(Packages(resolver.activityInfo.packageName, appName))
if (appName(resolver).first().uppercase() == letter) {
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
}
}
letter == "" -> {
if (!numberPattern.matcher(appName.first().uppercase()).matches() &&
!alphabetPattern.matcher(appName.first().uppercase()).matches()) {
packageList.add(Packages(resolver.activityInfo.packageName, appName))
if (!numberPattern.matcher(appName(resolver).first().uppercase()).matches() &&
!alphabetPattern.matcher(appName(resolver).first().uppercase()).matches()) {
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
}
}
}
Expand Down Expand Up @@ -195,7 +198,6 @@ internal class AppDrawer : Fragment() {
PackageManager.ResolveInfoFlags.of(0)
)
} else {
@Suppress("DEPRECATION")
(packageManager?.queryIntentActivities(
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0))
})?.apply {
Expand All @@ -206,10 +208,7 @@ internal class AppDrawer : Fragment() {
/* add package and app names to the list */
packageList.clear()
for (resolver in packageInfoList) {
packageList.add(Packages(
resolver.activityInfo.packageName, appNamesPrefs?.getString(resolver.activityInfo.packageName,
resolver.loadLabel(packageManager).toString())!!
))
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
}

when {
Expand Down Expand Up @@ -247,9 +246,7 @@ internal class AppDrawer : Fragment() {
/* check each app name and add if it matches the search string */
packageList.clear()
for (resolver in packageInfoList) {
val appName = appNamesPrefs?.getString(resolver.activityInfo.packageName, resolver.loadLabel(packageManager).toString())!!

appName.let {
appName(resolver).let {
if (normalize(it).contains(searchString)) {
packageList.add(Packages(resolver.activityInfo.packageName, it))
}
Expand Down
37 changes: 18 additions & 19 deletions app/src/main/kotlin/rasel/lunar/launcher/apps/AppMenu.kt
Original file line number Diff line number Diff line change
Expand Up @@ -88,17 +88,19 @@ internal class AppMenu : BottomSheetDialogFragment() {
packageManager.getApplicationInfo(packageName,
PackageManager.ApplicationInfoFlags.of(PackageManager.GET_META_DATA.toLong()))
} else {
@Suppress("DEPRECATION")
packageManager.getApplicationInfo(packageName, PackageManager.GET_META_DATA)
}

/* get default app name */
val resolve = packageManager.resolveActivity(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER).setPackage(packageName), 0)
defAppName = resolve?.loadLabel(packageManager).toString()
defAppName = packageManager.resolveActivity(Intent(Intent.ACTION_MAIN).addCategory(Intent.CATEGORY_LAUNCHER)
.setPackage(packageName), 0)?.loadLabel(packageManager).toString()

/* set application name and package name */
binding.appName.setText(appNamesPrefs?.getString(packageName, defAppName))
binding.appName.hint = defAppName
binding.appName.apply {
setText(appNamesPrefs?.getString(packageName, defAppName))
hint = defAppName

}
binding.appPackage.text = packageName
/* favorite apps */
favoriteApps()
Expand Down Expand Up @@ -146,7 +148,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU)
packageManager.getPackageInfo(savedPackageName!!, PackageManager.PackageInfoFlags.of(0))
else
@Suppress("DEPRECATION") packageManager.getPackageInfo(savedPackageName!!, 0)
packageManager.getPackageInfo(savedPackageName!!, 0)
} catch (e: PackageManager.NameNotFoundException) {
requireContext().getSharedPreferences(PREFS_FAVORITE_APPS, 0)
.edit().remove(KEY_APP_NO_ + position).apply()
Expand Down Expand Up @@ -176,18 +178,16 @@ internal class AppMenu : BottomSheetDialogFragment() {
}
}

private fun appName()
{
private fun appName() {
binding.appName.setOnFocusChangeListener { _, hasFocus ->
if (hasFocus) {
binding.appName.minWidth = resources.getDimensionPixelOffset(R.dimen.twoSeventySix)
}
if (hasFocus) binding.appName.minWidth = resources.getDimensionPixelOffset(R.dimen.twoSeventySix)
else {
val imm = requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager
imm.hideSoftInputFromWindow(binding.appName.windowToken, 0)
(requireContext().getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager)
.hideSoftInputFromWindow(binding.appName.windowToken, 0)

binding.appName.minWidth = resources.getDimensionPixelOffset(R.dimen.zero)
binding.appName.apply {
minWidth = resources.getDimensionPixelOffset(R.dimen.zero)

if (text!!.isBlank()) setText(defAppName)
else setText(text!!.trim())

Expand All @@ -200,8 +200,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
}

binding.appName.setOnKeyListener { _, keyCode, event ->
if (event.action == KeyEvent.ACTION_DOWN)
{
if (event.action == KeyEvent.ACTION_DOWN) {
if (keyCode == KeyEvent.KEYCODE_ENTER || keyCode == KeyEvent.KEYCODE_BACK) {
binding.appName.clearFocus()
return@setOnKeyListener true
Expand All @@ -227,7 +226,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(0))
} else {
@Suppress("DEPRECATION") packageManager.getPackageInfo(packageName, 0)
packageManager.getPackageInfo(packageName, 0)
}

/* show infos */
Expand Down Expand Up @@ -259,7 +258,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_ACTIVITIES.toLong())
)
} else {
@Suppress("DEPRECATION") packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
packageManager.getPackageInfo(packageName, PackageManager.GET_ACTIVITIES)
}

/* show activity list */
Expand Down Expand Up @@ -398,7 +397,7 @@ internal class AppMenu : BottomSheetDialogFragment() {
val packageInfo = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager.getPackageInfo(packageName, PackageManager.PackageInfoFlags.of(PackageManager.GET_PERMISSIONS.toLong()))
} else {
@Suppress("DEPRECATION") packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)
packageManager.getPackageInfo(packageName, PackageManager.GET_PERMISSIONS)
}

return if (packageInfo.requestedPermissions.isNotEmpty()) {
Expand Down
9 changes: 2 additions & 7 deletions app/src/main/kotlin/rasel/lunar/launcher/apps/AppsAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.core.view.updatePadding
import androidx.fragment.app.DialogFragment
import androidx.fragment.app.FragmentManager
import androidx.recyclerview.widget.DiffUtil
import androidx.recyclerview.widget.RecyclerView
Expand Down Expand Up @@ -104,10 +103,7 @@ internal class AppsAdapter(

/* on long click - open app menu */
setOnLongClickListener {
AppMenu().let {
it.setStyle(DialogFragment.STYLE_NORMAL, R.style.BottomSheetDialog)
it.show(fragmentManager, item.packageName)
}
AppMenu().show(fragmentManager, item.packageName)
true
}
}
Expand All @@ -119,8 +115,7 @@ internal class AppsAdapter(

/* update app list */
fun updateData(newList: List<Packages>) {
val diffUtil = AppsDiffUtil(oldList, newList)
val diffUtilResult = DiffUtil.calculateDiff(diffUtil)
val diffUtilResult = DiffUtil.calculateDiff(AppsDiffUtil(oldList, newList))

oldList.clear()
oldList.addAll(newList)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,6 @@ internal class UniUtils {
/* favorite apps */
private fun populateFavApps(context: Context, linearLayoutCompat: LinearLayoutCompat) {
val prefsFavApps = context.getSharedPreferences(PREFS_FAVORITE_APPS, 0)
val useIconPack = context.getSharedPreferences(PREFS_SETTINGS, 0).getInt(KEY_APPS_LAYOUT, 0) != 0
if (linearLayoutCompat.isVisible || prefsFavApps.all.toString().length < 3) {
linearLayoutCompat.visibility = View.GONE
} else {
Expand Down
2 changes: 0 additions & 2 deletions app/src/main/res/layout/app_menu.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
android:minWidth="@dimen/zero"
android:gravity="center"
android:padding="@dimen/eight"
android:inputType="textNoSuggestions"
android:textAppearance="@style/TextAppearance.Material3.TitleLarge" />

</com.google.android.material.textfield.TextInputLayout>

<com.google.android.material.button.MaterialButton
Expand Down

0 comments on commit a8a1d28

Please sign in to comment.