Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
144a0cc
add observable search
Jina-n11 Aug 8, 2022
86defb3
Merge pull request #1 from devfalah/feature/search
Jina-n11 Aug 8, 2022
c55ffba
add api client class
Jina-n11 Aug 8, 2022
82f6f27
Merge pull request #2 from devfalah/feature/search
Jina-n11 Aug 8, 2022
dd67832
add weather service
devfalah Aug 10, 2022
8da3853
add weather repository
devfalah Aug 10, 2022
836bc52
Merge pull request #4 from devfalah/feature/add_weather_repository
devfalah Aug 9, 2022
8eecdc3
activity_main.xml -> i did edit text color to gray and edit backgroun…
moh05hus Aug 10, 2022
0c17b3c
change observable type
Aug 10, 2022
c5eb0ad
subscribe on observable
Aug 10, 2022
c0a41d7
delete unused code
Aug 10, 2022
1eb44b8
delete JsonParser
Aug 10, 2022
0d91393
Merge pull request #6 from devfalah/feature/subscribe_to_observable
karrarjasim Aug 10, 2022
91fc4b0
Merge pull request #7 from devfalah/feature/ui_details
karrarjasim Aug 10, 2022
ced3051
Merge pull request #8 from devfalah/feature/add_loading_logic
devfalah Aug 11, 2022
3ba85a0
activity_main.xml -> i did edit ui space , and show search error
moh05hus Aug 11, 2022
cd9fa8b
add loading logic
devfalah Aug 11, 2022
332a4b8
remove unused lottie files
devfalah Aug 11, 2022
7bda90e
remove unused class
devfalah Aug 11, 2022
0d9f6e5
add serialized name to all models
devfalah Aug 11, 2022
4490eb8
remove never used extensions
devfalah Aug 11, 2022
cca1c8f
edit constants name
devfalah Aug 11, 2022
01fff53
Merge pull request #9 from devfalah/feature/code_refactoring
devfalah Aug 11, 2022
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/.name

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

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.

4 changes: 3 additions & 1 deletion .idea/misc.xml

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

3 changes: 3 additions & 0 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,7 @@ dependencies {
implementation 'com.google.code.gson:gson:2.9.0'
implementation 'com.squareup.okhttp3:okhttp:4.10.0'
implementation 'com.airbnb.android:lottie:5.2.0'
implementation "io.reactivex.rxjava3:rxjava:3.1.5"
implementation 'io.reactivex.rxjava3:rxandroid:3.0.0'

}
7 changes: 7 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/State.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package com.cheese.weatherapp.data

sealed class State<out T> {
object Loading : State<Nothing>()
data class Fail(val message: String) : State<Nothing>()
data class Success<T>(val data: T) : State<T>()
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/models/Clouds.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class Clouds (
@SerializedName("all")
val all: Double
)
10 changes: 10 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/models/Coord.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class Coord (
@SerializedName("lon")
val lon: Double,
@SerializedName("lat")
val lat: Double
)
Original file line number Diff line number Diff line change
@@ -1,19 +1,16 @@
package com.cheese.weatherapp.models
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class Main (
@SerializedName("temp")
val temp: Double,

// @SerializedName("feels_like")
// val feelsLike: Double,

@SerializedName("temp_min")
val tempMin: Double,

@SerializedName("temp_max")
val tempMax: Double,

@SerializedName("pressure")
val pressure: Double,
@SerializedName("humidity")
val humidity: Double
)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cheese.weatherapp.models
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

Expand Down
16 changes: 16 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/models/Sys.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class Sys (
@SerializedName("type")
val type: Int,
@SerializedName("id")
val id: Int,
@SerializedName("country")
val country: String,
@SerializedName("sunrise")
val sunrise: Long,
@SerializedName("sunset")
val sunset: Long
)
11 changes: 11 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/models/Weather.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class Weather (
@SerializedName("main")
val main: String,
@SerializedName("description")
val description: String,
)

28 changes: 28 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/models/WeatherMain.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class WeatherMain(
@SerializedName("wind")
val wind: Wind,
@SerializedName("rain")
val rain :Rain,
@SerializedName("clouds")
val clouds: Clouds,
@SerializedName("name")
val name: String,
@SerializedName("weather")
val weather: List<Weather>,
@SerializedName("base")
val base: String,
@SerializedName("main")
val main: Main,
@SerializedName("sys")
val sys: Sys,
@SerializedName("cod")
val cod: Int,
@SerializedName("message")
val message: String,


)
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.cheese.weatherapp.models
package com.cheese.weatherapp.data.models

enum class WeatherState {
CLOUDS,
Expand Down
8 changes: 8 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/data/models/Wind.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.cheese.weatherapp.data.models

import com.google.gson.annotations.SerializedName

data class Wind (
@SerializedName("speed")
val speed: Double,
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.cheese.weatherapp.data.repository

import com.cheese.weatherapp.data.State
import com.cheese.weatherapp.data.models.Weather
import com.cheese.weatherapp.data.services.BaseWeatherService
import com.cheese.weatherapp.data.models.WeatherMain
import io.reactivex.rxjava3.core.Observable

interface WeatherRepository {
fun getWeatherByCityName(cityName: String): Observable<State<WeatherMain>>
}

class WeatherRepositoryImp(private val weatherService: BaseWeatherService) : WeatherRepository {
override fun getWeatherByCityName(cityName: String): Observable<State<WeatherMain>> {
return Observable.create { emit ->
emit.onNext(State.Loading)
emit.onNext(weatherService.getWeatherByCityName(cityName))
emit.onComplete()
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.cheese.weatherapp.data.services

import com.example.mikmok.util.Constants
import com.example.mikmok.util.Params
import okhttp3.HttpUrl
import okhttp3.Request

object RequestHelper {
fun makeWeatherRequest(cityName: String): Request {
val url= HttpUrl.Builder()
.scheme(Constants.SCHEMA)
.host(Constants.HOST)
.addPathSegment(Constants.PATH)
.addQueryParameter(Params.UNITS, Params.Values.units)
.addQueryParameter(Params.APP_ID, Params.Values.APP_ID)
.addQueryParameter(Params.CITY,cityName)
.build()
return Request.Builder()
.url(url)
.get()
.addHeader(Constants.ACCEPT, Constants.TYPE)
.build()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.cheese.weatherapp.data.services

import com.cheese.weatherapp.data.State
import com.cheese.weatherapp.data.models.WeatherMain
import com.google.gson.Gson
import okhttp3.OkHttpClient

interface BaseWeatherService {
fun getWeatherByCityName(cityName: String): State<WeatherMain>

}

class WeatherService : BaseWeatherService {
private val client = OkHttpClient()
override fun getWeatherByCityName(cityName: String): State<WeatherMain> {
val response = client.newCall(RequestHelper.makeWeatherRequest(cityName)).execute()
return if (response.isSuccessful) {
Gson().fromJson(response.body?.string(), WeatherMain::class.java).run {
State.Success(this)
}
} else {
State.Fail(response.message)
}
}
}
5 changes: 0 additions & 5 deletions app/src/main/java/com/cheese/weatherapp/models/Clouds.kt

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/java/com/cheese/weatherapp/models/Coord.kt

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/java/com/cheese/weatherapp/models/Sys.kt

This file was deleted.

9 changes: 0 additions & 9 deletions app/src/main/java/com/cheese/weatherapp/models/Weather.kt

This file was deleted.

69 changes: 0 additions & 69 deletions app/src/main/java/com/cheese/weatherapp/models/WeatherMain.kt

This file was deleted.

6 changes: 0 additions & 6 deletions app/src/main/java/com/cheese/weatherapp/models/Wind.kt

This file was deleted.

3 changes: 3 additions & 0 deletions app/src/main/java/com/cheese/weatherapp/ui/BaseActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.cheese.weatherapp.ui
import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import androidx.viewbinding.ViewBinding
Expand Down Expand Up @@ -37,4 +38,6 @@ abstract class BaseActivity<VB :ViewBinding> :AppCompatActivity() {
).show()
}



}
Loading