moving the main view in a separate fragment

This commit is contained in:
tibbi 2020-03-31 18:06:19 +02:00
parent 91c6b7084b
commit 51548338a7
4 changed files with 60 additions and 44 deletions

View File

@ -15,7 +15,7 @@ import com.simplemobiletools.voicerecorder.helpers.GET_RECORDER_INFO
import com.simplemobiletools.voicerecorder.helpers.STOP_AMPLITUDE_UPDATE
import com.simplemobiletools.voicerecorder.models.Events
import com.simplemobiletools.voicerecorder.services.RecorderService
import kotlinx.android.synthetic.main.activity_main.*
import kotlinx.android.synthetic.main.fragment_recorder.*
import org.greenrobot.eventbus.EventBus
import org.greenrobot.eventbus.Subscribe
import org.greenrobot.eventbus.ThreadMode
@ -50,7 +50,7 @@ class MainActivity : SimpleActivity() {
background.applyColorFilter(adjustedPrimaryColor)
}
visualizer.chunkColor = adjustedPrimaryColor
recorder_visualizer.chunkColor = adjustedPrimaryColor
recording_duration.setTextColor(config.textColor)
}
@ -93,7 +93,7 @@ class MainActivity : SimpleActivity() {
}
private fun initVoiceRecorder() {
visualizer.recreate()
recorder_visualizer.recreate()
bus = EventBus.getDefault()
bus!!.register(this)
@ -145,14 +145,14 @@ class MainActivity : SimpleActivity() {
isRecording = event.isRecording
toggle_recording_button.setImageDrawable(getToggleButtonIcon())
if (isRecording) {
visualizer.recreate()
recorder_visualizer.recreate()
}
}
@Subscribe(threadMode = ThreadMode.MAIN)
fun gotAmplitudeEvent(event: Events.RecordingAmplitude) {
val amplitude = event.amplitude
visualizer.update(amplitude)
recorder_visualizer.update(amplitude)
}
private fun getToggleButtonIcon(): Drawable {

View File

@ -0,0 +1,7 @@
package com.simplemobiletools.voicerecorder.fragments
import android.content.Context
import android.util.AttributeSet
import android.widget.RelativeLayout
class RecorderFragment(context: Context, attributeSet: AttributeSet) : RelativeLayout(context, attributeSet)

View File

@ -1,46 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recorder_holder"
android:id="@+id/main_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.visualizer.amplitude.AudioRecordView
android:id="@+id/visualizer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/recording_duration"
android:layout_margin="@dimen/big_margin"
android:background="@drawable/frame_background"
app:chunkAlignTo="center"
app:chunkMaxHeight="200dp"
app:chunkMinHeight="2dp"
app:chunkRoundedCorners="true"
app:chunkSoftTransition="true"
app:chunkSpace="1dp"
app:chunkWidth="3dp" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/recording_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/toggle_recording_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/bigger_margin"
android:textSize="@dimen/extra_big_text_size"
tools:text="00:00" />
<ImageView
android:id="@+id/toggle_recording_button"
android:layout_width="@dimen/toggle_recording_button_size"
android:layout_height="@dimen/toggle_recording_button_size"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/big_margin"
android:background="@drawable/circle_background"
android:elevation="@dimen/medium_margin"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_microphone_vector" />
<include layout="@layout/fragment_recorder" />
</RelativeLayout>

View File

@ -0,0 +1,46 @@
<?xml version="1.0" encoding="utf-8"?>
<com.simplemobiletools.voicerecorder.fragments.RecorderFragment xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/recorder_holder"
android:layout_width="match_parent"
android:layout_height="match_parent">
<com.visualizer.amplitude.AudioRecordView
android:id="@+id/recorder_visualizer"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/recording_duration"
android:layout_margin="@dimen/big_margin"
android:background="@drawable/frame_background"
app:chunkAlignTo="center"
app:chunkMaxHeight="200dp"
app:chunkMinHeight="2dp"
app:chunkRoundedCorners="true"
app:chunkSoftTransition="true"
app:chunkSpace="1dp"
app:chunkWidth="3dp" />
<com.simplemobiletools.commons.views.MyTextView
android:id="@+id/recording_duration"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/toggle_recording_button"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/bigger_margin"
android:textSize="@dimen/extra_big_text_size"
tools:text="00:00" />
<ImageView
android:id="@+id/toggle_recording_button"
android:layout_width="@dimen/toggle_recording_button_size"
android:layout_height="@dimen/toggle_recording_button_size"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="@dimen/big_margin"
android:background="@drawable/circle_background"
android:elevation="@dimen/medium_margin"
android:padding="@dimen/normal_margin"
android:src="@drawable/ic_microphone_vector" />
</com.simplemobiletools.voicerecorder.fragments.RecorderFragment>