-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
397 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
app/src/main/java/com/hasan/weatherapp/data/database/Converters.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
package com.hasan.weatherapp.data.database | ||
|
||
import androidx.room.ProvidedTypeConverter | ||
import androidx.room.TypeConverter | ||
import com.hasan.weatherapp.data.util.JsonParser | ||
import com.hasan.weatherapp.domain.weather.WeatherData | ||
import com.hasan.weatherapp.domain.weather.WeatherType | ||
|
||
import com.squareup.moshi.Types | ||
import java.time.LocalDateTime | ||
import java.time.format.DateTimeFormatter | ||
|
||
@ProvidedTypeConverter | ||
class Converters( | ||
private val jsonParser: JsonParser | ||
) { | ||
// @TypeConverter | ||
// fun fromWeatherDataJson(json: String): Map<Int, List<WeatherEntity>>? { | ||
// return jsonParser.fromJson( | ||
// json, | ||
// Types.newParameterizedType(MutableMap::class.java,Int::class.java, | ||
// Types.newParameterizedType(ArrayList::class.java, WeatherEntity::class.javaObjectType)))?: emptyMap() | ||
// } | ||
// | ||
// // TODO: maybe just fuckin remove the map since the list works so we loop and insert all of the map interies and each will be diffrant using time | ||
// @TypeConverter | ||
// fun fromWeatherDataJson(map: Map<Int, List<WeatherEntity>>): String { | ||
// return jsonParser.toJson( | ||
// map, | ||
// Types.newParameterizedType(MutableMap::class.java,Int::class.java, | ||
// Types.newParameterizedType(ArrayList::class.java, WeatherEntity::class.javaObjectType))) ?: "[]" | ||
// } | ||
|
||
|
||
// | ||
// @TypeConverter | ||
// fun toMWeatherDataJson(weatherData: List<WeatherEntity>): String { | ||
// return jsonParser.toJson( | ||
// weatherData, | ||
// Types.newParameterizedType(List::class.java, WeatherEntity::class.javaObjectType) | ||
// ) ?: "[]" | ||
// } | ||
|
||
@TypeConverter | ||
fun fromWeatherTypeNumber(num: Int): WeatherType { | ||
return WeatherType.fromWMO(num) | ||
} | ||
|
||
@TypeConverter | ||
fun toMWeatherDataNumber(weathertype: WeatherType): Int { | ||
return weathertype.code | ||
} | ||
|
||
@TypeConverter | ||
fun fromLocalDateTimeString(str: String): LocalDateTime { | ||
return LocalDateTime.parse(str, DateTimeFormatter.ISO_DATE_TIME) | ||
} | ||
|
||
@TypeConverter | ||
fun toLocalDateTimeString(localDateTime: LocalDateTime): String { | ||
return localDateTime.toString() | ||
} | ||
|
||
|
||
} |
29 changes: 29 additions & 0 deletions
29
app/src/main/java/com/hasan/weatherapp/data/database/WeatherDao.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.hasan.weatherapp.data.database | ||
|
||
import androidx.room.Dao | ||
import androidx.room.Insert | ||
import androidx.room.MapInfo | ||
import androidx.room.OnConflictStrategy | ||
import androidx.room.Query | ||
|
||
import com.hasan.weatherapp.domain.weather.WeatherData | ||
import kotlinx.coroutines.flow.Flow | ||
import java.time.LocalDateTime | ||
|
||
@Dao | ||
interface WeatherDao { | ||
|
||
@Insert(onConflict = OnConflictStrategy.REPLACE) | ||
suspend fun insertWeatherInfos(infos: WeatherData) | ||
|
||
// @Query("DELETE FROM WeatherData WHERE time IN(:time)") | ||
// suspend fun deletetWeatherInfos(time: LocalDateTime) | ||
|
||
@Query("DELETE FROM WeatherData") | ||
suspend fun deletetWeatherInfo() | ||
|
||
// @Query("SELECT * FROM WeatherData WHERE time LIKE '%' || :time || '%'") | ||
// suspend fun gettWeatherInfos(time: LocalDateTime): List<WeatherData> | ||
@Query("SELECT * FROM WeatherData ") | ||
fun gettWeatherInfos(): Flow<List<WeatherData>> | ||
} |
16 changes: 16 additions & 0 deletions
16
app/src/main/java/com/hasan/weatherapp/data/database/WeatherDatabase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.hasan.weatherapp.data.database | ||
|
||
import androidx.room.Database | ||
import androidx.room.RoomDatabase | ||
import androidx.room.TypeConverters | ||
import com.hasan.weatherapp.domain.weather.WeatherData | ||
|
||
@Database( | ||
entities = [WeatherData::class], | ||
version = 1 | ||
) | ||
@TypeConverters(Converters::class) | ||
abstract class WeatherDatabase: RoomDatabase() { | ||
|
||
abstract val dao: WeatherDao | ||
} |
31 changes: 31 additions & 0 deletions
31
app/src/main/java/com/hasan/weatherapp/data/database/entity/WeatherEntity.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.hasan.weatherapp.data.database.entity | ||
// | ||
// | ||
//import androidx.room.Entity | ||
//import androidx.room.PrimaryKey | ||
//import com.hasan.weatherapp.domain.weather.WeatherData | ||
//import com.hasan.weatherapp.domain.weather.WeatherType | ||
//import java.time.LocalDateTime | ||
// | ||
//@Entity | ||
//data class WeatherEntity( | ||
// val time: LocalDateTime, | ||
// val temperatureCelsius: Double, | ||
// val pressure: Double, | ||
// val windSpeed: Double, | ||
// val humidity: Double, | ||
// val weatherType: WeatherType, | ||
// @PrimaryKey val id: Int? = null | ||
//) { | ||
// fun toWordInfo(): WeatherData { | ||
// return WeatherData( | ||
// time = time, | ||
// temperatureCelsius = temperatureCelsius, | ||
// pressure = pressure, | ||
// windSpeed = windSpeed, | ||
// humidity = humidity, | ||
// weatherType = weatherType | ||
// | ||
// ) | ||
// } | ||
//} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 98 additions & 5 deletions
103
app/src/main/java/com/hasan/weatherapp/data/repository/RepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
app/src/main/java/com/hasan/weatherapp/data/util/JsonParser.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.hasan.weatherapp.data.util | ||
|
||
import java.lang.reflect.Type | ||
|
||
interface JsonParser { | ||
|
||
fun <T> fromJson(json: String, type: Type): T? | ||
|
||
fun <T> toJson(obj: T, type: Type): String? | ||
} |
Oops, something went wrong.