• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1import router from '@ohos.router';
2import sim from '@ohos.telephony.sim';
3import { ApnInfo } from '../common/constant/apnInfo';
4import { PreferenceUtil } from '../common/utils/PreferenceUtil';
5import { ApnDataStorage } from '../model/apnDataStorage';
6import common from '@ohos.app.ability.common';
7import { ApnDetailDataConst } from '../common/constant/apnData';
8
9@Entry
10@Component
11struct ApnList {
12  private storage: ApnDataStorage = new ApnDataStorage()
13  @State apnList: ApnInfo[] = []
14  @State mccmnc: string = ''
15  // @State iccID: string = ''
16  @State selectedApn: number = -1
17  private cardTpye: number = 0
18  @StorageLink('ApnStatus') @Watch('queryApnList') apnStatus: boolean = false;
19
20  async aboutToAppear() {
21    this.storage.initData(getContext() as common.UIAbilityContext).then(() => {
22      this.queryApnList()
23    })
24    this.mccmnc = sim.getSimOperatorNumericSync(this.cardTpye)
25    // this.iccID = await sim.getSimIccId(this.cardTpye)
26    this.selectedApn = Number(PreferenceUtil.get('select_apn_common_' + this.mccmnc, -1))
27
28  }
29
30  queryApnList() {
31    this.apnList = []
32    this.storage.queryApnList(this.mccmnc).then((resultSet) => {
33      if (resultSet == null) {
34        return
35	  }
36      while (resultSet.goToNextRow()) {
37        let info: ApnInfo = new ApnInfo()
38        info.profile_id = resultSet.getLong(resultSet.getColumnIndex(ApnDetailDataConst.PROFILE_ID));
39        info.profile_name = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.PROFILE_NAME));
40        info.mcc = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.MCC));
41        info.mnc = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.MNC));
42        info.mccmnc = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.MCCMNC));
43        info.apn = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.APN));
44        info.auth_type = resultSet.getLong(resultSet.getColumnIndex(ApnDetailDataConst.AUTH_TYPE));
45        info.auth_user = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.AUTH_USER));
46        info.auth_pwd = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.AUTH_PWD));
47        info.apn_types = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.APN_TYPES));
48        info.is_roaming_apn = resultSet.getLong(resultSet.getColumnIndex(ApnDetailDataConst.IS_ROAMING_APN));
49        info.apn_protocol = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.APN_PROTOCOL));
50        info.apn_roam_protocol = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.APN_ROAM_PROTOCOL));
51        info.home_url = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.HOME_URL));
52        info.mms_ip_address = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.MMS_IP_ADDRESS));
53        info.proxy_ip_address = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.PROXY_IP_ADDRESS));
54        info.bearing_system_type = resultSet.getLong(resultSet.getColumnIndex(ApnDetailDataConst.BEARING_SYSTEM_TYPE));
55        info.mvno_type = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.MVNO_TYPE));
56        info.mvno_match_data = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.MVNO_MATCH_DATA));
57        info.edited = resultSet.getLong(resultSet.getColumnIndex(ApnDetailDataConst.EDITED));
58        info.server = resultSet.getString(resultSet.getColumnIndex(ApnDetailDataConst.SERVER));
59        this.apnList.push(info)
60        let id = PreferenceUtil.get('select_apn_common_' + this.mccmnc, -1)
61        if (id == -1) {
62          PreferenceUtil.put('select_apn_common_' + this.mccmnc, resultSet.getLong(resultSet.getColumnIndex('profile_id')))
63        }
64        this.selectedApn = Number(PreferenceUtil.get('select_apn_common_' + this.mccmnc, -1))
65      }
66    })
67  }
68
69  build() {
70    Column() {
71      Row() {
72        Row() {
73          Stack({ alignContent: Alignment.Center }) {
74            Image($r('app.media.ic_back'))
75              .width(24)
76              .height(24)
77              .fillColor($r('sys.color.ohos_id_color_primary'))
78          }
79          .margin({ right: 16 })
80          .backgroundColor($r('app.color.color_00000000_transparent'))
81          .onClick(() => {
82            router.back()
83          })
84
85          Text($r('app.string.apn_title'))
86            .fontSize(20)
87            .fontFamily('HarmonyHeiTi-Bold')
88            .fontWeight(FontWeight.Medium)
89            .fontColor($r('sys.color.ohos_id_color_text_primary'))
90            .maxLines(1)
91            .textOverflow({ overflow: TextOverflow.Ellipsis })
92            .textAlign(TextAlign.Start)
93            .margin({ top: 15, bottom: 15 });
94        }
95
96        Image($r('app.media.ic_add'))
97          .width(24)
98          .height(24)
99          .fillColor($r('sys.color.ohos_id_color_primary'))
100          .onClick((event: ClickEvent) => {
101            router.pushUrl({
102              url: 'pages/apnDetail'
103            })
104          })
105      }
106      .justifyContent(FlexAlign.SpaceBetween)
107      .width('100%')
108      .padding({ left: 12, right: 12 })
109      .height(56)
110      .alignItems(VerticalAlign.Center)
111      .align(Alignment.Start)
112
113      Column() {
114        List() {
115          ForEach(this.apnList, (item: ApnInfo) => {
116            ListItem() {
117              Row() {
118                Row() {
119                  Image($r('app.media.ic_redio_check'))
120                    .width(24)
121                    .height(24)
122                    .margin({ right: 10 })
123                    .visibility(item.profile_id === this.selectedApn ? Visibility.Visible : Visibility.Hidden)
124                  Column() {
125                    Text(item.profile_name)
126                      .fontFamily('HarmonyHeiTi')
127                      .fontSize($r('sys.float.ohos_id_text_size_body1'))
128                      .fontWeight(FontWeight.Medium)
129                      .fontColor($r('sys.color.ohos_id_color_text_primary'))
130                      .letterSpacing(1)
131                      .lineHeight(22)
132                      .textAlign(TextAlign.Start)
133                    Text(item.apn)
134                      .fontFamily('HarmonyHeiTi')
135                      .fontSize($r('sys.float.ohos_id_text_size_body2'))
136                      .fontWeight(FontWeight.Medium)
137                      .fontColor('#666666')
138                      .letterSpacing(1)
139                      .lineHeight(22)
140                      .textAlign(TextAlign.Start)
141                  }
142                  .justifyContent(FlexAlign.Start)
143                  .alignItems(HorizontalAlign.Start)
144                }
145
146                Navigator({ target: 'pages/apnDetail', type: NavigationType.Push }) {
147                  Image($r('app.media.ic_about_apn'))
148                    .padding(10)
149                    .width(40)
150                    .height(40)
151                    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
152                    .borderRadius(100)
153                }.params(item)
154
155              }
156              .height(80)
157              .width('96%')
158              .justifyContent(FlexAlign.SpaceBetween)
159              .borderRadius(15)
160              .backgroundColor(Color.White)
161              .margin({ top: 5, left: 10, right: 10, bottom: 5 })
162              .padding({ left: 10, right: 10 })
163            }.width('100%')
164            .margin({ bottom: '1px' })
165            .height(60)
166            .onClick((event: ClickEvent) => {
167              if (this.selectedApn != item.profile_id) {
168                this.storage.initData(getContext() as common.UIAbilityContext).then(() => {
169                  this.storage.updateXmlPeofileID(1, item.profile_id)
170                    .then((success) => {
171                      PreferenceUtil.put('select_apn_common_' + this.mccmnc, item.profile_id)
172                      this.selectedApn = item.profile_id
173                      if (success) {
174                        router.back()
175                      }
176                    })
177                })
178              }
179            })
180          })
181        }
182        .width('100%')
183        .height('100%')
184        .margin({ bottom: 20 })
185      }.layoutWeight(1)
186      .width('100%')
187    }
188    .backgroundColor($r('sys.color.ohos_id_color_sub_background'))
189    .width('100%')
190    .height('100%')
191  }
192}
193