Skip to content

Commit

Permalink
WIP Migrating away from StoreBox to DataStore
Browse files Browse the repository at this point in the history
- Added DataStore dependency
- Created AppPreferencesImpl

Signed-off-by: Julius Linus <[email protected]>
  • Loading branch information
rapterjet2004 committed Sep 5, 2023
1 parent 4ca0620 commit 433c2f9
Show file tree
Hide file tree
Showing 6 changed files with 678 additions and 387 deletions.
2 changes: 2 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,7 @@ configurations.all {

dependencies {
implementation 'androidx.preference:preference-ktx:1.2.1'
implementation 'androidx.datastore:datastore-core:1.0.0'
detektPlugins("io.gitlab.arturbosch.detekt:detekt-formatting:1.23.1")

implementation fileTree(include: ['*'], dir: 'libs')
Expand Down Expand Up @@ -282,6 +283,7 @@ dependencies {
//noinspection DuplicatePlatformClasses
exclude group: 'org.apache.httpcomponents', module: 'httpclient'
})
implementation("androidx.datastore:datastore-preferences:1.0.0")

implementation 'androidx.core:core-ktx:1.10.1'

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@

import com.nextcloud.talk.data.source.local.TalkDatabase;
import com.nextcloud.talk.utils.preferences.AppPreferences;

import net.orange_box.storebox.StoreBox;
import com.nextcloud.talk.utils.preferences.AppPreferencesImpl;

import javax.inject.Singleton;

Expand All @@ -39,7 +38,7 @@ public class DatabaseModule {
@Provides
@Singleton
public AppPreferences providePreferences(@NonNull final Context poContext) {
AppPreferences preferences = StoreBox.create(poContext, AppPreferences.class);
AppPreferences preferences = new AppPreferencesImpl(poContext);
preferences.removeLinkPreviews();
return preferences;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import io.reactivex.Observer
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.disposables.Disposable
import io.reactivex.schedulers.Schedulers
import net.orange_box.storebox.listeners.OnPreferenceValueChangedListener
import java.io.File
import javax.inject.Inject

Expand Down Expand Up @@ -66,7 +65,8 @@ class RemoteFileBrowserItemsViewModel @Inject constructor(
class FinishState(val selectedPaths: Set<String>) : ViewState

private val initialSortOrder = FileSortOrder.getFileSortOrder(appPreferences.sorting)
private val sortingPrefListener: SortChangeListener = SortChangeListener()
// TODO remove this after implementing kotlin flow
// private val sortingPrefListener: SortChangeListener = SortChangeListener()

private val _viewState: MutableLiveData<ViewState> = MutableLiveData(InitialState)
val viewState: LiveData<ViewState>
Expand All @@ -86,19 +86,15 @@ class RemoteFileBrowserItemsViewModel @Inject constructor(
get() = _selectedPaths

init {
appPreferences.registerSortingChangeListener(sortingPrefListener)
// TODO change this to a kotlin flow
// appPreferences.registerSortingChangeListener(sortingPrefListener)
}

inner class SortChangeListener : OnPreferenceValueChangedListener<String> {
override fun onChanged(newValue: String) {
onSelectSortOrder(newValue)
}
}

override fun onCleared() {
super.onCleared()
appPreferences.unregisterSortingChangeListener(sortingPrefListener)
}
// inner class SortChangeListener : OnPreferenceValueChangedListener<String> {
// override fun onChanged(newValue: String) {
// onSelectSortOrder(newValue)
// }
// }

fun loadItems() {
_viewState.value = LoadingItemsState
Expand Down
Loading

0 comments on commit 433c2f9

Please sign in to comment.