Line data Source code
1 : import 'package:pal/src/database/entity/helper/helper_entity.dart'; 2 : import 'package:pal/src/extensions/color_extension.dart'; 3 : import 'package:pal/src/ui/shared/helper_shared_viewmodels.dart'; 4 : import 'package:pal/src/ui/editor/pages/helper_editor/font_editor/pickers/font_weight_picker/font_weight_picker_loader.dart'; 5 : 6 : ///------------------------------- 7 : /// KEYS to link data to right element 8 : ///------------------------------- 9 : class SimpleHelperKeys { 10 : static const CONTENT_KEY = "CONTENT"; 11 : static const BACKGROUND_KEY = "BACKGROUND_KEY"; // mandatory 12 : } 13 : 14 : class FullscreenHelperKeys { 15 : static const TITLE_KEY = "TITLE_KEY"; // mandatory 16 : static const DESCRIPTION_KEY = "DESCRIPTION_KEY"; //TODO for next release 17 : static const POSITIV_KEY = "POSITIV_KEY"; // not mandatory 18 : static const NEGATIV_KEY = "NEGATIV_KEY"; // not mandatory 19 : static const IMAGE_KEY = "IMAGE_KEY"; // not mandatory 20 : static const BACKGROUND_KEY = "BACKGROUND_KEY"; // mandatory 21 : } 22 : 23 : class UpdatescreenHelperKeys { 24 : static const TITLE_KEY = "TITLE_KEY"; // mandatory 25 : static const LINES_KEY = "LINES_KEY"; //first mandatory 26 : static const POSITIV_KEY = "POSITIV_KEY"; // not mandatory 27 : static const IMAGE_KEY = "IMAGE_KEY"; // not mandatory 28 : static const BACKGROUND_KEY = "BACKGROUND_KEY"; // mandatory 29 : } 30 : 31 : class HelperSharedFactory { 32 2 : static HelperTextViewModel parseTextLabel( 33 : final String key, 34 : final List<HelperTextEntity> helperTexts, 35 : ) { 36 4 : for (HelperTextEntity helperText in helperTexts) { 37 4 : if (key == helperText?.key) { 38 2 : return HelperTextViewModel( 39 2 : id: helperText?.id, 40 2 : text: helperText?.value, 41 4 : fontColor: HexColor.fromHex(helperText?.fontColor), 42 4 : fontSize: helperText?.fontSize?.toDouble(), 43 2 : fontFamily: helperText?.fontFamily, 44 4 : fontWeight: FontWeightMapper.toFontWeight(helperText?.fontWeight), 45 : ); 46 : } 47 : } 48 : return null; 49 : } 50 : 51 2 : static HelperImageViewModel parseImageUrl( 52 : final String key, 53 : final List<HelperImageEntity> helperImages, 54 : ) { 55 4 : for (HelperImageEntity helperImage in helperImages) { 56 4 : if (key == helperImage?.key) { 57 2 : return HelperImageViewModel( 58 2 : id: helperImage?.id, 59 2 : url: helperImage?.url, 60 : ); 61 : } 62 : } 63 : return null; 64 : } 65 : 66 2 : static HelperBoxViewModel parseBoxBackground( 67 : final String key, 68 : final List<HelperBoxEntity> helperBoxes, 69 : ) { 70 4 : for (HelperBoxEntity helperBox in helperBoxes) { 71 4 : if (key == helperBox?.key) { 72 2 : return HelperBoxViewModel( 73 2 : id: helperBox?.id, 74 4 : backgroundColor: HexColor.fromHex(helperBox?.backgroundColor)); 75 : } 76 : } 77 : return null; 78 : } 79 : 80 0 : static HelperBorderViewModel parseBorder( 81 : final String key, 82 : final List<HelperBorderEntity> helperBorders, 83 : ) { 84 0 : for (HelperBorderEntity helperBorder in helperBorders) { 85 0 : if (key == helperBorder?.key) { 86 0 : return HelperBorderViewModel( 87 0 : id: helperBorder?.id, 88 0 : style: helperBorder?.style, 89 0 : color: HexColor.fromHex(helperBorder?.color), 90 0 : width: helperBorder?.width, 91 : ); 92 : } 93 : } 94 : return null; 95 : } 96 : 97 1 : static List<HelperTextViewModel> parseTextsLabel( 98 : final String key, 99 : final List<HelperTextEntity> helperTexts, 100 : ) { 101 : // TODO: Reorganize array from back ? 102 1 : List<HelperTextViewModel> customLabels = []; 103 2 : for (HelperTextEntity helperText in helperTexts) { 104 2 : if (helperText.key.startsWith(key)) { 105 1 : customLabels.add( 106 1 : HelperTextViewModel( 107 2 : id: helperText?.id ?? helperTexts.indexOf(helperText), 108 1 : text: helperText?.value, 109 2 : fontColor: HexColor.fromHex(helperText?.fontColor), 110 2 : fontSize: helperText?.fontSize?.toDouble(), 111 1 : fontFamily: helperText?.fontFamily, 112 2 : fontWeight: FontWeightMapper.toFontWeight(helperText?.fontWeight), 113 : ), 114 : ); 115 : } 116 : } 117 : return customLabels; 118 : } 119 : }