forked from mozilla-mobile/fenix
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
For mozilla-mobile#21593 - Persist stories categories selections in a…
… Proto DataStore A fast and easy solution with all the ACID requirements. Also supports easy migrations if later the data we need persisted changes.
- Loading branch information
1 parent
565beb8
commit e4489b8
Showing
10 changed files
with
391 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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
17 changes: 17 additions & 0 deletions
17
app/src/main/java/org/mozilla/fenix/datastore/DataStores.kt
This file contains 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,17 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.datastore | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.dataStore | ||
|
||
/** | ||
* Application / process unique [DataStore] for IO operations related to Pocket recommended stories selected categories. | ||
*/ | ||
internal val Context.pocketStoriesSelectedCategoriesDataStore: DataStore<SelectedPocketStoriesCategories> by dataStore( | ||
fileName = "pocket_recommendations_selected_categories.pb", | ||
serializer = SelectedPocketStoriesCategorySerializer | ||
) |
25 changes: 25 additions & 0 deletions
25
app/src/main/java/org/mozilla/fenix/datastore/SelectedPocketStoriesCategorySerializer.kt
This file contains 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,25 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.fenix.datastore | ||
|
||
import androidx.datastore.core.Serializer | ||
import java.io.InputStream | ||
import java.io.OutputStream | ||
|
||
/** | ||
* Serializer for [SelectedPocketStoriesCategories] defined in selected_pocket_stories_categories.proto. | ||
*/ | ||
@Suppress("BlockingMethodInNonBlockingContext") | ||
object SelectedPocketStoriesCategorySerializer : Serializer<SelectedPocketStoriesCategories> { | ||
override val defaultValue: SelectedPocketStoriesCategories = SelectedPocketStoriesCategories.getDefaultInstance() | ||
|
||
override suspend fun readFrom(input: InputStream): SelectedPocketStoriesCategories { | ||
return SelectedPocketStoriesCategories.parseFrom(input) | ||
} | ||
|
||
override suspend fun writeTo(t: SelectedPocketStoriesCategories, output: OutputStream) { | ||
t.writeTo(output) | ||
} | ||
} |
This file contains 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 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 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
26 changes: 26 additions & 0 deletions
26
app/src/main/proto/selected_pocket_stories_categories.proto
This file contains 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,26 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this | ||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
|
||
syntax = "proto3"; | ||
|
||
package proto; | ||
|
||
option java_package = "org.mozilla.fenix.datastore"; | ||
option java_multiple_files = true; | ||
|
||
// List of currently selected Pocket recommended stories categories. | ||
message SelectedPocketStoriesCategories { | ||
|
||
// Details about a selected Pocket recommended stories category. | ||
// See [org.mozilla.fenix.home.sessioncontrol.viewholders.pocket.PocketRecommendedStoriesSelectedCategory] | ||
message SelectedPocketStoriesCategory { | ||
// Name of this category. | ||
string name = 1; | ||
// Timestamp for when this category was selected. | ||
int64 selectionTimestamp = 2; | ||
} | ||
|
||
// Currently selected Pocket stories categories. | ||
repeated SelectedPocketStoriesCategory values = 1; | ||
} |
This file contains 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.