// Update is called once per frame public void SetData(WorksWall data) { float workWallItemHeight = 0; if (data.babyId == PlayerPrefsUtil.GetBabyId()) { BtnShare.gameObject.SetActive(true); } else { BtnShare.gameObject.SetActive(false); } // 分享事件 BtnShare.onClick.AddListener(() => { AttendanceModel model = new AttendanceModel(); model.boxDay = data.boxDay; model.punchPath = data.punchPathUrl; model.punchText = data.punchText; model.punchType = data.punchType; model.shareScore = data.shareScore; model.finishPunchNum = data.finishPunchNum; model.relBoxId = data.relBoxId; model.id = data.id; model.subject = data.subject; UIMgr.OpenPanel <AttendanceSharePanel>(new AttendanceSharePanelData() { AttendanceModel = model, isWall = true }, UITransitionType.CIRCLE); }); // 查看我的打卡 图片or 视频 BtnImgPreview.onClick.AddListener(() => { if (data.punchType == 0) //图文 { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForShowPic(data.punchPathUrl); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { UIMgr.OpenPanel <PhotoBrowserPanel>(new PhotoBrowserPanelData() { ImageUrl = data.punchPathUrl, }, UITransitionType.NULL); } } else if (data.punchType == 2) //视频 { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForPlayVideo(data.punchPathUrl); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> paramDic = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); subParam.Add("url", data.punchPathUrl); paramDic.Add("target", AppConst.VIDEO_IOS); paramDic.Add("method", IOSClientUtil.VideoMediaPlay); paramDic.Add("params", subParam); IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson()); } } }); TextShareContent.text = StringUtil.Emoji(data.punchText); TextAge.text = data.age; TextName.text = StringUtil.Emoji(data.name); TextTimeLine.text = data.createTime; IsAudioPreviewPlaying.Subscribe(isPlaying => { Texture2D soundOnTexture = mResLoader.LoadSync <Texture2D>(isPlaying ? "ic_works_wall_audio_pause" : "ic_works_wall_audio_start"); ImgAudio.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); }).AddTo(this); IsAudioContenPlaying.Subscribe(isPlaying => { Texture2D soundOnTexture = mResLoader.LoadSync <Texture2D>(isPlaying ? "ic_audio_playing" : "ic_audiio_pause"); ImgPlayState.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); }).AddTo(this); AudioContenPlayingTime.Subscribe(time => { if (time == 0) { TextTime.text = AudioContenTotleTime.Value + "\""; } else { TextTime.text = time + "\"" + "/" + AudioContenTotleTime.Value + "\""; } }).AddTo(this); // 用户头像,没有传头像 使用默认的 Texture2D mTexture2DHBoy = mResLoader.LoadSync <Texture2D>("ic_head_boy"); Texture2D mTexture2DHGirl = mResLoader.LoadSync <Texture2D>("ic_head_girl"); if (PlayerPrefsUtil.UserInfo.babyInfoVo.babyLogoUrl.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage(data.logoRelativePathUrl, ImageUserIcon); } else if (PlayerPrefsUtil.UserInfo.babyInfoVo.sex == 1) { ImageUserIcon.sprite = Sprite.Create(mTexture2DHBoy, new Rect(0, 0, mTexture2DHBoy.width, mTexture2DHBoy.height), Vector2.one * 0.5f); } else if (PlayerPrefsUtil.UserInfo.babyInfoVo.sex == 2) { ImageUserIcon.sprite = Sprite.Create(mTexture2DHGirl, new Rect(0, 0, mTexture2DHGirl.width, mTexture2DHGirl.height), Vector2.one * 0.5f); } // 0-图文打卡 1-音频打卡 2-视频打卡 if (data.punchType == 0) { ImgSharePreview.SetActive(true); ImgAudioPreview.SetActive(false); ImageDownloadUtils.Instance.SetAsyncImage(data.punchPathUrl, ImageThumIcon); ImagePunchType.gameObject.SetActive(false); } else if (data.punchType == 1) { ImgSharePreview.SetActive(false); ImgAudioPreview.SetActive(true); BtnAudioPreview.onClick.AddListener(() => { if (AudioContentAudioSource.isPlaying) { AudioContentAudioSource.Pause(); } Log.I("data.punchPathUrl==" + data.punchPathUrl); if (AudioPreviewAudioSource.isPlaying) { AudioPreviewAudioSource.Pause(); } else { StartCoroutine(SetAudioClip(data.punchPathUrl, AudioPreviewAudioSource)); } }); ImagePunchType.gameObject.SetActive(false); } else if (data.punchType == 2) { ImgSharePreview.SetActive(true); ImgAudioPreview.SetActive(false); ImageDownloadUtils.Instance.SetAsyncImage(data.thumbnailPath, ImageThumIcon); ImagePunchType.gameObject.SetActive(true); } if (data.comments.IsNotNull() && data.comments.Count > 0) { Line.SetActive(true); TextReply.gameObject.SetActive(true); TextReplyContent.gameObject.SetActive(data.comments[0].commentContent.IsNotNullAndEmpty()); TextReplyContent.text = StringUtil.Emoji(data.comments[0].commentContent); if (data.comments[0].commentPathUrl.IsNotNullAndEmpty()) { AudioContent.SetActive(true); TextTime.text = data.comments[0].duration / 1000 + "\""; BtnPlayState.onClick.AddListener(() => { if (AudioPreviewAudioSource.isPlaying) { AudioPreviewAudioSource.Pause(); } if (AudioContentAudioSource.isPlaying) { AudioContentAudioSource.Pause(); } else { StartCoroutine(SetAudioClip(data.comments[0].commentPathUrl, AudioContentAudioSource)); } }); } else { AudioContent.SetActive(false); } } else { Line.SetActive(false); TextReply.gameObject.SetActive(false); TextReplyContent.gameObject.SetActive(false); AudioContent.SetActive(false); } LayoutRebuilder.ForceRebuildLayoutImmediate(MidPanelTransform); int height = (int)(Mathf.Abs(MidPanelTransform.rect.height) + 168); Debug.Log("MidPanelTransform 的高度 是 " + MidPanelTransform.rect.height); Debug.Log("TextShareContent 的高度 是 " + (TextShareContent.rectTransform.rect.height)); workWallItemHeight += TextName.rectTransform.rect.height; // 名称 workWallItemHeight += 10; // spacing workWallItemHeight += TextTimeLine.rectTransform.rect.height; // 发布时间 workWallItemHeight += 10; // spacing workWallItemHeight += TextShareContent.rectTransform.rect.height; // 发布的内容 workWallItemHeight += 10; // spacing if (data.comments.Count > 0) { workWallItemHeight += TextReply.rectTransform.rect.height; // 老师回复 workWallItemHeight += 10; // spacing workWallItemHeight += TextReplyContent.rectTransform.rect.height; // 点评的内容 if (data.comments[0].commentPathUrl.IsNotNullAndEmpty()) { workWallItemHeight += 44; // 回复音频高度 workWallItemHeight += 10; // spacing } } workWallItemHeight += (34 + 60); // spacing if (workWallItemHeight < 312) { workWallItemHeight = 312; } transform.GetComponent <RectTransform>().sizeDelta = new Vector2(940, workWallItemHeight); }
protected override void OnInit(QFramework.IUIData uiData) { mData = uiData as AttendanceAddPanelData ?? new AttendanceAddPanelData(); mPath = mData.Path; mThumbnailPath = mData.ThumbnailPath; texture2DAddPhoto = mResLoader.LoadSync <Texture2D>("attendance_main_add"); BtnBack.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Back(); }); BtnCancel.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); Back(); }); BtnPush.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); // if (InputContent.text.IsNullOrEmpty()) // { // CommonUtil.toast("请输入内容"); // Log.I("请输入内容"); // return; // } if (mPath.IsNullOrEmpty()) { if (mData.Action == AttendanceAdd.Pic) { CommonUtil.toast("请添加图片"); Log.I("请添加图片"); } else if (mData.Action == AttendanceAdd.Audio) { CommonUtil.toast("请添加音频"); Log.I("请添加音频"); } else if (mData.Action == AttendanceAdd.Video) { CommonUtil.toast("请添加视频"); Log.I("请添加视频"); } return; } LoadingManager.GetInstance().CreatLoading(); BtnPush.enabled = false; if (mData.Action == AttendanceAdd.Pic) { string fileType = mPath.Substring(mPath.LastIndexOf(".")); Log.I("mPath: " + mPath + " fileType: " + fileType); StartRequestForUpload("attendance" + fileType, mPath); } else if (mData.Action == AttendanceAdd.Audio) { MicrophoneManager.GetInstance().StopPlay(); string fileType = mPath.Substring(mPath.LastIndexOf(".")); Log.I("mPath: " + mPath + " fileType: " + fileType); StartRequestForUpload("attendance" + fileType, mPath); } else if (mData.Action == AttendanceAdd.Video) { if (Application.platform == RuntimePlatform.Android) { // CommonUtil.toast("视频压缩上传中,请稍等"); AndroidForUnity.CallAndroidForVideoCompress(mPath); } else { StartCoroutine(IPhonePlayerCompressFinished()); } } }); BtnAdd.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (mData.Action == AttendanceAdd.Audio) { UIMgr.OpenPanel <AttendanceAudioRecordPanel>(new AttendanceAudioRecordPanelData(), UITransitionType.CIRCLE); } else { //unityForPlayVideo if (mPath.IsNullOrEmpty()) { if (mData.Action == AttendanceAdd.Pic) { UIMgr.OpenPanel <ChoosePhotoPanel>(new ChoosePhotoPanelData() { action = ChoosePhotoAction.AttendancePic, }); } else if (mData.Action == AttendanceAdd.Video) { // UIMgr.OpenPanel<ChoosePhotoPanel>(new ChoosePhotoPanelData() // { // action = ChoosePhotoAction.AttendanceVideo, // showTip = true // // }); if (Application.platform == RuntimePlatform.IPhonePlayer) { IPhonePlayerMakeVideoOpenCamera(); } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetVideoFromGalleryForAndroid((json) => { if (json.IsNotNullAndEmpty()) { NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json); if (model.IsNotNull()) { if (model.status == 1) { mPath = model.videoPath; mThumbnailPath = model.imagePath; AudioContent.gameObject.SetActive(false); if (model.imagePath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic); BtnVideo.gameObject.SetActive(true); BtnDel.gameObject.SetActive(true); } } else if (model.status == 0) { mPath = null; mThumbnailPath = null; ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(false); } } } }, "选择视频", "video/*", action); } }, (int)NativeAction.Camera); } } } else { if (mData.Action == AttendanceAdd.Pic) { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForShowPic(mPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { UIMgr.OpenPanel <PhotoBrowserPanel>(new PhotoBrowserPanelData() { ImageUrl = mPath, }, UITransitionType.NULL); } } else if (mData.Action == AttendanceAdd.Video) { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForPlayVideo(mPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> paramDic = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); subParam.Add("url", mPath); paramDic.Add("target", AppConst.VIDEO_IOS); paramDic.Add("method", IOSClientUtil.VideoMediaPlay); paramDic.Add("params", subParam); IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson()); } } } } }); BtnVideo.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); if (mData.Action == AttendanceAdd.Video) { if (Application.platform == RuntimePlatform.Android) { AndroidForUnity.CallAndroidForPlayVideo(mPath); } else if (Application.platform == RuntimePlatform.IPhonePlayer) { Dictionary <string, object> paramDic = new Dictionary <string, object>(); Dictionary <string, object> subParam = new Dictionary <string, object>(); subParam.Add("url", mPath); paramDic.Add("target", AppConst.VIDEO_IOS); paramDic.Add("method", IOSClientUtil.VideoMediaPlay); paramDic.Add("params", subParam); IOSClientUtil.CommonMethodCallIOSClient(paramDic.ToJson()); } } }); if (mData.Action == AttendanceAdd.Audio) { UpdateTvTime("0"); AddContent.gameObject.SetActive(mPath.IsNullOrEmpty()); AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty()); TextAdd.text = "添加语音"; } else { if (mData.Action == AttendanceAdd.Pic) { TextAdd.text = "添加图片"; AudioContent.gameObject.SetActive(false); if (mPath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(true); } } else { TextAdd.text = "添加视频"; AudioContent.gameObject.SetActive(false); if (mPath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic); BtnVideo.gameObject.SetActive(true); BtnDel.gameObject.SetActive(true); } } } BtnPlayAndPause.onClick.AddListener(() => { if (mPath.IsNotNullAndEmpty()) { if (mPlayStatus == PlayStatus.NoPlaying || mPlayStatus == PlayStatus.Stop) { MicrophoneManager.GetInstance().PlayRecord(); } else if (mPlayStatus == PlayStatus.Playing) { MicrophoneManager.GetInstance().PausePlay(); } else if (mPlayStatus == PlayStatus.Pause) { MicrophoneManager.GetInstance().PlayRecord(MicrophoneManager.GetInstance().mPlayingTime.Value); } } }); BtnClose.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); mPath = null; MicrophoneManager.GetInstance().StopPlay(); AddContent.gameObject.SetActive(mPath.IsNullOrEmpty()); AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty()); }); BtnDel.onClick.AddListener(() => { AudioManager.PlaySound("Button_Audio"); // 弹窗 UIMgr.OpenPanel <TipPanel>(new TipPanelData() { action = TipAction.DelAttendance, message = "确定要删除当前内容吗?", }); }); InputContent.onValueChange.AddListener(EditChange); if (mData.Action == AttendanceAdd.Audio) { MicrophoneManager.GetInstance().mPlayStatus.Subscribe(status => { mPlayStatus = status; if (mPlayStatus == PlayStatus.Playing) { // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audio_playing"); // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); ImgPlayAndPause.gameObject.SetActive(false); ImgPlaying.gameObject.SetActive(true); } else { // var soundOnTexture = mResLoader.LoadSync<Texture2D>("ic_audiio_pause"); // ImgPlayAndPause.sprite = Sprite.Create(soundOnTexture, new Rect(0, 0, soundOnTexture.width, soundOnTexture.height), Vector2.one * 0.5f); ImgPlayAndPause.gameObject.SetActive(true); ImgPlaying.gameObject.SetActive(false); } if (mPlayStatus == PlayStatus.Stop) { UpdateTvTime("0"); } }).AddTo(this); } SimpleEventSystem.GetEvent <RecordPath>().Subscribe(Path => { mPath = Path.Path; UpdateTvTime("0"); AddContent.gameObject.SetActive(mPath.IsNullOrEmpty()); AudioContent.gameObject.SetActive(mPath.IsNotNullAndEmpty()); }).AddTo(this); SimpleEventSystem.GetEvent <ChoosePhotoClick>() .Subscribe(_ => { if (_.GetPhotoAction == ChoosePhotoAction.AttendancePic) { if (Application.platform == RuntimePlatform.IPhonePlayer) { if (_.GetAction == NativeAction.Camera) { IPhonePlayerSelectPictureOpenCamera(); } else if (_.GetAction == NativeAction.Album) { IPhonePlayerSelectPictureOpenAlbum(); } } else if (Application.platform == RuntimePlatform.Android) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetImageFromGalleryForAndroid((path) => { if (path.IsNotNullAndEmpty()) { mPath = path; mThumbnailPath = path; AudioContent.gameObject.SetActive(false); if (mPath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + mThumbnailPath, ImagePic); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(true); } } Debug.Log("Image path: " + path); }, "选择图片", "image/*", true, action); } }, (int)_.GetAction); } } // 视频不需要了 else if (_.GetPhotoAction == ChoosePhotoAction.AttendanceVideo) { NativeGallery.RequestPermission((result, action) => { if (result == (int)NativeGallery.Permission.Granted) { NativeGallery.GetVideoFromGalleryForAndroid((json) => { if (json.IsNotNullAndEmpty()) { NativeVideoModel model = SerializeHelper.FromJson <NativeVideoModel>(json); if (model.IsNotNull()) { if (model.status == 1) { mPath = model.videoPath; mThumbnailPath = model.imagePath; AudioContent.gameObject.SetActive(false); if (model.imagePath.IsNotNullAndEmpty()) { ImageDownloadUtils.Instance.SetAsyncImage("file://" + model.imagePath, ImagePic); BtnVideo.gameObject.SetActive(true); BtnDel.gameObject.SetActive(true); } } else if (model.status == 0) { mPath = null; mThumbnailPath = null; ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(false); } } } }, "选择视频", "video/*", action); } }, (int)_.GetAction); } }).AddTo(this); SimpleEventSystem.GetEvent <TipConfirmClick>() .Subscribe(_ => { if (_.GetAction == TipAction.DelAttendance) { mPath = null; mThumbnailPath = null; ImagePic.sprite = Sprite.Create(texture2DAddPhoto, new Rect(0, 0, texture2DAddPhoto.width, texture2DAddPhoto.height), Vector2.one * 0.5f); BtnVideo.gameObject.SetActive(false); BtnDel.gameObject.SetActive(false); } }).AddTo(this); SimpleEventSystem.GetEvent <VideoCompressResult>().Subscribe(res => { VideoCompressModel model = res.Model; if (Application.platform == RuntimePlatform.Android) { if (model.status == 1) { string fileType = model.path.Substring(model.path.LastIndexOf(".")); Log.I("mPath: " + model.path + " fileType: " + fileType); StartRequestForUpload("attendance" + fileType, model.path); } else { CommonUtil.toast("视频压缩失败"); } } else if (Application.platform == RuntimePlatform.IPhonePlayer) { } }).AddTo(this); }