This commit is contained in:
Tommaso Berlose 2020-05-22 18:30:38 +02:00
parent 9e40586456
commit 0d2287dbdf
4 changed files with 35 additions and 11 deletions

View File

@ -32,9 +32,11 @@ import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
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.DateHelper import com.tommasoberlose.anotherwidget.helpers.DateHelper
import com.tommasoberlose.anotherwidget.helpers.IntentHelper
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import com.tommasoberlose.anotherwidget.utils.toast import com.tommasoberlose.anotherwidget.utils.toast
import kotlinx.android.synthetic.main.fragment_calendar_settings.* import kotlinx.android.synthetic.main.fragment_calendar_settings.*
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
@ -157,7 +159,18 @@ class CalendarTabFragment : Fragment() {
viewModel.calendarAppName.observe(viewLifecycleOwner, Observer { viewModel.calendarAppName.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
calendar_app_label?.text = if (it != "") it else getString(R.string.default_calendar_app) calendar_app_label?.text = when {
Preferences.clockAppName != "" -> Preferences.clockAppName
else -> {
if (IntentHelper.getCalendarIntent(requireContext()).isDefaultSet(requireContext())) {
getString(
R.string.default_calendar_app
)
} else {
getString(R.string.nothing)
}
}
}
} }
}) })

View File

@ -36,6 +36,7 @@ import com.tommasoberlose.anotherwidget.helpers.IntentHelper
import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity import com.tommasoberlose.anotherwidget.ui.activities.ChooseApplicationActivity
import com.tommasoberlose.anotherwidget.ui.activities.MainActivity import com.tommasoberlose.anotherwidget.ui.activities.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import kotlinx.android.synthetic.main.fragment_clock_settings.* import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay import kotlinx.coroutines.delay
@ -155,17 +156,17 @@ class ClockTabFragment : Fragment() {
viewModel.clockAppName.observe(viewLifecycleOwner, Observer { viewModel.clockAppName.observe(viewLifecycleOwner, Observer {
maintainScrollPosition { maintainScrollPosition {
clock_app_label?.text = try { clock_app_label?.text = when {
with(requireContext().packageManager) { Preferences.clockAppName != "" -> Preferences.clockAppName
Log.d("ciao", "app: ${IntentHelper.getClockIntent(requireContext()).resolveActivity(this)}") else -> {
if (IntentHelper.getClockIntent(requireContext()).resolveActivity(this) == null) if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) {
throw Exception() getString(
R.string.default_clock_app
)
} else {
getString(R.string.nothing)
}
} }
if (Preferences.clockAppName != "") Preferences.clockAppName else getString(
R.string.default_clock_app
)
} catch (ex: Exception) {
"Nothing"
} }
} }
}) })

View File

@ -221,4 +221,13 @@ fun Context.checkIfFitInstalled(): Boolean {
} catch (e: Exception) { } catch (e: Exception) {
false false
} }
}
fun Intent.isDefaultSet(context: Context): Boolean {
val pm = context.packageManager
return try {
resolveActivity(pm) != null && resolveActivity(pm).packageName.isNotBlank()
} catch (ex: java.lang.Exception) {
false
}
} }

View File

@ -206,4 +206,5 @@
<string name="support_dev_subtitle">This is a single developer project,\nso thank you for the support!</string> <string name="support_dev_subtitle">This is a single developer project,\nso thank you for the support!</string>
<string name="settings_title_integrations">Integrations</string> <string name="settings_title_integrations">Integrations</string>
<string name="label_count_installed_integrations">%d installed integrations</string> <string name="label_count_installed_integrations">%d installed integrations</string>
<string name="nothing">Nothing</string>
</resources> </resources>