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