enhance(capacitor): add native datepicker

This commit is contained in:
charlie
2025-05-16 17:08:42 +08:00
parent 5cbd2a4ae5
commit ed8e7d9daf
9 changed files with 47 additions and 45 deletions

View File

@@ -1,5 +1,8 @@
apply plugin: 'com.android.application'
apply from: 'capacitor.build.gradle'
apply plugin: 'kotlin-android'
android {
namespace "com.logseq.app"
compileSdkVersion rootProject.ext.compileSdkVersion
@@ -11,8 +14,8 @@ android {
versionName "0.11.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
// Default: https://android.googlesource.com/platform/frameworks/base/+/282e181b58cf72b6ca770dc7ca5f91f135444502/tools/aapt/AaptAssets.cpp#61
ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
}
}
@@ -22,10 +25,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
kotlinOptions {
jvmTarget = '21'
}
}
repositories {
flatDir{
flatDir {
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
}
}
@@ -43,13 +50,11 @@ dependencies {
implementation project(':capacitor-cordova-android-plugins')
}
apply from: 'capacitor.build.gradle'
try {
def servicesJSON = file('google-services.json')
if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services'
}
} catch(Exception e) {
} catch (Exception e) {
logger.warn("google-services.json not found, google-services plugin not applied. Push Notifications won't work")
}

View File

@@ -1,14 +1,15 @@
// DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
android {
compileOptions {
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21
}
}
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies {
implementation 'androidx.core:core-ktx:1.16.0'
implementation project(':capacitor-action-sheet')
implementation project(':capacitor-app')
implementation project(':capacitor-camera')
@@ -21,7 +22,6 @@ dependencies {
implementation project(':capacitor-status-bar')
implementation project(':capawesome-capacitor-background-task')
implementation project(':capgo-capacitor-navigation-bar')
implementation project(':logseq-capacitor-file-sync')
implementation project(':capacitor-voice-recorder')
implementation project(':send-intent')
implementation project(':jcesarmobile-ssl-skip')
@@ -30,5 +30,5 @@ dependencies {
if (hasProperty('postBuildExtras')) {
postBuildExtras()
postBuildExtras()
}

View File

@@ -47,10 +47,6 @@
"pkg": "@capgo/capacitor-navigation-bar",
"classpath": "ee.forgr.capacitor_navigation_bar.NavigationBarPlugin"
},
{
"pkg": "@logseq/capacitor-file-sync",
"classpath": "com.logseq.app.filesync.FileSyncPlugin"
},
{
"pkg": "capacitor-voice-recorder",
"classpath": "com.tchvu3.capacitorvoicerecorder.VoiceRecorder"

View File

@@ -13,7 +13,8 @@ public class MainActivity extends BridgeActivity {
@Override
public void onCreate(Bundle savedInstanceState) {
registerPlugin(FolderPicker.class);
registerPlugin(FsWatcher.class);
registerPlugin(UILocal.class);
super.onCreate(savedInstanceState);
new Timer().schedule(new TimerTask() {
@@ -27,7 +28,6 @@ public class MainActivity extends BridgeActivity {
});
}
}, 5000);
}
@Override
@@ -51,6 +51,4 @@ public class MainActivity extends BridgeActivity {
});
}
}
}

View File

@@ -2,6 +2,9 @@
buildscript {
ext {
kotlin_version = '2.1.21'
}
repositories {
google()
jcenter()
@@ -10,6 +13,7 @@ buildscript {
dependencies {
classpath 'com.android.tools.build:gradle:8.7.2'
classpath 'com.google.gms:google-services:4.4.2'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files

View File

@@ -38,9 +38,6 @@ project(':capawesome-capacitor-background-task').projectDir = new File('../node_
include ':capgo-capacitor-navigation-bar'
project(':capgo-capacitor-navigation-bar').projectDir = new File('../node_modules/@capgo/capacitor-navigation-bar/android')
include ':logseq-capacitor-file-sync'
project(':logseq-capacitor-file-sync').projectDir = new File('../node_modules/@logseq/capacitor-file-sync/android')
include ':capacitor-voice-recorder'
project(':capacitor-voice-recorder').projectDir = new File('../node_modules/capacitor-voice-recorder/android')

View File

@@ -1,16 +1,14 @@
import { CapacitorConfig } from '@capacitor/cli'
import fs from 'fs'
import * as fs from 'fs'
const version = fs.readFileSync('static/package.json', 'utf8').match(/"version": "(.*?)"/)?.at(1) ?? '0.0.0'
const config: CapacitorConfig = {
appId: 'com.logseq.app',
appName: 'Logseq',
bundledWebRuntime: false,
webDir: 'public',
loggingBehavior: 'debug',
server: {
// https://capacitorjs.com/docs/updating/5-0#update-androidscheme
androidScheme: 'http',
},
plugins: {
@@ -38,11 +36,6 @@ const config: CapacitorConfig = {
ios: {
scheme: 'Logseq',
appendUserAgent: `Logseq/${version} (iOS)`
},
cordova: {
staticPlugins: [
'@logseq/capacitor-file-sync', // AgeEncryption requires static link
]
}
}

View File

@@ -19,6 +19,7 @@
[frontend.db.utils :as db-util]
[frontend.date :as frontend-date]
[frontend.handler.repo :as repo-handler]
[frontend.mobile.util :as mobile-util]
[goog.date :as gdate]
[logseq.db :as ldb]
[capacitor.pages.settings :as settings]))
@@ -204,19 +205,26 @@
(ionic/ion-button
{:size "small" :fill "clear"
:on-click (fn []
(ui/open-modal!
(fn [{:keys [close!]}]
(ionic/ion-datetime
{:presentation "date"
:onIonChange (fn [^js e]
(let [val (.-value (.-detail e))]
(let [page-name (frontend-date/journal-name (gdate/Date. (js/Date. val)))
nav-to-journal! #(pages-util/nav-to-block! % {:reload-pages! (fn [] ())})]
(if-let [journal (handler/local-page page-name)]
(nav-to-journal! journal)
(-> (handler/<create-page! page-name)
(p/then #(nav-to-journal! (handler/local-page page-name)))))
(close!))))}))))}
(let [apply-date! (fn [date]
(let [page-name (frontend-date/journal-name (gdate/Date. (js/Date. date)))
nav-to-journal! #(pages-util/nav-to-block! % {:reload-pages! (fn [] ())})]
(if-let [journal (handler/local-page page-name)]
(nav-to-journal! journal)
(-> (handler/<create-page! page-name)
(p/then #(nav-to-journal! (handler/local-page page-name)))))))]
(if (mobile-util/native-android?)
(-> (.showDatePicker mobile-util/ui-local)
(p/then (fn [^js e] (some-> e (.-value) (apply-date!)))))
(ui/open-modal!
(fn [{:keys [close!]}]
(ionic/ion-datetime
{:presentation "date"
:onIonChange (fn [^js e]
(let [val (.-value (.-detail e))]
(apply-date! val)
(close!)))}))))))}
[:span {:slot "icon-only"} (ionic/tabler-icon "calendar-month" {:size 22})])
(ionic/ion-button {:fill "clear"}
@@ -224,7 +232,7 @@
{:routerDirection "forward"
:class "w-full"
:component settings/page}
(ionic/tabler-icon "dots-circle-horizontal" {:size 24}))))))
[:span {:slot "icon-only"} (ionic/tabler-icon "dots-circle-horizontal" {:size 24})])))))
;; main content
(if db-restoring?

View File

@@ -22,6 +22,7 @@
(.convertFileSrc Capacitor path-str))
(defonce folder-picker (registerPlugin "FolderPicker"))
(defonce ui-local (registerPlugin "UILocal"))
(when (native-ios?)
(defonce ios-utils (registerPlugin "Utils")))