Skip to content

Commit

Permalink
✅ 更新demo 兼容34
Browse files Browse the repository at this point in the history
  • Loading branch information
SheTieJun committed Mar 21, 2024
1 parent a76b9f8 commit 278e631
Show file tree
Hide file tree
Showing 13 changed files with 142 additions and 148 deletions.
3 changes: 1 addition & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ plugins {

androidApplication("me.shetj.mp3recorder"){
defaultConfig {
minSdk = 24
ndk {
this.abiFilters.addAll(listOf("armeabi-v7a", "arm64-v8a", "x86_64", "x86"))
}
Expand Down Expand Up @@ -37,9 +38,7 @@ dependencies {
implementation(project(":recorder-mix"))
implementation(project(":recorder-sim"))
implementation(project(":recorder-core"))
implementation(project(":recorder-ui"))
implementation(project(":recorder-st"))
implementation("com.github.SheTieJun:BaseKit:85dc1cb78d")
ksp(libs.androidx.room.compiler)
implementation("com.github.SheTieJun:OrangeDialog:0.0.2")
}
13 changes: 9 additions & 4 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,13 @@
>

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"
android:maxSdkVersion="32" />
<uses-permission android:name="android.permission.READ_MEDIA_IMAGES" />
<uses-permission android:name="android.permission.READ_MEDIA_VIDEO" />
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> <!-- 修复权限 -->
<uses-permission android:name="android.permission.RECORD_AUDIO" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="android.permission.BLUETOOTH" />
Expand All @@ -18,7 +23,7 @@
android:requestLegacyExternalStorage="true"
android:roundIcon="@mipmap/icon_record_app"
android:supportsRtl="true"
android:theme="@style/BaseTheme.MD3">
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:exported="true"
Expand All @@ -34,7 +39,7 @@
android:configChanges="orientation|screenSize|keyboardHidden"
android:exported="false"
android:screenOrientation="portrait"
android:theme="@style/BaseTheme.MD3"
android:theme="@style/AppTheme"
android:windowSoftInputMode="stateHidden|adjustPan" />
</application>

Expand Down
34 changes: 2 additions & 32 deletions app/src/main/java/me/shetj/mp3recorder/MainActivity.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

package me.shetj.mp3recorder

import android.Manifest
import android.animation.ObjectAnimator
import android.content.Context
import android.graphics.Color
Expand All @@ -14,19 +13,16 @@ import androidx.core.animation.doOnEnd
import androidx.core.splashscreen.SplashScreen
import androidx.core.splashscreen.SplashScreen.Companion.installSplashScreen
import androidx.lifecycle.lifecycleScope
import kotlinx.coroutines.NonCancellable.start
import kotlinx.coroutines.delay
import kotlinx.coroutines.launch
import me.shetj.base.BaseKit
import me.shetj.base.ktx.hasPermission
import me.shetj.base.fix.FixPermission
import me.shetj.base.ktx.setAppearance
import me.shetj.base.ktx.showToast
import me.shetj.base.ktx.start
import me.shetj.base.mvvm.viewbind.BaseBindingActivity
import me.shetj.base.mvvm.viewbind.BaseViewModel
import me.shetj.mp3recorder.databinding.ActivityMainTestBinding
import me.shetj.mp3recorder.record.activity.mix.RecordActivity
import me.shetj.recorder.ui.RecorderPopup

class MainActivity : BaseBindingActivity<ActivityMainTestBinding, BaseViewModel>() {
private var splashScreen: SplashScreen? =null
Expand Down Expand Up @@ -60,34 +56,14 @@ class MainActivity : BaseBindingActivity<ActivityMainTestBinding, BaseViewModel>
super.onCreate(savedInstanceState)
}

private val recorderPopup: RecorderPopup by lazy {
RecorderPopup(this, needPlay = false, maxTime = (10 * 1000).toLong()) {
it.showToast()
}
}


override fun initBaseView() {
hasPermission(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO,
isRequest = true
)
mBinding.btnDemo3.setOnClickListener {
if (hasPermission(
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO, isRequest = true
)
) {
if (FixPermission.checkReadMediaFile(this, isRequest = true)) {
start<RecordActivity>()
}
}

mBinding.btnDemo4.setOnClickListener {
recorderPopup.showPop()
}
mBinding.msg.apply {
append("获取当前手机录音最佳参数:")
append("最佳采样率:${getBestSampleRate()}\n")
Expand Down Expand Up @@ -129,10 +105,4 @@ class MainActivity : BaseBindingActivity<ActivityMainTestBinding, BaseViewModel>
super.onRequestPermissionsResult(requestCode, permissions, grantResults)
}


override fun onBackPressed() {
if (recorderPopup.onBackPress()) {
super.onBackPressed()
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import me.shetj.mp3recorder.R
import me.shetj.mp3recorder.record.RecordingNotification
import me.shetj.mp3recorder.record.utils.EventCallback
import kotlinx.coroutines.delay
import me.shetj.base.fix.FixPermission
import me.shetj.base.ktx.launch


Expand Down Expand Up @@ -96,11 +97,7 @@ class RecordActivity : BaseActivity<EmptyPresenter>(), EventCallback {
}

private fun canRecord() {
hasPermission(
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.RECORD_AUDIO, isRequest = true
)
FixPermission.checkReadMediaFile(this,true)
}

override fun onBackPressed() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.AppCompatButton
import androidx.lifecycle.lifecycleScope
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.InternalCoroutinesApi
import kotlinx.coroutines.flow.MutableSharedFlow
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import me.shetj.base.ktx.logI
import me.shetj.base.tools.app.ArmsUtils
import me.shetj.dialog.OrangeDialog
import me.shetj.mp3recorder.R
import me.shetj.mp3recorder.databinding.PageRecordMixBinding
import me.shetj.mp3recorder.record.bean.MusicQ
Expand Down Expand Up @@ -195,10 +195,6 @@ open class RecordPage(
}


override fun onReset() {
super.onReset()
}

override fun needPermission() {
callback.onEvent(3)
}
Expand Down Expand Up @@ -245,13 +241,13 @@ open class RecordPage(
* 是否录制新内容
*/
private fun showRecordNewDialog() {
OrangeDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle("录音已保存")
.setContent("录音已保存。是否继续录制下一条?")
.setNegativeText("查看本条")
.setOnNegativeCallBack { _, _ -> callback.onEvent(1) }
.setPositiveText("录下一条")
.setonPositiveCallBack { _, _ ->
.setMessage("录音已保存。是否继续录制下一条?")
.setNegativeButton("查看本条"){
_, _ -> callback.onEvent(1)
}
.setPositiveButton("录下一条"){ _, _ ->
setRecord(null)
ArmsUtils.makeText("上条录音已保存至“我的录音”")
}
Expand Down Expand Up @@ -326,18 +322,17 @@ open class RecordPage(
* 展示重新录制
*/
private fun showRerecordDialog() {
OrangeDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle("重新录制")
.setContent("确定删除当前的录音,并重新录制吗?")
.setNegativeText("取消").setOnNegativeCallBack { _, _ -> recordUtils!!.stopFullRecord() }
.setPositiveText("重录").setonPositiveCallBack { _, _ ->
.setMessage("确定删除当前的录音,并重新录制吗?")
.setNegativeButton("取消") { _, _ -> recordUtils!!.stopFullRecord() }
.setPositiveButton("重录") { _, _ ->
//可自行判断是否删除老的文件
oldRecord?.audioLength = 0
oldRecord?.audio_url = ""
setRecord(oldRecord)
recordUtils!!.reset()
recordUtils!!.setTime(0)

}
.show()
}
Expand All @@ -347,11 +342,11 @@ open class RecordPage(
*/
private fun showTipDialog() {
onPause()//先暂停
OrangeDialog.Builder(context)
MaterialAlertDialogBuilder(context)
.setTitle("温馨提示")
.setContent("确定要停止录音吗?")
.setNegativeText("停止录音").setOnNegativeCallBack { _, _ -> recordUtils!!.stopFullRecord() }
.setPositiveText("继续录音").setonPositiveCallBack { _, _ -> recordUtils!!.startOrPause() }
.setMessage("确定要停止录音吗?")
.setNegativeButton("停止录音") { _, _ -> recordUtils!!.stopFullRecord() }
.setPositiveButton("继续录音") { _, _ -> recordUtils!!.startOrPause() }
.show()
}

Expand Down
Loading

0 comments on commit 278e631

Please sign in to comment.