mirror of
				https://github.com/mihonapp/mihon.git
				synced 2025-10-31 14:27:57 +01:00 
			
		
		
		
	Add button to reorder categories alphabetically (#9369)
Closes #6459 Co-authored-by: arkon <arkon@users.noreply.github.com>
This commit is contained in:
		| @@ -55,6 +55,27 @@ class ReorderCategory( | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     suspend fun sortAlphabetically() = withNonCancellableContext { | ||||
|         mutex.withLock { | ||||
|             val updates = categoryRepository.getAll() | ||||
|                 .sortedBy { category -> category.name } | ||||
|                 .mapIndexed { index, category -> | ||||
|                     CategoryUpdate( | ||||
|                         id = category.id, | ||||
|                         order = index.toLong(), | ||||
|                     ) | ||||
|                 } | ||||
|  | ||||
|             try { | ||||
|                 categoryRepository.updatePartial(updates) | ||||
|                 Result.Success | ||||
|             } catch (e: Exception) { | ||||
|                 logcat(LogPriority.ERROR, e) | ||||
|                 Result.InternalError(e) | ||||
|             } | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     sealed interface Result { | ||||
|         data object Success : Result | ||||
|         data object Unchanged : Result | ||||
|   | ||||
		Reference in New Issue
	
	Block a user