-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add initial Exposure Notification API implementation
- Loading branch information
Showing
92 changed files
with
4,921 additions
and
19 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,3 +19,7 @@ wire { | |
compileKotlin { | ||
kotlinOptions.jvmTarget = 1.8 | ||
} | ||
|
||
compileTestKotlin { | ||
kotlinOptions.jvmTarget = 1.8 | ||
} |
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
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
58 changes: 58 additions & 0 deletions
58
play-services-core/src/main/kotlin/org/microg/gms/ui/BarChartPreference.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,58 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.ui | ||
|
||
import android.content.Context | ||
import android.util.AttributeSet | ||
import android.util.Log | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceViewHolder | ||
import com.db.williamchart.data.Scale | ||
import com.db.williamchart.view.BarChartView | ||
import com.google.android.gms.R | ||
|
||
class BarChartPreference : Preference { | ||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int, defStyleRes: Int) : super(context, attrs, defStyleAttr, defStyleRes) | ||
constructor(context: Context?, attrs: AttributeSet?, defStyleAttr: Int) : super(context, attrs, defStyleAttr) | ||
constructor(context: Context?, attrs: AttributeSet?) : super(context, attrs) | ||
constructor(context: Context?) : super(context) | ||
|
||
init { | ||
layoutResource = R.layout.preference_bar_chart | ||
} | ||
|
||
private lateinit var chart: BarChartView | ||
var labelsFormatter: (Float) -> String = { it.toString() } | ||
set(value) { | ||
field = value | ||
if (this::chart.isInitialized) { | ||
chart.labelsFormatter = value | ||
} | ||
} | ||
var scale: Scale? = null | ||
set(value) { | ||
field = value | ||
if (value != null && this::chart.isInitialized) { | ||
chart.scale = value | ||
} | ||
} | ||
var data: LinkedHashMap<String, Float> = linkedMapOf() | ||
set(value) { | ||
field = value | ||
if (this::chart.isInitialized) { | ||
chart.animate(data) | ||
} | ||
} | ||
|
||
override fun onBindViewHolder(holder: PreferenceViewHolder) { | ||
super.onBindViewHolder(holder) | ||
chart = holder.itemView as? BarChartView ?: holder.findViewById(R.id.bar_chart) as BarChartView | ||
chart.labelsFormatter = labelsFormatter | ||
scale?.let { chart.scale = it } | ||
chart.animate(data) | ||
} | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
play-services-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsAppFragment.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,57 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.ui | ||
|
||
import android.content.Intent | ||
import android.net.Uri | ||
import android.os.Bundle | ||
import android.provider.Settings | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.appcompat.content.res.AppCompatResources | ||
import androidx.fragment.app.Fragment | ||
import androidx.lifecycle.lifecycleScope | ||
import com.google.android.gms.R | ||
import com.google.android.gms.databinding.ExposureNotificationsAppFragmentBinding | ||
import com.google.android.gms.databinding.ExposureNotificationsFragmentBinding | ||
import org.microg.gms.nearby.exposurenotification.ExposurePreferences | ||
|
||
class ExposureNotificationsAppFragment : Fragment(R.layout.exposure_notifications_app_fragment) { | ||
private lateinit var binding: ExposureNotificationsAppFragmentBinding | ||
val packageName: String? | ||
get() = arguments?.getString("package") | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
binding = ExposureNotificationsAppFragmentBinding.inflate(inflater, container, false) | ||
binding.callbacks = object : ExposureNotificationsAppFragmentCallbacks { | ||
override fun onAppClicked() { | ||
val intent = Intent() | ||
intent.action = Settings.ACTION_APPLICATION_DETAILS_SETTINGS | ||
val uri: Uri = Uri.fromParts("package", packageName, null) | ||
intent.data = uri | ||
context!!.startActivity(intent) | ||
} | ||
} | ||
childFragmentManager.findFragmentById(R.id.sub_preferences)?.arguments = arguments | ||
return binding.root | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
lifecycleScope.launchWhenResumed { | ||
val pm = requireContext().packageManager | ||
val applicationInfo = pm.getApplicationInfoIfExists(packageName) | ||
binding.appName = applicationInfo?.loadLabel(pm)?.toString() ?: packageName | ||
binding.appIcon = applicationInfo?.loadIcon(pm) | ||
?: AppCompatResources.getDrawable(requireContext(), android.R.mipmap.sym_def_app_icon) | ||
} | ||
} | ||
} | ||
|
||
interface ExposureNotificationsAppFragmentCallbacks { | ||
fun onAppClicked() | ||
} |
60 changes: 60 additions & 0 deletions
60
...ces-core/src/main/kotlin/org/microg/gms/ui/ExposureNotificationsAppPreferencesFragment.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 @@ | ||
/* | ||
* SPDX-FileCopyrightText: 2020, microG Project Team | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package org.microg.gms.ui | ||
|
||
import android.content.Intent | ||
import android.os.Bundle | ||
import android.text.format.DateUtils | ||
import androidx.preference.Preference | ||
import androidx.preference.PreferenceFragmentCompat | ||
import com.google.android.gms.R | ||
import org.microg.gms.nearby.exposurenotification.ExposureDatabase | ||
|
||
class ExposureNotificationsAppPreferencesFragment : PreferenceFragmentCompat() { | ||
private lateinit var open: Preference | ||
private lateinit var checks: Preference | ||
private val packageName: String? | ||
get() = arguments?.getString("package") | ||
|
||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) { | ||
addPreferencesFromResource(R.xml.preferences_exposure_notifications_app) | ||
} | ||
|
||
override fun onBindPreferences() { | ||
open = preferenceScreen.findPreference("pref_exposure_app_open") ?: open | ||
checks = preferenceScreen.findPreference("pref_exposure_app_checks") ?: checks | ||
open.onPreferenceClickListener = Preference.OnPreferenceClickListener { | ||
try { | ||
packageName?.let { | ||
context?.packageManager?.getLaunchIntentForPackage(it)?.let { intent -> | ||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK) | ||
context?.startActivity(intent) | ||
} | ||
} | ||
} catch (ignored: Exception) { | ||
} | ||
true | ||
} | ||
} | ||
|
||
override fun onResume() { | ||
super.onResume() | ||
updateContent() | ||
} | ||
|
||
fun updateContent() { | ||
packageName?.let { packageName -> | ||
val database = ExposureDatabase(requireContext()) | ||
var str = getString(R.string.pref_exposure_app_checks_summary, database.countMethodCalls(packageName, "provideDiagnosisKeys")) | ||
val lastCheckTime = database.lastMethodCall(packageName, "provideDiagnosisKeys") | ||
if (lastCheckTime != null && lastCheckTime != 0L) { | ||
str += "\n" + getString(R.string.pref_exposure_app_last_check_summary, DateUtils.getRelativeDateTimeString(context, lastCheckTime, DateUtils.MINUTE_IN_MILLIS, DateUtils.WEEK_IN_MILLIS, DateUtils.FORMAT_SHOW_TIME)) | ||
} | ||
checks.summary = str | ||
database.close() | ||
} | ||
} | ||
} |
Oops, something went wrong.