Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .aiexclude
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
keystore.properties
6 changes: 3 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
uses: actions/checkout@v5

- name: Gradle Wrapper Validation
uses: gradle/wrapper-validation-action@v1
uses: gradle/actions/wrapper-validation@v3

- name: Install JDK
uses: actions/setup-java@v2
uses: actions/setup-java@v5
with:
distribution: 'zulu'
java-version: 17
Expand Down
14 changes: 8 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ android {
}
}

compileSdk 33
compileSdk 35

defaultConfig {
applicationId "de.stephanlindauer.criticalmaps"
minSdkVersion 16
targetSdkVersion 33
targetSdkVersion 35
versionCode 48
versionName "2.9.0"
vectorDrawables.useSupportLibrary = true
Expand All @@ -39,7 +39,7 @@ android {
debug {
applicationIdSuffix ".debug"
pseudoLocalesEnabled true
minifyEnabled true
minifyEnabled false
shrinkResources false
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
}
Expand All @@ -64,6 +64,7 @@ android {

buildFeatures {
viewBinding = true
buildConfig true
}

lint {
Expand All @@ -77,10 +78,11 @@ dependencies {
implementation 'com.squareup:otto:1.3.8'
implementation 'org.osmdroid:osmdroid-android:6.1.8'
implementation 'com.squareup.picasso:picasso:2.8'
implementation 'androidx.core:core:1.12.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'androidx.annotation:annotation:1.6.0'
implementation 'androidx.annotation:annotation:1.9.1'
implementation 'com.google.android.material:material:1.9.0'
implementation 'androidx.exifinterface:exifinterface:1.3.6'
implementation 'androidx.exifinterface:exifinterface:1.3.7'
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'com.jakewharton.timber:timber:5.0.1'
Expand All @@ -92,7 +94,7 @@ dependencies {
implementation "com.google.dagger:dagger:$dagger_version"
annotationProcessor "com.google.dagger:dagger-compiler:$dagger_version"

debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.12'
debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.14'

errorprone("com.google.errorprone:error_prone_core:2.18.0")

Expand Down
4 changes: 4 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="18" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission
android:name="android.permission.POST_NOTIFICATIONS"
android:minSdkVersion="33" />

<uses-feature
android:name="android.hardware.location.network"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
public interface AppComponent {
void inject(Main main);
void inject(ServerSyncService serverSyncService);
void inject(MapFragment serverSyncService);
void inject(MapFragment mapFragment);
void inject(ChatFragment chatFragment);
void inject(SettingsFragment settingsFragment);

Expand Down
38 changes: 30 additions & 8 deletions app/src/main/java/de/stephanlindauer/criticalmaps/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.animation.ArgbEvaluator;
import android.animation.ValueAnimator;
import android.annotation.TargetApi;
import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
Expand All @@ -23,6 +22,7 @@

import androidx.annotation.IdRes;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.ActionBarDrawerToggle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.SwitchCompat;
Expand Down Expand Up @@ -82,7 +82,7 @@ public class Main extends AppCompatActivity implements NavigationView.OnNavigati
setKeepScreenOn();
break;
case SharedPrefsKeys.PRIVACY_POLICY_ACCEPTED:
if (!locationUpdateManager.checkPermission()) {
if (!LocationUpdateManager.checkPermission()) {
locationUpdateManager.requestPermission();
}
break;
Expand Down Expand Up @@ -143,8 +143,6 @@ public void onCreate(Bundle bundle) {

setShowOnLockscreen();
setKeepScreenOn();

ServerSyncService.startService();
}

@Override
Expand Down Expand Up @@ -226,15 +224,26 @@ public void onDrawerClosed(@NonNull View drawerView) {
navigateTo(R.id.navigation_map);
}

final boolean isPrivacyPolicyAccepted =
!privacyPolicyAcceptedPreference.isSet() || !privacyPolicyAcceptedPreference.get();
if (isPrivacyPolicyAccepted) {
locationUpdateManager.initialize();

final boolean isPrivacyPolicyAccepted = privacyPolicyAcceptedPreference.get();
if (!isPrivacyPolicyAccepted) {
binding.introductionText.setMovementMethod(LinkMovementMethod.getInstance());
binding.introductionText.setText(Html.fromHtml(getString(R.string.introduction_gps)));
binding.introductionView.setVisibility(View.VISIBLE);
}
}

@Override
protected void onResume() {
super.onResume();
Timber.d("onResume() called");
final boolean isPrivacyPolicyAccepted = privacyPolicyAcceptedPreference.get();
if (isPrivacyPolicyAccepted) {
initiateServiceStartIfPermitted();
}
}

@Override
protected void onStop() {
permissionCheckHandler.detachActivity();
Expand Down Expand Up @@ -454,7 +463,7 @@ private void animateToolbar(int durationMillis, boolean toMap) {
radiusAnimator.start();
}

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@RequiresApi(Build.VERSION_CODES.LOLLIPOP)
private void fadeInStatusBarColor(int duration, boolean toMap) {
int colorMap = ContextCompat.getColor(this, R.color.main_statusbarcolor_map);
int colorOthers = ContextCompat.getColor(this, R.color.main_statusbarcolor_others);
Expand Down Expand Up @@ -484,4 +493,17 @@ private void handleObserverModeSwitchCheckedChanged(boolean isChecked) {
new BooleanPreference(
sharedPreferences, SharedPrefsKeys.OBSERVER_MODE_ACTIVE).set(isChecked);
}

private void initiateServiceStartIfPermitted() {
if (LocationUpdateManager.checkPermission()) {
if (!ServerSyncService.isCurrentlyRunning()) {
Timber.d("Location and notification permissions granted. Attempting to start ServerSyncService.");
ServerSyncService.startService();
} else {
Timber.d("Location and notification permission granted, but service is already running.");
}
} else {
Timber.d("Location and notification permission NOT granted. ServerSyncService will not be started.");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package de.stephanlindauer.criticalmaps.adapter;

import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.view.LayoutInflater;
import android.view.ViewGroup;

Expand All @@ -13,7 +11,6 @@
import java.util.Locale;
import java.util.TimeZone;

import de.stephanlindauer.criticalmaps.R;
import de.stephanlindauer.criticalmaps.databinding.ViewChatmessageBinding;
import de.stephanlindauer.criticalmaps.model.chat.ReceivedChatMessage;
import de.stephanlindauer.criticalmaps.utils.TimeToWordStringConverter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ public void run() {
getChatmessagesHandler.get().execute();
}
};
timerGetChatmessages.scheduleAtFixedRate(timerTaskPullServer, 0, SERVER_SYNC_INTERVAL);
timerGetChatmessages.schedule(timerTaskPullServer, 0, SERVER_SYNC_INTERVAL);
}

private void stopGetChatmessagesTimer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.animation.AnimatorInflater;
import android.animation.ObjectAnimator;
import android.annotation.TargetApi;
import android.content.Intent;
import android.content.SharedPreferences;
import android.graphics.drawable.Drawable;
Expand All @@ -19,6 +18,7 @@
import androidx.annotation.ColorRes;
import androidx.annotation.DrawableRes;
import androidx.annotation.NonNull;
import androidx.annotation.RequiresApi;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.content.res.AppCompatResources;
import androidx.core.content.ContextCompat;
Expand Down Expand Up @@ -256,9 +256,13 @@ public void onRotate(float deltaAngle) {
binding.mapSetNorthFab.setRotation(mapView.getMapOrientation());

showGpxHandler.showGpx(mapView);

if (!LocationUpdateManager.checkPermission()) {
zoomToLocation(defaultGeoPoint, NO_GPS_PERMISSION_ZOOM_LEVEL);
}
}

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@RequiresApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
private void adjustToWindowsInsets() {
// No-op on < API21
ViewCompat.setOnApplyWindowInsetsListener(binding.mapOverlayContainerLayout, (v, insets) -> {
Expand Down Expand Up @@ -321,12 +325,6 @@ public void onResume() {
sharedPreferences.registerOnSharedPreferenceChangeListener(
observerModeOnSharedPreferenceChangeListener);

if (locationUpdateManager.checkPermission()) {
locationUpdateManager.startListening();
} else {
zoomToLocation(defaultGeoPoint, NO_GPS_PERMISSION_ZOOM_LEVEL);
}

startGetLocationTimer();
}

Expand Down Expand Up @@ -505,7 +503,7 @@ public void run() {
getLocationHandler.get().execute();
}
};
timerGetLocation.scheduleAtFixedRate(timerTaskPullServer, 0, SERVER_SYNC_INTERVAL);
timerGetLocation.schedule(timerTaskPullServer, 0, SERVER_SYNC_INTERVAL);
}

private void stopGetLocationTimer() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void requestPermissionsWithRationaleIfNeeded(PermissionRequest permission
activePermissionRequest = permissionRequest;

// short-circuit here if already granted
if (checkPermissionsGranted(permissionRequest.getPermissions())) {
if (checkAllPermissionsGranted(permissionRequest.getPermissions())) {
activePermissionRequest.getOnGrantedCallback().run();
activePermissionRequest = null;
return;
Expand Down Expand Up @@ -91,7 +91,8 @@ public boolean handlePermissionRequestCallback(int requestCode, int[] grantResul
return false;
}

boolean allPermissionsGranted = true;
// Note: Can be an empty array that should be treated as cancellation.
boolean allPermissionsGranted = grantResults.length > 0;
for (int result : grantResults) {
allPermissionsGranted = allPermissionsGranted &&
result == PackageManager.PERMISSION_GRANTED;
Expand Down Expand Up @@ -120,7 +121,7 @@ public boolean handlePermissionRequestCallback(int requestCode, int[] grantResul
return true;
}

public static boolean checkPermissionsGranted(String[] permissions) {
public static boolean checkAllPermissionsGranted(String[] permissions) {
boolean permissionsGranted = true;
for (String permission : permissions) {
permissionsGranted = permissionsGranted && (PackageManager.PERMISSION_GRANTED ==
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import android.Manifest;
import android.annotation.SuppressLint;
import android.content.Context;
import android.content.pm.PackageManager;
import android.location.Location;
import android.location.LocationListener;
import android.location.LocationManager;
import android.os.Bundle;

import androidx.core.content.ContextCompat;

import com.squareup.otto.Produce;

import org.osmdroid.util.GeoPoint;
Expand Down Expand Up @@ -42,9 +45,12 @@ public class LocationUpdateManager {
private final String[] USED_PROVIDERS = new String[]{
LocationManager.GPS_PROVIDER,
LocationManager.NETWORK_PROVIDER};

@SuppressLint("InlinedApi")
private final String[] PERMISSIONS = {
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION};
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.POST_NOTIFICATIONS};
private final LocationManager locationManager;
private Location lastPublishedLocation;

Expand Down Expand Up @@ -143,7 +149,7 @@ public boolean isUpdating() {
return isUpdating;
}

public void initializeAndStartListening() {
public void initialize() {
boolean noProviderExists = !checkIfAtLeastOneProviderExits();
boolean noPermission = !checkPermission();

Expand All @@ -165,8 +171,6 @@ public void initializeAndStartListening() {
if (noPermission) {
return;
}

startListening();
}

public void startListening() {
Expand Down Expand Up @@ -203,8 +207,12 @@ private void requestLocationUpdatesIfProviderExists(String provider) {
}
}

public boolean checkPermission() {
return PermissionCheckHandler.checkPermissionsGranted(PERMISSIONS);
@SuppressLint("InlinedApi")
public static boolean checkPermission() {
App app = App.components().app();
return (ContextCompat.checkSelfPermission(app, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED
|| ContextCompat.checkSelfPermission(app, Manifest.permission.ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED)
&& ContextCompat.checkSelfPermission(app, Manifest.permission.POST_NOTIFICATIONS) == PackageManager.PERMISSION_GRANTED;
}

public void requestPermission() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.Date;
import java.util.List;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@
import org.osmdroid.util.GeoPoint;

import java.util.ArrayList;
import java.util.Iterator;

import javax.inject.Inject;
import javax.inject.Provider;
import javax.inject.Singleton;

@Singleton
Expand Down
Loading
Loading