[Modify]声音卡点击返回键时的弹窗
This commit is contained in:
@@ -23,7 +23,7 @@ import com.yizhuan.erban.audio.viewmodel.SoundViewModel
|
|||||||
import com.yizhuan.erban.base.BaseViewBindingActivity
|
import com.yizhuan.erban.base.BaseViewBindingActivity
|
||||||
import com.yizhuan.erban.common.widget.dialog.DialogManager.OkCancelDialogListener
|
import com.yizhuan.erban.common.widget.dialog.DialogManager.OkCancelDialogListener
|
||||||
import com.yizhuan.erban.databinding.ActivitySoundSignatureBinding
|
import com.yizhuan.erban.databinding.ActivitySoundSignatureBinding
|
||||||
import com.yizhuan.erban.ui.widget.dialog.CommonTipDialog
|
import com.yizhuan.erban.ui.widget.dialog.CommonDialog
|
||||||
import com.yizhuan.xchat_android_core.file.FileModel
|
import com.yizhuan.xchat_android_core.file.FileModel
|
||||||
import com.yizhuan.xchat_android_core.room.model.AvRoomModel
|
import com.yizhuan.xchat_android_core.room.model.AvRoomModel
|
||||||
import com.yizhuan.xchat_android_core.statistic.StatisticManager
|
import com.yizhuan.xchat_android_core.statistic.StatisticManager
|
||||||
@@ -152,6 +152,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|||||||
ResUtil.getString(R.string.audio_presenter_recordingvoicepresenter_02)
|
ResUtil.getString(R.string.audio_presenter_recordingvoicepresenter_02)
|
||||||
)
|
)
|
||||||
refreshButtonView(SoundViewModel.STATE_RECORD_SAVE_SUCCESS)
|
refreshButtonView(SoundViewModel.STATE_RECORD_SAVE_SUCCESS)
|
||||||
|
soundViewModel.audioState = SoundViewModel.STATE_RECORD_SAVE_SUCCESS
|
||||||
SingleToastUtil.showToast(getString(R.string.update_success))
|
SingleToastUtil.showToast(getString(R.string.update_success))
|
||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.putExtra(AUDIO_FILE, soundViewModel.audioUrl)
|
intent.putExtra(AUDIO_FILE, soundViewModel.audioUrl)
|
||||||
@@ -172,6 +173,34 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|||||||
soundViewModel.showNormalState()
|
soundViewModel.showNormalState()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
soundViewModel.showSaveConfirmDialogLiveData.observe(this) {
|
||||||
|
CommonDialog(this).apply {
|
||||||
|
setTipMsg(ResUtil.getString(R.string.sound_has_not_been_saved))
|
||||||
|
setOnActionListener(
|
||||||
|
object : CommonDialog.OnActionListener {
|
||||||
|
override fun onOk() {
|
||||||
|
finishView(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
soundViewModel.showRecordConfirmDialogLiveData.observe(this) {
|
||||||
|
CommonDialog(this).apply {
|
||||||
|
setTipMsg(ResUtil.getString(R.string.sound_has_not_been_recorded_yet))
|
||||||
|
setOnActionListener(
|
||||||
|
object : CommonDialog.OnActionListener {
|
||||||
|
override fun onOk() {
|
||||||
|
finishView(null)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
show()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun showLoad() {
|
private fun showLoad() {
|
||||||
@@ -205,7 +234,7 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}else {
|
} else {
|
||||||
soundViewModel.clickCenterIcon()
|
soundViewModel.clickCenterIcon()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -222,17 +251,17 @@ class SoundSignatureActivity : BaseViewBindingActivity<ActivitySoundSignatureBin
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun deleteRecord() {
|
private fun deleteRecord() {
|
||||||
val tipDialog = CommonTipDialog(this)
|
CommonDialog(this).apply {
|
||||||
tipDialog.setTipMsg(ResUtil.getString(R.string.sure_to_delete_sound))
|
setTipMsg(ResUtil.getString(R.string.sure_to_delete_sound))
|
||||||
tipDialog.setOkText(getString(R.string.sure))
|
setOnActionListener(
|
||||||
tipDialog.setOnActionListener(
|
object : CommonDialog.OnActionListener {
|
||||||
object : CommonTipDialog.OnActionListener {
|
override fun onOk() {
|
||||||
override fun onOk() {
|
soundViewModel.deleteRecord()
|
||||||
soundViewModel.deleteRecord()
|
}
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
)
|
show()
|
||||||
tipDialog.show()
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@@ -10,10 +10,12 @@ import com.yizhuan.erban.R
|
|||||||
import com.yizhuan.erban.audio.SoundSignatureActivity
|
import com.yizhuan.erban.audio.SoundSignatureActivity
|
||||||
import com.yizhuan.erban.audio.helper.AudioPlayerHelper
|
import com.yizhuan.erban.audio.helper.AudioPlayerHelper
|
||||||
import com.yizhuan.erban.audio.helper.OnPlayListener
|
import com.yizhuan.erban.audio.helper.OnPlayListener
|
||||||
|
import com.yizhuan.erban.audio.presenter.RecordingVoicePresenter
|
||||||
import com.yizhuan.erban.base.BaseViewModel
|
import com.yizhuan.erban.base.BaseViewModel
|
||||||
import com.yizhuan.xchat_android_core.audio.AudioPlayAndRecordManager
|
import com.yizhuan.xchat_android_core.audio.AudioPlayAndRecordManager
|
||||||
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
|
import com.yizhuan.xchat_android_core.manager.AvRoomDataManager
|
||||||
import com.yizhuan.xchat_android_core.sound.model.SoundModel
|
import com.yizhuan.xchat_android_core.sound.model.SoundModel
|
||||||
|
import com.yizhuan.xchat_android_core.utils.Logger
|
||||||
import com.yizhuan.xchat_android_core.utils.toast
|
import com.yizhuan.xchat_android_core.utils.toast
|
||||||
import com.yizhuan.xchat_android_library.common.application.BaseApp
|
import com.yizhuan.xchat_android_library.common.application.BaseApp
|
||||||
import com.yizhuan.xchat_android_library.utils.ResUtil
|
import com.yizhuan.xchat_android_library.utils.ResUtil
|
||||||
@@ -75,6 +77,12 @@ class SoundViewModel : BaseViewModel() {
|
|||||||
private val _deleteRecordLiveData = MutableLiveData<String?>()
|
private val _deleteRecordLiveData = MutableLiveData<String?>()
|
||||||
val deleteRecordLiveData: MutableLiveData<String?> = _deleteRecordLiveData
|
val deleteRecordLiveData: MutableLiveData<String?> = _deleteRecordLiveData
|
||||||
|
|
||||||
|
private val _showSaveConfirmDialogLiveData = MutableLiveData<String?>()
|
||||||
|
val showSaveConfirmDialogLiveData: MutableLiveData<String?> = _showSaveConfirmDialogLiveData
|
||||||
|
|
||||||
|
private val _showRecordConfirmDialogLiveData = MutableLiveData<String?>()
|
||||||
|
val showRecordConfirmDialogLiveData: MutableLiveData<String?> = _showRecordConfirmDialogLiveData
|
||||||
|
|
||||||
init {
|
init {
|
||||||
audioManager = AudioPlayAndRecordManager.getInstance()
|
audioManager = AudioPlayAndRecordManager.getInstance()
|
||||||
}
|
}
|
||||||
@@ -87,6 +95,7 @@ class SoundViewModel : BaseViewModel() {
|
|||||||
STATE_RECORD_NORMAL -> startRecord() // 默认状态,点击了中间按钮:开始录音
|
STATE_RECORD_NORMAL -> startRecord() // 默认状态,点击了中间按钮:开始录音
|
||||||
STATE_RECORD_RECORDING -> stopRecord() // 录制中状态,点击了中间按钮:停止录音
|
STATE_RECORD_RECORDING -> stopRecord() // 录制中状态,点击了中间按钮:停止录音
|
||||||
STATE_RECORD_SUCCESS -> clickAudition() // 试听状态,点击了中间按钮:试听声音
|
STATE_RECORD_SUCCESS -> clickAudition() // 试听状态,点击了中间按钮:试听声音
|
||||||
|
STATE_RECORD_SAVE_SUCCESS -> clickAudition() //保存成功,点击了中间按钮:试听声音
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -238,14 +247,18 @@ class SoundViewModel : BaseViewModel() {
|
|||||||
AudioPlayerHelper.get().endPlay()
|
AudioPlayerHelper.get().endPlay()
|
||||||
_refreshPlayStatusLiveData.value = false // 返回页面时,此时正在播放声音,则停止播放并显示停止状态(播放按钮)
|
_refreshPlayStatusLiveData.value = false // 返回页面时,此时正在播放声音,则停止播放并显示停止状态(播放按钮)
|
||||||
}
|
}
|
||||||
_finishViewLiveData.value = null// 退出页面
|
if (audioState == STATE_RECORD_SUCCESS) { // 已经录制未保存:未保存提示(确定则返回页面/取消则保留当前页面)
|
||||||
|
_showSaveConfirmDialogLiveData.value = null
|
||||||
|
} else {
|
||||||
|
_finishViewLiveData.value = null// 退出页面
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 试听按钮
|
* 试听按钮
|
||||||
*/
|
*/
|
||||||
private fun clickAudition() {
|
private fun clickAudition() {
|
||||||
if (audioState == STATE_RECORD_SUCCESS) {
|
if (audioState == STATE_RECORD_SUCCESS || audioState == STATE_RECORD_SAVE_SUCCESS || audioState == STATE_RECORD_AUDIT_SUCCESS) {
|
||||||
if (AudioPlayerHelper.get().isPlaying) {
|
if (AudioPlayerHelper.get().isPlaying) {
|
||||||
AudioPlayerHelper.get().pausePlay()
|
AudioPlayerHelper.get().pausePlay()
|
||||||
_refreshPlayStatusLiveData.value = false// 点击试听按钮此时正在播放声音,则暂停播放并显示停止状态(播放按钮)
|
_refreshPlayStatusLiveData.value = false// 点击试听按钮此时正在播放声音,则暂停播放并显示停止状态(播放按钮)
|
||||||
|
@@ -0,0 +1,123 @@
|
|||||||
|
package com.yizhuan.erban.ui.widget.dialog;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.text.SpannableStringBuilder;
|
||||||
|
import android.text.Spanned;
|
||||||
|
import android.text.style.AbsoluteSizeSpan;
|
||||||
|
import android.text.style.StyleSpan;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.annotation.ColorRes;
|
||||||
|
|
||||||
|
import com.yizhuan.erban.R;
|
||||||
|
import com.yizhuan.xchat_android_core.utils.TextUtils;
|
||||||
|
import com.yizhuan.xchat_android_library.utils.ResUtil;
|
||||||
|
|
||||||
|
import static android.graphics.Typeface.BOLD;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author jack
|
||||||
|
* @Description
|
||||||
|
* @Date 2019/1/21
|
||||||
|
*/
|
||||||
|
public class CommonDialog extends BaseDialog {
|
||||||
|
private String tipMsg = "";
|
||||||
|
|
||||||
|
private String okText = ResUtil.getString(R.string.widget_dialog_commontipdialog_01);
|
||||||
|
private String cancelText = ResUtil.getString(R.string.widget_dialog_commontipdialog_02);
|
||||||
|
private boolean isBold;
|
||||||
|
private @ColorRes
|
||||||
|
int color = -1;
|
||||||
|
private int textSize = -1;
|
||||||
|
|
||||||
|
public CommonDialog(Context context) {
|
||||||
|
super(context, R.style.dialog);
|
||||||
|
init();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init() {
|
||||||
|
this.setCancelable(true);
|
||||||
|
this.setCanceledOnTouchOutside(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
setContentView(R.layout.layout_common_dialog);
|
||||||
|
|
||||||
|
TextView tip = findViewById(R.id.message);
|
||||||
|
tip.setText(tipMsg);
|
||||||
|
if (color != -1) {
|
||||||
|
tip.setTextColor(getContext().getResources().getColor(color));
|
||||||
|
}
|
||||||
|
SpannableStringBuilder builder = new SpannableStringBuilder(tipMsg);
|
||||||
|
if (textSize != -1) {
|
||||||
|
AbsoluteSizeSpan sizeSpan = new AbsoluteSizeSpan(textSize);
|
||||||
|
builder.setSpan(sizeSpan, 0, builder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||||
|
}
|
||||||
|
if (isBold) {
|
||||||
|
StyleSpan boldSpan = new StyleSpan(BOLD);
|
||||||
|
builder.setSpan(boldSpan, 0, builder.length(), Spanned.SPAN_INCLUSIVE_INCLUSIVE);
|
||||||
|
}
|
||||||
|
tip.setText(builder);
|
||||||
|
TextView ok = findViewById(R.id.btn_ok);
|
||||||
|
ok.setText(okText);
|
||||||
|
ok.setOnClickListener(v -> {
|
||||||
|
this.dismiss();
|
||||||
|
if (l != null) {
|
||||||
|
l.onOk();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
TextView cancel = findViewById(R.id.btn_cancel);
|
||||||
|
cancel.setText(cancelText);
|
||||||
|
cancel.setOnClickListener(v -> {
|
||||||
|
this.dismiss();
|
||||||
|
if (l != null) {
|
||||||
|
l.onCancel();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTipMsg(String tipMsg) {
|
||||||
|
this.tipMsg = tipMsg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBold(boolean isBold) {
|
||||||
|
this.isBold = isBold;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextColor(@ColorRes int color) {
|
||||||
|
this.color = color;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTextSize(int textSize) {
|
||||||
|
this.textSize = textSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private OnActionListener l;
|
||||||
|
|
||||||
|
public void setOkText(String okText) {
|
||||||
|
if (!TextUtils.isEmptyText(okText))
|
||||||
|
this.okText = okText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCancelText(String cancelText) {
|
||||||
|
if (!TextUtils.isEmptyText(cancelText))
|
||||||
|
this.cancelText = cancelText;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnActionListener(OnActionListener l) {
|
||||||
|
this.l = l;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnActionListener {
|
||||||
|
default void onOk() {
|
||||||
|
}
|
||||||
|
|
||||||
|
default void onCancel() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
9
app/src/main/res/drawable/bg_e6e6f0_28.xml
Normal file
9
app/src/main/res/drawable/bg_e6e6f0_28.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<shape xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:shape="rectangle">
|
||||||
|
|
||||||
|
<corners android:radius="@dimen/dp_28"/>
|
||||||
|
|
||||||
|
<solid android:color="@color/color_E6E6F0"/>
|
||||||
|
|
||||||
|
</shape>
|
59
app/src/main/res/layout/layout_common_dialog.xml
Normal file
59
app/src/main/res/layout/layout_common_dialog.xml
Normal file
@@ -0,0 +1,59 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="295dp"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_gravity="center_horizontal"
|
||||||
|
android:background="@drawable/shape_white_12dp_round"
|
||||||
|
android:orientation="vertical"
|
||||||
|
tools:background="@color/black_transparent_10">
|
||||||
|
|
||||||
|
<View
|
||||||
|
android:layout_width="0dp"
|
||||||
|
android:layout_height="@dimen/dp_26" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/message"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="0dp"
|
||||||
|
android:layout_marginBottom="@dimen/dp_32"
|
||||||
|
android:layout_weight="1"
|
||||||
|
android:gravity="center"
|
||||||
|
android:lineSpacingMultiplier="1.2"
|
||||||
|
android:paddingStart="20dp"
|
||||||
|
android:paddingEnd="20dp"
|
||||||
|
android:textColor="@color/text_title_color"
|
||||||
|
android:textSize="14sp"
|
||||||
|
tools:text="@string/layout_layout_ok_cancel_dialog_01" />
|
||||||
|
|
||||||
|
<LinearLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginBottom="24dp"
|
||||||
|
android:gravity="center_horizontal"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btn_ok"
|
||||||
|
android:layout_width="120dp"
|
||||||
|
android:layout_height="38dp"
|
||||||
|
android:background="@drawable/bg_e6e6f0_28"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/text_ok"
|
||||||
|
android:textColor="@color/color_B3B3C3"
|
||||||
|
android:textSize="@dimen/sp_14" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/btn_cancel"
|
||||||
|
android:layout_width="120dp"
|
||||||
|
android:layout_height="38dp"
|
||||||
|
android:layout_marginStart="@dimen/dp_16"
|
||||||
|
android:background="@drawable/bg_common_confirm"
|
||||||
|
android:gravity="center"
|
||||||
|
android:text="@string/cancel"
|
||||||
|
android:textColor="@color/white"
|
||||||
|
android:textSize="@dimen/sp_14" />
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
|
</LinearLayout>
|
@@ -5049,5 +5049,7 @@
|
|||||||
<string name="sound_duration">%d"</string>
|
<string name="sound_duration">%d"</string>
|
||||||
<string name="no_room_has_been_added_yet">暫未加入房間</string>
|
<string name="no_room_has_been_added_yet">暫未加入房間</string>
|
||||||
<string name="user_no_room_has_been_added_yet">該用戶暫未加入房間</string>
|
<string name="user_no_room_has_been_added_yet">該用戶暫未加入房間</string>
|
||||||
|
<string name="sound_has_not_been_saved">聲音還未保存,確認退出嗎?</string>
|
||||||
|
<string name="sound_has_not_been_recorded_yet">聲音還未錄製完成,確認退出嗎?</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
Reference in New Issue
Block a user