Update the glance section
This commit is contained in:
@ -29,6 +29,7 @@ import com.tommasoberlose.anotherwidget.receivers.ActivityDetectionReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MusicPlayersFilterActivity
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import kotlinx.android.synthetic.main.glance_provider_settings_layout.view.*
|
||||
import kotlinx.coroutines.*
|
||||
|
||||
class GlanceSettingsDialog(val context: Activity, val provider: Constants.GlanceProviderId, private val statusCallback: (() -> Unit)?) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
@ -77,7 +78,9 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
|
||||
/* GOOGLE STEPS */
|
||||
view.action_toggle_google_fit.isVisible = provider == Constants.GlanceProviderId.GOOGLE_FIT_STEPS
|
||||
if (provider == Constants.GlanceProviderId.GOOGLE_FIT_STEPS) {
|
||||
view.warning_container.isVisible = false
|
||||
checkFitnessPermission(view)
|
||||
checkGoogleFitConnection(view)
|
||||
}
|
||||
|
||||
/* BATTERY INFO */
|
||||
@ -111,48 +114,64 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
|
||||
Constants.GlanceProviderId.GREETINGS -> Preferences.showGreetings
|
||||
}
|
||||
|
||||
var job: Job? = null
|
||||
|
||||
view.provider_switch.setOnCheckedChangeListener { _, isChecked ->
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
Preferences.showMusic = isChecked
|
||||
checkNotificationPermission(view)
|
||||
}
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
Preferences.showNextAlarm = isChecked
|
||||
checkNextAlarm(view)
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
Preferences.showBatteryCharging = isChecked
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
Preferences.showNotifications = isChecked
|
||||
checkLastNotificationsPermission(view)
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
Preferences.showGreetings = isChecked
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (isChecked) {
|
||||
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
|
||||
if (!GoogleSignIn.hasPermissions(account,
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS
|
||||
)) {
|
||||
val mGoogleSignInClient = GoogleSignIn.getClient(context, GoogleSignInOptions.Builder(
|
||||
GoogleSignInOptions.DEFAULT_SIGN_IN).addExtension(
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS
|
||||
).build())
|
||||
context.startActivityForResult(mGoogleSignInClient.signInIntent, 2)
|
||||
} else {
|
||||
Preferences.showDailySteps = true
|
||||
job?.cancel()
|
||||
job = GlobalScope.launch(Dispatchers.IO) {
|
||||
delay(300)
|
||||
withContext(Dispatchers.Main) {
|
||||
when (provider) {
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
Preferences.showMusic = isChecked
|
||||
checkNotificationPermission(view)
|
||||
}
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
Preferences.showNextAlarm = isChecked
|
||||
checkNextAlarm(view)
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
Preferences.showBatteryCharging = isChecked
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
Preferences.showNotifications = isChecked
|
||||
checkLastNotificationsPermission(view)
|
||||
}
|
||||
Constants.GlanceProviderId.GREETINGS -> {
|
||||
Preferences.showGreetings = isChecked
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (isChecked) {
|
||||
val account: GoogleSignInAccount? =
|
||||
GoogleSignIn.getLastSignedInAccount(context)
|
||||
if (!GoogleSignIn.hasPermissions(account,
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS
|
||||
)
|
||||
) {
|
||||
val mGoogleSignInClient =
|
||||
GoogleSignIn.getClient(context, GoogleSignInOptions.Builder(
|
||||
GoogleSignInOptions.DEFAULT_SIGN_IN).addExtension(
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS
|
||||
).build())
|
||||
context.startActivityForResult(mGoogleSignInClient.signInIntent,
|
||||
2)
|
||||
} else {
|
||||
Preferences.showDailySteps = true
|
||||
}
|
||||
} else {
|
||||
Preferences.showDailySteps = false
|
||||
}
|
||||
|
||||
view.warning_container.isVisible = false
|
||||
checkFitnessPermission(view)
|
||||
checkGoogleFitConnection(view)
|
||||
}
|
||||
else -> {
|
||||
}
|
||||
} else {
|
||||
Preferences.showDailySteps = false
|
||||
}
|
||||
checkFitnessPermission(view)
|
||||
statusCallback?.invoke()
|
||||
}
|
||||
else -> {}
|
||||
}
|
||||
statusCallback?.invoke()
|
||||
}
|
||||
|
||||
setContentView(view)
|
||||
@ -180,7 +199,6 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
|
||||
}
|
||||
|
||||
private fun checkNotificationPermission(view: View) {
|
||||
Log.d("ciao", NotificationManagerCompat.getEnabledListenerPackages(context).toString())
|
||||
when {
|
||||
NotificationManagerCompat.getEnabledListenerPackages(context).contains(context.packageName) -> {
|
||||
view.warning_container.isVisible = false
|
||||
@ -223,7 +241,6 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || context.checkGrantedPermission(
|
||||
Manifest.permission.ACTIVITY_RECOGNITION)
|
||||
) {
|
||||
view.warning_container.isVisible = false
|
||||
if (Preferences.showDailySteps) {
|
||||
ActivityDetectionReceiver.registerFence(context)
|
||||
} else {
|
||||
@ -238,11 +255,51 @@ class GlanceSettingsDialog(val context: Activity, val provider: Constants.Glance
|
||||
}
|
||||
} else {
|
||||
ActivityDetectionReceiver.unregisterFence(context)
|
||||
view.warning_container.isVisible = false
|
||||
}
|
||||
statusCallback?.invoke()
|
||||
}
|
||||
|
||||
private fun checkGoogleFitConnection(view: View) {
|
||||
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
|
||||
if (!GoogleSignIn.hasPermissions(account,
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS
|
||||
)) {
|
||||
view.warning_container.isVisible = true
|
||||
view.warning_title.text = context.getString(R.string.settings_request_fitness_access)
|
||||
view.warning_container.setOnClickListener {
|
||||
GoogleSignIn.requestPermissions(
|
||||
context,
|
||||
1,
|
||||
account,
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS)
|
||||
}
|
||||
view.action_connect_to_google_fit.isVisible = true
|
||||
view.action_disconnect_to_google_fit.isVisible = false
|
||||
view.action_connect_to_google_fit.setOnClickListener {
|
||||
GoogleSignIn.requestPermissions(
|
||||
context,
|
||||
1,
|
||||
account,
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS)
|
||||
}
|
||||
view.action_disconnect_to_google_fit.setOnClickListener(null)
|
||||
view.google_fit_status_label.text = context.getString(R.string.google_fit_account_not_connected)
|
||||
} else {
|
||||
view.action_connect_to_google_fit.isVisible = false
|
||||
view.action_disconnect_to_google_fit.isVisible = true
|
||||
view.action_connect_to_google_fit.setOnClickListener(null)
|
||||
view.action_disconnect_to_google_fit.setOnClickListener {
|
||||
GoogleSignIn.getClient(context, GoogleSignInOptions.Builder(
|
||||
GoogleSignInOptions.DEFAULT_SIGN_IN).addExtension(
|
||||
ActivityDetectionReceiver.FITNESS_OPTIONS
|
||||
).build()).signOut().addOnCompleteListener {
|
||||
show()
|
||||
}
|
||||
}
|
||||
view.google_fit_status_label.text = context.getString(R.string.google_fit_account_connected)
|
||||
}
|
||||
}
|
||||
|
||||
private fun requireFitnessPermission(view: View) {
|
||||
Dexter.withContext(context)
|
||||
.withPermissions(
|
||||
|
@ -43,19 +43,19 @@ object GlanceProviderHelper {
|
||||
Constants.GlanceProviderId.NEXT_CLOCK_ALARM -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_show_next_alarm_title),
|
||||
R.drawable.round_alarm
|
||||
R.drawable.round_access_alarm
|
||||
)
|
||||
}
|
||||
Constants.GlanceProviderId.PLAYING_SONG -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_show_music_title),
|
||||
R.drawable.round_music_note
|
||||
R.drawable.round_radio
|
||||
)
|
||||
}
|
||||
Constants.GlanceProviderId.CUSTOM_INFO -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_custom_notes_title),
|
||||
R.drawable.round_notes
|
||||
R.drawable.round_sticky_note_2
|
||||
)
|
||||
}
|
||||
Constants.GlanceProviderId.BATTERY_LEVEL_LOW -> {
|
||||
@ -67,7 +67,7 @@ object GlanceProviderHelper {
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
GlanceProvider(providerId.id,
|
||||
context.getString(R.string.settings_daily_steps_title),
|
||||
R.drawable.round_directions_walk
|
||||
R.drawable.round_run_circle
|
||||
)
|
||||
}
|
||||
Constants.GlanceProviderId.NOTIFICATIONS -> {
|
||||
|
@ -202,8 +202,9 @@ class GlanceTabFragment : Fragment() {
|
||||
injector.visibility(R.id.info_icon, View.VISIBLE)
|
||||
}
|
||||
Constants.GlanceProviderId.GOOGLE_FIT_STEPS -> {
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || activity?.checkGrantedPermission(
|
||||
Manifest.permission.ACTIVITY_RECOGNITION) == true
|
||||
val account: GoogleSignInAccount? = GoogleSignIn.getLastSignedInAccount(context)
|
||||
if (GoogleSignIn.hasPermissions(account, FITNESS_OPTIONS) && (Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || activity?.checkGrantedPermission(
|
||||
Manifest.permission.ACTIVITY_RECOGNITION) == true)
|
||||
) {
|
||||
injector.text(R.id.label,
|
||||
if (Preferences.showDailySteps) getString(R.string.settings_visible) else getString(
|
||||
@ -361,14 +362,12 @@ class GlanceTabFragment : Fragment() {
|
||||
1 -> {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
adapter.notifyItemRangeChanged(0, adapter.data.size)
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
} else {
|
||||
Preferences.showDailySteps = false
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
}
|
||||
2 -> {
|
||||
@ -383,16 +382,14 @@ class GlanceTabFragment : Fragment() {
|
||||
FITNESS_OPTIONS)
|
||||
} else {
|
||||
adapter.notifyItemRangeChanged(0, adapter.data.size)
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
}
|
||||
} catch (e: ApiException) {
|
||||
e.printStackTrace()
|
||||
Preferences.showDailySteps = false
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
}
|
||||
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -410,5 +407,8 @@ class GlanceTabFragment : Fragment() {
|
||||
override fun onResume() {
|
||||
super.onResume()
|
||||
adapter.notifyItemRangeChanged(0, adapter.data.size)
|
||||
if (dialog != null) {
|
||||
dialog?.show()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -30,11 +30,8 @@ import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.MaterialBottomSheetDialog
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.global.Preferences
|
||||
import com.tommasoberlose.anotherwidget.helpers.BitmapHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.*
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
|
||||
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.WidgetHelper
|
||||
import com.tommasoberlose.anotherwidget.receivers.ActivityDetectionReceiver
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.adapters.ViewPagerAdapter
|
||||
@ -360,12 +357,13 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
|
||||
false
|
||||
}
|
||||
|
||||
// Music error indicator
|
||||
// Glance error indicator
|
||||
tabs?.getTabAt(4)?.orCreateBadge?.apply {
|
||||
backgroundColor = ContextCompat.getColor(requireContext(), R.color.errorColorText)
|
||||
badgeGravity = BadgeDrawable.TOP_END
|
||||
}?.isVisible = ((Preferences.showMusic || Preferences.showNotifications) && !NotificationManagerCompat.getEnabledListenerPackages(requireContext()).contains(requireContext().packageName)) ||
|
||||
(Preferences.showDailySteps && !(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || requireActivity().checkGrantedPermission(Manifest.permission.ACTIVITY_RECOGNITION)))
|
||||
(Preferences.showDailySteps && !(Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || requireActivity().checkGrantedPermission(Manifest.permission.ACTIVITY_RECOGNITION))) ||
|
||||
(AlarmHelper.isAlarmProbablyWrong(requireContext()))
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
|
Reference in New Issue
Block a user