Skip to content

Commit

Permalink
bug fixed.
Browse files Browse the repository at this point in the history
  • Loading branch information
WangDaYeeeeee committed Apr 9, 2021
1 parent b8a1c6d commit 441a264
Show file tree
Hide file tree
Showing 54 changed files with 594,316 additions and 198 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "wangdaye.com.geometricweather"
minSdkVersion 19
targetSdkVersion 30
versionCode 30006
versionName "3.006"
versionCode 30007
versionName "3.007"
multiDexEnabled true
ndk {
abiFilters 'armeabi', 'x86', 'armeabi-v7a', 'x86_64', 'arm64-v8a'
Expand Down
3 changes: 1 addition & 2 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,9 @@
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />

<!-- query internet status. -->
<!-- query internet state. -->
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE" />
<uses-permission android:name="android.permission.CHANGE_WIFI_STATE" />
<uses-permission android:name="android.permission.INTERNET" />

<!-- widgets. -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@ private void possiblyResizeChildOfContent() {
int usableHeightNow = computeUsableHeight();
if (usableHeightNow != mUsableHeightPrevious) {
int contentViewHeight = mContentChild.getRootView().getHeight();
if (contentViewHeight - usableHeightNow > contentViewHeight / 5) {
if (DisplayUtils.isKeyboardExpanded(contentViewHeight,
contentViewHeight - usableHeightNow)) {
// keyboard probably just became visible.
mContentChildParams.height = usableHeightNow;
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

public enum WeatherSource {


ACCU("accu", 0xffef5823, "accuweather.com"),
OWM("owm", 0xffeb6e4b, "openweathermap.org"),
MF("mf", 0xff005892, "meteofrance.com"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,14 @@ public SnackbarLayout(Context context, AttributeSet attrs) {
});
}

@Override
protected boolean fitSystemWindows(Rect insets) {
mWindowInsets.set(insets.left, insets.top, insets.right, insets.bottom);
Utils.fitKeyboardExpand(this, mWindowInsets);
requestLayout();
return false;
}

public @LayoutRes int getLayoutId() {
return R.layout.container_snackbar_layout_inner;
}
Expand All @@ -477,13 +485,6 @@ Button getActionView() {
return mActionView;
}

@Override
protected boolean fitSystemWindows(Rect insets) {
mWindowInsets.set(insets.left, insets.top, insets.right, insets.bottom);
requestLayout();
return false;
}

@Override
protected LayoutParams generateLayoutParams(LayoutParams p) {
return new MarginLayoutParams(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import android.animation.Animator;
import android.animation.AnimatorSet;
import android.content.Context;
import android.graphics.Rect;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.Interpolator;

import androidx.interpolator.view.animation.FastOutSlowInInterpolator;
Expand All @@ -27,4 +31,15 @@ static Animator getEnterAnimator(View view, boolean cardStyle) {
set.playTogether(animators[0], animators[1], animators[2]);
return set;
}

static void fitKeyboardExpand(View view, Rect insets) {
DisplayMetrics metrics = new DisplayMetrics();
WindowManager wm = (WindowManager) view.getContext().getSystemService(
Context.WINDOW_SERVICE);
wm.getDefaultDisplay().getRealMetrics(metrics);

if (DisplayUtils.isKeyboardExpanded(metrics.heightPixels, insets.bottom)) {
insets.bottom = 0;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,8 @@
import android.media.ThumbnailUtils;
import android.os.Build;
import android.text.format.DateFormat;
import android.util.DisplayMetrics;
import android.view.View;
import android.view.Window;
import android.view.WindowInsets;
import android.view.WindowManager;
import android.view.animation.DecelerateInterpolator;
import android.view.animation.Interpolator;
import android.view.animation.OvershootInterpolator;
Expand Down Expand Up @@ -284,6 +281,10 @@ public static Animator[] getFloatingOvershotEnterAnimators(View view,
return new Animator[] {translation, scaleX, scaleY};
}

public static boolean isKeyboardExpanded(int screenHeight, int bottomInset) {
return screenHeight - bottomInset > screenHeight / 5;
}

public static void getVisibleDisplayFrame(View view, Rect rect) {
/*
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
Expand All @@ -304,6 +305,7 @@ public static void getVisibleDisplayFrame(View view, Rect rect) {
view.getWindowVisibleDisplayFrame(rect);
}
*/
// looks like has a good performance.
view.getWindowVisibleDisplayFrame(rect);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package wangdaye.com.geometricweather.main.utils;

import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.Color;

import androidx.annotation.ColorInt;
Expand All @@ -21,6 +20,7 @@
import wangdaye.com.geometricweather.common.utils.DisplayUtils;
import wangdaye.com.geometricweather.common.theme.ThemeManager;
import wangdaye.com.geometricweather.resource.utils.ResourceUtils;
import wangdaye.com.geometricweather.settings.ConfigStore;
import wangdaye.com.geometricweather.settings.SettingsOptionManager;

public class MainThemeManager extends ThemeManager {
Expand All @@ -35,8 +35,8 @@ public class MainThemeManager extends ThemeManager {
@Inject
public MainThemeManager(@ActivityContext Context context) {
mWeatherView = null;
mDaytime = context.getSharedPreferences(PREFERENCE_NAME, Context.MODE_PRIVATE)
.getBoolean(KEY_DAY_TIME, DisplayUtils.isDaylight(TimeZone.getDefault()));
mDaytime = ConfigStore.getInstance(context, PREFERENCE_NAME).getBoolean(
KEY_DAY_TIME, DisplayUtils.isDaylight(TimeZone.getDefault()));
update(context, null);
}

Expand Down Expand Up @@ -71,11 +71,10 @@ private synchronized void updateDaytime(Context context, @Nullable Location loca

mDaytime = location.isDaylight();

SharedPreferences.Editor editor = context.getSharedPreferences(
PREFERENCE_NAME, Context.MODE_PRIVATE
).edit();
editor.putBoolean(KEY_DAY_TIME, mDaytime);
editor.apply();
ConfigStore.getInstance(context, PREFERENCE_NAME)
.edit()
.putBoolean(KEY_DAY_TIME, mDaytime)
.apply();
}

public synchronized void registerWeatherView(WeatherView weatherView) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package wangdaye.com.geometricweather.main.utils;

import android.content.Context;
import android.content.SharedPreferences;

import javax.inject.Inject;

import dagger.hilt.android.qualifiers.ActivityContext;
import wangdaye.com.geometricweather.settings.ConfigStore;

public class StatementManager {

Expand All @@ -18,13 +18,12 @@ public class StatementManager {

@Inject
public StatementManager(@ActivityContext Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
SP_STATEMENT_RECORD, Context.MODE_PRIVATE);
ConfigStore config = ConfigStore.getInstance(context, SP_STATEMENT_RECORD);

locationPermissionDeclared = sharedPreferences.getBoolean(
locationPermissionDeclared = config.getBoolean(
KEY_LOCATION_PERMISSION_DECLARED, false);

backgroundLocationDeclared = sharedPreferences.getBoolean(
backgroundLocationDeclared = config.getBoolean(
KEY_BACKGROUND_LOCATION_DECLARED, false);
}

Expand All @@ -35,8 +34,9 @@ public boolean isLocationPermissionDeclared() {
public void setLocationPermissionDeclared(Context context) {
locationPermissionDeclared = true;

context.getSharedPreferences(SP_STATEMENT_RECORD, Context.MODE_PRIVATE)
.edit().putBoolean(KEY_LOCATION_PERMISSION_DECLARED, true)
ConfigStore.getInstance(context, SP_STATEMENT_RECORD)
.edit()
.putBoolean(KEY_LOCATION_PERMISSION_DECLARED, true)
.apply();
}

Expand All @@ -47,8 +47,9 @@ public boolean isBackgroundLocationDeclared() {
public void setBackgroundLocationDeclared(Context context) {
backgroundLocationDeclared = true;

context.getSharedPreferences(SP_STATEMENT_RECORD, Context.MODE_PRIVATE)
.edit().putBoolean(KEY_BACKGROUND_LOCATION_DECLARED, true)
ConfigStore.getInstance(context, SP_STATEMENT_RECORD)
.edit()
.putBoolean(KEY_BACKGROUND_LOCATION_DECLARED, true)
.apply();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.app.NotificationManager;
import android.app.PendingIntent;
import android.content.Context;
import android.content.SharedPreferences;
import android.graphics.BitmapFactory;
import android.os.Build;

Expand All @@ -30,6 +29,7 @@
import wangdaye.com.geometricweather.common.basic.models.weather.Weather;
import wangdaye.com.geometricweather.common.utils.helpers.IntentHelper;
import wangdaye.com.geometricweather.remoteviews.presenters.notification.NormalNotificationIMP;
import wangdaye.com.geometricweather.settings.ConfigStore;
import wangdaye.com.geometricweather.settings.SettingsOptionManager;

/**
Expand Down Expand Up @@ -199,18 +199,17 @@ private static Notification buildAlertGroupSummaryNotification(Context context,
}

private static int getAlertNotificationId(Context context) {
SharedPreferences sharedPreferences = context.getSharedPreferences(
PREFERENCE_NOTIFICATION, Context.MODE_PRIVATE);
ConfigStore config = ConfigStore.getInstance(context, PREFERENCE_NOTIFICATION);

int id = sharedPreferences.getInt(
int id = config.getInt(
KEY_NOTIFICATION_ID, GeometricWeather.NOTIFICATION_ID_ALERT_MIN) + 1;
if (id > GeometricWeather.NOTIFICATION_ID_ALERT_MAX) {
id = GeometricWeather.NOTIFICATION_ID_ALERT_MIN;
}

SharedPreferences.Editor editor = sharedPreferences.edit();
editor.putInt(KEY_NOTIFICATION_ID, id);
editor.apply();
config.edit()
.putInt(KEY_NOTIFICATION_ID, id)
.apply();

return id;
}
Expand All @@ -233,10 +232,10 @@ public static void checkAndSendPrecipitationForecast(Context context,

Weather weather = location.getWeather();

SharedPreferences sharedPreferences = context.getSharedPreferences(
PREFERENCE_SHORT_TERM_PRECIPITATION_ALERT, Context.MODE_PRIVATE);
String locationKey = sharedPreferences.getString(KEY_PRECIPITATION_LOCATION_KEY, null);
long date = sharedPreferences.getLong(KEY_PRECIPITATION_DATE, 0);
ConfigStore config = ConfigStore.getInstance(
context, PREFERENCE_SHORT_TERM_PRECIPITATION_ALERT);
String locationKey = config.getString(KEY_PRECIPITATION_LOCATION_KEY, null);
long date = config.getLong(KEY_PRECIPITATION_DATE, 0);

if ((!location.getFormattedId().equals(locationKey)
|| isDifferentDays(date, weather.getBase().getPublishTime()))
Expand All @@ -260,7 +259,7 @@ && isShortTermLiquid(weather)) {
)
).build()
);
sharedPreferences.edit()
config.edit()
.putString(KEY_PRECIPITATION_LOCATION_KEY, location.getFormattedId())
.putLong(KEY_PRECIPITATION_DATE, weather.getBase().getPublishTime())
.apply();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import android.appwidget.AppWidgetManager;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
Expand Down Expand Up @@ -52,6 +51,7 @@
import wangdaye.com.geometricweather.common.utils.DisplayUtils;
import wangdaye.com.geometricweather.common.utils.helpers.SnackbarHelper;
import wangdaye.com.geometricweather.db.DatabaseHelper;
import wangdaye.com.geometricweather.settings.ConfigStore;
import wangdaye.com.geometricweather.settings.SettingsOptionManager;
import wangdaye.com.geometricweather.weather.WeatherHelper;

Expand Down Expand Up @@ -247,17 +247,17 @@ public void initData() {
}

private void readConfig() {
SharedPreferences sharedPreferences = getSharedPreferences(getSharedPreferencesName(), MODE_PRIVATE);
viewTypeValueNow = sharedPreferences.getString(getString(R.string.key_view_type), viewTypeValueNow);
cardStyleValueNow = sharedPreferences.getString(getString(R.string.key_card_style), cardStyleValueNow);
cardAlpha = sharedPreferences.getInt(getString(R.string.key_card_alpha), cardAlpha);
hideSubtitle = sharedPreferences.getBoolean(getString(R.string.key_hide_subtitle), hideSubtitle);
subtitleDataValueNow = sharedPreferences.getString(getString(R.string.key_subtitle_data), subtitleDataValueNow);
textColorValueNow = sharedPreferences.getString(getString(R.string.key_text_color), textColorValueNow);
textSize = sharedPreferences.getInt(getString(R.string.key_text_size), textSize);
clockFontValueNow = sharedPreferences.getString(getString(R.string.key_clock_font), clockFontValueNow);
hideLunar = sharedPreferences.getBoolean(getString(R.string.key_hide_lunar), hideLunar);
alignEnd = sharedPreferences.getBoolean(getString(R.string.key_align_end), alignEnd);
ConfigStore config = ConfigStore.getInstance(this, getConfigStoreName());
viewTypeValueNow = config.getString(getString(R.string.key_view_type), viewTypeValueNow);
cardStyleValueNow = config.getString(getString(R.string.key_card_style), cardStyleValueNow);
cardAlpha = config.getInt(getString(R.string.key_card_alpha), cardAlpha);
hideSubtitle = config.getBoolean(getString(R.string.key_hide_subtitle), hideSubtitle);
subtitleDataValueNow = config.getString(getString(R.string.key_subtitle_data), subtitleDataValueNow);
textColorValueNow = config.getString(getString(R.string.key_text_color), textColorValueNow);
textSize = config.getInt(getString(R.string.key_text_size), textSize);
clockFontValueNow = config.getString(getString(R.string.key_clock_font), clockFontValueNow);
hideLunar = config.getBoolean(getString(R.string.key_hide_lunar), hideLunar);
alignEnd = config.getBoolean(getString(R.string.key_align_end), alignEnd);
}

@SuppressLint("UseSwitchCompatOrMaterialCode")
Expand Down Expand Up @@ -380,7 +380,7 @@ public void initView() {

Button doneButton = findViewById(R.id.activity_widget_config_doneButton);
doneButton.setOnClickListener(v -> {
getSharedPreferences(getSharedPreferencesName(), MODE_PRIVATE)
getSharedPreferences(getConfigStoreName(), MODE_PRIVATE)
.edit()
.putString(getString(R.string.key_view_type), viewTypeValueNow)
.putString(getString(R.string.key_card_style), cardStyleValueNow)
Expand Down Expand Up @@ -491,7 +491,7 @@ public Location getLocationNow() {
return locationNow;
}

public abstract String getSharedPreferencesName();
public abstract String getConfigStoreName();

private int indexValue(String[] values, String current) {
for (int i = 0; i < values.length; i ++) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public RemoteViews getRemoteViews() {
}

@Override
public String getSharedPreferencesName() {
public String getConfigStoreName() {
return getString(R.string.sp_widget_clock_day_details_setting);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public RemoteViews getRemoteViews() {
}

@Override
public String getSharedPreferencesName() {
public String getConfigStoreName() {
return getString(R.string.sp_widget_clock_day_horizontal_setting);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ this, getLocationNow(),
}

@Override
public String getSharedPreferencesName() {
public String getConfigStoreName() {
return getString(R.string.sp_widget_clock_day_vertical_setting);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public RemoteViews getRemoteViews() {
}

@Override
public String getSharedPreferencesName() {
public String getConfigStoreName() {
return getString(R.string.sp_widget_clock_day_week_setting);
}
}
Loading

0 comments on commit 441a264

Please sign in to comment.