This commit is contained in:
lunaticbum 2024-08-14 17:40:21 +09:00
parent 4e26fab27c
commit 20a41d27e1
8 changed files with 11356 additions and 40 deletions

View File

@ -19,10 +19,10 @@
package rasel.lunar.launcher.apps
import android.annotation.SuppressLint
import android.content.ContentUris
import android.content.Context
import android.content.Intent
import android.content.SharedPreferences
import android.content.pm.ApplicationInfo
import android.content.pm.PackageManager
import android.content.pm.ResolveInfo
import android.net.Uri
@ -72,7 +72,7 @@ internal class AppDrawer : Fragment() {
private var contactAdapter : ContactAdapter? = null
private var packageInfoList: MutableList<ResolveInfo> = mutableListOf()
private var packageList = mutableListOf<Packages>()
private var oringinPackageList = mutableListOf<Packages>()
// private val numberPattern = Pattern.compile("[0-9]")
// private val alphabetPattern = Pattern.compile("[A-Z]")
@JvmStatic var settingsPrefs: SharedPreferences? = null
@ -91,6 +91,22 @@ internal class AppDrawer : Fragment() {
}
private fun getCategory(category : Int) : String {
return when(category) {
ApplicationInfo.CATEGORY_UNDEFINED -> "UNDEFINED"
ApplicationInfo.CATEGORY_GAME -> "GAME"
ApplicationInfo.CATEGORY_AUDIO -> "AUDIO"
ApplicationInfo.CATEGORY_VIDEO -> "VIDEO"
ApplicationInfo.CATEGORY_IMAGE -> "IMAGE"
ApplicationInfo.CATEGORY_SOCIAL -> "SOCIAL"
ApplicationInfo.CATEGORY_NEWS -> "NEWS"
ApplicationInfo.CATEGORY_MAPS -> "MAPS"
ApplicationInfo.CATEGORY_PRODUCTIVITY -> "PRODUCTIVITY"
ApplicationInfo.CATEGORY_ACCESSIBILITY -> "ACCESSIBILITY"
else -> {"UNKNOWN"}
}
}
}
fun getInputText() = binding.searchInput.text.toString()
@ -127,6 +143,10 @@ internal class AppDrawer : Fragment() {
binding.searchNamuwiki.setOnClickListener {
openSearchApps("https://namu.wiki/Search?q=${getInputText()}")
}
binding.searchTranslate.setOnClickListener {
openSearchApps("https://translate.google.com/?hl=ko&sl=ko&tl=en&text=${getInputText()}&op=translate","com.android.chrome")
}
setLayout()
return binding.root
@ -249,40 +269,62 @@ internal class AppDrawer : Fragment() {
/* update app list with app and package name */
fun fetchApps() {
GlobalScope.launch {
packageInfoList = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager?.queryIntentActivities(
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER),
PackageManager.ResolveInfoFlags.of(0)
)
} else {
(packageManager?.queryIntentActivities(
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0
))
})?.apply {
removeIf { it.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID) }
sortedBy {
appName(it)
}
}!!
/* add package and app names to the list */
if (oringinPackageList.size > 0) {
packageList.clear()
var edit = appNamesPrefs?.edit()
for (resolver in packageInfoList) {
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
for(pkg in oringinPackageList) {
packageList.add(pkg)
}
} else {
packageList.clear()
oringinPackageList.clear()
GlobalScope.launch {
packageInfoList = (if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
packageManager?.queryIntentActivities(
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER),
PackageManager.ResolveInfoFlags.of(0)
)
} else {
(packageManager?.queryIntentActivities(
Intent(Intent.ACTION_MAIN, null).addCategory(Intent.CATEGORY_LAUNCHER), 0
))
})?.apply {
removeIf { it.activityInfo.packageName.equals(BuildConfig.APPLICATION_ID) }
forEach {
oringinPackageList.add(
Packages(
it.activityInfo.packageName,
appName(it),
getCategory(it.activityInfo.applicationInfo.category)
)
)
packageList.add(
Packages(
it.activityInfo.packageName,
appName(it),
getCategory(it.activityInfo.applicationInfo.category)
)
)
}
}!!
}
/* add package and app names to the list */
// var edit = appNamesPrefs?.edit()
// for (resolver in packageInfoList) {
// packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
// }
}
// when {
// packageList.size < 1 -> return
// else -> {
if (packageList.size > 0) {
MainScope().launch {
appsAdapter?.updateData(packageList)
}
if (packageList.size > 0) {
MainScope().launch {
appsAdapter?.updateData(packageList)
}
// }
}
// }
}
private fun getAlphabetItems() {
@ -317,14 +359,10 @@ internal class AppDrawer : Fragment() {
if (lastSearchStringLength > 0 && (lastSearchStringLength != searchString.length || lastSearchString.equals(searchString) == false)) {
BLog.LOGE("START FILTER")
packageList.clear()
for (resolver in packageInfoList) {
appName(resolver).let {
// BLog.LOGE("searchString >>> ${searchString} , normalize(it) ${normalize(it)} ${normalize(it).contains(normalize(searchString), false)}")
if (normalize(it).contains(normalize(searchString), false)) {
packageList.add(Packages(resolver.activityInfo.packageName, it))
} else {
}
for (pkg in oringinPackageList) {
if (pkg.appName.contains(searchString,true) || pkg.category.contains(searchString,true) || pkg.packageName.contains(searchString,true)) {
BLog.LOGE("pkg >>> ${pkg.category} , ${pkg.appName}")
packageList.add(pkg)
}
}
BLog.LOGE("MIDDLE FILTER")
@ -364,8 +402,8 @@ internal class AppDrawer : Fragment() {
contactList.add(item)
}
packageList.clear()
for (resolver in packageInfoList) {
packageList.add(Packages(resolver.activityInfo.packageName, appName(resolver)))
for (resolver in oringinPackageList) {
packageList.add(resolver)
}
appsAdapter?.updateData(packageList)
contactAdapter?.updateData(contactList)

View File

@ -122,9 +122,10 @@ internal class AppsAdapter(
}
}
internal data class Packages (
data class Packages (
val packageName: String,
val appName: String
val appName: String,
val category : String
)
internal class AppsDiffUtil(

View File

@ -38,8 +38,10 @@ import org.xmlpull.v1.XmlPullParserFactory
import rasel.lunar.launcher.LauncherActivity.Companion.lActivity
import rasel.lunar.launcher.helpers.Constants.Companion.DEFAULT_ICON_PACK
import rasel.lunar.launcher.helpers.Constants.Companion.KEY_ICON_PACK
import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_PKGICS
import rasel.lunar.launcher.helpers.Constants.Companion.PREFS_SETTINGS
import rasel.lunar.launcher.utils.BLog
import rasel.lunar.launcher.utils.ImageUtils
import java.io.IOException
import java.util.Locale
@ -50,6 +52,7 @@ internal class IconPackManager {
companion object {
private val settingsPrefs = lActivity!!.getSharedPreferences(PREFS_SETTINGS, 0)
private val icsPrefs = lActivity!!.getSharedPreferences(PREFS_PKGICS,0)
private val packageName = settingsPrefs.getString(KEY_ICON_PACK, DEFAULT_ICON_PACK)
private var loaded = false
private val packagesDrawables = HashMap<String?, String?>()
@ -139,6 +142,11 @@ internal class IconPackManager {
private fun loadBitmap(drawableName: String): Bitmap? {
if (packageName != null && packageName.length > 0) {
var bm = bitmapCache.get(packageName)
GlobalScope.async {
bm?.let { ImageUtils.bitmapToBase64String(it)?.let {
icsPrefs.contains(packageName)
} }
}
if (bm != null) return bm
}
iconPackRes!!.getIdentifier(drawableName, "drawable", packageName).let { id ->
@ -166,6 +174,13 @@ internal class IconPackManager {
fun putAfterReturn(packages: String, drawable : Drawable?) : Drawable? {
if (drawable != null) {
appPackageIconDrawables.put(packages, drawable)
(drawable as? BitmapDrawable)?.let {
if(icsPrefs.contains(packageName)) {
} else {
icsPrefs.edit().putString(packageName, ImageUtils.bitmapToBase64String(it.bitmap)).apply()
}
}
}
return drawable
}

View File

@ -35,6 +35,9 @@ internal class Constants {
const val KEY_WIDGET_IDS = "widget_ids"
const val KEY_WIDGET_HEIGHTS = "widget_heights"
const val PREFS_PKGICS = "rasel.lunar.launcher.Icons"
/* settings */
const val PREFS_SETTINGS = "rasel.lunar.launcher.SETTINGS"
const val KEY_TIME_FORMAT = "time_format"

View File

@ -0,0 +1,34 @@
package rasel.lunar.launcher.utils
import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.graphics.drawable.Icon
import android.util.Base64
import androidx.core.content.pm.ShortcutInfoCompat
import androidx.core.graphics.drawable.IconCompat
import java.io.ByteArrayOutputStream
object ImageUtils {
fun bitmapToBase64String(resource : Bitmap) : String? {
val baos = ByteArrayOutputStream()
resource.compress(Bitmap.CompressFormat.PNG, 100, baos)
val iconArray = baos.toByteArray()
return if (iconArray != null && iconArray.size > 0) {
Base64.encodeToString(iconArray, Base64.DEFAULT)
} else {
null
}
}
fun stringToBitmap(src : String) : Bitmap? {
val iconArray = Base64.decode(src?.toByteArray(), Base64.DEFAULT)
return if (iconArray != null && iconArray.size > 0) {
BitmapFactory.decodeByteArray(iconArray, 0, iconArray.size)
} else {
null
}
}
}

File diff suppressed because it is too large Load Diff

Binary file not shown.

After

Width:  |  Height:  |  Size: 22 KiB

View File

@ -90,6 +90,10 @@
android:src="@drawable/tmap"
style="@style/SearchIcons"
android:id="@+id/search_tmap"/>
<rasel.lunar.launcher.view.CircleImageView
android:src="@drawable/translate"
style="@style/SearchIcons"
android:id="@+id/search_translate"/>
</LinearLayout>
<TextView
android:paddingLeft="15dp"