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.helpers.CalendarHelper
import com.tommasoberlose.anotherwidget.helpers.DateHelper
import com.tommasoberlose.anotherwidget.helpers.IntentHelper
import com.tommasoberlose.anotherwidget.helpers.SettingsStringHelper
import com.tommasoberlose.anotherwidget.ui.activities.CustomDateActivity
import com.tommasoberlose.anotherwidget.utils.checkGrantedPermission
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import com.tommasoberlose.anotherwidget.utils.toast
import kotlinx.android.synthetic.main.fragment_calendar_settings.*
import kotlinx.android.synthetic.main.fragment_calendar_settings.scrollView
@ -157,7 +159,18 @@ class CalendarTabFragment : Fragment() {
viewModel.calendarAppName.observe(viewLifecycleOwner, Observer {
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.MainActivity
import com.tommasoberlose.anotherwidget.ui.viewmodels.MainViewModel
import com.tommasoberlose.anotherwidget.utils.isDefaultSet
import kotlinx.android.synthetic.main.fragment_clock_settings.*
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.delay
@ -155,17 +156,17 @@ class ClockTabFragment : Fragment() {
viewModel.clockAppName.observe(viewLifecycleOwner, Observer {
maintainScrollPosition {
clock_app_label?.text = try {
with(requireContext().packageManager) {
Log.d("ciao", "app: ${IntentHelper.getClockIntent(requireContext()).resolveActivity(this)}")
if (IntentHelper.getClockIntent(requireContext()).resolveActivity(this) == null)
throw Exception()
clock_app_label?.text = when {
Preferences.clockAppName != "" -> Preferences.clockAppName
else -> {
if (IntentHelper.getClockIntent(requireContext()).isDefaultSet(requireContext())) {
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

@ -222,3 +222,12 @@ fun Context.checkIfFitInstalled(): Boolean {
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="settings_title_integrations">Integrations</string>
<string name="label_count_installed_integrations">%d installed integrations</string>
<string name="nothing">Nothing</string>
</resources>