Skip to content
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
1 change: 1 addition & 0 deletions .idea/gradle.xml

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

2 changes: 1 addition & 1 deletion .idea/misc.xml

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

68 changes: 68 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'kotlin-kapt'

android {
compileSdkVersion 30
Expand All @@ -16,20 +17,87 @@ android {
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}



androidExtensions {
experimental = true
}

buildFeatures {
viewBinding true
}

buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
}

buildTypes.each {
it.buildConfigField 'String', 'API_ENDPOINT', baseUrl
it.buildConfigField 'String', 'API_KEY', apiKey
}

compileOptions {
sourceCompatibility = "1.8"
targetCompatibility = "1.8"
}
}

def retrofit = "2.9.0"
def moxy = "2.2.1"

dependencies {
implementation fileTree(dir: "libs", include: ["*.jar"])
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
implementation 'androidx.core:core-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2"
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.2"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.2.0'
implementation 'com.google.android.material:material:1.1.0'



def room_version = "2.2.6"

implementation "androidx.room:room-runtime:$room_version"
kapt "androidx.room:room-compiler:$room_version"

// optional - Kotlin Extensions and Coroutines support for Room
implementation "androidx.room:room-ktx:$room_version"

// optional - Test helpers
testImplementation "androidx.room:room-testing:$room_version"


// region Retrofit
implementation "com.squareup.retrofit2:retrofit:${retrofit}"
implementation "com.squareup.retrofit2:converter-gson:${retrofit}"
implementation "com.squareup.retrofit2:adapter-rxjava2:2.9.0"
// endregion

//RecylerView
implementation 'androidx.recyclerview:recyclerview:1.1.0'

//CircleImage
implementation 'de.hdodenhof:circleimageview:3.1.0'

//Google Service Location
implementation 'com.google.android.gms:play-services-location:15.0.1'

implementation 'com.squareup.okhttp3:logging-interceptor:3.12.8' // 3.13.+ require minSDK 21

//Moxy
implementation "com.github.moxy-community:moxy:$moxy"
implementation "com.github.moxy-community:moxy-androidx:$moxy"
implementation "com.github.moxy-community:moxy-ktx:$moxy"
kapt "com.github.moxy-community:moxy-compiler:$moxy"

testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,26 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.androidpractice2020">

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

<application
android:name=".application.WeatherApplication"
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/AppTheme">
<activity android:name=".MainActivity">
<activity android:name=".presentation.activity.MainActivity">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name=".presentation.activity.DetailCityActivity" />
</application>

</manifest>
Binary file added app/src/main/ic_geo-playstore.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 0 additions & 11 deletions app/src/main/java/com/example/androidpractice2020/MainActivity.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.androidpractice2020.application

import android.app.Application
import com.example.androidpractice2020.data.api.ApiFactory
import com.example.androidpractice2020.data.database.WeatherRoomDatabase
import com.example.androidpractice2020.data.database.repository.WeatherRepositoryImpl

class WeatherApplication : Application() {

val database by lazy {
WeatherRoomDatabase.getDataBase(this)
}

val repository by lazy {
WeatherRepositoryImpl(
ApiFactory.weatherApi,
database.weatherDao()
)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.androidpractice2020.data

import android.annotation.SuppressLint
import android.location.Location
import com.google.android.gms.location.FusedLocationProviderClient
import kotlinx.coroutines.suspendCancellableCoroutine
import kotlin.coroutines.resume
import kotlin.coroutines.resumeWithException

class LocationRepositoryImpl(
private var client: FusedLocationProviderClient
) {

@SuppressLint("MissingPermission")
suspend fun getUserLocation(): Location = suspendCancellableCoroutine { continuation ->
client.lastLocation.addOnSuccessListener {
continuation.resume(it)
}.addOnFailureListener {
continuation.resumeWithException(it)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package com.example.androidpractice2020.data.api

import com.example.androidpractice2020.BuildConfig
import okhttp3.Interceptor
import okhttp3.OkHttpClient
import retrofit2.Retrofit
import retrofit2.converter.gson.GsonConverterFactory
import java.util.concurrent.TimeUnit

object ApiFactory {

private val QUERY_API_KEY = "appid"
private val QUERY_UNIT = "units"


private val apiKeyInterceptor = Interceptor { chain ->
val original = chain.request()
original.url().newBuilder()
.addQueryParameter(QUERY_API_KEY, BuildConfig.API_KEY)
.build().let {
chain.proceed(
original.newBuilder().url(it).build()
)
}
}

private val unitsInterceptor = Interceptor { chain ->
val original = chain.request()
original.url().newBuilder()
.addQueryParameter(QUERY_UNIT, "metric")
.build().let {
chain.proceed(
original.newBuilder().url(it).build()
)
}
}

private val client by lazy {
OkHttpClient.Builder()
.connectTimeout(30, TimeUnit.SECONDS)
.addInterceptor(apiKeyInterceptor)
.addInterceptor(unitsInterceptor)
.addInterceptor(LoggingInterceptor())
.build()
}

private val retrofit by lazy {
Retrofit.Builder()
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.baseUrl(BuildConfig.API_ENDPOINT)
.build()
}

val weatherApi by lazy {
retrofit.create(
WeatherApi::class.java
)
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.example.androidpractice2020.data.api

import com.example.androidpractice2020.BuildConfig
import okhttp3.logging.HttpLoggingInterceptor
import okhttp3.Interceptor
import okhttp3.Response
import java.io.IOException

class LoggingInterceptor(
private val loggingInterceptor: HttpLoggingInterceptor =
HttpLoggingInterceptor().setLevel(
if (BuildConfig.DEBUG)
HttpLoggingInterceptor.Level.BODY
else
HttpLoggingInterceptor.Level.NONE
)
) : Interceptor {

@Throws(IOException::class)
override fun intercept(chain: Interceptor.Chain): Response =
loggingInterceptor.intercept(chain)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.example.androidpractice2020.data.api

import com.example.androidpractice2020.data.api.response.CitiesWeatherResponse
import com.example.androidpractice2020.data.api.response.WeatherResponse
import retrofit2.http.GET
import retrofit2.http.Query

interface WeatherApi {

@GET("weather?lang=ru")
suspend fun getWeather(
@Query("q") cityName: String
): WeatherResponse

@GET("find?lang=ru")
suspend fun getCitiesWeather(
@Query("lat") latitudeUser: Double,
@Query("lon") longitude: Double,
@Query("cnt") countCities: Int
): CitiesWeatherResponse

@GET("weather?lang=ru")
suspend fun getCityById(
@Query("id") cityId: Int
): WeatherResponse
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.androidpractice2020.data.api.response

data class CitiesWeatherResponse(
val cod: String,
val count: Int,
val list: ArrayList<InfoCity>,
val message: String
)

data class InfoCity(
val clouds: Clouds,
val coord: Coord,
val dt: Int,
val id: Int,
val main: Main,
val name: String,
val rain: Any,
val snow: Any,
val sys: Sys,
val weather: List<Weather>,
val wind: Wind
)

Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package com.example.androidpractice2020.data.api.response


data class WeatherResponse(
val base: String,
val clouds: Clouds,
val cod: Int,
val coord: Coord,
val dt: Int,
val id: Int,
val main: Main,
val name: String,
val sys: Sys,
val timezone: Int,
val visibility: Int,
val weather: List<Weather>,
val wind: Wind
)

data class Clouds(
val all: Int
)

data class Coord(
val lat: Double,
val lon: Double
)

data class Main(
val feels_like: Double,
val humidity: Int,
val pressure: Int,
val temp: Double,
val temp_max: Double,
val temp_min: Double
)

data class Sys(
val country: String,
val id: Int,
val sunrise: Int,
val sunset: Int,
val type: Int
)

data class Weather(
val description: String,
val icon: String,
val id: Int,
val main: String
)

data class Wind(
val deg: Int,
val speed: Double
)
Loading