diff options
author | Daniel Weipert <git@mail.dweipert.de> | 2024-01-25 20:40:16 +0100 |
---|---|---|
committer | Daniel Weipert <git@mail.dweipert.de> | 2024-01-25 20:40:16 +0100 |
commit | 466d03a38cb01e9ff9a2d11be113a81c2bdce34a (patch) | |
tree | d584482d4ed5e9b8fe569af7ce25594c1bd51d63 /mobile/app |
initial commit
Diffstat (limited to 'mobile/app')
-rw-r--r-- | mobile/app/app-root.xml | 2 | ||||
-rw-r--r-- | mobile/app/app.css | 6 | ||||
-rw-r--r-- | mobile/app/app.ts | 14 | ||||
-rw-r--r-- | mobile/app/gallery-page.ts | 7 | ||||
-rw-r--r-- | mobile/app/gallery-page.xml | 7 | ||||
-rw-r--r-- | mobile/app/gallery-view-model.ts | 51 | ||||
-rw-r--r-- | mobile/app/main-page.ts | 7 | ||||
-rw-r--r-- | mobile/app/main-page.xml | 17 | ||||
-rw-r--r-- | mobile/app/main-view-model.ts | 29 |
9 files changed, 140 insertions, 0 deletions
diff --git a/mobile/app/app-root.xml b/mobile/app/app-root.xml new file mode 100644 index 0000000..54e70d9 --- /dev/null +++ b/mobile/app/app-root.xml @@ -0,0 +1,2 @@ +<Frame defaultPage="main-page"> +</Frame> diff --git a/mobile/app/app.css b/mobile/app/app.css new file mode 100644 index 0000000..14de482 --- /dev/null +++ b/mobile/app/app.css @@ -0,0 +1,6 @@ +@import '@nativescript/theme/css/core.css'; +@import '@nativescript/theme/css/default.css'; + +Button.-primary { + font-size: 18; +} diff --git a/mobile/app/app.ts b/mobile/app/app.ts new file mode 100644 index 0000000..1947b6e --- /dev/null +++ b/mobile/app/app.ts @@ -0,0 +1,14 @@ +/* +In NativeScript, the app.ts file is the entry point to your application. +You can use this file to perform app-level initialization, but the primary +purpose of the file is to pass control to the app’s first module. +*/ + +import { Application } from '@nativescript/core'; + +Application.run({ moduleName: 'app-root' }); + +/* +Do not place any code after the application has been started as it will not +be executed on iOS. +*/ diff --git a/mobile/app/gallery-page.ts b/mobile/app/gallery-page.ts new file mode 100644 index 0000000..517ac8a --- /dev/null +++ b/mobile/app/gallery-page.ts @@ -0,0 +1,7 @@ +import { EventData, Page } from '@nativescript/core' +import { GalleryModel } from './gallery-view-model'; + +export function navigatingTo(args: EventData) { + const page = <Page>args.object; + page.bindingContext = new GalleryModel(); +} diff --git a/mobile/app/gallery-page.xml b/mobile/app/gallery-page.xml new file mode 100644 index 0000000..aa545e8 --- /dev/null +++ b/mobile/app/gallery-page.xml @@ -0,0 +1,7 @@ +<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo"> + <ActionBar title="Galleries" icon="" /> + + <StackLayout class="p-20"> + <Button text="peng" tap="{{ peng }}" class="-primary" /> + </StackLayout> +</Page> 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)); + } + }); + } +} diff --git a/mobile/app/main-page.ts b/mobile/app/main-page.ts new file mode 100644 index 0000000..745d6c6 --- /dev/null +++ b/mobile/app/main-page.ts @@ -0,0 +1,7 @@ +import { EventData, Page } from '@nativescript/core' +import { LoginModel } from './main-view-model'; + +export function navigatingTo(args: EventData) { + const page = <Page>args.object; + page.bindingContext = new LoginModel(); +} diff --git a/mobile/app/main-page.xml b/mobile/app/main-page.xml new file mode 100644 index 0000000..03fff55 --- /dev/null +++ b/mobile/app/main-page.xml @@ -0,0 +1,17 @@ +<Page xmlns="http://schemas.nativescript.org/tns.xsd" navigatingTo="navigatingTo"> + <ActionBar title="Image Sync" icon=""> + <ActionItem + text="Galleries" + tap="{{ goToGalleries }}" + /> + </ActionBar> + + <StackLayout class="p-20"> + <Label text="Login" class="h1 text-center" /> + + <TextField hint="Server" text="{{ server }}" class="h2" /> + <TextField hint="Username" text="{{ username }}" class="h2" /> + <TextField hint="Password" text="{{ password }}" secure="true" class="h2" /> + <Button text="Login" tap="{{ onLogin }}" class="-primary" /> + </StackLayout> +</Page> diff --git a/mobile/app/main-view-model.ts b/mobile/app/main-view-model.ts new file mode 100644 index 0000000..714abe1 --- /dev/null +++ b/mobile/app/main-view-model.ts @@ -0,0 +1,29 @@ +import { Frame, Http, Observable } from '@nativescript/core'; + +export class LoginModel extends Observable { + public server: string = 'http://192.168.178.59:8080'; + public username: string; + public password: string; + + constructor() { + super(); + } + + async onLogin() { + const content = new FormData(); + content.append('username', this.username); + content.append('password', this.password); + const response = await Http.request({ + url: this.server, + method: 'POST', + content: content, + }); + + console.log(response.content?.toString()); + } + + goToGalleries() { + const frame = Frame.topmost(); + frame.navigate('gallery-page'); + } +} |