diff --git a/build.gradle b/build.gradle index 49f858094..7d4be6169 100644 --- a/build.gradle +++ b/build.gradle @@ -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 diff --git a/org.envirocar.app/AndroidManifest.xml b/org.envirocar.app/AndroidManifest.xml index cccbbe1f7..f4e3985e0 100644 --- a/org.envirocar.app/AndroidManifest.xml +++ b/org.envirocar.app/AndroidManifest.xml @@ -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"> diff --git a/org.envirocar.app/build.gradle b/org.envirocar.app/build.gradle index cb5e4dd8d..903f883d2 100644 --- a/org.envirocar.app/build.gradle +++ b/org.envirocar.app/build.gradle @@ -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' diff --git a/org.envirocar.app/res/values-de/strings.xml b/org.envirocar.app/res/values-de/strings.xml index 9920c9236..09ef13640 100644 --- a/org.envirocar.app/res/values-de/strings.xml +++ b/org.envirocar.app/res/values-de/strings.xml @@ -124,4 +124,9 @@ GPS ist deaktiviert. Bitte aktivieren Sie Ihr GPS. Bluetooth ist deaktiviert. Bitte aktivieren Sie Ihr Bluetooth. + + + + 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. + diff --git a/org.envirocar.app/res/values/strings.xml b/org.envirocar.app/res/values/strings.xml index 15e95f9c4..7b192957b 100644 --- a/org.envirocar.app/res/values/strings.xml +++ b/org.envirocar.app/res/values/strings.xml @@ -165,4 +165,10 @@ No car selected. Please go to the Car selection and select one. GPS is disabled. Please activate your GPS. Bluetooth is disabled. Please activate your Bluetooth. + + + + + + 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. diff --git a/org.envirocar.app/src/org/envirocar/app/handler/TrackUploadHandler.java b/org.envirocar.app/src/org/envirocar/app/handler/TrackUploadHandler.java index c032eebac..5e3672540 100644 --- a/org.envirocar.app/src/org/envirocar/app/handler/TrackUploadHandler.java +++ b/org.envirocar.app/src/org/envirocar/app/handler/TrackUploadHandler.java @@ -1,18 +1,18 @@ /** * 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/. */ diff --git a/org.envirocar.app/src/org/envirocar/app/handler/preferences/UserPreferenceHandler.java b/org.envirocar.app/src/org/envirocar/app/handler/preferences/UserPreferenceHandler.java index 86a289a77..f68762e5a 100644 --- a/org.envirocar.app/src/org/envirocar/app/handler/preferences/UserPreferenceHandler.java +++ b/org.envirocar.app/src/org/envirocar/app/handler/preferences/UserPreferenceHandler.java @@ -1,18 +1,18 @@ /** * 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/. */ diff --git a/org.envirocar.app/src/org/envirocar/app/interactor/UploadAllTracks.java b/org.envirocar.app/src/org/envirocar/app/interactor/UploadAllTracks.java index d3675a61d..dfbd22c22 100644 --- a/org.envirocar.app/src/org/envirocar/app/interactor/UploadAllTracks.java +++ b/org.envirocar.app/src/org/envirocar/app/interactor/UploadAllTracks.java @@ -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; diff --git a/org.envirocar.app/src/org/envirocar/app/interactor/UploadTrack.java b/org.envirocar.app/src/org/envirocar/app/interactor/UploadTrack.java index 937379633..326cd5b6b 100644 --- a/org.envirocar.app/src/org/envirocar/app/interactor/UploadTrack.java +++ b/org.envirocar.app/src/org/envirocar/app/interactor/UploadTrack.java @@ -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; diff --git a/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java b/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java index 37b7291a2..ed7d77e16 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/BaseMainActivity.java @@ -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; @@ -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 @@ -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 handleTermsOfUseValidation() { return new DisposableObserver() { @Override public void onNext(Boolean aBoolean) { - LOGGER.info("Wurst " + aBoolean); + LOGGER.info("accepted? " + aBoolean); } @Override @@ -207,7 +219,7 @@ public void onError(Throwable e) { @Override public void onComplete() { - LOGGER.info("Wurst onComplete"); + LOGGER.info("onComplete"); } }; } @@ -217,11 +229,6 @@ protected void onPause() { LOGGER.info("BaseMainActivity : onPause"); super.onPause(); this.paused = false; - - //first init - firstInit(); - -// checkKeepScreenOn(); } @Override @@ -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 @@ -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( @@ -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 perms) { + LOGGER.info("Permission Granted: " + requestCode + ": " + perms.size()); + } + + @Override + public void onPermissionsDenied(int requestCode, @NonNull List perms) { + LOGGER.info("Permission Denied: " + requestCode + ": " + perms.size()); + } } diff --git a/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java b/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java index 754c07b2d..98a62c48c 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/SplashScreenActivity.java @@ -29,6 +29,7 @@ import butterknife.ButterKnife; import io.reactivex.Completable; +import io.reactivex.disposables.Disposable; /** * @author dewall @@ -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; } @@ -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 @@ -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(); diff --git a/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java b/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java index b30f41f40..8674f593d 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/dashboard/DashboardFragment.java @@ -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()); diff --git a/org.envirocar.app/src/org/envirocar/app/views/settings/SettingsActivity.java b/org.envirocar.app/src/org/envirocar/app/views/settings/SettingsActivity.java index 9983d3128..642412fdd 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/settings/SettingsActivity.java +++ b/org.envirocar.app/src/org/envirocar/app/views/settings/SettingsActivity.java @@ -56,7 +56,6 @@ protected void onCreate(@Nullable Bundle savedInstanceState) { public static class SettingsFragment extends PreferenceFragmentCompat { - private Preference automaticUpload; private Preference automaticRecording; private Preference searchInterval; private Preference enableGPSMode; @@ -73,15 +72,12 @@ public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceStat super.onViewCreated(view, savedInstanceState); // find all preferences - this.automaticUpload = findPreference(getString(R.string.prefkey_always_upload)); this.automaticRecording = findPreference(getString(R.string.prefkey_automatic_recording)); this.searchInterval = findPreference(getString(R.string.prefkey_search_interval)); this.enableGPSMode = findPreference(getString(R.string.prefkey_enable_gps_based_track_recording)); this.gpsTrimDuration = findPreference(getString(R.string.prefkey_track_trim_duration)); this.gpsAutoRecording = findPreference(getString(R.string.prefkey_gps_mode_ar)); - // disable automatic upload for now. - this.automaticUpload.setVisible(false); // set initial state this.searchInterval.setVisible(((CheckBoxPreference) automaticRecording).isChecked()); diff --git a/org.envirocar.app/src/org/envirocar/app/views/tracklist/TrackListLocalCardFragment.java b/org.envirocar.app/src/org/envirocar/app/views/tracklist/TrackListLocalCardFragment.java index f36149306..fffe10a53 100644 --- a/org.envirocar.app/src/org/envirocar/app/views/tracklist/TrackListLocalCardFragment.java +++ b/org.envirocar.app/src/org/envirocar/app/views/tracklist/TrackListLocalCardFragment.java @@ -1,18 +1,18 @@ /** * 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/. */ diff --git a/org.envirocar.core/src/main/java/org/envirocar/core/exception/TrackUploadException.java b/org.envirocar.core/src/main/java/org/envirocar/core/exception/TrackUploadException.java index 660e3f06e..4fe457159 100644 --- a/org.envirocar.core/src/main/java/org/envirocar/core/exception/TrackUploadException.java +++ b/org.envirocar.core/src/main/java/org/envirocar/core/exception/TrackUploadException.java @@ -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.core.exception; import org.envirocar.core.entity.Track; diff --git a/org.envirocar.core/src/main/java/org/envirocar/core/utils/rx/OptionalOrError.java b/org.envirocar.core/src/main/java/org/envirocar/core/utils/rx/OptionalOrError.java index f71f6bcc4..24cfc3c25 100644 --- a/org.envirocar.core/src/main/java/org/envirocar/core/utils/rx/OptionalOrError.java +++ b/org.envirocar.core/src/main/java/org/envirocar/core/utils/rx/OptionalOrError.java @@ -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.core.utils.rx; public class OptionalOrError extends Optional { diff --git a/org.envirocar.storage/src/main/java/org/envirocar/storage/EnviroCarDBImpl.java b/org.envirocar.storage/src/main/java/org/envirocar/storage/EnviroCarDBImpl.java index e94fcac85..94ac95263 100644 --- a/org.envirocar.storage/src/main/java/org/envirocar/storage/EnviroCarDBImpl.java +++ b/org.envirocar.storage/src/main/java/org/envirocar/storage/EnviroCarDBImpl.java @@ -1,18 +1,18 @@ /** * 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/. */