summaryrefslogtreecommitdiff
path: root/mobile-ns/app
diff options
context:
space:
mode:
authorDaniel Weipert <git@mail.dweipert.de>2024-01-26 14:51:36 +0100
committerDaniel Weipert <git@mail.dweipert.de>2024-01-26 14:52:57 +0100
commitd3bf2d09f740221771806789b00bf915c9f5f2e3 (patch)
tree95f99eabd763dff1907f107393504ee75aa747d7 /mobile-ns/app
parent466d03a38cb01e9ff9a2d11be113a81c2bdce34a (diff)
initial commitHEADmain
Diffstat (limited to 'mobile-ns/app')
-rw-r--r--mobile-ns/app/app-root.xml2
-rw-r--r--mobile-ns/app/app.css6
-rw-r--r--mobile-ns/app/app.ts14
-rw-r--r--mobile-ns/app/gallery-page.ts7
-rw-r--r--mobile-ns/app/gallery-page.xml7
-rw-r--r--mobile-ns/app/gallery-view-model.ts65
-rw-r--r--mobile-ns/app/main-page.ts7
-rw-r--r--mobile-ns/app/main-page.xml17
-rw-r--r--mobile-ns/app/main-view-model.ts50
9 files changed, 175 insertions, 0 deletions
diff --git a/mobile-ns/app/app-root.xml b/mobile-ns/app/app-root.xml
new file mode 100644
index 0000000..54e70d9
--- /dev/null
+++ b/mobile-ns/app/app-root.xml
@@ -0,0 +1,2 @@
+<Frame defaultPage="main-page">
+</Frame>
diff --git a/mobile-ns/app/app.css b/mobile-ns/app/app.css
new file mode 100644
index 0000000..14de482
--- /dev/null
+++ b/mobile-ns/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-ns/app/app.ts b/mobile-ns/app/app.ts
new file mode 100644
index 0000000..1947b6e
--- /dev/null
+++ b/mobile-ns/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-ns/app/gallery-page.ts b/mobile-ns/app/gallery-page.ts
new file mode 100644
index 0000000..517ac8a
--- /dev/null
+++ b/mobile-ns/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-ns/app/gallery-page.xml b/mobile-ns/app/gallery-page.xml
new file mode 100644
index 0000000..aa545e8
--- /dev/null
+++ b/mobile-ns/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-ns/app/gallery-view-model.ts b/mobile-ns/app/gallery-view-model.ts
new file mode 100644
index 0000000..f48fe6f
--- /dev/null
+++ b/mobile-ns/app/gallery-view-model.ts
@@ -0,0 +1,65 @@
+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,
+ android.Manifest.permission.READ_CONTACTS,
+ ], 3766);
+ function onActivityResult(args) {
+ if (args.requestCode === 3766) {
+ Application.android.off(Application.android.activityRequestPermissionsEvent, onActivityResult);
+ console.log(args);
+ console.log(args.grantResults);
+ resolve(args);
+ }
+ }
+ Application.android.on(Application.android.activityRequestPermissionsEvent, onActivityResult);
+ });
+ } */
+
+ (Application.android.foregroundActivity || Application.android.startActivity).requestPermissions([
+ android.Manifest.permission.READ_MEDIA_IMAGES,
+ ], 3765);
+ console.log(Application.android.foregroundActivity, Application.android.startActivity);
+ return;
+
+ // 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,
+ ],
+ null,
+ null,
+ );
+
+ const contacts = Utils.android.getApplicationContext().getContentResolver().query(
+ android.provider.Contacts.Phones.CONTENT_URI,
+ [
+ android.provider.Contacts.PhonesColumns.LABEL,
+ android.provider.Contacts.PhonesColumns.TYPE,
+ ],
+ null,
+ null
+ );
+ console.log(contacts, contacts.getCount());
+
+ console.log(cursor, cursor.getCount());
+ if (cursor && 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-ns/app/main-page.ts b/mobile-ns/app/main-page.ts
new file mode 100644
index 0000000..745d6c6
--- /dev/null
+++ b/mobile-ns/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-ns/app/main-page.xml b/mobile-ns/app/main-page.xml
new file mode 100644
index 0000000..03fff55
--- /dev/null
+++ b/mobile-ns/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-ns/app/main-view-model.ts b/mobile-ns/app/main-view-model.ts
new file mode 100644
index 0000000..a354a5d
--- /dev/null
+++ b/mobile-ns/app/main-view-model.ts
@@ -0,0 +1,50 @@
+import { Application, Frame, Http, Observable, Utils } from '@nativescript/core';
+import * as permissions from '@nativescript-community/perms';
+
+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());
+
+ console.log(
+ Application.android.foregroundActivity.requestPermissions([
+ android.Manifest.permission.READ_EXTERNAL_STORAGE,
+ ], 3765)
+ );
+ console.log(
+ Application.android.foregroundActivity.shouldShowRequestPermissionRationale(android.Manifest.permission.READ_EXTERNAL_STORAGE)
+ );
+
+ console.log(
+ Utils.android.getApplicationContext().checkPermission(android.Manifest.permission.READ_EXTERNAL_STORAGE, android.os.Process.myPid(), android.os.Process.myUid())
+ );
+
+ console.log(
+ permissions.request({
+ storage: { read: true, write: false },
+ photo: { reason: 'to pick images' },
+ })
+ );
+ }
+
+ goToGalleries() {
+ const frame = Frame.topmost();
+ frame.navigate('gallery-page');
+ }
+}