Bugfixes
This commit is contained in:
@ -3,16 +3,29 @@ package com.tommasoberlose.anotherwidget.components
|
||||
import android.content.Context
|
||||
import android.content.res.ColorStateList
|
||||
import android.graphics.Color
|
||||
import android.text.Editable
|
||||
import android.text.TextWatcher
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.GridLayout
|
||||
import androidx.annotation.ColorInt
|
||||
import androidx.core.content.ContextCompat
|
||||
import androidx.core.view.isVisible
|
||||
import androidx.core.widget.addTextChangedListener
|
||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper
|
||||
import com.tommasoberlose.anotherwidget.helpers.ColorHelper.isColorDark
|
||||
import com.tommasoberlose.anotherwidget.utils.expand
|
||||
import com.tommasoberlose.anotherwidget.utils.reveal
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.*
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.*
|
||||
import kotlinx.android.synthetic.main.bottom_sheet_menu_hor.view.color_loader
|
||||
import kotlinx.android.synthetic.main.color_picker_menu_item.view.*
|
||||
import kotlinx.coroutines.*
|
||||
import java.lang.Exception
|
||||
import java.util.prefs.Preferences
|
||||
|
||||
class BottomSheetColorPicker(
|
||||
context: Context,
|
||||
@ -22,6 +35,8 @@ class BottomSheetColorPicker(
|
||||
private val onColorSelected: ((selectedValue: Int) -> Unit)? = null
|
||||
) : BottomSheetDialog(context, R.style.BottomSheetDialogTheme) {
|
||||
|
||||
private val loadingJob: Job? = null
|
||||
|
||||
override fun show() {
|
||||
val view = View.inflate(context, R.layout.bottom_sheet_menu_hor, null)
|
||||
|
||||
@ -29,27 +44,45 @@ class BottomSheetColorPicker(
|
||||
view.header.isVisible = header != null
|
||||
view.header_text.text = header ?: ""
|
||||
|
||||
// Menu
|
||||
for (@ColorInt color: Int in colors) {
|
||||
val itemView = View.inflate(context, R.layout.color_picker_menu_item, null)
|
||||
itemView.color.setCardBackgroundColor(ColorStateList.valueOf(color))
|
||||
itemView.check.setColorFilter(ContextCompat.getColor(context,
|
||||
if (color.isColorDark()) android.R.color.white else android.R.color.black
|
||||
), android.graphics.PorterDuff.Mode.MULTIPLY)
|
||||
itemView.check.isVisible = selected == color
|
||||
itemView.color.setOnClickListener {
|
||||
onColorSelected?.invoke(color)
|
||||
this.dismiss()
|
||||
val itemViews: ArrayList<View> = ArrayList()
|
||||
|
||||
GlobalScope.launch(Dispatchers.IO) {
|
||||
for (@ColorInt color: Int in colors) {
|
||||
val itemView = View.inflate(context, R.layout.color_picker_menu_item, null)
|
||||
itemView.color.setCardBackgroundColor(ColorStateList.valueOf(color))
|
||||
itemView.check.setColorFilter(ContextCompat.getColor(context,
|
||||
if (color.isColorDark()) android.R.color.white else android.R.color.black
|
||||
), android.graphics.PorterDuff.Mode.MULTIPLY)
|
||||
itemView.check.isVisible = selected == color
|
||||
itemView.color.setOnClickListener {
|
||||
onColorSelected?.invoke(color)
|
||||
this@BottomSheetColorPicker.dismiss()
|
||||
}
|
||||
itemViews.add(itemView)
|
||||
}
|
||||
|
||||
withContext(Dispatchers.Main) {
|
||||
itemViews.forEach {
|
||||
view.menu.addView(it, GridLayout.LayoutParams(
|
||||
GridLayout.spec(GridLayout.UNDEFINED, 1f),
|
||||
GridLayout.spec(GridLayout.UNDEFINED, 1f)
|
||||
))
|
||||
}
|
||||
color_loader.isVisible = false
|
||||
view.menu.isVisible = true
|
||||
this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||
}
|
||||
view.menu.addView(itemView, GridLayout.LayoutParams(
|
||||
GridLayout.spec(GridLayout.UNDEFINED, 1f),
|
||||
GridLayout.spec(GridLayout.UNDEFINED, 1f)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
// Menu
|
||||
|
||||
setContentView(view)
|
||||
super.show()
|
||||
}
|
||||
|
||||
override fun onStop() {
|
||||
loadingJob?.cancel()
|
||||
super.onStop()
|
||||
}
|
||||
|
||||
}
|
@ -7,12 +7,13 @@ import java.util.*
|
||||
|
||||
object AlarmHelper {
|
||||
fun getNextAlarm(context: Context): String = with(context.getSystemService(Context.ALARM_SERVICE) as AlarmManager) {
|
||||
val alarm = nextAlarmClock
|
||||
return if (
|
||||
nextAlarmClock != null
|
||||
&& nextAlarmClock.triggerTime - Calendar.getInstance().timeInMillis > 2 * 60 * 1000
|
||||
&& nextAlarmClock.triggerTime - Calendar.getInstance().timeInMillis < 24 * 60 * 60 * 1000
|
||||
alarm != null
|
||||
&& alarm.triggerTime - Calendar.getInstance().timeInMillis > 2 * 60 * 1000
|
||||
&& alarm.triggerTime - Calendar.getInstance().timeInMillis < 24 * 60 * 60 * 1000
|
||||
) {
|
||||
DateFormat.getTimeFormat(context).format(Date(nextAlarmClock.triggerTime))
|
||||
DateFormat.getTimeFormat(context).format(Date(alarm.triggerTime))
|
||||
} else {
|
||||
""
|
||||
}
|
||||
|
@ -29,6 +29,7 @@ import com.tommasoberlose.anotherwidget.ui.activities.SupportDevActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||
import com.tommasoberlose.anotherwidget.utils.openURI
|
||||
import kotlinx.android.synthetic.main.fragment_advanced_settings.*
|
||||
import kotlinx.coroutines.delay
|
||||
@ -86,7 +87,7 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
})
|
||||
|
||||
viewModel.showWallpaper.observe(viewLifecycleOwner, Observer {
|
||||
show_wallpaper_label.text = if (it && requireActivity().checkSelfPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
show_wallpaper_label.text = if (it && activity?.checkGrantedPermission(Manifest.permission.READ_EXTERNAL_STORAGE) == true) getString(R.string.settings_visible) else getString(R.string.settings_not_visible)
|
||||
})
|
||||
}
|
||||
|
||||
@ -136,15 +137,15 @@ class AdvancedSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
action_translate.setOnClickListener {
|
||||
requireActivity().openURI("https://github.com/tommasoberlose/another-widget/blob/master/app/src/main/res/values/strings.xml")
|
||||
activity?.openURI("https://github.com/tommasoberlose/another-widget/blob/master/app/src/main/res/values/strings.xml")
|
||||
}
|
||||
|
||||
action_website.setOnClickListener {
|
||||
requireActivity().openURI("http://tommasoberlose.com/")
|
||||
activity?.openURI("http://tommasoberlose.com/")
|
||||
}
|
||||
|
||||
action_feedback.setOnClickListener {
|
||||
requireActivity().openURI("https://github.com/tommasoberlose/another-widget/issues")
|
||||
activity?.openURI("https://github.com/tommasoberlose/another-widget/issues")
|
||||
}
|
||||
|
||||
action_help_dev.setOnClickListener {
|
||||
|
@ -208,7 +208,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
checkReadEventsPermission()
|
||||
}.show()
|
||||
} else {
|
||||
requireActivity().toast(getString(R.string.calendar_settings_list_error))
|
||||
activity?.toast(getString(R.string.calendar_settings_list_error))
|
||||
}
|
||||
}
|
||||
|
||||
@ -293,7 +293,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
|
||||
dialog.addOnSelectItemListener { value ->
|
||||
if (value == "-") {
|
||||
startActivity(Intent(requireActivity(), CustomDateActivity::class.java))
|
||||
startActivity(Intent(requireContext(), CustomDateActivity::class.java))
|
||||
} else {
|
||||
Preferences.dateFormat = value
|
||||
}
|
||||
@ -311,7 +311,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkReadEventsPermission(showEvents: Boolean = Preferences.showEvents) {
|
||||
if (requireActivity().checkGrantedPermission(Manifest.permission.READ_CALENDAR)) {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.READ_CALENDAR) == true) {
|
||||
show_events_label.text = if (showEvents) getString(R.string.show_events_visible) else getString(R.string.show_events_not_visible)
|
||||
read_calendar_permission_alert_icon.isVisible = false
|
||||
CalendarHelper.updateEventList(requireContext())
|
||||
@ -325,7 +325,7 @@ class CalendarSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun requirePermission() {
|
||||
Dexter.withContext(requireActivity())
|
||||
Dexter.withContext(requireContext())
|
||||
.withPermissions(
|
||||
Manifest.permission.READ_CALENDAR
|
||||
).withListener(object: MultiplePermissionsListener {
|
||||
|
@ -127,7 +127,7 @@ class ClockSettingsFragment : Fragment() {
|
||||
|
||||
action_clock_app.setOnClickListener {
|
||||
if (Preferences.showClock) {
|
||||
startActivityForResult(Intent(requireActivity(), ChooseApplicationActivity::class.java),
|
||||
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java),
|
||||
RequestCode.CLOCK_APP_REQUEST_CODE.code
|
||||
)
|
||||
}
|
||||
|
@ -22,8 +22,10 @@ import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import kotlinx.android.synthetic.main.fragment_general_settings.*
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
|
||||
class GeneralSettingsFragment : Fragment() {
|
||||
@ -33,6 +35,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var colors: IntArray
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
@ -59,6 +62,12 @@ class GeneralSettingsFragment : Fragment() {
|
||||
super.onActivityCreated(savedInstanceState)
|
||||
|
||||
setupListener()
|
||||
lifecycleScope.launch(Dispatchers.IO) {
|
||||
val lazyColors = requireContext().resources.getIntArray(R.array.material_colors)
|
||||
withContext(Dispatchers.Main) {
|
||||
colors = lazyColors
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -140,7 +149,7 @@ class GeneralSettingsFragment : Fragment() {
|
||||
Color.parseColor(Preferences.textGlobalColor)
|
||||
}
|
||||
BottomSheetColorPicker(requireContext(),
|
||||
colors = requireActivity().resources.getIntArray(R.array.grey),
|
||||
colors = colors,
|
||||
header = getString(R.string.settings_font_color_title),
|
||||
selected = textColor,
|
||||
onColorSelected = { color: Int ->
|
||||
|
@ -132,7 +132,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun checkLocationPermission() {
|
||||
if (requireActivity().checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION)) {
|
||||
if (activity?.checkGrantedPermission(Manifest.permission.ACCESS_FINE_LOCATION) == true) {
|
||||
location_permission_alert_icon.isVisible = false
|
||||
WeatherReceiver.setUpdates(requireContext())
|
||||
} else if (Preferences.showWeather && Preferences.customLocationAdd == "") {
|
||||
@ -228,7 +228,7 @@ class WeatherSettingsFragment : Fragment() {
|
||||
}
|
||||
|
||||
private fun requirePermission() {
|
||||
Dexter.withContext(requireActivity())
|
||||
Dexter.withContext(requireContext())
|
||||
.withPermissions(
|
||||
Manifest.permission.ACCESS_FINE_LOCATION
|
||||
).withListener(object: MultiplePermissionsListener {
|
||||
|
@ -49,13 +49,14 @@ class SupportDevViewModel : ViewModel() {
|
||||
fun handlePurchase(purchase: Purchase) {
|
||||
if (!purchase.isAcknowledged) {
|
||||
viewModelScope.launch(Dispatchers.IO) {
|
||||
val token = purchase.purchaseToken
|
||||
val acknowledgePurchaseParams = AcknowledgePurchaseParams.newBuilder()
|
||||
.setPurchaseToken(purchase.purchaseToken)
|
||||
.setPurchaseToken(token)
|
||||
billingClient.acknowledgePurchase(acknowledgePurchaseParams.build())
|
||||
|
||||
val consumeParams =
|
||||
ConsumeParams.newBuilder()
|
||||
.setPurchaseToken(purchase.purchaseToken)
|
||||
.setPurchaseToken(token)
|
||||
.build()
|
||||
billingClient.consumePurchase(consumeParams)
|
||||
}
|
||||
|
Reference in New Issue
Block a user