To improve the CLauncher application, we can focus on code optimization, user experience, and maintainability. Here's a breakdown of the areas for improvement:
1. Code Quality Enhancements
A. Reduce Redundancy
Many methods and functionalities are repeated across classes. For example:
populateHomeScreen in HomeFragment has repetitive code to set visibility for home app slots. This can be refactored into a loop:
private fun populateHomeScreen(appCountUpdated: Boolean) {
if (appCountUpdated) hideHomeApps()
populateDateTime()
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q)
populateScreenTime()
val homeApps = listOf(
binding.homeApp1 to prefs.appName1,
binding.homeApp2 to prefs.appName2,
binding.homeApp3 to prefs.appName3,
binding.homeApp4 to prefs.appName4,
binding.homeApp5 to prefs.appName5,
binding.homeApp6 to prefs.appName6,
binding.homeApp7 to prefs.appName7,
binding.homeApp8 to prefs.appName8
)
homeApps.forEachIndexed { index, (appView, appName) ->
appView.visibility = if (index < prefs.homeAppsNum) View.VISIBLE else View.GONE
appView.text = if (isPackageInstalled(requireContext(), prefs.getAppPackage(index + 1), prefs.getAppUser(index + 1))) {
appName
} else {
prefs.clearAppPrefs(index + 1)
""
}
}
}
B. Encapsulate Repetitive Logic
Move shared logic to helper functions or Prefs. For example:
Prefs can include methods like:
fun getAppPackage(index: Int): String = when (index) {
1 -> appPackage1
2 -> appPackage2
3 -> appPackage3
else -> ""
}
fun clearAppPrefs(index: Int) {
when (index) {
1 -> { appName1 = ""; appPackage1 = "" }
2 -> { appName2 = ""; appPackage2 = "" }
...
}
}
C. Use Sealed Classes for State Management
- Replace
MutableLiveData with a sealed class to better represent view states. This change improves error handling and debugging:
sealed class ViewState<out T> {
object Loading : ViewState<Nothing>()
data class Success<T>(val data: T) : ViewState<T>()
data class Error(val message: String) : ViewState<Nothing>()
}
private val _viewState = MutableLiveData<ViewState<List<AppModel>>>()
val viewState: LiveData<ViewState<List<AppModel>>> = _viewState
2. User Experience (UX) Improvements
A. Dynamic Search Bar
- Add a search bar to filter apps dynamically in the
HomeFragment or SettingsFragment. For example:
private fun setupSearch() {
binding.searchBar.addTextChangedListener { query ->
val filteredApps = appList.value?.filter {
it.appLabel.contains(query.toString(), ignoreCase = true)
}
updateAppList(filteredApps ?: emptyList())
}
}
B. Onboarding for New Users
- Add a one-time onboarding dialog for first-time users (instead of just showing the
firstRunTips text). Example:
private fun showOnboardingDialog() {
AlertDialog.Builder(requireContext())
.setTitle(getString(R.string.welcome))
.setMessage(getString(R.string.onboarding_message))
.setPositiveButton(getString(R.string.okay)) { dialog, _ -> dialog.dismiss() }
.show()
}
C. Improved Feedback for User Actions
- Add snackbars for actions like "App Hidden", "Launcher Set", or "Wallpaper Set" instead of using simple toasts.
Snackbar.make(binding.root, "Wallpaper Set Successfully", Snackbar.LENGTH_SHORT).show()
D. Settings Fragment: Group Related Preferences
- The
SettingsFragment has many unrelated options displayed together. Use categories or collapsible sections for grouping:
- Home Screen Settings
- Appearance
- Gestures
- About
This can be done using ExpandableListView or NavigationView.
E. Add Support for Widgets
- Allow users to add widgets on the home screen for more customization. Example:
val appWidgetManager = AppWidgetManager.getInstance(context)
val appWidgetHost = AppWidgetHost(context, APP_WIDGET_HOST_ID)
val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_PICK)
startActivityForResult(intent, REQUEST_PICK_APPWIDGET)
3. Performance Optimization
A. Optimize App List Fetching
- The
getAppsList method fetches all apps on every call, which could be resource-intensive. Implement caching to avoid redundant calls:
private var cachedAppList: List<AppModel>? = null
fun getAppList(includeHiddenApps: Boolean): List<AppModel> {
if (cachedAppList == null) {
cachedAppList = fetchAppListFromSystem(includeHiddenApps)
}
return cachedAppList!!
}
B. Use ViewBinding Instead of findViewById
- Replace
findViewById with ViewBinding in layouts like HomeFragment and SettingsFragment. This reduces boilerplate and improves performance.
C. Debounce User Input
- Add debouncing for input events like search field updates or swipe gestures to avoid overloading the app with frequent calls.
private val debounceJob = Job()
private val coroutineScope = CoroutineScope(Dispatchers.Main + debounceJob)
fun debounce(action: () -> Unit, delayMs: Long = 300) {
debounceJob.cancel()
coroutineScope.launch {
delay(delayMs)
action()
}
}
4. Maintainability Improvements
A. Use Dependency Injection
- Introduce a dependency injection framework like Hilt or Koin for managing dependencies (
Prefs, ViewModel, etc.) instead of manually initializing them.
B. Improve Constants Management
- The
[Redacted Person] object has many unrelated values. Group them into separate objects for better clarity:
object SwipeActions {
const val NOTIFICATIONS = 1
const val SEARCH = 2
}
object DateTimeVisibility {
const val ON = 1
const val OFF = 0
const val DATE_ONLY = 2
}
5. New Features
A. Dark Mode Customization
- Allow users to set custom dark mode schedules instead of relying on the system's default setting.
prefs.darkModeStartTime = "22:00"
prefs.darkModeEndTime = "06:00"
B. Backup and Restore Settings
- Add an option to export/import user settings (e.g., home apps, themes, gestures). Example:
fun exportSettings(context: Context) {
val settingsJson = JSONObject()
settingsJson.put("homeAppsNum", prefs.homeAppsNum)
settingsJson.put("theme", prefs.appTheme)
// Save to file or cloud storage
}
C. Custom Gestures
- Allow users to assign gestures to specific actions (e.g., swipe down to open settings).
6. Bugs to Fix
A. Handling Screen Orientation
- In
MainActivity, setupOrientation() forces portrait mode for non-tablet devices. Add an option for users to choose their preferred orientation.
B. Crash on Missing Permissions
- Add permission checks in methods like
getUsageStats to avoid crashes when permissions are not granted.
if (!hasUsageStatsPermission(context)) {
_viewState.postValue(ViewState.Error("Usage stats permission required"))
return
}
7. Documentation
A. Project Documentation
- Improve the README.md with:
- A feature list.
- Screenshots or GIFs of the launcher in action.
- Contribution guidelines for open-source contributors.
B. Code Comments
- Add meaningful comments to complex methods like
getAppsList and populateHomeScreen.
Final Notes:
- These improvements will enhance code readability, performance, and user satisfaction.
- Start by prioritizing critical fixes (e.g., crashes) and UX improvements (e.g., onboarding) before implementing new features like widgets or backup settings.