Skip to content

Commit

Permalink
2.231
Browse files Browse the repository at this point in the history
  • Loading branch information
WangDaYeeeeee committed Jan 18, 2019
1 parent 79d391d commit e1ba535
Show file tree
Hide file tree
Showing 9 changed files with 82 additions and 42 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ android {
applicationId "wangdaye.com.geometricweather"
minSdkVersion 19
targetSdkVersion 28
versionCode 2221
versionName "2.221"
versionCode 2231
versionName "2.231"
}
buildTypes {
release {
Expand Down
2 changes: 1 addition & 1 deletion app/release/output.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2221,"versionName":"2.221","enabled":true,"outputFile":"GeometricWeather 2.221.apk","fullName":"release","baseName":"release"},"path":"GeometricWeather 2.221.apk","properties":{}}]
[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":2231,"versionName":"2.231","enabled":true,"outputFile":"GeometricWeather 2.231.apk","fullName":"release","baseName":"release"},"path":"GeometricWeather 2.231.apk","properties":{}}]
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import java.util.List;

import okhttp3.OkHttpClient;
import okhttp3.logging.HttpLoggingInterceptor;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
Expand Down Expand Up @@ -58,7 +59,7 @@ public class AccuWeatherService extends WeatherService {
public AccuWeatherService() {
OkHttpClient client = getClientBuilder()
.addInterceptor(new GzipInterceptor())
// .addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.addInterceptor(new HttpLoggingInterceptor().setLevel(HttpLoggingInterceptor.Level.BODY))
.build();
client.dispatcher().setMaxRequestsPerHost(1);

Expand Down Expand Up @@ -322,18 +323,17 @@ public void onResponse(Call<AccuMinuteResult> call, Response<AccuMinuteResult> r
if (response.isSuccessful() && response.body() != null) {
if (!isFailed(location)) {
weather.index.buildIndex(response.body());
loadSucceed(location, callback);

}
} else {
loadFailed(location, callback);
}
loadSucceed(location, callback);
}
}

@Override
public void onFailure(Call<AccuMinuteResult> call, Throwable t) {
if (callback != null) {
loadFailed(location, callback);
loadSucceed(location, callback);
}
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public class CMWeatherProviderService extends WeatherProviderService

private LocationHelper.OnRequestLocationListener locationListener
= new LocationHelper.OnRequestLocationListener() {

@Override
public void requestLocationSuccess(Location requestLocation) {
if (request != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.design.widget.CoordinatorLayout;
import android.support.v4.content.ContextCompat;
import android.support.v7.widget.AppCompatImageView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import wangdaye.com.geometricweather.GeometricWeather;
Expand All @@ -23,7 +21,6 @@
import wangdaye.com.geometricweather.ui.widget.MoonPhaseView;
import wangdaye.com.geometricweather.utils.LanguageUtils;
import wangdaye.com.geometricweather.utils.helpter.LunarHelper;
import wangdaye.com.geometricweather.utils.manager.TimeManager;
import wangdaye.com.geometricweather.utils.ValueUtils;
import wangdaye.com.geometricweather.utils.helpter.WeatherHelper;

Expand Down Expand Up @@ -173,10 +170,14 @@ private void initWidget(View view) {
view.findViewById(R.id.dialog_weather_moonrise_moonset)};
if (daily) {
sunMoonText[0].setText(
weather.dailyList.get(position).astros[0] + " / " + weather.dailyList.get(position).astros[1]);
weather.dailyList.get(position).astros[0] + "↑"
+ " / "
+ weather.dailyList.get(position).astros[1] + "↓");
if (!TextUtils.isEmpty(weather.dailyList.get(position).astros[2])) {
sunMoonText[1].setText(
weather.dailyList.get(position).astros[2] + " / " + weather.dailyList.get(position).astros[3]);
weather.dailyList.get(position).astros[2] + "↑"
+ " / "
+ weather.dailyList.get(position).astros[3] + "↓");
} else {
view.findViewById(R.id.dialog_weather_moonContainer).setVisibility(View.GONE);
}
Expand All @@ -187,16 +188,6 @@ private void initWidget(View view) {
sunMoonText[1].setVisibility(View.GONE);
}

Button done = view.findViewById(R.id.dialog_weather_button);
boolean dayTime = daily
? TimeManager.getInstance(getActivity()).isDayTime() : weather.hourlyList.get(position).dayTime;
if (dayTime) {
done.setTextColor(ContextCompat.getColor(getActivity(), R.color.lightPrimary_3));
} else {
done.setTextColor(ContextCompat.getColor(getActivity(), R.color.darkPrimary_1));
}
done.setOnClickListener(this);

if (daily) {
int[] daytimeAnimatorIds = WeatherHelper.getAnimatorId(
weather.dailyList.get(position).weatherKinds[0], true);
Expand Down Expand Up @@ -245,10 +236,6 @@ public void setData(Weather weather, int position, boolean daily) {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.dialog_weather_button:
dismiss();
break;

case R.id.dialog_weather_weatherContainer_day:
for (AnimatorSet a : iconAnimatorSets[0]) {
if (a != null) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package wangdaye.com.geometricweather.utils.helpter;

import android.content.Context;
import android.content.SharedPreferences;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.support.annotation.NonNull;
Expand Down Expand Up @@ -31,6 +32,12 @@ public class LocationHelper {
private LocationService locationService;
private WeatherService weatherService;

private static final String PREFERENCE_LOCAL = "LOCAL_PREFERENCE";
private static final String KEY_OLD_DISTRICT = "OLD_DISTRICT";
private static final String KEY_OLD_CITY = "OLD_CITY";
private static final String KEY_OLD_PROVINCE = "OLD_PROVINCE";
private static final String KEY_OLD_KEY = "OLD_KEY";

private class RequestLocationListener implements LocationService.LocationCallback {
// data
private Context c;
Expand Down Expand Up @@ -74,18 +81,26 @@ public void onCompleted(@Nullable LocationService.Result result) {
}

private class AccuLocationCallback implements WeatherService.RequestLocationCallback {

// data
private Context context;
private Location location;
private OnRequestLocationListener listener;

AccuLocationCallback(Location location, @NonNull OnRequestLocationListener l) {
AccuLocationCallback(Context c, Location location, @NonNull OnRequestLocationListener l) {
this.context = c;
this.location = location;
this.listener = l;
}

@Override
public void requestLocationSuccess(String query, List<Location> locationList) {
if (locationList.size() > 0) {
if (!TextUtils.isEmpty(locationList.get(0).cityId)) {
context.getSharedPreferences(PREFERENCE_LOCAL, Context.MODE_PRIVATE)
.edit()
.putString(KEY_OLD_KEY, locationList.get(0).cityId)
.apply();
}
listener.requestLocationSuccess(locationList.get(0).setLocal());
} else {
requestLocationFailed(query);
Expand All @@ -94,6 +109,13 @@ public void requestLocationSuccess(String query, List<Location> locationList) {

@Override
public void requestLocationFailed(String query) {
context.getSharedPreferences(PREFERENCE_LOCAL, Context.MODE_PRIVATE)
.edit()
.putString(KEY_OLD_DISTRICT, "")
.putString(KEY_OLD_CITY, "")
.putString(KEY_OLD_PROVINCE, "")
.putString(KEY_OLD_KEY, "")
.apply();
listener.requestLocationFailed(location);
}
}
Expand Down Expand Up @@ -163,19 +185,41 @@ public void requestLocation(Context c, Location location, @NonNull OnRequestLoca
private void requestAvailableWeatherLocation(Context c,
Location location,
@NonNull OnRequestLocationListener l) {
SharedPreferences sharedPreferences = c.getSharedPreferences(
PREFERENCE_LOCAL, Context.MODE_PRIVATE);
if (!location.canUseChineseSource()
|| GeometricWeather.getInstance().getChineseSource().equals("accu")) {
// use accu as weather service api.
location.source = "accu";

String oldDistrict = sharedPreferences.getString(KEY_OLD_DISTRICT, "");
String oldCity = sharedPreferences.getString(KEY_OLD_CITY, "");
String oldProvince = sharedPreferences.getString(KEY_OLD_PROVINCE, "");
String oldKey = sharedPreferences.getString(KEY_OLD_KEY, "");

if (queryEqualsIgnoreEmpty(location.district, oldDistrict)
&& queryEquals(location.city, oldCity)
&& queryEquals(location.province, oldProvince)
&& queryEquals(location.cityId, oldKey)) {
l.requestLocationSuccess(location);
return;
}

sharedPreferences.edit()
.putString(KEY_OLD_DISTRICT, location.district)
.putString(KEY_OLD_CITY, location.city)
.putString(KEY_OLD_PROVINCE, location.province)
.apply();

weatherService = new AccuWeatherService();
if (GeometricWeather.getInstance().getLocationService().equals("baidu_ip")) {
weatherService.requestLocation(
c,
TextUtils.isEmpty(location.district) ? location.city : location.district,
new AccuLocationCallback(location, l));
new AccuLocationCallback(c, location, l));
} else {
weatherService.requestLocation(
c, location.lat, location.lon, new AccuLocationCallback(location, l));
c, location.lat, location.lon, new AccuLocationCallback(c, location, l));
}
} else if (GeometricWeather.getInstance().getChineseSource().equals("cn")) {
// use cn weather net as the weather service api.
Expand Down Expand Up @@ -205,6 +249,23 @@ public void cancel() {
}
}

private boolean queryEquals(String a, String b) {
if (!TextUtils.isEmpty(a) && !TextUtils.isEmpty(b)) {
return a.equals(b);
}
return false;
}

private boolean queryEqualsIgnoreEmpty(String a, String b) {
if (TextUtils.isEmpty(a) && TextUtils.isEmpty(b)) {
return true;
}
if (!TextUtils.isEmpty(a) && !TextUtils.isEmpty(b)) {
return a.equals(b);
}
return false;
}

// interface.

public interface OnRequestLocationListener {
Expand Down
11 changes: 1 addition & 10 deletions app/src/main/res/layout/dialog_weather.xml
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="@id/dialog_weather_sunContainer"
android:layout_alignParentEnd="true"
android:layout_margin="@dimen/normal_margin"
tools:ignore="RtlHardcoded">

Expand All @@ -220,15 +220,6 @@

</RelativeLayout>

<Button
android:id="@+id/dialog_weather_button"
android:text="@string/done"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:textColor="@color/colorAccent"
style="@style/material_button"
tools:ignore="RtlHardcoded" />

</RelativeLayout>

</LinearLayout>
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<string name="app_name">Weather</string>
<string name="geometric_weather">Geometric Weather</string>
<string name="package_name">wangdaye.com.geometricweather</string>
<string name="version_code">v2.221</string>
<string name="version_code">v2.231</string>

<!-- keyword. -->
<string name="local">local</string>
Expand Down
Binary file not shown.

0 comments on commit e1ba535

Please sign in to comment.