2020-08-03 16:07:06 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileCopyrightText: 2020, microG Project Team
|
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
|
|
*/
|
|
|
|
|
|
|
|
package org.microg.gms.ui
|
|
|
|
|
|
|
|
import android.os.Bundle
|
|
|
|
import android.view.LayoutInflater
|
|
|
|
import android.view.View
|
|
|
|
import android.view.ViewGroup
|
|
|
|
import androidx.fragment.app.Fragment
|
|
|
|
import androidx.lifecycle.lifecycleScope
|
|
|
|
import com.google.android.gms.R
|
|
|
|
import com.google.android.gms.databinding.ExposureNotificationsFragmentBinding
|
2020-09-02 19:41:15 +00:00
|
|
|
import org.microg.gms.nearby.exposurenotification.ServiceInfo
|
|
|
|
import org.microg.gms.nearby.exposurenotification.getExposureNotificationsServiceInfo
|
|
|
|
import org.microg.gms.nearby.exposurenotification.setExposureNotificationsServiceConfiguration
|
2020-08-03 16:07:06 +00:00
|
|
|
|
|
|
|
class ExposureNotificationsFragment : Fragment(R.layout.exposure_notifications_fragment) {
|
|
|
|
private lateinit var binding: ExposureNotificationsFragmentBinding
|
|
|
|
|
|
|
|
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
|
|
|
binding = ExposureNotificationsFragmentBinding.inflate(inflater, container, false)
|
|
|
|
binding.switchBarCallback = object : PreferenceSwitchBarCallback {
|
|
|
|
override fun onChecked(newStatus: Boolean) {
|
2020-09-02 19:41:15 +00:00
|
|
|
setEnabled(newStatus)
|
2020-08-03 16:07:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return binding.root
|
|
|
|
}
|
|
|
|
|
2020-09-02 19:41:15 +00:00
|
|
|
fun setEnabled(newStatus: Boolean) {
|
|
|
|
lifecycleScope.launchWhenResumed {
|
|
|
|
val info = getExposureNotificationsServiceInfo(requireContext())
|
|
|
|
val newConfiguration = info.configuration.copy(enabled = newStatus)
|
|
|
|
displayServiceInfo(setExposureNotificationsServiceConfiguration(requireContext(), newConfiguration))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fun displayServiceInfo(serviceInfo: ServiceInfo) {
|
|
|
|
binding.scannerEnabled = serviceInfo.configuration.enabled
|
|
|
|
}
|
|
|
|
|
2020-08-03 16:07:06 +00:00
|
|
|
override fun onResume() {
|
|
|
|
super.onResume()
|
|
|
|
lifecycleScope.launchWhenResumed {
|
2020-09-02 19:41:15 +00:00
|
|
|
displayServiceInfo(getExposureNotificationsServiceInfo(requireContext()))
|
2020-08-03 16:07:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|