Skip to content

Commit

Permalink
Refactor app drawer folder preferences
Browse files Browse the repository at this point in the history
  • Loading branch information
SuperDragonXD committed Feb 15, 2025
1 parent 987b478 commit d42fad3
Show file tree
Hide file tree
Showing 8 changed files with 464 additions and 646 deletions.
28 changes: 1 addition & 27 deletions lawnchair/src/app/lawnchair/data/folder/model/FolderViewModel.kt
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package app.lawnchair.data.folder.model

import android.content.Context
import android.util.Log
import androidx.lifecycle.LiveData
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import androidx.lifecycle.viewModelScope
import app.lawnchair.data.folder.service.FolderService
import app.lawnchair.ui.preferences.destinations.Action
import com.android.launcher3.R
import com.android.launcher3.model.data.AppInfo
import com.android.launcher3.model.data.FolderInfo
import kotlinx.coroutines.flow.MutableStateFlow
Expand All @@ -25,12 +22,6 @@ class FolderViewModel(context: Context) : ViewModel() {
private val _folders = MutableStateFlow<List<FolderInfo>>(emptyList())
val folders: StateFlow<List<FolderInfo>> = _folders.asStateFlow()

private val _currentTitle = MutableStateFlow(context.resources.getString(R.string.my_folder_label))
val currentTitle: StateFlow<String> = _currentTitle.asStateFlow()

private val _action = MutableStateFlow(Action.DEFAULT)
val action: StateFlow<Action> = _action.asStateFlow()

private val _foldersMutable = MutableLiveData<List<FolderInfo>>()
val foldersMutable: LiveData<List<FolderInfo>> = _foldersMutable

Expand All @@ -39,7 +30,6 @@ class FolderViewModel(context: Context) : ViewModel() {

private val _folderInfo = MutableStateFlow<FolderInfo?>(null)
val folderInfo = _folderInfo.asStateFlow()
private var tempTitle: String = ""

private val mutex = Mutex()

Expand All @@ -51,13 +41,6 @@ class FolderViewModel(context: Context) : ViewModel() {
}
}

fun setAction(newAction: Action) {
if (_action.value != newAction) {
Log.d("FolderPreferences", "Transitioning action from ${action.value} to $newAction")
_action.value = newAction
}
}

fun refreshFolders() {
viewModelScope.launch {
mutex.withLock {
Expand All @@ -73,15 +56,6 @@ class FolderViewModel(context: Context) : ViewModel() {
}
}

fun updateCurrentTitle(title: String) {
if (action.value == Action.EDIT) {
tempTitle = title
_currentTitle.value = title
} else if (action.value != Action.SETTLE) {
_currentTitle.value = title
}
}

fun setFolderInfo(folderInfoId: Int, hasId: Boolean) {
viewModelScope.launch {
_folderInfo.value = repository.getFolderInfo(folderInfoId, hasId)
Expand Down Expand Up @@ -115,7 +89,7 @@ class FolderViewModel(context: Context) : ViewModel() {
}
}

suspend fun loadFolders() {
private suspend fun loadFolders() {
val folders = repository.getAllFolders()
_folders.value = folders
_foldersMutable.postValue(folders)
Expand Down

This file was deleted.

Loading

0 comments on commit d42fad3

Please sign in to comment.