Skip to content

Commit

Permalink
Revert "Merge branch 'master' into master"
Browse files Browse the repository at this point in the history
This reverts commit 3e419bd, reversing
changes made to b56d558.
  • Loading branch information
robinpaulson committed Dec 11, 2021
1 parent affd74e commit 4eb0565
Show file tree
Hide file tree
Showing 22 changed files with 102 additions and 558 deletions.
6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,10 @@ android {
defaultConfig {
applicationId "cz.martykan.forecastie"
minSdkVersion 15
//noinspection ExpiringTargetSdkVersion
targetSdkVersion 29
versionCode 68
versionName "1.18.2"
versionCode 69
versionName "1.19.0"
}

lintOptions {
Expand All @@ -36,7 +37,6 @@ dependencies {
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation "com.google.android.material:material:1.2.1"
implementation "com.google.android.flexbox:flexbox:3.0.0"
implementation "androidx.core:core:1.5.0"

/** Lifecycle */
implementation "androidx.lifecycle:lifecycle-extensions:$lifecycleVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,27 @@
import cz.martykan.forecastie.notifications.WeatherNotificationService;

public class SplashActivity extends AppCompatActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

showWeatherNotificationIfNeeded();

Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}

private void showWeatherNotificationIfNeeded() {
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs == null)
return;

// we should check permission here because user can update Android version between app launches
boolean foregroundServicesPermissionGranted = isForegroundServicesPermissionGranted();
boolean isWeatherNotificationEnabled =
prefs.getBoolean(getString(R.string.settings_enable_notification_key), false);
if (isWeatherNotificationEnabled && foregroundServicesPermissionGranted) {
boolean foregroundServicesPermissionGranted =
Build.VERSION.SDK_INT < Build.VERSION_CODES.P
||
ContextCompat.checkSelfPermission(this, Manifest.permission.FOREGROUND_SERVICE)
== PackageManager.PERMISSION_GRANTED;
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
if (prefs != null
&& prefs.getBoolean(getString(R.string.settings_enable_notification_key), false)
&& foregroundServicesPermissionGranted
) {
WeatherNotificationService.start(this);
}
}

private boolean isForegroundServicesPermissionGranted() {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.P)
return true; // There is no need for this permission prior Android Pie (Android SDK 28)
return ContextCompat.checkSelfPermission(this, Manifest.permission.FOREGROUND_SERVICE)
== PackageManager.PERMISSION_GRANTED;
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,12 @@ public class WeatherPresentation {
public static final String DEFAULT_WIND_DIRECTION_FORMAT = "arrow";
/** Default pressure units is hPa/mBar. */
public static final String DEFAULT_PRESSURE_UNITS = "hPa/mBar";
/** Show temperature in status bar by default. */
public static final boolean DEFAULT_SHOW_TEMPERATURE_IN_STATUS_BAR = true;

private final boolean roundedTemperature;
private final String temperatureUnits;
private final String windSpeedUnits;
private final String windDirectionFormat;
private final String pressureUnits;
private final boolean showTemperatureInStatusBar;
/** Weather information. */
private final ImmutableWeather weather;
private final WeatherFormatterType type;
Expand All @@ -34,24 +31,20 @@ public WeatherPresentation() {
windSpeedUnits = DEFAULT_WIND_SPEED_UNITS;
windDirectionFormat = DEFAULT_WIND_DIRECTION_FORMAT;
pressureUnits = DEFAULT_PRESSURE_UNITS;
showTemperatureInStatusBar = DEFAULT_SHOW_TEMPERATURE_IN_STATUS_BAR;
weather = ImmutableWeather.EMPTY;
type = WeatherFormatterType.NOTIFICATION_SIMPLE;
}

public WeatherPresentation(
boolean roundedTemperature, @NonNull String temperatureUnits,
public WeatherPresentation(boolean roundedTemperature, @NonNull String temperatureUnits,
@NonNull String windSpeedUnits, @NonNull String windDirectionFormat,
@NonNull String pressureUnits, boolean showTemperatureInStatusBar,
@NonNull ImmutableWeather weather,
@NonNull String pressureUnits, @NonNull ImmutableWeather weather,
@NonNull WeatherFormatterType type
) {
this.roundedTemperature = roundedTemperature;
this.temperatureUnits = temperatureUnits;
this.windSpeedUnits = windSpeedUnits;
this.windDirectionFormat = windDirectionFormat;
this.pressureUnits = pressureUnits;
this.showTemperatureInStatusBar = showTemperatureInStatusBar;
this.weather = weather;
this.type = type;
}
Expand All @@ -64,14 +57,6 @@ public boolean isRoundedTemperature() {
return roundedTemperature;
}

/**
* Returns {@code true} if temperature should be shown in status bar and {@code false} if shouldn't.
* @return {@code true} if temperature should be shown in status bar and {@code false} if shouldn't
*/
public boolean shouldShowTemperatureInStatusBar() {
return showTemperatureInStatusBar;
}

/**
* Returns temperature units as temperature unit key.
* @return temperature units
Expand Down Expand Up @@ -121,67 +106,38 @@ public WeatherFormatterType getType() {
}

public WeatherPresentation copy(boolean roundedTemperature) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

public WeatherPresentation copyTemperatureUnits(@NonNull String temperatureUnits) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

public WeatherPresentation copyWindSpeedUnits(@NonNull String windSpeedUnits) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

public WeatherPresentation copyWindDirectionFormat(@NonNull String windDirectionFormat) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

public WeatherPresentation copyPressureUnits(@NonNull String pressureUnits) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
}

public WeatherPresentation copyShowTemperatureInStatusBar(boolean showTemperatureInStatusBar) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

public WeatherPresentation copy(@NonNull ImmutableWeather weather) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

public WeatherPresentation copy(@NonNull WeatherFormatterType type) {
return new WeatherPresentation(
roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, showTemperatureInStatusBar,
weather, type
);
return new WeatherPresentation(roundedTemperature, temperatureUnits, windSpeedUnits,
windDirectionFormat, pressureUnits, weather, type);
}

@Override
Expand All @@ -197,7 +153,6 @@ public boolean equals(Object o) {
if (!windDirectionFormat.equals(that.windDirectionFormat)) return false;
if (!pressureUnits.equals(that.pressureUnits)) return false;
if (!weather.equals(that.weather)) return false;
if (showTemperatureInStatusBar != that.showTemperatureInStatusBar) return false;
return type == that.type;
}

Expand All @@ -208,13 +163,11 @@ public int hashCode() {
result = 31 * result + windSpeedUnits.hashCode();
result = 31 * result + windDirectionFormat.hashCode();
result = 31 * result + pressureUnits.hashCode();
result = 31 * result + (showTemperatureInStatusBar ? 1 : 0);
result = 31 * result + weather.hashCode();
result = 31 * result + type.hashCode();
return result;
}

@NonNull
@Override
public String toString() {
return "WeatherPresentation{" +
Expand All @@ -223,7 +176,6 @@ public String toString() {
", windSpeedUnits='" + windSpeedUnits + '\'' +
", windDirectionFormat='" + windDirectionFormat + '\'' +
", pressureUnits='" + pressureUnits + '\'' +
", shouldShowTemperatureInStatusBar=" + showTemperatureInStatusBar +
", weather=" + weather +
", type=" + type +
'}';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
* Service for showing and updating notification.
*/
public class WeatherNotificationService extends Service {
private static final String TAG = "WeatherNotificationServ";
public static int WEATHER_NOTIFICATION_ID = 1;
private static final String WEATHER_NOTIFICATION_CHANNEL_ID = "weather_notification_channel";

Expand All @@ -57,6 +56,7 @@ public void onCreate() {
repositoryListener = new WeatherRepository.RepositoryListener() {
@Override
public void onChange(@NonNull WeatherPresentation newData) {
Log.e("f", "RepositoryListener: " + newData.toString());
updateNotification(newData);
}
};
Expand All @@ -74,7 +74,7 @@ public void onConfigurationChanged(Configuration newConfig) {

private void configureNotification(PendingIntent pendingIntent) {
notification = new NotificationCompat.Builder(this, WEATHER_NOTIFICATION_CHANNEL_ID)
.setSmallIcon(NotificationContentUpdater.DEFAULT_NOTIFICATION_ICON)
.setSmallIcon(R.drawable.cloud)
.setContentIntent(pendingIntent)
.setOngoing(true)
.setOnlyAlertOnce(true)
Expand Down Expand Up @@ -127,7 +127,7 @@ public IBinder onBind(Intent intent) {
* Put data into notification.
*/
private void updateNotification(@NonNull WeatherPresentation weatherPresentation) {
Log.e(TAG, "notification update: " + weatherPresentation.toString());
Log.e("f", "notification update: " + weatherPresentation.toString());
NotificationContentUpdater updater = getContentUpdater(weatherPresentation.getType());
if (updater.isLayoutCustom()) {
RemoteViews layout = updater.prepareRemoteView(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
* Intent when some class updates data because Observer pattern grants us one source of truth.
*/
public class WeatherRepository {
private String notificationTypeKey;
private String notificationTypeDefaultKey;
private String notificationTypeSimpleKey;
private String notificationTypeDefault;
private String showTemperatureInStatusBarKey;
private String typeKey;
private String typeDefaultKey;
private String typeSimpleKey;
private String typeDefault;

private final Executor executor;
private SharedPreferences prefs;
Expand Down Expand Up @@ -119,7 +118,6 @@ private WeatherPresentation readValuesFromStorage() {
prefs.getString("speedUnit", WeatherPresentation.DEFAULT_WIND_SPEED_UNITS),
prefs.getString("windDirectionFormat", WeatherPresentation.DEFAULT_WIND_DIRECTION_FORMAT),
prefs.getString("pressureUnit", WeatherPresentation.DEFAULT_PRESSURE_UNITS),
prefs.getBoolean(showTemperatureInStatusBarKey, WeatherPresentation.DEFAULT_SHOW_TEMPERATURE_IN_STATUS_BAR),
weather, type
);
}
Expand All @@ -128,13 +126,13 @@ private WeatherPresentation readValuesFromStorage() {
@NonNull
private WeatherFormatterType readNotificationType(@NonNull SharedPreferences prefs) {
WeatherFormatterType result;
String typePref = prefs.getString(notificationTypeKey, notificationTypeDefault);
if (typePref != null && typePref.equalsIgnoreCase(notificationTypeDefaultKey)) {
String typePref = prefs.getString(typeKey, typeDefault);
if (typePref != null && typePref.equalsIgnoreCase(typeDefaultKey)) {
result = WeatherFormatterType.NOTIFICATION_DEFAULT;
} else if (typePref != null && typePref.equalsIgnoreCase(notificationTypeSimpleKey)) {
} else if (typePref != null && typePref.equalsIgnoreCase(typeSimpleKey)) {
result = WeatherFormatterType.NOTIFICATION_SIMPLE;
} else {
if (notificationTypeDefault == null || notificationTypeDefault.equalsIgnoreCase(notificationTypeDefaultKey)) {
if (typeDefault == null || typeDefault.equalsIgnoreCase(typeDefaultKey)) {
result = WeatherFormatterType.NOTIFICATION_DEFAULT;
} else {
result = WeatherFormatterType.NOTIFICATION_SIMPLE;
Expand All @@ -144,11 +142,10 @@ private WeatherFormatterType readNotificationType(@NonNull SharedPreferences pre
}

private void prepareSettingsConstants(@NonNull Context context) {
notificationTypeKey = context.getString(R.string.settings_notification_type_key);
notificationTypeDefaultKey = context.getString(R.string.settings_notification_type_key_default);
notificationTypeSimpleKey = context.getString(R.string.settings_notification_type_key_simple);
notificationTypeDefault = context.getString(R.string.settings_notification_type_default_value);
showTemperatureInStatusBarKey = context.getString(R.string.settings_show_temperature_in_status_bar_key);
typeKey = context.getString(R.string.settings_notification_type_key);
typeDefaultKey = context.getString(R.string.settings_notification_type_key_default);
typeSimpleKey = context.getString(R.string.settings_notification_type_key_simple);
typeDefault = context.getString(R.string.settings_notification_type_default_value);
}

/** Callback method to get updated weather data and settings. */
Expand Down Expand Up @@ -198,7 +195,7 @@ public void run() {
case "lastUpdate":
case "lastToday":
String json = sharedPreferences.getString("lastToday", "");
if (json != null && !json.isEmpty()) {
if (!json.isEmpty()) {
long lastUpdate = sharedPreferences.getLong("lastUpdate", -1L);
ImmutableWeather weather = ImmutableWeather.fromJson(json, lastUpdate);
result = weatherPresentation.copy(weather);
Expand All @@ -212,41 +209,27 @@ public void run() {
case "unit":
String temperatureUnits = sharedPreferences.getString(key,
WeatherPresentation.DEFAULT_TEMPERATURE_UNITS);
if (temperatureUnits != null) {
result = weatherPresentation.copyTemperatureUnits(temperatureUnits);
}
result = weatherPresentation.copyTemperatureUnits(temperatureUnits);
break;
case "speedUnit":
String windSpeedUnits = sharedPreferences.getString(key,
WeatherPresentation.DEFAULT_WIND_SPEED_UNITS);
if (windSpeedUnits != null) {
result = weatherPresentation.copyWindSpeedUnits(windSpeedUnits);
}
result = weatherPresentation.copyWindSpeedUnits(windSpeedUnits);
break;
case "windDirectionFormat":
String windDirectionFormat = sharedPreferences.getString(key,
WeatherPresentation.DEFAULT_WIND_DIRECTION_FORMAT);
if (windDirectionFormat != null) {
result = weatherPresentation.copyWindDirectionFormat(windDirectionFormat);
}
result = weatherPresentation.copyWindDirectionFormat(windDirectionFormat);
break;
case "pressureUnit":
String pressureUnits = sharedPreferences.getString(key,
WeatherPresentation.DEFAULT_PRESSURE_UNITS);
if (pressureUnits != null) {
result = weatherPresentation.copyPressureUnits(pressureUnits);
}
result = weatherPresentation.copyPressureUnits(pressureUnits);
break;

default:
if (key.equalsIgnoreCase(notificationTypeKey)) {
if (key.equalsIgnoreCase(typeKey)) {
result = weatherPresentation.copy(readNotificationType(sharedPreferences));
} else if (key.equalsIgnoreCase(showTemperatureInStatusBarKey)) {
boolean showTemperatureInStatusBar = sharedPreferences.getBoolean(
showTemperatureInStatusBarKey,
WeatherPresentation.DEFAULT_SHOW_TEMPERATURE_IN_STATUS_BAR
);
result = weatherPresentation.copyShowTemperatureInStatusBar(showTemperatureInStatusBar);
}
break;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ public void updateNotification(@NonNull WeatherPresentation weatherPresentation,
if (context == null)
throw new NullPointerException("context is null");

super.updateNotification(weatherPresentation, notification, context);

notification
.setCustomContentView(null)
.setContent(null)
Expand Down
Loading

0 comments on commit 4eb0565

Please sign in to comment.