Skip to content

Commit

Permalink
#805 - Fixing image selection to remove check permission
Browse files Browse the repository at this point in the history
  • Loading branch information
graphefruit committed Oct 18, 2024
1 parent ddde0d5 commit 9dbaa29
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 101 deletions.
5 changes: 4 additions & 1 deletion android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,10 @@
will add that attribute from the Bluetooth LE plugin. -->
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" tools:remove="android:maxSdkVersion" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />



<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
Expand Down
135 changes: 35 additions & 100 deletions src/services/uiImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,53 +75,45 @@ export class UIImage {

public async choosePhoto(): Promise<any> {
const promise = new Promise(async (resolve, reject) => {
this.__checkPermission(
async () => {
setTimeout(async () => {
const fileurls: Array<string> = [];

const results = await Camera.pickImages({
quality: this.getImageQuality(),
});

await this.uiAlert.showLoadingSpinner();

for await (const file of results.photos) {
try {
const imageBase64 = await this.uiFileHelper.readFileAsBase64(
file.path
);

try {
const newUri = await this.saveBase64Photo(imageBase64);
fileurls.push(newUri);
} catch (ex) {}
} catch (ex) {
setTimeout(() => {
this.uiAlert.hideLoadingSpinner();
}, 50);
reject(ex);
}
}
try {
const fileurls: Array<string> = [];

const results = await Camera.pickImages({
quality: this.getImageQuality(),
});

await this.uiAlert.showLoadingSpinner();

for await (const file of results.photos) {
try {
const imageBase64 = await this.uiFileHelper.readFileAsBase64(
file.path
);

try {
const newUri = await this.saveBase64Photo(imageBase64);
fileurls.push(newUri);
} catch (ex) {}
} catch (ex) {
setTimeout(() => {
this.uiAlert.hideLoadingSpinner();
}, 50);
// this.__cleanupCamera();

if (fileurls.length > 0) {
resolve(fileurls);
} else {
reject('We found no file urls');
}
});
},
(_err) => {
setTimeout(() => {
this.uiAlert.hideLoadingSpinner();
}, 50);
reject(_err);
reject(ex);
}
}
setTimeout(() => {
this.uiAlert.hideLoadingSpinner();
}, 50);
// this.__cleanupCamera();

if (fileurls.length > 0) {
resolve(fileurls);
} else {
reject('We found no file urls');
}
);
} catch (ex) {
this.uiAlert.hideLoadingSpinner();
}
});

return promise;
Expand Down Expand Up @@ -153,63 +145,6 @@ export class UIImage {
return promise;
}

private __requestGaleryPermission(_success: any, _error: any): void {
this.androidPermissions
.requestPermissions([
this.androidPermissions.PERMISSION.READ_MEDIA_IMAGES,
])
.then(
(_status) => {
if (_status.hasPermission) {
_success();
} else {
_error();
}
},
() => {
_error();
}
);
}

private __checkPermission(_success: any, _error: any): void {
this.platform.ready().then(() => {
const isCordova: boolean = this.platform.is('capacitor');
const isAndroid: boolean = this.platform.is('android');
if (isCordova && isAndroid) {
this.androidPermissions
.checkPermission(this.androidPermissions.PERMISSION.READ_MEDIA_IMAGES)
.then(
(_status) => {
if (_status.hasPermission === false) {
this.__requestGaleryPermission(_success, _error);
} else {
// We already have permission
_success();
}
},
() => {
this.__requestGaleryPermission(_success, _error);
}
);
} else {
// No need to check for validations
_success();
}
});

/**
* Check if we have permission to read images
* @returns {Promise<boolean>} Returns a promise that resolves with a boolean that indicates whether we have permission
*/
// hasReadPermission(): Promise<boolean>;
/**
* Request permission to read images
* @returns {Promise<any>}
*/
// requestReadPermission(): Promise<any>;
}

public async viewPhotos(
_data:
| Bean
Expand Down

0 comments on commit 9dbaa29

Please sign in to comment.