Refactor: Cleaned up some unneeded code.
This commit is contained in:
@@ -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? {
|
||||
|
||||
@@ -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
|
||||
}
|
||||
@@ -22,16 +22,12 @@ interface AppInfoDAO {
|
||||
@Insert(onConflict = OnConflictStrategy.REPLACE)
|
||||
suspend fun restoreAll(apps: List<AppInfo>)
|
||||
|
||||
|
||||
@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)
|
||||
}
|
||||
|
||||
|
||||
@@ -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<AppInfo>
|
||||
val gson = Gson()
|
||||
val type = object : TypeToken<List<AppInfo>>() {}.type
|
||||
|
||||
@@ -44,7 +44,7 @@ class AppInfoRepository @Inject constructor(
|
||||
}
|
||||
|
||||
suspend fun updateInfo(appInfo: AppInfo) {
|
||||
appDao.update(appInfo)
|
||||
appDao.updateAppInfo(appInfo)
|
||||
}
|
||||
|
||||
suspend fun updateAppOrder(appInfoList: List<AppInfo>) {
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
}
|
||||
|
||||
@@ -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")
|
||||
|
||||
Reference in New Issue
Block a user