mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2026-03-18 15:36:04 +00:00
Imperial units (#24)
- change location retrieval accuracy - change location retrieval caching from location provider - expand unit test suite - code refactoring - Imperial units added - UI test for unit change
This commit is contained in:
@@ -16,22 +16,22 @@ import kotlinx.android.synthetic.main.fragment_home.swipe_refresh
|
||||
|
||||
class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
|
||||
|
||||
private var param1: String? = null
|
||||
private var retrievedLocationName: String? = null
|
||||
|
||||
private lateinit var recyclerAdapter: WeatherRecyclerAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
param1 = WorldItemFragmentArgs.fromBundle(requireArguments()).locationName
|
||||
param1?.let { viewModel.setLocation(it) }
|
||||
retrievedLocationName = WorldItemFragmentArgs.fromBundle(requireArguments()).locationName
|
||||
retrievedLocationName?.let { viewModel.setLocation(it) }
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
recyclerAdapter = WeatherRecyclerAdapter {
|
||||
val directions =
|
||||
WorldItemFragmentDirections.actionWorldItemFragmentToFurtherDetailsFragment(it)
|
||||
val directions = WorldItemFragmentDirections
|
||||
.actionWorldItemFragmentToFurtherDetailsFragment(it)
|
||||
navigateTo(directions)
|
||||
}
|
||||
|
||||
@@ -42,14 +42,14 @@ class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
|
||||
|
||||
swipe_refresh.apply {
|
||||
setOnRefreshListener {
|
||||
param1?.let {
|
||||
retrievedLocationName?.let {
|
||||
viewModel.fetchDataForSingleLocation(it)
|
||||
isRefreshing = true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
param1?.let { viewModel.getSingleLocation(it) }
|
||||
retrievedLocationName?.let { viewModel.getSingleLocation(it) }
|
||||
}
|
||||
|
||||
override fun onSuccess(data: Any?) {
|
||||
|
||||
@@ -1,46 +1,24 @@
|
||||
package com.appttude.h_mal.monoWeather.ui.settings
|
||||
|
||||
import android.appwidget.AppWidgetManager
|
||||
import android.content.ComponentName
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.PreferenceManager
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.widget.NewAppWidget
|
||||
import com.appttude.h_mal.atlas_weather.base.BasePreferencesFragment
|
||||
import com.appttude.h_mal.atlas_weather.utils.displayToast
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.SettingsViewModel
|
||||
|
||||
class SettingsFragment : PreferenceFragmentCompat() {
|
||||
class SettingsFragment : BasePreferencesFragment<SettingsViewModel>(R.xml.prefs_screen) {
|
||||
|
||||
override fun onCreatePreferences(savedInstanceState: Bundle?, rootKey: String?) {
|
||||
setPreferencesFromResource(R.xml.prefs_screen, rootKey)
|
||||
|
||||
//listener on changed sort order preference:
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(requireContext())
|
||||
prefs.registerOnSharedPreferenceChangeListener { _, key ->
|
||||
if (key == "temp_units") {
|
||||
val intent = Intent(requireContext(), NewAppWidget::class.java)
|
||||
intent.action = AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
val ids = AppWidgetManager.getInstance(requireContext())
|
||||
.getAppWidgetIds(ComponentName(requireContext(), NewAppWidget::class.java))
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
||||
requireContext().sendBroadcast(intent)
|
||||
}
|
||||
|
||||
if (key == "widget_black_background") {
|
||||
val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
|
||||
val widgetManager = AppWidgetManager.getInstance(requireContext())
|
||||
val ids =
|
||||
widgetManager.getAppWidgetIds(
|
||||
ComponentName(
|
||||
requireContext(),
|
||||
NewAppWidget::class.java
|
||||
)
|
||||
)
|
||||
AppWidgetManager.getInstance(requireContext())
|
||||
.notifyAppWidgetViewDataChanged(ids, R.id.whole_widget_view)
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
||||
requireContext().sendBroadcast(intent)
|
||||
override fun preferenceChanged(key: String) {
|
||||
when (key) {
|
||||
"UnitType" -> viewModel.refreshWeatherData()
|
||||
"widget_black_background" -> {
|
||||
viewModel.updateWidget()
|
||||
displayToast("Widget background has been updates")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
override fun onSuccess(data: Any?) {
|
||||
super.onSuccess(data)
|
||||
if (data is String) displayToast(data)
|
||||
}
|
||||
}
|
||||
@@ -23,8 +23,8 @@
|
||||
android:layout_height="32dp"
|
||||
android:layout_marginEnd="12dp"
|
||||
android:contentDescription="@string/image_string"
|
||||
app:tint="@color/colorAccent"
|
||||
app:srcCompat="@drawable/maps_and_flags" />
|
||||
app:srcCompat="@drawable/maps_and_flags"
|
||||
app:tint="@color/colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/location_main_4"
|
||||
@@ -51,11 +51,11 @@
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="9dp"
|
||||
android:text="@string/degrees_c"
|
||||
android:textSize="24sp"
|
||||
android:textStyle="bold"
|
||||
app:layout_constraintLeft_toRightOf="@id/temp_main_4"
|
||||
app:layout_constraintTop_toTopOf="@id/temp_main_4" />
|
||||
app:layout_constraintTop_toTopOf="@id/temp_main_4"
|
||||
tools:text="@string/degrees_c" />
|
||||
|
||||
<ImageView
|
||||
android:id="@+id/icon_main_4"
|
||||
@@ -64,11 +64,11 @@
|
||||
android:layout_marginTop="6dp"
|
||||
android:layout_marginBottom="12dp"
|
||||
android:contentDescription="@string/image_string"
|
||||
app:tint="@color/colorAccent"
|
||||
app:layout_constraintLeft_toLeftOf="parent"
|
||||
app:layout_constraintRight_toRightOf="parent"
|
||||
app:layout_constraintTop_toBottomOf="@id/temp_main_4"
|
||||
app:srcCompat="@drawable/cloud_symbol" />
|
||||
app:srcCompat="@drawable/cloud_symbol"
|
||||
app:tint="@color/colorAccent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/condition_main_4"
|
||||
|
||||
@@ -1,10 +1,17 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<ListPreference
|
||||
android:title="@string/weather_units"
|
||||
android:entries="@array/units"
|
||||
android:entryValues="@array/units"
|
||||
android:defaultValue="Metric"
|
||||
android:key="UnitType"
|
||||
/>
|
||||
<PreferenceCategory android:title="Widget Settings">
|
||||
<SwitchPreference
|
||||
android:defaultValue="false"
|
||||
android:key="widget_black_background"
|
||||
android:key="@string/widget_black_background"
|
||||
android:title="Set widget background black" />
|
||||
</PreferenceCategory>
|
||||
</PreferenceScreen>
|
||||
Reference in New Issue
Block a user