-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature: Expansion of Preferences Manager #96
base: master
Are you sure you want to change the base?
Changes from all commits
234cad7
d34a5e6
08a583e
fea2a19
ff89a43
dcad00e
a815816
a0f4652
5b29c28
cf6e43f
8eff8bd
ee3f2e3
a50d5ed
e099d88
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package com.infinum.sentinel.data.sources.raw.collectors | ||
|
||
import android.content.Context | ||
import android.content.Context.MODE_PRIVATE | ||
import com.infinum.sentinel.data.models.raw.PreferenceType | ||
import com.infinum.sentinel.data.models.raw.PreferencesData | ||
import com.infinum.sentinel.domain.collectors.Collectors | ||
import me.tatarka.inject.annotations.Inject | ||
|
||
@Inject | ||
internal class TargetedPreferencesCollector( | ||
private val context: Context, | ||
private val targetedPreferences: Map<String, List<String>> | ||
) : Collectors.TargetedPreferences { | ||
|
||
override fun invoke(): List<PreferencesData> { | ||
if (targetedPreferences.isEmpty()) return emptyList() | ||
|
||
return targetedPreferences.mapNotNull { (fileName, keys) -> | ||
val allPrefs = context.getSharedPreferences(fileName, MODE_PRIVATE).all | ||
|
||
val tuples = allPrefs.keys | ||
.filter { keys.isEmpty() || keys.contains(it) } | ||
.mapNotNull { key -> | ||
@Suppress("UNCHECKED_CAST") | ||
when (val value = allPrefs[key]) { | ||
is Boolean -> Triple(PreferenceType.BOOLEAN, key, value) | ||
is Float -> Triple(PreferenceType.FLOAT, key, value) | ||
is Int -> Triple(PreferenceType.INT, key, value) | ||
is Long -> Triple(PreferenceType.LONG, key, value) | ||
is String -> Triple(PreferenceType.STRING, key, value) | ||
is Set<*> -> Triple(PreferenceType.SET, key, value as Set<String>) | ||
else -> null | ||
} | ||
} | ||
|
||
if (tuples.isNotEmpty()) PreferencesData(fileName, tuples) else null | ||
Comment on lines
+11
to
+37
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could this be included in regular There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it can be done. I would just have to add additional filtering of files since there we also fetch all preference files. 👍 |
||
} | ||
} | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kudos for docs 👏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have questions:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In selected preferences quick view, you can monitor multiple files but you have to provide names of those files. If that's what you are asking. IMO, it makes sense since app will have dozens of not so relevant files which are then cluttering your UI [but you can access them in AllFiles].
To my knowledge, they don't have option to display all files, they just display what clients want. They also have some logic of mapping where clients can provide readable names of properties (instead of KEY_ONE they can send mapping "key one" which is more readable lets say.) I will have to double check with them just in case.