mirror of
https://github.com/hmalik144/Weather-apps.git
synced 2026-03-18 15:36:04 +00:00
Lint fixes (#19)
- Code inspection - Redundant resources removed - Resources moved the corresponding flavours - Deprecated dependencies upgraded - lint changes - circleci updated to capture screenshot
This commit is contained in:
@@ -1,14 +1,10 @@
|
||||
package com.appttude.h_mal.monoWeather.dialog
|
||||
|
||||
import android.content.Context
|
||||
import android.content.res.Resources
|
||||
import android.os.Build
|
||||
import android.text.Html
|
||||
import androidx.annotation.RequiresApi
|
||||
import androidx.annotation.StringRes
|
||||
import androidx.core.content.ContextCompat
|
||||
|
||||
interface DeclarationBuilder{
|
||||
interface DeclarationBuilder {
|
||||
val link: String
|
||||
val message: String
|
||||
|
||||
|
||||
@@ -10,10 +10,11 @@ import androidx.appcompat.app.AlertDialog
|
||||
class PermissionsDeclarationDialog(context: Context) : BaseDeclarationDialog(context) {
|
||||
|
||||
override val link: String = "https://sites.google.com/view/hmaldev/home/monochrome"
|
||||
override val message: String = "Hi, thank you for downloading my app. Google play isn't letting me upload my app to the Playstore until I have a privacy declaration :(. My app is basically used to demonstrate my code=ing to potential employers and others. I do NOT store or process any information. The location permission in the app is there just to provide the end user with weather data."
|
||||
override val message: String =
|
||||
"Hi, thank you for downloading my app. Google play isn't letting me upload my app to the Playstore until I have a privacy declaration :(. My app is basically used to demonstrate my coding to potential employers and others. I do NOT store or process any information. The location permission in the app is there just to provide the end user with weather data."
|
||||
}
|
||||
|
||||
abstract class BaseDeclarationDialog(val context: Context): DeclarationBuilder {
|
||||
abstract class BaseDeclarationDialog(val context: Context) : DeclarationBuilder {
|
||||
abstract override val link: String
|
||||
abstract override val message: String
|
||||
|
||||
@@ -23,14 +24,14 @@ abstract class BaseDeclarationDialog(val context: Context): DeclarationBuilder {
|
||||
val myMessage = buildMessage()
|
||||
|
||||
val builder = AlertDialog.Builder(context)
|
||||
.setPositiveButton("agree") { _, _ ->
|
||||
agreeCallback()
|
||||
}
|
||||
.setNegativeButton("disagree") { _, _ ->
|
||||
disagreeCallback()
|
||||
}
|
||||
.setMessage(myMessage)
|
||||
.setCancelable(false)
|
||||
.setPositiveButton("agree") { _, _ ->
|
||||
agreeCallback()
|
||||
}
|
||||
.setNegativeButton("disagree") { _, _ ->
|
||||
disagreeCallback()
|
||||
}
|
||||
.setMessage(myMessage)
|
||||
.setCancelable(false)
|
||||
|
||||
dialog = builder.create()
|
||||
dialog.show()
|
||||
|
||||
@@ -7,12 +7,12 @@ import androidx.annotation.DrawableRes
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
|
||||
class EmptyViewHolder(itemView: View): RecyclerView.ViewHolder(itemView){
|
||||
class EmptyViewHolder(itemView: View) : RecyclerView.ViewHolder(itemView) {
|
||||
val icon: ImageView = itemView.findViewById(R.id.icon)
|
||||
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){
|
||||
fun bindData(@DrawableRes imageRes: Int?, header: String, body: String) {
|
||||
imageRes?.let { icon.setImageResource(it) }
|
||||
headerTV.text = header
|
||||
bodyTV.text = body
|
||||
|
||||
@@ -6,10 +6,12 @@ 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.monoWeather.ui.home.adapter.WeatherRecyclerAdapter
|
||||
import com.appttude.h_mal.atlas_weather.utils.navigateTo
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.WorldViewModel
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
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) {
|
||||
@@ -27,7 +29,7 @@ class WorldItemFragment : BaseFragment(R.layout.fragment_home) {
|
||||
|
||||
val recyclerAdapter = WeatherRecyclerAdapter {
|
||||
val directions =
|
||||
WorldItemFragmentDirections.actionWorldItemFragmentToFurtherDetailsFragment(it)
|
||||
WorldItemFragmentDirections.actionWorldItemFragmentToFurtherDetailsFragment(it)
|
||||
navigateTo(directions)
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,11 @@ class FurtherInfoFragment : Fragment() {
|
||||
|
||||
}
|
||||
|
||||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater,
|
||||
container: ViewGroup?,
|
||||
savedInstanceState: Bundle?
|
||||
): View? {
|
||||
return inflater.inflate(R.layout.activity_further_info, container, false)
|
||||
}
|
||||
|
||||
@@ -31,18 +35,20 @@ class FurtherInfoFragment : Fragment() {
|
||||
super.onViewCreated(view, savedInstanceState)
|
||||
|
||||
maxtemp.text = param1?.mainTemp.appendWith(requireContext().getString(R.string.degrees))
|
||||
averagetemp.text = param1?.averageTemp.appendWith(requireContext().getString(R.string.degrees))
|
||||
minimumtemp.text = param1?.minorTemp.appendWith(requireContext().getString(R.string.degrees))
|
||||
averagetemp.text =
|
||||
param1?.averageTemp.appendWith(requireContext().getString(R.string.degrees))
|
||||
minimumtemp.text =
|
||||
param1?.minorTemp.appendWith(requireContext().getString(R.string.degrees))
|
||||
windtext.text = param1?.windText.appendWith(" km")
|
||||
preciptext.text = param1?.precipitation.appendWith(" %")
|
||||
cloudtext.text = param1?.cloud.appendWith(" %")
|
||||
cloudtext.text = param1?.cloud.appendWith(" %")
|
||||
humiditytext.text = param1?.humidity.appendWith(" %")
|
||||
uvtext.text = param1?.uvi
|
||||
sunrisetext.text = param1?.sunrise
|
||||
sunsettext.text = param1?.sunset
|
||||
}
|
||||
|
||||
fun String?.appendWith(suffix: String): String?{
|
||||
fun String?.appendWith(suffix: String): String? {
|
||||
return this?.let {
|
||||
StringBuilder().append(it).append(suffix).toString()
|
||||
}
|
||||
|
||||
@@ -13,11 +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.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.monoWeather.ui.home.adapter.WeatherRecyclerAdapter
|
||||
import com.appttude.h_mal.atlas_weather.utils.navigateTo
|
||||
import com.appttude.h_mal.atlas_weather.viewmodel.MainViewModel
|
||||
import kotlinx.android.synthetic.main.fragment_home.*
|
||||
|
||||
|
||||
@@ -81,9 +81,9 @@ class HomeFragment : BaseFragment(R.layout.fragment_home) {
|
||||
viewModel.fetchData()
|
||||
}
|
||||
|
||||
private fun navigateToFurtherDetails(forecast: Forecast){
|
||||
private fun navigateToFurtherDetails(forecast: Forecast) {
|
||||
val directions = HomeFragmentDirections
|
||||
.actionHomeFragmentToFurtherDetailsFragment(forecast)
|
||||
.actionHomeFragmentToFurtherDetailsFragment(forecast)
|
||||
navigateTo(directions)
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ class ViewHolderCurrent(listItemView: View) : RecyclerView.ViewHolder(listItemVi
|
||||
var avgTempTV: TextView = listItemView.findViewById(R.id.temp_main_4)
|
||||
var tempUnit: TextView = listItemView.findViewById(R.id.temp_unit_4)
|
||||
|
||||
fun bindData(weather: WeatherDisplay?){
|
||||
fun bindData(weather: WeatherDisplay?) {
|
||||
locationTV.text = weather?.displayName
|
||||
conditionTV.text = weather?.description
|
||||
weatherIV.loadImage(weather?.iconURL)
|
||||
|
||||
@@ -5,40 +5,44 @@ import androidx.recyclerview.widget.RecyclerView
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
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.generateView
|
||||
import com.appttude.h_mal.monoWeather.ui.EmptyViewHolder
|
||||
import com.appttude.h_mal.monoWeather.ui.home.adapter.forecast.ViewHolderForecast
|
||||
import com.appttude.h_mal.monoWeather.ui.home.adapter.forecastDaily.ViewHolderForecastDaily
|
||||
import com.appttude.h_mal.monoWeather.ui.home.adapter.further.ViewHolderFurtherDetails
|
||||
import com.appttude.h_mal.atlas_weather.utils.generateView
|
||||
|
||||
class WeatherRecyclerAdapter(
|
||||
private val itemClick: (Forecast) -> Unit
|
||||
private val itemClick: (Forecast) -> Unit
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
var weather: WeatherDisplay? = null
|
||||
|
||||
fun addCurrent(current: WeatherDisplay){
|
||||
fun addCurrent(current: WeatherDisplay) {
|
||||
weather = current
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return when (getDataType(viewType)){
|
||||
return when (getDataType(viewType)) {
|
||||
is ViewType.Empty -> {
|
||||
val emptyViewHolder = parent.generateView(R.layout.empty_state_layout)
|
||||
EmptyViewHolder(emptyViewHolder)
|
||||
}
|
||||
|
||||
is ViewType.Current -> {
|
||||
val viewCurrent = parent.generateView(R.layout.mono_item_one)
|
||||
ViewHolderCurrent(viewCurrent)
|
||||
}
|
||||
|
||||
is ViewType.ForecastHourly -> {
|
||||
val viewForecast = parent.generateView(R.layout.mono_item_forecast)
|
||||
ViewHolderForecast(viewForecast)
|
||||
}
|
||||
|
||||
is ViewType.Further -> {
|
||||
val viewFurther = parent.generateView(R.layout.mono_item_two)
|
||||
ViewHolderFurtherDetails(viewFurther)
|
||||
}
|
||||
|
||||
is ViewType.ForecastDaily -> {
|
||||
val viewForecast = parent.generateView(R.layout.list_item_forecast)
|
||||
ViewHolderForecastDaily(viewForecast)
|
||||
@@ -46,7 +50,7 @@ class WeatherRecyclerAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ViewType{
|
||||
sealed class ViewType {
|
||||
object Empty : ViewType()
|
||||
object Current : ViewType()
|
||||
object ForecastHourly : ViewType()
|
||||
@@ -55,7 +59,7 @@ class WeatherRecyclerAdapter(
|
||||
}
|
||||
|
||||
private fun getDataType(type: Int): ViewType {
|
||||
return when (type){
|
||||
return when (type) {
|
||||
0 -> ViewType.Empty
|
||||
1 -> ViewType.Current
|
||||
2 -> ViewType.ForecastHourly
|
||||
@@ -67,32 +71,36 @@ class WeatherRecyclerAdapter(
|
||||
|
||||
override fun getItemViewType(position: Int): Int {
|
||||
if (weather == null) return 0
|
||||
return when(position){
|
||||
return when (position) {
|
||||
0 -> 1
|
||||
1 -> 3
|
||||
2 -> 2
|
||||
2 -> 2
|
||||
in 3 until (itemCount) -> 4
|
||||
else -> 0
|
||||
}
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (getDataType(getItemViewType(position))){
|
||||
when (getDataType(getItemViewType(position))) {
|
||||
is ViewType.Empty -> {
|
||||
holder as EmptyViewHolder
|
||||
}
|
||||
|
||||
is ViewType.Current -> {
|
||||
val viewHolderCurrent = holder as ViewHolderCurrent
|
||||
viewHolderCurrent.bindData(weather)
|
||||
}
|
||||
|
||||
is ViewType.Further -> {
|
||||
val viewHolderCurrent = holder as ViewHolderFurtherDetails
|
||||
viewHolderCurrent.bindData(weather)
|
||||
}
|
||||
|
||||
is ViewType.ForecastHourly -> {
|
||||
val viewHolderForecast = holder as ViewHolderForecast
|
||||
viewHolderForecast.bindView(weather?.hourly)
|
||||
}
|
||||
|
||||
is ViewType.ForecastDaily -> {
|
||||
val viewHolderForecast = holder as ViewHolderForecastDaily
|
||||
weather?.forecast?.getOrNull(position - 3)?.let { f ->
|
||||
|
||||
@@ -6,10 +6,10 @@ import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.model.weather.Hour
|
||||
import com.appttude.h_mal.atlas_weather.utils.generateView
|
||||
|
||||
class GridForecastAdapter(): RecyclerView.Adapter<RecyclerView.ViewHolder>(){
|
||||
class GridForecastAdapter : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
var weather: MutableList<Hour> = mutableListOf()
|
||||
|
||||
fun addCurrent(current: List<Hour>?){
|
||||
fun addCurrent(current: List<Hour>?) {
|
||||
weather.clear()
|
||||
current?.let { weather.addAll(it) }
|
||||
notifyDataSetChanged()
|
||||
|
||||
@@ -6,7 +6,7 @@ import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.model.weather.Hour
|
||||
|
||||
class ViewHolderForecast(
|
||||
itemView: View
|
||||
itemView: View
|
||||
) : RecyclerView.ViewHolder(itemView) {
|
||||
|
||||
var recyclerView: RecyclerView = itemView.findViewById(R.id.forecast_recyclerview)
|
||||
|
||||
@@ -6,13 +6,14 @@ import android.view.ViewGroup
|
||||
import android.widget.ArrayAdapter
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.utils.generateView
|
||||
import kotlinx.android.synthetic.monoWeather.mono_item_two_cell.view.*
|
||||
import kotlinx.android.synthetic.monoWeather.mono_item_two_cell.view.mono_item_cell
|
||||
import kotlinx.android.synthetic.monoWeather.mono_item_two_cell.view.mono_text_cell
|
||||
|
||||
|
||||
class GridAdapter(
|
||||
context: Context,
|
||||
list: List<Pair<Int, String>>
|
||||
) : ArrayAdapter<Pair<Int, String>>(context, 0, list){
|
||||
context: Context,
|
||||
list: List<Pair<Int, String>>
|
||||
) : ArrayAdapter<Pair<Int, String>>(context, 0, list) {
|
||||
override fun getView(position: Int, convertView: View?, parent: ViewGroup): View {
|
||||
val view = convertView ?: parent.generateView(R.layout.mono_item_two_cell)
|
||||
|
||||
|
||||
@@ -10,12 +10,14 @@ class ViewHolderFurtherDetails(itemView: View) : RecyclerView.ViewHolder(itemVie
|
||||
|
||||
var grid: GridView = itemView.findViewById(R.id.grid_mono)
|
||||
|
||||
fun bindData(weather: WeatherDisplay?){
|
||||
grid.adapter = GridAdapter(itemView.context, listOf<Pair<Int, String>>(
|
||||
Pair(R.drawable.breeze,"${weather?.windSpeed ?: "0"} km"),
|
||||
Pair(R.drawable.water_drop,"${weather?.precipitation ?: "0"} %" ),
|
||||
Pair(R.drawable.cloud_symbol,"${weather?.clouds ?: "0"} %" )
|
||||
))
|
||||
fun bindData(weather: WeatherDisplay?) {
|
||||
grid.adapter = GridAdapter(
|
||||
itemView.context, listOf<Pair<Int, String>>(
|
||||
Pair(R.drawable.breeze, "${weather?.windSpeed ?: "0"} km"),
|
||||
Pair(R.drawable.water_drop, "${weather?.precipitation ?: "0"} %"),
|
||||
Pair(R.drawable.cloud_symbol, "${weather?.clouds ?: "0"} %")
|
||||
)
|
||||
)
|
||||
|
||||
}
|
||||
}
|
||||
@@ -30,7 +30,12 @@ class SettingsFragment : PreferenceFragmentCompat() {
|
||||
val intent = Intent(AppWidgetManager.ACTION_APPWIDGET_UPDATE)
|
||||
val widgetManager = AppWidgetManager.getInstance(requireContext())
|
||||
val ids =
|
||||
widgetManager.getAppWidgetIds(ComponentName(requireContext(), NewAppWidget::class.java))
|
||||
widgetManager.getAppWidgetIds(
|
||||
ComponentName(
|
||||
requireContext(),
|
||||
NewAppWidget::class.java
|
||||
)
|
||||
)
|
||||
AppWidgetManager.getInstance(requireContext())
|
||||
.notifyAppWidgetViewDataChanged(ids, R.id.whole_widget_view)
|
||||
intent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, ids)
|
||||
|
||||
@@ -2,7 +2,10 @@ package com.appttude.h_mal.monoWeather.ui.widget
|
||||
|
||||
import android.Manifest.permission.ACCESS_COARSE_LOCATION
|
||||
import android.app.Activity
|
||||
import android.appwidget.AppWidgetManager.*
|
||||
import android.appwidget.AppWidgetManager.ACTION_APPWIDGET_UPDATE
|
||||
import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_ID
|
||||
import android.appwidget.AppWidgetManager.EXTRA_APPWIDGET_IDS
|
||||
import android.appwidget.AppWidgetManager.INVALID_APPWIDGET_ID
|
||||
import android.content.Intent
|
||||
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
||||
import android.os.Bundle
|
||||
@@ -11,9 +14,10 @@ import android.widget.TextView
|
||||
import androidx.appcompat.app.AppCompatActivity
|
||||
import androidx.core.app.ActivityCompat.checkSelfPermission
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.monoWeather.dialog.DeclarationBuilder
|
||||
import com.appttude.h_mal.atlas_weather.utils.displayToast
|
||||
import kotlinx.android.synthetic.monoWeather.permissions_declaration_dialog.*
|
||||
import com.appttude.h_mal.monoWeather.dialog.DeclarationBuilder
|
||||
import kotlinx.android.synthetic.monoWeather.permissions_declaration_dialog.cancel
|
||||
import kotlinx.android.synthetic.monoWeather.permissions_declaration_dialog.submit
|
||||
|
||||
const val PERMISSION_CODE = 401
|
||||
|
||||
@@ -60,7 +64,11 @@ class WidgetLocationPermissionActivity : AppCompatActivity(), DeclarationBuilder
|
||||
cancel.setOnClickListener { finish() }
|
||||
}
|
||||
|
||||
override fun onRequestPermissionsResult(requestCode: Int, permissions: Array<out String>, grantResults: IntArray) {
|
||||
override fun onRequestPermissionsResult(
|
||||
requestCode: Int,
|
||||
permissions: Array<out String>,
|
||||
grantResults: IntArray
|
||||
) {
|
||||
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
|
||||
if (requestCode == PERMISSION_CODE) {
|
||||
if (grantResults.isNotEmpty() && grantResults[0] == PERMISSION_GRANTED) {
|
||||
@@ -87,8 +95,9 @@ class WidgetLocationPermissionActivity : AppCompatActivity(), DeclarationBuilder
|
||||
private fun sendUpdateIntent() {
|
||||
// It is the responsibility of the configuration activity to update the app widget
|
||||
// Send update broadcast to widget app class
|
||||
Intent(this@WidgetLocationPermissionActivity,
|
||||
WidgetLocationPermissionActivity::class.java
|
||||
Intent(
|
||||
this@WidgetLocationPermissionActivity,
|
||||
WidgetLocationPermissionActivity::class.java
|
||||
).apply {
|
||||
action = ACTION_APPWIDGET_UPDATE
|
||||
|
||||
|
||||
@@ -4,24 +4,26 @@ 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.monoWeather.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 kotlinx.android.synthetic.main.activity_add_forecast.*
|
||||
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) {
|
||||
|
||||
private val viewModel by getFragmentViewModel<WorldViewModel>()
|
||||
|
||||
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()){
|
||||
if (locationName.isNullOrBlank()) {
|
||||
location_name_tv.error = "Location cannot be blank"
|
||||
return@setOnClickListener
|
||||
}
|
||||
@@ -37,7 +39,6 @@ class AddLocationFragment : BaseFragment(R.layout.activity_add_forecast) {
|
||||
displayToast(message)
|
||||
}
|
||||
goBack()
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,14 +6,14 @@ 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.monoWeather.ui.BaseFragment
|
||||
import com.appttude.h_mal.monoWeather.ui.world.WorldFragmentDirections.actionWorldFragmentToWorldItemFragment
|
||||
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.*
|
||||
import kotlinx.android.synthetic.main.fragment_add_location.floatingActionButton
|
||||
import kotlinx.android.synthetic.main.fragment_add_location.world_recycler
|
||||
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
|
||||
|
||||
|
||||
/**
|
||||
@@ -34,18 +34,18 @@ class WorldFragment : BaseFragment(R.layout.fragment__two) {
|
||||
|
||||
val recyclerAdapter = WorldRecyclerAdapter({
|
||||
val direction =
|
||||
actionWorldFragmentToWorldItemFragment(it.location)
|
||||
actionWorldFragmentToWorldItemFragment(it.location)
|
||||
navigateTo(direction)
|
||||
}){
|
||||
}) {
|
||||
MaterialAlertDialogBuilder(requireContext())
|
||||
.setTitle("Delete weather?")
|
||||
.setMessage("Are you sure want to delete $it?")
|
||||
.setPositiveButton("Yes"){ _, _ ->
|
||||
viewModel.deleteLocation(it)
|
||||
}
|
||||
.setNegativeButton("No", null)
|
||||
.create()
|
||||
.show()
|
||||
.setTitle("Delete weather?")
|
||||
.setMessage("Are you sure want to delete $it?")
|
||||
.setPositiveButton("Yes") { _, _ ->
|
||||
viewModel.deleteLocation(it)
|
||||
}
|
||||
.setNegativeButton("No", null)
|
||||
.create()
|
||||
.show()
|
||||
}
|
||||
|
||||
world_recycler.apply {
|
||||
@@ -57,7 +57,7 @@ class WorldFragment : BaseFragment(R.layout.fragment__two) {
|
||||
recyclerAdapter.addCurrent(it)
|
||||
}
|
||||
|
||||
floatingActionButton.setOnClickListener{
|
||||
floatingActionButton.setOnClickListener {
|
||||
navigateTo(R.id.action_worldFragment_to_addLocationFragment)
|
||||
}
|
||||
|
||||
|
||||
@@ -7,28 +7,29 @@ import android.widget.TextView
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import com.appttude.h_mal.atlas_weather.R
|
||||
import com.appttude.h_mal.atlas_weather.model.forecast.WeatherDisplay
|
||||
import com.appttude.h_mal.monoWeather.ui.EmptyViewHolder
|
||||
import com.appttude.h_mal.atlas_weather.utils.generateView
|
||||
import com.appttude.h_mal.atlas_weather.utils.loadImage
|
||||
import com.appttude.h_mal.monoWeather.ui.EmptyViewHolder
|
||||
|
||||
class WorldRecyclerAdapter(
|
||||
private val itemClick: (WeatherDisplay) -> Unit,
|
||||
private val itemLongClick: (String) -> Unit
|
||||
private val itemClick: (WeatherDisplay) -> Unit,
|
||||
private val itemLongClick: (String) -> Unit
|
||||
) : RecyclerView.Adapter<RecyclerView.ViewHolder>() {
|
||||
var weather: MutableList<WeatherDisplay> = mutableListOf()
|
||||
|
||||
fun addCurrent(current: List<WeatherDisplay>){
|
||||
fun addCurrent(current: List<WeatherDisplay>) {
|
||||
weather.clear()
|
||||
weather.addAll(current)
|
||||
notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
|
||||
return when (getDataType(viewType)){
|
||||
return when (getDataType(viewType)) {
|
||||
is ViewType.Empty -> {
|
||||
val emptyViewHolder = parent.generateView(R.layout.empty_state_layout)
|
||||
EmptyViewHolder(emptyViewHolder)
|
||||
}
|
||||
|
||||
is ViewType.Current -> {
|
||||
val viewCurrent = parent.generateView(R.layout.db_list_item)
|
||||
WorldHolderCurrent(viewCurrent)
|
||||
@@ -36,13 +37,13 @@ class WorldRecyclerAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
sealed class ViewType{
|
||||
sealed class ViewType {
|
||||
object Empty : ViewType()
|
||||
object Current : ViewType()
|
||||
}
|
||||
|
||||
private fun getDataType(type: Int): ViewType {
|
||||
return when (type){
|
||||
return when (type) {
|
||||
0 -> ViewType.Empty
|
||||
1 -> ViewType.Current
|
||||
else -> ViewType.Empty
|
||||
@@ -54,11 +55,12 @@ class WorldRecyclerAdapter(
|
||||
}
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (getDataType(getItemViewType(position))){
|
||||
when (getDataType(getItemViewType(position))) {
|
||||
is ViewType.Empty -> {
|
||||
holder as EmptyViewHolder
|
||||
holder.bindData(null, "World List Empty", "Please add a location")
|
||||
}
|
||||
|
||||
is ViewType.Current -> {
|
||||
val viewHolderCurrent = holder as WorldHolderCurrent
|
||||
val currentWeather = weather[position]
|
||||
@@ -86,7 +88,7 @@ class WorldRecyclerAdapter(
|
||||
private val avgTempTV: TextView = cellView.findViewById(R.id.db_main_temp)
|
||||
private val tempUnit: TextView = cellView.findViewById(R.id.db_temp_unit)
|
||||
|
||||
override fun bindData(data: WeatherDisplay?){
|
||||
override fun bindData(data: WeatherDisplay?) {
|
||||
locationTV.text = data?.displayName
|
||||
conditionTV.text = data?.description
|
||||
weatherIV.loadImage(data?.iconURL)
|
||||
@@ -95,7 +97,7 @@ class WorldRecyclerAdapter(
|
||||
}
|
||||
}
|
||||
|
||||
abstract class BaseViewHolder<T : Any>(cellView: View) : RecyclerView.ViewHolder(cellView) {
|
||||
abstract fun bindData(data : T?)
|
||||
abstract class BaseViewHolder<T : Any>(cellView: View) : RecyclerView.ViewHolder(cellView) {
|
||||
abstract fun bindData(data: T?)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user