• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2022-2023 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 *     http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16import router from '@ohos.router'
17import contact from '@ohos.contact'
18import Logger from '../data/Logger'
19
20const TAG: string = 'ContactInfo'
21
22@Preview
23@Component
24export struct ContactInfo {
25  @State contact: contact.Contact = undefined
26
27  build() {
28    Column() {
29      Column() {
30        Text(this.contact.name.fullName.substring(0, 1)
31          .toUpperCase())
32          .width(130)
33          .height(130)
34          .fontSize(30)
35          .fontColor(Color.White)
36          .borderRadius(100)
37          .margin({ top: 62, bottom: 22 })
38          .textAlign(TextAlign.Center)
39          .backgroundColor($r('app.color.user_name_color'))
40
41        Text(this.contact.name.fullName)
42          .fontSize(32)
43          .margin({ bottom: 16 })
44
45        Column() {
46          Row() {
47            if (this.contact.phoneNumbers !== undefined) {
48              Text(this.contact.phoneNumbers[0].phoneNumber)
49                .width('50%')
50                .fontSize(22)
51                .margin({ left: 16 })
52            } else {
53              Text()
54                .width('50%')
55                .fontSize(22)
56                .margin({ left: 16 })
57            }
58
59            Blank()
60
61            Image($r('app.media.phone2'))
62              .width(32)
63              .height(32)
64              .margin({ right: 24 })
65              .objectFit(ImageFit.Contain)
66
67            Image($r('app.media.note'))
68              .width(32)
69              .height(32)
70              .margin({ right: 24 })
71              .objectFit(ImageFit.Contain)
72          }
73          .width('100%')
74          .height('50%')
75
76          Divider()
77            .width('90%')
78            .strokeWidth(1)
79            .color($r('app.color.color5'))
80
81          Row() {
82            Column() {
83              Text($r('app.string.defaults'))
84                .fontSize(22)
85                .margin({ left: 16 })
86              Text($r('app.string.phone_ring'))
87                .fontSize(20)
88                .fontColor(Color.Gray)
89                .margin({ left: 16 })
90            }
91            .alignItems(HorizontalAlign.Start)
92
93            Blank()
94              .width('52%')
95
96            Image($r('app.media.right'))
97              .width(16)
98              .height(32)
99              .margin({ right: 24 })
100          }
101          .width('100%')
102          .height('50%')
103        }
104        .width('90%')
105        .height(178)
106        .borderRadius(30)
107        .backgroundColor(Color.White)
108      }
109
110      Blank()
111
112      Divider()
113        .strokeWidth(0.65)
114        .color(Color.Black)
115        .opacity(0.05)
116
117      Row() {
118        Column() {
119          Image($r('app.media.editor'))
120            .width(32)
121            .height(32)
122            .margin({ top: 6 })
123            .objectFit(ImageFit.Contain)
124
125          Text($r('app.string.editor'))
126            .fontSize(14)
127            .fontColor(Color.Black)
128            .margin(4)
129            .borderRadius(10)
130        }
131        .id('editContact')
132        .onClick(() => {
133          router.pushUrl({
134            url: 'pages/EditContact',
135            params: { data: this.contact }
136          })
137        })
138        .layoutWeight(1)
139
140        Column() {
141          Image($r('app.media.delete'))
142            .width(32)
143            .height(32)
144            .margin({ top: 6 })
145            .objectFit(ImageFit.Contain)
146
147          Text($r('app.string.delete'))
148            .fontSize(14)
149            .fontColor(Color.Black)
150            .borderRadius(10)
151        }
152        .id('deleteContact')
153        .onClick(async () => {
154          AlertDialog.show(
155            {
156              title: $r('app.string.warning'),
157              message: $r('app.string.delete_show'),
158              primaryButton: {
159                value: $r('app.string.confirm'),
160                action: async () => {
161                  await contact.deleteContact(this.contact.key)
162                  router.replaceUrl({
163                    url: 'pages/Index'
164                  })
165                  router.clear()
166                }
167              },
168              secondaryButton: {
169                value: $r('app.string.cancel'),
170                action: () => {
171                  Logger.info(TAG, `AlertDialog enter`)
172                }
173              },
174              cancel: () => {
175                Logger.info(TAG, `AlertDialog close`)
176              }
177            })
178        })
179        .layoutWeight(1)
180      }
181      .width('100%')
182      .height('20%')
183      .margin({ bottom: 10 })
184    }
185    .width('100%')
186    .height('100%')
187    .backgroundColor($r('app.color.index_bg'))
188  }
189}