Skip to content

Commit

Permalink
Update deprecated code
Browse files Browse the repository at this point in the history
  • Loading branch information
hameno committed May 15, 2021
1 parent 91a5d02 commit 442f44f
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 29 deletions.
1 change: 1 addition & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ android {
lintOptions {
lintConfig project.file('lint.xml')
disable "GoogleAppIndexingWarning"
disable "RemoveWorkManagerInitializer"
enable 'Interoperability'
}
packagingOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,27 @@ import android.widget.TextView
import de.psdev.devdrawer.R
import de.psdev.devdrawer.database.DevDrawerDatabase
import kotlinx.coroutines.runBlocking
import java.util.*

class PartialMatchAdapter(
activity: Activity,
private val profileId: String,
private val items: List<String>,
private val devDrawerDatabase: DevDrawerDatabase,
private val editMode: Boolean = false
): BaseAdapter(), Filterable {
) : BaseAdapter(), Filterable {
private val filteredItems = mutableListOf<String>()
private val layoutInflater: LayoutInflater = activity.layoutInflater
private val packageFilter = object: Filter() {
private val packageFilter = object : Filter() {
override fun performFiltering(charSequence: CharSequence?): FilterResults {
return if (charSequence == null) {
FilterResults().apply {
count = items.size
values = items
}
} else {
val existingFilters = runBlocking { devDrawerDatabase.packageFilterDao().findAllByProfile(profileId) }
.map { it.filter }
val existingFilters =
runBlocking { devDrawerDatabase.packageFilterDao().findAllByProfile(profileId) }
.map { it.filter }
val existingFilterRegexes = existingFilters
.map { it.replace("*", ".*").toRegex() }
val filteredItems = items
Expand All @@ -40,7 +40,7 @@ class PartialMatchAdapter(
// Filter item matching existing filters with regex
.filterNot { !editMode && existingFilterRegexes.any { regex -> regex.matches(it) } }
// Filter matching
.filter { it.toLowerCase(Locale.ROOT).contains(charSequence.toString().toLowerCase(Locale.ROOT)) }
.filter { it.lowercase().contains(charSequence.toString().lowercase()) }
FilterResults().apply {
count = filteredItems.size
values = filteredItems
Expand All @@ -66,7 +66,7 @@ class PartialMatchAdapter(

override fun getItemId(position: Int): Long = filteredItems[position].hashCode().toLong()

override fun getView(position: Int, convertView: View?, viewGroup: ViewGroup): View? {
override fun getView(position: Int, convertView: View?, viewGroup: ViewGroup): View {
val view = convertView ?: createView(viewGroup)
bindView(position, view)
return view
Expand Down
50 changes: 30 additions & 20 deletions app/src/main/java/de/psdev/devdrawer/analytics/TrackingService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,11 @@ class TrackingService @Inject constructor(
const val CONFIG_KEY_MIN_TIME = "feature_analytics_optin_min_time"
}

private val sharedPreferences by lazy { PreferenceManager.getDefaultSharedPreferences(application) }
private val sharedPreferences by lazy {
PreferenceManager.getDefaultSharedPreferences(
application
)
}
private var firebaseAnalyticsOptInStatus: OptInStatus
get() = if (sharedPreferences.contains(PREF_KEY_OPTED_IN)) {
when (sharedPreferences.getBoolean(PREF_KEY_OPTED_IN, false)) {
Expand All @@ -51,24 +55,26 @@ class TrackingService @Inject constructor(
OptInStatus.UNKNOWN -> throw IllegalArgumentException("UNKNOWN not allowed")
}
private val firebaseAnalytics: FirebaseAnalytics = Firebase.analytics
private val preferenceChangedListener = OnSharedPreferenceChangeListener { sharedPreferences, key ->
logger.info { "Preference changed: $key" }
when (key) {
PREF_KEY_OPTED_IN -> {
val value = sharedPreferences.getBoolean(key, false)
sharedPreferences.edit {
putLong(PREF_KEY_OPTED_IN_TIME, System.currentTimeMillis())
}
if (value) {
setConsentStatus(FirebaseAnalytics.ConsentStatus.GRANTED)
firebaseAnalytics.setAnalyticsCollectionEnabled(true)
} else {
setConsentStatus(FirebaseAnalytics.ConsentStatus.DENIED)
firebaseAnalytics.setAnalyticsCollectionEnabled(false)
private val preferenceChangedListener =
OnSharedPreferenceChangeListener { sharedPreferences, key ->
logger.info { "Preference changed: $key" }
when (key) {
PREF_KEY_OPTED_IN -> {
val value = sharedPreferences.getBoolean(key, false)
sharedPreferences.edit {
putLong(PREF_KEY_OPTED_IN_TIME, System.currentTimeMillis())
}
if (value) {
setConsentStatus(FirebaseAnalytics.ConsentStatus.GRANTED)
firebaseAnalytics.setAnalyticsCollectionEnabled(true)
} else {
setConsentStatus(FirebaseAnalytics.ConsentStatus.DENIED)
firebaseAnalytics.setAnalyticsCollectionEnabled(false)
}
}
}
}
}
private val coroutineScope = CoroutineScope(SupervisorJob() + Dispatchers.Main)

init {
sharedPreferences.registerOnSharedPreferenceChangeListener(preferenceChangedListener)
Expand Down Expand Up @@ -117,9 +123,13 @@ class TrackingService @Inject constructor(
)
.setPositiveButton("Opt-in") { _, _ ->
optIn()
Snackbar.make(activity.findViewById(android.R.id.content), buildSpannedString {
bold { append("Thank you! You can change your decision anytime on the settings tab.") }
}, Snackbar.LENGTH_LONG).apply {
Snackbar.make(
activity.findViewById(android.R.id.content),
buildSpannedString {
bold { append("Thank you! You can change your decision anytime on the settings tab.") }
},
Snackbar.LENGTH_LONG
).apply {
animationMode = Snackbar.ANIMATION_MODE_SLIDE
setAction("OK") {
dismiss()
Expand All @@ -131,7 +141,7 @@ class TrackingService @Inject constructor(
.setCancelable(false)
.create()
alertDialog.setCanceledOnTouchOutside(false)
val job = GlobalScope.async(Dispatchers.Main, start = CoroutineStart.LAZY) {
val job = coroutineScope.async(start = CoroutineStart.LAZY) {
alertDialog.findViewById<TextView>(android.R.id.message)?.movementMethod =
LinkMovementMethod.getInstance()
val positiveButton = alertDialog.getButton(AlertDialog.BUTTON_POSITIVE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import de.psdev.devdrawer.database.FilterType
import de.psdev.devdrawer.database.PackageFilter
import de.psdev.devdrawer.databinding.ListItemPackageFilterBinding
import de.psdev.devdrawer.utils.layoutInflater
import java.util.*

class PackageFilterListAdapter(
private val onDeleteClickListener: PackageFilterActionListener,
Expand Down Expand Up @@ -81,7 +80,7 @@ class PackageFilterListAdapter(
val text = when (packageFilter.type) {
FilterType.PACKAGE_NAME -> packageFilter.description
FilterType.SIGNATURE -> "SHA256: ${
packageFilter.filter.toUpperCase(Locale.ROOT).chunkedSequence(2)
packageFilter.filter.uppercase().chunkedSequence(2)
.joinToString(separator = ":")
}"
}
Expand Down

0 comments on commit 442f44f

Please sign in to comment.