From cd584f5a603766f85031e5f1faca18ca98621f60 Mon Sep 17 00:00:00 2001 From: Maxim Murzamuratov Date: Mon, 15 Jul 2019 14:03:57 -0400 Subject: [PATCH] Fixed bug when app crashes if a user click record user name button while it's recording. Fixed visual issues on create login screen (#1152) --- .../login/fragments/FragmentCreateProfile.kt | 14 +--- .../login/fragments/FragmentReviewProfile.kt | 31 ++++--- .../res/drawable/circle_with_white_bg.xml | 12 +-- .../drawable/circle_with_white_bg_pause.xml | 17 ++++ .../main/res/drawable/ic_check_white_36dp.xml | 10 +++ .../main/res/drawable/ic_redo_blue_36dp.xml | 10 +++ .../main/res/drawable/pause_record_48dp.xml | 10 +++ .../main/res/drawable/play_record_48dp.xml | 11 ++- .../src/main/res/layout/activity_login.xml | 2 +- .../res/layout/fragment_review_profile.xml | 80 +++++++++++-------- 10 files changed, 131 insertions(+), 66 deletions(-) create mode 100644 translationRecorder/app/src/main/res/drawable/circle_with_white_bg_pause.xml create mode 100644 translationRecorder/app/src/main/res/drawable/ic_check_white_36dp.xml create mode 100644 translationRecorder/app/src/main/res/drawable/ic_redo_blue_36dp.xml create mode 100644 translationRecorder/app/src/main/res/drawable/pause_record_48dp.xml diff --git a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentCreateProfile.kt b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentCreateProfile.kt index bd8b3f0ea..b0531637f 100644 --- a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentCreateProfile.kt +++ b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentCreateProfile.kt @@ -75,11 +75,7 @@ class FragmentCreateProfile : Fragment() { btnRecord as Button btnRecord.setOnClickListener { (btnRecord.background as Animatable).start() - if (btnRecord.isActivated) { - btnRecord.isActivated = false - stopRecording() - } else { - + if (btnRecord.isActivated.not()) { btnRecord.isActivated = true startRecording() } @@ -108,10 +104,7 @@ class FragmentCreateProfile : Fragment() { activity.startService(Intent(activity, WavRecorder::class.java)) activity.startService(WavFileWriter.getIntent(activity, mNewRecording)) mRenderer.listenForRecording(false) - Handler(Looper.getMainLooper()).postDelayed({ btnRecord.performClick() }, 3000) - - } else { - stopRecording() + Handler(Looper.getMainLooper()).postDelayed({ stopRecording() }, 3000) } } @@ -121,6 +114,7 @@ class FragmentCreateProfile : Fragment() { RecordingQueues.pauseQueues() RecordingQueues.stopQueues(activity) isRecording = false + btnRecord.isActivated = true convertAudio() } @@ -134,6 +128,4 @@ class FragmentCreateProfile : Fragment() { profileCreatedCallback?.onProfileCreated(mNewRecording!!, userAudio, hash) } } - - } diff --git a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentReviewProfile.kt b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentReviewProfile.kt index 6e61ddc81..27d837d00 100644 --- a/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentReviewProfile.kt +++ b/translationRecorder/app/src/main/java/org/wycliffeassociates/translationrecorder/login/fragments/FragmentReviewProfile.kt @@ -8,7 +8,6 @@ import android.graphics.Paint import android.media.AudioTrack import android.os.Bundle import android.preference.PreferenceManager -import androidx.appcompat.widget.AppCompatImageButton import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -16,18 +15,16 @@ import android.view.ViewTreeObserver import android.widget.Button import android.widget.FrameLayout import android.widget.ImageView +import androidx.appcompat.widget.AppCompatImageButton import com.pixplicity.sharp.Sharp import jdenticon.Jdenticon import kotlinx.android.synthetic.main.fragment_review_profile.* +import org.wycliffeassociates.translationrecorder.* import org.wycliffeassociates.translationrecorder.AudioVisualization.WavVisualizer -import org.wycliffeassociates.translationrecorder.MainMenu import org.wycliffeassociates.translationrecorder.Playback.Editing.CutOp import org.wycliffeassociates.translationrecorder.Playback.overlays.WaveformLayer import org.wycliffeassociates.translationrecorder.Playback.player.WavPlayer -import org.wycliffeassociates.translationrecorder.R import org.wycliffeassociates.translationrecorder.SettingsPage.Settings -import org.wycliffeassociates.translationrecorder.TranslationRecorderApp -import org.wycliffeassociates.translationrecorder.WavFileLoader import org.wycliffeassociates.translationrecorder.database.ProjectDatabaseHelper import org.wycliffeassociates.translationrecorder.login.interfaces.OnRedoListener import org.wycliffeassociates.translationrecorder.project.components.User @@ -110,20 +107,25 @@ class FragmentReviewProfile : Fragment(), WaveformLayer.WaveformDrawDelegator { mWaveformLayer.viewTreeObserver.addOnGlobalLayoutListener(layoutListener) btn_play as AppCompatImageButton btn_play.setOnClickListener { - if (!mPlayer.isPlaying) { - mPlayer.play() - } + showPauseButton() + mPlayer.play() + } + btn_pause as AppCompatImageButton + btn_pause.setOnClickListener { + showPlayButton() + mPlayer.pause() } audioTrack = (activity.application as TranslationRecorderApp).audioTrack trackBufferSize = (activity.application as TranslationRecorderApp).trackBufferSize } - private fun renderIdenticon(hash: String, view: ImageView): Unit { + private fun renderIdenticon(hash: String, view: ImageView) { val svg = Jdenticon.toSvg(hash, 512, 0f) Sharp.loadString(svg).into(view) } private fun initializeRenderer() { + showPlayButton() wav.overwriteHeaderData() val wavFileLoader = WavFileLoader(wav, activity) val numThreads = 4 @@ -138,5 +140,16 @@ class FragmentReviewProfile : Fragment(), WaveformLayer.WaveformDrawDelegator { CutOp() ) mPlayer = WavPlayer(audioTrack, trackBufferSize, uncompressed, CutOp(), LinkedList()) + mPlayer.setOnCompleteListener { + showPlayButton() + } + } + + private fun showPauseButton() { + Utils.swapViews(arrayOf(btn_pause), arrayOf(btn_play)) + } + + private fun showPlayButton() { + Utils.swapViews(arrayOf(btn_play), arrayOf(btn_pause)) } } diff --git a/translationRecorder/app/src/main/res/drawable/circle_with_white_bg.xml b/translationRecorder/app/src/main/res/drawable/circle_with_white_bg.xml index ab7e3c5f4..b2c3a2b6e 100644 --- a/translationRecorder/app/src/main/res/drawable/circle_with_white_bg.xml +++ b/translationRecorder/app/src/main/res/drawable/circle_with_white_bg.xml @@ -4,14 +4,14 @@ + android:width="48dp" + android:height="48dp" /> + android:left="-1dp" + android:right="-1dp" + android:top="-1dp" /> \ No newline at end of file diff --git a/translationRecorder/app/src/main/res/drawable/circle_with_white_bg_pause.xml b/translationRecorder/app/src/main/res/drawable/circle_with_white_bg_pause.xml new file mode 100644 index 000000000..7b1dd410b --- /dev/null +++ b/translationRecorder/app/src/main/res/drawable/circle_with_white_bg_pause.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/translationRecorder/app/src/main/res/drawable/ic_check_white_36dp.xml b/translationRecorder/app/src/main/res/drawable/ic_check_white_36dp.xml new file mode 100644 index 000000000..2523d00c4 --- /dev/null +++ b/translationRecorder/app/src/main/res/drawable/ic_check_white_36dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/translationRecorder/app/src/main/res/drawable/ic_redo_blue_36dp.xml b/translationRecorder/app/src/main/res/drawable/ic_redo_blue_36dp.xml new file mode 100644 index 000000000..2dc89efe3 --- /dev/null +++ b/translationRecorder/app/src/main/res/drawable/ic_redo_blue_36dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/translationRecorder/app/src/main/res/drawable/pause_record_48dp.xml b/translationRecorder/app/src/main/res/drawable/pause_record_48dp.xml new file mode 100644 index 000000000..113a14a7a --- /dev/null +++ b/translationRecorder/app/src/main/res/drawable/pause_record_48dp.xml @@ -0,0 +1,10 @@ + + + diff --git a/translationRecorder/app/src/main/res/drawable/play_record_48dp.xml b/translationRecorder/app/src/main/res/drawable/play_record_48dp.xml index bef641383..bdca9afea 100644 --- a/translationRecorder/app/src/main/res/drawable/play_record_48dp.xml +++ b/translationRecorder/app/src/main/res/drawable/play_record_48dp.xml @@ -1,10 +1,9 @@ - + android:viewportHeight="512" + android:viewportWidth="512"> + diff --git a/translationRecorder/app/src/main/res/layout/activity_login.xml b/translationRecorder/app/src/main/res/layout/activity_login.xml index 87d829b1c..06fecce2d 100644 --- a/translationRecorder/app/src/main/res/layout/activity_login.xml +++ b/translationRecorder/app/src/main/res/layout/activity_login.xml @@ -17,6 +17,6 @@ card_view:layout_constraintLeft_toLeftOf="parent" card_view:layout_constraintRight_toRightOf="parent" card_view:layout_constraintTop_toTopOf="parent" - card_view:layout_constraintWidth_percent="0.5" /> + card_view:layout_constraintWidth_percent="0.7" /> \ No newline at end of file diff --git a/translationRecorder/app/src/main/res/layout/fragment_review_profile.xml b/translationRecorder/app/src/main/res/layout/fragment_review_profile.xml index 8d9030a07..f60273dfe 100644 --- a/translationRecorder/app/src/main/res/layout/fragment_review_profile.xml +++ b/translationRecorder/app/src/main/res/layout/fragment_review_profile.xml @@ -31,6 +31,22 @@ app:srcCompat="@drawable/play_record_48dp" tools:ignore="VectorDrawableCompat" /> + +