Skip to content

Commit

Permalink
Update weather models and add fetch weather details api
Browse files Browse the repository at this point in the history
  • Loading branch information
shounakmulay committed May 25, 2022
1 parent 5c1ccba commit 8996479
Show file tree
Hide file tree
Showing 48 changed files with 1,156 additions and 344 deletions.
16 changes: 9 additions & 7 deletions android.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}

flavorDimensions "version"
productFlavors {
qa {
Expand All @@ -26,8 +21,15 @@ android {
}
}

Properties props = new Properties()
props.load(new FileInputStream(new File('local.properties')))

buildTypes {
release {}
debug {}
release {
buildConfigField 'String', 'OPEN_WEATHER_API_KEY', props['OPEN_WEATHER_API_KEY']
}
debug {
buildConfigField 'String', 'OPEN_WEATHER_API_KEY', props['DEBUG_OPEN_WEATHER_API_KEY']
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@ package com.wednesday.template.domain.weather

data class Weather(
val title: String,
val woeid: Int,
val dayWeatherList: List<DayWeather>
val description: String,
val lat: Double,
val lon: Double,
val minTemp: Double,
val maxTemp: Double,
val temp: Double,
val feelsLike: Double,
val iconUrl: String
)
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.wednesday.template.domain.weather.models

import com.wednesday.template.domain.date.Date
import com.wednesday.template.domain.weather.DayWeather
import com.wednesday.template.domain.weather.Weather

val weather = Weather(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@ import com.wednesday.template.interactor.weather.SearchCityInteractor
import com.wednesday.template.interactor.weather.UICityMapper
import com.wednesday.template.interactor.weather.UICityMapperImpl
import com.wednesday.template.interactor.weather.favourite.FavouriteWeatherInteractorImpl
import com.wednesday.template.interactor.weather.favourite.UIDayWeatherMapper
import com.wednesday.template.interactor.weather.favourite.UIDayWeatherMapperImpl
import com.wednesday.template.interactor.weather.favourite.UIWeatherListMapper
import com.wednesday.template.interactor.weather.favourite.UIWeatherListMapperImpl
import com.wednesday.template.interactor.weather.search.SearchCityInteractorImpl
Expand All @@ -31,9 +29,7 @@ val interactorModule = module {

single<UICitySearchResultsMapper> { UICitySearchResultsMapperImpl(get()) }

single<UIDayWeatherMapper> { UIDayWeatherMapperImpl(get()) }

single<UIWeatherListMapper> { UIWeatherListMapperImpl(get(), get()) }
single<UIWeatherListMapper> { UIWeatherListMapperImpl() }

factory<FavouriteWeatherInteractor> { FavouriteWeatherInteractorImpl(get(), get(), get(), get(), get(), get(), get(), get()) }

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,34 @@ package com.wednesday.template.interactor.weather.favourite

import com.wednesday.template.domain.weather.Weather
import com.wednesday.template.interactor.base.Mapper
import com.wednesday.template.interactor.base.datetime.UIDateMapper
import com.wednesday.template.interactor_impl.R
import com.wednesday.template.presentation.base.UIList
import com.wednesday.template.presentation.base.UIListItemBase
import com.wednesday.template.presentation.base.UIText
import com.wednesday.template.presentation.weather.UIDayWeatherHeading
import com.wednesday.template.presentation.weather.UISearchCitiesPlaceholder
import com.wednesday.template.presentation.weather.UIWeather
import timber.log.Timber

interface UIWeatherListMapper : Mapper<List<Weather>, UIList>

class UIWeatherListMapperImpl(
private val dayWeatherMapper: UIDayWeatherMapper,
private val uiDateMapper: UIDateMapper
) : UIWeatherListMapper {
class UIWeatherListMapperImpl : UIWeatherListMapper {

override fun map(from: List<Weather>): UIList {
Timber.tag(TAG).d("map() called with: from = $from")
val weatherList = from
.sortedBy { it.title }
.map {

val currentWeather = it.dayWeatherList.firstOrNull { dayWeather -> dayWeather.isToday }
?: it.dayWeatherList.first()

val dayWeatherList = mutableListOf<UIListItemBase>()

dayWeatherList.add(
UIDayWeatherHeading(
text = UIText { block(R.string.forecast) }
)
)

dayWeatherList.addAll(
it.dayWeatherList
.filter { dayWeather -> !dayWeather.isToday }
.sortedBy { dayWeather -> uiDateMapper.map(dayWeather.date).timeAsLong }
.map { dayWeather -> dayWeatherMapper.map(dayWeather, it.woeid) }
)

UIWeather(
cityId = it.woeid,
lat = it.lat,
lon = it.lon,
title = UIText { block(it.title) },
currentTemp = UIText { block("${currentWeather.temp} °C") },
minMaxTemp = UIText { block("${currentWeather.minTemp} - ${currentWeather.maxTemp} °C") },
dayWeatherList = dayWeatherList
description = UIText { block(it.description) },
currentTemp = UIText { block("${it.temp} °C") },
minMaxTemp = UIText { block("Temperature Range: ${it.minTemp} - ${it.maxTemp} °C") },
feelsLike = UIText {
block(R.string.feels_like)
block("${it.feelsLike} °C")
},
iconUrl = it.iconUrl
)
}

Expand Down
3 changes: 3 additions & 0 deletions local.skeleton.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# This is a skeleton file. All all the properties here to your local.properties file.
OPEN_WEATHER_API_KEY="Your api key"
DEBUG_OPEN_WEATHER_API_KEY="Your api key"
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,12 @@ import kotlinx.parcelize.Parcelize

@Parcelize
data class UIWeather(
val cityId: Int,
val lat: Double,
val lon: Double,
val title: UIText,
val description: UIText,
val currentTemp: UIText,
val minMaxTemp: UIText,
val dayWeatherList: List<UIListItemBase>
) : UIListItemBase(id = "UICity $cityId")
val feelsLike: UIText,
val iconUrl: String
) : UIListItemBase(id = "UICity $lat $lon")
Original file line number Diff line number Diff line change
Expand Up @@ -7,76 +7,71 @@ import androidx.compose.foundation.layout.padding
import androidx.compose.material.Scaffold
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.annotation.IdRes
import androidx.annotation.NavigationRes
import androidx.appcompat.app.AppCompatActivity
import androidx.core.os.bundleOf
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import com.wednesday.template.presentation.weather.home.HomeViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel

class MainActivity : AppCompatActivity() {
val viewModel: HomeViewModel by viewModel()
private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
// Handle the splash screen transition.
installSplashScreen()

super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
displayFragment()
setContentView(binding.root)
}

@SuppressLint("ResourceType")
private fun displayFragment() {
val (graph, controller) = getNavGraphWithController(
binding.mainNavHostFragment.id,
R.navigation.nav_main
)

val startScreen = HomeScreen

viewModel.onCreate(null)
setContent {
// val state by viewModel.screenState.observeAsState()
graph.setup(
controller,
R.id.startFragment,
bundleOf("key_args" to startScreen)
)
}

Scaffold(modifier = Modifier.padding(16.dp)) {
// LazyColumn(modifier = Modifier.fillMaxSize()) {
// item(key = 1) {
// Box {
// TextObs(showLoading = state?.showLoading)
// }
// }
// item(key = 2) { StateObserver() }
// item(key = 3) {
// Button(onClick = { viewModel.onIntent(HomeScreenIntent.Loading) }) {
// Text("one")
// }
// }
// item(key = 4) {
// Button(onClick = { viewModel.onIntent(HomeScreenIntent.Loading2) }) {
// Text("two")
// }
// }
// item(key = 5) {
// Button(onClick = { viewModel.onIntent(HomeScreenIntent.Loading3) }) {
// Text("three")
// }
// }
// }
}
private fun NavGraph.setup(
navController: NavController,
startDestId: Int,
startDestinationArgs: Bundle? = null
) {
startDestination = startDestId
if (startDestinationArgs != null) {
navController.setGraph(this, startDestinationArgs)
} else {
navController.graph = this
}
}

// @Composable
// fun TextObs(showLoading: Boolean?) {
// Timber.e(" ------ Text updating")
// Text("Hello from Compose $showLoading!")
// }
//
// @Composable
// fun StateObserver() {
// val state by viewModel.subState.collectAsState(initial = null)
// Timber.e(" ----- state observer updated")
// Column {
// T1(state = state?.title?.asString().toString())
// T2(state = state?.hasBackButton ?: false)
// }
// }
//
// @androidx.compose.runtime.Composable
// fun T1(state: String) {
// Timber.e(" ----- T1 updated $state")
// Text("State is $state")
// }
//
// @androidx.compose.runtime.Composable
// fun T2(state: Boolean) {
// Timber.e(" ----- T2 updated $state")
// Text("State is $state")
// }
}
private fun FragmentActivity.getNavGraphWithController(
@IdRes navHostFragmentId: Int,
@NavigationRes navGraphId: Int
): NavGraphWithController {
val navHost =
supportFragmentManager.findFragmentById(navHostFragmentId) as NavHostFragment
val navController = navHost.findNavController()
val navInflater = navController.navInflater
val graph = navInflater.inflate(navGraphId)

return NavGraphWithController(graph, navController)
}

private data class NavGraphWithController(
val graph: NavGraph,
val controller: NavController
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import androidx.annotation.CallSuper
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.viewbinding.ViewBinding
import com.wednesday.template.presentation.R
import com.wednesday.template.presentation.base.UIListItemBase
import com.wednesday.template.presentation.base.list.ListAdapter
import com.wednesday.template.presentation.base.list.renderer.ListItemRenderer
Expand All @@ -17,7 +16,7 @@ abstract class BaseNestedListViewHolder<T : UIListItemBase>(
protected val renderers: MutableList<Pair<KClass<*>, ListItemRenderer<UIListItemBase>>> = mutableListOf()

private val nestedRecyclerView: RecyclerView
get() = itemView.findViewById(R.id.nestedRecyclerView)
get() = itemView.findViewById(/* R.id.nestedRecyclerView : uncomment after creating id */ 1)

abstract fun getNestedListItems(item: T): List<UIListItemBase>

Expand Down
Loading

0 comments on commit 8996479

Please sign in to comment.