This commit is contained in:
Tommaso Berlose
2020-05-16 12:47:29 +02:00
parent b04b103634
commit b81461f725
18 changed files with 59 additions and 33 deletions

View File

@ -76,7 +76,9 @@ class MainActivity : AppCompatActivity() {
viewModel = ViewModelProvider(this).get(MainViewModel::class.java)
controlExtras(intent)
requirePermission()
if (Preferences.showWallpaper) {
requirePermission()
}
}
override fun onBackPressed() {

View File

@ -321,7 +321,7 @@ class GeneralTabFragment : Fragment() {
}
action_show_dividers.setOnClickListener {
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_multiple_events_title)).setSelectedValue(Preferences.showDividers)
BottomSheetMenu<Boolean>(requireContext(), header = getString(R.string.settings_show_dividers_title)).setSelectedValue(Preferences.showDividers)
.addItem(getString(R.string.settings_visible), true)
.addItem(getString(R.string.settings_not_visible), false)
.addOnSelectItemListener { value ->

View File

@ -145,7 +145,7 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
ColorHelper.getBackgroundColor()
)
)
uiJob = viewLifecycleOwner.lifecycleScope.launch(Dispatchers.IO) {
uiJob = lifecycleScope.launch(Dispatchers.IO) {
val generatedView = MainWidget.generateWidgetView(requireContext())
withContext(Dispatchers.Main) {
@ -230,10 +230,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
).apply {
duration = 500L
addUpdateListener {
val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams
layoutParams.height = animatedValue
preview.layoutParams = layoutParams
if (preview != null) {
val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams
layoutParams.height = animatedValue
preview.layoutParams = layoutParams
}
}
}.start()
}
@ -253,10 +255,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
).apply {
duration = 300L
addUpdateListener {
val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams
layoutParams.height = animatedValue
preview?.layoutParams = layoutParams
if (preview != null) {
val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams
layoutParams.height = animatedValue
preview?.layoutParams = layoutParams
}
}
}.start()
}
@ -264,8 +268,8 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
widget_loader?.animate()?.scaleX(0f)?.scaleY(0f)?.alpha(0f)?.setDuration(200L)?.start()
bitmap_container?.apply {
setImageBitmap(bitmap)
scaleX = 0.9f
scaleY = 0.9f
// scaleX = 0.9f
// scaleY = 0.9f
}
widget?.animate()?.alpha(1f)?.start()
}
@ -278,10 +282,12 @@ class MainFragment : Fragment(), SharedPreferences.OnSharedPreferenceChangeList
).apply {
duration = 300L
addUpdateListener {
val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams
layoutParams.height = animatedValue
preview.layoutParams = layoutParams
if (preview != null) {
val animatedValue = animatedValue as Int
val layoutParams = preview.layoutParams
layoutParams.height = animatedValue
preview.layoutParams = layoutParams
}
}
}.start()
}

View File

@ -36,6 +36,7 @@ import java.text.DateFormat
import java.util.*
import java.util.concurrent.TimeUnit
import kotlin.math.min
import kotlin.math.roundToInt
class MainWidget : AppWidgetProvider() {
@ -140,9 +141,8 @@ class MainWidget : AppWidgetProvider() {
}
private fun updateCalendarView(context: Context, v: View, views: RemoteViews, widgetID: Int): RemoteViews {
val eventRepository = EventRepository(context)
try {
val eventRepository = EventRepository(context)
views.setImageViewBitmap(
R.id.empty_date_rect,
BitmapHelper.getBitmapFromView(v.empty_date, draw = false)
@ -340,6 +340,8 @@ class MainWidget : AppWidgetProvider() {
} catch (ex: Exception) {
ex.printStackTrace()
CrashlyticsReceiver.sendCrash(context, ex)
} finally {
eventRepository.close()
}
return views
@ -698,7 +700,7 @@ class MainWidget : AppWidgetProvider() {
v.weather.visibility = View.VISIBLE
v.calendar_weather.visibility = View.VISIBLE
v.special_weather.visibility = View.VISIBLE
val currentTemp = String.format(Locale.getDefault(), "%.0f °%s", Preferences.weatherTemp, Preferences.weatherRealTempUnit)
val currentTemp = String.format(Locale.getDefault(), "%d °%s", Preferences.weatherTemp.roundToInt(), Preferences.weatherRealTempUnit)
val icon: String = Preferences.weatherIcon
if (icon == "") {
@ -734,6 +736,8 @@ class MainWidget : AppWidgetProvider() {
it.isVisible = Preferences.showDividers
}
eventRepository.close()
return v
}
}