Skip to content

Commit

Permalink
com.guolindev.permissionx:permissionx replacing com.github.tbruyelle:…
Browse files Browse the repository at this point in the history
…rxpermissions
  • Loading branch information
federicoiosue committed Aug 23, 2024
1 parent 5ef4455 commit 1217aff
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 49 deletions.
4 changes: 1 addition & 3 deletions omniNotes/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,7 @@ dependencies {
implementation 'org.apache.commons:commons-lang3:3.9'
implementation 'com.pnikosis:materialish-progress:1.5'
implementation 'com.github.paolorotolo:appintro:1.3.0'
// implementation 'io.reactivex.rxjava3:rxandroid:3.0.2'
// implementation 'io.reactivex.rxjava3:rxjava:3.1.5'
implementation 'com.github.tbruyelle:rxpermissions:0.12'
implementation 'com.guolindev.permissionx:permissionx:1.8.0'
implementation 'org.ocpsoft.prettytime:prettytime:3.2.7.Final'
implementation 'org.bitbucket.cowwoc:diff-match-patch:1.2'
implementation 'com.github.bosphere.android-filelogger:filelogger:1.0.7'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -718,7 +718,7 @@ private void initViewLocation() {

private void getLocation(OnGeoUtilResultListener onGeoUtilResultListener) {
PermissionsHelper
.requestPermission(getActivity(), Manifest.permission.ACCESS_FINE_LOCATION, R.string
.requestPermission(this, Manifest.permission.ACCESS_FINE_LOCATION, R.string
.permission_coarse_location, binding.snackbarPlaceholder,
() -> GeocodeHelper.getLocation(onGeoUtilResultListener));
}
Expand Down Expand Up @@ -1326,7 +1326,7 @@ private void takePhoto() {
return;
}

PermissionsHelper.requestPermission(getActivity(), CAMERA,
PermissionsHelper.requestPermission(this, CAMERA,
R.string.permission_camera, binding.snackbarPlaceholder, () -> {
// Checks for created file validity
File f = StorageHelper.createNewAttachmentFile(mainActivity, MIME_TYPE_IMAGE_EXT);
Expand All @@ -1349,7 +1349,7 @@ private void takeVideo() {
return;
}

PermissionsHelper.requestPermission(getActivity(), CAMERA,
PermissionsHelper.requestPermission(this, CAMERA,
R.string.permission_camera, binding.snackbarPlaceholder, () -> {
// File is stored in custom ON folder to speedup the attachment
var f = StorageHelper.createNewAttachmentFile(mainActivity, MIME_TYPE_VIDEO_EXT);
Expand Down Expand Up @@ -1795,7 +1795,7 @@ private void stopPlaying() {
}

private void startRecording(View v) {
PermissionsHelper.requestPermission(getActivity(), Manifest.permission.RECORD_AUDIO,
PermissionsHelper.requestPermission(this, Manifest.permission.RECORD_AUDIO,
R.string.permission_audio_recording, binding.snackbarPlaceholder, () -> {

isRecording = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ public void onResume() {
enableFileLogging.setOnPreferenceChangeListener((preference, newValue) -> {
if ((Boolean) newValue) {
PermissionsHelper
.requestPermission(getActivity(), permission.WRITE_EXTERNAL_STORAGE, R
.requestPermission(this, permission.WRITE_EXTERNAL_STORAGE, R
.string.permission_external_storage,
getActivity().findViewById(R.id.crouton_handle),
() -> enableFileLogging.setChecked(true));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,37 @@
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_INDEFINITE;
import static com.google.android.material.snackbar.BaseTransientBottomBar.LENGTH_LONG;

import android.app.Activity;
import android.os.Build.VERSION_CODES;
import android.view.View;
import androidx.core.app.ActivityCompat;
import androidx.core.content.ContextCompat;
import androidx.fragment.app.Fragment;
import com.google.android.material.snackbar.Snackbar;
import com.tbruyelle.rxpermissions.RxPermissions;
import com.permissionx.guolindev.PermissionX;
import it.feio.android.omninotes.R;
import it.feio.android.omninotes.models.listeners.OnPermissionRequestedListener;
import lombok.experimental.UtilityClass;

@UtilityClass
public class PermissionsHelper {

public static void requestPermission(Activity activity, String permission,
int rationaleDescription, View messageView, OnPermissionRequestedListener onPermissionRequestedListener) {
public static void requestPermission(Fragment fragment, String permission,
int rationaleDescription, View messageView,
OnPermissionRequestedListener onPermissionRequestedListener) {

if (skipPermissionRequest(permission)) {
onPermissionRequestedListener.onPermissionGranted();
return;
}

if (ContextCompat.checkSelfPermission(activity, permission) != PERMISSION_GRANTED) {

if (ActivityCompat.shouldShowRequestPermissionRationale(activity, permission)) {
if (ContextCompat.checkSelfPermission(fragment.getActivity(), permission) != PERMISSION_GRANTED) {
if (ActivityCompat.shouldShowRequestPermissionRationale(fragment.getActivity(), permission)) {
Snackbar.make(messageView, rationaleDescription, LENGTH_INDEFINITE)
.setAction(R.string.ok, view -> requestPermissionExecute(activity, permission,
.setAction(R.string.ok, view -> requestPermissionExecute(fragment, permission,
onPermissionRequestedListener, messageView))
.show();
} else {
requestPermissionExecute(activity, permission, onPermissionRequestedListener, messageView);
requestPermissionExecute(fragment, permission, onPermissionRequestedListener, messageView);
}
} else {
if (onPermissionRequestedListener != null) {
Expand All @@ -65,15 +65,15 @@ private static boolean skipPermissionRequest(String permission) {
return BuildHelper.isAbove(VERSION_CODES.Q) && permission.equals(WRITE_EXTERNAL_STORAGE);
}

private static void requestPermissionExecute(Activity activity, String permission,
private static void requestPermissionExecute(Fragment fragment, String permission,
OnPermissionRequestedListener onPermissionRequestedListener, View messageView) {
RxPermissions.getInstance(activity)
.request(permission)
.subscribe(granted -> {
if (Boolean.TRUE.equals(granted) && onPermissionRequestedListener != null) {
PermissionX.init(fragment)
.permissions(permission)
.request((allGranted, grantedList, deniedList) -> {
if (allGranted) {
onPermissionRequestedListener.onPermissionGranted();
} else {
var msg = activity.getString(R.string.permission_not_granted) + ": " + permission;
var msg = fragment.getString(R.string.permission_not_granted) + ": " + permission;
Snackbar.make(messageView, msg, LENGTH_LONG).show();
}
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import android.text.TextUtils;
import io.nlopez.smartlocation.SmartLocation;
import io.nlopez.smartlocation.location.config.LocationParams;
import io.nlopez.smartlocation.rx.ObservableFactory;
import it.feio.android.omninotes.OmniNotes;
import it.feio.android.omninotes.helpers.LogDelegate;
import it.feio.android.omninotes.models.listeners.OnGeoUtilResultListener;
Expand All @@ -45,13 +44,10 @@
import java.util.Collections;
import java.util.List;
import java.util.Locale;
import java.util.concurrent.TimeUnit;
import java.util.regex.Pattern;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import rx.Observable;
import rx.Subscriber;


public class GeocodeHelper implements LocationListener {
Expand Down Expand Up @@ -86,33 +82,21 @@ public void onProviderDisabled(String provider) {


public static void getLocation(OnGeoUtilResultListener onGeoUtilResultListener) {
SmartLocation.LocationControl bod = SmartLocation.with(OmniNotes.getAppContext())
SmartLocation.LocationControl bod = SmartLocation.with(OmniNotes.getAppContext())
.location(getProvider(OmniNotes.getAppContext()))
.config(LocationParams.NAVIGATION).oneFix();

Observable<Location> locations = ObservableFactory.from(bod).timeout(2, TimeUnit.SECONDS);
locations.subscribe(new Subscriber<>() {
@Override
public void onNext(Location location) {
onGeoUtilResultListener.onLocationRetrieved(location);
unsubscribe();
}

@Override
public void onCompleted() {
// Nothing to do
}
var location = bod.oneFix().getLastLocation();

@Override
public void onError(Throwable e) {
if(checkHighAccuracyLocationProvider(OmniNotes.getAppContext()) == true) {
onGeoUtilResultListener.onLocationUnavailable();
}else{
onGeoUtilResultListener.onLocationNotEnabled();
}
unsubscribe();
if (location != null) {
onGeoUtilResultListener.onLocationRetrieved(location);
} else {
if (checkHighAccuracyLocationProvider(OmniNotes.getAppContext())) {
onGeoUtilResultListener.onLocationUnavailable();
} else {
onGeoUtilResultListener.onLocationNotEnabled();
}
});
}
}


Expand Down

0 comments on commit 1217aff

Please sign in to comment.