Fix #72
This commit is contained in:
parent
5ca06e817e
commit
0adf192965
app/src/main
java/com/tommasoberlose/anotherwidget
components
helpers
ui
res/layout
@ -16,6 +16,7 @@ import androidx.core.content.ContextCompat
|
|||||||
import androidx.core.view.isVisible
|
import androidx.core.view.isVisible
|
||||||
import androidx.core.widget.addTextChangedListener
|
import androidx.core.widget.addTextChangedListener
|
||||||
import androidx.recyclerview.widget.GridLayoutManager
|
import androidx.recyclerview.widget.GridLayoutManager
|
||||||
|
import androidx.recyclerview.widget.RecyclerView
|
||||||
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
import com.google.android.material.bottomsheet.BottomSheetBehavior
|
||||||
import com.google.android.material.bottomsheet.BottomSheetDialog
|
import com.google.android.material.bottomsheet.BottomSheetDialog
|
||||||
import com.google.android.material.card.MaterialCardView
|
import com.google.android.material.card.MaterialCardView
|
||||||
@ -79,61 +80,51 @@ class BottomSheetColorPicker(
|
|||||||
|
|
||||||
// List
|
// List
|
||||||
|
|
||||||
view.menu.setHasFixedSize(true)
|
|
||||||
val mLayoutManager = GridLayoutManager(context, 6)
|
|
||||||
view.menu.layoutManager = mLayoutManager
|
|
||||||
|
|
||||||
adapter = SlimAdapter.create()
|
adapter = SlimAdapter.create()
|
||||||
|
|
||||||
adapter
|
|
||||||
.register<Int>(R.layout.color_picker_menu_item) { item, injector ->
|
|
||||||
injector
|
|
||||||
.with<MaterialCardView>(R.id.color) {
|
|
||||||
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
val colorList = ColorStateList.valueOf(item)
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
it.setCardBackgroundColor(colorList)
|
|
||||||
}
|
|
||||||
})
|
|
||||||
}
|
|
||||||
.with<AppCompatImageView>(R.id.check) {
|
|
||||||
if (getSelected?.invoke() == item) {
|
|
||||||
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
|
|
||||||
val colorList = ContextCompat.getColor(
|
|
||||||
context,
|
|
||||||
if (item.isColorDark()) android.R.color.white else android.R.color.black
|
|
||||||
)
|
|
||||||
withContext(Dispatchers.Main) {
|
|
||||||
it.setColorFilter(
|
|
||||||
colorList,
|
|
||||||
android.graphics.PorterDuff.Mode.MULTIPLY
|
|
||||||
)
|
|
||||||
it.isVisible = true
|
|
||||||
}
|
|
||||||
})
|
|
||||||
} else {
|
|
||||||
it.isVisible = false
|
|
||||||
}
|
|
||||||
}
|
|
||||||
injector.clicked(R.id.color) {
|
|
||||||
adapter.notifyItemChanged(adapter.data.indexOf(getSelected?.invoke()))
|
|
||||||
onColorSelected?.invoke(item)
|
|
||||||
val position = adapter.data.indexOf(item)
|
|
||||||
adapter.notifyItemChanged(position)
|
|
||||||
(view.menu.layoutManager as GridLayoutManager).scrollToPositionWithOffset(position,0)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
.attachTo(view.menu)
|
|
||||||
|
|
||||||
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
|
loadingJobs.add(GlobalScope.launch(Dispatchers.IO) {
|
||||||
|
val listView = View.inflate(context, R.layout.bottom_sheet_menu_list, null) as RecyclerView
|
||||||
|
listView.setHasFixedSize(true)
|
||||||
|
val mLayoutManager = GridLayoutManager(context, 6)
|
||||||
|
listView.layoutManager = mLayoutManager
|
||||||
|
|
||||||
|
adapter
|
||||||
|
.register<Int>(R.layout.color_picker_menu_item) { item, injector ->
|
||||||
|
injector
|
||||||
|
.with<MaterialCardView>(R.id.color) {
|
||||||
|
it.setCardBackgroundColor(ColorStateList.valueOf(item))
|
||||||
|
}
|
||||||
|
.with<AppCompatImageView>(R.id.check) {
|
||||||
|
if (getSelected?.invoke() == item) {
|
||||||
|
it.setColorFilter(
|
||||||
|
ContextCompat.getColor(
|
||||||
|
context,
|
||||||
|
if (item.isColorDark()) android.R.color.white else android.R.color.black
|
||||||
|
),
|
||||||
|
android.graphics.PorterDuff.Mode.MULTIPLY
|
||||||
|
)
|
||||||
|
it.isVisible = true
|
||||||
|
} else {
|
||||||
|
it.isVisible = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.clicked(R.id.color) {
|
||||||
|
adapter.notifyItemChanged(adapter.data.indexOf(getSelected?.invoke()))
|
||||||
|
onColorSelected?.invoke(item)
|
||||||
|
val position = adapter.data.indexOf(item)
|
||||||
|
adapter.notifyItemChanged(position)
|
||||||
|
(listView.layoutManager as GridLayoutManager).scrollToPositionWithOffset(position,0)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
.attachTo(listView)
|
||||||
|
|
||||||
adapter.updateData(colors.toList())
|
adapter.updateData(colors.toList())
|
||||||
|
|
||||||
withContext(Dispatchers.Main) {
|
withContext(Dispatchers.Main) {
|
||||||
view.color_loader.isVisible = false
|
view.color_loader.isVisible = false
|
||||||
|
view.list_container.addView(listView)
|
||||||
this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
this@BottomSheetColorPicker.behavior.state = BottomSheetBehavior.STATE_EXPANDED
|
||||||
// this@BottomSheetColorPicker.behavior.isFitToContents = false
|
view.list_container.isVisible = true
|
||||||
view.menu.isVisible = true
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
@ -79,7 +79,7 @@ object IntentHelper {
|
|||||||
val calendarUri = CalendarContract.CONTENT_URI
|
val calendarUri = CalendarContract.CONTENT_URI
|
||||||
.buildUpon()
|
.buildUpon()
|
||||||
.appendPath("time")
|
.appendPath("time")
|
||||||
.appendPath("0".toString())
|
.appendPath(Calendar.getInstance().timeInMillis.toString())
|
||||||
.build()
|
.build()
|
||||||
return when (Preferences.calendarAppPackage) {
|
return when (Preferences.calendarAppPackage) {
|
||||||
"" -> {
|
"" -> {
|
||||||
@ -116,6 +116,8 @@ object IntentHelper {
|
|||||||
data = uri
|
data = uri
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, if (e.allDay) 1 else 0)
|
||||||
|
// type = "vnd.android.cursor.item/event"
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
getCalendarIntent(context).apply {
|
getCalendarIntent(context).apply {
|
||||||
@ -123,6 +125,8 @@ object IntentHelper {
|
|||||||
data = uri
|
data = uri
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, e.startDate)
|
||||||
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
putExtra(CalendarContract.EXTRA_EVENT_END_TIME, e.endDate)
|
||||||
|
putExtra(CalendarContract.EXTRA_EVENT_ALL_DAY, if (e.allDay) 1 else 0)
|
||||||
|
// type = "vnd.android.cursor.item/event"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -92,9 +92,6 @@ class MainActivity : AppCompatActivity(), SharedPreferences.OnSharedPreferenceCh
|
|||||||
subscribeUi(viewModel)
|
subscribeUi(viewModel)
|
||||||
updateUI()
|
updateUI()
|
||||||
|
|
||||||
WeatherHelper.updateWeather(this)
|
|
||||||
|
|
||||||
|
|
||||||
// Warnings
|
// Warnings
|
||||||
if (getString(R.string.xiaomi_manufacturer).equals(Build.MANUFACTURER, ignoreCase = true) && Preferences.showXiaomiWarning) {
|
if (getString(R.string.xiaomi_manufacturer).equals(Build.MANUFACTURER, ignoreCase = true) && Preferences.showXiaomiWarning) {
|
||||||
MaterialBottomSheetDialog(this, getString(R.string.xiaomi_warning_title), getString(R.string.xiaomi_warning_message))
|
MaterialBottomSheetDialog(this, getString(R.string.xiaomi_warning_title), getString(R.string.xiaomi_warning_message))
|
||||||
|
@ -29,6 +29,7 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
|||||||
import com.tommasoberlose.anotherwidget.ui.activities.SupportDevActivity
|
import com.tommasoberlose.anotherwidget.ui.activities.SupportDevActivity
|
||||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||||
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
import com.tommasoberlose.anotherwidget.helpers.CalendarHelper
|
||||||
|
import com.tommasoberlose.anotherwidget.helpers.WeatherHelper
|
||||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||||
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
|
||||||
import com.tommasoberlose.anotherwidget.utils.openURI
|
import com.tommasoberlose.anotherwidget.utils.openURI
|
||||||
@ -187,7 +188,7 @@ class AdvancedSettingsFragment : Fragment() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
action_refresh_widget.setOnClickListener {
|
action_refresh_widget.setOnClickListener {
|
||||||
MainWidget.updateWidget(requireContext())
|
WeatherHelper.updateWeather(requireContext())
|
||||||
CalendarHelper.updateEventList(requireContext())
|
CalendarHelper.updateEventList(requireContext())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -156,6 +156,9 @@ class CalendarSettingsFragment : Fragment() {
|
|||||||
|
|
||||||
action_show_events.setOnClickListener {
|
action_show_events.setOnClickListener {
|
||||||
Preferences.showEvents = !Preferences.showEvents
|
Preferences.showEvents = !Preferences.showEvents
|
||||||
|
if (Preferences.showEvents) {
|
||||||
|
requirePermission()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
action_filter_calendar.setOnClickListener {
|
action_filter_calendar.setOnClickListener {
|
||||||
|
@ -81,12 +81,14 @@ class WeatherSettingsFragment : Fragment() {
|
|||||||
) {
|
) {
|
||||||
viewModel.showWeatherWarning.observe(viewLifecycleOwner, Observer {
|
viewModel.showWeatherWarning.observe(viewLifecycleOwner, Observer {
|
||||||
weather_warning?.isVisible = it
|
weather_warning?.isVisible = it
|
||||||
|
checkLocationPermission()
|
||||||
})
|
})
|
||||||
|
|
||||||
viewModel.showWeather.observe(viewLifecycleOwner, Observer {
|
viewModel.showWeather.observe(viewLifecycleOwner, Observer {
|
||||||
maintainScrollPosition {
|
maintainScrollPosition {
|
||||||
show_weather_label?.text =
|
show_weather_label?.text =
|
||||||
if (it) getString(R.string.show_weather_visible) else getString(R.string.show_weather_not_visible)
|
if (it) getString(R.string.show_weather_visible) else getString(R.string.show_weather_not_visible)
|
||||||
|
checkWeatherProviderConfig()
|
||||||
binding.isWeatherVisible = it
|
binding.isWeatherVisible = it
|
||||||
}
|
}
|
||||||
checkLocationPermission()
|
checkLocationPermission()
|
||||||
@ -94,11 +96,7 @@ class WeatherSettingsFragment : Fragment() {
|
|||||||
|
|
||||||
viewModel.weatherProviderApi.observe(viewLifecycleOwner, Observer {
|
viewModel.weatherProviderApi.observe(viewLifecycleOwner, Observer {
|
||||||
maintainScrollPosition {
|
maintainScrollPosition {
|
||||||
label_weather_provider_api_key?.text =
|
checkWeatherProviderConfig()
|
||||||
if (it == "") getString(R.string.settings_weather_provider_api_key_subtitle_not_set) else getString(
|
|
||||||
R.string.settings_weather_provider_api_key_subtitle_all_set
|
|
||||||
)
|
|
||||||
label_weather_provider_api_key?.setTextColor(ContextCompat.getColor(requireContext(), if (it == "") R.color.errorColorText else R.color.colorSecondaryText))
|
|
||||||
}
|
}
|
||||||
checkLocationPermission()
|
checkLocationPermission()
|
||||||
})
|
})
|
||||||
@ -148,9 +146,19 @@ class WeatherSettingsFragment : Fragment() {
|
|||||||
location_permission_alert?.setOnClickListener {
|
location_permission_alert?.setOnClickListener {
|
||||||
requirePermission()
|
requirePermission()
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
location_permission_alert?.isVisible = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private fun checkWeatherProviderConfig() {
|
||||||
|
label_weather_provider_api_key?.text =
|
||||||
|
if (Preferences.weatherProviderApi == "") getString(R.string.settings_weather_provider_api_key_subtitle_not_set) else getString(
|
||||||
|
R.string.settings_weather_provider_api_key_subtitle_all_set
|
||||||
|
)
|
||||||
|
label_weather_provider_api_key?.setTextColor(ContextCompat.getColor(requireContext(), if (Preferences.weatherProviderApi == "" && Preferences.showWeather) R.color.errorColorText else R.color.colorSecondaryText))
|
||||||
|
}
|
||||||
|
|
||||||
private fun setupListener() {
|
private fun setupListener() {
|
||||||
action_hide_weather_warning.setOnClickListener {
|
action_hide_weather_warning.setOnClickListener {
|
||||||
Preferences.showWeatherWarning = false
|
Preferences.showWeatherWarning = false
|
||||||
|
@ -96,13 +96,11 @@
|
|||||||
<RelativeLayout
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content">
|
android:layout_height="wrap_content">
|
||||||
<androidx.recyclerview.widget.RecyclerView
|
<LinearLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="300dp"
|
android:layout_height="260dp"
|
||||||
android:id="@+id/menu"
|
android:id="@+id/list_container"
|
||||||
android:visibility="gone"
|
android:orientation="vertical" />
|
||||||
android:clipToPadding="false"
|
|
||||||
android:padding="16dp"/>
|
|
||||||
<ProgressBar
|
<ProgressBar
|
||||||
android:layout_width="32dp"
|
android:layout_width="32dp"
|
||||||
android:layout_height="32dp"
|
android:layout_height="32dp"
|
||||||
|
8
app/src/main/res/layout/bottom_sheet_menu_list.xml
Normal file
8
app/src/main/res/layout/bottom_sheet_menu_list.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<androidx.recyclerview.widget.RecyclerView
|
||||||
|
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="260dp"
|
||||||
|
android:id="@+id/menu"
|
||||||
|
android:clipToPadding="false"
|
||||||
|
android:padding="16dp"/>
|
@ -198,6 +198,7 @@
|
|||||||
android:paddingBottom="0dp"
|
android:paddingBottom="0dp"
|
||||||
android:paddingTop="0dp"
|
android:paddingTop="0dp"
|
||||||
android:focusable="true"
|
android:focusable="true"
|
||||||
|
android:visibility="gone"
|
||||||
android:id="@+id/location_permission_alert"
|
android:id="@+id/location_permission_alert"
|
||||||
android:textColor="@color/errorColorText"
|
android:textColor="@color/errorColorText"
|
||||||
android:text="@string/action_grant_permission"/>
|
android:text="@string/action_grant_permission"/>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user