From 466d03a38cb01e9ff9a2d11be113a81c2bdce34a Mon Sep 17 00:00:00 2001 From: Daniel Weipert Date: Thu, 25 Jan 2024 20:40:16 +0100 Subject: initial commit --- mobile/app/gallery-view-model.ts | 51 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 mobile/app/gallery-view-model.ts (limited to 'mobile/app/gallery-view-model.ts') diff --git a/mobile/app/gallery-view-model.ts b/mobile/app/gallery-view-model.ts new file mode 100644 index 0000000..e15839a --- /dev/null +++ b/mobile/app/gallery-view-model.ts @@ -0,0 +1,51 @@ +import { AndroidActivityRequestPermissionsEventData, Application, Observable, Utils } from '@nativescript/core'; + +export class GalleryModel extends Observable { + constructor() { + super(); + } + + peng() { + const check = function () { + return new Promise((resolve, reject) => { + (Application.android.foregroundActivity || Application.android.startActivity).requestPermissions([ + android.Manifest.permission.READ_EXTERNAL_STORAGE, + ], 1337); + function onActivityResult(args) { + if (args.requestCode === 1337) { + Application.android.off(Application.android.activityRequestPermissionsEvent, onActivityResult); + console.log(args); + console.log(args.grantResults); + resolve(args); + } + } + Application.android.on(Application.android.activityRequestPermissionsEvent, onActivityResult); + }); + } + + + check().then(() => { + console.log('query'); + const cursor = Utils.android.getApplicationContext().getContentResolver().query( + android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI, + [ + android.provider.MediaStore.Images.ImageColumns._ID, + android.provider.MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, + android.provider.MediaStore.Images.ImageColumns.DATE_TAKEN, + ], + '1) GROUP BY (' + android.provider.MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME, + null, + null + ); + + console.log(cursor, cursor.getCount()); + if (cursor) { + console.log(cursor.moveToFirst()); + + const bucketColumn = cursor.getColumnIndex(android.provider.MediaStore.Images.ImageColumns.BUCKET_DISPLAY_NAME); + console.log(bucketColumn); + // console.log(cursor.getString(bucketColumn)); + } + }); + } +} -- cgit v1.2.3