Skip to content

Commit

Permalink
Merge pull request #143 from kike-canaries/devel
Browse files Browse the repository at this point in the history
[Devel] Power saving settings and Spanish version
  • Loading branch information
hpsaturn authored Feb 22, 2022
2 parents 201cde3 + 99e7afd commit d2232cf
Show file tree
Hide file tree
Showing 23 changed files with 625 additions and 76 deletions.
14 changes: 4 additions & 10 deletions .github/workflows/android.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,12 @@
name: Android CI

on: [push]

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- name: set up JDK 11
uses: actions/setup-java@v1
with:
java-version: 11
- name: Checkout the code
uses: actions/checkout@v2
- name: Loading submodules
run: git submodule update --init --recursive
- name: Work directory
Expand All @@ -24,6 +18,6 @@ jobs:
run: |
echo $gservices > ./app/google-services.json
echo $aqicnkey > ./app/src/main/res/values/api_aqicn.xml
- name: Build with Gradle
- name: Build the app
run: ./gradlew build

2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ dependencies {
implementation 'com.trello.rxlifecycle2:rxlifecycle:2.2.1'
implementation 'com.trello.rxlifecycle2:rxlifecycle-components:2.2.1'
implementation 'com.jakewharton.rx2:replaying-share:2.1.1'
implementation "com.polidea.rxandroidble2:rxandroidble:1.8.1"
implementation 'com.polidea.rxandroidble2:rxandroidble:1.13.1'

implementation 'com.github.pwittchen:reactivewifi-rx2:0.3.0'

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 @@ -7,6 +7,7 @@
<uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" />
<uses-permission android:name="android.permission.BLUETOOTH" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
<uses-permission android:name="android.permission.INTERNET" />
Expand Down
11 changes: 3 additions & 8 deletions app/src/main/java/hpsaturn/pollutionreporter/BaseActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void checkBluetoohtBle() {
BluetoothManager bluetoothManager = (BluetoothManager) getSystemService(Context.BLUETOOTH_SERVICE);
BluetoothAdapter mBluetoothAdapter = bluetoothManager.getAdapter();
if (!getPackageManager().hasSystemFeature(PackageManager.FEATURE_BLUETOOTH_LE)) {
Toast.makeText(this, R.string.ble_not_supported, Toast.LENGTH_SHORT).show();
Toast.makeText(this, R.string.msg_ble_not_supported, Toast.LENGTH_SHORT).show();
} else if (mBluetoothAdapter == null || !mBluetoothAdapter.isEnabled()) {
Intent enableBtIntent = new Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE);
startActivityForResult(enableBtIntent, 0);
Expand Down Expand Up @@ -133,12 +133,6 @@ public void showFragmentFull(Fragment fragment, String fragmentTag, boolean toSt

}

public void showDialog(Fragment fragment, String fragmentTag) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.add(fragment, fragmentTag);
ft.show(fragment);
ft.commitAllowingStateLoss();
}

public void showDialogFragment(DialogFragment dialog, String TAG) {
FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
Expand Down Expand Up @@ -242,7 +236,7 @@ public boolean onOptionsItemSelected(MenuItem item) {
break;

case R.id.action_about:
UITools.viewLink(this,getString(R.string.url_canairio_page));
actionShowAbout();
break;

case R.id.action_feedback:
Expand All @@ -264,6 +258,7 @@ public boolean onOptionsItemSelected(MenuItem item) {

abstract void actionUnPair();
abstract void actionVarFilter();
abstract void actionShowAbout();

/**
* A native method that is implemented by the 'native-lib' native library,
Expand Down
49 changes: 40 additions & 9 deletions app/src/main/java/hpsaturn/pollutionreporter/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package hpsaturn.pollutionreporter;

import android.Manifest;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.Bundle;
Expand Down Expand Up @@ -43,6 +44,7 @@
import hpsaturn.pollutionreporter.service.RecordTrackManager;
import hpsaturn.pollutionreporter.service.RecordTrackScheduler;
import hpsaturn.pollutionreporter.service.RecordTrackService;
import hpsaturn.pollutionreporter.view.AboutFragment;
import hpsaturn.pollutionreporter.view.ChartFragment;
import hpsaturn.pollutionreporter.view.DisclosureFragment;
import hpsaturn.pollutionreporter.view.MapFragment;
Expand Down Expand Up @@ -238,7 +240,8 @@ public void setupAppFragments(){
}

private void setupFragmentPicker() {
List<PickerFragmentInfo> pickerFragmentInfos = PickerFragmentData.get().getFragmentsInfo();
Context ctx = getApplicationContext();
List<PickerFragmentInfo> pickerFragmentInfos = PickerFragmentData.get().getFragmentsInfo(ctx);
fragmentPicker.setVisibility(View.VISIBLE);
fragmentPicker.setSlideOnFling(true);
fragmentPicker.setAdapter(new PickerFragmentAdapter(pickerFragmentInfos));
Expand Down Expand Up @@ -439,6 +442,11 @@ public void showDisclosureFragment(int title, int desc, int img) {
showDialogFragment(dialog,DisclosureFragment.TAG);
}

public void showAboutFragment() {
AboutFragment about = new AboutFragment();
showDialogFragment(about,AboutFragment.TAG);
}

public boolean isStorageGranted(){
return prefBuilder.getBoolean(Keys.PERMISSION_STORAGE,false);
}
Expand All @@ -452,14 +460,29 @@ public boolean isBLEGranted(){
}

public void startPermissionsBLEFlow() {
Dexter.withContext(this)
.withPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.BLUETOOTH
)
.withListener(blePermissionListener)
.check();
Logger.i(TAG, "starting BLE permission flow");
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
Dexter.withContext(this)
.withPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.BLUETOOTH_SCAN

)
.withListener(blePermissionListener)
.check();
}else {
Dexter.withContext(this)
.withPermissions(
Manifest.permission.ACCESS_FINE_LOCATION,
Manifest.permission.ACCESS_COARSE_LOCATION,
Manifest.permission.BLUETOOTH

)
.withListener(blePermissionListener)
.check();
}
}

public void startPermissionsGPSFlow() {
Expand All @@ -486,6 +509,7 @@ public void startPermissionsGPSFlow() {
}

public void startPermissionsStorageFlow() {
Logger.i(TAG, "starting Storage permission flow");
Dexter.withContext(this)
.withPermissions(Manifest.permission.WRITE_EXTERNAL_STORAGE)
.withListener(storagePermissionListener)
Expand All @@ -500,6 +524,8 @@ public void onPermissionsChecked(MultiplePermissionsReport multiplePermissionsRe
if(!isBLEGranted())prefBuilder.addBoolean(Keys.PERMISSION_BLE, true).save();
if(scanFragment!=null)scanFragment.executeScan();
}
else
Logger.e(TAG, "BLEPermissions Not Granted");
}
@Override
public void onPermissionRationaleShouldBeShown(List<PermissionRequest> list, PermissionToken permissionToken) {
Expand Down Expand Up @@ -563,6 +589,11 @@ void actionVarFilter() {
showDialogFragment(new VariableFilterFragment(), VariableFilterFragment.TAG);
}

@Override
void actionShowAbout(){
showAboutFragment();
}

@Override
protected void onDestroy() {
stopRecordTrackService();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package hpsaturn.pollutionreporter.models;

/**
* Created by Antonio Vanegas @hpsaturn on 10/13/20.
*/
public class DeepSleepConfig extends SensorConfig {

public int deepSleep; //sample time
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class ResponseConfig extends SensorConfig {

public float altoffset = 0;

public float sealevel = 1013.25F;

public String ssid;

public String apiusr;
Expand Down Expand Up @@ -52,4 +54,6 @@ public class ResponseConfig extends SensorConfig {
public String hasspsw;

public int hasspt;

public int deepSleep = 0;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package hpsaturn.pollutionreporter.models;

/**
* Created by Antonio Vanegas @hpsaturn on 6/22/21.
*/
public class SeaLevelConfig extends SensorConfig {

public float sealevel = 1013.25F;
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,6 @@ public class SensorConfig {

public boolean i2conly;

public boolean sse;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package hpsaturn.pollutionreporter.view;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ScrollView;
import android.widget.TextView;

import androidx.fragment.app.DialogFragment;

import com.hpsaturn.tools.DeviceUtil;

import hpsaturn.pollutionreporter.R;

/**
* Created by izel on 9/11/15.
*/
public class AboutFragment extends DialogFragment {
public static final String TAG = AboutFragment.class.getSimpleName();

private ScrollView _sv_about;

@Override
public View onCreateView(LayoutInflater inflater,ViewGroup container,Bundle savedInstanceState){

View view = inflater.inflate(R.layout.about, container, false);
TextView aboutText = view.findViewById(R.id.tv_about_version_revision);

String version = DeviceUtil.getVersionName(requireActivity());
String revision = " r"+DeviceUtil.getVersionCode(requireActivity());
aboutText.setText("v"+version+revision);

_sv_about = view.findViewById(R.id.sv_about);
Animation translatebu= AnimationUtils.loadAnimation(getActivity(), R.anim.about);
_sv_about.startAnimation(translatebu);

return view;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
import java.util.Arrays;
import java.util.List;

import android.content.Context;
import android.content.res.Resources;

import hpsaturn.pollutionreporter.R;

/**
Expand All @@ -18,14 +21,14 @@ public static PickerFragmentData get() {
private PickerFragmentData() {
}

public List<PickerFragmentInfo> getFragmentsInfo() {

public List<PickerFragmentInfo> getFragmentsInfo(Context ctx) {
Resources res = ctx.getResources();
return Arrays.asList(
new PickerFragmentInfo("Reports", R.drawable.ic_picker_map),
new PickerFragmentInfo("Public", R.drawable.ic_picker_cloud),
new PickerFragmentInfo("MyDevice", R.drawable.ic_picker_chart),
new PickerFragmentInfo("MyRecords", R.drawable.ic_picker_records),
new PickerFragmentInfo("Settings", R.drawable.ic_picker_settings)
new PickerFragmentInfo(res.getString(R.string.title_icon_map), R.drawable.ic_picker_map),
new PickerFragmentInfo(res.getString(R.string.title_icon_reports), R.drawable.ic_picker_cloud),
new PickerFragmentInfo(res.getString(R.string.title_icon_mydevice), R.drawable.ic_picker_chart),
new PickerFragmentInfo(res.getString(R.string.title_icon_myrecords), R.drawable.ic_picker_records),
new PickerFragmentInfo(res.getString(R.string.title_icon_settings), R.drawable.ic_picker_settings)
);

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle sa
View view = inflater.inflate(R.layout.fragment_records, container, false);
mEmptyMessage = view.findViewById(R.id.tv_records_empty_list);
mRecordsList = view.findViewById(R.id.rv_records);
mEmptyMessage.setText(R.string.msg_not_public_recors);
mEmptyMessage.setText(R.string.msg_not_public_records);

LinearLayoutManager mManager = new LinearLayoutManager(getActivity());
mManager.setReverseLayout(true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,8 @@ void printResponseConfig(ResponseConfig config) {
Logger.i(TAG, "[Config] vtag : " + config.vtag);
Logger.i(TAG, "[Config] lskey : " + config.lskey);
Logger.i(TAG, "[Config] toffset : " + config.toffset);
Logger.i(TAG, "[Config] sse : " + config.sse);
Logger.i(TAG, "[Config] dstime: " + config.deepSleep);
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@

import com.fonfon.geohash.GeoHash;
import com.google.firebase.crashlytics.FirebaseCrashlytics;
import com.google.firebase.crashlytics.internal.model.CrashlyticsReport;
import com.hpsaturn.tools.Logger;
import com.hpsaturn.tools.UITools;
import com.iamhabib.easy_preference.EasyPreference;
Expand Down Expand Up @@ -329,7 +328,7 @@ private void updateLocationSummary(Location location, String geoHash) {
else if (geoHash.length() >=2 ) {
try {
summary = summary + geoHash;
ifxdbSwitch.setSummary(R.string.key_enable_ifx_summary_ready);
ifxdbSwitch.setSummary(R.string.summary_key_enable_ifx_ready);
EasyPreference.Builder prefBuilder = AppData.getPrefBuilder(getContext());
String name = geoHash.substring(0,3);
String flavor = prefBuilder.getString(Keys.DEVICE_FLAVOR,"");
Expand All @@ -339,7 +338,7 @@ else if (geoHash.length() >=2 ) {
name = name.replace("_","");
name = name.replace(":","");
name = name.toUpperCase();
name = getString(R.string.fixed_stations_map_summary)+"\nYour station: "+name;
name = getString(R.string.summary_fixed_stations_map)+"\nYour station: "+name;
updateSummary(R.string.key_fixed_stations_map,name);
} catch (Exception e) {
EasyPreference.Builder prefBuilder = AppData.getPrefBuilder(getContext());
Expand Down
Loading

0 comments on commit d2232cf

Please sign in to comment.