liyubing

Merge remote-tracking branch 'origin/main'

import data_preferences from '@ohos.data.preferences';
import { Logger } from './Logger';
import { JSON } from '@kit.ArkTS';
const TAG = 'SPHelper'
const logEnable = false
/**
* sp存储,单条数据,value<1k;业务数据超过1k的,建议使用KVStoreHelper
*/
... ... @@ -12,10 +15,14 @@ export class SPHelper {
static init(context: Context) {
SPHelper.context = context;
if (context) {
Logger.debug(TAG, '初始化context')
}
}
static setSpFilename(spFilename: string) {
SPHelper.spFilename = spFilename;
Logger.debug(TAG, '设置文件名: ' + spFilename)
}
// 静态属性
... ... @@ -37,47 +44,75 @@ export class SPHelper {
}
async save(key: string, value: data_preferences.ValueType) {
try {
const preferences: data_preferences.Preferences = await this.getVideoPreferences();
await preferences.put(key, value)
await preferences.flush()
if (logEnable) {
Logger.debug(TAG, '保存 key: ' + key + " value => " + value)
}
} catch (e) {
Logger.error(TAG, '保存 key: ' + key + " value => " + value + " 报错:" + JSON.stringify(e))
}
}
saveSync(key: string, value: data_preferences.ValueType) {
const preferences: data_preferences.Preferences = this.getVideoPreferencesSync();
preferences.putSync(key, value)
preferences.flush().then(() => {
Logger.debug(TAG, 'saveSync flush success')
if (logEnable) {
Logger.debug(TAG, 'sync保存 key: ' + key + " value => " + value)
}
}).catch((error: object) => {
Logger.debug(TAG, 'saveSync flush failed: ' + JSON.stringify(error))
Logger.error(TAG, 'sync保存 key: ' + key + " value => " + value + " 报错:" + JSON.stringify(error))
});
}
async get(key: string, defValue: data_preferences.ValueType): Promise<data_preferences.ValueType> {
const preferences: data_preferences.Preferences = await this.getVideoPreferences();
return await preferences.get(key, defValue);
const data = await preferences.get(key, defValue);
if (logEnable) {
Logger.debug(TAG, '获取 key: ' + key + " value => " + data + "| 默认值:" + defValue)
}
return data
}
getSync(key: string, defValue: data_preferences.ValueType): data_preferences.ValueType {
const preferences: data_preferences.Preferences = this.getVideoPreferencesSync();
return preferences.getSync(key, defValue);
const data = preferences.getSync(key, defValue);
if (logEnable) {
Logger.debug(TAG, 'sync获取 key: ' + key + " value => " + data + "| 默认值:" + defValue)
}
return data
}
async has(key: string): Promise<boolean> {
const preferences: data_preferences.Preferences = await this.getVideoPreferences();
return await preferences.has(key);
const data = await preferences.has(key);
if (logEnable) {
Logger.debug(TAG, 'has key: ' + key + ' => ' + data)
}
return data
}
hasSync(key: string): boolean {
const preferences: data_preferences.Preferences = this.getVideoPreferencesSync();
return preferences.hasSync(key);
const data = preferences.hasSync(key);
if (logEnable) {
Logger.debug(TAG, 'synchas key: ' + key + ' => ' + data)
}
return data
}
async delete(key: string) {
const preferences: data_preferences.Preferences = await this.getVideoPreferences();
preferences.delete(key).then(async () => {
await preferences.flush();
if (logEnable) {
Logger.debug(TAG, '删除 key: ' + key)
}
}).catch((err: Error) => {
// Logger.error(TAG, 'Failed to delete the key. Cause: ' + err);
Logger.error(TAG, '删除 key失败:' + JSON.stringify(err));
});
}
... ... @@ -85,9 +120,11 @@ export class SPHelper {
const preferences: data_preferences.Preferences = this.getVideoPreferencesSync();
preferences.deleteSync(key)
preferences.flush().then(() => {
Logger.debug(TAG, 'deleteSync flush success')
if (logEnable) {
Logger.debug(TAG, 'sync删除 key: ' + key)
}
}).catch((error: object) => {
Logger.debug(TAG, 'deleteSync flush failed: ' + JSON.stringify(error))
Logger.error(TAG, 'sync删除 key失败:' + JSON.stringify(error));
});
}
... ... @@ -95,8 +132,9 @@ export class SPHelper {
this.getVideoPreferences().then(async (preferences: data_preferences.Preferences) => {
preferences.clearSync()
await preferences.flush()
Logger.debug(TAG, 'sync清除所有数据');
}).catch((err: Error) => {
// Logger.error(TAG, 'get the preferences failed, Cause: ' + err);
Logger.error(TAG, 'sync清除所有数据,失败:' + JSON.stringify(err));
});
}
... ...
... ... @@ -9,6 +9,16 @@ import { commentInfo } from './commentInfo';
import { BaseDTO } from '../component/BaseDTO';
import { LiveRoomDataBean } from '../live/LiveRoomDataBean';
export class ContentShareInfoDTO {
shareTitle: string = ''
shareUrl: string = ''
shareSummary: string = ''
shareCoverUrl: string = ''
sharePosterCoverUrl: string = ''
shareOpen: number = 0
sharePosterOpen: number = 0
}
@Observed
export class ContentDTO implements BaseDTO {
seoTags: string = '';
... ... @@ -70,6 +80,7 @@ export class ContentDTO implements BaseDTO {
fullColumnImgUrls: FullColumnImgUrlDTO[] = [];
liveInfo: LiveInfoDTO = {} as LiveInfoDTO; // 直播新闻信息【BFF聚合】
videoInfo: VideoInfoDTO = {} as VideoInfoDTO; // 视频新闻信息【BFF聚合】,视频非原片+清晰度最高的
shareInfo: ContentShareInfoDTO = {} as ContentShareInfoDTO
newsSummary: string = ''; //appstyle:2 ,新闻详情
contentText?: string = '';
... ... @@ -154,6 +165,7 @@ export class ContentDTO implements BaseDTO {
content.fullColumnImgUrls = old.fullColumnImgUrls;
content.liveInfo = old.liveInfo;
content.videoInfo = old.videoInfo;
content.shareInfo = old.shareInfo
content.newsSummary = old.newsSummary;
content.interactData = old.interactData;
content.hasMore = old.hasMore;
... ...
... ... @@ -6,6 +6,7 @@ import { ProcessUtils, WDRouterRule } from 'wdRouter';
import { TrackConstants,
TrackingButton,
TrackingContent, TrackingPageBrowse, TrackParamConvert } from 'wdTracking/Index';
import { WDShare } from 'wdShare/Index';
const TAG: string = 'CardView';
... ... @@ -588,7 +589,7 @@ export struct PaperSingleColumn999CardView {
right: { anchor: '__container__', align: HorizontalAlign.End }
})
.onClick(() => {
ToastUtils.showToast('分享为公共方法,待开发', 1000)
WDShare.shareProgram(this.item)
})
}.width(CommonConstants.FULL_PARENT)
.justifyContent(FlexAlign.SpaceBetween)
... ...
import { SpConstants } from 'wdConstant';
import { Logger, SPHelper, ToastUtils, EmitterEventId, EmitterUtils, DateTimeUtils, CustomToast } from 'wdKit';
import {MineMainSettingFunctionItem} from '../../viewmodel/MineMainSettingFunctionItem';
import MineSettingDatasModel from '../../model/MineSettingDatasModel';
import { MineSettingDatasModel } from '../../model/MineSettingDatasModel';
import router from '@ohos.router';
import { WDRouterPage, WDRouterRule } from 'wdRouter';
import { Params } from 'wdBean';
... ...
... ... @@ -9,13 +9,15 @@ import { Params } from 'wdBean';
// import { common } from '@kit.AbilityKit';
import fs from '@ohos.file.fs';
import { CustomCacheDialog } from './CustomCacheDialog';
import MineSettingDatasModel from '../../model/MineSettingDatasModel';
import { MineSettingDatasModel } from '../../model/MineSettingDatasModel';
import { MineMainSettingFunctionItem } from '../../viewmodel/MineMainSettingFunctionItem';
import common from '@ohos.app.ability.common';
import dataPreferences from '@ohos.data.preferences';
import { TitleBackComponent } from './TitleBackComponent';
import { MyCustomDialog } from '../reusable/MyCustomDialog';
import { TrackingButton, TrackConstants } from 'wdTracking/Index';
import { JSON } from '@kit.ArkTS';
import { HttpUtils } from 'wdNetwork/Index';
@Component
export struct MineSettingComponent {
... ... @@ -82,10 +84,9 @@ export struct MineSettingComponent {
async getSettingPageData() {
let oldList = MineSettingDatasModel.getMineMainSettingFunctionItemData();
let userId=await SPHelper.default.get(SpConstants.USER_ID,'') as string
if(userId==''){
this.listData=oldList.slice(1,oldList.length)
}else {
if (!HttpUtils.isLogin()) {
this.listData = oldList.slice(1,oldList.length)
} else {
this.listData = oldList;
}
... ... @@ -167,6 +168,7 @@ export struct MineSettingComponent {
.margin({ left: `${this.calcHeight(81)}lpx`, right: `${this.calcHeight(29)}lpx` })
.selectedColor("#ED2800")
.onChange((isOn: boolean) => {
Logger.debug("SPHelper", "数据 : " + JSON.stringify(item))
if(item.itemType=='push_switch'){
trackButtonClick("settingPagePushSwitch")
//推送
... ...
... ... @@ -296,7 +296,6 @@ export struct LiveOperRowListView {
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
.onClick((event: ClickEvent) => {
// ToastUtils.showToast('分享为公共方法,待开发', 1000);
this.share()
})
}
... ...
... ... @@ -391,7 +391,6 @@ export struct OperRowListView {
.aspectRatio(1)
.interpolation(ImageInterpolation.High)
.onClick((event: ClickEvent) => {
// ToastUtils.showToast('分享为公共方法,待开发', 1000);
this.share()
})
}
... ...
... ... @@ -12,74 +12,49 @@ const TAG = "MineSettingDatasModel"
/**
* 我的设置页面 所有数据 获取封装类
*/
class MineSettingDatasModel{
private static instance: MineSettingDatasModel;
mainSettingData:Array<MineMainSettingFunctionItem> = []
accountAndSecurityData:Array<MineMainSettingFunctionItem> = []
private constructor() { }
/**
* 单例模式
* @returns
*/
public static getInstance(): MineSettingDatasModel {
if (!MineSettingDatasModel.instance) {
MineSettingDatasModel.instance = new MineSettingDatasModel();
}
return MineSettingDatasModel.instance;
}
export class MineSettingDatasModel {
/**
* 评论 关注 收藏 等7个数据
* 包含名字和图标
*/
getMineMainSettingFunctionItemData():MineMainSettingFunctionItem[]{
if(this.mainSettingData.length === 7){
return this.mainSettingData
}
this.mainSettingData = []
this.mainSettingData.push(new MineMainSettingFunctionItem(null, '账户与安全', '18888888888', 0, false,"account"))
static getMineMainSettingFunctionItemData() {
let mainSettingData: MineMainSettingFunctionItem[] = []
mainSettingData.push(new MineMainSettingFunctionItem(null, '账户与安全', '18888888888', 0, false,"account"))
let pushState=SPHelper.default.getSync(SpConstants.SETTING_PUSH_SWITCH,false) as boolean
this.mainSettingData.push(new MineMainSettingFunctionItem(null, '接收推送', null, 1, pushState,"push_switch"))
this.mainSettingData.push(new MineMainSettingFunctionItem(null, '隐私设罝', null, 0, false,"private_setting"))
mainSettingData.push(new MineMainSettingFunctionItem(null, '接收推送', null, 1, pushState,"push_switch"))
mainSettingData.push(new MineMainSettingFunctionItem(null, '隐私设罝', null, 0, false,"private_setting"))
let wifiState=SPHelper.default.getSync(SpConstants.SETTING_WIFI_IMAGE_SWITCH,false) as boolean
this.mainSettingData.push(new MineMainSettingFunctionItem(null, '仅wifi网络加载图片', null, 1, wifiState,"wifi_switch"))
mainSettingData.push(new MineMainSettingFunctionItem(null, '仅wifi网络加载图片', null, 1, wifiState,"wifi_switch"))
let videoState=SPHelper.default.getSync(SpConstants.SETTING_WIFI_VIDEO_SWITCH,false) as boolean
this.mainSettingData.push(new MineMainSettingFunctionItem(null, 'wifi网络情况下自动播放视频', null, 1, videoState,"video_switch"))
mainSettingData.push(new MineMainSettingFunctionItem(null, 'wifi网络情况下自动播放视频', null, 1, videoState,"video_switch"))
let suspensionState=SPHelper.default.getSync(SpConstants.SETTING_SUSPENSION_SWITCH,false) as boolean
this.mainSettingData.push(new MineMainSettingFunctionItem(null, '开启播放器悬浮窗', null, 1, suspensionState,"suspensionState_switch"))
mainSettingData.push(new MineMainSettingFunctionItem(null, '开启播放器悬浮窗', null, 1, suspensionState,"suspensionState_switch"))
// this.mainSettingData.push(new MineMainSettingFunctionItem(null, null, null, 2, null,""))
this.mainSettingData.push(new MineMainSettingFunctionItem(null, '清理缓存', '32MB', 0, false,"clear_cache"))
mainSettingData.push(new MineMainSettingFunctionItem(null, '清理缓存', '32MB', 0, false,"clear_cache"))
// this.mainSettingData.push(new MineMainSettingFunctionItem(null, '评价我们', null, 0, false,""))
return this.mainSettingData
return mainSettingData
}
/**
* 评论 关注 收藏 等7个数据
* 包含名字和图标
*/
getAccountAndSecuritySettingData():MineMainSettingFunctionItem[]{
if(this.accountAndSecurityData.length === 7){
return this.accountAndSecurityData
}
this.accountAndSecurityData = []
this.accountAndSecurityData.push(new MineMainSettingFunctionItem(null, '更换手机号', '18888888888', 0, false,""))
this.accountAndSecurityData.push(new MineMainSettingFunctionItem(null, '设置密码', null, 0, false,""))
this.accountAndSecurityData.push(new MineMainSettingFunctionItem(null, null, null, 2, null,""))
static getAccountAndSecuritySettingData():MineMainSettingFunctionItem[]{
let accountAndSecurityData: MineMainSettingFunctionItem[] = []
accountAndSecurityData.push(new MineMainSettingFunctionItem(null, '更换手机号', '18888888888', 0, false,""))
accountAndSecurityData.push(new MineMainSettingFunctionItem(null, '设置密码', null, 0, false,""))
accountAndSecurityData.push(new MineMainSettingFunctionItem(null, null, null, 2, null,""))
// this.accountAndSecurityData.push(new MineMainSettingFunctionItem($r('app.media.account_qqicon'), '绑定QQ', '立即绑定', 0, false,""))
// this.accountAndSecurityData.push(new MineMainSettingFunctionItem($r('app.media.account_wechaticon'), '绑定微信', '立即绑定', 0, false,""))
// this.accountAndSecurityData.push(new MineMainSettingFunctionItem($r('app.media.account_weiboicon'), '绑定新浪微博', '立即绑定', 0, false,""))
// this.accountAndSecurityData.push(new MineMainSettingFunctionItem($r('app.media.account_appleicon'), 'Apple ID', null, 0, false,""))
// this.accountAndSecurityData.push(new MineMainSettingFunctionItem(null, null, null, 2, null,""))
this.accountAndSecurityData.push(new MineMainSettingFunctionItem(null, '注销账号', null, 0, false,""))
accountAndSecurityData.push(new MineMainSettingFunctionItem(null, '注销账号', null, 0, false,""))
return this.accountAndSecurityData
return accountAndSecurityData
}
... ... @@ -113,10 +88,10 @@ class MineSettingDatasModel{
/**
* 判断是否设置过密码
*/
checkSetPassword(): Promise<CheckSetPasswordItem> {
static checkSetPassword(): Promise<CheckSetPasswordItem> {
return new Promise<CheckSetPasswordItem>((success, error) => {
Logger.info(TAG, `checkSetPassword start`);
this.fetchCheckSetPassword().then((navResDTO: ResponseDTO<CheckSetPasswordItem>) => {
MineSettingDatasModel.fetchCheckSetPassword().then((navResDTO: ResponseDTO<CheckSetPasswordItem>) => {
if (!navResDTO || navResDTO.code != 0) {
error(null)
return
... ... @@ -131,13 +106,9 @@ class MineSettingDatasModel{
})
}
fetchCheckSetPassword() {
static fetchCheckSetPassword() {
let url = HttpUrlUtils.checkSetPassword()
return WDHttp.get<ResponseDTO<CheckSetPasswordItem>>(url)
};
}
const mineSettingDatasModel = MineSettingDatasModel.getInstance()
export default mineSettingDatasModel as MineSettingDatasModel
// export default MineMainSettingFunctionItem as MineMainSettingFunctionItem
... ...
... ... @@ -13,6 +13,7 @@ import { HttpUrlUtils } from 'wdNetwork/Index';
import { WDPlayerController } from 'wdPlayer/Index';
import { WDRouterPage, WDRouterRule } from 'wdRouter/Index';
import { SpConstants } from 'wdConstant/Index'
import { WDShare } from 'wdShare/Index';
export interface OperationItem {
icon: Resource;
... ... @@ -282,7 +283,7 @@ export struct OperationListView {
.width(32)
.aspectRatio(1)
.onClick((event: ClickEvent) => {
ToastUtils.showToast('分享为公共方法,待开发', 1000);
WDShare.shareContent(this.contentDetailData)
})
Text(item.text)
.width('100%')// .margin({ top: 4, left: 6, right: 6 })// .backgroundColor(Color.Brown)
... ...
... ... @@ -22,7 +22,18 @@ export class WDShare {
}
static shareProgram(program: ContentDTO, pageName: string ="", pageId: string = "") {
//TODO: 处理分享弹框交互和 海报逻辑
WDShareBase.getInstance().share({
to: ShareType.System,
scene: ShareScene.System,
type: ShareContentType.Link,
obj: {
title: program.shareInfo.shareTitle,
desc: program.shareInfo.shareSummary,
link: program.shareInfo.shareUrl,
}
})
}
static shareSubject(subject: PageInfoDTO) {
... ...