diff --git a/live/src/main/java/com/yunbao/live/dialog/VoiceDialog.java b/live/src/main/java/com/yunbao/live/dialog/VoiceDialog.java index f50a3bc5e..4e8ec052d 100644 --- a/live/src/main/java/com/yunbao/live/dialog/VoiceDialog.java +++ b/live/src/main/java/com/yunbao/live/dialog/VoiceDialog.java @@ -1,6 +1,7 @@ package com.yunbao.live.dialog; import android.os.Bundle; +import android.os.Handler; import android.text.SpannableStringBuilder; import android.text.TextUtils; import android.util.Log; @@ -41,6 +42,7 @@ public class VoiceDialog extends AbsDialogFragment { private GifImageView gifView; private SpannableStringBuilder builder = new SpannableStringBuilder(); private boolean isSend = true; + private Handler handler = new Handler(); public boolean isSend() { return isSend; @@ -85,6 +87,19 @@ public class VoiceDialog extends AbsDialogFragment { params.height = WindowManager.LayoutParams.WRAP_CONTENT; params.gravity = Gravity.CENTER; window.setAttributes(params); + handler.postDelayed(new Runnable() { + @Override + public void run() { + + } + }, 30000); + } + + @Override + public void dismiss() { + listener = null; + handler.removeCallbacks(timeOut); + super.dismiss(); } @Override @@ -99,8 +114,18 @@ public class VoiceDialog extends AbsDialogFragment { iconWithdraw.setVisibility(View.GONE); gifView.setVisibility(View.GONE); voiceFluctuations.setVisibility(View.VISIBLE); + handler.postDelayed(timeOut, 30000); } + private Runnable timeOut = new Runnable() { + @Override + public void run() { + if (listener != null) { + listener.timeout(); + } + } + }; + /** * 上划取消 */ @@ -297,4 +322,15 @@ public class VoiceDialog extends AbsDialogFragment { } return ret.toString(); } + + private VoiceListener listener; + + public VoiceDialog setListener(VoiceListener listener) { + this.listener = listener; + return this; + } + + public interface VoiceListener { + void timeout(); + } } diff --git a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java index 5039ea535..d1d39a522 100644 --- a/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java +++ b/live/src/main/java/com/yunbao/live/views/LiveAudienceViewHolder.java @@ -294,7 +294,7 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { voiceDialog.withdraw(); } if ((downY - moveY < 100) && (downY - moveY > 30)) { - if (voiceDialog != null&& voiceDialog.isAdded()) + if (voiceDialog != null && voiceDialog.isAdded()) voiceDialog.notWithdraw(); } } else if (event.getAction() == MotionEvent.ACTION_UP) { @@ -329,6 +329,25 @@ public class LiveAudienceViewHolder extends AbsLiveViewHolder { vibrator.vibrate(100);//震动时间(ms) if (voiceDialog == null) { voiceDialog = new VoiceDialog(); + voiceDialog.setListener(new VoiceDialog.VoiceListener() { + @Override + public void timeout() { + //松开 + handler.removeCallbacks(mLongPressed); + Bus.get().post(new LiveAudienceEvent() + .setVoicePress(false) + .setType(LiveAudienceEvent.LiveAudienceType.VOICE_PRESS)); + + if (voiceDialog != null) { + if (voiceDialog.isSend() && !TextUtils.isEmpty(voiceDialog.sendMessage())) { + ((LiveActivity) mContext).sendChatMessage(voiceDialog.sendMessage(), null, null); + } + + voiceDialog.dismiss(); + voiceDialog = null; + } + } + }); } voiceDialog.show(((LiveAudienceActivity) mContext).getSupportFragmentManager(), "VoiceDialog"); Bus.get().post(new LiveAudienceEvent()