This repository was archived by the owner on Aug 22, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 105
Refactor UI components #135
Draft
X1nto
wants to merge
5
commits into
master
Choose a base branch
from
refactor/presentation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 13 additions & 7 deletions
20
app/src/main/java/com/xinto/opencord/di/ViewModelModule.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,17 +1,23 @@ | ||
| package com.xinto.opencord.di | ||
|
|
||
| import com.xinto.opencord.ui.viewmodel.* | ||
| import com.xinto.opencord.ui.screens.home.panels.channel.HomeChannelsPanelViewModel | ||
| import com.xinto.opencord.ui.screens.home.panels.chat.HomeChatPanelViewModel | ||
| import com.xinto.opencord.ui.screens.home.panels.guild.GuildsViewModel | ||
| import com.xinto.opencord.ui.screens.home.panels.messagemenu.HomeMessageMenuPanelViewModel | ||
| import com.xinto.opencord.ui.screens.home.panels.user.HomeUserPanelViewModel | ||
| import com.xinto.opencord.ui.screens.login.LoginViewModel | ||
| import com.xinto.opencord.ui.screens.mentions.MentionsViewModel | ||
| import com.xinto.opencord.ui.screens.pins.PinsScreenViewModel | ||
| import org.koin.androidx.viewmodel.dsl.viewModelOf | ||
| import org.koin.dsl.module | ||
|
|
||
| val viewModelModule = module { | ||
| viewModelOf(::LoginViewModel) | ||
| viewModelOf(::ChatViewModel) | ||
| viewModelOf(::HomeChatPanelViewModel) | ||
| viewModelOf(::GuildsViewModel) | ||
| viewModelOf(::ChannelsViewModel) | ||
| viewModelOf(::ChannelPinsViewModel) | ||
| viewModelOf(::CurrentUserViewModel) | ||
| viewModelOf(::MessageMenuViewModel) | ||
| viewModelOf(::HomeChannelsPanelViewModel) | ||
| viewModelOf(::PinsScreenViewModel) | ||
| viewModelOf(::HomeUserPanelViewModel) | ||
| viewModelOf(::HomeMessageMenuPanelViewModel) | ||
| viewModelOf(::MentionsViewModel) | ||
| viewModelOf(::ChatInputViewModel) | ||
| } |
95 changes: 95 additions & 0 deletions
95
app/src/main/java/com/xinto/opencord/store/PersistentDataStore.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,95 @@ | ||
| package com.xinto.opencord.store | ||
|
|
||
| import android.content.Context | ||
| import androidx.datastore.preferences.core.edit | ||
| import androidx.datastore.preferences.core.longPreferencesKey | ||
| import androidx.datastore.preferences.core.stringSetPreferencesKey | ||
| import androidx.datastore.preferences.preferencesDataStore | ||
| import kotlinx.coroutines.flow.Flow | ||
| import kotlinx.coroutines.flow.map | ||
|
|
||
| interface PersistentDataStore { | ||
|
|
||
| fun observeCurrentGuild(): Flow<Long> | ||
| fun observeCurrentChannel(): Flow<Long> | ||
| fun observeCollapsedCategories(): Flow<List<Long>> | ||
|
|
||
| suspend fun updateCurrentGuild(guildId: Long) | ||
| suspend fun updateCurrentChannel(channelId: Long) | ||
| suspend fun toggleCategory(categoryId: Long) | ||
| suspend fun collapseCategory(categoryId: Long) | ||
| suspend fun expandCategory(categoryId: Long) | ||
|
|
||
| } | ||
|
|
||
| class PersistentDataStoreImpl( | ||
| private val context: Context | ||
| ) : PersistentDataStore { | ||
|
|
||
| private val Context.dataStore by preferencesDataStore("persistent") | ||
|
|
||
| override fun observeCurrentGuild(): Flow<Long> { | ||
| return context.dataStore.data.map { preferences -> | ||
| preferences[CURRENT_GUILD_KEY] ?: 0L | ||
| } | ||
| } | ||
|
|
||
| override fun observeCurrentChannel(): Flow<Long> { | ||
| return context.dataStore.data.map { preferences -> | ||
| preferences[CURRENT_CHANNEL_KEY] ?: 0L | ||
| } | ||
| } | ||
|
|
||
| override fun observeCollapsedCategories(): Flow<List<Long>> { | ||
| return context.dataStore.data.map { preferences -> | ||
| (preferences[COLLAPSED_CATEGORIES_KEY] ?: emptySet()).mapNotNull { | ||
| it.toLongOrNull() | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override suspend fun updateCurrentGuild(guildId: Long) { | ||
| context.dataStore.edit { preferences -> | ||
| preferences[CURRENT_GUILD_KEY] = guildId | ||
| } | ||
| } | ||
|
|
||
| override suspend fun updateCurrentChannel(channelId: Long) { | ||
| context.dataStore.edit { preferences -> | ||
| preferences[CURRENT_CHANNEL_KEY] = channelId | ||
| } | ||
| } | ||
|
|
||
| override suspend fun toggleCategory(categoryId: Long) { | ||
| context.dataStore.edit { preferences -> | ||
| val current = preferences[COLLAPSED_CATEGORIES_KEY] ?: emptySet() | ||
| val stringCategoryId = categoryId.toString() | ||
| if (current.contains(stringCategoryId)) { | ||
| preferences[COLLAPSED_CATEGORIES_KEY] = current - stringCategoryId | ||
| } else { | ||
| preferences[COLLAPSED_CATEGORIES_KEY] = current + stringCategoryId | ||
| } | ||
| } | ||
| } | ||
|
|
||
| override suspend fun expandCategory(categoryId: Long) { | ||
| context.dataStore.edit { preferences -> | ||
| val current = preferences[COLLAPSED_CATEGORIES_KEY] ?: emptySet() | ||
| preferences[COLLAPSED_CATEGORIES_KEY] = current - categoryId.toString() | ||
| } | ||
| } | ||
|
|
||
| override suspend fun collapseCategory(categoryId: Long) { | ||
| context.dataStore.edit { preferences -> | ||
| val current = preferences[COLLAPSED_CATEGORIES_KEY] ?: emptySet() | ||
| preferences[COLLAPSED_CATEGORIES_KEY] = current + categoryId.toString() | ||
| } | ||
| } | ||
|
|
||
| private companion object { | ||
| val CURRENT_GUILD_KEY = longPreferencesKey("CURRENT_GULD") | ||
| val CURRENT_CHANNEL_KEY = longPreferencesKey("CURRENT_CHANNEL") | ||
| val COLLAPSED_CATEGORIES_KEY = stringSetPreferencesKey("COLLAPSED_CATEGORIES") | ||
| } | ||
|
|
||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.