diff --git a/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt b/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt index f1f35ff4..d2f85c3d 100644 --- a/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt +++ b/app/src/main/java/com/github/droidworksstudio/common/ContextExtensions.kt @@ -31,7 +31,6 @@ import androidx.annotation.DrawableRes import androidx.core.content.ContextCompat import androidx.core.graphics.drawable.IconCompat import androidx.core.graphics.drawable.toBitmap -import androidx.core.os.ConfigurationCompat import androidx.lifecycle.LifecycleObserver import androidx.lifecycle.LifecycleOwner import com.github.droidworksstudio.launcher.data.entities.AppInfo @@ -112,8 +111,6 @@ fun Context.createIconWithResourceCompat( } } -fun Context.currentLanguage() = ConfigurationCompat.getLocales(resources.configuration)[0]?.language - fun Context.openBrowser(url: String, clearFromRecent: Boolean = true) { val browserIntent = Intent(Intent.ACTION_VIEW, Uri.parse(url)) if (clearFromRecent) browserIntent.flags = @@ -182,7 +179,7 @@ fun Context.resetDefaultLauncher() { try { val intent = Intent("android.settings.HOME_SETTINGS") this.startActivity(intent) - } catch (e: ActivityNotFoundException) { + } catch (_: ActivityNotFoundException) { // Fallback to general settings if specific launcher settings are not found try { val intent = Intent(Settings.ACTION_SETTINGS) @@ -266,7 +263,7 @@ fun Context.launchCalendar() { builder.appendPath("time") builder.appendPath(time.toString()) this.startActivity(Intent(Intent.ACTION_VIEW, builder.build())) - } catch (e: Exception) { + } catch (_: Exception) { try { val intent = Intent(this, LauncherActivity::class.java) intent.addCategory(Intent.CATEGORY_APP_CALENDAR) @@ -281,7 +278,7 @@ fun Context.openBatteryManager() { try { val intent = Intent(Intent.ACTION_POWER_USAGE_SUMMARY) this.startActivity(intent) - } catch (e: ActivityNotFoundException) { + } catch (_: ActivityNotFoundException) { // Battery manager settings cannot be opened // Handle this case as needed showLongToast("Battery manager settings are not available on this device.") @@ -375,7 +372,7 @@ fun Context.isPackageInstalled( ): Boolean { val launcher = getSystemService(Context.LAUNCHER_APPS_SERVICE) as LauncherApps val activityInfo = launcher.getActivityList(packageName, userHandle) - return activityInfo.size > 0 + return activityInfo.isNotEmpty() } fun Context.getAppNameFromPackageName(packageName: String): String? { diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/data/AppDatabase.kt b/app/src/main/java/com/github/droidworksstudio/launcher/data/AppDatabase.kt index ee748f08..880761dc 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/data/AppDatabase.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/data/AppDatabase.kt @@ -6,7 +6,7 @@ import androidx.room.RoomDatabase import com.github.droidworksstudio.launcher.data.dao.AppInfoDAO import com.github.droidworksstudio.launcher.data.entities.AppInfo -@Database(entities = [AppInfo::class], version = 1, exportSchema = false) +@Database(entities = [AppInfo::class], version = 1, exportSchema = true) abstract class AppDatabase : RoomDatabase() { abstract fun appDao(): AppInfoDAO } \ No newline at end of file diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/data/dao/AppInfoDAO.kt b/app/src/main/java/com/github/droidworksstudio/launcher/data/dao/AppInfoDAO.kt index 12b1becd..a3f9bc14 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/data/dao/AppInfoDAO.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/data/dao/AppInfoDAO.kt @@ -22,16 +22,12 @@ interface AppInfoDAO { @Insert(onConflict = OnConflictStrategy.REPLACE) suspend fun restoreAll(apps: List) - @Query("DELETE FROM app") suspend fun clearAll() @Query("DELETE FROM sqlite_sequence WHERE name = 'app'") suspend fun resetAutoIncrement() - @Update - suspend fun update(app: AppInfo) - @Delete fun delete(app: AppInfo) @@ -65,21 +61,21 @@ interface AppInfoDAO { @Transaction suspend fun updateAppName(appInfo: AppInfo, newAppName: String) { appInfo.appName = newAppName - update(appInfo) + updateAppInfo(appInfo) logUpdate("App name updated", appInfo) } @Transaction suspend fun updateAppHidden(appInfo: AppInfo, appHidden: Boolean) { appInfo.hidden = appHidden - update(appInfo) + updateAppInfo(appInfo) logUpdate("App hidden status updated", appInfo) } @Transaction suspend fun updateLockApp(appInfo: AppInfo, appLock: Boolean) { appInfo.lock = appLock - update(appInfo) + updateAppInfo(appInfo) logUpdate("App lock status updated", appInfo) } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt b/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt index 13d57544..65ddb121 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/helper/AppHelper.kt @@ -16,6 +16,7 @@ import android.os.Vibrator import android.os.VibratorManager import android.text.SpannableStringBuilder import android.text.style.ImageSpan +import android.util.JsonReader import android.util.Log import android.util.TypedValue import android.view.Gravity @@ -41,6 +42,7 @@ import com.google.gson.reflect.TypeToken import kotlinx.coroutines.flow.first import retrofit2.Retrofit import retrofit2.converter.gson.GsonConverterFactory +import java.io.StringReader import java.net.UnknownHostException import java.text.SimpleDateFormat import java.util.Calendar @@ -384,6 +386,10 @@ class AppHelper @Inject constructor() { // Read the content from the InputStream val jsonString = inputStream.bufferedReader().use { it.readText() } + // Create a JsonReader with lenient parsing + val jsonReader = JsonReader(StringReader(jsonString)) + jsonReader.isLenient = true // Enable lenient mode + // Convert JSON to List val gson = Gson() val type = object : TypeToken>() {}.type diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/repository/AppInfoRepository.kt b/app/src/main/java/com/github/droidworksstudio/launcher/repository/AppInfoRepository.kt index d439c4d0..838e16f5 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/repository/AppInfoRepository.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/repository/AppInfoRepository.kt @@ -44,7 +44,7 @@ class AppInfoRepository @Inject constructor( } suspend fun updateInfo(appInfo: AppInfo) { - appDao.update(appInfo) + appDao.updateAppInfo(appInfo) } suspend fun updateAppOrder(appInfoList: List) { @@ -175,22 +175,8 @@ class AppInfoRepository @Inject constructor( launcherApps.getActivityList(null, profile) .mapNotNull { app -> val packageName = app.applicationInfo.packageName - val currentDateTime = LocalDateTime.now() - if (packageName !in existingPackageNames && packageName !in excludedPackageNames) { - AppInfo( - appName = app.label.toString(), - packageName = packageName, - favorite = false, - hidden = false, - lock = false, - createTime = currentDateTime.toString(), - userHandle = userId, - ) - } else { - val existingApp = getAppByPackageNameWork(packageName) - existingApp?.let { appList.add(it) } - existingApp - } + val existingApp = getAppByPackageNameWork(packageName) + existingApp } } } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/bottomsheetdialog/AppInfoBottomSheetFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/bottomsheetdialog/AppInfoBottomSheetFragment.kt index bc01b855..7d0b1d21 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/bottomsheetdialog/AppInfoBottomSheetFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/bottomsheetdialog/AppInfoBottomSheetFragment.kt @@ -47,20 +47,19 @@ class AppInfoBottomSheetFragment(private val appInfo: AppInfo) : BottomSheetDial private var appStateClickListener: OnItemClickedListener.OnAppStateClickListener? = null - fun setOnAppStateClickListener(listener: OnItemClickedListener.OnAppStateClickListener) { appStateClickListener = listener } override fun onCreateView( inflater: LayoutInflater, container: ViewGroup?, - savedInstanceState: Bundle? + savedInstanceState: Bundle?, ): View { _binding = BottomsheetDialogBinding.inflate(inflater, container, false) return binding.root } - @RequiresApi(Build.VERSION_CODES.O) + @RequiresApi(Build.VERSION_CODES.R) override fun onViewCreated(view: View, savedInstanceState: Bundle?) { super.onViewCreated(view, savedInstanceState) @@ -89,13 +88,21 @@ class AppInfoBottomSheetFragment(private val appInfo: AppInfo) : BottomSheetDial } - @RequiresApi(Build.VERSION_CODES.O) + + @RequiresApi(Build.VERSION_CODES.R) private fun observeClickListener() { val packageName = appInfo.packageName + var appName = appInfo.packageName - val packageManager = context?.packageManager - val applicationInfo = packageManager?.getApplicationInfo(packageName, 0) - val appName = applicationInfo?.let { packageManager.getApplicationLabel(it).toString() } + try { + // Get the context's PackageManager + val packageManager = context?.packageManager + + val applicationInfo = packageManager?.getApplicationInfo(packageName, 0) + appName = applicationInfo?.let { packageManager.getApplicationLabel(it).toString() }.toString() + } catch (e: Exception) { + e.printStackTrace() + } binding.apply { bottomSheetFavHidden.setOnClickListener { @@ -135,7 +142,7 @@ class AppInfoBottomSheetFragment(private val appInfo: AppInfo) : BottomSheetDial ) ) binding.bottomSheetRename.hint = appName - appInfo.appName = appName ?: "" + appInfo.appName = appName } else { appInfo.appName = s.toString() } diff --git a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt index f0190e81..2b41e7d3 100644 --- a/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt +++ b/app/src/main/java/com/github/droidworksstudio/launcher/ui/drawer/DrawFragment.kt @@ -348,8 +348,6 @@ class DrawFragment : Fragment(), } private fun showSelectedApp(appInfo: AppInfo) { - binding.searchViewText.setQuery("", false) - val bottomSheetFragment = AppInfoBottomSheetFragment(appInfo) bottomSheetFragment.setOnAppStateClickListener(this) bottomSheetFragment.show(parentFragmentManager, "BottomSheetDialog")