Skip to content

Hw2 weather app clean #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 10 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

26 changes: 20 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'kotlin-parcelize'
id 'kotlin-kapt'
id 'androidx.navigation.safeargs'
}

android {
compileSdk 31
compileSdk 32

defaultConfig {
applicationId "ru.itis.karakurik.androidLab2"
minSdk 23
targetSdk 31
targetSdk 32
versionCode 1
versionName "1.0"

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildFeatures {
viewBinding true
viewBinding = true
}

buildTypes {
Expand All @@ -38,6 +39,7 @@ android {
}

dependencies {
implementation 'com.google.android.gms:play-services-location:19.0.1'
def room_version = "2.4.2"
implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"
Expand All @@ -46,10 +48,22 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.3'
implementation "androidx.lifecycle:lifecycle-runtime-ktx:2.4.1"

//SwipeRefreshLayout
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"

//Timber
implementation 'com.jakewharton.timber:timber:5.0.1'

//Coil
implementation "io.coil-kt:coil:1.1.1"

def navigation = "2.4.1"
implementation "androidx.navigation:navigation-fragment-ktx:$navigation"
implementation "androidx.navigation:navigation-ui-ktx:$navigation"
implementation "androidx.navigation:navigation-runtime-ktx:$navigation"

def nav_version = "2.4.1"
implementation "androidx.navigation:navigation-fragment:$nav_version"
implementation "androidx.navigation:navigation-ui:$nav_version"

implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.0"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.0"
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,17 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ru.itis.karakurik.androidLab2" >
package="ru.itis.karakurik.androidLab2">

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.INTERNET" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/Theme.Androidlab2" >
android:theme="@style/Theme.Androidlab2"
android:usesCleartextTraffic="true">
<activity
android:name=".MainActivity"
android:exported="true" >
android:name=".presentation.activities.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
12 changes: 0 additions & 12 deletions app/src/main/java/ru/itis/karakurik/androidLab2/MainActivity.kt

This file was deleted.

21 changes: 21 additions & 0 deletions app/src/main/java/ru/itis/karakurik/androidLab2/data/api/Api.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package ru.itis.karakurik.androidLab2.data.api

import retrofit2.http.GET
import retrofit2.http.Query
import ru.itis.karakurik.androidLab2.data.api.response.citiesResponse.CitiesResponse
import ru.itis.karakurik.androidLab2.data.api.response.weatherResponse.WeatherResponse

interface Api {
@GET("weather")
suspend fun getWeather(@Query("q") city: String): WeatherResponse

@GET("weather")
suspend fun getWeather(@Query("id") id: Int): WeatherResponse

@GET("find")
suspend fun getWeathers(
@Query("lat") lat: Double,
@Query("lon") lon: Double,
@Query("cnt") cnt: Int
) : CitiesResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package ru.itis.karakurik.androidLab2.data.api.mapper

class WeatherIconUrlMapper {
fun map(iconId: String): String {
return "http://openweathermap.org/img/wn/${iconId}@2x.png"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package ru.itis.karakurik.androidLab2.data.api.mapper

import ru.itis.karakurik.androidLab2.data.api.response.citiesResponse.City
import ru.itis.karakurik.androidLab2.data.api.response.weatherResponse.WeatherResponse
import ru.itis.karakurik.androidLab2.domain.entity.Weather

class WeatherMapper(
private val windDegMapper: WindDegMapper,
private val weatherIconUrlMapper: WeatherIconUrlMapper
) {
fun map(weatherResponse: WeatherResponse) : Weather = Weather(
id = weatherResponse.id,
name = weatherResponse.name,
lat = weatherResponse.coord.lat,
lon = weatherResponse.coord.lon,
temp = weatherResponse.main.temp,
tempMin = weatherResponse.main.tempMin,
tempMax = weatherResponse.main.tempMax,
humidity = weatherResponse.main.humidity,
windDeg = windDegMapper.map(weatherResponse.wind.deg),
windSpeed = weatherResponse.wind.speed,
pressure = weatherResponse.main.pressure,
iconUrl = weatherIconUrlMapper.map(weatherResponse.weather[0].icon)
)

fun map(city: City) : Weather = Weather(
id = city.id,
name = city.name,
lat = city.coord.lat,
lon = city.coord.lon,
temp = city.main.temp,
tempMin = city.main.tempMin,
tempMax = city.main.tempMax,
humidity = city.main.humidity,
windDeg = windDegMapper.map(city.wind.deg),
windSpeed = city.wind.speed,
pressure = city.main.pressure,
iconUrl = weatherIconUrlMapper.map(city.weather[0].icon)
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package ru.itis.karakurik.androidLab2.data.api.mapper

import ru.itis.karakurik.androidLab2.domain.enum.WindDeg

class WindDegMapper {
fun map(deg: Int) : WindDeg {
return when ((deg / 45 + 2* (deg%45) / 45) * 45 % 360) {
0 -> WindDeg.N
45 -> WindDeg.NE
90 -> WindDeg.E
135 -> WindDeg.SE
180 -> WindDeg.S
225 -> WindDeg.SW
270 -> WindDeg.W
else -> WindDeg.NW
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class CitiesResponse(
@SerializedName("cod")
val cod: String,
@SerializedName("count")
val count: Int,
@SerializedName("list")
val list: List<City>,
@SerializedName("message")
val message: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class City (
@SerializedName("clouds")
val clouds: Clouds,
@SerializedName("coord")
val coord: Coord,
@SerializedName("dt")
val dt: Int,
@SerializedName("id")
val id: Int,
@SerializedName("main")
val main: Main,
@SerializedName("name")
val name: String,
@SerializedName("rain")
val rain: Any,
@SerializedName("snow")
val snow: Any,
@SerializedName("sys")
val sys: Sys,
@SerializedName("weather")
val weather: List<Weather>,
@SerializedName("wind")
val wind: Wind
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class Clouds(
@SerializedName("all")
val all: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class Coord(
@SerializedName("lat")
val lat: Double,
@SerializedName("lon")
val lon: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class Main(
@SerializedName("feels_like")
val feelsLike: Double,
@SerializedName("grnd_level")
val grndLevel: Int,
@SerializedName("humidity")
val humidity: Int,
@SerializedName("pressure")
val pressure: Int,
@SerializedName("sea_level")
val seaLevel: Int,
@SerializedName("temp")
val temp: Double,
@SerializedName("temp_max")
val tempMax: Double,
@SerializedName("temp_min")
val tempMin: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class Sys(
@SerializedName("country")
val country: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class Weather(
@SerializedName("description")
val description: String,
@SerializedName("icon")
val icon: String,
@SerializedName("id")
val id: Int,
@SerializedName("main")
val main: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.itis.karakurik.androidLab2.data.api.response.citiesResponse


import com.google.gson.annotations.SerializedName

data class Wind(
@SerializedName("deg")
val deg: Int,
@SerializedName("speed")
val speed: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package ru.itis.karakurik.androidLab2.data.api.response.weatherResponse


import com.google.gson.annotations.SerializedName

data class Clouds(
@SerializedName("all")
val all: Int
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package ru.itis.karakurik.androidLab2.data.api.response.weatherResponse


import com.google.gson.annotations.SerializedName

data class Coord(
@SerializedName("lat")
val lat: Double,
@SerializedName("lon")
val lon: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package ru.itis.karakurik.androidLab2.data.api.response.weatherResponse


import com.google.gson.annotations.SerializedName

data class Main(
@SerializedName("feels_like")
val feelsLike: Double,
@SerializedName("grnd_level")
val grndLevel: Int,
@SerializedName("humidity")
val humidity: Int,
@SerializedName("pressure")
val pressure: Int,
@SerializedName("sea_level")
val seaLevel: Int,
@SerializedName("temp")
val temp: Double,
@SerializedName("temp_max")
val tempMax: Double,
@SerializedName("temp_min")
val tempMin: Double
)
Loading