Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possible fix to CI gradle version issue #165

Closed
wants to merge 8 commits into from
Closed
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
7 changes: 4 additions & 3 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ jobs:
runs-on: ubuntu-latest
steps:
- name: Checkout the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Set up Java
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
distribution: "temurin"
distribution: "zulu"
java-version: 17
cache: 'gradle'

- name: Loading submodules
run: git submodule update --init --recursive
Expand Down
13 changes: 6 additions & 7 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation project(path: ':libtoolscommon')

implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.constraintlayout:constraintlayout:2.2.0'
implementation 'androidx.cardview:cardview:1.0.0'
implementation 'com.google.android.material:material:1.6.1'
implementation 'com.google.android.material:material:1.12.0'
implementation 'androidx.preference:preference:1.2.1'
implementation 'androidx.multidex:multidex:2.0.1'

Expand All @@ -71,13 +71,12 @@ dependencies {
implementation 'com.github.pwittchen:reactivewifi-rx2:0.3.0'
implementation 'com.github.PhilJay:MPAndroidChart:v3.1.0-alpha'
implementation 'com.google.code.gson:gson:2.10.1'
implementation 'com.iamhabib:easy-preference:1.0.1'

implementation 'com.github.MKergall:osmbonuspack:6.5.2'
implementation 'io.nlopez.smartlocation:library:3.3.3'
implementation 'org.osmdroid:osmdroid-android:6.1.5'

implementation 'com.google.android.gms:play-services-location:20.0.0' // Smartlocation fails with higher version
implementation 'com.google.android.gms:play-services-location:21.3.0' // Smartlocation fails with higher version
implementation 'com.github.jemshit:DiscreteScrollView:1.5.2'
implementation 'com.github.bumptech.glide:glide:3.7.0'

Expand All @@ -97,10 +96,10 @@ dependencies {


testImplementation 'junit:junit:4.13.2'
testImplementation 'androidx.test:core:1.5.0'
testImplementation 'androidx.test:core:1.6.1'
testImplementation 'org.mockito:mockito-core:3.3.3'
androidTestImplementation 'androidx.test:runner:1.5.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.5.1'
androidTestImplementation 'androidx.test:runner:1.6.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.6.1'
}

apply plugin: 'com.google.gms.google-services'
Expand Down
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
Expand Down
15 changes: 9 additions & 6 deletions app/src/main/java/hpsaturn/pollutionreporter/AppData.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import androidx.multidex.MultiDexApplication;

import com.google.firebase.database.FirebaseDatabase;
import com.iamhabib.easy_preference.EasyPreference;
import com.polidea.rxandroidble2.RxBleClient;
import com.polidea.rxandroidble2.internal.RxBleLog;

Expand All @@ -18,16 +17,19 @@
public class AppData extends MultiDexApplication{

private RxBleClient rxBleClient;
private EasyPreference.Builder prefBuilder;

public static RxBleClient getRxBleClient(Context context) {
AppData application = (AppData) context.getApplicationContext();
return application.rxBleClient;
}

public static EasyPreference.Builder getPrefBuilder(Context context){
AppData application = (AppData) context.getApplicationContext();
return application.prefBuilder;
// public static EasyPreference.Builder getPrefBuilder(Context context){
// AppData application = (AppData) context.getApplicationContext();
// return application.prefBuilder;
// }

public Context getContext() {
return this.getContext();
}

@Override
Expand All @@ -42,7 +44,8 @@ public void onCreate() {
RxJavaPlugins.setErrorHandler(throwable -> {});
rxBleClient = RxBleClient.create(this);
RxBleClient.setLogLevel(RxBleLog.VERBOSE);
prefBuilder = EasyPreference.with(this,"KEYS_APP_PREFERENCES");

// prefBuilder = EasyPreference.with(this,"KEYS_APP_PREFERENCES");
// AqicnApiManager.getInstance().init(this);
super.onCreate();
}
Expand Down
36 changes: 17 additions & 19 deletions app/src/main/java/hpsaturn/pollutionreporter/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import com.google.firebase.database.FirebaseDatabase;
import com.hpsaturn.tools.Logger;
import com.hpsaturn.tools.UITools;
import com.iamhabib.easy_preference.EasyPreference;
import com.yarolegovich.discretescrollview.DiscreteScrollView;
import com.yarolegovich.discretescrollview.transform.ScaleTransformer;

Expand All @@ -40,6 +39,7 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import hpsaturn.pollutionreporter.common.Keys;
import hpsaturn.pollutionreporter.common.Storage;
import hpsaturn.pollutionreporter.models.ResponseConfig;
import hpsaturn.pollutionreporter.models.SensorData;
import hpsaturn.pollutionreporter.models.SensorTrackInfo;
Expand Down Expand Up @@ -90,7 +90,6 @@ public class MainActivity extends BaseActivity implements
DiscreteScrollView fragmentPicker;

private ScanFragment scanFragment;
private EasyPreference.Builder prefBuilder;
private ChartFragment chartFragment;
private RecordTrackManager recordTrackManager;
private MapFragment mapFragment;
Expand All @@ -110,7 +109,6 @@ protected void onCreate(Bundle savedInstanceState) {
startRecordTrackService();

ButterKnife.bind(this);
prefBuilder = AppData.getPrefBuilder(this);

startDataBase();
setSupportActionBar(toolbar);
Expand Down Expand Up @@ -198,7 +196,7 @@ public void onSensorConfigWrite(String config) {
};

public boolean isRecording(){
return prefBuilder.getBoolean(Keys.SENSOR_RECORD, false);
return Storage.getBoolean(Keys.SENSOR_RECORD, false, this);
}

private void buttonRecordingAction () {
Expand All @@ -221,14 +219,14 @@ public void shareAction(String metadata, boolean isShare){

private void stopRecord() {
showSnackMessage(R.string.msg_record_stop);
prefBuilder.addBoolean(Keys.SENSOR_RECORD, false).save();
Storage.addBoolean(Keys.SENSOR_RECORD, false, this);
recordTrackManager.serviceRecordStop();
fabUpdateLayout();
}

private void startRecord() {
showSnackMessage(R.string.msg_record);
prefBuilder.addBoolean(Keys.SENSOR_RECORD, true).save();
Storage.addBoolean(Keys.SENSOR_RECORD, true, this);
recordTrackManager.serviceRecord();
fabUpdateLayout();
}
Expand Down Expand Up @@ -328,7 +326,7 @@ private void scrollToRecordsFragment() {

private void fabUpdateLayout() {
fab.hide();
if (prefBuilder.getBoolean(Keys.SENSOR_RECORD, false)) {
if (Storage.getBoolean(Keys.SENSOR_RECORD, false, this)) {
fab.setBackgroundTintList(ContextCompat.getColorStateList(this,R.color.color_state_record_stop));
fab.setImageDrawable(ContextCompat.getDrawable(this,R.drawable.ic_stop_white_24dp));
} else {
Expand Down Expand Up @@ -420,7 +418,7 @@ public void stopRecordTrackService() {
}

public void deviceConnect() {
if (prefBuilder.getBoolean(Keys.DEVICE_PAIR, false)) {
if (Storage.getBoolean(Keys.DEVICE_PAIR, false, this)) {
startRecordTrackService();
showSnackMessage(R.string.msg_device_connecting);
}
Expand Down Expand Up @@ -462,15 +460,15 @@ public boolean isStorageGranted(){
int permissionState = ContextCompat.checkSelfPermission(this,
Manifest.permission.WRITE_EXTERNAL_STORAGE);
return permissionState == PackageManager.PERMISSION_GRANTED;
// return prefBuilder.getBoolean(Keys.PERMISSION_STORAGE,false);
// return Storage.getBoolean(Keys.PERMISSION_STORAGE,false);
}

public boolean isGPSGranted(){
return prefBuilder.getBoolean(Keys.PERMISSION_BACKGROUND,false);
return Storage.getBoolean(Keys.PERMISSION_BACKGROUND,false, this);
}

public boolean isBLEGranted(){
return prefBuilder.getBoolean(Keys.PERMISSION_BLE,false);
return Storage.getBoolean(Keys.PERMISSION_BLE,false, this);
}

public void checkPreviousPermission() {
Expand Down Expand Up @@ -560,16 +558,16 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
break;
}
Log.i(TAG, "[PERM] User granted background location permission");
prefBuilder.addBoolean(Keys.PERMISSION_BACKGROUND, true).save();
Storage.addBoolean(Keys.PERMISSION_BACKGROUND, true, this);
buttonRecordingAction();
break;
case STORAGE:
if (grantResults.length == 0 || grantResults[0] != PackageManager.PERMISSION_GRANTED) {
prefBuilder.addBoolean(Keys.PERMISSION_STORAGE, false).save();
Storage.addBoolean(Keys.PERMISSION_STORAGE, false, this);
Log.i(TAG, "[PERM] User denied WRITE_EXTERNAL_STORAGE permission.");
} else {
Log.i(TAG, "[PERM] User granted WRITE_EXTERNAL_STORAGE permission.");
prefBuilder.addBoolean(Keys.PERMISSION_STORAGE, true).save();
Storage.addBoolean(Keys.PERMISSION_STORAGE, true, this);
}
break;
case BLUETOOTH:
Expand All @@ -588,7 +586,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
break;
}
Log.i(TAG, "[PERM] User granted scan nearby devices permission");
prefBuilder.addBoolean(Keys.PERMISSION_BLE, true).save();
Storage.addBoolean(Keys.PERMISSION_BLE, true, this);
requestLocationPermission();

default:
Expand All @@ -597,7 +595,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
}

public void performBLEScan() {
if(!isBLEGranted())prefBuilder.addBoolean(Keys.PERMISSION_BLE, true).save();
if(!isBLEGranted())Storage.addBoolean(Keys.PERMISSION_BLE, true, this);
if(scanFragment!=null)scanFragment.executeScan();
}

Expand All @@ -609,8 +607,8 @@ void actionUnPair() {
Logger.i(TAG, "[BLE] unpaired..");
stopRecord();
recordTrackManager.stop();
prefBuilder.addString(Keys.DEVICE_ADDRESS,"").save();
prefBuilder.addBoolean(Keys.DEVICE_PAIR, false).save();
Storage.addString(Keys.DEVICE_ADDRESS,"", this);
Storage.addBoolean(Keys.DEVICE_PAIR, false, this);
fab.hide();
if (chartFragment != null) chartFragment.clearData();
removeFragment(chartFragment);
Expand Down Expand Up @@ -638,7 +636,7 @@ protected void onDestroy() {
}

private boolean isPaired(){
return prefBuilder.getBoolean(Keys.DEVICE_PAIR, false);
return Storage.getBoolean(Keys.DEVICE_PAIR, false, this);
}

public boolean isDeviceConnected() {
Expand Down
24 changes: 23 additions & 1 deletion app/src/main/java/hpsaturn/pollutionreporter/common/Storage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.preference.PreferenceManager;

import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
Expand Down Expand Up @@ -115,4 +114,27 @@ public static List<String> getTempAPList(Context ctx) {
}
}

public static boolean getBoolean(String key, boolean value, Context ctx) {
SharedPreferences preferences = ctx.getSharedPreferences(KEYS_TRACKS_PREFERENCES,0);
return preferences.getBoolean(key, value);
}

public static void addBoolean(String key, boolean value, Context ctx) {
SharedPreferences preferences = ctx.getSharedPreferences(KEYS_TRACKS_PREFERENCES,0);
SharedPreferences.Editor editor = preferences.edit();
editor.putBoolean(key, value);
editor.apply();
}

public static void addString(String key, String value, Context ctx) {
SharedPreferences preferences = ctx.getSharedPreferences(KEYS_TRACKS_PREFERENCES,0);
SharedPreferences.Editor editor = preferences.edit();
editor.putString(key, value);
editor.apply();
}

public static String getString(String key, String value, Context ctx) {
SharedPreferences preferences = ctx.getSharedPreferences(KEYS_TRACKS_PREFERENCES,0);
return preferences.getString(key, value);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,21 @@
import android.content.Context;
import android.content.Intent;
import android.location.Location;
import android.os.Build;
import android.os.IBinder;

import androidx.annotation.RequiresApi;
import androidx.core.app.NotificationCompat;

import com.fonfon.geohash.GeoHash;
import com.google.gson.Gson;
import com.hpsaturn.tools.FileTools;
import com.hpsaturn.tools.Logger;
import com.hpsaturn.tools.UITools;
import com.iamhabib.easy_preference.EasyPreference;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.Locale;

import hpsaturn.pollutionreporter.AppData;
import hpsaturn.pollutionreporter.Config;
import hpsaturn.pollutionreporter.MainActivity;
import hpsaturn.pollutionreporter.R;
Expand All @@ -50,7 +45,6 @@ public class RecordTrackService extends Service {

private static final String TAG = RecordTrackService.class.getSimpleName();
private static final boolean VERBOSE = Config.DEBUG && false;
private EasyPreference.Builder prefBuilder;
private BLEHandler bleHandler;
private boolean isRecording;
private RecordTrackManager recordTrackManager;
Expand All @@ -64,15 +58,14 @@ public class RecordTrackService extends Service {
public void onCreate() {
super.onCreate();
Logger.i(TAG, "[BLE] Creating Service container..");
prefBuilder = AppData.getPrefBuilder(this);
isRecording = prefBuilder.getBoolean(Keys.SENSOR_RECORD, false);
isRecording = Storage.getBoolean(Keys.SENSOR_RECORD, false, this);
if (isRecording) restoreValues();
recordTrackManager = new RecordTrackManager(this, managerListener);
notificationSetup();
}

private void startConnection() {
if (prefBuilder.getBoolean(Keys.DEVICE_PAIR, false)) {
if (Storage.getBoolean(Keys.DEVICE_PAIR, false, this)) {
if (bleHandler == null) {
connect();
}
Expand All @@ -86,7 +79,7 @@ else if (bleHandler.isConnected()) {

private void connect() {
Logger.i(TAG, "[BLE] starting BLE connection..");
String macAddress = prefBuilder.getString(Keys.DEVICE_ADDRESS, "");
String macAddress = Storage.getString(Keys.DEVICE_ADDRESS, "", this);
Logger.i(TAG, "[BLE] deviceConnect to " + macAddress);
bleHandler = new BLEHandler(this, macAddress, bleListener);
bleHandler.connect();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.hpsaturn.tools.Logger;
import com.hpsaturn.tools.UITools;
import com.iamhabib.easy_preference.EasyPreference;
import com.polidea.rxandroidble2.RxBleClient;
import com.polidea.rxandroidble2.exceptions.BleScanException;
import com.polidea.rxandroidble2.scan.ScanFilter;
Expand All @@ -33,6 +32,7 @@
import hpsaturn.pollutionreporter.PermissionUtil;
import hpsaturn.pollutionreporter.R;
import hpsaturn.pollutionreporter.common.Keys;
import hpsaturn.pollutionreporter.common.Storage;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;

Expand Down Expand Up @@ -162,9 +162,9 @@ private void onDeviceConnectClick(ScanResult scanResults) {
String macAddress = scanResults.getBleDevice().getMacAddress();
String deviceName = scanResults.getBleDevice().getName();
Logger.i(TAG, "onDeviceConnectClick: "+deviceName+ " " + macAddress);
EasyPreference.Builder prefBuilder = AppData.getPrefBuilder(getContext());
prefBuilder.addString(Keys.DEVICE_ADDRESS, macAddress).save();
prefBuilder.addBoolean(Keys.DEVICE_PAIR, true).save();
// EasyPreference.Builder Storage = AppData.getPrefBuilder(getContext());
Storage.addString(Keys.DEVICE_ADDRESS, macAddress, requireContext());
Storage.addBoolean(Keys.DEVICE_PAIR, true, requireContext());
getMain().deviceConnect();
getMain().removeScanFragment();
}
Expand Down
Loading
Loading