Skip to content

Commit

Permalink
Fixed bug when app crashes if a user click record user name button wh…
Browse files Browse the repository at this point in the history
…ile it's recording. Fixed visual issues on create login screen (#1152)
  • Loading branch information
mXaln authored and jsarabia committed Jul 15, 2019
1 parent 1bd5e71 commit cd584f5
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 66 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -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)
}
}

Expand All @@ -121,6 +114,7 @@ class FragmentCreateProfile : Fragment() {
RecordingQueues.pauseQueues()
RecordingQueues.stopQueues(activity)
isRecording = false
btnRecord.isActivated = true
convertAudio()
}

Expand All @@ -134,6 +128,4 @@ class FragmentCreateProfile : Fragment() {
profileCreatedCallback?.onProfileCreated(mNewRecording!!, userAudio, hash)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,23 @@ 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
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
Expand Down Expand Up @@ -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
Expand All @@ -138,5 +140,16 @@ class FragmentReviewProfile : Fragment(), WaveformLayer.WaveformDrawDelegator {
CutOp()
)
mPlayer = WavPlayer(audioTrack, trackBufferSize, uncompressed, CutOp(), LinkedList<WavCue>())
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))
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
<shape android:shape="oval">
<solid android:color="@color/white" />
<size
android:width="24dp"
android:height="24dp" />
android:width="48dp"
android:height="48dp" />
</shape>
</item>
<item
android:bottom="-5dp"
android:bottom="-1dp"
android:drawable="@drawable/play_record_48dp"
android:left="-5dp"
android:right="-5dp"
android:top="-5dp" />
android:left="-1dp"
android:right="-1dp"
android:top="-1dp" />
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item>
<shape android:shape="oval">
<solid android:color="@color/white" />
<size
android:width="48dp"
android:height="48dp" />
</shape>
</item>
<item
android:bottom="-1dp"
android:drawable="@drawable/pause_record_48dp"
android:left="-1dp"
android:right="-1dp"
android:top="-1dp" />
</layer-list>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:tint="#FFFFFF"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M9,16.17L4.83,12l-1.42,1.41L9,19 21,7l-1.41,-1.41z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="36dp"
android:height="36dp"
android:tint="#00C5FF"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M18.4,10.6C16.55,8.99 14.15,8 11.5,8c-4.65,0 -8.58,3.03 -9.96,7.22L3.9,16c1.05,-3.19 4.05,-5.5 7.6,-5.5 1.95,0 3.73,0.72 5.12,1.88L13,16h9V7l-3.6,3.6z" />
</vector>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="48dp"
android:width="48dp"
android:tint="#010000"
android:viewportHeight="512"
android:viewportWidth="512">
<path
android:fillColor="#FF000000"
android:pathData="M256,8C119,8 8,119 8,256s111,248 248,248 248,-111 248,-248S393,8 256,8zM256,456c-110.5,0 -200,-89.5 -200,-200S145.5,56 256,56s200,89.5 200,200 -89.5,200 -200,200zM352,176v160c0,8.8 -7.2,16 -16,16h-48c-8.8,0 -16,-7.2 -16,-16L272,176c0,-8.8 7.2,-16 16,-16h48c8.8,0 16,7.2 16,16zM240,176v160c0,8.8 -7.2,16 -16,16h-48c-8.8,0 -16,-7.2 -16,-16L160,176c0,-8.8 7.2,-16 16,-16h48c8.8,0 16,7.2 16,16z"/>
</vector>
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="48dp"
android:height="48dp"
android:width="48dp"
android:tint="#010000"
android:viewportHeight="24.0"
android:viewportWidth="24.0">
<path
android:fillColor="#FF000000"
android:pathData="M10,16.5l6,-4.5 -6,-4.5v9zM12,2C6.48,2 2,6.48 2,12s4.48,10 10,10 10,-4.48 10,-10S17.52,2 12,2zM12,20c-4.41,0 -8,-3.59 -8,-8s3.59,-8 8,-8 8,3.59 8,8 -3.59,8 -8,8z" />
android:viewportHeight="512"
android:viewportWidth="512">
<path android:fillColor="#FF000000"
android:pathData="M371.7,238l-176,-107c-15.8,-8.8 -35.7,2.5 -35.7,21v208c0,18.4 19.8,29.8 35.7,21l176,-101c16.4,-9.1 16.4,-32.8 0,-42zM504,256C504,119 393,8 256,8S8,119 8,256s111,248 248,248 248,-111 248,-248zM56,256c0,-110.5 89.5,-200 200,-200s200,89.5 200,200 -89.5,200 -200,200S56,366.5 56,256z"/>
</vector>
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,22 @@
app:srcCompat="@drawable/play_record_48dp"
tools:ignore="VectorDrawableCompat" />

<ImageButton
android:id="@+id/btn_pause"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:contentDescription="@null"
android:background="@drawable/circle_with_white_bg_pause"
app:layout_constraintBottom_toBottomOf="@+id/waveform_frame"
app:layout_constraintDimensionRatio="w,1:1"
app:layout_constraintEnd_toEndOf="@+id/waveform_frame"
app:layout_constraintStart_toStartOf="@+id/waveform_frame"
app:layout_constraintTop_toBottomOf="@+id/waveform_frame"
app:srcCompat="@drawable/pause_record_48dp"
android:visibility="gone"
tools:ignore="VectorDrawableCompat" />

<TextView
android:id="@+id/textView4"
android:layout_width="wrap_content"
Expand Down Expand Up @@ -71,41 +87,39 @@
app:srcCompat="@android:drawable/btn_dialog" />

<Button
android:id="@+id/btnRedo"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:background="@drawable/round_corners"
android:drawableRight="@drawable/ic_redo_blue_48dp"
android:paddingHorizontal="24dp"
android:text="@string/txt_btn_redo"
android:textColor="#00C5FF"
app:layout_constraintBaseline_toBaselineOf="@+id/btnYes"
app:layout_constraintEnd_toStartOf="@+id/btnYes"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/guideline"
app:layout_constraintStart_toStartOf="@+id/guideline" />
android:id="@+id/btnRedo"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/round_corners"
android:drawableRight="@drawable/ic_redo_blue_36dp"
android:paddingHorizontal="24dp"
android:text="@string/txt_btn_redo"
android:textColor="#00C5FF"
app:layout_constraintEnd_toStartOf="@+id/btnYes"
app:layout_constraintStart_toStartOf="@+id/guideline"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/icon_hash"
app:layout_constraintBottom_toBottomOf="parent"
android:layout_marginBottom="16dp"/>

<Button
android:id="@+id/btnYes"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginBottom="24dp"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:background="@drawable/round_corner_with_gradient"
android:drawableRight="@drawable/ic_check_white_48dp"
android:paddingHorizontal="24dp"
android:text="@string/txt_btn_yes"
android:textColor="#FFFFFF"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toStartOf="@+id/guideline2"
app:layout_constraintHorizontal_bias="0.5"
app:layout_constraintStart_toEndOf="@+id/btnRedo"
app:layout_constraintTop_toBottomOf="@+id/icon_hash"
app:layout_constraintVertical_bias="1.0" />
android:id="@+id/btnYes"
style="?android:attr/borderlessButtonStyle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@drawable/round_corner_with_gradient"
android:drawableRight="@drawable/ic_check_white_36dp"
android:paddingHorizontal="24dp"
android:text="@string/txt_btn_yes"
android:textColor="#FFFFFF"
app:layout_constraintEnd_toStartOf="@+id/guideline2"
android:layout_marginTop="16dp"
app:layout_constraintTop_toBottomOf="@+id/icon_hash"
app:layout_constraintStart_toEndOf="@+id/btnRedo"
android:layout_marginStart="8dp"
android:layout_marginBottom="16dp"
app:layout_constraintBottom_toBottomOf="parent"/>

<androidx.constraintlayout.widget.Guideline
android:id="@+id/guideline"
Expand Down

0 comments on commit cd584f5

Please sign in to comment.