-
-
Notifications
You must be signed in to change notification settings - Fork 82
Expand file tree
/
Copy pathWebdavDataSyncSettings.svelte
More file actions
136 lines (130 loc) · 6.03 KB
/
WebdavDataSyncSettings.svelte
File metadata and controls
136 lines (130 loc) · 6.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<script lang="ts">
import { CheckBox } from '@nativescript-community/ui-checkbox';
import { Color, View } from '@nativescript/core';
import { get, writable } from 'svelte/store';
import { lc } from '~/helpers/locale';
import { SERVICES_SYNC_COLOR } from '~/services/sync/types';
import { WebdavDataSyncOptions } from '~/services/sync/WebdavDataSyncService';
import { showError } from '@shared/utils/showError';
import { closeModal } from '@shared/utils/svelte/ui';
import { pickColor, requestNotificationPermission } from '~/utils/ui';
import { colors, windowInset } from '~/variables';
import CActionBar from '../common/CActionBar.svelte';
import ListItemAutoSize from '../common/ListItemAutoSize.svelte';
import WebdavSettingsView from './WebdavSettingsView.svelte';
import { checkAlarmPermission } from '~/services/sync/BaseSyncService';
// technique for only specific properties to get updated on store change
$: ({ colorError, colorOnError, colorOnSurfaceVariant, colorOutline, colorPrimary, colorSecondary } = $colors);
export let data: WebdavDataSyncOptions = null;
const store = writable(Object.assign({ autoSync: false, enabled: true, color: SERVICES_SYNC_COLOR['webdav_data'] as string | Color }, data));
let webdavView: WebdavSettingsView;
async function save() {
if (await webdavView?.validateSave()) {
if (__ANDROID__) {
await requestNotificationPermission();
}
const result = get(store);
closeModal(result);
// WebdavDataSyncService.saveData({ username, password, remoteURL, remoteFolder, authType, token });
// closeBottomSheet(true);
}
}
let checkboxTapTimer;
function clearCheckboxTimer() {
if (checkboxTapTimer) {
clearTimeout(checkboxTapTimer);
checkboxTapTimer = null;
}
}
let ignoreNextOnCheckBoxChange = false;
async function onCheckBox(event, onUpdate) {
if (ignoreNextOnCheckBoxChange) {
return;
}
const value = event.value;
clearCheckboxTimer();
try {
ignoreNextOnCheckBoxChange = true;
onUpdate(event);
} catch (error) {
showError(error);
} finally {
ignoreNextOnCheckBoxChange = false;
}
}
function unCheckBoxItemTap(event) {
// we dont want duplicate events so let s timeout and see if we clicking diretly on the checkbox
const checkboxView: CheckBox = ((event.object as View).parent as View).getViewById('checkbox');
clearCheckboxTimer();
checkboxTapTimer = setTimeout(() => {
checkboxView.checked = !checkboxView.checked;
}, 10);
}
async function changeColor(event) {
try {
const newColor = await pickColor($store.color, { anchor: event.object });
if (newColor) {
$store.color = newColor.hex;
}
} catch (error) {
showError(error);
}
}
</script>
<page id="webdavsyncsettings" actionBarHidden={true}>
<gridlayout class="pageContent" rows="auto,*">
<scrollview row={1}>
<stacklayout android:paddingBottom={$windowInset.bottom}>
<ListItemAutoSize fontSize={20} subtitle={lc('sync_service_color_desc')} title={lc('color')} on:tap={changeColor}>
<absolutelayout backgroundColor={$store.color} borderColor={colorOutline} borderRadius="50%" borderWidth={2} col={1} height={40} marginLeft={10} width={40} />
</ListItemAutoSize>
<ListItemAutoSize fontSize={20} title={lc('enabled')} on:tap={unCheckBoxItemTap}>
<switch
id="checkbox"
checked={$store.enabled}
col={1}
marginLeft={10}
verticalAlignment="center"
on:checkedChange={(e) =>
onCheckBox(e, (e) => {
$store.enabled = e.value;
})} />
</ListItemAutoSize>
<ListItemAutoSize fontSize={20} subtitle={lc('remote_data_auto_sync')} title={lc('auto_sync')} on:tap={unCheckBoxItemTap}>
<switch
id="checkbox"
checked={$store.autoSync}
col={1}
marginLeft={10}
verticalAlignment="center"
on:checkedChange={(e) =>
onCheckBox(e, (e) => {
$store.autoSync = e.value;
})} />
</ListItemAutoSize>
{#if $store.autoSync}
<ListItemAutoSize fontSize={20} subtitle={lc('sync_throttle_desc')} title={lc('sync_throttle_seconds')}>
<textfield
col={1}
hint="0"
keyboardType="number"
marginLeft={10}
text={String($store.syncThrottleSeconds || 0)}
width={100}
on:textChange={(e) => {
const value = parseInt(e.value, 10) || 0;
if (checkAlarmPermission(value)) {
$store.syncThrottleSeconds = Math.max(0, value);
}
}} />
</ListItemAutoSize>
{/if}
<WebdavSettingsView bind:this={webdavView} {store} />
</stacklayout>
</scrollview>
<CActionBar canGoBack modalWindow={true} title={lc('webdav_config')}>
<mdbutton text={lc('save')} variant="text" verticalAlignment="middle" on:tap={save} />
<!-- <mdbutton class="actionBarButton" text={lc('save')} variant="text" on:tap={save} /> -->
</CActionBar>
</gridlayout>
</page>