-
Notifications
You must be signed in to change notification settings - Fork 747
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5009 from vector-im/feature/adm/storing-use-case
Storing and tracking the onboarding messaging use case
- Loading branch information
Showing
9 changed files
with
142 additions
and
14 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
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
29 changes: 29 additions & 0 deletions
29
vector/src/main/java/im/vector/app/features/analytics/extensions/IdentityExt.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,29 @@ | ||
/* | ||
* Copyright (c) 2022 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.analytics.extensions | ||
|
||
import im.vector.app.features.analytics.plan.Identity | ||
import im.vector.app.features.onboarding.FtueUseCase | ||
|
||
fun FtueUseCase.toTrackingValue(): Identity.FtueUseCaseSelection { | ||
return when (this) { | ||
FtueUseCase.FRIENDS_FAMILY -> Identity.FtueUseCaseSelection.PersonalMessaging | ||
FtueUseCase.TEAMS -> Identity.FtueUseCaseSelection.WorkMessaging | ||
FtueUseCase.COMMUNITIES -> Identity.FtueUseCaseSelection.CommunityMessaging | ||
FtueUseCase.SKIP -> Identity.FtueUseCaseSelection.Skip | ||
} | ||
} |
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
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
60 changes: 60 additions & 0 deletions
60
vector/src/main/java/im/vector/app/features/session/VectorSessionStore.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,60 @@ | ||
/* | ||
* Copyright (c) 2021 New Vector Ltd | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package im.vector.app.features.session | ||
|
||
import android.content.Context | ||
import androidx.datastore.core.DataStore | ||
import androidx.datastore.preferences.core.Preferences | ||
import androidx.datastore.preferences.core.edit | ||
import androidx.datastore.preferences.core.stringPreferencesKey | ||
import androidx.datastore.preferences.preferencesDataStore | ||
import im.vector.app.features.onboarding.FtueUseCase | ||
import kotlinx.coroutines.flow.first | ||
import org.matrix.android.sdk.internal.util.md5 | ||
|
||
/** | ||
* Local storage for: | ||
* - messaging use case (Enum/String) | ||
*/ | ||
class VectorSessionStore constructor( | ||
private val context: Context, | ||
myUserId: String | ||
) { | ||
|
||
private val Context.dataStore: DataStore<Preferences> by preferencesDataStore(name = "vector_session_store_${myUserId.md5()}") | ||
private val useCaseKey = stringPreferencesKey("use_case") | ||
|
||
suspend fun readUseCase() = context.dataStore.data.first().let { preferences -> | ||
preferences[useCaseKey]?.let { FtueUseCase.from(it) } | ||
} | ||
|
||
suspend fun setUseCase(useCase: FtueUseCase) { | ||
context.dataStore.edit { settings -> | ||
settings[useCaseKey] = useCase.persistableValue | ||
} | ||
} | ||
|
||
suspend fun resetUseCase() { | ||
context.dataStore.edit { settings -> | ||
settings.remove(useCaseKey) | ||
} | ||
} | ||
|
||
suspend fun clear() { | ||
context.dataStore.edit { settings -> settings.clear() } | ||
} | ||
} |