8000 Pull Request by pronichenk · Pull Request #1 · raylemon/Weather · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Pull Request #1

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 24 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
16 changes: 0 additions & 16 deletions .idea/misc.xml

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

4 changes: 2 additions & 2 deletions .idea/modules.xml

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

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

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

Original file line number Diff line number Diff line change
@@ -1,12 +1,97 @@
package com.github.raylemon.weather.data.domain

import java.util.*
import android.os.Parcel
import android.os.Parcelable

/**
* Created by big04 on 06-03-16.
*/
data class ForecastList(val city: String, val country: String, val weather: List<Forecast>) {
data class ForecastList(val city: String, val country: String, val weather: List<Forecast>) : Parcelable {
operator fun get(position: Int) = weather[position]

val size = weather.size

constructor(source: Parcel): this(source.readString(), source.readString(), ArrayList<Forecast>().apply { source.readTypedList(this, Forecast.CREATOR)})

override fun describeContents(): Int {
return 0
}

override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeString(city)
dest?.writeString(country)
dest?.writeList(weather)
}

companion object {
@JvmField final val CREATOR: Parcelable.Creator<ForecastList> = object : Parcelable.Creator<ForecastList> {
override fun createFromParcel(source: Parcel): ForecastList {
return ForecastList(source)
}

override fun newArray(size: Int): Array<ForecastList?> {
return arrayOfNulls(size)
}
}
}
}

data class Forecast(val dt: Long, val desc: String, val icon: String, val temp: Temperatures, val pressure: Float, val humidity: Int) : Parcelable {
constructor(source: Parcel): this(source.readLong(), source.readString(), source.readString(), source.readTypedObject(Temperatures.CREATOR), source.readFloat(), source.readInt())

override fun describeContents(): Int {
return 0
}

override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeLong(dt)
dest?.writeString(desc)
dest?.writeString(icon)
dest?.writeTypedObject(temp, flags)
dest?.writeFloat(pressure)
dest?.writeInt(humidity)
}

companion object {
@JvmField final val CREATOR: Parcelable.Creator<Forecast> = object : Parcelable.Creator<Forecast> {
override fun createFromParcel(source: Parcel): Forecast {
return Forecast(source)
}

override fun newArray(size: Int): Array<Forecast?> {
return arrayOfNulls(size)
}
}
}
}

data class Temperatures(val day: Float, val min: Float, val max: Float, val night: Float, val eve: Float, val morn: Float) : Parcelable {
constructor(source: Parcel): this(source.readFloat(), source.readFloat(), source.readFloat(), source.readFloat(), source.readFloat(), source.readFloat())

override fun describeContents(): Int {
return 0
}

override fun writeToParcel(dest: Parcel?, flags: Int) {
dest?.writeFloat(day)
dest?.writeFloat(min)
dest?.writeFloat(max)
dest?.writeFloat(night)
dest?.writeFloat(eve)
dest?.writeFloat(morn)
}

companion object {
@JvmField final val CREATOR: Parcelable.Creator<Temperatures> = object : Parcelable.Creator<Temperatures> {
override fun createFromParcel(source: Parcel): Temperatures {
return Temperatures(source)
}

override fun newArray(size: Int): Array<Temperatures?> {
return arrayOfNulls(size)
}
}
}
}

data class Forecast(val dt: Long, val desc: String, val icon: String, val temp: Temperatures)
data class Temperatures(val day: Float, val min: Float, val max: Float, val night: Float, val eve: Float, val morn: Float)
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ object JsonMapper {
private fun convertListToDomain(list: List<Forecast>) = list.map { convertItemToDomain(it) }

private fun convertItemToDomain(item: Forecast) = with(item) {
DomainForecast(dt = dt, desc = weather.first().description, icon = fullUrl(weather.first().icon), temp = convertTempToDomain(temp))
DomainForecast(dt = dt, desc = weather.first().description, icon = fullUrl(weather.first().icon), temp = convertTempToDomain(temp), pressure = pressure, humidity = humidity)
}

private fun convertTempToDomain(temp: Temperatures) = with(temp) {
Expand Down
27 changes: 27 additions & 0 deletions app/src/main/java/com/github/raylemon/weather/ui/DetailAktivity.kt
F438
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.github.raylemon.weather.ui

import android.os.Bundle
import android.support.design.widget.CollapsingToolbarLayout
import android.support.v7.app.AppCompatActivity
import android.support.v7.widget.Toolbar
import com.github.raylemon.weather.R
import com.github.raylemon.weather.data.domain.Forecast
import org.jetbrains.anko.find

/**
* Created by big04 on 13-03-16.
*/
class DetailAktivity : AppCompatActivity() {

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.detail_aktivity)
val forecast = intent.getParcelableExtra<Forecast>(DetailFragment.KEY)
if (savedInstanceState == null ) fragmentManager
.beginTransaction()
.replace(R.id.container, DetailFragment().apply {
arguments = Bundle().apply { putParcelable(DetailFragment.KEY, forecast) }
})
.commit()
}
}
71 changes: 71 additions & 0 deletions app/src/main/java/com/github/raylemon/weather/ui/DetailFragment.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.github.raylemon.weather.ui

import android.app.Fragment
import android.os.Bundle
import android.support.v4.content.ContextCompat
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import com.github.raylemon.weather.R
import com.github.raylemon.weather.data.domain.Forecast
import com.github.raylemon.weather.ext.toDate
import kotlinx.android.synthetic.main.detail_fragment.*

/**
* Created by christophe on 14/03/16.
*/
class DetailFragment : Fragment() {
private lateinit var forecast : Forecast
private set

companion object {
const val KEY = "forecast"
const val CITY = "city"
}

override fun onCreate(savedInstanceState: Bundle?){
super.onCreate(savedInstanceState)
if (arguments != null && arguments.containsKey(KEY)) forecast = arguments.getParcelable(KEY)
}

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return inflater.inflate(R.layout.detail_fragment, container)
}

override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
with (forecast) {
vDate.text = dt.toDate()
vDescription.text = desc
vMaxTemp.text = temp.max.toString() + "°C"
vMinTemp.text = temp.min.toString() + "°C"
vPressure.text = pressure.toString() + "hPa"
vHumidity.text = humidity.toString() + "%"
vDay.apply {
text = temp.day.toString() + "°C"
setBackgroundColor(defineColor(temp.day))
}
vNight.apply {
text = temp.night.toString() + "°C"
setBackgroundColor(defineColor(temp.night))
}
vMorn.apply {
text = temp.morn.toString() + "°C"
setBackgroundColor(defineColor(temp.morn))
}

vEve.apply {
text = temp.eve.toString() + "°C"
setBackgroundColor(defineColor(temp.eve))
}

}
}

private fun defineColor(temp: Float) = when {
temp < 10f -> ContextCompat.getColor(activity, R.color.frost)
temp in 10f..20f -> ContextCompat.getColor(activity, R.color.mid_frost)
temp in 20f..30f -> ContextCompat.getColor(activity, R.color.mid_warm)
else -> ContextCompat.getColor(activity, R.color.warm)
}
}
Original file line number Diff line number Diff line change
@@ -1,36 +1,50 @@
package com.github.raylemon.weather.ui

import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v7.app.AppCompatActivity
import com.github.raylemon.weather.R
import com.github.raylemon.weather.data.JsonServer
import com.github.raylemon.weather.ext.toDate
import com.github.raylemon.weather.ui.adapter.ForecastAdapter
import kotlinx.android.synthetic.main.forecast_list.*
import kotlinx.android.synthetic.main.main_activity.*
import org.jetbrains.anko.async
import org.jetbrains.anko.toast
import org.jetbrains.anko.uiThread
import org.jetbrains.anko.startActivity

/**
* Created by big04 on 06-03-16.
*/
class MainAktivity : AppCompatActivity() {

private val prefs by lazy { PreferenceManager.getDefaultSharedPreferences(this) }
private val city by lazy { prefs.getString(PreferencesDialog.CITY_KEY, "Brussels") }
private val cnt by lazy { prefs.getInt(PreferencesDialog.CNT_KEY, 7) }

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main_activity)
fab.setOnClickListener {
PreferencesDialog().show(supportFragmentManager, "prefs")
}
}

private val cnt = 16
private val city = "Wavre"

override fun onResume() {
super.onResume()
async() {
val items = JsonServer().getForecast(cnt, city)
uiThread {
vForecastList.adapter = ForecastAdapter(items) {
toast(it.dt.toDate())
vForecastList.adapter = ForecastAdapter(items) { forecast ->
if (!resources.getBoolean(R.bool.twoPane)) startActivity<DetailAktivity>(DetailFragment.KEY to forecast, DetailFragment.CITY to city)
else
fragmentManager
.beginTransaction()
.replace(R.id.container, DetailFragment().apply {
arguments = Bundle().apply { putParcelable(DetailFragment.KEY, forecast) }
})
.commit()
}
}
}
Expand Down
53A1
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.github.raylemon.weather.ui

import android.app.Dialog
import android.os.Bundle
import android.preference.PreferenceManager
import android.support.v7.app.AppCompatDialogFragment
import android.view.LayoutInflater
import android.widget.EditText
import android.widget.NumberPicker
import com.github.raylemon.weather.R
import kotlinx.android.synthetic.main.pref_dialog.*
import org.jetbrains.anko.AlertDialogBuilder
import org.jetbrains.anko.find

/**
* Created by christophe on 14/03/16.
*/
class PreferencesDialog() : AppCompatDialogFragment() {
companion object {
const val CITY_KEY = "City"
const val CNT_KEY = "cnt"
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val view = LayoutInflater.from(activity).inflate(R.layout.pref_dialog, null)
val prefs = PreferenceManager.getDefaultSharedPreferences(activity)
view.find<EditText>(R.id.vPrefCity).setText(prefs.getString(CITY_KEY,""))
val pick = view.find<NumberPicker>(R.id.vDayPicker).apply {
minValue = 1
maxValue = 16
value = prefs.getInt(CNT_KEY, 7)
}
return AlertDialogBuilder(activity).apply {
title("Preferences")
customView(view)
positiveButton("Set !")
{
with (prefs.edit()){
putString(CITY_KEY, vPrefCity.text.toString())
putInt(CNT_KEY, vDayPicker.value)
}
}
negativeButton("Cancel") { cancel() }
}.builder.create()
}
}
26 changes: 26 additions & 0 deletions app/src/main/res/layout-xlarge/forecast_list.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
android:divider="?attr/dividerHorizontal"
android:showDividers="middle">

<android.support.v7.widget.RecyclerView

android:id="@+id/vForecastList"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_marginLeft="16dp"
android:layout_marginRight="16dp"
app:layoutManager="LinearLayoutManager" />

<FrameLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"
android:id="@+id/container"/>

</LinearLayout>
Loading
0