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