Skip to content

Commit

Permalink
Feat: Changes to stabilise app behaviour
Browse files Browse the repository at this point in the history
- implemented room db
  • Loading branch information
bosankus committed Nov 21, 2024
1 parent 192e22f commit 414205f
Show file tree
Hide file tree
Showing 21 changed files with 177 additions and 383 deletions.
11 changes: 10 additions & 1 deletion app/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import org.jetbrains.kotlin.compose.compiler.gradle.ComposeFeatureFlag

plugins {
id("com.android.application")
id("kotlin-android")
Expand All @@ -22,6 +24,11 @@ android {
multiDexEnabled = ConfigData.multiDexEnabled
testInstrumentationRunner = "bose.ankush.weatherify.helper.HiltTestRunner"
resourceConfigurations.addAll(listOf("en", "hi", "iw"))
kapt {
arguments {
arg("room.schemaLocation", "$projectDir/schemas")
}
}
}

buildTypes {
Expand Down Expand Up @@ -64,7 +71,9 @@ android {
}

composeCompiler {
enableStrongSkippingMode = true
featureFlags = setOf(
ComposeFeatureFlag.StrongSkipping.disabled()
)
}

dependencies {
Expand Down
47 changes: 47 additions & 0 deletions app/google-services.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{
"project_info": {
"project_number": "1017382896100",
"project_id": "weatherify-mvvm",
"storage_bucket": "weatherify-mvvm.appspot.com"
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "1:1017382896100:android:acbec7a4fb7820c07447f1",
"android_client_info": {
"package_name": "bose.ankush.weatherify"
}
},
"oauth_client": [
{
"client_id": "1017382896100-v9kjtoppk4kmgup2tn277o2e2dahuinn.apps.googleusercontent.com",
"client_type": 1,
"android_info": {
"package_name": "bose.ankush.weatherify",
"certificate_hash": "2c54b48f7f6d440fd60a7afbb0690dee22bb1064"
}
},
{
"client_id": "1017382896100-scedcrpgilgcpn5omgl17o17vnl0phup.apps.googleusercontent.com",
"client_type": 3
}
],
"api_key": [
{
"current_key": "AIzaSyCQj2QfVnblNnyIrIcgFxRS4AvHIZs1tCU"
}
],
"services": {
"appinvite_service": {
"other_platform_oauth_client": [
{
"client_id": "1017382896100-scedcrpgilgcpn5omgl17o17vnl0phup.apps.googleusercontent.com",
"client_type": 3
}
]
}
}
}
],
"configuration_version": "1"
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ const val APP_UPDATE_REQ_CODE = 111
const val APP_PREFERENCE_KEY = "app_preferences"

/*Fallback user location coordinates*/
val DEFAULT_LOCATION_COORDINATES = Pair(28.61792, 77.2079)
const val DEFAULT_CITY_NAME = "New Delhi"

/* Permission constants */
Expand All @@ -30,7 +29,4 @@ val PERMISSIONS_TO_REQUEST = arrayOf(

/*Room central db name*/
const val WEATHER_DATABASE_NAME = "central_weather_table"

/*private const val PERMISSION_DENIED = 0
private const val PERMISSION_GIVEN = 1
private const val REQUEST_PERMISSION = 2*/
const val AQ_DATABASE_NAME = "central_aq_table"
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ package bose.ankush.weatherify.data.remote.api

import bose.ankush.weatherify.BuildConfig
import bose.ankush.weatherify.data.remote.dto.AirQualityDto
import bose.ankush.weatherify.data.remote.dto.ForecastDto
import bose.ankush.weatherify.data.remote.dto.WeatherDto
import bose.ankush.weatherify.data.room.weather.WeatherEntity
import retrofit2.http.GET
import retrofit2.http.Query
Expand All @@ -14,18 +12,6 @@ Date: 05,May,2021
**/
interface OpenWeatherApiService {

@GET("data/2.5/weather")
suspend fun getTodaysWeatherReport(
@Query("q") location: String,
@Query("APPID") AppId: String = BuildConfig.OPEN_WEATHER_API
): WeatherDto

@GET("data/2.5/forecast")
suspend fun getWeatherForecastList(
@Query("q") location: String,
@Query("APPID") AppId: String = BuildConfig.OPEN_WEATHER_API
): ForecastDto

@GET("/data/2.5/air_pollution")
suspend fun getCurrentAirQuality(
@Query("lat") latitude: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,5 +59,4 @@ internal fun AirQualityDto.toAirQuality(): AirQuality = AirQuality(
so2 = data[0].components.o3,
pm10 = data[0].components.pm10,
pm25 = data[0].components.pm25,
coord = Pair(coord.lat, coord.lon)
)

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package bose.ankush.weatherify.data.repository

import androidx.room.withTransaction
import bose.ankush.weatherify.base.dispatcher.DispatcherProvider
import bose.ankush.weatherify.data.remote.api.OpenWeatherApiService
import bose.ankush.weatherify.data.remote.dto.AirQualityDto
import bose.ankush.weatherify.data.remote.dto.ForecastDto
import bose.ankush.weatherify.data.remote.dto.WeatherDto
import bose.ankush.weatherify.data.remote.dto.toAirQuality
import bose.ankush.weatherify.data.room.weather.WeatherDatabase
import bose.ankush.weatherify.data.room.weather.WeatherEntity
import bose.ankush.weatherify.domain.model.AirQuality
import bose.ankush.weatherify.domain.repository.WeatherRepository
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.withContext
Expand All @@ -23,26 +23,10 @@ class WeatherRepositoryImpl @Inject constructor(
private val dispatcher: DispatcherProvider,
) : WeatherRepository {

override suspend fun getAirQualityReport(lat: String, lang: String): Flow<AirQuality> =
weatherDatabase.weatherDao().getAirQuality()

override suspend fun getTodaysWeatherReport(cityName: String): WeatherDto =
withContext(dispatcher.io) {
apiService.getTodaysWeatherReport(location = cityName)
}

override suspend fun getWeatherForecastList(cityName: String): ForecastDto =
withContext(dispatcher.io) {
apiService.getWeatherForecastList(location = cityName)
}

override suspend fun getAirQualityReport(lat: String, lang: String): AirQualityDto =
withContext(dispatcher.io) {
apiService.getCurrentAirQuality(
latitude = lat,
longitude = lang
)
}

override fun getWeatherReport(): Flow<WeatherEntity> =
override suspend fun getWeatherReport(location: Pair<Double, Double>): Flow<WeatherEntity?> =
weatherDatabase.weatherDao().getWeather()

/**
Expand All @@ -56,8 +40,14 @@ class WeatherRepositoryImpl @Inject constructor(
coordinates.first.toString(),
coordinates.second.toString()
)
val airQuality = apiService.getCurrentAirQuality(
latitude = coordinates.first.toString(),
longitude = coordinates.second.toString()
).toAirQuality()
// store the data in room db
weatherDatabase.weatherDao().refreshWeather(weatherData)
weatherDatabase.withTransaction {
weatherDatabase.weatherDao().refreshWeather(weatherData, airQuality)
}
} catch (e: Exception) {
// throw exception in case of error
e.message
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,37 @@ import androidx.room.Insert
import androidx.room.OnConflictStrategy
import androidx.room.Query
import androidx.room.Transaction
import bose.ankush.weatherify.base.common.AQ_DATABASE_NAME
import bose.ankush.weatherify.base.common.WEATHER_DATABASE_NAME
import bose.ankush.weatherify.domain.model.AirQuality
import kotlinx.coroutines.flow.Flow

@Dao
interface WeatherDao {

@Transaction
fun refreshWeather(weather: WeatherEntity) {
fun refreshWeather(weather: WeatherEntity, airQuality: AirQuality) {
deleteAllWeatherDetails()
deleteAllAirQualityDetails()
insertWeather(weather)
insertAirQuality(airQuality)
}

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertWeather(weather: WeatherEntity)

@Insert(onConflict = OnConflictStrategy.REPLACE)
fun insertAirQuality(airQuality: AirQuality)

@Query("SELECT * from $WEATHER_DATABASE_NAME")
fun getWeather(): Flow<WeatherEntity>

@Query("SELECT * from $AQ_DATABASE_NAME")
fun getAirQuality(): Flow<AirQuality>

@Query("DELETE from $WEATHER_DATABASE_NAME")
fun deleteAllWeatherDetails()

@Query("DELETE from $AQ_DATABASE_NAME")
fun deleteAllAirQualityDetails()
}
Loading

0 comments on commit 414205f

Please sign in to comment.