Skip to content

Commit

Permalink
Merge pull request #376 from enviroCar/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
dewall authored Nov 22, 2019
2 parents c2bddd0 + 22d1398 commit 65572ad
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 63 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ ext {
compileSdkVersion = 28
targetSdkVersion = 28
buildToolsVersion = '28.0.3'
versionCode = 35
versionName = "1.0.0"
versionCode = 37
versionName = "1.0.1"

javaCompileVersion = JavaVersion.VERSION_1_8

Expand Down
4 changes: 2 additions & 2 deletions org.envirocar.app/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
xmlns:tools="http://schemas.android.com/tools"
package="org.envirocar.app"
android:installLocation="internalOnly"
android:versionCode="36"
android:versionName="1.0.0">
android:versionCode="37"
android:versionName="1.0.1">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down
2 changes: 2 additions & 0 deletions org.envirocar.app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ dependencies {
implementation rootProject.ext.rxBindingCore
implementation rootProject.ext.rxBindingAppCompat

implementation 'pub.devrel:easypermissions:3.0.0'

//implementation rootProject.ext.guava
// implementation(materialDialogs) {
// exclude module: 'appcompat-v7'
Expand Down
5 changes: 5 additions & 0 deletions org.envirocar.app/res/values-de/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,9 @@
<string name="notification_autorecording_gps_disabled_subtext">GPS ist deaktiviert. Bitte aktivieren Sie Ihr GPS.</string>
<string name="notification_autorecording_bluetooth_disabled_subtext">Bluetooth ist deaktiviert. Bitte aktivieren Sie Ihr Bluetooth.</string>

<!-- ################# -->
<!-- Permissions -->
<!-- ################# -->
<string name="permissions_request_dialog">Die enviroCar App benötigt für die Aufzeichnung von Fahrten weitere Berechtigung, die Sie im Folgenden manuell bestätigen können. Hierzu gehört zum einem die genaue Positionsbestimmung des Smartphones, damit gesammelte Parameter einer Fahrt im Raum verortet werden können, und zum anderen die Schreibberechtigung auf den externen Speicher, damit Logs generiert und im Falle von Fehlverhalten durch die Funktion "Problem melden" an uns übermittelt werden können. </string>

</resources>
6 changes: 6 additions & 0 deletions org.envirocar.app/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -165,4 +165,10 @@
<string name="notification_autorecording_no_car_selected_subtext">No car selected. Please go to the Car selection and select one.</string>
<string name="notification_autorecording_gps_disabled_subtext">GPS is disabled. Please activate your GPS.</string>
<string name="notification_autorecording_bluetooth_disabled_subtext">Bluetooth is disabled. Please activate your Bluetooth.</string>


<!-- ################# -->
<!-- Permissions -->
<!-- ################# -->
<string name="permissions_request_dialog">The enviroCar App requires additional permissions for recording tracks, which you can confirm manually in the following. This includes the exact positioning of the smartphone, so that collected parameters of a journey can be spatially located, and the write permission to the external memory, so that logs can be generated and transmitted via the "Report issue" function.</string>
</resources>
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* Copyright (C) 2013 - 2019 the enviroCar community
* <p>
*
* This file is part of the enviroCar app.
* <p>
*
* The enviroCar app is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
*
* The enviroCar app is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
* <p>
*
* You should have received a copy of the GNU General Public License along
* with the enviroCar app. If not, see http://www.gnu.org/licenses/.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
/**
* Copyright (C) 2013 - 2019 the enviroCar community
* <p>
*
* This file is part of the enviroCar app.
* <p>
*
* The enviroCar app is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* <p>
*
* The enviroCar app is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
* <p>
*
* You should have received a copy of the GNU General Public License along
* with the enviroCar app. If not, see http://www.gnu.org/licenses/.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright (C) 2013 - 2019 the enviroCar community
*
* This file is part of the enviroCar app.
*
* The enviroCar app is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The enviroCar app is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the enviroCar app. If not, see http://www.gnu.org/licenses/.
*/
package org.envirocar.app.interactor;

import android.app.Activity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
/**
* Copyright (C) 2013 - 2019 the enviroCar community
*
* This file is part of the enviroCar app.
*
* The enviroCar app is free software: you can redistribute it and/or
* modify it under the terms of the GNU General Public License as published
* by the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* The enviroCar app is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
* Public License for more details.
*
* You should have received a copy of the GNU General Public License along
* with the enviroCar app. If not, see http://www.gnu.org/licenses/.
*/
package org.envirocar.app.interactor;

import android.app.Activity;
Expand Down
80 changes: 48 additions & 32 deletions org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@
*/
package org.envirocar.app.views;

import android.Manifest;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.view.WindowManager;

import androidx.annotation.NonNull;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;

Expand Down Expand Up @@ -57,24 +57,30 @@
import org.envirocar.core.logging.Logger;
import org.envirocar.core.utils.ServiceUtils;

import java.util.List;

import javax.inject.Inject;

import butterknife.BindView;
import butterknife.ButterKnife;
import io.reactivex.Observable;
import io.reactivex.Scheduler;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.CompositeDisposable;
import io.reactivex.observers.DisposableObserver;
import io.reactivex.schedulers.Schedulers;
import pub.devrel.easypermissions.AfterPermissionGranted;
import pub.devrel.easypermissions.EasyPermissions;
import pub.devrel.easypermissions.PermissionRequest;

/**
* @authro dewall
*/
public class BaseMainActivity extends BaseInjectorActivity {
public class BaseMainActivity extends BaseInjectorActivity implements EasyPermissions.PermissionCallbacks {
private static final Logger LOGGER = Logger.getLogger(BaseMainActivity.class);

private static final String TROUBLESHOOTING_TAG = "TROUBLESHOOTING";
private static final String[] LOCATION_AND_WRITE = {Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.WRITE_EXTERNAL_STORAGE};
private static final int RC_LOCATION_AND_WRITE_PERM = 124;


// Injected variables
@Inject
Expand Down Expand Up @@ -193,11 +199,17 @@ public void onReceive(Context context, Intent intent) {
registerReceiver(errorInformationReceiver, new IntentFilter(TroubleshootingFragment.INTENT));
}

@Override
protected void onStart() {
super.onStart();
checkPermissions();
}

private DisposableObserver<Boolean> handleTermsOfUseValidation() {
return new DisposableObserver<Boolean>() {
@Override
public void onNext(Boolean aBoolean) {
LOGGER.info("Wurst " + aBoolean);
LOGGER.info("accepted? " + aBoolean);
}

@Override
Expand All @@ -207,7 +219,7 @@ public void onError(Throwable e) {

@Override
public void onComplete() {
LOGGER.info("Wurst onComplete");
LOGGER.info("onComplete");
}
};
}
Expand All @@ -217,11 +229,6 @@ protected void onPause() {
LOGGER.info("BaseMainActivity : onPause");
super.onPause();
this.paused = false;

//first init
firstInit();

// checkKeepScreenOn();
}

@Override
Expand All @@ -236,17 +243,6 @@ protected void onResume() {
super.onResume();
// Check whether the screen is required to keep the screen on.
checkKeepScreenOn();

// Observable.just(true)
// .filter(bool -> mUserManager.isLoggedIn())
// .compose(new AgreementManager.TermsOfUseValidator<>(agreementManager, this))
// .observeOn(AndroidSchedulers.mainThread())
// .subscribeOn(Schedulers.io())
// .doOnNext(bool -> {
// LOGGER.info("SUCCESSFUL");
// })
// .doOnError(LOGGER::error)
// .subscribe();
}

@Override
Expand All @@ -262,17 +258,13 @@ protected void onDestroy() {
}
}

private void firstInit() {
SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this);
if (!preferences.contains("first_init")) {

SharedPreferences.Editor e = preferences.edit();
e.putString("first_init", "seen");
e.putBoolean("pref_privacy", true);
e.commit();
}
@Override
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
EasyPermissions.onRequestPermissionsResult(requestCode, permissions, grantResults, this);
}


private void addPreferenceSubscriptions() {
// Keep screen active setting;
subscriptions.add(
Expand Down Expand Up @@ -339,4 +331,28 @@ private void showSnackbar(int infoRes) {
private void showSnackbar(String info) {
Snackbar.make(navigationBottomBar, info, Snackbar.LENGTH_LONG).show();
}


@AfterPermissionGranted(RC_LOCATION_AND_WRITE_PERM)
public void checkPermissions() {
if (EasyPermissions.hasPermissions(this, LOCATION_AND_WRITE)) {
LOGGER.info("Application has location and write permissions!");
} else {
EasyPermissions.requestPermissions(
new PermissionRequest.Builder(this, RC_LOCATION_AND_WRITE_PERM, LOCATION_AND_WRITE)
.setRationale(R.string.permissions_request_dialog)
.setPositiveButtonText(R.string.ok)
.build());
}
}

@Override
public void onPermissionsGranted(int requestCode, @NonNull List<String> perms) {
LOGGER.info("Permission Granted: " + requestCode + ": " + perms.size());
}

@Override
public void onPermissionsDenied(int requestCode, @NonNull List<String> perms) {
LOGGER.info("Permission Denied: " + requestCode + ": " + perms.size());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

import butterknife.ButterKnife;
import io.reactivex.Completable;
import io.reactivex.disposables.Disposable;

/**
* @author dewall
Expand All @@ -37,10 +38,12 @@ public class SplashScreenActivity extends Activity {
private static final Logger LOG = Logger.getLogger(SplashScreenActivity.class);
private static final String HAS_BEEN_SEEN_KEY = "has_been_seen";

private Disposable timerDisposable;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
if(savedInstanceState != null && savedInstanceState.getBoolean(HAS_BEEN_SEEN_KEY, false)){
if (savedInstanceState != null && savedInstanceState.getBoolean(HAS_BEEN_SEEN_KEY, false)) {
startMainActivity();
return;
}
Expand All @@ -53,8 +56,25 @@ protected void onCreate(Bundle savedInstanceState) {
finish();
return;
}
}

Completable.timer(2000, TimeUnit.MILLISECONDS).subscribe(() -> startMainActivity());
@Override
protected void onResume() {
super.onResume();

// register a timer for starting the main activity
timerDisposable = Completable.timer(2000, TimeUnit.MILLISECONDS)
.subscribe(() -> startMainActivity());
}

@Override
protected void onStop() {
super.onStop();

// remove the timer for starting the main activity
if (timerDisposable != null && !timerDisposable.isDisposed()) {
timerDisposable.dispose();
}
}

@Override
Expand All @@ -64,7 +84,7 @@ protected void onSaveInstanceState(Bundle outState) {
outState.putBoolean(HAS_BEEN_SEEN_KEY, true);
}

private void startMainActivity(){
private void startMainActivity() {
Intent intent = new Intent(this, BaseMainActivity.class);
this.startActivity(intent);
finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -221,10 +221,10 @@ public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup c
RxToolbar.itemClicks(this.toolbar).subscribe(this::onToolbarItemClicked);

//
PermissionUtils.requestLocationPermissionIfRequired(getActivity())
.doOnComplete(() -> LOG.info("Accepted"))
.doOnError(LOG::error)
.subscribe();
// PermissionUtils.requestLocationPermissionIfRequired(getActivity())
// .doOnComplete(() -> LOG.info("Accepted"))
// .doOnError(LOG::error)
// .subscribe();

//
this.updateUserLogin(userHandler.getUser());
Expand Down
Loading

0 comments on commit 65572ad

Please sign in to comment.