mirror of
https://gitee.com/openharmony/codelabs
synced 2024-11-23 06:19:52 +00:00
闹钟(ArkTS) Codelinter整改
Signed-off-by: 13871184879 <452399386@qq.com>
This commit is contained in:
parent
704e20a6b3
commit
0d500f4523
@ -22,20 +22,14 @@
|
||||
|
||||
### 相关权限
|
||||
|
||||
本篇Codelab使用了后台代理提醒,需要在配置文件module.json5文件里添加权限:ohos.permission.PUBLISH_AGENT_REMINDER。
|
||||
本篇Codelab需要在module.json5中配置如下权限:
|
||||
|
||||
```
|
||||
{
|
||||
"module": {
|
||||
"name": "entry",
|
||||
...
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.PUBLISH_AGENT_REMINDER"
|
||||
}
|
||||
]
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.PUBLISH_AGENT_REMINDER"
|
||||
}
|
||||
}
|
||||
]
|
||||
```
|
||||
|
||||
## 环境搭建
|
||||
@ -43,13 +37,13 @@
|
||||
|
||||
### 软件要求
|
||||
|
||||
- [DevEco Studio](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/start-overview.md#%E5%B7%A5%E5%85%B7%E5%87%86%E5%A4%87)版本:DevEco Studio 3.1 Release及以上版本。
|
||||
- OpenHarmony SDK版本:API version 9及以上版本。
|
||||
- [DevEco Studio](https://gitee.com/openharmony/docs/blob/master/zh-cn/application-dev/quick-start/start-overview.md#%E5%B7%A5%E5%85%B7%E5%87%86%E5%A4%87)版本:DevEco Studio 3.1 Release。
|
||||
- OpenHarmony SDK版本:API version 9。
|
||||
|
||||
### 硬件要求
|
||||
|
||||
- 开发板类型:[润和RK3568开发板](https://gitee.com/openharmony/docs/blob/master/zh-cn/device-dev/quick-start/quickstart-appendix-rk3568.md)。
|
||||
- OpenHarmony系统:3.2 Release及以上版本。
|
||||
- OpenHarmony系统:3.2 Release。
|
||||
|
||||
### 环境搭建
|
||||
|
||||
@ -77,10 +71,6 @@
|
||||
```
|
||||
├──entry/src/main/ets // 代码区
|
||||
│ ├──common
|
||||
│ │ ├──bean
|
||||
│ │ │ ├──AlarmItemBean.ets // 闹钟属性类
|
||||
│ │ │ ├──AlarmSettingBean.ets // 闹钟设置属性类
|
||||
│ │ │ └──ReminderItemBean.ets // 后台提醒属性类
|
||||
│ │ ├──constants
|
||||
│ │ │ ├──AlarmSettingType.ets // 闹钟设置类型枚举
|
||||
│ │ │ ├──CommonConstants.ets // 公共常量类
|
||||
@ -88,7 +78,8 @@
|
||||
│ │ │ └──MainConstant.ets // 首页常量类
|
||||
│ │ └──utils
|
||||
│ │ ├──DataTypeUtils.ets // 数据类型工具类
|
||||
│ │ └──DimensionUtil.ets // 屏幕适配工具类
|
||||
│ │ ├──DimensionUtil.ets // 屏幕适配工具类
|
||||
│ │ └──GlobalContext.ets // 全局变量工具类
|
||||
│ ├──entryability
|
||||
│ │ └──EntryAbility.ets // 程序入口类
|
||||
│ ├──model
|
||||
@ -115,8 +106,12 @@
|
||||
│ │ │ └──ClockArea.ets // 主页时钟组件
|
||||
│ │ └──BackContainer.ets // 自定义头部组件
|
||||
│ └──viewmodel
|
||||
│ ├──AlarmItemBean.ets // 闹钟属性类
|
||||
│ ├──AlarmSettingBean.ets // 闹钟设置属性类
|
||||
│ ├──DayDateBean.ets // 日期属性类
|
||||
│ ├──DetailViewModel.ets // 详情模块逻辑功能类
|
||||
│ └──MainViewModel.ets // 主页逻辑功能类
|
||||
│ ├──MainViewModel.ets // 主页逻辑功能类
|
||||
│ └──ReminderItemBean.ets // 后台提醒属性类
|
||||
└──entry/src/main/resources // 资源文件目录
|
||||
```
|
||||
|
||||
@ -143,6 +138,7 @@
|
||||
// ClockArea.ets
|
||||
@Component
|
||||
export default struct ClockArea {
|
||||
...
|
||||
build() {
|
||||
Canvas(this.renderContext)
|
||||
.width(this.canvasSize)
|
||||
@ -156,7 +152,6 @@ export default struct ClockArea {
|
||||
this.showClock = !this.showClock;
|
||||
})
|
||||
}
|
||||
...
|
||||
// 启动绘画任务
|
||||
private startDrawTask() {
|
||||
let that = this;
|
||||
@ -168,6 +163,7 @@ export default struct ClockArea {
|
||||
that.drawClockArea();
|
||||
}, MainConstant.DEFAULT_ONE_SECOND_MS);
|
||||
}
|
||||
...
|
||||
}
|
||||
```
|
||||
|
||||
@ -180,8 +176,8 @@ export default struct ClockArea {
|
||||
private drawClockArea(): void{
|
||||
this.renderContext.clearRect(
|
||||
-this.canvasSize,
|
||||
-this.canvasSize / Constants.DEFAULT_DOUBLE,
|
||||
this.canvasSize * Constants.DEFAULT_DOUBLE,
|
||||
-this.canvasSize / CommonConstants.DEFAULT_DOUBLE,
|
||||
this.canvasSize * CommonConstants.DEFAULT_DOUBLE,
|
||||
this.canvasSize);
|
||||
let date = new Date();
|
||||
let hours = date.getHours();
|
||||
@ -203,11 +199,12 @@ private drawClockArea(): void{
|
||||
public queryAlarmsTasker(callback: (alarms: Array<AlarmItem>) => void) {
|
||||
let that = this;
|
||||
that.queryDatabaseAlarms(callback);
|
||||
globalThis.preference.addPreferencesListener({
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.addPreferencesListener({
|
||||
onDataChanged() {
|
||||
that.queryDatabaseAlarms(callback);
|
||||
}
|
||||
})
|
||||
} as PreferencesListener)
|
||||
}
|
||||
```
|
||||
|
||||
@ -227,8 +224,7 @@ export default struct AlarmList {
|
||||
}.onClick(() => {
|
||||
router.pushUrl({ url: "pages/DetailIndex", params: { alarmItem: item } });
|
||||
})
|
||||
},
|
||||
item => item.id.toString())
|
||||
}, (item: AlarmItem) => JSON.stringify(item))
|
||||
}
|
||||
.padding({
|
||||
left: DimensionUtil.getVp($r('app.float.alarm_list_content_distance')),
|
||||
@ -285,7 +281,8 @@ public openAlarm(id: number, isOpen: boolean) {
|
||||
} else {
|
||||
this.reminderService.deleteReminder(this.alarms[i].id);
|
||||
}
|
||||
globalThis.preference.set(ALARM_KEY, JSON.stringify(this.alarms));
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.set(CommonConstants.ALARM_KEY, JSON.stringify(this.alarms));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -311,18 +308,28 @@ public openAlarm(id: number, isOpen: boolean) {
|
||||
|
||||
```typescript
|
||||
// DetailIndex.ets
|
||||
build() {
|
||||
Row() {
|
||||
build()
|
||||
{
|
||||
Column() {
|
||||
...
|
||||
Button() {
|
||||
Image(this.backImgRes == null ? $r('app.media.ic_public_back') : this.backImgRes).objectFit(ImageFit.Fill)
|
||||
Image($r('app.media.ic_confirm')).objectFit(ImageFit.Fill)
|
||||
}
|
||||
.backgroundColor($r('app.color.trans_parent'))
|
||||
.width(DimensionUtil.getVp($r('app.float.title_button_size')))
|
||||
.height(DimensionUtil.getVp($r('app.float.title_button_size')))
|
||||
.onClick(() => {
|
||||
this.backFunc ? this.backFunc() : router.back();
|
||||
this.viewModel.setAlarmRemind(this.alarmItem);
|
||||
router.back();
|
||||
})
|
||||
...
|
||||
}
|
||||
}
|
||||
|
||||
// BackContainer.ets
|
||||
build() {
|
||||
Row() {
|
||||
...
|
||||
Text(this.header)
|
||||
.fontSize(DimensionUtil.getFp($r('app.float.detail_title_font_size')))
|
||||
.lineHeight(DimensionUtil.getVp($r('app.float.title_line_height')))
|
||||
@ -353,14 +360,14 @@ export default struct DatePickArea {
|
||||
build() {
|
||||
Stack({ alignContent: Alignment.Center }) {
|
||||
Row() {
|
||||
ForEach(DetailConstant.DAY_DATA, (item) => {
|
||||
ForEach(DetailConstant.DAY_DATA, (item: DayDataBean) => {
|
||||
TextPicker({ range: item.data, selected: item.delSelect })
|
||||
.layoutWeight(CommonConstants.DEFAULT_LAYOUT_WEIGHT)
|
||||
.backgroundColor($r('app.color.grey_light'))
|
||||
.onChange((value: string, index: number) => {
|
||||
item.delSelect = index;
|
||||
})
|
||||
}, item => item.timeType)
|
||||
}, (item: DayDataBean) => JSON.stringify(item))
|
||||
}
|
||||
}
|
||||
.height(DimensionUtil.getVp($r('app.float.date_picker_height')))
|
||||
@ -380,7 +387,7 @@ export default struct DatePickArea {
|
||||
// SettingItem.ets
|
||||
build() {
|
||||
Column() {
|
||||
ForEach(this.settingInfo, (item: SettingInfo, index: number) => {
|
||||
ForEach(this.settingInfo, (item: AlarmSettingBean, index: number | undefined) => {
|
||||
Divider()
|
||||
...
|
||||
Row() {
|
||||
@ -392,7 +399,7 @@ build() {
|
||||
.onClick(() => {
|
||||
this.showSettingDialog(item.sType);
|
||||
})
|
||||
}, (item, index) => JSON.stringify(item) + index)
|
||||
}, (item: AlarmSettingBean, index: number | undefined) => JSON.stringify(item) + index)
|
||||
}
|
||||
...
|
||||
}
|
||||
@ -405,33 +412,33 @@ build() {
|
||||
```typescript
|
||||
// DetailViewModel.ets
|
||||
public async setAlarmRemind(alarmItem: AlarmItem) {
|
||||
alarmItem.hour = this.getAlarmTime(Constants.DEFAULT_SINGLE);
|
||||
alarmItem.minute = this.getAlarmTime(Constants.DEFAULT_DATA_PICKER_HOUR_SELECTION);
|
||||
alarmItem.hour = this.getAlarmTime(CommonConstants.DEFAULT_SINGLE);
|
||||
alarmItem.minute = this.getAlarmTime(CommonConstants.DEFAULT_DATA_PICKER_HOUR_SELECTION);
|
||||
let index = await this.findAlarmWithId(alarmItem.id);
|
||||
if (index !== Constants.DEFAULT_NUMBER_NEGATIVE) {
|
||||
// 已存在,删除原有提醒
|
||||
if (index !== CommonConstants.DEFAULT_NUMBER_NEGATIVE) { // 已存在,删除原有提醒
|
||||
this.reminderService.deleteReminder(alarmItem.id);
|
||||
} else {
|
||||
// 不存在,以数据长度为notificationId新增闹钟数据
|
||||
} else { // 不存在,以数据长度为notificationId新增闹钟数据
|
||||
index = this.alarms.length;
|
||||
alarmItem.notificationId = index;
|
||||
this.alarms.push(alarmItem);
|
||||
}
|
||||
this.reminderService.addReminder(alarmItem, (newId) => {
|
||||
this.reminderService.addReminder(alarmItem, (newId: number) => {
|
||||
alarmItem.id = newId;
|
||||
alarmItem.isOpen = true;
|
||||
this.alarms[index] = alarmItem;
|
||||
globalThis.preference.set(ALARM_KEY, JSON.stringify(this.alarms));
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.set(CommonConstants.ALARM_KEY, JSON.stringify(this.alarms));
|
||||
})
|
||||
}
|
||||
|
||||
public async removeAlarmRemind(id: number) {
|
||||
this.reminderService.deleteReminder(id);
|
||||
let index = await this.findAlarmWithId(id);
|
||||
if (index !== Constants.DEFAULT_NUMBER_NEGATIVE) {
|
||||
this.alarms.splice(index, Constants.DEFAULT_SINGLE);
|
||||
if (index !== CommonConstants.DEFAULT_NUMBER_NEGATIVE) {
|
||||
this.alarms.splice(index, CommonConstants.DEFAULT_SINGLE);
|
||||
}
|
||||
globalThis.preference.set(ALARM_KEY, JSON.stringify(this.alarms));
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.set(CommonConstants.ALARM_KEY, JSON.stringify(this.alarms));
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -13,174 +13,130 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
/**
|
||||
* database preference id.
|
||||
*/
|
||||
export const PREFERENCE_ID = 'storageId';
|
||||
|
||||
/**
|
||||
* database alarm data key.
|
||||
*/
|
||||
export const ALARM_KEY = 'alarmData';
|
||||
|
||||
/**
|
||||
* database alarm item key.
|
||||
*/
|
||||
export const PARAM_KEY = 'alarmItem';
|
||||
|
||||
export const CommonConstants = {
|
||||
export class CommonConstants {
|
||||
/**
|
||||
* database preference id.
|
||||
*/
|
||||
static readonly PREFERENCE_ID = 'storageId';
|
||||
/**
|
||||
* database alarm data key.
|
||||
*/
|
||||
static readonly ALARM_KEY = 'alarmData';
|
||||
/**
|
||||
* common full length
|
||||
*/
|
||||
FULL_LENGTH: '100%',
|
||||
|
||||
static readonly FULL_LENGTH: string = '100%';
|
||||
/**
|
||||
* default string space.
|
||||
*/
|
||||
DEFAULT_STRING_SPACE: ' ',
|
||||
|
||||
static readonly DEFAULT_STRING_SPACE: string = ' ';
|
||||
/**
|
||||
* default string comma.
|
||||
*/
|
||||
DEFAULT_STRING_COMMA: ',',
|
||||
|
||||
static readonly DEFAULT_STRING_COMMA: string = ',';
|
||||
/**
|
||||
* default string no repeat.
|
||||
*/
|
||||
DEFAULT_STRING_NO_REPEAT: '不重复',
|
||||
|
||||
static readonly DEFAULT_STRING_NO_REPEAT: string = '不重复';
|
||||
/**
|
||||
* default number negative.
|
||||
*/
|
||||
DEFAULT_NUMBER_NEGATIVE: -1,
|
||||
|
||||
static readonly DEFAULT_NUMBER_NEGATIVE: number = -1;
|
||||
/**
|
||||
* default layout weight.
|
||||
*/
|
||||
DEFAULT_LAYOUT_WEIGHT: 1,
|
||||
|
||||
/**
|
||||
* default number monday.
|
||||
*/
|
||||
DEFAULT_NUMBER_MONDAY: 1,
|
||||
|
||||
/**
|
||||
* default number tuesday.
|
||||
*/
|
||||
DEFAULT_NUMBER_TUESDAY: 2,
|
||||
|
||||
/**
|
||||
* default number wednesday.
|
||||
*/
|
||||
DEFAULT_NUMBER_WEDNESDAY: 3,
|
||||
|
||||
/**
|
||||
* default number thursday.
|
||||
*/
|
||||
DEFAULT_NUMBER_THURSDAY: 4,
|
||||
|
||||
/**
|
||||
* default number friday.
|
||||
*/
|
||||
DEFAULT_NUMBER_FRIDAY: 5,
|
||||
|
||||
/**
|
||||
* default number saturday.
|
||||
*/
|
||||
DEFAULT_NUMBER_SATURDAY: 6,
|
||||
|
||||
/**
|
||||
* default number sunday.
|
||||
*/
|
||||
DEFAULT_NUMBER_SUNDAY: 7,
|
||||
|
||||
static readonly DEFAULT_LAYOUT_WEIGHT: number = 1;
|
||||
/**
|
||||
* default single.
|
||||
*/
|
||||
DEFAULT_SINGLE: 1,
|
||||
|
||||
static readonly DEFAULT_SINGLE: number = 1;
|
||||
/**
|
||||
* default double.
|
||||
*/
|
||||
DEFAULT_DOUBLE: 2,
|
||||
|
||||
* default double.
|
||||
*/
|
||||
static readonly DEFAULT_DOUBLE: number = 2;
|
||||
/**
|
||||
* default data picker hour selection.
|
||||
*/
|
||||
DEFAULT_DATA_PICKER_HOUR_SELECTION: 2,
|
||||
|
||||
static readonly DEFAULT_DATA_PICKER_HOUR_SELECTION: number = 2;
|
||||
/**
|
||||
* default total minute.
|
||||
*/
|
||||
DEFAULT_TOTAL_MINUTE: 60,
|
||||
|
||||
static readonly DEFAULT_TOTAL_MINUTE: number = 60;
|
||||
/**
|
||||
* default string monday.
|
||||
*/
|
||||
DEFAULT_STRING_MONDAY: '周一',
|
||||
|
||||
static readonly DEFAULT_STRING_MONDAY: string = '周一';
|
||||
/**
|
||||
* default string tuesday.
|
||||
*/
|
||||
DEFAULT_STRING_TUESDAY: '周二',
|
||||
|
||||
static readonly DEFAULT_STRING_TUESDAY: string = '周二';
|
||||
/**
|
||||
* default string wednesday.
|
||||
*/
|
||||
DEFAULT_STRING_WEDNESDAY: '周三',
|
||||
|
||||
static readonly DEFAULT_STRING_WEDNESDAY: string = '周三';
|
||||
/**
|
||||
* default string thursday.
|
||||
*/
|
||||
DEFAULT_STRING_THURSDAY: '周四',
|
||||
|
||||
static readonly DEFAULT_STRING_THURSDAY: string = '周四';
|
||||
/**
|
||||
* default string friday.
|
||||
*/
|
||||
DEFAULT_STRING_FRIDAY: '周五',
|
||||
|
||||
static readonly DEFAULT_STRING_FRIDAY: string = '周五';
|
||||
/**
|
||||
* default string saturday.
|
||||
*/
|
||||
DEFAULT_STRING_SATURDAY: '周六',
|
||||
|
||||
static readonly DEFAULT_STRING_SATURDAY: string = '周六';
|
||||
/**
|
||||
* default string sunday.
|
||||
*/
|
||||
DEFAULT_STRING_SUNDAY: '周日',
|
||||
|
||||
static readonly DEFAULT_STRING_SUNDAY: string = '周日';
|
||||
/**
|
||||
* default number moment.
|
||||
*/
|
||||
DEFAULT_NUMBER_MOMENT: 3,
|
||||
|
||||
static readonly DEFAULT_NUMBER_MOMENT: number = 3;
|
||||
/**
|
||||
* default interval step.
|
||||
*/
|
||||
DEFAULT_INTERVAL_STEP: 5,
|
||||
|
||||
static readonly DEFAULT_INTERVAL_STEP: number = 5;
|
||||
/**
|
||||
* default common degree
|
||||
*/
|
||||
DEFAULT_COMMON_DEGREE: 6,
|
||||
|
||||
static readonly DEFAULT_COMMON_DEGREE: number = 6;
|
||||
/**
|
||||
* default pointer width.
|
||||
*/
|
||||
DEFAULT_POINTER_WIDTH: 10,
|
||||
|
||||
static readonly DEFAULT_POINTER_WIDTH: number = 10;
|
||||
/**
|
||||
* default total hour.
|
||||
*/
|
||||
DEFAULT_TOTAL_HOUR: 12,
|
||||
|
||||
static readonly DEFAULT_TOTAL_HOUR: number = 12;
|
||||
/**
|
||||
* default interval time max.
|
||||
*/
|
||||
DEFAULT_INTERVAL_TIME_MAX: 10,
|
||||
|
||||
static readonly DEFAULT_INTERVAL_TIME_MAX: number = 10;
|
||||
/**
|
||||
* default interval minute max.
|
||||
*/
|
||||
DEFAULT_INTERVAL_MINUTE_MAX: 30,
|
||||
static readonly DEFAULT_INTERVAL_MINUTE_MAX: number = 30;
|
||||
/**
|
||||
* bundle name.
|
||||
*/
|
||||
static readonly BUNDLE_NAME: string = 'com.huawei.alarmclock';
|
||||
/**
|
||||
* ability name.
|
||||
*/
|
||||
static readonly ABILITY_NAME: string = 'EntryAbility';
|
||||
}
|
||||
|
||||
/**
|
||||
* Default number for a week.
|
||||
*/
|
||||
export enum WeekDays {
|
||||
DEFAULT_NUMBER_MONDAY = 1,
|
||||
DEFAULT_NUMBER_TUESDAY = 2,
|
||||
DEFAULT_NUMBER_WEDNESDAY = 3,
|
||||
DEFAULT_NUMBER_THURSDAY = 4,
|
||||
DEFAULT_NUMBER_FRIDAY = 5,
|
||||
DEFAULT_NUMBER_SATURDAY = 6,
|
||||
DEFAULT_NUMBER_SUNDAY = 7
|
||||
}
|
@ -12,72 +12,70 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import DayDataBean from '../../viewmodel/DayDateBean'
|
||||
|
||||
/**
|
||||
* Detail page constant description.
|
||||
*/
|
||||
export const DetailConstant = {
|
||||
export class DetailConstant {
|
||||
/**
|
||||
* detail page day data.
|
||||
*/
|
||||
DAY_DATA: [
|
||||
{ timeType: 0, delSelect: 0, data: ['上午', '下午'] },
|
||||
{ timeType: 1, delSelect: 0, data: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'] },
|
||||
{ timeType: 2, delSelect: 0, data: ['01', '02', '03', '04', '05', '06', '07', '08', '09', '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', '00',
|
||||
] }
|
||||
],
|
||||
|
||||
static readonly DAY_DATA: DayDataBean[] = [
|
||||
{ timeType: 0, delSelect: 0, data: ['上午', '下午'] } as DayDataBean,
|
||||
{ timeType: 1, delSelect: 0, data:
|
||||
[
|
||||
'01', '02', '03', '04', '05', '06', '07', '08', '09', '10', '11', '12'
|
||||
]
|
||||
} as DayDataBean,
|
||||
{ timeType: 2, delSelect: 0, data:
|
||||
[
|
||||
'01', '02', '03', '04', '05', '06', '07', '08', '09', '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', '00',
|
||||
]
|
||||
} as DayDataBean
|
||||
];
|
||||
/**
|
||||
* week day data.
|
||||
*/
|
||||
WEEKDAY_DATA: [1, 2, 3, 4, 5, 6, 7],
|
||||
|
||||
static readonly WEEKDAY_DATA: number[] = [1, 2, 3, 4, 5, 6, 7];
|
||||
/**
|
||||
* ring duration list data.
|
||||
*/
|
||||
RING_DURATION: [1, 5, 10, 15, 20, 30],
|
||||
|
||||
static readonly RING_DURATION: number[] = [1, 5, 10, 15, 20, 30];
|
||||
/**
|
||||
* default string minute.
|
||||
*/
|
||||
DEFAULT_STRING_MINUTE: '分钟',
|
||||
|
||||
static readonly DEFAULT_STRING_MINUTE: string = '分钟';
|
||||
/**
|
||||
* default string group name.
|
||||
*/
|
||||
DEFAULT_STRING_GROUP_NAME: 'radioGroup',
|
||||
|
||||
static readonly DEFAULT_STRING_GROUP_NAME: string = 'radioGroup';
|
||||
/**
|
||||
* default string provider key.
|
||||
*/
|
||||
DEFAULT_PROVIDER_KEY: 'alarmItemProvide',
|
||||
|
||||
static readonly DEFAULT_PROVIDER_KEY: string = 'alarmItemProvide';
|
||||
/**
|
||||
* default string repeat.
|
||||
*/
|
||||
DEFAULT_STRING_REPEAT: '重复',
|
||||
|
||||
static readonly DEFAULT_STRING_REPEAT: string = '重复';
|
||||
/**
|
||||
* default string alarm name.
|
||||
*/
|
||||
DEFAULT_STRING_ALARM_NAME: '闹钟名',
|
||||
|
||||
static readonly DEFAULT_STRING_ALARM_NAME: string = '闹钟名';
|
||||
/**
|
||||
* default string interval.
|
||||
*/
|
||||
DEFAULT_STRING_INTERVAL: '再响间隔',
|
||||
|
||||
static readonly DEFAULT_STRING_INTERVAL: string = '再响间隔';
|
||||
/**
|
||||
* default string duration.
|
||||
*/
|
||||
DEFAULT_STRING_DURATION: '闹铃时长',
|
||||
|
||||
static readonly DEFAULT_STRING_DURATION: string = '闹铃时长';
|
||||
/**
|
||||
* default string times.
|
||||
*/
|
||||
DEFAULT_STRING_TIMES: '次',
|
||||
static readonly DEFAULT_STRING_TIMES: string = '次';
|
||||
}
|
@ -16,79 +16,65 @@
|
||||
/**
|
||||
* Main page constant description.
|
||||
*/
|
||||
export const MainConstant = {
|
||||
export class MainConstant {
|
||||
/**
|
||||
* Main page times list.
|
||||
*/
|
||||
TIMES: [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2],
|
||||
|
||||
static readonly TIMES: number[] = [3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 1, 2];
|
||||
/**
|
||||
* Default single digit max.
|
||||
*/
|
||||
DEFAULT_SINGLE_DIGIT_MAX: 9,
|
||||
|
||||
static readonly DEFAULT_SINGLE_DIGIT_MAX: number = 9;
|
||||
/**
|
||||
* Default horizontal angle.
|
||||
*/
|
||||
DEFAULT_HORIZONTAL_ANGLE: 180,
|
||||
|
||||
static readonly DEFAULT_HORIZONTAL_ANGLE: number = 180;
|
||||
/**
|
||||
* Default one second ms.
|
||||
*/
|
||||
DEFAULT_ONE_SECOND_MS: 1000,
|
||||
|
||||
static readonly DEFAULT_ONE_SECOND_MS: number = 1000;
|
||||
/**
|
||||
* Default zeroing.
|
||||
*/
|
||||
DEFAULT_ZEROING: "0",
|
||||
|
||||
static readonly DEFAULT_ZEROING: string = '0';
|
||||
/**
|
||||
* Default string morning.
|
||||
*/
|
||||
DEFAULT_STRING_MORNING: '上午',
|
||||
|
||||
static readonly DEFAULT_STRING_MORNING: string = '上午';
|
||||
/**
|
||||
* Default string afternoon.
|
||||
*/
|
||||
DEFAULT_STRING_AFTERNOON: '下午',
|
||||
|
||||
static readonly DEFAULT_STRING_AFTERNOON: string = '下午';
|
||||
/**
|
||||
* Default string alarm name.
|
||||
*/
|
||||
DEFAULT_STRING_ALARM: '闹钟',
|
||||
|
||||
static readonly DEFAULT_STRING_ALARM: string = '闹钟';
|
||||
/**
|
||||
* Default string quotation.
|
||||
*/
|
||||
DEFAULT_STRING_NULL: "",
|
||||
|
||||
static readonly DEFAULT_STRING_NULL: string = '';
|
||||
/**
|
||||
* Default string colon.
|
||||
*/
|
||||
DEFAULT_STRING_COLON: ':',
|
||||
|
||||
static readonly DEFAULT_STRING_COLON: string = ':';
|
||||
/**
|
||||
* Default clock time font size unit.
|
||||
*/
|
||||
CLOCK_TIME_FONT_SIZE_UNIT: 'px',
|
||||
|
||||
static readonly CLOCK_TIME_FONT_SIZE_UNIT: string = 'px';
|
||||
/**
|
||||
* Hour pointer image url.
|
||||
*/
|
||||
HOUR_POINTER_IMAGE_URL: "../../../resources/base/media/ic_hour_pointer.png",
|
||||
|
||||
static readonly HOUR_POINTER_IMAGE_URL: string = '../../../resources/base/media/ic_hour_pointer.png';
|
||||
/**
|
||||
* Minute pointer image url.
|
||||
*/
|
||||
MINUTE_POINTER_IMAGE_URL: "../../../resources/base/media/ic_minute_pointer.png",
|
||||
|
||||
static readonly MINUTE_POINTER_IMAGE_URL: string = '../../../resources/base/media/ic_minute_pointer.png';
|
||||
/**
|
||||
* Second pointer image url.
|
||||
*/
|
||||
SECOND_POINTER_IMAGE_URL: "../../../resources/base/media/ic_second_pointer.png",
|
||||
|
||||
static readonly SECOND_POINTER_IMAGE_URL: string = '../../../resources/base/media/ic_second_pointer.png';
|
||||
/**
|
||||
* Clock pan image url.
|
||||
*/
|
||||
CLOCK_PAN_IMAGE_URL: '../../../resources/base/media/ic_clock_pan.png',
|
||||
static readonly CLOCK_PAN_IMAGE_URL: string = '../../../resources/base/media/ic_clock_pan.png';
|
||||
}
|
@ -17,21 +17,12 @@
|
||||
* Data type utils.
|
||||
*/
|
||||
export default class DataTypeUtils {
|
||||
/**
|
||||
* return value is number.
|
||||
*
|
||||
* @return boolean.
|
||||
*/
|
||||
static isNumber(value): boolean{
|
||||
return typeof value === 'number' && isFinite(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* return obj is null.
|
||||
*
|
||||
* @return boolean.
|
||||
*/
|
||||
static isNull(obj): boolean {
|
||||
static isNull(obj: Object): boolean {
|
||||
return (typeof obj === 'undefined' || obj == null || obj === '');
|
||||
}
|
||||
|
||||
@ -40,18 +31,10 @@ export default class DataTypeUtils {
|
||||
*
|
||||
* @return type in obj.
|
||||
*/
|
||||
static deepCopy(obj) {
|
||||
var newObj = obj.constructor === Array ? [] : {};
|
||||
if (typeof obj !== 'object') {
|
||||
return obj;
|
||||
} else {
|
||||
for (var i in obj) {
|
||||
if (typeof obj[i] === 'object') {
|
||||
newObj[i] = this.deepCopy(obj[i]);
|
||||
} else {
|
||||
newObj[i] = obj[i];
|
||||
}
|
||||
}
|
||||
static deepCopy(obj: number[]) {
|
||||
let newObj: number[] = [];
|
||||
for (let i = 0; i < obj.length; i++) {
|
||||
newObj[i] = JSON.parse(JSON.stringify(obj[i]));
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
|
@ -12,8 +12,10 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
import display from '@ohos.display';
|
||||
import { GlobalContext } from './GlobalContext';
|
||||
|
||||
var context = getContext(this);
|
||||
let context = getContext(this);
|
||||
|
||||
/**
|
||||
* Design drawing width.
|
||||
@ -35,7 +37,7 @@ export default class DimensionUtil {
|
||||
* @return number
|
||||
*/
|
||||
static adaptDimension(value: number): number {
|
||||
let deviceDisplay = globalThis.display;
|
||||
let deviceDisplay = GlobalContext.getContext().getObject('globalDisplay') as display.Display;
|
||||
let widthScale = deviceDisplay.width / DESIGN_WIDTH;
|
||||
let virtualHeight = widthScale * DESIGN_HEIGHT;
|
||||
let designDim = Math.sqrt(DESIGN_WIDTH * DESIGN_WIDTH + DESIGN_HEIGHT * DESIGN_HEIGHT);
|
||||
@ -50,7 +52,7 @@ export default class DimensionUtil {
|
||||
*/
|
||||
static getPx(value: Resource): number {
|
||||
let beforeVp = context.resourceManager.getNumber(value.id);
|
||||
return this.adaptDimension(beforeVp);
|
||||
return DimensionUtil.adaptDimension(beforeVp);
|
||||
}
|
||||
|
||||
/**
|
||||
@ -60,7 +62,7 @@ export default class DimensionUtil {
|
||||
*/
|
||||
static getVp(value: Resource): number {
|
||||
let beforeVp = context.resourceManager.getNumber(value.id);
|
||||
return px2vp(this.adaptDimension(beforeVp));
|
||||
return px2vp(DimensionUtil.adaptDimension(beforeVp));
|
||||
}
|
||||
|
||||
/**
|
||||
@ -70,6 +72,6 @@ export default class DimensionUtil {
|
||||
*/
|
||||
static getFp(value: Resource): number {
|
||||
let beforeFp = context.resourceManager.getNumber(value.id);
|
||||
return px2fp(this.adaptDimension(beforeFp));
|
||||
return px2fp(DimensionUtil.adaptDimension(beforeFp));
|
||||
}
|
||||
}
|
@ -0,0 +1,37 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License,Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export class GlobalContext {
|
||||
private constructor() {
|
||||
}
|
||||
|
||||
private static instance: GlobalContext;
|
||||
private _objects = new Map<string, Object>();
|
||||
|
||||
public static getContext(): GlobalContext {
|
||||
if (!GlobalContext.instance) {
|
||||
GlobalContext.instance = new GlobalContext();
|
||||
}
|
||||
return GlobalContext.instance;
|
||||
}
|
||||
|
||||
getObject(value: string): Object | undefined {
|
||||
return this._objects.get(value);
|
||||
}
|
||||
|
||||
setObject(key: string, objectClass: Object): void {
|
||||
this._objects.set(key, objectClass);
|
||||
}
|
||||
}
|
@ -16,19 +16,40 @@
|
||||
import display from '@ohos.display';
|
||||
import UIAbility from '@ohos.app.ability.UIAbility';
|
||||
import PreferencesHandler from '../model/database/PreferencesHandler';
|
||||
import window from '@ohos.window';
|
||||
import { GlobalContext } from '../common/utils/GlobalContext';
|
||||
import hilog from '@ohos.hilog';
|
||||
|
||||
export default class EntryAbility extends UIAbility {
|
||||
onCreate(want) {
|
||||
let abilityInfo = this.context.abilityInfo;
|
||||
globalThis.bundleName = abilityInfo.bundleName;
|
||||
globalThis.abilityName = abilityInfo.name;
|
||||
globalThis.abilityWant = want;
|
||||
globalThis.preference = PreferencesHandler.getInstance();
|
||||
onCreate() {
|
||||
GlobalContext.getContext().setObject('preference', PreferencesHandler.instance);
|
||||
}
|
||||
|
||||
async onWindowStageCreate(windowStage) {
|
||||
globalThis.display = await display.getDefaultDisplay();
|
||||
await globalThis.preference.configure(this.context.getApplicationContext());
|
||||
windowStage.setUIContent(this.context, "pages/MainIndex", null);
|
||||
async onWindowStageCreate(windowStage: window.WindowStage) {
|
||||
// Main window is created, set main page for this ability
|
||||
let globalDisplay: display.Display = display.getDefaultDisplaySync();
|
||||
GlobalContext.getContext().setObject('globalDisplay', globalDisplay);
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
await preference.configure(this.context.getApplicationContext());
|
||||
// windowStage.setUIContent(this.context, "pages/MainIndex", null);
|
||||
|
||||
let windowClass: window.Window | null = null;
|
||||
windowStage.getMainWindow((_err, data) => {
|
||||
let isLayoutFullScreen = false;
|
||||
windowClass = data;
|
||||
windowClass.setWindowLayoutFullScreen(isLayoutFullScreen, (err) => {
|
||||
if (err.code) {
|
||||
return;
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
windowStage.loadContent('pages/MainIndex', (err, data) => {
|
||||
if (err.code) {
|
||||
hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? '');
|
||||
return;
|
||||
}
|
||||
hilog.info(0x0000, 'testTag', 'Succeeded in loading the content. Data: %{public}s', JSON.stringify(data) ?? '');
|
||||
});
|
||||
}
|
||||
}
|
@ -16,7 +16,7 @@
|
||||
import reminderAgent from '@ohos.reminderAgentManager';
|
||||
import notification from '@ohos.notificationManager';
|
||||
import { CommonConstants } from '../common/constants/CommonConstants';
|
||||
import ReminderItem from '../common/bean/ReminderItemBean';
|
||||
import ReminderItem from '../viewmodel/ReminderItemBean';
|
||||
|
||||
/**
|
||||
* Base on ohos reminder agent service
|
||||
@ -28,7 +28,7 @@ export default class ReminderService {
|
||||
public openNotificationPermission() {
|
||||
notification.requestEnableNotification().then(() => {
|
||||
console.info('Enable notification success');
|
||||
}).catch((err) => {
|
||||
}).catch((err: Error) => {
|
||||
console.error('Enable notification failed because ' + JSON.stringify(err));
|
||||
});
|
||||
}
|
||||
@ -39,7 +39,7 @@ export default class ReminderService {
|
||||
* @param alarmItem ReminderItem
|
||||
* @param callback callback
|
||||
*/
|
||||
public addReminder(alarmItem: ReminderItem, callback?) {
|
||||
public addReminder(alarmItem: ReminderItem, callback?: (reminderId: number) => void) {
|
||||
let reminder = this.initReminder(alarmItem);
|
||||
reminderAgent.publishReminder(reminder, (err, reminderId) => {
|
||||
if (callback != null) {
|
||||
@ -78,8 +78,8 @@ export default class ReminderService {
|
||||
},
|
||||
],
|
||||
wantAgent: {
|
||||
pkgName: globalThis.bundleName,
|
||||
abilityName: globalThis.abilityName
|
||||
pkgName: CommonConstants.BUNDLE_NAME,
|
||||
abilityName: CommonConstants.ABILITY_NAME
|
||||
},
|
||||
notificationId: item.notificationId,
|
||||
expiredContent: 'this reminder has expired',
|
||||
|
@ -14,15 +14,15 @@
|
||||
*/
|
||||
|
||||
import data_preferences from '@ohos.data.preferences';
|
||||
import { PREFERENCE_ID } from '../../common/constants/CommonConstants';
|
||||
import { CommonConstants } from '../../common/constants/CommonConstants';
|
||||
import PreferencesListener from './PreferencesListener';
|
||||
|
||||
/**
|
||||
* Based on lightweight databases preferences handler.
|
||||
*/
|
||||
export default class PreferencesHandler {
|
||||
private static instance: PreferencesHandler;
|
||||
private preferences;
|
||||
static instance: PreferencesHandler = new PreferencesHandler();
|
||||
private preferences: data_preferences.Preferences | null = null;
|
||||
private defaultValue = '';
|
||||
private listeners: PreferencesListener[];
|
||||
|
||||
@ -35,23 +35,23 @@ export default class PreferencesHandler {
|
||||
*
|
||||
* @return instance
|
||||
*/
|
||||
public static getInstance() {
|
||||
if (this.instance == null) {
|
||||
this.instance = new PreferencesHandler();
|
||||
}
|
||||
return this.instance;
|
||||
}
|
||||
// public static getInstance() {
|
||||
// if (this.instance == null) {
|
||||
// this.instance = new PreferencesHandler();
|
||||
// }
|
||||
// return this.instance;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Configure PreferencesHandler.
|
||||
*
|
||||
* @param context Context
|
||||
*/
|
||||
public async configure(context) {
|
||||
this.preferences = await data_preferences.getPreferences(context, PREFERENCE_ID);
|
||||
this.preferences.on('change', (key) => {
|
||||
public async configure(context: Context) {
|
||||
this.preferences = await data_preferences.getPreferences(context, CommonConstants.PREFERENCE_ID);
|
||||
this.preferences.on('change', (data: Record<string, Object>) => {
|
||||
for (let preferencesListener of this.listeners) {
|
||||
preferencesListener.onDataChanged(key);
|
||||
preferencesListener.onDataChanged(data.key as string);
|
||||
}
|
||||
});
|
||||
}
|
||||
@ -62,7 +62,7 @@ export default class PreferencesHandler {
|
||||
* @param key string
|
||||
* @param value any
|
||||
*/
|
||||
public async set(key: string, value) {
|
||||
public async set(key: string, value: string) {
|
||||
if (this.preferences != null) {
|
||||
await this.preferences.put(key, value);
|
||||
await this.preferences.flush();
|
||||
@ -76,10 +76,10 @@ export default class PreferencesHandler {
|
||||
* @param defValue any
|
||||
* @return data about key
|
||||
*/
|
||||
public async get(key: string, defValue?) {
|
||||
let data;
|
||||
public async get(key: string) {
|
||||
let data: string = '';
|
||||
if (this.preferences != null) {
|
||||
data = await this.preferences.get(key, defValue == null ? this.defaultValue : defValue);
|
||||
data = await this.preferences.get(key, this.defaultValue) as string;
|
||||
}
|
||||
return data;
|
||||
}
|
||||
@ -98,13 +98,13 @@ export default class PreferencesHandler {
|
||||
*
|
||||
* @return data
|
||||
*/
|
||||
public async getAll() {
|
||||
let data;
|
||||
if (this.preferences != null) {
|
||||
data = await this.preferences.getAll();
|
||||
}
|
||||
return data;
|
||||
}
|
||||
// public async getAll() {
|
||||
// let data;
|
||||
// if (this.preferences != null) {
|
||||
// data = await this.preferences.getAll();
|
||||
// }
|
||||
// return data;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Add preferences listener in PreferencesHandler.
|
||||
|
@ -22,5 +22,5 @@ export default interface PreferencesListener {
|
||||
*
|
||||
* @param key string
|
||||
*/
|
||||
onDataChanged(key: string): void
|
||||
onDataChanged: (key: string) => void
|
||||
}
|
||||
|
@ -14,9 +14,9 @@
|
||||
*/
|
||||
|
||||
import router from '@ohos.router';
|
||||
import { PARAM_KEY, CommonConstants } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from '../common/bean/AlarmItemBean';
|
||||
import AlarmSettingBean from '../common/bean/AlarmSettingBean';
|
||||
import { CommonConstants } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from '../viewmodel/AlarmItemBean';
|
||||
import AlarmSettingBean from '../viewmodel/AlarmSettingBean';
|
||||
import { AlarmSettingType } from '../common/constants/AlarmSettingType';
|
||||
import { DetailConstant } from '../common/constants/DetailConstant';
|
||||
import BackContainer from '../view/BackContainer';
|
||||
@ -32,13 +32,19 @@ struct DetailIndex {
|
||||
@State repeatSettingArr: Array<AlarmSettingBean> = [];
|
||||
@State alarmSettingInfoArr: Array<AlarmSettingBean> = [];
|
||||
private isNow: boolean = true;
|
||||
private viewModel: DetailModel = DetailModel.getInstant();
|
||||
private viewModel: DetailModel = DetailModel.instant;
|
||||
|
||||
aboutToAppear() {
|
||||
if (router.getParams() != null && router.getParams().hasOwnProperty(PARAM_KEY)) {
|
||||
this.isNow = false;
|
||||
this.alarmItem = router.getParams()[PARAM_KEY];
|
||||
this.viewModel.setAlarmDefaultTime(this.alarmItem);
|
||||
let params = router.getParams() as Record<string, Object|undefined>;
|
||||
if (params !== undefined) {
|
||||
let alarmItem: AlarmItem = params.alarmItem as AlarmItem;
|
||||
if (alarmItem !== undefined) {
|
||||
this.isNow = false;
|
||||
this.alarmItem = alarmItem;
|
||||
this.viewModel.setAlarmDefaultTime(this.alarmItem);
|
||||
}else {
|
||||
this.viewModel.setAlarmDefaultTime();
|
||||
}
|
||||
} else {
|
||||
this.viewModel.setAlarmDefaultTime();
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import router from '@ohos.router';
|
||||
import { CommonConstants } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from '../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../viewmodel/AlarmItemBean';
|
||||
import { MainConstant } from '../common/constants/MainConstant';
|
||||
import MainModel from '../viewmodel/MainViewModel';
|
||||
import ClockArea from './../view/Main/ClockArea';
|
||||
@ -25,7 +25,7 @@ import DimensionUtil from '../common/utils/DimensionUtil';
|
||||
@Entry
|
||||
@Component
|
||||
struct MainIndex {
|
||||
private mainModel: MainModel = MainModel.getInstant();
|
||||
private mainModel: MainModel = MainModel.instant;
|
||||
@State alarmItems: Array<AlarmItem> = new Array();
|
||||
@State isAuth: boolean = false;
|
||||
|
||||
|
@ -19,10 +19,10 @@ import DimensionUtil from '../common/utils/DimensionUtil';
|
||||
|
||||
@Component
|
||||
export default struct BackContainer {
|
||||
private header: string | Resource;
|
||||
private backImgRes: string | Resource;
|
||||
private backFunc: () => void;
|
||||
@BuilderParam closer: () => void;
|
||||
private header: string | Resource = $r('app.string.new_alarm');
|
||||
private backImgRes: string | Resource = $r('app.media.ic_cancel');
|
||||
private backFunc?: () => void;
|
||||
@BuilderParam closer?: () => void;
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
|
@ -16,20 +16,21 @@
|
||||
import { DetailConstant } from '../../common/constants/DetailConstant';
|
||||
import { CommonConstants } from '../../common/constants/CommonConstants';
|
||||
import DimensionUtil from '../../common/utils/DimensionUtil';
|
||||
import DayDataBean from '../../viewmodel/DayDateBean';
|
||||
|
||||
@Component
|
||||
export default struct DatePickArea {
|
||||
build() {
|
||||
Stack({ alignContent: Alignment.Center }) {
|
||||
Row() {
|
||||
ForEach(DetailConstant.DAY_DATA, (item) => {
|
||||
ForEach(DetailConstant.DAY_DATA, (item: DayDataBean) => {
|
||||
TextPicker({ range: item.data, selected: item.delSelect })
|
||||
.layoutWeight(CommonConstants.DEFAULT_LAYOUT_WEIGHT)
|
||||
.backgroundColor($r('app.color.grey_light'))
|
||||
.onChange((value: string, index: number) => {
|
||||
item.delSelect = index;
|
||||
})
|
||||
}, item => JSON.stringify(item))
|
||||
}, (item: DayDataBean) => JSON.stringify(item))
|
||||
}
|
||||
}
|
||||
.height(DimensionUtil.getVp($r('app.float.date_picker_height')))
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import { CommonConstants } from '../../common/constants/CommonConstants';
|
||||
import { AlarmSettingType } from '../../common/constants/AlarmSettingType';
|
||||
import AlarmSettingBean from '../../common/bean/AlarmSettingBean';
|
||||
import AlarmSettingBean from '../../viewmodel/AlarmSettingBean';
|
||||
import DimensionUtil from '../../common/utils/DimensionUtil';
|
||||
import IntervalDialog from './dialog/IntervalDialog';
|
||||
import DurationDialog from './dialog/DurationDialog';
|
||||
@ -63,7 +63,7 @@ export default struct SettingItem {
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
ForEach(this.settingInfo, (item: AlarmSettingBean, index: number) => {
|
||||
ForEach(this.settingInfo, (item: AlarmSettingBean, index: number | undefined) => {
|
||||
Divider()
|
||||
.visibility(index === 0 ? Visibility.Hidden : Visibility.Visible)
|
||||
.opacity($r('app.float.divider_opacity'))
|
||||
@ -101,7 +101,7 @@ export default struct SettingItem {
|
||||
.onClick(() => {
|
||||
this.showSettingDialog(item.sType);
|
||||
})
|
||||
}, (item, index) => JSON.stringify(item) + index)
|
||||
}, (item: AlarmSettingBean, index: number | undefined) => JSON.stringify(item) + index)
|
||||
}
|
||||
.margin({
|
||||
bottom: DimensionUtil.getVp($r('app.float.setting_item_interval')),
|
||||
|
@ -18,10 +18,12 @@ import DimensionUtil from '../../../common/utils/DimensionUtil';
|
||||
|
||||
@Component
|
||||
export default struct CommonDialog {
|
||||
private title: string | Resource;
|
||||
private controller: CustomDialogController;
|
||||
private onConfirm: () => void;
|
||||
@BuilderParam closer: () => void;
|
||||
private title?: string | Resource;
|
||||
private controller?: CustomDialogController;
|
||||
private onConfirm: () => void = () => {
|
||||
};
|
||||
@BuilderParam closer: () => void = () => {
|
||||
};
|
||||
|
||||
build() {
|
||||
Column() {
|
||||
@ -35,11 +37,17 @@ export default struct CommonDialog {
|
||||
this.closer()
|
||||
Row() {
|
||||
Button($r('app.string.cancel')).actionBtnStyle().onClick(() => {
|
||||
if (!this.controller) {
|
||||
return;
|
||||
}
|
||||
this.controller.close();
|
||||
})
|
||||
if (this.onConfirm) {
|
||||
Button($r('app.string.confirm')).actionBtnStyle().onClick(() => {
|
||||
this.onConfirm();
|
||||
if (!this.controller) {
|
||||
return;
|
||||
}
|
||||
this.controller.close();
|
||||
})
|
||||
}
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import { CommonConstants } from '../../../common/constants/CommonConstants';
|
||||
import { DetailConstant } from '../../../common/constants/DetailConstant';
|
||||
import AlarmItem from '../../../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../../../viewmodel/AlarmItemBean';
|
||||
import CommonDialog from './CommonDialog';
|
||||
import DimensionUtil from '../../../common/utils/DimensionUtil';
|
||||
|
||||
@ -23,7 +23,7 @@ import DimensionUtil from '../../../common/utils/DimensionUtil';
|
||||
export default struct DurationDialog {
|
||||
@Consume(DetailConstant.DEFAULT_PROVIDER_KEY) alarmItem: AlarmItem;
|
||||
private durations: Array<number> = DetailConstant.RING_DURATION; //响铃时长,分钟
|
||||
controller: CustomDialogController;
|
||||
controller?: CustomDialogController;
|
||||
|
||||
build() {
|
||||
Flex() {
|
||||
@ -31,17 +31,20 @@ export default struct DurationDialog {
|
||||
title: $r('app.string.ring_duration'),
|
||||
controller: this.controller
|
||||
}) {
|
||||
ForEach(this.durations, item => {
|
||||
ForEach(this.durations, (item: number) => {
|
||||
Row() {
|
||||
Text(item + CommonConstants.DEFAULT_STRING_SPACE + DetailConstant.DEFAULT_STRING_MINUTE)
|
||||
.layoutWeight(CommonConstants.DEFAULT_LAYOUT_WEIGHT)
|
||||
.fontColor($r('app.color.grey_divider'))
|
||||
.fontSize(DimensionUtil.getFp($r('app.float.duration_dialog_content_font_size')))
|
||||
Radio({ value: item, group: DetailConstant.DEFAULT_STRING_GROUP_NAME })
|
||||
Radio({ value: item.toString(), group: DetailConstant.DEFAULT_STRING_GROUP_NAME })
|
||||
.checked(item === this.alarmItem.duration ? true : false)
|
||||
.height(DimensionUtil.getVp($r('app.float.duration_dialog_radio_size')))
|
||||
.width(DimensionUtil.getVp($r('app.float.duration_dialog_radio_size')))
|
||||
.onChange(() => {
|
||||
if (!this.controller) {
|
||||
return;
|
||||
}
|
||||
this.controller.close();
|
||||
this.alarmItem.duration = item
|
||||
})
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import { CommonConstants } from '../../../common/constants/CommonConstants';
|
||||
import { DetailConstant } from '../../../common/constants/DetailConstant';
|
||||
import AlarmItem from '../../../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../../../viewmodel/AlarmItemBean';
|
||||
import CommonDialog from './CommonDialog';
|
||||
import DimensionUtil from '../../../common/utils/DimensionUtil';
|
||||
|
||||
@ -24,7 +24,7 @@ export default struct IntervalDialog {
|
||||
@Consume(DetailConstant.DEFAULT_PROVIDER_KEY) alarmItem: AlarmItem;
|
||||
@State intervalMinuteSelect: number = 0;
|
||||
@State intervalTimesSelect: number = 0;
|
||||
controller: CustomDialogController;
|
||||
controller?: CustomDialogController;
|
||||
|
||||
aboutToAppear(): void{
|
||||
this.intervalMinuteSelect = this.alarmItem.intervalMinute;
|
||||
|
@ -15,15 +15,18 @@
|
||||
|
||||
import { CommonConstants } from '../../../common/constants/CommonConstants';
|
||||
import { DetailConstant } from '../../../common/constants/DetailConstant';
|
||||
import AlarmItem from '../../../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../../../viewmodel/AlarmItemBean';
|
||||
import CommonDialog from './CommonDialog';
|
||||
import DimensionUtil from '../../../common/utils/DimensionUtil';
|
||||
|
||||
@CustomDialog
|
||||
export default struct RenameDialog {
|
||||
@Consume(DetailConstant.DEFAULT_PROVIDER_KEY) alarmItem: AlarmItem;
|
||||
private name: string;
|
||||
controller: CustomDialogController;
|
||||
private name: string = '';
|
||||
controller: CustomDialogController = new CustomDialogController({
|
||||
builder: RenameDialog(),
|
||||
autoCancel: true
|
||||
});
|
||||
|
||||
build() {
|
||||
Flex() {
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import { CommonConstants } from '../../../common/constants/CommonConstants';
|
||||
import { DetailConstant } from '../../../common/constants/DetailConstant';
|
||||
import AlarmItem from '../../../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../../../viewmodel/AlarmItemBean';
|
||||
import DetailModel from '../../../viewmodel/DetailViewModel';
|
||||
import CommonDialog from './CommonDialog';
|
||||
import DataTypeUtils from '../../../common/utils/DataTypeUtils';
|
||||
@ -24,9 +24,12 @@ import DimensionUtil from '../../../common/utils/DimensionUtil';
|
||||
@CustomDialog
|
||||
export default struct RepeatDialog {
|
||||
@Consume(DetailConstant.DEFAULT_PROVIDER_KEY) alarmItem: AlarmItem;
|
||||
private viewModel: DetailModel = DetailModel.getInstant();
|
||||
private viewModel: DetailModel = DetailModel.instant;
|
||||
private selects: number[] = [];
|
||||
controller: CustomDialogController;
|
||||
controller: CustomDialogController = new CustomDialogController({
|
||||
builder: RepeatDialog(),
|
||||
autoCancel: true
|
||||
});
|
||||
|
||||
aboutToAppear() {
|
||||
this.selects = DataTypeUtils.deepCopy(this.alarmItem.repeatDays);
|
||||
@ -43,14 +46,14 @@ export default struct RepeatDialog {
|
||||
this.alarmItem.isRepeat = this.selects.length > 0;
|
||||
}
|
||||
}) {
|
||||
ForEach(DetailConstant.WEEKDAY_DATA, (item) => {
|
||||
ForEach(DetailConstant.WEEKDAY_DATA, (item: number) => {
|
||||
Row() {
|
||||
Text(this.viewModel.transAlarmRepeatDayContent(item))
|
||||
.layoutWeight(CommonConstants.DEFAULT_LAYOUT_WEIGHT)
|
||||
.fontColor($r('app.color.grey_divider'))
|
||||
.fontSize(DimensionUtil.getFp($r('app.float.repeat_dialog_check_font_size')))
|
||||
|
||||
Checkbox({ name: item })
|
||||
Checkbox({ name: item.toString() })
|
||||
.select(this.alarmItem.repeatDays.indexOf(item) !== CommonConstants.DEFAULT_NUMBER_NEGATIVE)
|
||||
.width(DimensionUtil.getVp($r('app.float.repeat_dialog_check_box_size')))
|
||||
.height(DimensionUtil.getVp($r('app.float.repeat_dialog_check_box_size')))
|
||||
|
@ -15,7 +15,7 @@
|
||||
|
||||
import router from '@ohos.router';
|
||||
import { CommonConstants } from '../../common/constants/CommonConstants';
|
||||
import AlarmItem from '../../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../../viewmodel/AlarmItemBean';
|
||||
import AlarmListItem from '../Main/AlarmListItem';
|
||||
import DimensionUtil from '../../common/utils/DimensionUtil';
|
||||
|
||||
@ -31,7 +31,7 @@ export default struct AlarmList {
|
||||
}.onClick(() => {
|
||||
router.pushUrl({ url: "pages/DetailIndex", params: { alarmItem: item } });
|
||||
})
|
||||
}, item => JSON.stringify(item))
|
||||
}, (item: AlarmItem) => JSON.stringify(item))
|
||||
}
|
||||
.padding({
|
||||
left: DimensionUtil.getVp($r('app.float.alarm_list_content_distance')),
|
||||
|
@ -15,13 +15,13 @@
|
||||
|
||||
import MainModel from './../../viewmodel/MainViewModel';
|
||||
import { CommonConstants } from '../../common/constants/CommonConstants';
|
||||
import AlarmItem from '../../common/bean/AlarmItemBean';
|
||||
import AlarmItem from '../../viewmodel/AlarmItemBean';
|
||||
import DimensionUtil from '../../common/utils/DimensionUtil';
|
||||
|
||||
@Component
|
||||
export default struct AlarmListItem {
|
||||
private mainModel: MainModel = MainModel.getInstant();
|
||||
private alarmItem: AlarmItem;
|
||||
private mainModel: MainModel = MainModel.instant;
|
||||
private alarmItem: AlarmItem = new AlarmItem();
|
||||
|
||||
build() {
|
||||
Row() {
|
||||
@ -40,7 +40,7 @@ export default struct AlarmListItem {
|
||||
.CommonTextAttr(DimensionUtil.getFp($r('app.float.alarms_item_dec_font_size')),
|
||||
FontWeight.Normal,
|
||||
{ top: DimensionUtil.getVp($r('app.float.alarms_item_dec_margin_top')) },
|
||||
$r('app.float.alarms_item_desc_text_opacity'))
|
||||
$r('app.float.alarms_item_desc_text_opacity'))
|
||||
}
|
||||
.width(CommonConstants.FULL_LENGTH)
|
||||
.alignItems(HorizontalAlign.Start)
|
||||
@ -64,10 +64,10 @@ export default struct AlarmListItem {
|
||||
}
|
||||
}
|
||||
|
||||
@Extend(Text) function CommonTextAttr (fontSize: number, fontWeight: number, margin?, opacity?) {
|
||||
@Extend(Text) function CommonTextAttr (fontSize: number, fontWeight: number, margin?: Margin, opacity?: Resource) {
|
||||
.fontColor($r('app.color.grey_divider'))
|
||||
.fontSize(fontSize)
|
||||
.fontWeight(fontWeight)
|
||||
.margin(margin)
|
||||
.opacity(opacity)
|
||||
.margin(margin ? margin : '')
|
||||
.opacity(opacity ? opacity : 1.0)
|
||||
}
|
@ -20,16 +20,16 @@ import DimensionUtil from '../../common/utils/DimensionUtil';
|
||||
|
||||
@Component
|
||||
export default struct ClockArea {
|
||||
private mainModel: MainModel;
|
||||
private drawInterval: any = CommonConstants.DEFAULT_NUMBER_NEGATIVE;
|
||||
private mainModel: MainModel = MainModel.instant;
|
||||
private drawInterval: number = CommonConstants.DEFAULT_NUMBER_NEGATIVE;
|
||||
@State showClock: boolean = true;
|
||||
private canvasSize: number;
|
||||
private clockRadius: number;
|
||||
private canvasSize: number = DimensionUtil.getVp($r('app.float.clock_size'));
|
||||
private clockRadius: number = this.canvasSize / CommonConstants.DEFAULT_DOUBLE - CommonConstants.DEFAULT_DOUBLE;
|
||||
private settings: RenderingContextSettings = new RenderingContextSettings(true);
|
||||
private renderContext: CanvasRenderingContext2D = new CanvasRenderingContext2D(this.settings);
|
||||
|
||||
aboutToAppear() {
|
||||
this.mainModel = MainModel.getInstant();
|
||||
this.mainModel = MainModel.instant;
|
||||
this.canvasSize = DimensionUtil.getVp($r('app.float.clock_size'));
|
||||
this.clockRadius = this.canvasSize / CommonConstants.DEFAULT_DOUBLE - CommonConstants.DEFAULT_DOUBLE;
|
||||
}
|
||||
@ -100,9 +100,9 @@ export default struct ClockArea {
|
||||
}
|
||||
|
||||
// 绘制时针、分针、秒针
|
||||
private drawPointer(degree, pointerImgRes) {
|
||||
private drawPointer(degree: number, pointerImgRes: string) {
|
||||
this.renderContext.save();
|
||||
var theta = (degree + MainConstant.DEFAULT_HORIZONTAL_ANGLE) * Math.PI / MainConstant.DEFAULT_HORIZONTAL_ANGLE;
|
||||
let theta = (degree + MainConstant.DEFAULT_HORIZONTAL_ANGLE) * Math.PI / MainConstant.DEFAULT_HORIZONTAL_ANGLE;
|
||||
this.renderContext.rotate(theta);
|
||||
this.renderContext.beginPath();
|
||||
let secondImg = new ImageBitmap(pointerImgRes);
|
||||
|
@ -52,5 +52,5 @@ import ReminderItem from './ReminderItemBean';
|
||||
/**
|
||||
* Custom alarm notification id.
|
||||
*/
|
||||
notificationId: number;
|
||||
notificationId: number = 0;
|
||||
}
|
@ -13,7 +13,7 @@
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
import { AlarmSettingType } from '../constants/AlarmSettingType';
|
||||
import { AlarmSettingType } from '../common/constants/AlarmSettingType';
|
||||
|
||||
/**
|
||||
* Alarm setting bean information.
|
||||
@ -34,7 +34,7 @@ export default class AlarmSettingBean {
|
||||
*/
|
||||
public sType: AlarmSettingType;
|
||||
|
||||
constructor(title, content, sType) {
|
||||
constructor(title: string, content: string, sType: AlarmSettingType){
|
||||
this.title = title;
|
||||
this.content = content;
|
||||
this.sType = sType;
|
@ -0,0 +1,20 @@
|
||||
/*
|
||||
* Copyright (c) 2023 Huawei Device Co., Ltd.
|
||||
* Licensed under the Apache License,Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
export default class DayDataBean {
|
||||
timeType: number = 0;
|
||||
delSelect: number = 0;
|
||||
data: Array<string> = [];
|
||||
}
|
@ -14,16 +14,18 @@
|
||||
*/
|
||||
|
||||
import { DetailConstant } from '../common/constants/DetailConstant';
|
||||
import { ALARM_KEY, CommonConstants } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from '../common/bean/AlarmItemBean';
|
||||
import { CommonConstants, WeekDays } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from './AlarmItemBean';
|
||||
import ReminderService from '../model/ReminderService';
|
||||
import DataTypeUtils from '../common/utils/DataTypeUtils';
|
||||
import { GlobalContext } from '../common/utils/GlobalContext';
|
||||
import PreferencesHandler from '../model/database/PreferencesHandler';
|
||||
|
||||
/**
|
||||
* Detail page view model description
|
||||
*/
|
||||
export default class DetailViewModel {
|
||||
private static instant;
|
||||
static instant: DetailViewModel = new DetailViewModel();
|
||||
private reminderService: ReminderService;
|
||||
private alarms: Array<AlarmItem>;
|
||||
|
||||
@ -37,12 +39,12 @@ export default class DetailViewModel {
|
||||
*
|
||||
* @return instance
|
||||
*/
|
||||
public static getInstant() {
|
||||
if (this.instant == null) {
|
||||
this.instant = new DetailViewModel();
|
||||
}
|
||||
return this.instant;
|
||||
}
|
||||
// public static getInstant() {
|
||||
// if (this.instant == null) {
|
||||
// this.instant = new DetailViewModel();
|
||||
// }
|
||||
// return this.instant;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Conversion alarm repeat day content
|
||||
@ -51,27 +53,27 @@ export default class DetailViewModel {
|
||||
* @return repeatContent string
|
||||
*/
|
||||
public transAlarmRepeatDayContent(repeatDay: number): string{
|
||||
let repeatContent;
|
||||
let repeatContent: string = CommonConstants.DEFAULT_STRING_MONDAY;;
|
||||
switch (repeatDay) {
|
||||
case CommonConstants.DEFAULT_NUMBER_MONDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_MONDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_MONDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_TUESDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_TUESDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_TUESDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_WEDNESDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_WEDNESDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_WEDNESDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_THURSDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_THURSDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_THURSDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_FRIDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_FRIDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_FRIDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_SATURDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_SATURDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_SATURDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_SUNDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_SUNDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_SUNDAY;
|
||||
break;
|
||||
default:
|
||||
@ -86,8 +88,8 @@ export default class DetailViewModel {
|
||||
* @param alarmItem AlarmItem
|
||||
*/
|
||||
public setAlarmDefaultTime(alarmItem?: AlarmItem) {
|
||||
let hour;
|
||||
let minute;
|
||||
let hour: number;
|
||||
let minute: number;
|
||||
if (alarmItem == null) {
|
||||
let date = new Date();
|
||||
hour = date.getHours();
|
||||
@ -123,11 +125,12 @@ export default class DetailViewModel {
|
||||
alarmItem.notificationId = index;
|
||||
this.alarms.push(alarmItem);
|
||||
}
|
||||
this.reminderService.addReminder(alarmItem, (newId) => {
|
||||
this.reminderService.addReminder(alarmItem, (newId: number) => {
|
||||
alarmItem.id = newId;
|
||||
alarmItem.isOpen = true;
|
||||
this.alarms[index] = alarmItem;
|
||||
globalThis.preference.set(ALARM_KEY, JSON.stringify(this.alarms));
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.set(CommonConstants.ALARM_KEY, JSON.stringify(this.alarms));
|
||||
})
|
||||
}
|
||||
|
||||
@ -142,7 +145,8 @@ export default class DetailViewModel {
|
||||
if (index !== CommonConstants.DEFAULT_NUMBER_NEGATIVE) {
|
||||
this.alarms.splice(index, CommonConstants.DEFAULT_SINGLE);
|
||||
}
|
||||
globalThis.preference.set(ALARM_KEY, JSON.stringify(this.alarms));
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.set(CommonConstants.ALARM_KEY, JSON.stringify(this.alarms));
|
||||
}
|
||||
|
||||
private getAlarmTime(aType: number): number{
|
||||
@ -159,7 +163,8 @@ export default class DetailViewModel {
|
||||
}
|
||||
|
||||
private async findAlarmWithId(id: number) {
|
||||
let data = await globalThis.preference.get(ALARM_KEY);
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
let data = await preference.get(CommonConstants.ALARM_KEY);
|
||||
if (!DataTypeUtils.isNull(data)) {
|
||||
this.alarms = JSON.parse(data);
|
||||
for (let i = 0;i < this.alarms.length; i++) {
|
||||
|
@ -15,19 +15,20 @@
|
||||
|
||||
import { MainConstant } from '../common/constants/MainConstant';
|
||||
import ReminderService from '../model/ReminderService';
|
||||
import { ALARM_KEY, CommonConstants } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from '../common/bean/AlarmItemBean';
|
||||
import { CommonConstants, WeekDays } from '../common/constants/CommonConstants';
|
||||
import AlarmItem from './AlarmItemBean';
|
||||
import DataTypeUtils from '../common/utils/DataTypeUtils';
|
||||
import { GlobalContext } from '../common/utils/GlobalContext';
|
||||
import PreferencesHandler from '../model/database/PreferencesHandler';
|
||||
import PreferencesListener from '../model/database/PreferencesListener';
|
||||
|
||||
/**
|
||||
* Declare class of main view model.
|
||||
*/
|
||||
export default class MainViewModel {
|
||||
private static instant;
|
||||
static instant: MainViewModel = new MainViewModel();
|
||||
private reminderService: ReminderService;
|
||||
private alarms: Array<AlarmItem>;
|
||||
private drawInterval: any = CommonConstants.DEFAULT_NUMBER_NEGATIVE;
|
||||
private showClock: boolean = true;
|
||||
|
||||
private constructor() {
|
||||
this.alarms = new Array();
|
||||
@ -38,12 +39,12 @@ export default class MainViewModel {
|
||||
/**
|
||||
* Get instant in MainViewModel.
|
||||
*/
|
||||
public static getInstant() {
|
||||
if (this.instant == null) {
|
||||
this.instant = new MainViewModel();
|
||||
}
|
||||
return this.instant;
|
||||
}
|
||||
// public static getInstant() {
|
||||
// if (this.instant == null) {
|
||||
// this.instant = new MainViewModel();
|
||||
// }
|
||||
// return this.instant;
|
||||
// }
|
||||
|
||||
/**
|
||||
* Querying alarm task database tables.
|
||||
@ -51,7 +52,8 @@ export default class MainViewModel {
|
||||
* @param callback (alarms: Array<AlarmItem>) => void
|
||||
*/
|
||||
private queryDatabaseAlarms(callback: (alarms: Array<AlarmItem>) => void) {
|
||||
globalThis.preference.get(ALARM_KEY).then((data) => {
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.get(CommonConstants.ALARM_KEY).then((data: string) => {
|
||||
if (!DataTypeUtils.isNull(data)) {
|
||||
this.alarms = JSON.parse(data);
|
||||
callback(this.alarms);
|
||||
@ -67,11 +69,12 @@ export default class MainViewModel {
|
||||
public queryAlarmsTasker(callback: (alarms: Array<AlarmItem>) => void) {
|
||||
let that = this;
|
||||
that.queryDatabaseAlarms(callback);
|
||||
globalThis.preference.addPreferencesListener({
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.addPreferencesListener({
|
||||
onDataChanged() {
|
||||
that.queryDatabaseAlarms(callback);
|
||||
}
|
||||
})
|
||||
} as PreferencesListener)
|
||||
}
|
||||
|
||||
/**
|
||||
@ -132,29 +135,29 @@ export default class MainViewModel {
|
||||
*/
|
||||
public getAlarmRepeatDayContent(repeatDays: Array<number>): string{
|
||||
let content = MainConstant.DEFAULT_STRING_NULL;
|
||||
for (var i = 0; i < repeatDays.length; i++) {
|
||||
for (let i = 0; i < repeatDays.length; i++) {
|
||||
let repeatDay = repeatDays[i];
|
||||
let repeatContent;
|
||||
let repeatContent: string = CommonConstants.DEFAULT_STRING_MONDAY;
|
||||
switch (repeatDay) {
|
||||
case CommonConstants.DEFAULT_NUMBER_MONDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_MONDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_MONDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_TUESDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_TUESDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_TUESDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_WEDNESDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_WEDNESDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_WEDNESDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_THURSDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_THURSDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_THURSDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_FRIDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_FRIDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_FRIDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_SATURDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_SATURDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_SATURDAY;
|
||||
break;
|
||||
case CommonConstants.DEFAULT_NUMBER_SUNDAY:
|
||||
case WeekDays.DEFAULT_NUMBER_SUNDAY:
|
||||
repeatContent = CommonConstants.DEFAULT_STRING_SUNDAY;
|
||||
break;
|
||||
default:
|
||||
@ -180,7 +183,8 @@ export default class MainViewModel {
|
||||
} else {
|
||||
this.reminderService.deleteReminder(this.alarms[i].id);
|
||||
}
|
||||
globalThis.preference.set(ALARM_KEY, JSON.stringify(this.alarms));
|
||||
let preference = GlobalContext.getContext().getObject('preference') as PreferencesHandler;
|
||||
preference.set(CommonConstants.ALARM_KEY, JSON.stringify(this.alarms));
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -16,15 +16,15 @@
|
||||
import reminderAgent from '@ohos.reminderAgentManager';
|
||||
|
||||
export default class ReminderItemBean {
|
||||
id: number;
|
||||
id: number = 0;
|
||||
remindType: reminderAgent.ReminderType = reminderAgent.ReminderType.REMINDER_TYPE_ALARM;
|
||||
name: string;
|
||||
hour: number;
|
||||
minute: number;
|
||||
duration: number;
|
||||
intervalMinute: number;
|
||||
intervalTimes: number;
|
||||
name: string = '';
|
||||
hour: number = 0;
|
||||
minute: number = 0;
|
||||
duration: number = 0;
|
||||
intervalMinute: number = 0;
|
||||
intervalTimes: number = 0;
|
||||
repeatDays: Array<number> = [];
|
||||
notificationId: number;
|
||||
notificationId: number = 0;
|
||||
}
|
||||
|
@ -35,14 +35,7 @@
|
||||
],
|
||||
"requestPermissions": [
|
||||
{
|
||||
"name": "ohos.permission.PUBLISH_AGENT_REMINDER",
|
||||
"reason": "$string:reason",
|
||||
"usedScene": {
|
||||
"abilities": [
|
||||
"EntryAbility"
|
||||
],
|
||||
"when": "inuse"
|
||||
}
|
||||
"name": "ohos.permission.PUBLISH_AGENT_REMINDER"
|
||||
}
|
||||
]
|
||||
}
|
||||
|
@ -59,10 +59,6 @@
|
||||
{
|
||||
"name": "main_page_title_font_family",
|
||||
"value": "HarmonyHeiTi-Bold"
|
||||
},
|
||||
{
|
||||
"name": "reason",
|
||||
"value": "通知"
|
||||
}
|
||||
]
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"hvigorVersion": "2.0.0",
|
||||
"hvigorVersion": "2.4.2",
|
||||
"dependencies": {
|
||||
"@ohos/hvigor-ohos-plugin": "2.0.0"
|
||||
"@ohos/hvigor-ohos-plugin": "2.4.2"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user