• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/*
2 * Copyright (c) 2023-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 SelectionModel from '../../Model/SelectionModel'
17import { Log } from '@ohos/common';
18import CheckEmptyUtils from '@ohos/common';
19import WifiP2pHelper from '../../Common/Adapter/WifiP2pHelper';
20import { Constants, Duplex, PrinterInfo } from '@ohos/common';
21
22const TAG = 'SelectComponent'
23
24@Extend(Row) function selectStyle() {
25  .width($r('app.float.select_comp_width'))
26  .height($r('app.float.params_comp_height'))
27  .margin({ top: $r('app.float.select_comp_margin_top'), bottom: $r('app.float.select_comp_margin_bottom')
28  , left: $r('app.float.select_comp_margin_left'), right: $r('app.float.select_comp_margin_right') })
29  .border({ width: $r('app.float.border_width'), radius: $r('app.float.radius_s'), color: $r('app.color.border_line') })
30}
31
32@Extend(Row) function selectItemStyle() {
33  .width($r('app.float.select_item_width'))
34  .height($r('app.float.select_item_height'))
35  .justifyContent(FlexAlign.Start)
36  .margin({ top: $r('app.float.select_item_margin_top'), bottom: $r('app.float.select_item_margin_bottom') })
37  .borderRadius($r('app.float.radius_m'))
38}
39
40@Component
41export struct PrinterSelection {
42  @Consume('PrinterSelectArray') selectArray: Array<SelectionModel>;
43  @Consume('CurrentPrinter') currentPrinterSelection: SelectionModel;
44  @Consume('CanPrint') canPrint: boolean;
45  @Provide('PrinterPopup') customPopup: boolean = false
46  @State bgColor: Resource = $r('app.color.effect_color_white');
47
48  @Builder popupBuilder() {
49    if (this.customPopup){
50      List() {
51        ForEach(this.selectArray, (select: SelectionModel) => {
52          ListItem() {
53            PrinterSelectionComponent({ selection: select })
54          }.key(`Selection_ListItem_${select.name}`)
55        }, (select: SelectionModel) => select.name)
56      }
57      .edgeEffect(EdgeEffect.Spring)
58      .width($r('app.float.select_comp_width'))
59      .padding($r('app.float.select_comp_padding'))
60    }
61  }
62
63  build() {
64    Row() {
65      Text($r('app.string.index_printer'))
66        .fontSize($r('app.float.font_size_body2'))
67        .width($r('app.float.text_label_width'))
68        .textAlign(TextAlign.End)
69        .key('Index_Text_printer')
70      Row() {
71        LoadingProgress()
72          .width($r('app.float.select_loadingProgress_size'))
73          .height($r('app.float.select_loadingProgress_size'))
74          .margin({
75            left: $r('app.float.select_loadingProgress_margin_left'),
76            right: $r('app.float.select_loadingProgress_margin_right')
77          })
78          .key('Index_LoadingProgress_printer')
79          .visibility(this.checkLoading() ? Visibility.Visible : Visibility.None)
80        Text(this.currentPrinterSelection.res)
81          .fontSize($r('app.float.font_size_body2'))
82          .textAlign(TextAlign.Start)
83          .textOverflow({ overflow: TextOverflow.Ellipsis })
84          .maxLines(Constants.NUMBER_1)
85          .width(this.checkLoading() ? $r('app.float.select_checkLoading_true_width') : $r('app.float.select_checkLoading_false_width'))
86          .margin({
87            left: this.checkLoading() ? $r('app.float.select_checkLoading_true_margin_left') : $r('app.float.select_checkLoading_false_margin_left')
88          })
89        Image($r('app.media.ic_select_button'))
90          .height($r('app.float.select_image_button_size'))
91          .width($r('app.float.select_image_button_size'))
92          .margin({
93            left: $r('app.float.select_image_button_margin_left'),
94            right: $r('app.float.select_image_button_margin_right')
95          })
96      }
97      .key('Selection_Printer')
98      .selectStyle()
99      .onClick(() => {
100        this.customPopup = !this.customPopup
101      })
102      .bindPopup(this.customPopup, {
103        builder: this.popupBuilder,
104        placement: Placement.Bottom,
105        popupColor: Color.White,
106        enableArrow: false,
107        onStateChange: (e) => {
108          if (!e.isVisible) {
109            this.customPopup = false
110          }
111        }
112      })
113      .backgroundColor(this.bgColor)
114      .onHover((isHover: boolean) => {
115        if (isHover) {
116          this.bgColor = $r('app.color.effect_color_hover')
117        } else {
118          this.bgColor = $r('app.color.effect_color_white')
119        }
120      })
121      .onTouch((event: TouchEvent) => {
122        if (event.type === TouchType.Down) {
123          this.bgColor = $r('app.color.effect_color_press')
124        }
125        if (event.type === TouchType.Up) {
126          this.bgColor = $r('app.color.effect_color_white')
127        }
128      })
129    }.height($r('app.float.params_row_height')).width($r('app.float.params_row_width'))
130
131  }
132
133  aboutToAppear() {
134  }
135
136  checkLoading() {
137    let printer: PrinterInfo | undefined = SelectionModel.getSelectionValue<PrinterInfo>(this.currentPrinterSelection.name);
138    if ((!CheckEmptyUtils.isEmpty(printer)
139    && printer!.printerId !== '-1'
140    && !this.canPrint)) {
141      return true;
142    }
143    return false;
144  }
145}
146
147@Component
148struct PrinterSelectionComponent {
149  @Consume('CurrentPrinter') currentPrinterSelection: SelectionModel;
150  @Consume('PrinterPopup') customPopup: boolean
151  @Consume('PrinterSelectFlag') printerSelectFlag: boolean
152  @Consume('OpenWLANFlag') openWlanFlag: boolean
153  @State bgColor: Resource = $r('app.color.effect_color_white');
154  private selection?: SelectionModel;
155
156  build() {
157    Row() {
158      Text(this.selection!.res)
159        .textAlign(TextAlign.Start)
160        .fontSize($r('app.float.font_size_body2'))
161        .margin({ left: $r('app.float.select_text_margin_left'), right: $r('app.float.select_text_margin_right') })
162        .onTouch((event: TouchEvent) => {
163          if (event.type === TouchType.Down) {
164            this.bgColor = $r('app.color.effect_color_press')
165          }
166          if (event.type === TouchType.Up) {
167            this.bgColor = $r('app.color.effect_color_white')
168          }
169        })
170    }
171    .selectItemStyle()
172    .onClick(() => {
173      if (WifiP2pHelper.checkWifiActive()) {
174        this.printerSelectFlag = true
175      } else {
176        this.openWlanFlag = !this.openWlanFlag
177      }
178      this.customPopup = false
179    })
180    .backgroundColor(this.bgColor)
181    .onHover((isHover: boolean) => {
182      if (isHover) {
183        this.bgColor = $r('app.color.effect_color_hover')
184      } else {
185        this.bgColor = $r('app.color.effect_color_white')
186      }
187    })
188
189  }
190}
191
192
193@Component
194export struct MediaSizeSelection {
195  @Consume('MediaSizeSelectArray') selectArray: Array<SelectionModel>;
196  @Consume('CurrentMediaSize') currentMediaSize: SelectionModel;
197  @Provide('MediaSizePopup') customPopup: boolean = false;
198  @State bgColor: Resource = $r('app.color.effect_color_white');
199
200  @Builder popupBuilder() {
201    if (this.customPopup){
202      List() {
203        ForEach(this.selectArray, (select: SelectionModel) => {
204          ListItem() {
205            MediaSizeSelectionComponent({ selection: select })
206          }.key(`Selection_ListItem_${select.name}`)
207        }, (select: SelectionModel) => JSON.stringify(select))
208      }
209      .edgeEffect(EdgeEffect.Spring)
210      .scrollBar(this.selectArray.length > Constants.NUMBER_5 ? BarState.Auto : BarState.Off)
211      .height(this.selectArray.length > Constants.NUMBER_5 ?
212      $r('app.float.select_max_height') : this.selectArray.length * Constants.NUMBER_48)
213      .width($r('app.float.select_comp_width'))
214      .padding($r('app.float.select_comp_padding'))
215    }
216  }
217
218  build() {
219    Row() {
220      Text($r('app.string.index_media_size'))
221        .fontSize($r('app.float.font_size_body2'))
222        .width($r('app.float.text_label_width'))
223        .textAlign(TextAlign.End)
224        .key('Index_Text_mediaSize')
225      Row() {
226        Text(this.currentMediaSize.res).fontSize($r('app.float.font_size_body2')).textAlign(TextAlign.Start)
227          .width($r('app.float.select_text_width'))
228          .margin({ left: $r('app.float.select_text_margin_left') })
229        Image($r('app.media.ic_select_button'))
230          .height($r('app.float.select_image_button_size'))
231          .width($r('app.float.select_image_button_size'))
232          .margin({
233            left: $r('app.float.select_image_button_margin_left'),
234            right: $r('app.float.select_image_button_margin_right')
235          })
236      }
237      .key('Selection_MediaSize')
238      .selectStyle()
239      .backgroundColor(this.bgColor)
240      .onClick(() => {
241        this.customPopup = !this.customPopup
242      })
243      .bindPopup(this.customPopup, {
244        builder: this.popupBuilder,
245        placement: Placement.Bottom,
246        popupColor: Color.White,
247        enableArrow: false,
248        onStateChange: (e) => {
249          if (!e.isVisible) {
250            this.customPopup = false
251          }
252        }
253      })
254      .onHover((isHover: boolean) => {
255        if (isHover) {
256          this.bgColor = $r('app.color.effect_color_hover')
257        } else {
258          this.bgColor = $r('app.color.effect_color_white')
259        }
260      })
261      .onTouch((event: TouchEvent) => {
262        if (event.type === TouchType.Down) {
263          this.bgColor = $r('app.color.effect_color_press')
264        }
265        if (event.type === TouchType.Up) {
266          this.bgColor = $r('app.color.effect_color_white')
267        }
268      })
269    }
270  }
271
272  aboutToAppear() {
273    Log.info(TAG, 'aboutToAppear this.selectArray length = ' + this.selectArray.length)
274
275  }
276}
277
278@Component
279struct MediaSizeSelectionComponent {
280  @Consume('CurrentMediaSize') currentMediaSize: SelectionModel;
281  @Consume('MediaSizePopup') customPopup: boolean
282  @State bgColor: Resource = $r('app.color.effect_color_white');
283  private selection?: SelectionModel;
284
285  build() {
286    Row() {
287      Text(this.selection!.res)
288        .textAlign(TextAlign.Start)
289        .fontSize($r('app.float.font_size_body2'))
290        .margin({ left: $r('app.float.select_text_margin_left'), right: $r('app.float.select_text_margin_right') })
291    }
292    .selectItemStyle()
293    .onClick(() => {
294      this.currentMediaSize = this.selection!
295      this.customPopup = false
296    })
297    .backgroundColor(this.bgColor)
298    .onHover((isHover: boolean) => {
299      if (isHover) {
300        this.bgColor = $r('app.color.effect_color_hover')
301      } else {
302        this.checkSelectedColor()
303      }
304    })
305    .onTouch((event: TouchEvent) => {
306      if (event.type === TouchType.Down) {
307        this.bgColor = $r('app.color.effect_color_press')
308      }
309      if (event.type === TouchType.Up) {
310        this.checkSelectedColor()
311      }
312    })
313  }
314
315  aboutToAppear() {
316    this.checkSelectedColor()
317  }
318
319  checkSelectedColor() {
320    if (this.selection!.name === this.currentMediaSize.name) {
321      this.bgColor = $r('app.color.selected_color')
322    } else {
323      this.bgColor = $r('app.color.effect_color_white')
324    }
325  }
326}
327
328@Component
329export struct DirectionSelection {
330  @Consume('DirectionSelectArray') selectArray: Array<SelectionModel>;
331  @Consume('CurrentDirection') currentDirection: SelectionModel;
332  @Provide('DirectionPopup') customPopup: boolean = false
333  @State bgColor: Resource = $r('app.color.effect_color_white');
334
335  @Builder popupBuilder() {
336    if (this.customPopup){
337      List() {
338        ForEach(this.selectArray, (select: SelectionModel) => {
339          ListItem() {
340            DirectionSelectionComponent({ selection: select })
341          }.key(`Selection_ListItem_${select.name}`)
342        }, (select: SelectionModel) => select.name)
343      }
344      .width($r('app.float.select_comp_width'))
345      .padding($r('app.float.select_comp_padding'))
346    }
347  }
348
349  build() {
350    Row() {
351      Text($r('app.string.index_direction'))
352        .fontSize($r('app.float.font_size_body2'))
353        .width($r('app.float.text_label_width'))
354        .textAlign(TextAlign.End)
355        .key('Index_Text_direction')
356      Row() {
357        Text(this.currentDirection.res).fontSize($r('app.float.font_size_body2')).textAlign(TextAlign.Start)
358          .width($r('app.float.select_text_width'))
359          .margin({ left: $r('app.float.select_text_margin_left') })
360        Image($r('app.media.ic_select_button'))
361          .height($r('app.float.select_image_button_size'))
362          .width($r('app.float.select_image_button_size'))
363          .margin({
364            left: $r('app.float.select_image_button_margin_left'),
365            right: $r('app.float.select_image_button_margin_right')
366          })
367      }
368      .key('Selection_Direction')
369      .selectStyle()
370      .onClick(() => {
371        this.customPopup = !this.customPopup
372      })
373      .bindPopup(this.customPopup, {
374        builder: this.popupBuilder,
375        placement: Placement.Bottom,
376        popupColor: Color.White,
377        enableArrow: false,
378        onStateChange: (e) => {
379          if (!e.isVisible) {
380            this.customPopup = false
381          }
382        }
383      })
384      .backgroundColor(this.bgColor)
385      .onHover((isHover: boolean) => {
386        if (isHover) {
387          this.bgColor = $r('app.color.effect_color_hover')
388        } else {
389          this.bgColor = $r('app.color.effect_color_white')
390        }
391      })
392      .onTouch((event: TouchEvent) => {
393        if (event.type === TouchType.Down) {
394          this.bgColor = $r('app.color.effect_color_press')
395        }
396        if (event.type === TouchType.Up) {
397          this.bgColor = $r('app.color.effect_color_white')
398        }
399      })
400    }
401  }
402
403  aboutToAppear() {
404  }
405}
406
407@Component
408struct DirectionSelectionComponent {
409  @Consume('CurrentDirection') currentDirection: SelectionModel;
410  @Consume('DirectionPopup') customPopup: boolean
411  @State bgColor: Resource = $r('app.color.effect_color_white');
412  private selection?: SelectionModel
413
414  build() {
415    Row() {
416      Text(this.selection!.res)
417        .textAlign(TextAlign.Start)
418        .fontSize($r('app.float.font_size_body2'))
419        .margin({ left: $r('app.float.select_text_margin_left'), right: $r('app.float.select_text_margin_right') })
420    }
421    .backgroundColor(this.selection!.name === this.currentDirection.name ? $r('app.color.selected_color') : Color.White)
422    .selectItemStyle()
423    .onClick(() => {
424      this.currentDirection = this.selection!
425      this.customPopup = false
426    })
427    .backgroundColor(this.bgColor)
428    .onHover((isHover: boolean) => {
429      if (isHover) {
430        this.bgColor = $r('app.color.effect_color_hover')
431      } else {
432        this.checkSelectedColor()
433      }
434    })
435    .onTouch((event: TouchEvent) => {
436      if (event.type === TouchType.Down) {
437        this.bgColor = $r('app.color.effect_color_press')
438      }
439      if (event.type === TouchType.Up) {
440        this.checkSelectedColor()
441      }
442    })
443  }
444
445  aboutToAppear() {
446    this.checkSelectedColor()
447  }
448
449  checkSelectedColor() {
450    if (this.selection!.name === this.currentDirection.name) {
451      this.bgColor = $r('app.color.selected_color')
452    } else {
453      this.bgColor = $r('app.color.effect_color_white')
454    }
455  }
456}
457
458@Component
459export struct MediaTypeSelection {
460  @Consume('MediaTypeSelectArray') selectArray: Array<SelectionModel>;
461  @Consume('CurrentMediaType') currentMediaType: SelectionModel;
462  @Provide('MediaTypePopup') customPopup: boolean = false
463  @State bgColor: Resource = $r('app.color.effect_color_white');
464
465  @Builder popupBuilder() {
466    if (this.customPopup){
467      List() {
468        ForEach(this.selectArray, (select: SelectionModel) => {
469          ListItem() {
470            MediaTypeSelectionComponent({ selection: select })
471          }.key(`Selection_ListItem_${select.name}`)
472        }, (select: SelectionModel) => select.name)
473      }
474      .width($r('app.float.select_comp_width'))
475      .padding($r('app.float.select_comp_padding'))
476    }
477  }
478
479  build() {
480    Row() {
481      Text($r('app.string.index_media_type'))
482        .fontSize($r('app.float.font_size_body2'))
483        .width($r('app.float.text_label_width'))
484        .textAlign(TextAlign.End)
485        .key('Index_Text_mediaType')
486      Row() {
487        Text(this.currentMediaType.res).fontSize($r('app.float.font_size_body2')).textAlign(TextAlign.Start)
488          .width($r('app.float.select_text_width'))
489          .margin({ left: $r('app.float.select_text_margin_left') })
490        Image($r('app.media.ic_select_button'))
491          .height($r('app.float.select_image_button_size'))
492          .width($r('app.float.select_image_button_size'))
493          .margin({
494            left: $r('app.float.select_image_button_margin_left'),
495            right: $r('app.float.select_image_button_margin_right')
496          })
497      }
498      .key('Selection_MediaType')
499      .selectStyle()
500      .onClick(() => {
501        this.customPopup = !this.customPopup
502      })
503      .bindPopup(this.customPopup, {
504        builder: this.popupBuilder,
505        placement: Placement.Bottom,
506        popupColor: Color.White,
507        enableArrow: false,
508        onStateChange: (e) => {
509          if (!e.isVisible) {
510            this.customPopup = false
511          }
512        }
513      })
514      .backgroundColor(this.bgColor)
515      .onHover((isHover: boolean) => {
516        if (isHover) {
517          this.bgColor = $r('app.color.effect_color_hover')
518        } else {
519          this.bgColor = $r('app.color.effect_color_white')
520        }
521      })
522      .onTouch((event: TouchEvent) => {
523        if (event.type === TouchType.Down) {
524          this.bgColor = $r('app.color.effect_color_press')
525        }
526        if (event.type === TouchType.Up) {
527          this.bgColor = $r('app.color.effect_color_white')
528        }
529      })
530    }
531  }
532
533  aboutToAppear() {
534  }
535}
536
537@Component
538struct MediaTypeSelectionComponent {
539  @Consume('CurrentMediaType') currentMediaType: SelectionModel;
540  @Consume('MediaTypePopup') customPopup: boolean
541  @State bgColor: Resource = $r('app.color.effect_color_white')
542  private selection?: SelectionModel;
543
544  build() {
545    Row() {
546      Text(this.selection!.res)
547        .textAlign(TextAlign.Start)
548        .fontSize($r('app.float.font_size_body2'))
549        .margin({ left: $r('app.float.select_text_margin_left'), right: $r('app.float.select_text_margin_right') })
550    }
551    .backgroundColor(this.selection!.name === this.currentMediaType.name ? $r('app.color.selected_color') : Color.White)
552    .selectItemStyle()
553    .onClick(() => {
554      this.currentMediaType = this.selection!
555      this.customPopup = false
556    })
557    .backgroundColor(this.bgColor)
558    .onHover((isHover: boolean) => {
559      if (isHover) {
560        this.bgColor = $r('app.color.effect_color_hover')
561      } else {
562        this.checkSelectedColor()
563      }
564    })
565    .onTouch((event: TouchEvent) => {
566      if (event.type === TouchType.Down) {
567        this.bgColor = $r('app.color.effect_color_press')
568      }
569      if (event.type === TouchType.Up) {
570        this.checkSelectedColor()
571      }
572    })
573  }
574
575  aboutToAppear() {
576    this.checkSelectedColor()
577  }
578
579  checkSelectedColor() {
580    if (this.selection!.name === this.currentMediaType.name) {
581      this.bgColor = $r('app.color.selected_color')
582    } else {
583      this.bgColor = $r('app.color.effect_color_white')
584    }
585  }
586}
587
588@Component
589export struct QualitySelection {
590  @Consume('QualitySelectArray') selectArray: Array<SelectionModel>;
591  @Consume('CurrentQuality') currentQuality: SelectionModel;
592  @Provide('QualityPopup') customPopup: boolean = false
593  @State bgColor: Resource = $r('app.color.effect_color_white');
594
595  @Builder popupBuilder() {
596    if (this.customPopup){
597      List() {
598        ForEach(this.selectArray, (select: SelectionModel) => {
599          ListItem() {
600            QualitySelectionComponent({ selection: select })
601          }.key(`Selection_ListItem_${select.name}`)
602        }, (select: SelectionModel) => select.name)
603      }
604      .width($r('app.float.select_comp_width'))
605      .padding($r('app.float.select_comp_padding'))
606    }
607  }
608
609  build() {
610    Row() {
611      Text($r('app.string.index_print_quality'))
612        .fontSize($r('app.float.font_size_body2'))
613        .width($r('app.float.text_label_width'))
614        .textAlign(TextAlign.End)
615        .key('Index_Text_printQuality')
616      Row() {
617        Text(this.currentQuality.res).fontSize($r('app.float.font_size_body2')).textAlign(TextAlign.Start)
618          .width($r('app.float.select_text_width'))
619          .margin({ left: $r('app.float.select_text_margin_left') })
620        Image($r('app.media.ic_select_button'))
621          .height($r('app.float.select_image_button_size'))
622          .width($r('app.float.select_image_button_size'))
623          .margin({
624            left: $r('app.float.select_image_button_margin_left'),
625            right: $r('app.float.select_image_button_margin_right')
626          })
627      }
628      .key('Selection_Quality')
629      .selectStyle()
630      .onClick(() => {
631        this.customPopup = !this.customPopup
632      })
633      .bindPopup(this.customPopup, {
634        builder: this.popupBuilder,
635        placement: Placement.Bottom,
636        popupColor: Color.White,
637        enableArrow: false,
638        onStateChange: (e) => {
639          if (!e.isVisible) {
640            this.customPopup = false
641          }
642        }
643      })
644      .backgroundColor(this.bgColor)
645      .onHover((isHover: boolean) => {
646        if (isHover) {
647          this.bgColor = $r('app.color.effect_color_hover')
648        } else {
649          this.bgColor = $r('app.color.effect_color_white')
650        }
651      })
652      .onTouch((event: TouchEvent) => {
653        if (event.type === TouchType.Down) {
654          this.bgColor = $r('app.color.effect_color_press')
655        }
656        if (event.type === TouchType.Up) {
657          this.bgColor = $r('app.color.effect_color_white')
658        }
659      })
660    }
661  }
662
663  aboutToAppear() {
664  }
665}
666
667@Component
668struct QualitySelectionComponent {
669  @Consume('CurrentQuality') currentQuality: SelectionModel;
670  @Consume('QualityPopup') customPopup: boolean
671  @State bgColor: Resource = $r('app.color.effect_color_white');
672  private selection?: SelectionModel;
673
674  build() {
675    Row() {
676      Text(this.selection!.res)
677        .textAlign(TextAlign.Start)
678        .fontSize($r('app.float.font_size_body2'))
679        .margin({ left: $r('app.float.select_text_margin_left'), right: $r('app.float.select_text_margin_right') })
680    }
681    .backgroundColor(this.selection!.name === this.currentQuality.name ? $r('app.color.selected_color') : Color.White)
682    .selectItemStyle()
683    .onClick(() => {
684      this.currentQuality = this.selection!
685      this.customPopup = false
686    })
687    .backgroundColor(this.bgColor)
688    .onHover((isHover: boolean) => {
689      if (isHover) {
690        this.bgColor = $r('app.color.effect_color_hover')
691      } else {
692        this.checkSelectedColor()
693      }
694    })
695    .onTouch((event: TouchEvent) => {
696      if (event.type === TouchType.Down) {
697        this.bgColor = $r('app.color.effect_color_press')
698      }
699      if (event.type === TouchType.Up) {
700        this.checkSelectedColor()
701      }
702    })
703  }
704
705  aboutToAppear() {
706    this.checkSelectedColor()
707  }
708
709  checkSelectedColor() {
710    if (this.selection!.name === this.currentQuality.name) {
711      this.bgColor = $r('app.color.selected_color')
712    } else {
713      this.bgColor = $r('app.color.effect_color_white')
714    }
715  }
716}
717
718@Component
719export struct DuplexSelection {
720  @Consume('DuplexSelectArray') selectArray: Array<SelectionModel>;
721  @Consume('CurrentDuplex') currentDuplex: SelectionModel;
722  @Provide('DuplexPopup') customPopup: boolean = false
723  @State bgColor: Resource = $r('app.color.effect_color_white');
724
725  @Builder popupBuilder() {
726    if (this.customPopup){
727      List() {
728        ForEach(this.selectArray, (select: SelectionModel) => {
729          ListItem() {
730            DuplexSelectionComponent({ selection: select })
731          }.key(`Selection_ListItem_${select.name}`)
732        }, (select: SelectionModel) => select.name)
733      }
734      .width($r('app.float.select_comp_width'))
735      .padding($r('app.float.select_comp_padding'))
736    }
737  }
738
739  build() {
740    Row() {
741      Text($r('app.string.index_duplex_mode'))
742        .fontSize($r('app.float.font_size_body2'))
743        .width($r('app.float.text_label_width'))
744        .textAlign(TextAlign.End)
745        .key('Index_Text_printDuplex')
746      Row() {
747        Text(this.getText()).fontSize($r('app.float.font_size_body2')).textAlign(TextAlign.Start)
748          .width($r('app.float.select_text_width'))
749          .margin({ left: $r('app.float.select_text_margin_left') })
750        Image($r('app.media.ic_select_button'))
751          .height($r('app.float.select_image_button_size'))
752          .width($r('app.float.select_image_button_size'))
753          .margin({
754            left: $r('app.float.select_image_button_margin_left'),
755            right: $r('app.float.select_image_button_margin_right')
756          })
757      }
758      .key('Selection_Duplex')
759      .selectStyle()
760      .onClick(() => {
761        this.customPopup = !this.customPopup
762      })
763      .bindPopup(this.customPopup, {
764        builder: this.popupBuilder,
765        placement: Placement.Bottom,
766        popupColor: Color.White,
767        enableArrow: false,
768        onStateChange: (e) => {
769          if (!e.isVisible) {
770            this.customPopup = false
771          }
772        }
773      })
774      .backgroundColor(this.bgColor)
775      .onHover((isHover: boolean) => {
776        if (isHover) {
777          this.bgColor = $r('app.color.effect_color_hover')
778        } else {
779          this.bgColor = $r('app.color.effect_color_white')
780        }
781      })
782      .onTouch((event: TouchEvent) => {
783        if (event.type === TouchType.Down) {
784          this.bgColor = $r('app.color.effect_color_press')
785        }
786        if (event.type === TouchType.Up) {
787          this.bgColor = $r('app.color.effect_color_white')
788        }
789      })
790    }
791  }
792
793  getText(){
794    if(SelectionModel.getSelectionValue<number>(this.currentDuplex.name) === Duplex.SINGLE){
795      return $r('app.string.DuplexMode_SINGLE')
796    } else {
797      return this.currentDuplex.res
798    }
799  }
800
801  aboutToAppear() {
802  }
803}
804
805@Component
806struct DuplexSelectionComponent {
807  @Consume('CurrentDuplex') currentDuplex: SelectionModel;
808  @Consume('DuplexPopup') customPopup: boolean;
809  @Consume('NeedDuplex') needDuplex: boolean;
810  @State bgColor: Resource = $r('app.color.effect_color_white');
811  @State isSingle: boolean = true;
812  private selection?: SelectionModel;
813
814  build() {
815    Row() {
816      Image(this.getImage()).width(48).height(48).margin({right:16}).objectFit(ImageFit.Contain)
817      Column(){
818        Text(SelectionModel.getSelectionValue<number>(this.selection!.name)! === Duplex.SINGLE?$r('app.string.DuplexMode_SINGLE'):$r('app.string.DuplexMode_DOUBLE'))
819          .textAlign(TextAlign.Start)
820          .fontSize($r('app.float.font_size_body1'))
821          .fontColor('#E5000000')
822        Text(this.selection!.res)
823          .textAlign(TextAlign.Start)
824          .fontSize($r('app.float.font_size_body2'))
825          .fontColor('#99000000')
826      }.alignItems(HorizontalAlign.Start)
827    }
828    .backgroundColor(this.selection!.name === this.currentDuplex.name ? $r('app.color.selected_color') : Color.White)
829    .width($r('app.float.select_item_width'))
830    .height($r('app.float.duplex_select_item_height'))
831    .justifyContent(FlexAlign.Start)
832    .alignItems(VerticalAlign.Center)
833    .margin({ top: $r('app.float.select_item_margin_top'), bottom: $r('app.float.select_item_margin_bottom')})
834    .padding({left:16,right:16})
835    .borderRadius($r('app.float.radius_m'))
836    .enabled(this.isSingle||this.needDuplex)
837    .opacity(this.isSingle||this.needDuplex?1:0.4)
838    .onClick(() => {
839      this.currentDuplex = this.selection!
840      this.customPopup = false
841    })
842    .backgroundColor(this.bgColor)
843    .onHover((isHover: boolean) => {
844      if (isHover) {
845        this.bgColor = $r('app.color.effect_color_hover')
846      } else {
847        this.checkSelectedColor()
848      }
849    })
850    .onTouch((event: TouchEvent) => {
851      if (event.type === TouchType.Down) {
852        this.bgColor = $r('app.color.effect_color_press')
853      }
854      if (event.type === TouchType.Up) {
855        this.checkSelectedColor()
856      }
857    })
858  }
859
860  aboutToAppear() {
861    Log.info(TAG,'DuplexSelectionComponent: ',JSON.stringify(this.currentDuplex))
862    this.isSingle = (SelectionModel.getSelectionValue<number>(this.selection!.name) === Duplex.SINGLE);
863    this.checkSelectedColor()
864  }
865
866  checkSelectedColor() {
867    if (this.selection!.name === this.currentDuplex.name) {
868      this.bgColor = $r('app.color.selected_color')
869    } else {
870      this.bgColor = $r('app.color.effect_color_white')
871    }
872  }
873
874  getImage(){
875    Log.info(TAG,'getImage: ',this.selection!.name)
876    let res = $r('app.media.ic_single');
877    if (SelectionModel.getSelectionValue<number>(this.selection!.name) === Duplex.LONG) {
878      Log.info(TAG,'getImage: app.media.ic_long',this.selection!.name)
879      res = $r('app.media.ic_long')
880    } else if(SelectionModel.getSelectionValue<number>(this.selection!.name) === Duplex.SHORT) {
881      Log.info(TAG,'getImage: app.media.ic_short',this.selection!.name)
882      res = $r('app.media.ic_short')
883    }
884    return res
885  }
886}
887