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 plugin: 'com.android.application'
apply from: 'capacitor.build.gradle'
apply plugin: 'kotlin-android'
android { android {
namespace "com.logseq.app" namespace "com.logseq.app"
compileSdkVersion rootProject.ext.compileSdkVersion compileSdkVersion rootProject.ext.compileSdkVersion
@@ -11,8 +14,8 @@ android {
versionName "0.11.0" versionName "0.11.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions { aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps. // 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 // 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:!*~' ignoreAssetsPattern '!.svn:!.git:!.ds_store:!*.scc:.*:!CVS:!thumbs.db:!picasa.ini:!*~'
} }
} }
@@ -22,10 +25,14 @@ android {
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
} }
} }
kotlinOptions {
jvmTarget = '21'
}
} }
repositories { repositories {
flatDir{ flatDir {
dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs' dirs '../capacitor-cordova-android-plugins/src/main/libs', 'libs'
} }
} }
@@ -43,13 +50,11 @@ dependencies {
implementation project(':capacitor-cordova-android-plugins') implementation project(':capacitor-cordova-android-plugins')
} }
apply from: 'capacitor.build.gradle'
try { try {
def servicesJSON = file('google-services.json') def servicesJSON = file('google-services.json')
if (servicesJSON.text) { if (servicesJSON.text) {
apply plugin: 'com.google.gms.google-services' 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") 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 // DO NOT EDIT THIS FILE! IT IS GENERATED EACH TIME "capacitor update" IS RUN
android { android {
compileOptions { compileOptions {
sourceCompatibility JavaVersion.VERSION_21 sourceCompatibility JavaVersion.VERSION_21
targetCompatibility JavaVersion.VERSION_21 targetCompatibility JavaVersion.VERSION_21
} }
} }
apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle" apply from: "../capacitor-cordova-android-plugins/cordova.variables.gradle"
dependencies { dependencies {
implementation 'androidx.core:core-ktx:1.16.0'
implementation project(':capacitor-action-sheet') implementation project(':capacitor-action-sheet')
implementation project(':capacitor-app') implementation project(':capacitor-app')
implementation project(':capacitor-camera') implementation project(':capacitor-camera')
@@ -21,7 +22,6 @@ dependencies {
implementation project(':capacitor-status-bar') implementation project(':capacitor-status-bar')
implementation project(':capawesome-capacitor-background-task') implementation project(':capawesome-capacitor-background-task')
implementation project(':capgo-capacitor-navigation-bar') implementation project(':capgo-capacitor-navigation-bar')
implementation project(':logseq-capacitor-file-sync')
implementation project(':capacitor-voice-recorder') implementation project(':capacitor-voice-recorder')
implementation project(':send-intent') implementation project(':send-intent')
implementation project(':jcesarmobile-ssl-skip') implementation project(':jcesarmobile-ssl-skip')
@@ -30,5 +30,5 @@ dependencies {
if (hasProperty('postBuildExtras')) { if (hasProperty('postBuildExtras')) {
postBuildExtras() postBuildExtras()
} }

View File

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

View File

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

View File

@@ -2,6 +2,9 @@
buildscript { buildscript {
ext {
kotlin_version = '2.1.21'
}
repositories { repositories {
google() google()
jcenter() jcenter()
@@ -10,6 +13,7 @@ buildscript {
dependencies { dependencies {
classpath 'com.android.tools.build:gradle:8.7.2' classpath 'com.android.tools.build:gradle:8.7.2'
classpath 'com.google.gms:google-services:4.4.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 // NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files // 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' include ':capgo-capacitor-navigation-bar'
project(':capgo-capacitor-navigation-bar').projectDir = new File('../node_modules/@capgo/capacitor-navigation-bar/android') 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' include ':capacitor-voice-recorder'
project(':capacitor-voice-recorder').projectDir = new File('../node_modules/capacitor-voice-recorder/android') 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 { 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 version = fs.readFileSync('static/package.json', 'utf8').match(/"version": "(.*?)"/)?.at(1) ?? '0.0.0'
const config: CapacitorConfig = { const config: CapacitorConfig = {
appId: 'com.logseq.app', appId: 'com.logseq.app',
appName: 'Logseq', appName: 'Logseq',
bundledWebRuntime: false,
webDir: 'public', webDir: 'public',
loggingBehavior: 'debug', loggingBehavior: 'debug',
server: { server: {
// https://capacitorjs.com/docs/updating/5-0#update-androidscheme
androidScheme: 'http', androidScheme: 'http',
}, },
plugins: { plugins: {
@@ -38,11 +36,6 @@ const config: CapacitorConfig = {
ios: { ios: {
scheme: 'Logseq', scheme: 'Logseq',
appendUserAgent: `Logseq/${version} (iOS)` 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.db.utils :as db-util]
[frontend.date :as frontend-date] [frontend.date :as frontend-date]
[frontend.handler.repo :as repo-handler] [frontend.handler.repo :as repo-handler]
[frontend.mobile.util :as mobile-util]
[goog.date :as gdate] [goog.date :as gdate]
[logseq.db :as ldb] [logseq.db :as ldb]
[capacitor.pages.settings :as settings])) [capacitor.pages.settings :as settings]))
@@ -204,19 +205,26 @@
(ionic/ion-button (ionic/ion-button
{:size "small" :fill "clear" {:size "small" :fill "clear"
:on-click (fn [] :on-click (fn []
(ui/open-modal! (let [apply-date! (fn [date]
(fn [{:keys [close!]}] (let [page-name (frontend-date/journal-name (gdate/Date. (js/Date. date)))
(ionic/ion-datetime nav-to-journal! #(pages-util/nav-to-block! % {:reload-pages! (fn [] ())})]
{:presentation "date" (if-let [journal (handler/local-page page-name)]
:onIonChange (fn [^js e] (nav-to-journal! journal)
(let [val (.-value (.-detail e))] (-> (handler/<create-page! page-name)
(let [page-name (frontend-date/journal-name (gdate/Date. (js/Date. val))) (p/then #(nav-to-journal! (handler/local-page page-name)))))))]
nav-to-journal! #(pages-util/nav-to-block! % {:reload-pages! (fn [] ())})]
(if-let [journal (handler/local-page page-name)] (if (mobile-util/native-android?)
(nav-to-journal! journal) (-> (.showDatePicker mobile-util/ui-local)
(-> (handler/<create-page! page-name) (p/then (fn [^js e] (some-> e (.-value) (apply-date!)))))
(p/then #(nav-to-journal! (handler/local-page page-name)))))
(close!))))}))))} (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})]) [:span {:slot "icon-only"} (ionic/tabler-icon "calendar-month" {:size 22})])
(ionic/ion-button {:fill "clear"} (ionic/ion-button {:fill "clear"}
@@ -224,7 +232,7 @@
{:routerDirection "forward" {:routerDirection "forward"
:class "w-full" :class "w-full"
:component settings/page} :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 ;; main content
(if db-restoring? (if db-restoring?

View File

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