提交 cd00cecb 编写于 作者: Z zhongjianfei

Adapter Update Form Status Sample code.

Signed-off-by: Nzhongjianfei <zhongjianfei@huawei.com>
Change-Id: I88c455cc239171e4ea5ba9735ee24cdc2fbdef6c
上级 d0a9bc2c
...@@ -20,7 +20,8 @@ ...@@ -20,7 +20,8 @@
}, },
"colorMode": "auto", "colorMode": "auto",
"isDefault": true, "isDefault": true,
"updateEnabled": true,"scheduledUpdateTime": "07:00", "updateEnabled": true,
"scheduledUpdateTime": "07:00",
"updateDuration": 0, "updateDuration": 0,
"defaultDimension": "2*2", "defaultDimension": "2*2",
"supportDimensions": ["2*2"] "supportDimensions": ["2*2"]
...@@ -102,10 +103,15 @@ ...@@ -102,10 +103,15 @@
let isTempCard: boolean = want.parameters[formInfo.FormParam.TEMPORARY_KEY]; let isTempCard: boolean = want.parameters[formInfo.FormParam.TEMPORARY_KEY];
if (isTempCard === false) { // 如果为常态卡片,直接进行信息持久化 if (isTempCard === false) { // 如果为常态卡片,直接进行信息持久化
console.info('Not temp card, init db for:' + formId); console.info('Not temp card, init db for:' + formId);
let storeDB = dataPreferences.getPreferences(this.context, 'mystore') let promise = dataPreferences.getPreferences(this.context, 'myStore');
storeDB.put('A' + formId, 'false'); promise.then((storeDB) => {
storeDB.put('B' + formId, 'false'); console.info("Succeeded to get preferences.");
storeDB.flush(); storeDB.putSync('A' + formId, 'false');
storeDB.putSync('B' + formId, 'false');
storeDB.flush();
}).catch((err) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
} }
let formData = {}; let formData = {};
return formBindingData.createFormBindingData(formData); return formBindingData.createFormBindingData(formData);
...@@ -113,54 +119,71 @@ ...@@ -113,54 +119,71 @@
onRemoveForm(formId) { onRemoveForm(formId) {
console.info('onRemoveForm, formId:' + formId); console.info('onRemoveForm, formId:' + formId);
let storeDB = dataPreferences.getPreferences(this.context, 'mystore') let promise = dataPreferences.getPreferences(this.context, 'myStore');
storeDB.delete('A' + formId); promise.then((storeDB) => {
storeDB.delete('B' + formId); console.info("Succeeded to get preferences.");
storeDB.deleteSync('A' + formId);
storeDB.deleteSync('B' + formId);
}).catch((err) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
} }
// 如果在添加时为临时卡片,则建议转为常态卡片时进行信息持久化 // 如果在添加时为临时卡片,则建议转为常态卡片时进行信息持久化
onCastToNormalForm(formId) { onCastToNormalForm(formId) {
console.info('onCastToNormalForm, formId:' + formId); console.info('onCastToNormalForm, formId:' + formId);
let storeDB = dataPreferences.getPreferences(this.context, 'myStore') let promise = dataPreferences.getPreferences(this.context, 'myStore');
storeDB.put('A' + formId, 'false'); promise.then((storeDB) => {
storeDB.put('B' + formId, 'false'); console.info("Succeeded to get preferences.");
storeDB.flush(); storeDB.putSync('A' + formId, 'false');
storeDB.putSync('B' + formId, 'false');
storeDB.flush();
}).catch((err) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
} }
onUpdateForm(formId) { onUpdateForm(formId) {
let storeDB = dataPreferences.getPreferences(this.context, 'myStore') let promise = dataPreferences.getPreferences(this.context, 'myStore');
let stateA = storeDB.get('A' + formId, 'false').toString() promise.then((storeDB) => {
let stateB = storeDB.get('B' + formId, 'false').toString() console.info("Succeeded to get preferences.");
// A状态选中则更新textA let stateA = storeDB.getSync('A' + formId, 'false').toString();
if (stateA === 'true') { let stateB = storeDB.getSync('B' + formId, 'false').toString();
let formInfo = formBindingData.createFormBindingData({ // A状态选中则更新textA
'textA': 'AAA' if (stateA === 'true') {
}) let formInfo = formBindingData.createFormBindingData({'textA': 'AAA'});
formProvider.updateForm(formId, formInfo) formProvider.updateForm(formId, formInfo);
} }
// B状态选中则更新textB // B状态选中则更新textB
if (stateB === 'true') { if (stateB === 'true') {
let formInfo = formBindingData.createFormBindingData({ let formInfo = formBindingData.createFormBindingData({'textB': 'BBB'});
'textB': 'BBB' formProvider.updateForm(formId, formInfo);
}) }
formProvider.updateForm(formId, formInfo) console.info(`Update form success stateA:${stateA} stateB:${stateB}.`);
} }).catch((err) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
} }
onFormEvent(formId, message) { onFormEvent(formId, message) {
// 存放卡片状态 // 存放卡片状态
console.info('onFormEvent formId:' + formId + 'msg:' + message); console.info('onFormEvent formId:' + formId + 'msg:' + message);
let storeDB = dataPreferences.getPreferences(this.context, 'myStore') let promise = dataPreferences.getPreferences(this.context, 'myStore');
let msg = JSON.parse(message) promise.then((storeDB) => {
if (msg.selectA != undefined) { console.info("Succeeded to get preferences.");
console.info('onFormEvent selectA info:' + msg.selectA); let msg = JSON.parse(message);
storeDB.put('A' + formId, msg.selectA); if (msg.selectA != undefined) {
} console.info('onFormEvent selectA info:' + msg.selectA);
if (msg.selectB != undefined) { storeDB.putSync('A' + formId, msg.selectA);
console.info('onFormEvent selectB info:' + msg.selectB); }
storeDB.put('B' + formId, msg.selectB); if (msg.selectB != undefined) {
} console.info('onFormEvent selectB info:' + msg.selectB);
storeDB.flush(); storeDB.putSync('B' + formId, msg.selectB);
}
storeDB.flush();
}).catch((err) => {
console.info(`Failed to get preferences. ${JSON.stringify(err)}`);
})
} }
}; };
``` ```
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册