meowSuggestions.ets 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. import { animation_default } from '../../hosts/bunch_of_defaults';
  2. import linysText from '../../components/texts/linysText';
  3. import { get_relations } from '../../utils/label_link_relation_tools';
  4. import { bunch_of_bookmarks } from '../../hosts/bunch_of_bookmarks';
  5. import { bunch_of_history } from '../../hosts/bunch_of_history';
  6. @Component
  7. struct meowSuggestions {
  8. // Environments or settings
  9. @Prop top_margin: number = 0;
  10. @Prop bottom_margin: number = 0;
  11. @State content_height: number = 0;
  12. @StorageProp('is_search_input_typing') is_search_input_typing: boolean = false;
  13. @StorageProp('search_input') @Watch('refresh_suggestions') search_input: string = "";
  14. @StorageLink('search_extracted_keyword') search_extracted_keyword: string = '';
  15. @StorageProp('screen_height') screen_height: number = 0;
  16. @StorageProp('tablet_mode') tablet_mode: boolean = false;
  17. @StorageLink('leftAvoidWidth') leftAvoidWidth: number = 1;
  18. @StorageLink('rightAvoidWidth') rightAvoidWidth: number = 1;
  19. @StorageLink('showing_more_options') showing_more_options: boolean = false;
  20. @StorageLink('showing_app_settings') showing_app_settings: boolean = false;
  21. @StorageLink('showing_downloads') showing_downloads: boolean = false;
  22. // Hosts
  23. @StorageLink('bunch_of_bookmarks') bunch_of_bookmarks: bunch_of_bookmarks = new bunch_of_bookmarks("meow");
  24. @StorageLink('bunch_of_history') bunch_of_history: bunch_of_history = new bunch_of_history(true);
  25. // Settings
  26. @StorageProp('max_bookmark_advice') max_bookmark_advice: number = 5;
  27. @StorageProp('max_history_advice') max_history_advice: number = 5;
  28. // @StorageProp('max_bookmark_advice') @Watch('refresh_suggestions') max_bookmark_advice: number = 5;
  29. // @StorageProp('max_history_advice') @Watch('refresh_suggestions') max_history_advice: number = 5;
  30. // Myself
  31. @State bookmark_suggestions: string[][] = [];
  32. @State history_suggestions: string[][] = [];
  33. // Colors
  34. @StorageProp('color_current_primary') color_current_primary: ResourceColor = $r('app.color.start_window_background');
  35. @StorageProp('color_current_secondary') color_current_secondary: ResourceColor = $r('app.color.block_color');
  36. @StorageProp('color_current_font') color_current_font: ResourceColor = $r('app.color.font_color_title');
  37. build() {
  38. Scroll() {
  39. if (this.tablet_mode) {
  40. Row({ space: 10 }) {
  41. suggestionList({ suggestions: this.bookmark_suggestions })
  42. .layoutWeight(1)
  43. .visibility(this.bookmark_suggestions.length > 0 ? Visibility.Visible : Visibility.None)
  44. .animation(animation_default())
  45. suggestionList({ suggestions: this.history_suggestions })
  46. .layoutWeight(1)
  47. .visibility(this.history_suggestions.length > 0 ? Visibility.Visible : Visibility.None)
  48. .animation(animation_default())
  49. }
  50. .alignItems(VerticalAlign.Top)
  51. .onAreaChange((_o, n) => {
  52. this.content_height = n.height as number;
  53. })
  54. .animation(animation_default())
  55. } else {
  56. Column({ space: 10 }) {
  57. suggestionList({ suggestions: this.bookmark_suggestions })
  58. .width("100%")
  59. .visibility(this.bookmark_suggestions.length > 0 ? Visibility.Visible : Visibility.None)
  60. .animation(animation_default())
  61. suggestionList({ suggestions: this.history_suggestions })
  62. .width("100%")
  63. .visibility(this.history_suggestions.length > 0 ? Visibility.Visible : Visibility.None)
  64. .animation(animation_default())
  65. }
  66. .alignItems(HorizontalAlign.Start)
  67. .onAreaChange((_o, n) => {
  68. this.content_height = n.height as number;
  69. })
  70. .animation(animation_default())
  71. }
  72. }
  73. .scrollBar(BarState.Off)
  74. .margin({
  75. left: 15,
  76. right: 15,
  77. top: this.top_margin,
  78. bottom: this.bottom_margin
  79. })
  80. .backgroundColor(Color.Red)
  81. .height(Math.min(this.content_height, 0.4 * this.screen_height))
  82. // .visibility(this.visibility_suggestions())
  83. .animation(animation_default())
  84. .edgeEffect(EdgeEffect.Spring)
  85. }
  86. visibility_suggestions() {
  87. if (this.bookmark_suggestions.length + this.history_suggestions.length == 0) {
  88. return Visibility.None;
  89. }
  90. if (this.showing_more_options) {
  91. return Visibility.None;
  92. }
  93. if (this.search_input == "") {
  94. return Visibility.None;
  95. }
  96. if (!this.is_search_input_typing) {
  97. return Visibility.None;
  98. }
  99. return Visibility.Visible
  100. }
  101. refresh_suggestions() {
  102. this.showing_more_options = false;
  103. this.showing_app_settings = false;
  104. this.showing_downloads = false;
  105. if (this.search_input === undefined || this.search_input.length == 0) {
  106. this.bookmark_suggestions = [];
  107. this.history_suggestions = [];
  108. } else {
  109. let label_link_bookmark = this.bunch_of_bookmarks.get_all_plain_label_link();
  110. this.bookmark_suggestions = get_relations(label_link_bookmark, this.search_input, this.max_bookmark_advice);
  111. this.history_suggestions = bunch_of_history.search_with_index(this.search_input.toUpperCase(), this.max_history_advice);
  112. // get_relations(label_link_history, this.search_input, this.max_history_advice);
  113. }
  114. }
  115. }
  116. export default meowSuggestions;
  117. @Component
  118. struct meowRelation {
  119. @Prop relation: string[] = [];
  120. @Prop index: number;
  121. @State offset_y: number = 50;
  122. @State this_visibility: Visibility = Visibility.Hidden;
  123. @StorageLink('universal_load_url_gateway') load_url_gateway: string = "";
  124. build() {
  125. Column({ space: 2 }) {
  126. linysText({
  127. text: this.relation[0].length == 0 ? " " : this.relation[0]
  128. })
  129. linysText({
  130. text: this.relation[1]
  131. })
  132. .opacity(0.7)
  133. }
  134. .alignItems(HorizontalAlign.Start)
  135. .width("100%")
  136. .visibility(this.this_visibility)
  137. .offset({ y: this.offset_y })
  138. .animation(animation_default())
  139. .onClick(() => {
  140. this.load_url_gateway = this.relation[1];
  141. })
  142. .onAppear(() => {
  143. setTimeout(() => {
  144. this.offset_y = 0;
  145. this.this_visibility = Visibility.Visible;
  146. }, (this.index) * 60)
  147. })
  148. }
  149. }
  150. @Component
  151. struct suggestionList {
  152. @StorageProp('color_current_primary') color_current_primary: ResourceColor = $r('app.color.start_window_background');
  153. @Prop suggestions: string[][] = [];
  154. build() {
  155. Column({ space: 8 }) {
  156. ForEach(this.suggestions, (item: string[], index: number) => {
  157. meowRelation({
  158. relation: item,
  159. index: index
  160. })
  161. })
  162. }
  163. .padding(15)
  164. .backgroundColor(this.color_current_primary)
  165. .borderRadius(10)
  166. .visibility(this.suggestions.length > 0 ? Visibility.Visible : Visibility.None)
  167. .animation(animation_default())
  168. }
  169. }