mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2026-03-18 15:36:04 +00:00
Test suite expansion (#20)
- Code inspection - Redundant resources removed - Resources moved the corresponding flavours - Deprecated dependencies upgraded - lint changes - circleci updated to capture screenshot - Testsuite expansion
This commit is contained in:
@@ -12,10 +12,12 @@ class EmptyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
var bodyTV: TextView = itemView.findViewById(R.id.body_text)
|
||||
var headerTV: TextView = itemView.findViewById(R.id.header_text)
|
||||
|
||||
fun bindData(@DrawableRes imageRes: Int?, header: String, body: String) {
|
||||
imageRes?.let { icon.setImageResource(it) }
|
||||
headerTV.text = header
|
||||
bodyTV.text = body
|
||||
|
||||
}
|
||||
fun bindData(
|
||||
@DrawableRes imageRes: Int? = R.drawable.ic_baseline_cloud_off_24,
|
||||
header: String = itemView.resources.getString(R.string.retrieve_warning),
|
||||
body: String = itemView.resources.getString(R.string.empty_retrieve_warning) ){
|
||||
imageRes?.let { icon.setImageResource(it) }
|
||||
headerTV.text = header
|
||||
bodyTV.text = body
|
||||
}
|
||||
}
|
||||
@@ -3,43 +3,38 @@ package com.appttude.h_mal.monoWeather.ui
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.Observer
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
|
||||
import com.appttude.h_mal.atlas_weather.ui.BaseFragment
|
||||
import com.appttude.h_mal.atlas_weather.utils.navigateTo
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
|
||||
import com.appttude.h_mal.monoWeather.ui.home.adapter.WeatherRecyclerAdapter
|
||||
import kotlinx.android.synthetic.main.fragment_home.forecast_listview
|
||||
import kotlinx.android.synthetic.main.fragment_home.progressBar
|
||||
import kotlinx.android.synthetic.main.fragment_home.swipe_refresh
|
||||
|
||||
|
||||
class WorldItemFragment : BaseFragment(R.layout.fragment_home) {
|
||||
class WorldItemFragment : BaseFragment<WorldViewModel>(R.layout.fragment_home) {
|
||||
|
||||
private val viewModel by getFragmentViewModel<WorldViewModel>()
|
||||
private var param1: 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) }
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val recyclerAdapter = WeatherRecyclerAdapter {
|
||||
recyclerAdapter = WeatherRecyclerAdapter {
|
||||
val directions =
|
||||
WorldItemFragmentDirections.actionWorldItemFragmentToFurtherDetailsFragment(it)
|
||||
navigateTo(directions)
|
||||
}
|
||||
|
||||
param1?.let { viewModel.getSingleLocation(it) }
|
||||
|
||||
viewModel.singleWeatherLiveData.observe(viewLifecycleOwner, Observer {
|
||||
recyclerAdapter.addCurrent(it)
|
||||
swipe_refresh.isRefreshing = false
|
||||
})
|
||||
|
||||
forecast_listview.apply {
|
||||
layoutManager = LinearLayoutManager(context)
|
||||
adapter = recyclerAdapter
|
||||
@@ -54,9 +49,19 @@ class WorldItemFragment : BaseFragment(R.layout.fragment_home) {
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.operationState.observe(viewLifecycleOwner, progressBarStateObserver(progressBar))
|
||||
viewModel.operationError.observe(viewLifecycleOwner, errorObserver())
|
||||
viewModel.operationRefresh.observe(viewLifecycleOwner, refreshObserver(swipe_refresh))
|
||||
param1?.let { viewModel.getSingleLocation(it) }
|
||||
}
|
||||
|
||||
override fun onSuccess(data: Any?) {
|
||||
if (data is WeatherDisplay) {
|
||||
recyclerAdapter.addCurrent(data)
|
||||
}
|
||||
super.onSuccess(data)
|
||||
swipe_refresh.isRefreshing = false
|
||||
}
|
||||
|
||||
override fun onFailure(error: Any?) {
|
||||
super.onFailure(error)
|
||||
swipe_refresh.isRefreshing = false
|
||||
}
|
||||
}
|
||||
@@ -13,10 +13,11 @@ import androidx.navigation.ui.onNavDestinationSelected
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.application.LOCATION_PERMISSION_REQUEST
|
||||
import com.appttude.h_mal.atlas_weather.model.forecast.Forecast
|
||||
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
|
||||
import com.appttude.h_mal.atlas_weather.utils.navigateTo
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.MainViewModel
|
||||
import com.appttude.h_mal.monoWeather.dialog.PermissionsDeclarationDialog
|
||||
import com.appttude.h_mal.monoWeather.ui.BaseFragment
|
||||
import com.appttude.h_mal.atlas_weather.ui.BaseFragment
|
||||
import com.appttude.h_mal.monoWeather.ui.home.adapter.WeatherRecyclerAdapter
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
|
||||
@@ -25,22 +26,16 @@ import kotlinx.android.synthetic.main.fragment_home.*
|
||||
* A simple [Fragment] subclass.
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class HomeFragment : BaseFragment(R.layout.fragment_home) {
|
||||
|
||||
private val viewModel by getFragmentViewModel<MainViewModel>()
|
||||
class HomeFragment : BaseFragment<MainViewModel>(R.layout.fragment_home) {
|
||||
|
||||
lateinit var dialog: PermissionsDeclarationDialog
|
||||
lateinit var recyclerAdapter: WeatherRecyclerAdapter
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
setHasOptionsMenu(true)
|
||||
|
||||
val recyclerAdapter = WeatherRecyclerAdapter(itemClick = {
|
||||
navigateToFurtherDetails(it)
|
||||
})
|
||||
|
||||
forecast_listview.adapter = recyclerAdapter
|
||||
dialog = PermissionsDeclarationDialog(requireContext())
|
||||
|
||||
swipe_refresh.apply {
|
||||
@@ -52,13 +47,11 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.weatherLiveData.observe(viewLifecycleOwner) {
|
||||
recyclerAdapter.addCurrent(it)
|
||||
}
|
||||
recyclerAdapter = WeatherRecyclerAdapter(itemClick = {
|
||||
navigateToFurtherDetails(it)
|
||||
})
|
||||
|
||||
viewModel.operationState.observe(viewLifecycleOwner, progressBarStateObserver(progressBar))
|
||||
viewModel.operationError.observe(viewLifecycleOwner, errorObserver())
|
||||
viewModel.operationRefresh.observe(viewLifecycleOwner, refreshObserver(swipe_refresh))
|
||||
forecast_listview.adapter = recyclerAdapter
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
@@ -76,6 +69,20 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
|
||||
dialog.dismiss()
|
||||
}
|
||||
|
||||
override fun onSuccess(data: Any?) {
|
||||
super.onSuccess(data)
|
||||
swipe_refresh.isRefreshing = false
|
||||
|
||||
if (data is WeatherDisplay) {
|
||||
recyclerAdapter.addCurrent(data)
|
||||
}
|
||||
}
|
||||
|
||||
override fun onFailure(error: Any?) {
|
||||
super.onFailure(error)
|
||||
swipe_refresh.isRefreshing = false
|
||||
}
|
||||
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun permissionsGranted() {
|
||||
viewModel.fetchData()
|
||||
|
||||
@@ -83,7 +83,8 @@ class WeatherRecyclerAdapter(
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (getDataType(getItemViewType(position))) {
|
||||
is ViewType.Empty -> {
|
||||
holder as EmptyViewHolder
|
||||
val emptyViewHolder = holder as EmptyViewHolder
|
||||
emptyViewHolder.bindData()
|
||||
}
|
||||
|
||||
is ViewType.Current -> {
|
||||
@@ -115,7 +116,7 @@ class WeatherRecyclerAdapter(
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int {
|
||||
return if (weather == null) 0 else 3 + (weather?.forecast?.size ?: 0)
|
||||
return if (weather == null) 1 else 3 + (weather?.forecast?.size ?: 0)
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,6 +15,5 @@ class ViewHolderForecast(
|
||||
val adapter = GridForecastAdapter()
|
||||
adapter.addCurrent(forecasts)
|
||||
recyclerView.adapter = adapter
|
||||
|
||||
}
|
||||
}
|
||||
@@ -2,25 +2,21 @@ package com.appttude.h_mal.monoWeather.ui.world
|
||||
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.lifecycle.observe
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.ui.BaseFragment
|
||||
import com.appttude.h_mal.atlas_weather.utils.displayToast
|
||||
import com.appttude.h_mal.atlas_weather.utils.goBack
|
||||
import com.appttude.h_mal.atlas_weather.utils.hideKeyboard
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
|
||||
import com.appttude.h_mal.monoWeather.ui.BaseFragment
|
||||
import kotlinx.android.synthetic.main.activity_add_forecast.location_name_tv
|
||||
import kotlinx.android.synthetic.main.activity_add_forecast.progressBar
|
||||
import kotlinx.android.synthetic.main.activity_add_forecast.submit
|
||||
|
||||
|
||||
class AddLocationFragment : BaseFragment(R.layout.activity_add_forecast) {
|
||||
class AddLocationFragment : BaseFragment<WorldViewModel>(R.layout.activity_add_forecast) {
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val viewModel by getFragmentViewModel<WorldViewModel>()
|
||||
|
||||
submit.setOnClickListener {
|
||||
val locationName = location_name_tv.text?.trim()?.toString()
|
||||
if (locationName.isNullOrBlank()) {
|
||||
@@ -30,14 +26,12 @@ class AddLocationFragment : BaseFragment(R.layout.activity_add_forecast) {
|
||||
viewModel.fetchDataForSingleLocationSearch(locationName)
|
||||
hideKeyboard()
|
||||
}
|
||||
}
|
||||
|
||||
viewModel.operationState.observe(viewLifecycleOwner, progressBarStateObserver(progressBar))
|
||||
viewModel.operationError.observe(viewLifecycleOwner, errorObserver())
|
||||
|
||||
viewModel.operationComplete.observe(viewLifecycleOwner) {
|
||||
it?.getContentIfNotHandled()?.let { message ->
|
||||
displayToast(message)
|
||||
}
|
||||
override fun onSuccess(data: Any?) {
|
||||
super.onSuccess(data)
|
||||
if (data is String) {
|
||||
displayToast(data)
|
||||
goBack()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -3,36 +3,35 @@ package com.appttude.h_mal.monoWeather.ui.world
|
||||
import android.os.Bundle
|
||||
import android.view.View
|
||||
import androidx.fragment.app.Fragment
|
||||
import androidx.lifecycle.observe
|
||||
import androidx.recyclerview.widget.LinearLayoutManager
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
|
||||
import com.appttude.h_mal.atlas_weather.ui.BaseFragment
|
||||
import com.appttude.h_mal.atlas_weather.utils.navigateTo
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
|
||||
import com.appttude.h_mal.monoWeather.ui.BaseFragment
|
||||
import com.appttude.h_mal.monoWeather.ui.world.WorldFragmentDirections.actionWorldFragmentToWorldItemFragment
|
||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||
import kotlinx.android.synthetic.main.fragment__two.floatingActionButton
|
||||
import kotlinx.android.synthetic.main.fragment__two.progressBar
|
||||
import kotlinx.android.synthetic.main.fragment__two.world_recycler
|
||||
import kotlinx.android.synthetic.monoWeather.fragment__two.floatingActionButton
|
||||
import kotlinx.android.synthetic.monoWeather.fragment__two.world_recycler
|
||||
|
||||
|
||||
/**
|
||||
* A simple [Fragment] subclass.
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
class WorldFragment : BaseFragment(R.layout.fragment__two) {
|
||||
private val viewModel by getFragmentViewModel<WorldViewModel>()
|
||||
class WorldFragment : BaseFragment<WorldViewModel>(R.layout.fragment__two) {
|
||||
|
||||
lateinit var recyclerAdapter: WorldRecyclerAdapter
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
|
||||
viewModel.fetchAllLocations()
|
||||
}
|
||||
|
||||
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
val recyclerAdapter = WorldRecyclerAdapter({
|
||||
recyclerAdapter = WorldRecyclerAdapter({
|
||||
val direction =
|
||||
actionWorldFragmentToWorldItemFragment(it.location)
|
||||
navigateTo(direction)
|
||||
@@ -53,17 +52,19 @@ class WorldFragment : BaseFragment(R.layout.fragment__two) {
|
||||
adapter = recyclerAdapter
|
||||
}
|
||||
|
||||
viewModel.weatherLiveData.observe(viewLifecycleOwner) {
|
||||
recyclerAdapter.addCurrent(it)
|
||||
}
|
||||
|
||||
floatingActionButton.setOnClickListener {
|
||||
navigateTo(R.id.action_worldFragment_to_addLocationFragment)
|
||||
}
|
||||
|
||||
viewModel.operationState.observe(viewLifecycleOwner, progressBarStateObserver(progressBar))
|
||||
viewModel.operationError.observe(viewLifecycleOwner, errorObserver())
|
||||
}
|
||||
|
||||
@Suppress("UNCHECKED_CAST")
|
||||
override fun onSuccess(data: Any?) {
|
||||
super.onSuccess(data)
|
||||
|
||||
if (data is List<*>) {
|
||||
recyclerAdapter.addCurrent(data as List<WeatherDisplay>)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user