Skip to content

Commit

Permalink
Merge pull request #4 from heweather/feature-niu
Browse files Browse the repository at this point in the history
Feature niu
  • Loading branch information
QWRDA committed Apr 18, 2019
2 parents 941d60b + 28a6882 commit ed83d8e
Show file tree
Hide file tree
Showing 13 changed files with 176 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,29 +6,20 @@

import com.heweather.owp.presenters.WeatherInterface;
import com.heweather.owp.presenters.WeatherPresenters;
import com.heweather.owp.utils.AppNetConfig;
import com.heweather.owp.utils.ContentUtil;
import com.heweather.owp.utils.SpUtils;
import com.zhy.http.okhttp.callback.StringCallback;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;
import java.util.List;

import interfaces.heweather.com.interfacesmodule.bean.Lang;
import interfaces.heweather.com.interfacesmodule.bean.Unit;
import interfaces.heweather.com.interfacesmodule.bean.air.forecast.AirForecast;
import interfaces.heweather.com.interfacesmodule.bean.air.now.AirNow;
import interfaces.heweather.com.interfacesmodule.bean.alarm.Alarm;
import interfaces.heweather.com.interfacesmodule.bean.search.Search;
import interfaces.heweather.com.interfacesmodule.bean.weather.Weather;
import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.Forecast;
import interfaces.heweather.com.interfacesmodule.bean.weather.hourly.Hourly;
import interfaces.heweather.com.interfacesmodule.bean.weather.now.Now;
import interfaces.heweather.com.interfacesmodule.view.HeWeather;
import okhttp3.Call;

/**
* Created by niuchong on 2018/5/17.
Expand Down Expand Up @@ -100,8 +91,7 @@ public void getAlarm(String location) {
@Override
public void onError(Throwable throwable) {
weatherInterface.getAlarm(null);
SpUtils.saveBean(context, "alarm", null);
Log.i("sky", "getAlarm onError: ");
Log.i("sky", "getAlarm onError: " + throwable);
}

@Override
Expand Down Expand Up @@ -140,7 +130,7 @@ public void onError(Throwable throwable) {
@Override
public void onSuccess(Search search) {
String parentCity = search.getBasic().get(0).getParent_city();
if (TextUtils.isEmpty(parentCity)){
if (TextUtils.isEmpty(parentCity)) {
parentCity = search.getBasic().get(0).getAdmin_area();
}
HeWeather.getAirNow(context, parentCity, lang, unit, new HeWeather.OnResultAirNowBeansListener() {
Expand All @@ -161,21 +151,21 @@ public void onSuccess(List<AirNow> list) {

@Override
public void getAirForecast(String location) {
HeWeather.getAirForecast(context, location, lang, unit, new HeWeather.OnResultAirForecastBeansListener() {
@Override
public void onError(Throwable throwable) {
Log.i(TAG, "getAirForecast onError: ");
AirForecast airForecast = SpUtils.getBean(context, "airForecast", AirForecast.class);
weatherInterface.getAirForecast(airForecast);
}

@Override
public void onSuccess(List<AirForecast> list) {
weatherInterface.getAirForecast(list.get(0));
SpUtils.saveBean(context, "airForecast", list.get(0));

}
});
// HeWeather.getAirForecast(context, location, lang, unit, new HeWeather.OnResultAirForecastBeansListener() {
// @Override
// public void onError(Throwable throwable) {
// Log.i(TAG, "getAirForecast onError: ");
// AirForecast airForecast = SpUtils.getBean(context, "airForecast", AirForecast.class);
// weatherInterface.getAirForecast(airForecast);
// }
//
// @Override
// public void onSuccess(List<AirForecast> list) {
// weatherInterface.getAirForecast(list.get(0));
// SpUtils.saveBean(context, "airForecast", list.get(0));
//
// }
// });
}


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/com/heweather/owp/utils/ContentUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class ContentUtil {
//用户id
public static final String APK_USERNAME = "和风天气获取的ID";
//用户key
public static final String APK_KEY = "和风天气获取的key";
public static final String APK_KEY = "和风天气获取的KEY";
//当前所在位置
public static Double NOW_LON = 116.40;
public static Double NOW_LAT = 39.9;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.heweather.owp.view.activity;

import android.content.Context;
import android.content.pm.PackageManager;
import android.os.Bundle;
import android.view.View;
import android.widget.TextView;

import com.heweather.owp.R;

Expand All @@ -17,5 +20,26 @@ public void onClick(View view) {
onBackPressed();
}
});

TextView tvVersion = findViewById(R.id.tv_version_num);
tvVersion.setText(getVersionName(this));
}

/**
* 获取versionName
*
* @param context 上下文
* @return 版本号
*/
private static String getVersionName(Context context) {
String versionName = "";
try {
versionName = context.getPackageManager().
getPackageInfo(context.getPackageName(), 0).versionName;
} catch (PackageManager.NameNotFoundException e) {
e.printStackTrace();
}
return "v" + versionName;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.heweather.owp.view.fragment;

import android.annotation.SuppressLint;
import android.content.Intent;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.support.annotation.NonNull;
Expand All @@ -18,9 +20,9 @@
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.heweather.owp.dataInterface.DataUtil;
import com.heweather.owp.MyApplication;
import com.heweather.owp.R;
import com.heweather.owp.dataInterface.DataUtil;
import com.heweather.owp.presenters.WeatherInterface;
import com.heweather.owp.presenters.impl.WeatherImpl;
import com.heweather.owp.utils.ContentUtil;
Expand All @@ -42,6 +44,7 @@
import interfaces.heweather.com.interfacesmodule.bean.air.now.AirNow;
import interfaces.heweather.com.interfacesmodule.bean.air.now.AirNowCity;
import interfaces.heweather.com.interfacesmodule.bean.alarm.Alarm;
import interfaces.heweather.com.interfacesmodule.bean.alarm.AlarmBase;
import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.Forecast;
import interfaces.heweather.com.interfacesmodule.bean.weather.forecast.ForecastBase;
import interfaces.heweather.com.interfacesmodule.bean.weather.hourly.Hourly;
Expand Down Expand Up @@ -117,6 +120,7 @@ public class WeatherFragment extends Fragment implements WeatherInterface {
private GridLayout gridAir;
private SwipeRefreshLayout swipeRefreshLayout;
private TextView tvWeek1;
private TextView tvAlarm;

public static WeatherFragment newInstance(String cityId) {
WeatherFragment fragment = new WeatherFragment();
Expand Down Expand Up @@ -298,6 +302,16 @@ private void initView(View view) {
textViewList.add(tvLineMin);
tvLineMax = view.findViewById(R.id.tv_line_max_tmp);
textViewList.add(tvLineMax);
tvAlarm = view.findViewById(R.id.tv_today_alarm);
textViewList.add(tvAlarm);

TextView tvFrom = view.findViewById(R.id.tv_from);
tvFrom.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
startUri();
}
});

tvSunTitle = view.findViewById(R.id.tv_sun_title);
textViewList.add(tvSunTitle);
Expand Down Expand Up @@ -550,9 +564,51 @@ public void getWeatherForecast(Forecast bean) {
}
}

@SuppressLint("SetTextI18n")
@Override
public void getAlarm(Alarm bean) {

if (bean != null && bean.getAlarm().size() > 0 && bean.getAlarm().get(0) != null) {
tvAlarm.setVisibility(View.VISIBLE);
AlarmBase alarmBase = bean.getAlarm().get(0);
String level = alarmBase.getLevel();
String type = alarmBase.getType();
if (ContentUtil.SYS_LANG.equals("en")) {
tvAlarm.setText(type);
} else {
tvAlarm.setText(type + "预警");
}
if (!TextUtils.isEmpty(level)) {
switch (level) {
case "蓝色":
case "Blue":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_blue_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "黄色":
case "Yellow":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_yellow_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "橙色":
case "Orange":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_orange_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "红色":
case "Red":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_red_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.white));
break;
case "白色":
case "White":
tvAlarm.setBackground(getResources().getDrawable(R.drawable.shape_white_alarm));
tvAlarm.setTextColor(getResources().getColor(R.color.black));
break;
}
}
} else {
tvAlarm.setVisibility(View.GONE);
}
}

@Override
Expand Down Expand Up @@ -826,4 +882,10 @@ public void setUserVisibleHint(boolean isVisibleToUser) {
hasAni = true;
}
}

private void startUri() {
Uri uri = Uri.parse("https://www.heweather.com");
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
startActivity(intent);
}
}
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_blue_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/blue_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_orange_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/orange_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_red_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/red_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_white_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/white" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
9 changes: 9 additions & 0 deletions app/src/main/res/drawable/shape_yellow_alarm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>

<shape xmlns:android="http:https://schemas.android.com/apk/res/android">
<solid android:color="@color/yellow_alarm" />
<corners android:topLeftRadius="10dp"
android:topRightRadius="10dp"
android:bottomRightRadius="10dp"
android:bottomLeftRadius="10dp"/>
</shape>
18 changes: 17 additions & 1 deletion app/src/main/res/layout/fragment_weather.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http:https://schemas.android.com/tools"
android:id="@+id/swipe_layout"
android:layout_width="match_parent"
android:background="@color/back_white"
android:layout_height="match_parent"
android:background="@color/back_white"
tools:context=".view.fragment.WeatherFragment">

<android.support.v4.widget.NestedScrollView
Expand Down Expand Up @@ -66,6 +66,22 @@
android:textColor="@color/white80"
android:textSize="16sp" />

<TextView
android:id="@+id/tv_today_alarm"
android:layout_width="wrap_content"
android:layout_height="20dp"
android:layout_below="@+id/tv_today_cond"
android:layout_centerHorizontal="true"
android:layout_marginTop="16dp"
android:background="@drawable/shape_blue_alarm"
android:gravity="center"
android:paddingLeft="14dp"
android:paddingRight="14dp"
android:text="暴雨预警"
android:textColor="@color/white80"
android:textSize="12sp"
android:visibility="gone" />

</RelativeLayout>

<LinearLayout
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/layout_today_detail.xml
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,7 @@
</LinearLayout>

<TextView
android:id="@+id/tv_from"
android:layout_width="match_parent"
android:layout_height="20dp"
android:background="@color/back_white"
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/res/values-en/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,6 @@
<string name="Cape_Town">Cape Town</string>
<string name="Bangkok">Bangkok</string>
<string name="Madrid">Madrid</string>
<string name="powered">Powered By heweather.com</string>

</resources>
5 changes: 5 additions & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@
<color name="aqi_color_light">#B9C0CA</color>
<color name="color_8E8E93">#8E8E93</color>

<color name="red_alarm">#c01b09</color>
<color name="blue_alarm">#318bf8</color>
<color name="yellow_alarm">#d1ca13</color>
<color name="orange_alarm">#d76801</color>

<color name="dark_line">#1D2834</color>
<color name="set_line">#2E3A48</color>
<color name="light_line">#EDEEF0</color>
Expand Down

0 comments on commit ed83d8e

Please sign in to comment.