forecast
This commit is contained in:
parent
95655c3880
commit
3222f7392e
@ -1,11 +1,14 @@
|
|||||||
package com.amine.myterio.app;
|
package com.amine.myterio.app;
|
||||||
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.v7.app.ActionBarActivity;
|
import android.support.v7.app.AppCompatActivity;
|
||||||
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
import com.amine.myterio.app.adapters.ForecastAdapter;
|
||||||
import com.amine.myterio.app.api.WeatherAdapters;
|
import com.amine.myterio.app.api.WeatherAdapters;
|
||||||
import com.amine.myterio.app.api.WeatherApis;
|
import com.amine.myterio.app.api.WeatherApis;
|
||||||
import com.amine.myterio.app.model.City;
|
import com.amine.myterio.app.model.City;
|
||||||
@ -15,7 +18,7 @@ import retrofit.RetrofitError;
|
|||||||
import retrofit.client.Response;
|
import retrofit.client.Response;
|
||||||
|
|
||||||
|
|
||||||
public class DetailsActivity extends ActionBarActivity {
|
public class DetailsActivity extends AppCompatActivity {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@ -26,6 +29,11 @@ public class DetailsActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
WeatherAdapters adapters = new WeatherAdapters();
|
WeatherAdapters adapters = new WeatherAdapters();
|
||||||
final Forecast[] f = {null};
|
final Forecast[] f = {null};
|
||||||
|
final RecyclerView list = (RecyclerView) findViewById(R.id.weekForecast);
|
||||||
|
LinearLayoutManager layoutManager = new LinearLayoutManager(this);
|
||||||
|
list.setLayoutManager(layoutManager);
|
||||||
|
list.setHasFixedSize(true);
|
||||||
|
|
||||||
|
|
||||||
if (cityName != null) {
|
if (cityName != null) {
|
||||||
WeatherApis.WeatherDailyForecastLocationApi s = adapters.getWeatherForecastLocationAdapter();
|
WeatherApis.WeatherDailyForecastLocationApi s = adapters.getWeatherForecastLocationAdapter();
|
||||||
@ -34,6 +42,8 @@ public class DetailsActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void success(Forecast forecast, Response response) {
|
public void success(Forecast forecast, Response response) {
|
||||||
f[0] = forecast;
|
f[0] = forecast;
|
||||||
|
list.setAdapter(new ForecastAdapter(DetailsActivity.this, f[0]));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -50,6 +60,7 @@ public class DetailsActivity extends ActionBarActivity {
|
|||||||
@Override
|
@Override
|
||||||
public void success(Forecast forecast, Response response) {
|
public void success(Forecast forecast, Response response) {
|
||||||
f[0] = forecast;
|
f[0] = forecast;
|
||||||
|
list.setAdapter(new ForecastAdapter(DetailsActivity.this, f[0]));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -61,9 +72,6 @@ public class DetailsActivity extends ActionBarActivity {
|
|||||||
|
|
||||||
TextView name = (TextView) findViewById(R.id.cityName);
|
TextView name = (TextView) findViewById(R.id.cityName);
|
||||||
name.setText(cityName);
|
name.setText(cityName);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -0,0 +1,62 @@
|
|||||||
|
package com.amine.myterio.app.adapters;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.support.v7.widget.RecyclerView;
|
||||||
|
import android.view.LayoutInflater;
|
||||||
|
import android.view.View;
|
||||||
|
import android.view.ViewGroup;
|
||||||
|
import android.widget.TextView;
|
||||||
|
import com.amine.myterio.app.R;
|
||||||
|
import com.amine.myterio.app.model.Forecast;
|
||||||
|
import com.amine.myterio.app.model.ForecastWeather;
|
||||||
|
|
||||||
|
import java.text.DateFormat;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class ForecastAdapter extends RecyclerView.Adapter<ForecastAdapter.ViewHolder> {
|
||||||
|
private static Forecast forecast;
|
||||||
|
private static Context c;
|
||||||
|
|
||||||
|
public ForecastAdapter(Context c, Forecast forecast) {
|
||||||
|
this.forecast = forecast;
|
||||||
|
this.c = c;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ForecastAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||||
|
View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.detail_item, parent, false);
|
||||||
|
ViewHolder vh = new ViewHolder(v);
|
||||||
|
return vh;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onBindViewHolder(ForecastAdapter.ViewHolder holder, int position) {
|
||||||
|
ForecastWeather fw = this.forecast.getList().get(position);
|
||||||
|
// MARCHE PAS
|
||||||
|
Date date = new Date(fw.getDt());
|
||||||
|
DateFormat format = new SimpleDateFormat("EEEE");
|
||||||
|
String finalDay = format.format(date);
|
||||||
|
|
||||||
|
TextView dateView = (TextView) holder.itemView.findViewById(R.id.dateText);
|
||||||
|
TextView temp = (TextView) holder.itemView.findViewById(R.id.temp);
|
||||||
|
|
||||||
|
dateView.setText(finalDay);
|
||||||
|
temp.setText(fw.getTemp().getDay() + "");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemCount() {
|
||||||
|
return forecast.getList().size();
|
||||||
|
}
|
||||||
|
|
||||||
|
public class ViewHolder extends RecyclerView.ViewHolder {
|
||||||
|
public View itemView;
|
||||||
|
|
||||||
|
public ViewHolder(View itemView) {
|
||||||
|
super(itemView);
|
||||||
|
this.itemView = itemView;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -6,6 +6,7 @@ public class ForecastWeather {
|
|||||||
public TempInfo temp;
|
public TempInfo temp;
|
||||||
public List<Weather> weather;
|
public List<Weather> weather;
|
||||||
public float speed;
|
public float speed;
|
||||||
|
public int dt;
|
||||||
|
|
||||||
public TempInfo getTemp() {
|
public TempInfo getTemp() {
|
||||||
return temp;
|
return temp;
|
||||||
@ -30,4 +31,12 @@ public class ForecastWeather {
|
|||||||
public void setSpeed(float speed) {
|
public void setSpeed(float speed) {
|
||||||
this.speed = speed;
|
this.speed = speed;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDt() {
|
||||||
|
return dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDt(int dt) {
|
||||||
|
this.dt = dt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -24,7 +24,7 @@
|
|||||||
android:layout_centerHorizontal="true"
|
android:layout_centerHorizontal="true"
|
||||||
android:layout_marginTop="20dp"/>
|
android:layout_marginTop="20dp"/>
|
||||||
|
|
||||||
<ListView
|
<android.support.v7.widget.RecyclerView
|
||||||
android:id="@+id/weekForecast"
|
android:id="@+id/weekForecast"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
|
22
app/src/main/res/layout/detail_item.xml
Normal file
22
app/src/main/res/layout/detail_item.xml
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="fill_parent"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/dateText"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight=".2"
|
||||||
|
android:text="Large Text"
|
||||||
|
android:textAppearance="?android:attr/textAppearanceLarge"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/temp"
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_weight=".4"
|
||||||
|
android:text="New Text"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
Loading…
Reference in New Issue
Block a user