Skip to content

Commit

Permalink
Recorder: Use better view resource IDs
Browse files Browse the repository at this point in the history
Camel case and must end with the view type

Change-Id: I48c8bf8a9f29573197cda3de25cc01b9d91626aa
  • Loading branch information
SebaUbuntu committed Feb 24, 2024
1 parent c87c490 commit 27aa4f7
Show file tree
Hide file tree
Showing 9 changed files with 108 additions and 165 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/lineageos/recorder/DialogActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,11 @@ class DialogActivity : AppCompatActivity() {
.show()

val isRecording = intent.getBooleanExtra(EXTRA_IS_RECORDING, false)
locationSwitch = dialog.findViewById(R.id.dialog_content_settings_location_switch)!!
locationSwitch = dialog.findViewById(R.id.locationSwitch)!!

setupLocationSwitch(locationSwitch, isRecording)

highQualitySwitch = dialog.findViewById(R.id.dialog_content_settings_high_quality_switch)!!
highQualitySwitch = dialog.findViewById(R.id.highQualitySwitch)!!
setupHighQualitySwitch(highQualitySwitch, isRecording)
}

Expand Down
26 changes: 13 additions & 13 deletions app/src/main/java/org/lineageos/recorder/ListActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import android.os.Bundle
import android.view.ActionMode
import android.view.Menu
import android.view.MenuItem
import android.view.View
import android.widget.EditText
import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.coordinatorlayout.widget.CoordinatorLayout
import androidx.core.view.isVisible
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -38,11 +38,11 @@ import java.util.stream.Collectors

class ListActivity : AppCompatActivity(), RecordingListCallbacks {
// Views
private val coordinatorLayout by lazy { findViewById<CoordinatorLayout>(R.id.coordinator) }
private val contentView by lazy { findViewById<View>(android.R.id.content) }
private val listEmptyTextView by lazy { findViewById<TextView>(R.id.listEmptyTextView) }
private val listLoadingProgressBar by lazy { findViewById<ProgressBar>(R.id.listLoadingProgressBar) }
private val listRecyclerView by lazy { findViewById<RecyclerView>(R.id.listRecyclerView) }
private val toolbar by lazy { findViewById<Toolbar>(R.id.toolbar) }
private val listView by lazy { findViewById<RecyclerView>(R.id.list_view) }
private val progressBar by lazy { findViewById<ProgressBar>(R.id.list_loading) }
private val emptyText by lazy { findViewById<TextView>(R.id.list_empty) }

// Adapters
private val adapter by lazy {
Expand Down Expand Up @@ -77,13 +77,13 @@ class ListActivity : AppCompatActivity(), RecordingListCallbacks {
}
})

listView.layoutManager = LinearLayoutManager(this)
listView.adapter = adapter
listRecyclerView.layoutManager = LinearLayoutManager(this)
listRecyclerView.adapter = adapter

loadRecordings()

Utils.setFullScreen(window, coordinatorLayout)
Utils.setVerticalInsets(listView)
Utils.setFullScreen(window, contentView)
Utils.setVerticalInsets(listRecyclerView)
}

override fun onPlay(uri: Uri) {
Expand Down Expand Up @@ -113,7 +113,7 @@ class ListActivity : AppCompatActivity(), RecordingListCallbacks {
override fun onRename(index: Int, uri: Uri, currentName: String) {
val view = layoutInflater.inflate(R.layout.dialog_content_rename, null)

val editText = view.findViewById<EditText>(R.id.name)
val editText = view.findViewById<EditText>(R.id.nameEditText)
editText.setText(currentName)
editText.requestFocus()
Utils.showKeyboard(this)
Expand Down Expand Up @@ -190,7 +190,7 @@ class ListActivity : AppCompatActivity(), RecordingListCallbacks {
contentResolver
)
) { list: List<RecordingData> ->
progressBar.isVisible = false
listLoadingProgressBar.isVisible = false
adapter.data = list
changeEmptyView(list.isEmpty())
}
Expand Down Expand Up @@ -226,8 +226,8 @@ class ListActivity : AppCompatActivity(), RecordingListCallbacks {
}

private fun changeEmptyView(isEmpty: Boolean) {
emptyText.isVisible = isEmpty
listView.isVisible = !isEmpty
listEmptyTextView.isVisible = isEmpty
listRecyclerView.isVisible = !isEmpty
}

private fun shareSelectedRecordings() {
Expand Down
67 changes: 33 additions & 34 deletions app/src/main/java/org/lineageos/recorder/RecorderActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ import android.view.View
import android.widget.ImageView
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.constraintlayout.widget.ConstraintLayout
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible
import com.google.android.material.dialog.MaterialAlertDialogBuilder
Expand All @@ -52,14 +51,14 @@ import kotlin.reflect.safeCast

class RecorderActivity : AppCompatActivity(R.layout.activity_main) {
// Views
private val elapsedTimeText by lazy { findViewById<TextView>(R.id.main_elapsed_time) }
private val mainView by lazy { findViewById<ConstraintLayout>(R.id.main_root) }
private val pauseResume by lazy { findViewById<ImageView>(R.id.sound_pause_resume) }
private val recordingText by lazy { findViewById<TextView>(R.id.main_title) }
private val recordingVisualizer by lazy { findViewById<WaveFormView>(R.id.main_recording_visualizer) }
private val settings by lazy { findViewById<ImageView>(R.id.sound_settings) }
private val soundFab by lazy { findViewById<FloatingActionButton>(R.id.sound_fab) }
private val soundList by lazy { findViewById<ImageView>(R.id.sound_list_icon) }
private val contentView by lazy { findViewById<View>(android.R.id.content) }
private val elapsedTimeText by lazy { findViewById<TextView>(R.id.elapsedTimeTextView) }
private val floatingActionButton by lazy { findViewById<FloatingActionButton>(R.id.floatingActionButton) }
private val openSoundListImageView by lazy { findViewById<ImageView>(R.id.openSoundListImageView) }
private val pauseResumeImageView by lazy { findViewById<ImageView>(R.id.pauseResumeImageView) }
private val recordingWaveFormView by lazy { findViewById<WaveFormView>(R.id.recordingWaveFormView) }
private val settingsImageView by lazy { findViewById<ImageView>(R.id.settingsImageView) }
private val titleTextView by lazy { findViewById<TextView>(R.id.titleTextView) }

private val locationHelper by lazy { LocationHelper(this) }
private val permissionManager by lazy { PermissionManager(this) }
Expand Down Expand Up @@ -122,26 +121,26 @@ class RecorderActivity : AppCompatActivity(R.layout.activity_main) {
public override fun onCreate(savedInstance: Bundle?) {
super.onCreate(savedInstance)

soundFab.setOnClickListener { toggleSoundRecorder() }
pauseResume.setOnClickListener { togglePause() }
soundList.setOnClickListener { openList() }
settings.setOnClickListener { openSettings() }
floatingActionButton.setOnClickListener { toggleSoundRecorder() }
pauseResumeImageView.setOnClickListener { togglePause() }
openSoundListImageView.setOnClickListener { openList() }
settingsImageView.setOnClickListener { openSettings() }

Utils.setFullScreen(window, mainView)
Utils.setVerticalInsets(mainView)
Utils.setFullScreen(window, contentView)
Utils.setVerticalInsets(contentView)

lifecycle.addObserver(taskExecutor)

if (MediaStore.Audio.Media.RECORD_SOUND_ACTION == intent.action) {
returnAudio = true
soundList.isVisible = false
settings.isVisible = false
openSoundListImageView.isVisible = false
settingsImageView.isVisible = false
}

doBindService()

OnBoardingHelper.onBoardList(this, soundList)
OnBoardingHelper.onBoardSettings(this, settings)
OnBoardingHelper.onBoardList(this, openSoundListImageView)
OnBoardingHelper.onBoardSettings(this, settingsImageView)
}

public override fun onDestroy() {
Expand Down Expand Up @@ -191,7 +190,7 @@ class RecorderActivity : AppCompatActivity(R.layout.activity_main) {
}

private fun setVisualizerAmplitude(amplitude: Int) {
recordingVisualizer.post { recordingVisualizer.setAmplitude(amplitude) }
recordingWaveFormView.post { recordingWaveFormView.setAmplitude(amplitude) }
}

private fun setElapsedTime(seconds: Long) {
Expand Down Expand Up @@ -245,29 +244,29 @@ class RecorderActivity : AppCompatActivity(R.layout.activity_main) {
private fun applyUiStatus(status: UiStatus) {
uiStatus = status
if (UiStatus.READY == status) {
recordingText.text = getString(R.string.main_sound_action)
soundFab.setImageResource(R.drawable.ic_mic)
titleTextView.text = getString(R.string.main_sound_action)
floatingActionButton.setImageResource(R.drawable.ic_mic)
elapsedTimeText.isVisible = false
recordingVisualizer.isVisible = false
pauseResume.isVisible = false
recordingWaveFormView.isVisible = false
pauseResumeImageView.isVisible = false
} else {
soundFab.setImageResource(R.drawable.ic_stop)
floatingActionButton.setImageResource(R.drawable.ic_stop)
elapsedTimeText.isVisible = true
recordingVisualizer.isVisible = true
recordingVisualizer.setAmplitude(0)
pauseResume.isVisible = true
recordingWaveFormView.isVisible = true
recordingWaveFormView.setAmplitude(0)
pauseResumeImageView.isVisible = true
val prDrawable: Drawable?
if (UiStatus.PAUSED == status) {
recordingText.text = getString(R.string.sound_recording_title_paused)
pauseResume.contentDescription = getString(R.string.resume)
titleTextView.text = getString(R.string.sound_recording_title_paused)
pauseResumeImageView.contentDescription = getString(R.string.resume)
prDrawable = ContextCompat.getDrawable(this, R.drawable.avd_play_to_pause)
} else {
recordingText.text = getString(R.string.sound_recording_title_working)
pauseResume.contentDescription = getString(R.string.pause)
titleTextView.text = getString(R.string.sound_recording_title_working)
pauseResumeImageView.contentDescription = getString(R.string.pause)
prDrawable = ContextCompat.getDrawable(this, R.drawable.avd_pause_to_play)
}
pauseResume.tooltipText = pauseResume.contentDescription
pauseResume.setImageDrawable(prDrawable)
pauseResumeImageView.tooltipText = pauseResumeImageView.contentDescription
pauseResumeImageView.setImageDrawable(prDrawable)
AnimatedVectorDrawable::class.safeCast(prDrawable)?.start()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,29 +28,29 @@ class RecordingItemViewHolder(
private val dateFormat: DateTimeFormatter
) : RecyclerView.ViewHolder(itemView) {
// Views
private val iconView by lazy { itemView.findViewById<ImageView>(R.id.item_play) }
private val titleView by lazy { itemView.findViewById<TextView>(R.id.item_title) }
private val summaryView by lazy { itemView.findViewById<TextView>(R.id.item_date) }
private val menuView by lazy { itemView.findViewById<ImageView>(R.id.item_menu) }
private val dateTextView by lazy { itemView.findViewById<TextView>(R.id.dateTextView) }
private val menuImageView by lazy { itemView.findViewById<ImageView>(R.id.menuImageView) }
private val playImageView by lazy { itemView.findViewById<ImageView>(R.id.playImageView) }
private val titleTextView by lazy { itemView.findViewById<TextView>(R.id.titleTextView) }

var uri: Uri? = null
private set

init {
menuView.setOnClickListener { showPopupMenu(it) }
menuImageView.setOnClickListener { showPopupMenu(it) }
}

fun setData(data: RecordingData, selection: ListItemStatus) {
uri = data.uri
titleView.text = data.title
titleTextView.text = data.title
val duration = data.duration / 1000
summaryView.text = String.format(
dateTextView.text = String.format(
Locale.getDefault(), SUMMARY_FORMAT,
dateFormat.format(data.dateTime),
DateUtils.formatElapsedTime(duration)
)

iconView.setImageResource(
playImageView.setImageResource(
when (selection) {
ListItemStatus.DEFAULT -> R.drawable.ic_play_circle
ListItemStatus.UNCHECKED -> R.drawable.ic_radio_button_unchecked
Expand Down Expand Up @@ -80,7 +80,7 @@ class RecordingItemViewHolder(
private fun onActionSelected(actionId: Int) = uri?.let {
when (actionId) {
R.id.action_rename -> {
callbacks.onRename(adapterPosition, it, titleView.text.toString())
callbacks.onRename(adapterPosition, it, titleTextView.text.toString())
true
}
R.id.action_share -> {
Expand Down
25 changes: 7 additions & 18 deletions app/src/main/res/layout/activity_list.xml
Original file line number Diff line number Diff line change
@@ -1,22 +1,11 @@
<?xml version="1.0" encoding="utf-8"?>
<!-- Copyright (c) 2021 The LineageOS Project
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
<!--
SPDX-FileCopyrightText: 2021-2024 The LineageOS Project
SPDX-License-Identifier: Apache-2.0
-->
<androidx.coordinatorlayout.widget.CoordinatorLayout 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/coordinator"
android:layout_width="match_parent"
android:layout_height="match_parent">

Expand All @@ -32,16 +21,15 @@
android:layout_height="?attr/actionBarSize" />
</com.google.android.material.appbar.AppBarLayout>


<ProgressBar
android:id="@+id/list_loading"
android:id="@+id/listLoadingProgressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
tools:visibility="gone" />

<TextView
android:id="@+id/list_empty"
android:id="@+id/listEmptyTextView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
Expand All @@ -53,12 +41,13 @@
app:drawableTopCompat="@drawable/ic_empty_list" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/list_view"
android:id="@+id/listRecyclerView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:visibility="gone"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:listitem="@layout/list_item"
tools:visibility="visible" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
Loading

0 comments on commit 27aa4f7

Please sign in to comment.