Skip to content

Commit

Permalink
Merge pull request #137 in MOB/climate-android from ~KBAYGAN/climate-…
Browse files Browse the repository at this point in the history
…android:basic618 to master

Squashed commit of the following:

commit 13e4797b4024740769ebe66444ed59516320693a
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 17:12:10 2015 -0800

    replaced string resource names with resource ids

commit abb6c72d12d9c290760646f2a8ba3957080605e0
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 16:43:30 2015 -0800

    deleted setUnknown from fieldparser

commit 81426564c8c180b97263330f1fb84dc1dfc50a00
Merge: 958346c afc272a
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 15:48:36 2015 -0800

    another merge

commit 958346cdfc3dddd037d9d391ca54909adad6c3e3
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 15:41:21 2015 -0800

    moved some strings into final constants

commit bba706eb5ed8d53151d68a7d76daf6987f6f22af
Merge: f6cbedf 91bc88b
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 14:49:13 2015 -0800

    merge

commit f6cbedf52f2a291cd844d72e60538eaeeb873131
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 11:39:38 2015 -0800

    Removed the word day from image file names

commit bd8b547648cf4bd875415d5f16e0c9ff4298f878
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 11:28:09 2015 -0800

    replaced harcoded unknown with a static variable

commit e510875ded64aeb0f1e5c7d8178a46d093c6d7c3
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 10:59:06 2015 -0800

    Fixed a crash bug in ModuleLauncherAdapter. Need to check the size before operation. Moved the wind layout 2 dp up

commit c42596ef8431cabfca383698291f50d40a609ac8
Merge: ac73174 026c30a
Author: Kaz Baygan <kazb@baygan.com>
Date:   Mon Mar 2 10:43:26 2015 -0800

    merge

commit ac7317431c25cfb4d73d4785d27bade8fbda22fe
Author: Kaz Baygan <kazb@baygan.com>
Date:   Sun Mar 1 17:14:40 2015 -0800

    Basic 618 and Basic 633 - Current conditions and forecast on field summary
  • Loading branch information
Kaz Baygan committed Mar 3, 2015
1 parent afc272a commit a0d1016
Show file tree
Hide file tree
Showing 182 changed files with 462 additions and 226 deletions.
Expand Up @@ -9,6 +9,7 @@
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="ASSEMBLE_TEST_TASK_NAME" value="assembleDebugTest" />
Expand Down
@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
<module external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" external.system.module.group="ClimateGrowersProject" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet type="android-gradle" name="Android-Gradle">
<configuration>
Expand Down
39 changes: 20 additions & 19 deletions ClimateGrowersProject/ClimateGrowersApp/ClimateGrowersApp.iml
Expand Up @@ -8,35 +8,36 @@
</facet>
<facet type="android" name="Android">
<configuration>
<option name="SELECTED_BUILD_VARIANT" value="release" />
<option name="ASSEMBLE_TASK_NAME" value="assembleRelease" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileReleaseSources" />
<option name="SOURCE_GEN_TASK_NAME" value="generateReleaseSources" />
<option name="SELECTED_BUILD_VARIANT" value="debug" />
<option name="SELECTED_TEST_ARTIFACT" value="_android_test_" />
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
<option name="SOURCE_GEN_TASK_NAME" value="generateDebugSources" />
<option name="ALLOW_USER_CONFIGURATION" value="false" />
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/src/release/res" />
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res" />
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
</configuration>
</facet>
</component>
<component name="NewModuleRootManager" inherit-compiler-output="false">
<output url="file://$MODULE_DIR$/build/intermediates/classes/release" />
<output url="file://$MODULE_DIR$/build/intermediates/classes/debug" />
<exclude-output />
<content url="file://$MODULE_DIR$">
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/release" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/release" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/release" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/release/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/release/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/release/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/release/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/r/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/aidl/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/rs/debug" isTestSource="false" generated="true" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/generated/debug" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/jni" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
Expand Down
Expand Up @@ -30,14 +30,10 @@ public class HourlyForecastAdapter extends RecyclerView.Adapter<HourlyForecastAd
private List<Forecast> forecasts;
private static int MAX_PRECIP_GRAPH_HEIGHT = -1;

private final int VIEW_TYPE_HEADER = 0;
private final int VIEW_TYPE_FORECAST = 1;


@Override
public int getItemCount() {
if (forecasts == null) return 0;
else return forecasts.size() + 1;
else return forecasts.size();
}

public HourlyForecastAdapter(Context context, List<Forecast> forecasts) {
Expand All @@ -48,29 +44,20 @@ public HourlyForecastAdapter(Context context, List<Forecast> forecasts) {
MAX_PRECIP_GRAPH_HEIGHT = PxUtil.toPx(context, 31);
}


@Override
public Holder onCreateViewHolder(ViewGroup parent, int viewType) {
final View view = viewType == VIEW_TYPE_HEADER ?
LayoutInflater.from(context).inflate(R.layout.view_hourly_forecast_header, parent, false) :
LayoutInflater.from(context).inflate(R.layout.view_hourly_forecast, parent, false);
final View view =
inflater.inflate(R.layout.view_hourly_forecast, parent, false);

return new Holder(view, viewType);
}

@Override
public int getItemViewType(int position) {
return position == 0 ? VIEW_TYPE_HEADER : VIEW_TYPE_FORECAST;
}


@Override
public void onBindViewHolder(Holder holder, int position) {

if (holder.viewType == VIEW_TYPE_HEADER)
if (position>=forecasts.size())
return;

Forecast forecast = forecasts.get(position - 1);
Forecast forecast = forecasts.get(position);

//TIME
if (!DateFormat.is24HourFormat(context)) {
Expand Down Expand Up @@ -131,10 +118,8 @@ public void onBindViewHolder(Holder holder, int position) {
holder.vector.setImageDrawable(null);
}
}

}


public static class Holder extends RecyclerView.ViewHolder {
private TextView time, precip, windSpeed;
private ImageView vector, precipGraph;
Expand Down
Expand Up @@ -9,6 +9,7 @@
import com.climate.growers.android.managers.pojos.FieldSummary;
import com.climate.growers.android.managers.pojos.Forecast;
import com.climate.growers.android.managers.pojos.LatLong;
import com.climate.growers.android.widgets.WeatherConditionImageView;

import java.util.ArrayList;
import java.util.Collections;
Expand Down Expand Up @@ -126,7 +127,6 @@ public static FieldLazyDetails parseFieldLazyDetails(Map<String, Object> parsed)
List<Map<String, Object>> clus = (List<Map<String, Object>>) parsed.get("clus");
field.setClus(CLUParser.parseCLUs(clus));
}

if (parsed.containsKey("wind")) {
Map<String, Object> w = (Map<String, Object>) parsed.get("wind");
field.setWind(WindParser.parseWind(w));
Expand Down Expand Up @@ -161,7 +161,10 @@ public static DetailedField parseDetailedField(Map<String, Object> parsed) {
}
field.setWorkability(workability);
}

if (parsed.containsKey("temperature")) {
Map<String, Object> t = (Map<String, Object>) parsed.get("temperature");
field.setTemperature(TemperatureParser.parseTemperature(t));
}
if (parsed.containsKey("precipitation")) {
Map<String, Object> p = (Map<String, Object>) parsed.get("precipitation");
if (p.containsKey("last_twenty_four_hours")) {
Expand All @@ -172,7 +175,6 @@ public static DetailedField parseDetailedField(Map<String, Object> parsed) {
Map<String, Object> p72 = (Map<String, Object>) p.get("last_seventy_two_hours");
field.setPrecepLast72(PrecipitationParser.parsePrecipitation(p72));
}

if (p.containsKey("next_twenty_four_hours")) {
Map<String, Object> n24 = (Map<String, Object>) p.get("next_twenty_four_hours");
field.setPrecepNext24(PrecipitationParser.parsePrecipitation(n24));
Expand Down Expand Up @@ -207,6 +209,12 @@ public static DetailedField parseDetailedField(Map<String, Object> parsed) {
Collections.sort(forecasts, new ForecastComparable());
field.setDailyForecast(forecasts);
}
if (parsed.containsKey("wind")) {
Map<String, Object> w = (Map<String, Object>) parsed.get("wind");
field.setWind(WindParser.parseWind(w));
}
if (parsed.containsKey("weather_conditions"))
field.setWeatherCondition((String) parsed.get("weather_conditions"));

if (field != null) {
if (!DateUtils.isToday(field.getDailyForecast().get(0).getDate().getTime())) {
Expand All @@ -220,6 +228,7 @@ public static DetailedField parseDetailedField(Map<String, Object> parsed) {
field.getDailyForecast().add(0, todayForcast);
}
}

long d = System.currentTimeMillis() - then;
Log.d(TAG, "custom parsing time: " + d);
return field;
Expand Down
Expand Up @@ -13,15 +13,17 @@ public class DetailedField extends BaseObject {
private String county;
private String state;
private String crop;
private String weatherCondition;
private int workability;

private Precipitation precepLast24;
private Precipitation precepLast72;
private Precipitation precipNext24;
private String soilMoisture;
private String growthStage;
private ArrayList<Forecast> hourlyForecasts;
private ArrayList<Forecast> dailyForecast;
private Temperature temperature;
private Wind wind;

public long getId() {
return id;
Expand Down Expand Up @@ -145,28 +147,29 @@ public List<Forecast> getHourlyForecastForDay(Calendar startDate) {
}
}
return forecasts.isEmpty() ? null : forecasts;
}

public Temperature getTemperature() {
return temperature;
}

public void setTemperature(Temperature temperature) {
this.temperature = temperature;
}

public void setWind(Wind wind) {
this.wind = wind;
}

public Wind getWind() {
return wind;
}

public String getWeatherCondition() {
return weatherCondition;
}

// startDate = (Calendar)startDate.clone();
// startDate.set(Calendar.HOUR_OF_DAY, 0);
// startDate.set(Calendar.MINUTE, 0);
// startDate.set(Calendar.SECOND, 0);
// startDate.set(Calendar.MILLISECOND, 0);
// Calendar endDate = (Calendar)startDate.clone();
// endDate.set(Calendar.DAY_OF_MONTH, startDate.get(Calendar.DAY_OF_MONTH)+1);
// ArrayList<Forecast> forecasts = new ArrayList<Forecast>();
// Date d1 = startDate.getTime();
// Date d2 = endDate.getTime();
// for (Forecast f : hourlyForecasts) {
// Calendar cal = f.getCalendar();
// Date d3 = cal.getTime();
// int res1 = cal.compareTo(startDate);
// int res2 = cal.compareTo(endDate);
// if (cal.compareTo(startDate) >= 0 &&
// cal.compareTo(endDate) < 0) {
// forecasts.add(f);
// }
// }
// return forecasts.isEmpty() ? null : forecasts;
public void setWeatherCondition(String weatherCondition) {
this.weatherCondition = weatherCondition;
}
}
@@ -1,21 +1,32 @@
package com.climate.growers.android.renderers;

import android.content.Context;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.View;
import android.widget.ImageView;
import android.widget.RelativeLayout;
import android.widget.TableLayout;
import android.widget.TextView;

import com.climate.growers.android.R;
import com.climate.growers.android.managers.pojos.DetailedField;
import com.climate.growers.android.managers.pojos.FieldLazyDetails;
import com.climate.growers.android.managers.pojos.Temperature;
import com.climate.growers.android.utils.PrecipUtil;
import com.climate.growers.android.widgets.WeatherConditionImageView;

public class WeatherModuleCard extends RelativeLayout {

private TextView next24, last24, last72;
private TextView growth, last24Precip, last72Precip, next24Precip;
private TextView windSpeed, temperature;
private boolean isLoading = false;
private DetailedField weatherData;
private View progressBar;
private ImageView windIcon;
private FieldPrecipUncertaintyRenderer fieldPrecipUncertaintyRenderer;
private TableLayout dataTableLayout;
private WeatherConditionImageView weatherConditionIcon;

public WeatherModuleCard(Context context, AttributeSet attrs) {
super(context, attrs);
Expand All @@ -28,10 +39,19 @@ public WeatherModuleCard(Context context, AttributeSet attrs, int defStyle) {
@Override
protected void onFinishInflate() {
super.onFinishInflate();
next24 = (TextView)findViewById(R.id.next24);
last24 = (TextView)findViewById(R.id.last24);
last72 = (TextView)findViewById(R.id.last72);

temperature = (TextView) findViewById(R.id.temperature);
progressBar = findViewById(R.id.progressBar);
windSpeed = (TextView) findViewById(R.id.windSpeed);
windIcon = (ImageView) findViewById(R.id.windIcon);
growth = (TextView) findViewById(R.id.growth);
last24Precip = (TextView) findViewById(R.id.last24);
last72Precip = (TextView) findViewById(R.id.last72);
next24Precip = (TextView) findViewById(R.id.next24);
dataTableLayout = (TableLayout) findViewById(R.id.dataTableLayout);
weatherConditionIcon = (WeatherConditionImageView) findViewById(R.id.weatherConditionIcon);

fieldPrecipUncertaintyRenderer = new FieldPrecipUncertaintyRenderer(this);
}

public void setDetailedField(DetailedField detailedField) {
Expand All @@ -40,17 +60,52 @@ public void setDetailedField(DetailedField detailedField) {
}

private void bindData() {
final Context context = getContext();

if (weatherData == null) {
next24.setText("");
last24.setText("");
last72.setText("");
last24Precip.setText("");
last72Precip.setText("");
next24Precip.setText("");
growth.setText("");
windSpeed.setText("");
temperature.setText("");
} else {
next24.setText(PrecipUtil.getFormattedInches(getContext(),
weatherData.getPrecepLast24()) + "\n NEXT 24");
last24.setText(PrecipUtil.getFormattedInches(getContext(),
weatherData.getPrecepLast72()) + "\n LAST 24");
last72.setText(PrecipUtil.getFormattedPercent(getContext(),
weatherData.getPrecepNext24()) + "\n LAST 72");
temperature.setText(String.format(context.getString(R.string.temperature_format_string), weatherData.getTemperature().getFahrenheit()));

if (TextUtils.isEmpty(weatherData.getGrowthStage())) {
growth.setText(getContext().getString(R.string.not_available_abbrev));
} else {
if (weatherData.getGrowthStage().length() > 3) {
growth.setTextSize(11);
}
growth.setText(weatherData.getGrowthStage());
}

if (weatherData.getWind() != null) {
windSpeed.setText(weatherData.getWind().getMphSpeed() + " mph");
if (weatherData.getWind().getMphSpeedAsFloat() > 30f) {
windIcon.setImageResource(R.drawable.ic_arrow_up_red);
} else {
windIcon.setImageResource(R.drawable.ic_arrow_up);
}
windIcon.setRotation(weatherData.getWind().getDegreesAsFloat());
} else {
windSpeed.setText("");
windIcon.setVisibility(View.INVISIBLE);
}

fieldPrecipUncertaintyRenderer.setData(weatherData.getPrecepLast24().getUncertaintyInchesMap(), true);

last24Precip.setText(PrecipUtil.getFormattedInches(getContext(),
weatherData.getPrecepLast24()));
next24Precip.setText(PrecipUtil.getFormattedPercent(getContext(),
weatherData.getPrecepNext24()));
last72Precip.setText(PrecipUtil.getFormattedInches(getContext(),
weatherData.getPrecepLast72()));

weatherConditionIcon.setWeather(weatherData.getWeatherCondition());

dataTableLayout.setVisibility(VISIBLE);
}
}

Expand All @@ -61,5 +116,4 @@ public void updateLoadingStatus(boolean showLoading) {
progressBar.setVisibility(View.GONE);
}
}

}

0 comments on commit a0d1016

Please sign in to comment.