liyubing

Merge remote-tracking branch 'origin/main'

@@ -67,4 +67,8 @@ export { TingyunAPM } from './src/main/ets/tingyunAPM/TingyunAPM' @@ -67,4 +67,8 @@ export { TingyunAPM } from './src/main/ets/tingyunAPM/TingyunAPM'
67 export { FastClickUtil } from './src/main/ets/utils/FastClickUtil'; 67 export { FastClickUtil } from './src/main/ets/utils/FastClickUtil';
68 68
69 // export { PublicPopupDialogView } from "./src/main/ets/pubComps/dialog/PublicPopupDialogView" 69 // export { PublicPopupDialogView } from "./src/main/ets/pubComps/dialog/PublicPopupDialogView"
70 -export { PublicDialogManager, CloseAction } from "./src/main/ets/pubComps/dialog/PublicDialogManager"  
  70 +export { PublicDialogManager, CloseAction } from "./src/main/ets/pubComps/dialog/PublicDialogManager"
  71 +
  72 +export { CrptoUtils } from "./src/main/ets/utils/CrptoUtils"
  73 +
  74 +export { FileUtils } from "./src/main/ets/utils/FileUtils"
  1 +import cryptoFramework from '@ohos.security.cryptoFramework';
  2 +import buffer from '@ohos.buffer';
  3 +
  4 +export class CrptoUtils {
  5 +
  6 + static md5(message: string) : Promise<string> {
  7 + return CrptoUtils.mdFunc(message, 'MD5')
  8 + }
  9 +
  10 + static mdFunc(message: string, algoName: string = 'MD5'): Promise<string> {
  11 + return new Promise<string>(async (reslove, fail) => {
  12 +
  13 + try {
  14 + let md = cryptoFramework.createMd(algoName);
  15 + // 数据量较少时,可以只做一次update,将数据全部传入,接口未对入参长度做限制
  16 + await md.update({ data: new Uint8Array(buffer.from(message, 'utf-8').buffer) });
  17 + let mdResult = await md.digest();
  18 + // console.info('Md result:' + mdResult.data);
  19 +
  20 + // const string = mdResult.data.map((charCode, index, array) => {
  21 + // return String.fromCharCode(charCode)
  22 + // }).join("")
  23 +
  24 + let string = "";
  25 + for (let i = 0; i < mdResult.data.length; i++) {
  26 + string += mdResult.data[i].toString(16).padStart(2, "0")
  27 + }
  28 +
  29 + // const string = mdResult.data.join('')
  30 +
  31 + reslove(string)
  32 + } catch (e) {
  33 + fail(e)
  34 + }
  35 + })
  36 + }
  37 +}
  38 +
  39 +
  40 +
  41 +
  1 +
  2 +import fs from '@ohos.file.fs';
  3 +import { BusinessError } from '@kit.BasicServicesKit';
  4 +
  5 +export class FileUtils {
  6 +
  7 + // 文件是否存在,忽略错误
  8 + static fileExsit(path: string) : Promise<boolean> {
  9 + return new Promise((reslove, fail) => {
  10 + fs.stat(path).then(() => {
  11 + reslove(true)
  12 + }).catch((error: BusinessError) => {
  13 + if (error.code = 13900002) {
  14 + reslove(false)
  15 + } else {
  16 + reslove(true)
  17 + }
  18 + })
  19 + });
  20 + }
  21 +
  22 + static makeDirIfNotExsit(path: string) : Promise<void> {
  23 + return new Promise((reslove, fail) => {
  24 + fs.stat(path).then(() => {
  25 + reslove()
  26 + }).catch((error: BusinessError) => {
  27 + if (error.code = 13900002) {
  28 + fs.mkdirSync(path)
  29 + }
  30 + reslove()
  31 + })
  32 + })
  33 + }
  34 +}
@@ -49,9 +49,9 @@ export function registerRouter() { @@ -49,9 +49,9 @@ export function registerRouter() {
49 // }) 49 // })
50 50
51 Action2Page.register("JUMP_DETAIL_PAGE", (action: Action) => { 51 Action2Page.register("JUMP_DETAIL_PAGE", (action: Action) => {
52 - if (action.params?.detailPageType == 2 || action.params?.detailPageType == 6) { 52 + if (action.params?.detailPageType == 2) {
53 return WDRouterPage.detailPlayLiveCommon 53 return WDRouterPage.detailPlayLiveCommon
54 - } else if (action.params?.detailPageType == 7 || action.params?.detailPageType == 8) { 54 + } else if (action.params?.detailPageType == 1) {
55 return WDRouterPage.detailVideoListPage 55 return WDRouterPage.detailVideoListPage
56 } else if (action.params?.detailPageType == 9) { 56 } else if (action.params?.detailPageType == 9) {
57 //图集详情页 57 //图集详情页
@@ -59,16 +59,19 @@ export function registerRouter() { @@ -59,16 +59,19 @@ export function registerRouter() {
59 } else if (action.params?.detailPageType == 14 || action.params?.detailPageType == 15) { 59 } else if (action.params?.detailPageType == 14 || action.params?.detailPageType == 15) {
60 //动态详情页 60 //动态详情页
61 return WDRouterPage.dynamicDetailPage 61 return WDRouterPage.dynamicDetailPage
62 - } else if (action.params?.detailPageType == 17) {  
63 - return WDRouterPage.multiPictureDetailPage  
64 } else if (action.params?.detailPageType == 13) { 62 } else if (action.params?.detailPageType == 13) {
65 return WDRouterPage.audioDetail 63 return WDRouterPage.audioDetail
66 - } else if (action.params?.detailPageType == 18) { 64 + } else if (action.params?.detailPageType == 30) {
  65 + return WDRouterPage.themeListPage
  66 + } else if (action.params?.detailPageType == 8) {
  67 + return WDRouterPage.imageTextDetailPage
  68 + }
  69 +
  70 + //TODO: 以下两个最好改为pageID方式,以上都是有具体内容类型 对应详情页面
  71 + else if (action.params?.detailPageType == 18) {
67 return WDRouterPage.multiPictureListPage 72 return WDRouterPage.multiPictureListPage
68 } else if (action.params?.detailPageType == 19) { 73 } else if (action.params?.detailPageType == 19) {
69 return WDRouterPage.videoPlayPage 74 return WDRouterPage.videoPlayPage
70 - }else if (action.params?.detailPageType == 30) {  
71 - return WDRouterPage.themeListPage  
72 } 75 }
73 return WDRouterPage.detailPlayVodPage 76 return WDRouterPage.detailPlayVodPage
74 }) 77 })
@@ -3,6 +3,7 @@ import App from '@system.app' @@ -3,6 +3,7 @@ import App from '@system.app'
3 import { Action, Params } from 'wdBean/Index' 3 import { Action, Params } from 'wdBean/Index'
4 import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO' 4 import { ExtraDTO } from 'wdBean/src/main/ets/bean/component/extra/ExtraDTO'
5 import { Logger } from 'wdKit/Index' 5 import { Logger } from 'wdKit/Index'
  6 +import { ContentType } from '../common/ContentType'
6 import { WDRouterRule } from '../router/WDRouterRule' 7 import { WDRouterRule } from '../router/WDRouterRule'
7 import { ProcessUtils } from './ProcessUtils' 8 import { ProcessUtils } from './ProcessUtils'
8 9
@@ -111,13 +112,13 @@ export class AppInnerLink { @@ -111,13 +112,13 @@ export class AppInnerLink {
111 } 112 }
112 private static contentTypeWithType(type?: string) : number | undefined { 113 private static contentTypeWithType(type?: string) : number | undefined {
113 switch (type) { 114 switch (type) {
114 - case "video": return 1  
115 - case "dynamic": return 14  
116 - case "live": return 2  
117 - case "audio": return 13  
118 - case "picture": return 9  
119 - case "article": return 8  
120 - case "ask": return 16 115 + case "video": return ContentType.Video
  116 + case "dynamic": return ContentType.DynamicImageText
  117 + case "live": return ContentType.Live
  118 + case "audio": return ContentType.Audio
  119 + case "picture": return ContentType.Pictures
  120 + case "article": return ContentType.ImageText
  121 + case "ask": return ContentType.Ask
121 } 122 }
122 return 123 return
123 } 124 }
@@ -304,7 +304,7 @@ export class ProcessUtils { @@ -304,7 +304,7 @@ export class ProcessUtils {
304 let taskAction: Action = { 304 let taskAction: Action = {
305 type: 'JUMP_DETAIL_PAGE', 305 type: 'JUMP_DETAIL_PAGE',
306 params: { 306 params: {
307 - detailPageType: 7, 307 + detailPageType: 1,
308 contentID: content?.objectId, 308 contentID: content?.objectId,
309 extra: { 309 extra: {
310 relType: content?.relType, 310 relType: content?.relType,
@@ -382,7 +382,7 @@ export class ProcessUtils { @@ -382,7 +382,7 @@ export class ProcessUtils {
382 let taskAction: Action = { 382 let taskAction: Action = {
383 type: 'JUMP_DETAIL_PAGE', 383 type: 'JUMP_DETAIL_PAGE',
384 params: { 384 params: {
385 - detailPageType: 17, 385 + detailPageType: 9,
386 contentID: content?.objectId, 386 contentID: content?.objectId,
387 extra: { 387 extra: {
388 relType: content?.relType, 388 relType: content?.relType,
@@ -10,16 +10,13 @@ export interface Params { @@ -10,16 +10,13 @@ export interface Params {
10 // 详情页类型 10 // 详情页类型
11 // 1.点播详情页 11 // 1.点播详情页
12 // 2.直播详情页 12 // 2.直播详情页
13 - // 3.图文详情页  
14 - // 4.全民播详情页  
15 - // 5.欢喜详情页  
16 - // 6.挂件详情页  
17 - // 7.沉浸式竖屏详情页  
18 - // 8.专辑竖屏详情页  
19 - // 13.音频详情页  
20 - // 17.多图(图集)详情页  
21 - // 18.大图列表页  
22 - // 19.单个视频播放页 13 + // 8.图文详情页
  14 + // 9.多图(图集)详情页
  15 + // 14和15 动态详情页
  16 + // 13 音频详情页
  17 + // 30 金刚位
  18 + // 18.大图列表页 - 图片预览 ------ 需要变更待定
  19 + // 19.单个视频播放页 - 视频播放 ----- 需要变更待定
23 detailPageType?: number; // 详情页类型 20 detailPageType?: number; // 详情页类型
24 liveStyle?: number; // 直播类型:0横屏,1竖屏 21 liveStyle?: number; // 直播类型:0横屏,1竖屏
25 creatorId?: string; //号主id 22 creatorId?: string; //号主id
@@ -116,7 +116,7 @@ export struct Card17Component { @@ -116,7 +116,7 @@ export struct Card17Component {
116 let taskAction: Action = { 116 let taskAction: Action = {
117 type: 'JUMP_DETAIL_PAGE', 117 type: 'JUMP_DETAIL_PAGE',
118 params: { 118 params: {
119 - detailPageType: 17, 119 + detailPageType: 9,
120 contentID: this.contentDTO.objectId, 120 contentID: this.contentDTO.objectId,
121 extra: { 121 extra: {
122 relType: this.contentDTO.relType, 122 relType: this.contentDTO.relType,
@@ -4,7 +4,7 @@ import { ContentType } from 'wdRouter/Index'; @@ -4,7 +4,7 @@ import { ContentType } from 'wdRouter/Index';
4 4
5 export class DeepLinkUtil { 5 export class DeepLinkUtil {
6 6
7 - private static DEEP_LINK_PREFIX = "rmrbapp:rmrb.app/openwith" 7 + private static DEEP_LINK_PREFIX = "rmrbapp://rmrb.app/openwith"
8 8
9 static generateDeepLinkWithConent(content: ContentDetailDTO): string { 9 static generateDeepLinkWithConent(content: ContentDetailDTO): string {
10 10
@@ -23,7 +23,7 @@ export class DeepLinkUtil { @@ -23,7 +23,7 @@ export class DeepLinkUtil {
23 private static generate(contentType: number, contentId?: string, relId?: string, link?: string): string { 23 private static generate(contentType: number, contentId?: string, relId?: string, link?: string): string {
24 let deeplink = DeepLinkUtil.DEEP_LINK_PREFIX 24 let deeplink = DeepLinkUtil.DEEP_LINK_PREFIX
25 25
26 - let pubParam = `&contentId=${contentId}}&relId=${relId}&skipType=1` 26 + let pubParam = `&contentId=${contentId}&relId=${relId}&skipType=1`
27 27
28 let type: ContentType = Number(contentType) 28 let type: ContentType = Number(contentType)
29 switch (type) { 29 switch (type) {
@@ -38,7 +38,7 @@ export class DeepLinkUtil { @@ -38,7 +38,7 @@ export class DeepLinkUtil {
38 deeplink += "?type=article&subType=h5" 38 deeplink += "?type=article&subType=h5"
39 deeplink += "&url=" + encodeURIComponent(link) 39 deeplink += "&url=" + encodeURIComponent(link)
40 } else { 40 } else {
41 - deeplink += "type=article&subType=h5_template_article" 41 + deeplink += "?type=article&subType=h5_template_article"
42 } 42 }
43 break 43 break
44 case ContentType.DynamicImageText: 44 case ContentType.DynamicImageText:
1 import { formBindingData, FormExtensionAbility, formInfo, formProvider } from '@kit.FormKit'; 1 import { formBindingData, FormExtensionAbility, formInfo, formProvider } from '@kit.FormKit';
2 import { Want } from '@kit.AbilityKit'; 2 import { Want } from '@kit.AbilityKit';
3 -import { Logger, NetworkManager, SPHelper, StringUtils } from 'wdKit/Index'; 3 +import { FileUtils, Logger, NetworkManager, SPHelper, StringUtils } from 'wdKit/Index';
4 import { BusinessError } from '@kit.BasicServicesKit'; 4 import { BusinessError } from '@kit.BasicServicesKit';
5 -import { FormDataType, NewspaperDataFetcher } from './NewspaperDataFetcher'; 5 +import { NewspaperDataFetcher } from './NewspaperDataFetcher';
6 import { JSON } from '@kit.ArkTS'; 6 import { JSON } from '@kit.ArkTS';
7 -import { FormNewspaperPaperType } from '../dailynewspaperwidget/common/NewspaperWidgetData'; 7 +import { FormNewspaperData, FormNewspaperPaperType } from '../dailynewspaperwidget/common/NewspaperWidgetData';
8 import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index'; 8 import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index';
  9 +import fs from '@ohos.file.fs';
9 10
10 const TAG = "DailyNewspaperFormAbility" 11 const TAG = "DailyNewspaperFormAbility"
11 12
12 export default class DailyNewspaperFormAbility extends FormExtensionAbility { 13 export default class DailyNewspaperFormAbility extends FormExtensionAbility {
  14 + lastDatas: Record<string, FormNewspaperData> = {}
  15 +
13 onAddForm(want: Want) { 16 onAddForm(want: Want) {
14 Logger.debug(TAG, "onAddForm with " + JSON.stringify(want)) 17 Logger.debug(TAG, "onAddForm with " + JSON.stringify(want))
15 18
16 this.initApp() 19 this.initApp()
17 - 20 +
18 if (want.parameters) { 21 if (want.parameters) {
19 let formId = want.parameters[formInfo.FormParam.IDENTITY_KEY] as string 22 let formId = want.parameters[formInfo.FormParam.IDENTITY_KEY] as string
20 let isTempCard = want.parameters[formInfo.FormParam.TEMPORARY_KEY] as boolean 23 let isTempCard = want.parameters[formInfo.FormParam.TEMPORARY_KEY] as boolean
21 if (isTempCard === false) { // 如果为常态卡片,直接进行信息持久化 24 if (isTempCard === false) { // 如果为常态卡片,直接进行信息持久化
22 25
23 - Logger.debug(TAG, "开始刷新数据");  
24 - NewspaperDataFetcher.refreshDailyPaper().then((data) => {  
25 -  
26 - let formData = formBindingData.createFormBindingData(data);  
27 - formProvider.updateForm(formId, formData).catch((err: BusinessError) => {  
28 - Logger.debug(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);  
29 - });  
30 - }) 26 + this.fetchAndRefreshData(formId)
31 } 27 }
32 } 28 }
33 29
34 - let obj: FormDataType = {} 30 + let obj: FormNewspaperData = {} as FormNewspaperData
35 obj.paperType = FormNewspaperPaperType.unknown 31 obj.paperType = FormNewspaperPaperType.unknown
36 let formData = formBindingData.createFormBindingData(obj); 32 let formData = formBindingData.createFormBindingData(obj);
37 return formData; 33 return formData;
@@ -45,13 +41,9 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility { @@ -45,13 +41,9 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
45 onUpdateForm(formId: string) { 41 onUpdateForm(formId: string) {
46 // 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新 42 // 若卡片支持定时更新/定点更新/卡片使用方主动请求更新功能,则提供方需要重写该方法以支持数据更新
47 Logger.debug(TAG, 'onUpdateForm ' + formId); 43 Logger.debug(TAG, 'onUpdateForm ' + formId);
48 - NewspaperDataFetcher.refreshDailyPaper().then((data) => {  
49 44
50 - let formData = formBindingData.createFormBindingData(data);  
51 - formProvider.updateForm(formId, formData).catch((err: BusinessError) => {  
52 - Logger.debug(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);  
53 - });  
54 - }) 45 + this.initApp()
  46 + this.fetchAndRefreshData(formId)
55 } 47 }
56 48
57 onFormEvent(formId: string, message: string) { 49 onFormEvent(formId: string, message: string) {
@@ -61,7 +53,9 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility { @@ -61,7 +53,9 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
61 53
62 onRemoveForm(formId: string) { 54 onRemoveForm(formId: string) {
63 // 当对应的卡片删除时触发的回调,入参是被删除的卡片ID 55 // 当对应的卡片删除时触发的回调,入参是被删除的卡片ID
64 - Logger.debug(TAG, 'onRemoveForm'); 56 + Logger.debug(TAG, 'onRemoveForm / formId: ' + formId);
  57 + let data = this.lastDatas[formId]
  58 + NewspaperDataFetcher.closeFilesWith(data)
65 } 59 }
66 60
67 // onConfigurationUpdate(config: Configuration) { 61 // onConfigurationUpdate(config: Configuration) {
@@ -75,6 +69,32 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility { @@ -75,6 +69,32 @@ export default class DailyNewspaperFormAbility extends FormExtensionAbility {
75 return formInfo.FormState.READY; 69 return formInfo.FormState.READY;
76 } 70 }
77 71
  72 + fetchAndRefreshData(formId: string) {
  73 + Logger.debug(TAG, "开始刷新数据");
  74 + NewspaperDataFetcher.refreshDailyPaper().then(async (data) => {
  75 +
  76 + let formData = formBindingData.createFormBindingData(data);
  77 + formProvider.updateForm(formId, formData).then(() => {
  78 + this.lastDatas[formId] = data
  79 + }).catch((err: BusinessError) => {
  80 + Logger.debug(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);
  81 + });
  82 +
  83 + let fileDir = this.context.getApplicationContext().filesDir + "/widget-daily-newspaper"
  84 + await FileUtils.makeDirIfNotExsit(fileDir)
  85 +
  86 + NewspaperDataFetcher.dealWithPictures(data, formId, fileDir, (data) => {
  87 + Logger.debug(TAG, `refresh ui with new pictuers`);
  88 + let formData = formBindingData.createFormBindingData(data);
  89 + formProvider.updateForm(formId, formData).then(() => {
  90 + this.lastDatas[formId] = data
  91 + }).catch((err: BusinessError) => {
  92 + Logger.error(TAG, ` xFailed to updateForm. Code: ${err.code}, message: ${err.message}`);
  93 + });
  94 + })
  95 + })
  96 + }
  97 +
78 initApp() { 98 initApp() {
79 // KV存储 99 // KV存储
80 SPHelper.init(this.context); 100 SPHelper.init(this.context);
1 import { CompInfoBean, ContentDTO, PageInfoBean } from 'wdBean/Index'; 1 import { CompInfoBean, ContentDTO, PageInfoBean } from 'wdBean/Index';
2 import { MorningEveningViewModel } from 'wdComponent/Index'; 2 import { MorningEveningViewModel } from 'wdComponent/Index';
3 -import { Logger } from 'wdKit/Index'; 3 +import { CrptoUtils, FileUtils, Logger } from 'wdKit/Index';
4 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork/Index'; 4 import { HttpUrlUtils, ResponseDTO, WDHttp } from 'wdNetwork/Index';
5 import { DeepLinkUtil } from 'wdShare/Index' 5 import { DeepLinkUtil } from 'wdShare/Index'
6 -import { FormNewspaperPaperType, FormNewspaperPaperInfo, FormNewspaperPaperContent } from "../dailynewspaperwidget/common/NewspaperWidgetData" 6 +import { FormNewspaperPaperType, FormNewspaperPaperInfo, FormNewspaperPaperContent,
  7 + FormNewspaperData } from "../dailynewspaperwidget/common/NewspaperWidgetData"
  8 +import { http } from '@kit.NetworkKit';
  9 +import fs from '@ohos.file.fs';
  10 +import { BusinessError } from '@kit.BasicServicesKit';
  11 +import { JSON } from '@kit.ArkTS';
7 12
8 const TAG = "NewspaperDataFetcher" 13 const TAG = "NewspaperDataFetcher"
9 14
10 -export type FormDataType = Record<string, FormNewspaperPaperType | FormNewspaperPaperInfo | FormNewspaperPaperContent[]> 15 +// export type FormDataType = Record<string, FormNewspaperPaperType | FormNewspaperPaperInfo | FormNewspaperPaperContent[]>
11 16
12 export class NewspaperDataFetcher { 17 export class NewspaperDataFetcher {
13 18
14 - public static async refreshDailyPaper(): Promise<FormDataType> {  
15 - return new Promise<FormDataType>(async (reslove, fail) => { 19 + public static async refreshDailyPaper(): Promise<FormNewspaperData> {
  20 + return new Promise<FormNewspaperData>(async (reslove, fail) => {
16 21
17 - let data: FormDataType = { 'paperType': FormNewspaperPaperType.unknown } 22 + let data: FormNewspaperData = new FormNewspaperData()
18 data.paperInfo = { showLeftImage: false } 23 data.paperInfo = { showLeftImage: false }
19 24
20 try { 25 try {
21 let page: PageInfoBean = await MorningEveningViewModel.getDailyPaperTopic() 26 let page: PageInfoBean = await MorningEveningViewModel.getDailyPaperTopic()
22 - data.paperType = page.topicInfo?.frontFlag || FormNewspaperPaperType.unknown 27 + data.paperType = page.topicInfo?.topicPattern || FormNewspaperPaperType.unknown
23 28
24 let currentTime = new Date().getTime() 29 let currentTime = new Date().getTime()
25 let compInfo = await MorningEveningViewModel.getMorningEveningCompInfo( 30 let compInfo = await MorningEveningViewModel.getMorningEveningCompInfo(
@@ -29,7 +34,7 @@ export class NewspaperDataFetcher { @@ -29,7 +34,7 @@ export class NewspaperDataFetcher {
29 page.topicInfo?.topicId 34 page.topicInfo?.topicId
30 ) 35 )
31 36
32 - if (page.topicInfo.frontLinkObject) { 37 + if (page.topicInfo?.frontFlag && page.topicInfo.frontLinkObject) {
33 data.paperInfo.showLeftImage = true 38 data.paperInfo.showLeftImage = true
34 data.paperInfo.leftImageUrl = page.topicInfo.frontLinkObject.coverUrl 39 data.paperInfo.leftImageUrl = page.topicInfo.frontLinkObject.coverUrl
35 data.paperInfo.leftTitle = page.topicInfo.frontLinkObject.title 40 data.paperInfo.leftTitle = page.topicInfo.frontLinkObject.title
@@ -60,7 +65,7 @@ export class NewspaperDataFetcher { @@ -60,7 +65,7 @@ export class NewspaperDataFetcher {
60 }) 65 })
61 } 66 }
62 67
63 - static fakeData(): FormDataType { 68 + static fakeData(): FormNewspaperData {
64 let data : FormNewspaperPaperContent = { 69 let data : FormNewspaperPaperContent = {
65 title: "标题标题标题标题标题标题标题标题", 70 title: "标题标题标题标题标题标题标题标题",
66 coverUrl: "https://" 71 coverUrl: "https://"
@@ -72,6 +77,135 @@ export class NewspaperDataFetcher { @@ -72,6 +77,135 @@ export class NewspaperDataFetcher {
72 leftTitle: "leftTitleleftTitleleftTitleleftTitleleftTitleleftTitle" 77 leftTitle: "leftTitleleftTitleleftTitleleftTitleleftTitleleftTitle"
73 }, 78 },
74 "paperContents": [data, data, data] 79 "paperContents": [data, data, data]
  80 + } as FormNewspaperData
  81 + }
  82 +
  83 + static dealWithPictures(data: FormNewspaperData, formId: string ,tempDir: string, refreshCallback:(data: FormNewspaperData) => void) {
  84 +
  85 + let donwloadCount = data.paperContents.filter((value) => {
  86 + return value.coverUrl && value.coverUrl.length > 0
  87 + }).length
  88 +
  89 + let fileFDs: Record<string, string | number> = {};
  90 + if (data.paperInfo.leftImageUrl) {
  91 + donwloadCount += 1
  92 +
  93 + CrptoUtils.md5(data.paperInfo.leftImageUrl).then((md5String) => {
  94 +
  95 + const fileName = formId + "file" + md5String;
  96 + const filePath = tempDir + "/" + fileName
  97 + NewspaperDataFetcher.downloadUrlToPath(data.paperInfo.leftImageUrl!, filePath).then(() => {
  98 + let file = fs.openSync(filePath)
  99 + fileFDs[fileName] = file.fd
  100 + data.paperInfo.localLeftImageFileName = fileName
  101 + data.formImages = fileFDs
  102 +
  103 + if (--donwloadCount == 0) { refreshCallback(data) }
  104 + }).catch((e : BusinessError) => {
  105 + Logger.debug(TAG, "download file failed.");
  106 + if (--donwloadCount == 0) { refreshCallback(data) }
  107 + })
  108 + }).catch((e: BusinessError) => {
  109 + if (--donwloadCount == 0) { refreshCallback(data) }
  110 + })
  111 + }
  112 +
  113 +
  114 + for (let index = 0; index < data.paperContents.length; index++) {
  115 + const content = data.paperContents[index];
  116 + if (!content.coverUrl || content.coverUrl.length == 0) {
  117 + continue
  118 + }
  119 +
  120 + CrptoUtils.md5(content.coverUrl).then((md5String) => {
  121 + const fileName = formId + "file" + md5String;
  122 + const filePath = tempDir + "/" + fileName
  123 + NewspaperDataFetcher.downloadUrlToPath(content.coverUrl!, filePath).then(() => {
  124 + Logger.debug(TAG, "open file for display ");
  125 + let file = fs.openSync(filePath)
  126 + fileFDs[fileName] = file.fd
  127 + data.paperContents[index].localCoverFileName = fileName
  128 + data.formImages = fileFDs
  129 +
  130 + if (--donwloadCount == 0) { refreshCallback(data) }
  131 + }).catch((e : BusinessError) => {
  132 + Logger.debug(TAG, "download file failed." + JSON.stringify(e));
  133 + if (--donwloadCount == 0) { refreshCallback(data) }
  134 + })
  135 + }).catch((e: BusinessError) => {
  136 + if (--donwloadCount == 0) { refreshCallback(data) }
  137 + })
75 } 138 }
76 } 139 }
  140 +
  141 + static closeFilesWith(data?: FormNewspaperData) {
  142 + if (data && data.formImages) {
  143 + for (const obj of Object.entries(data.formImages)) {
  144 + const fileName = obj[0]
  145 + let fd: number = obj[1] as number
  146 + fs.close(fd)
  147 + }
  148 + }
  149 + }
  150 +
  151 + static downloadUrlToPath(url: string, toFilePath: string): Promise<void> {
  152 + Logger.debug(TAG, "will donwload url:" + url + " ======> " + toFilePath);
  153 +
  154 + return new Promise((reslove, fail) => {
  155 +
  156 + FileUtils.fileExsit(toFilePath).then((exsit: boolean) => {
  157 + if (exsit) {
  158 + Logger.debug(TAG, "file is exsit. " + toFilePath);
  159 + reslove()
  160 + return
  161 + }
  162 +
  163 + NewspaperDataFetcher.downloadUrlToPathWithout(url, toFilePath).then(() => {
  164 + reslove()
  165 + }).catch((e: BusinessError) => {
  166 + fail(e)
  167 + })
  168 + }).catch((e: BusinessError) => {
  169 + NewspaperDataFetcher.downloadUrlToPathWithout(url, toFilePath).then(() => {
  170 + reslove()
  171 + }).catch((e: BusinessError) => {
  172 + fail(e)
  173 + })
  174 + })
  175 + })
  176 + }
  177 +
  178 + static downloadUrlToPathWithout(url: string, toFilePath: string): Promise<void> {
  179 + Logger.debug(TAG, "will donwload url:" + url + " ======> " + toFilePath);
  180 +
  181 + return new Promise((reslove, fail) => {
  182 +
  183 + let httpRequest = http.createHttp()
  184 + httpRequest.request(url, (err, data) => {
  185 +
  186 + if (!err && data.responseCode == http.ResponseCode.OK) {
  187 + let imgFile = fs.openSync(toFilePath, fs.OpenMode.READ_WRITE | fs.OpenMode.CREATE);
  188 + let wroteLength = 0
  189 + fs.write(imgFile.fd, data.result as ArrayBuffer).then((writeLen: number) => {
  190 + Logger.debug(TAG, "write data to file succeed and size is:" + writeLen);
  191 + wroteLength = writeLen
  192 + }).catch((err: BusinessError) => {
  193 + Logger.error(TAG, "write data to file failed with error message: " + err.message + ", error code: " + err.code);
  194 + }).finally(() => {
  195 + fs.closeSync(imgFile);
  196 + httpRequest.destroy()
  197 +
  198 + wroteLength > 0 ? reslove() : fail("failed")
  199 + });
  200 + return
  201 + }
  202 +
  203 + httpRequest.destroy()
  204 + fail("failed")
  205 + });
  206 +
  207 + })
  208 + }
  209 +
  210 +
77 } 211 }
@@ -11,6 +11,8 @@ export class FormNewspaperPaperInfo { @@ -11,6 +11,8 @@ export class FormNewspaperPaperInfo {
11 showLeftImage: boolean = false 11 showLeftImage: boolean = false
12 12
13 leftImageUrl?: string 13 leftImageUrl?: string
  14 + localLeftImageFileName?: ResourceStr // 传递图片用
  15 + localLeftImageFileFD? : number // 传递图片用
14 leftTitle?: string 16 leftTitle?: string
15 leftDeepLink?: string 17 leftDeepLink?: string
16 18
@@ -20,5 +22,15 @@ export class FormNewspaperPaperInfo { @@ -20,5 +22,15 @@ export class FormNewspaperPaperInfo {
20 export class FormNewspaperPaperContent { 22 export class FormNewspaperPaperContent {
21 title: string = "" 23 title: string = ""
22 coverUrl?: string 24 coverUrl?: string
  25 + localCoverFileName?: ResourceStr // 传递图片用
  26 + localCoverFileFD? : number // 传递图片用
23 deepLink: string = "" 27 deepLink: string = ""
24 } 28 }
  29 +
  30 +export class FormNewspaperData {
  31 + paperType: FormNewspaperPaperType = FormNewspaperPaperType.unknown
  32 + paperInfo: FormNewspaperPaperInfo = {} as FormNewspaperPaperInfo
  33 + paperContents: FormNewspaperPaperContent[] = []
  34 +
  35 + formImages: Record<string, string | number> = {}
  36 +}
@@ -43,8 +43,8 @@ struct DailyNewspaperWidgetCard { @@ -43,8 +43,8 @@ struct DailyNewspaperWidgetCard {
43 43
44 @Builder leftImageView() { 44 @Builder leftImageView() {
45 Stack({ alignContent: Alignment.Bottom }) { 45 Stack({ alignContent: Alignment.Bottom }) {
46 - Image(this.paperInfo.leftImageUrl)  
47 - // Image($r("app.media.desktop_card_comp_place_holder_16_9")) 46 + Image("memory://" + this.paperInfo.localLeftImageFileName)
  47 + // Image(this.paperInfo.leftImageUrl)
48 .alt($r("app.media.desktop_card_comp_place_holder_16_9")) 48 .alt($r("app.media.desktop_card_comp_place_holder_16_9"))
49 .objectFit(ImageFit.Cover) 49 .objectFit(ImageFit.Cover)
50 .aspectRatio(87/116) 50 .aspectRatio(87/116)
@@ -109,8 +109,8 @@ struct ContentCellView { @@ -109,8 +109,8 @@ struct ContentCellView {
109 bottom: this.hasImage ? 0 : 6}) 109 bottom: this.hasImage ? 0 : 6})
110 110
111 if (this.hasImage) { 111 if (this.hasImage) {
112 - Image(this.content.coverUrl)  
113 - // Image($r("app.media.desktop_card_comp_place_holder_3_4")) 112 + Image("memory://" + this.content.localCoverFileName)
  113 + // Image(this.content.coverUrl)
114 .alt($r("app.media.desktop_card_comp_place_holder_3_4")) 114 .alt($r("app.media.desktop_card_comp_place_holder_3_4"))
115 .objectFit(ImageFit.Cover) 115 .objectFit(ImageFit.Cover)
116 .height(40) 116 .height(40)
@@ -151,14 +151,12 @@ function jumpWithDeepLink(deepLink: string, component: Object) { @@ -151,14 +151,12 @@ function jumpWithDeepLink(deepLink: string, component: Object) {
151 if (deepLink.length == 0) { 151 if (deepLink.length == 0) {
152 return 152 return
153 } 153 }
154 - const deepLinkKey: string = NewspaperWidgetCommon.JumpParam.DeepLinkKey  
155 - const fromDailyNewspaperKey: string = NewspaperWidgetCommon.JumpParam.FromNewspaperWidgetKey  
156 postCardAction(component, { 154 postCardAction(component, {
157 action: NewspaperWidgetCommon.PosterCardAction.ActionRouter, 155 action: NewspaperWidgetCommon.PosterCardAction.ActionRouter,
158 abilityName: NewspaperWidgetCommon.PosterCardAction.MainAbilityName, 156 abilityName: NewspaperWidgetCommon.PosterCardAction.MainAbilityName,
159 params: { 157 params: {
160 - deepLinkKey: deepLink,  
161 - fromDailyNewspaperKey: true 158 + "newspaper.widget.jump.deeplink": deepLink,
  159 + "newspaper.widget.jump.fromNewspaperWidget": 1
162 } 160 }
163 }); 161 });
164 } 162 }
@@ -12,13 +12,14 @@ import { DeviceUtil, @@ -12,13 +12,14 @@ import { DeviceUtil,
12 UmengStats } from 'wdKit/Index' 12 UmengStats } from 'wdKit/Index'
13 import { LoginModule } from 'wdLogin/Index' 13 import { LoginModule } from 'wdLogin/Index'
14 import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index' 14 import { HostEnum, HostManager, WDHttp } from 'wdNetwork/Index'
15 -import { registerRouter } from 'wdRouter/Index' 15 +import { AppInnerLink, registerRouter } from 'wdRouter/Index'
16 import { TrackingModule } from 'wdTracking/Index' 16 import { TrackingModule } from 'wdTracking/Index'
17 import { JSON } from '@kit.ArkTS' 17 import { JSON } from '@kit.ArkTS'
18 import app from '@system.app' 18 import app from '@system.app'
19 import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index' 19 import { GetuiPush, HWLocationUtils } from 'wdHwAbility/Index'
20 import { ImageKnife, ImageKnifeGlobal } from '@ohos/imageknife' 20 import { ImageKnife, ImageKnifeGlobal } from '@ohos/imageknife'
21 import { webview } from '@kit.ArkWeb' 21 import { webview } from '@kit.ArkWeb'
  22 +import { NewspaperWidgetCommon } from '../dailynewspaperwidget/common/NewspaperWidgetCommon'
22 23
23 const TAG = "[StartupManager]" 24 const TAG = "[StartupManager]"
24 25
@@ -26,6 +27,7 @@ const TAG = "[StartupManager]" @@ -26,6 +27,7 @@ const TAG = "[StartupManager]"
26 export class StartupManager { 27 export class StartupManager {
27 28
28 private context?: common.UIAbilityContext 29 private context?: common.UIAbilityContext
  30 + private lastStartupWant?: Want
29 31
30 private constructor() { 32 private constructor() {
31 } 33 }
@@ -74,10 +76,14 @@ export class StartupManager { @@ -74,10 +76,14 @@ export class StartupManager {
74 // 通知栏点击后启动 76 // 通知栏点击后启动
75 GetuiPush.sharedInstance().onWant(want) 77 GetuiPush.sharedInstance().onWant(want)
76 Logger.debug(TAG, "App onCreate: finised") 78 Logger.debug(TAG, "App onCreate: finised")
  79 +
  80 + this.lastStartupWant = want
77 } 81 }
78 82
79 appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) { 83 appOnNewWant(want: Want, launchParam: AbilityConstant.LaunchParam) {
80 GetuiPush.sharedInstance().onNewWant(want) 84 GetuiPush.sharedInstance().onNewWant(want)
  85 +
  86 + this.dealWithDeepLink(want)
81 } 87 }
82 88
83 appOnDestory() { 89 appOnDestory() {
@@ -124,6 +130,10 @@ export class StartupManager { @@ -124,6 +130,10 @@ export class StartupManager {
124 //TODO: 130 //TODO:
125 // 提前初始化webview 131 // 提前初始化webview
126 webview.WebviewController.initializeWebEngine() 132 webview.WebviewController.initializeWebEngine()
  133 +
  134 + if (this.lastStartupWant && this.dealWithDeepLink(this.lastStartupWant)) {
  135 + this.lastStartupWant = undefined
  136 + }
127 resolve() 137 resolve()
128 }) 138 })
129 } 139 }
@@ -195,4 +205,20 @@ export class StartupManager { @@ -195,4 +205,20 @@ export class StartupManager {
195 private initOthers() { 205 private initOthers() {
196 206
197 } 207 }
  208 +
  209 + private dealWithDeepLink(want: Want): boolean {
  210 +
  211 + if (!want.parameters) {
  212 + return false
  213 + }
  214 +
  215 + let deepLink = want.parameters[NewspaperWidgetCommon.JumpParam.DeepLinkKey] as string
  216 +
  217 + if (deepLink && deepLink.length) {
  218 +
  219 + AppInnerLink.jumpWithLink(deepLink)
  220 + return true
  221 + }
  222 + return false
  223 + }
198 } 224 }
@@ -14,8 +14,8 @@ @@ -14,8 +14,8 @@
14 "isDynamic": true, 14 "isDynamic": true,
15 "isDefault": true, 15 "isDefault": true,
16 "updateEnabled": true, 16 "updateEnabled": true,
17 - "scheduledUpdateTime": "10:30",  
18 - "updateDuration": 1, 17 + "scheduledUpdateTime": "18:26",
  18 + "updateDuration": 4,
19 "defaultDimension": "2*4", 19 "defaultDimension": "2*4",
20 "supportDimensions": [ 20 "supportDimensions": [
21 "2*4" 21 "2*4"