Fix #259
@ -15,6 +15,7 @@ import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.bumptech.glide.Glide
|
||||
import com.google.android.material.card.MaterialCardView
|
||||
import com.tommasoberlose.anotherwidget.databinding.ActivityChooseApplicationBinding
|
||||
import com.tommasoberlose.anotherwidget.global.Constants
|
||||
import com.tommasoberlose.anotherwidget.helpers.IntentHelper
|
||||
@ -30,9 +31,13 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
private lateinit var viewModel: ChooseApplicationViewModel
|
||||
private lateinit var binding: ActivityChooseApplicationBinding
|
||||
|
||||
private var selectedPackage: String? = null
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
selectedPackage = intent.extras?.getString(Constants.RESULT_APP_PACKAGE)
|
||||
|
||||
viewModel = ViewModelProvider(this).get(ChooseApplicationViewModel::class.java)
|
||||
binding = ActivityChooseApplicationBinding.inflate(layoutInflater)
|
||||
|
||||
@ -60,6 +65,10 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
.with<MaterialCardView>(R.id.item) {
|
||||
it.strokeColor = ContextCompat.getColor(this, if (selectedPackage == IntentHelper.DO_NOTHING_OPTION) R.color.colorAccent else R.color.cardBorder)
|
||||
it.setCardBackgroundColor(ContextCompat.getColor(this, if (selectedPackage == IntentHelper.DO_NOTHING_OPTION) R.color.colorAccent_op10 else R.color.colorPrimaryDark))
|
||||
}
|
||||
}
|
||||
IntentHelper.REFRESH_WIDGET_OPTION -> {
|
||||
injector
|
||||
@ -77,6 +86,10 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
.with<MaterialCardView>(R.id.item) {
|
||||
it.strokeColor = ContextCompat.getColor(this, if (selectedPackage == IntentHelper.REFRESH_WIDGET_OPTION) R.color.colorAccent else R.color.cardBorder)
|
||||
it.setCardBackgroundColor(ContextCompat.getColor(this, if (selectedPackage == IntentHelper.REFRESH_WIDGET_OPTION) R.color.colorAccent_op10 else R.color.colorPrimaryDark))
|
||||
}
|
||||
}
|
||||
else -> {
|
||||
injector
|
||||
@ -94,6 +107,10 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
setResult(Activity.RESULT_OK, resultIntent)
|
||||
finish()
|
||||
}
|
||||
.with<MaterialCardView>(R.id.item) {
|
||||
it.strokeColor = ContextCompat.getColor(this, if (selectedPackage == IntentHelper.DEFAULT_OPTION) R.color.colorAccent else R.color.cardBorder)
|
||||
it.setCardBackgroundColor(ContextCompat.getColor(this, if (selectedPackage == IntentHelper.DEFAULT_OPTION) R.color.colorAccent_op10 else R.color.colorPrimaryDark))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -107,10 +124,13 @@ class ChooseApplicationActivity : AppCompatActivity() {
|
||||
.centerCrop()
|
||||
.into(it)
|
||||
}
|
||||
|
||||
injector.clicked(R.id.item) {
|
||||
saveApp(item)
|
||||
}
|
||||
.clicked(R.id.item) {
|
||||
saveApp(item)
|
||||
}
|
||||
.with<MaterialCardView>(R.id.item) {
|
||||
it.strokeColor = ContextCompat.getColor(this, if (selectedPackage == item.activityInfo.packageName) R.color.colorAccent else R.color.cardBorder)
|
||||
it.setCardBackgroundColor(ContextCompat.getColor(this, if (selectedPackage == item.activityInfo.packageName) R.color.colorAccent_op10 else R.color.colorPrimaryDark))
|
||||
}
|
||||
}
|
||||
.attachTo(binding.listView)
|
||||
|
||||
|
@ -281,26 +281,6 @@ class CalendarFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK) {
|
||||
when (requestCode) {
|
||||
RequestCode.CALENDAR_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
calendarAppName = data?.getStringExtra(Constants.RESULT_APP_NAME) ?: getString(R.string.default_calendar_app)
|
||||
calendarAppPackage = data?.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: ""
|
||||
}
|
||||
}
|
||||
RequestCode.EVENT_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
eventAppName = data?.getStringExtra(Constants.RESULT_APP_NAME) ?: getString(R.string.default_event_app)
|
||||
eventAppPackage = data?.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: ""
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
private fun maintainScrollPosition(callback: () -> Unit) {
|
||||
binding.scrollView.isScrollable = false
|
||||
callback.invoke()
|
||||
|
@ -180,16 +180,6 @@ class ClockFragment : Fragment() {
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK && requestCode == RequestCode.CLOCK_APP_REQUEST_CODE.code) {
|
||||
Preferences.bulk {
|
||||
clockAppName = data?.getStringExtra(Constants.RESULT_APP_NAME) ?: getString(R.string.default_clock_app)
|
||||
clockAppPackage = data?.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: ""
|
||||
}
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
|
||||
override fun onResume() {
|
||||
binding.is24Format = DateFormat.is24HourFormat(requireContext())
|
||||
super.onResume()
|
||||
|
@ -1,6 +1,7 @@
|
||||
package com.tommasoberlose.anotherwidget.ui.fragments.tabs
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.view.LayoutInflater
|
||||
@ -12,6 +13,7 @@ import androidx.lifecycle.Observer
|
||||
import androidx.lifecycle.ViewModelProvider
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
import com.chibatching.kotpref.blockingBulk
|
||||
import com.chibatching.kotpref.bulk
|
||||
import com.google.android.material.transition.MaterialSharedAxis
|
||||
import com.tommasoberlose.anotherwidget.R
|
||||
import com.tommasoberlose.anotherwidget.components.BottomSheetColorPicker
|
||||
@ -30,6 +32,7 @@ import com.tommasoberlose.anotherwidget.ui.activities.tabs.CustomDateActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.activities.tabs.ChooseApplicationActivity
|
||||
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
|
||||
import com.tommasoberlose.anotherwidget.ui.widgets.MainWidget
|
||||
import com.tommasoberlose.anotherwidget.utils.isDarkTheme
|
||||
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
@ -45,7 +48,6 @@ class GesturesFragment : Fragment() {
|
||||
}
|
||||
|
||||
private lateinit var viewModel: MainViewModel
|
||||
private lateinit var colors: IntArray
|
||||
private lateinit var binding: FragmentTabGesturesBinding
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
@ -97,14 +99,16 @@ class GesturesFragment : Fragment() {
|
||||
viewModel.calendarAppName.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.calendarAppLabel.text = when {
|
||||
Preferences.calendarAppName != "" -> Preferences.calendarAppName
|
||||
it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing)
|
||||
it == IntentHelper.REFRESH_WIDGET_OPTION -> "None, the widget will be refreshed"
|
||||
it != IntentHelper.DEFAULT_OPTION -> it
|
||||
else -> {
|
||||
if (IntentHelper.getCalendarIntent(requireContext()).isDefaultSet(requireContext())) {
|
||||
getString(
|
||||
R.string.default_calendar_app
|
||||
)
|
||||
} else {
|
||||
getString(R.string.nothing)
|
||||
getString(R.string.gestures_do_nothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -120,14 +124,16 @@ class GesturesFragment : Fragment() {
|
||||
viewModel.clockAppName.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.clockAppLabel.text = when {
|
||||
Preferences.clockAppName != "" -> Preferences.clockAppName
|
||||
it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing)
|
||||
it == IntentHelper.REFRESH_WIDGET_OPTION -> "None, the widget will be refreshed"
|
||||
it != IntentHelper.DEFAULT_OPTION -> it
|
||||
else -> {
|
||||
if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) {
|
||||
getString(
|
||||
R.string.default_clock_app
|
||||
)
|
||||
} else {
|
||||
getString(R.string.nothing)
|
||||
getString(R.string.gestures_do_nothing)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -136,8 +142,12 @@ class GesturesFragment : Fragment() {
|
||||
|
||||
viewModel.weatherAppName.observe(viewLifecycleOwner) {
|
||||
maintainScrollPosition {
|
||||
binding.weatherAppLabel.text =
|
||||
if (it != "") it else getString(R.string.default_weather_app)
|
||||
binding.weatherAppLabel.text = when {
|
||||
it == IntentHelper.DO_NOTHING_OPTION -> getString(R.string.gestures_do_nothing)
|
||||
it == IntentHelper.REFRESH_WIDGET_OPTION -> "None, the widget will be refreshed"
|
||||
it != IntentHelper.DEFAULT_OPTION -> it
|
||||
else -> getString(R.string.default_weather_app)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -163,19 +173,25 @@ class GesturesFragment : Fragment() {
|
||||
}
|
||||
|
||||
binding.actionCalendarApp.setOnClickListener {
|
||||
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java), RequestCode.CALENDAR_APP_REQUEST_CODE.code)
|
||||
startActivityForResult(Intent(requireContext(), ChooseApplicationActivity::class.java).apply {
|
||||
putExtra(Constants.RESULT_APP_PACKAGE, Preferences.calendarAppPackage)
|
||||
}, RequestCode.CALENDAR_APP_REQUEST_CODE.code)
|
||||
}
|
||||
|
||||
binding.actionClockApp.setOnClickListener {
|
||||
startActivityForResult(
|
||||
Intent(requireContext(), ChooseApplicationActivity::class.java),
|
||||
Intent(requireContext(), ChooseApplicationActivity::class.java).apply {
|
||||
putExtra(Constants.RESULT_APP_PACKAGE, Preferences.clockAppPackage)
|
||||
},
|
||||
RequestCode.CLOCK_APP_REQUEST_CODE.code
|
||||
)
|
||||
}
|
||||
|
||||
binding.actionWeatherApp.setOnClickListener {
|
||||
startActivityForResult(
|
||||
Intent(requireContext(), ChooseApplicationActivity::class.java),
|
||||
Intent(requireContext(), ChooseApplicationActivity::class.java).apply {
|
||||
putExtra(Constants.RESULT_APP_PACKAGE, Preferences.weatherAppPackage)
|
||||
},
|
||||
RequestCode.WEATHER_APP_REQUEST_CODE.code
|
||||
)
|
||||
}
|
||||
@ -189,4 +205,37 @@ class GesturesFragment : Fragment() {
|
||||
binding.scrollView.isScrollable = true
|
||||
}
|
||||
}
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
if (resultCode == Activity.RESULT_OK && data != null && data.hasExtra(Constants.RESULT_APP_NAME) && data.hasExtra(Constants.RESULT_APP_PACKAGE)) {
|
||||
when (requestCode) {
|
||||
RequestCode.CALENDAR_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
calendarAppName = data.getStringExtra(Constants.RESULT_APP_NAME) ?: IntentHelper.DEFAULT_OPTION
|
||||
calendarAppPackage = data.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: IntentHelper.DEFAULT_OPTION
|
||||
}
|
||||
}
|
||||
RequestCode.EVENT_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
eventAppName = data.getStringExtra(Constants.RESULT_APP_NAME) ?: IntentHelper.DEFAULT_OPTION
|
||||
eventAppPackage = data.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: IntentHelper.DEFAULT_OPTION
|
||||
}
|
||||
}
|
||||
RequestCode.WEATHER_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
weatherAppName = data.getStringExtra(Constants.RESULT_APP_NAME) ?: IntentHelper.DEFAULT_OPTION
|
||||
weatherAppPackage = data.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: IntentHelper.DEFAULT_OPTION
|
||||
}
|
||||
}
|
||||
RequestCode.CLOCK_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
clockAppName = data.getStringExtra(Constants.RESULT_APP_NAME) ?: IntentHelper.DEFAULT_OPTION
|
||||
clockAppPackage = data.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: IntentHelper.DEFAULT_OPTION
|
||||
}
|
||||
}
|
||||
}
|
||||
MainWidget.updateWidget(requireContext())
|
||||
}
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
}
|
||||
}
|
||||
|
@ -209,13 +209,6 @@ class WeatherFragment : Fragment() {
|
||||
WeatherReceiver.setUpdates(requireContext())
|
||||
checkLocationPermission()
|
||||
}
|
||||
RequestCode.WEATHER_APP_REQUEST_CODE.code -> {
|
||||
Preferences.bulk {
|
||||
weatherAppName = data?.getStringExtra(Constants.RESULT_APP_NAME) ?: getString(R.string.default_weather_app)
|
||||
weatherAppPackage = data?.getStringExtra(Constants.RESULT_APP_PACKAGE) ?: ""
|
||||
}
|
||||
MainWidget.updateWidget(requireContext())
|
||||
}
|
||||
RequestCode.WEATHER_PROVIDER_REQUEST_CODE.code -> {
|
||||
checkLocationPermission()
|
||||
}
|
||||
|
Before Width: | Height: | Size: 546 B After Width: | Height: | Size: 546 B |
Before Width: | Height: | Size: 384 B After Width: | Height: | Size: 384 B |
Before Width: | Height: | Size: 601 B After Width: | Height: | Size: 601 B |
Before Width: | Height: | Size: 1.0 KiB After Width: | Height: | Size: 1.0 KiB |
Before Width: | Height: | Size: 1.2 KiB After Width: | Height: | Size: 1.2 KiB |
@ -21,8 +21,8 @@
|
||||
<LinearLayout
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:paddingBottom="8dp"
|
||||
android:paddingTop="8dp"
|
||||
android:paddingBottom="4dp"
|
||||
android:paddingTop="4dp"
|
||||
android:orientation="horizontal"
|
||||
android:gravity="center_vertical|start">
|
||||
<ImageView
|
||||
|