Skip to content

Commit

Permalink
Improve AnalyzeFragment UI
Browse files Browse the repository at this point in the history
  • Loading branch information
mileskrell committed Jul 28, 2022
1 parent ef0151b commit 4187923
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 77 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ class AnalyzeFragment : Fragment(R.layout.fragment_analyze) {
enterProgressDisplayingMode()
}

if (analyzeViewModel.clickedShowDetails) {
enterProgressDetailsMode()
}

b.analyzeButton.setOnClickListener {
logToBoth(TAG, "Clicked \"analyze\" button")
analyzeViewModel.clickedAnalyze = true
Expand All @@ -91,21 +87,8 @@ class AnalyzeFragment : Fragment(R.layout.fragment_analyze) {

private fun enterProgressDisplayingMode() {
b.analyzeButton.visibility = View.INVISIBLE
b.analyzingMessageThreadsTextView.visibility = View.VISIBLE
b.threadsProgressBar.visibility = View.VISIBLE
b.threadsProgressFractionTextView.visibility = View.VISIBLE
b.threadsProgressPercentageTextView.visibility = View.VISIBLE
b.threadsProgressFractionTextView.text =
getString(R.string.x_out_of_y_message_threads, 0, "?")
b.threadsProgressPercentageTextView.text = getString(R.string.x_percent, 0)

b.showDetailsButton.visibility = View.VISIBLE
b.showDetailsButton.setOnClickListener {
logToBoth(TAG, "Clicked \"show details\" button")
analyzeViewModel.clickedShowDetails = true
enterProgressDetailsMode()
}

b.analyzingMessageThreadsTextView.visibility = View.VISIBLE
valueAnimator = ValueAnimator.ofFloat(0f, 1f).apply {
duration = 1000
repeatCount = ValueAnimator.INFINITE
Expand All @@ -116,56 +99,62 @@ class AnalyzeFragment : Fragment(R.layout.fragment_analyze) {
start()
}

var threadsTotal = -1
analyzeViewModel.threadsTotal.observe({ lifecycle }) { newThreadsTotal ->
threadsTotal = newThreadsTotal
b.threadsProgressBar.visibility = View.VISIBLE
b.threadsProgressPercentageTextView.text = getString(R.string.x_percent, 0)
b.threadsProgressPercentageTextView.visibility = View.VISIBLE
b.threadsProgressFractionTextView.visibility = View.VISIBLE
analyzeViewModel.threadsTotal.observe({ lifecycle }) { threadsTotal ->
b.threadsProgressBar.max = threadsTotal
b.threadsProgressFractionTextView.text = getString(
R.string.x_out_of_y_message_threads,
analyzeViewModel.threadsCompleted.value ?: 0,
threadsTotal
)
}
analyzeViewModel.threadsCompleted.observe({ lifecycle }) { newThreadsCompleted ->
if (threadsTotal != -1) {
b.threadsProgressBar.progress = newThreadsCompleted
analyzeViewModel.threadsCompleted.observe({ lifecycle }) { threadsCompleted ->
analyzeViewModel.threadsTotal.value?.let { threadsTotal ->
b.threadsProgressBar.progress = threadsCompleted
b.threadsProgressPercentageTextView.text = getString(
R.string.x_percent,
(100.0 * threadsCompleted / threadsTotal).roundToInt()
)
b.threadsProgressFractionTextView.text = getString(
R.string.x_out_of_y_message_threads,
newThreadsCompleted,
threadsTotal.toString()
threadsCompleted,
threadsTotal
)
val percentDone = (100.0 * newThreadsCompleted / threadsTotal).roundToInt()
b.threadsProgressPercentageTextView.text =
getString(R.string.x_percent, percentDone)
}
}
var messagesTotal = -1
analyzeViewModel.messagesTotal.observe({ lifecycle }) { newMessagesTotal ->
messagesTotal = newMessagesTotal
b.messagesProgressBar.max = newMessagesTotal

b.forCurrentMessageThreadTextView.visibility = View.VISIBLE
b.messagesProgressBar.visibility = View.VISIBLE
b.messagesProgressPercentageTextView.text = getString(R.string.x_percent, 0)
b.messagesProgressPercentageTextView.visibility = View.VISIBLE
b.messagesProgressFractionTextView.visibility = View.VISIBLE
analyzeViewModel.messagesTotal.observe({ lifecycle }) { messagesTotal ->
b.messagesProgressBar.max = messagesTotal
b.messagesProgressFractionTextView.text = getString(
R.string.x_out_of_y_messages,
analyzeViewModel.messagesCompleted.value ?: 0,
messagesTotal
)
}
analyzeViewModel.messagesCompleted.observe({ lifecycle }) { newMessagesCompleted ->
if (messagesTotal != -1) {
b.messagesProgressBar.progress = newMessagesCompleted
analyzeViewModel.messagesCompleted.observe({ lifecycle }) { messagesCompleted ->
analyzeViewModel.messagesTotal.value?.let { messagesTotal ->
b.messagesProgressBar.progress = messagesCompleted
b.messagesProgressPercentageTextView.text = getString(
R.string.x_percent,
(100.0 * messagesCompleted / messagesTotal).roundToInt()
)
b.messagesProgressFractionTextView.text = getString(
R.string.x_out_of_y_messages,
newMessagesCompleted,
messagesTotal.toString()
messagesCompleted,
messagesTotal
)
val percentDone =
if (messagesTotal == 0) 100
else (100.0 * newMessagesCompleted / messagesTotal).roundToInt()
b.messagesProgressPercentageTextView.text =
getString(R.string.x_percent, percentDone)
}
}
}

private fun enterProgressDetailsMode() {
b.showDetailsButton.visibility = View.INVISIBLE
b.messagesProgressFractionTextView.text = getString(R.string.x_out_of_y_messages, 0, "?")
b.messagesProgressPercentageTextView.text = getString(R.string.x_percent, 0)
b.forCurrentMessageThreadTextView.visibility = View.VISIBLE
b.messagesProgressBar.visibility = View.VISIBLE
b.messagesProgressPercentageTextView.visibility = View.VISIBLE
b.messagesProgressFractionTextView.visibility = View.VISIBLE
}

override fun onDestroyView() {
super.onDestroyView()
_binding = null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class AnalyzeViewModel : ViewModel() {
val messagesCompleted = MutableLiveData(0)

var clickedAnalyze = false
var clickedShowDetails = false

fun initializeSocialRecordList(socialRecordsViewModel: SocialRecordsViewModel) {
viewModelScope.launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,6 @@ class ThreadGetter(val context: Context) {
Telephony.Sms.DATE
)?.use { messagesCursor ->
messagesTotal.postValue(messagesCursor.count)
messagesCompleted.postValue(0)

messagesCursorLoop@ while (messagesCursor.moveToNext()) {
val messageId = messagesCursor.getLong(Telephony.MmsSms._ID)
Expand Down
29 changes: 10 additions & 19 deletions app/src/main/res/layout/fragment_analyze.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,12 @@
android:textAlignment="center"
android:textAppearance="@style/TextAppearance.Material3.DisplaySmall"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@id/analyze_button"
app:layout_constraintBottom_toTopOf="@id/threads_progress_bar"
app:layout_constraintEnd_toStartOf="@id/guideline_right"
app:layout_constraintStart_toEndOf="@id/guideline_left"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.4"
app:layout_constraintVertical_chainStyle="packed"
tools:visibility="visible" />

<androidx.constraintlayout.widget.Guideline
Expand All @@ -55,10 +58,10 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintBottom_toTopOf="@id/threads_progress_percentage_text_view"
app:layout_constraintEnd_toStartOf="@id/guideline_right"
app:layout_constraintStart_toEndOf="@id/guideline_left"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintTop_toBottomOf="@id/analyzing_message_threads_text_view"
app:trackCornerRadius="2dp"
tools:progress="19"
tools:visibility="visible" />
Expand All @@ -70,6 +73,7 @@
android:layout_marginTop="8dp"
android:textStyle="bold"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@id/for_current_message_thread_text_view"
app:layout_constraintStart_toStartOf="@id/threads_progress_bar"
app:layout_constraintTop_toBottomOf="@id/threads_progress_bar"
tools:text="19%"
Expand All @@ -90,10 +94,11 @@
android:id="@+id/for_current_message_thread_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="64dp"
android:layout_marginTop="32dp"
android:text="@string/for_current_message_thread"
android:textAlignment="center"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@id/messages_progress_bar"
app:layout_constraintEnd_toStartOf="@id/guideline_right"
app:layout_constraintStart_toEndOf="@id/guideline_left"
app:layout_constraintTop_toBottomOf="@+id/threads_progress_percentage_text_view"
Expand All @@ -106,6 +111,7 @@
android:layout_marginHorizontal="32dp"
android:layout_marginTop="8dp"
android:visibility="invisible"
app:layout_constraintBottom_toTopOf="@id/messages_progress_percentage_text_view"
app:layout_constraintEnd_toStartOf="@id/guideline_right"
app:layout_constraintStart_toEndOf="@id/guideline_left"
app:layout_constraintTop_toBottomOf="@id/for_current_message_thread_text_view"
Expand All @@ -118,13 +124,11 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginBottom="16dp"
android:textStyle="bold"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="@id/messages_progress_bar"
app:layout_constraintTop_toBottomOf="@id/messages_progress_bar"
app:layout_constraintVertical_bias="0.0"
tools:text="60%"
tools:visibility="visible" />

Expand All @@ -138,18 +142,5 @@
app:layout_constraintTop_toBottomOf="@id/messages_progress_bar"
tools:text="228/380 messages"
tools:visibility="visible" />

<com.google.android.material.button.MaterialButton
android:id="@+id/show_details_button"
style="?attr/materialButtonOutlinedStyle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/show_details"
android:textAppearance="@style/TextAppearance.Material3.LabelLarge"
android:visibility="invisible"
app:layout_constraintBottom_toBottomOf="@id/messages_progress_bar"
app:layout_constraintEnd_toStartOf="@id/guideline_right"
app:layout_constraintStart_toEndOf="@id/guideline_left"
app:layout_constraintTop_toTopOf="@id/messages_progress_bar" />
</androidx.constraintlayout.widget.ConstraintLayout>
</ScrollView>
5 changes: 2 additions & 3 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,8 @@
<string name="analyze_my_texts">Analyze my texts!</string>
<string name="analyzing">Analyzing…</string>
<string name="x_percent">%d%%</string>
<string name="x_out_of_y_message_threads">%1$d/%2$s message threads</string>
<string name="show_details">Show details</string>
<string name="x_out_of_y_messages">%1$d/%2$s messages</string>
<string name="x_out_of_y_message_threads">%1$d/%2$d message threads</string>
<string name="x_out_of_y_messages">%1$d/%2$d messages</string>
<string name="for_current_message_thread">For current message thread:</string>

<string name="who_texts_first">Who texts first\?</string>
Expand Down

0 comments on commit 4187923

Please sign in to comment.