Skip to content

Commit

Permalink
prepare 1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
survivingwithandroid committed Jul 7, 2014
1 parent 5bd390b commit 5136eda
Show file tree
Hide file tree
Showing 9 changed files with 236 additions and 8 deletions.
4 changes: 2 additions & 2 deletions OkHttpClient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 1
versionName "1.5.1"
versionCode 152
versionName "1.5.2"
}
buildTypes {
release {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
package com.survivingwithandroid.weather.lib.demo15.fragment;


import android.app.Fragment;
import android.os.Bundle;


import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import android.widget.Toast;

import com.survivingwithandroid.weather.lib.WeatherClient;
import com.survivingwithandroid.weather.lib.WeatherConfig;
import com.survivingwithandroid.weather.lib.demo15.R;
import com.survivingwithandroid.weather.lib.exception.WeatherLibException;
import com.survivingwithandroid.weather.lib.exception.WeatherProviderInstantiationException;
import com.survivingwithandroid.weather.lib.model.HistoricalHourWeather;
import com.survivingwithandroid.weather.lib.model.HistoricalWeather;
import com.survivingwithandroid.weather.lib.provider.openweathermap.OpenweathermapProviderType;
import com.survivingwithandroid.weather.lib.request.WeatherRequest;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.List;


public class HistoricalWeatherFragment extends Fragment {

private RecyclerView rv;
private WeatherClient client;
private RecyclerWeatherAdapter rwa;

public HistoricalWeatherFragment() {
}


@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
WeatherClient.ClientBuilder builder = new WeatherClient.ClientBuilder();
WeatherConfig config = new WeatherConfig();

try {
client = builder.attach(getActivity())
.provider(new OpenweathermapProviderType())
.httpClient(com.survivingwithandroid.weather.lib.client.volley.WeatherClientDefault.class)
.config(config)
.build();
} catch (WeatherProviderInstantiationException wpie) {
wpie.printStackTrace();
}
}

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.fragment_historical_weather, container, false);
rv = (RecyclerView) v.findViewById(R.id.weather_recycler_view);
rv.setLayoutManager(new LinearLayoutManager(getActivity()));
rwa = new RecyclerWeatherAdapter(null);
rv.setAdapter(rwa);
return v;
}

@Override
public void onStart() {
super.onStart();

Calendar c1 = Calendar.getInstance();
c1.clear();
//c1.set(2014,Calendar.JANUARY,1,0,0,0);
c1.set(2014, Calendar.JULY, 6,0,0,0);

Date d1 = c1.getTime();

Calendar c2 = Calendar.getInstance();
c2.clear();
// c2.set(2014,Calendar.JANUARY, 2,0,0,0);
c2.set(2014, Calendar.JULY, 7,0,0,0);
Date d2 = c2.getTime();

//client.getHistoricalWeather(new WeatherRequest("2885679"), d1, d2, new WeatherClient.HistoricalWeatherEventListener() {
client.getHistoricalWeather(new WeatherRequest(56.0499F, 12.7067F), d1, d2, new WeatherClient.HistoricalWeatherEventListener() {
@Override
public void onWeatherRetrieved(HistoricalWeather histWeather) {

List<HistoricalHourWeather> histData = histWeather.getHoistoricalData();
Log.d("Hist", "Data ["+histData+"] - Size ["+histData.size()+"]");
rwa.setData(histData);
rwa.notifyDataSetChanged();

rv.setAdapter(rwa);
}

@Override
public void onWeatherError(WeatherLibException wle) {
Toast.makeText(getActivity(), "Error parsing the response", Toast.LENGTH_SHORT).show();
wle.printStackTrace();
}

@Override
public void onConnectionError(Throwable t) {
Toast.makeText(getActivity(), "Connection error", Toast.LENGTH_SHORT).show();
}
});

}


public static class RecyclerWeatherAdapter extends RecyclerView.Adapter<RecyclerWeatherAdapter.WeatherViewHolder> {

private List<HistoricalHourWeather> histData;
private SimpleDateFormat sdf = new SimpleDateFormat("EEE dd/MM/yyyy HH:mm");

public RecyclerWeatherAdapter(List<HistoricalHourWeather> histData) {
this.histData = histData;
}

@Override
public void onBindViewHolder(WeatherViewHolder weatherViewHolder, int i) {
HistoricalHourWeather hhw = histData.get(i);
Calendar c = Calendar.getInstance();
c.setTimeInMillis(hhw.timestamp);
String d = sdf.format(c.getTime());
weatherViewHolder.tvDate.setText(d);
weatherViewHolder.tvMinTemp.setText(String.valueOf(hhw.weather.temperature.getMinTemp()));
weatherViewHolder.tvMaxTemp.setText(String.valueOf(hhw.weather.temperature.getMaxTemp()));
}

@Override
public WeatherViewHolder onCreateViewHolder(ViewGroup viewGroup, int i) {
View v = LayoutInflater.from(viewGroup.getContext()).inflate(R.layout.hist_row, null);
WeatherViewHolder wvh = new WeatherViewHolder(v);
return wvh;
}

public static class WeatherViewHolder extends RecyclerView.ViewHolder {
protected TextView tvDate;
protected TextView tvMinTemp;
protected TextView tvMaxTemp;

public WeatherViewHolder(View v) {
super(v);
this.tvDate = (TextView) v.findViewById(R.id.hist_date);
this.tvMinTemp = (TextView) v.findViewById(R.id.hist_min_temp);
this.tvMaxTemp = (TextView) v.findViewById(R.id.hist_max_temp);
}
}


@Override
public int getItemCount() {
return histData == null ? 0 : histData.size();
}

@Override
public long getItemId(int position) {
return histData == null ? 0 : histData.get(position).hashCode();
}

public void setData(List<HistoricalHourWeather> histData) {
this.histData = histData;
}
}
}
6 changes: 6 additions & 0 deletions demo15/src/main/res/layout/drawer_list_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>

<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@android:id/text1"/>
13 changes: 13 additions & 0 deletions demo15/src/main/res/layout/fragment_historical_weather.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".fragment.HistoricalWeather">

<android.support.v7.widget.RecyclerView
android:id="@+id/weather_recycler_view"
android:scrollbars="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"/>

</FrameLayout>
33 changes: 33 additions & 0 deletions demo15/src/main/res/layout/hist_row.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?xml version="1.0" encoding="utf-8"?>

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">


<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/hist_date"
android:textColor="@android:color/white"
android:background="@android:color/holo_blue_dark"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hist_min_temp"
android:textColor="@android:color/holo_green_dark"
android:layout_below="@id/hist_date"
android:layout_marginTop="5dp"/>

<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/hist_max_temp"
android:textColor="@android:color/holo_red_dark"
android:layout_below="@id/hist_date"
android:layout_marginLeft="5dp"
android:layout_toRightOf="@id/hist_min_temp"
android:layout_alignBaseline="@id/hist_min_temp"/>

</RelativeLayout>
5 changes: 5 additions & 0 deletions demo15/src/main/res/values-v21/styles.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<style name="AppTheme" parent="android:Theme.Material.Light">
</style>
</resources>
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
VERSION_NAME=1.5.1
VERSION_CODE=11
VERSION_NAME=1.5.2
VERSION_CODE=12
GROUP=com.survivingwithandroid

POM_DESCRIPTION=Android Weather Lib
Expand Down
4 changes: 2 additions & 2 deletions lib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 5
versionName "1.5.1"
versionCode 152
versionName "1.5.2"
}
buildTypes {
release {
Expand Down
4 changes: 2 additions & 2 deletions volleyclient/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
defaultConfig {
minSdkVersion 9
targetSdkVersion 19
versionCode 2
versionName '1.5.1'
versionCode 152
versionName '1.5.2'
}
buildTypes {
release {
Expand Down

0 comments on commit 5136eda

Please sign in to comment.