Skip to content

Commit 4187923

Browse files
committed
Improve AnalyzeFragment UI
1 parent ef0151b commit 4187923

5 files changed

Lines changed: 54 additions & 77 deletions

File tree

app/src/main/java/com/mileskrell/texttorch/analyze/AnalyzeFragment.kt

Lines changed: 42 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,6 @@ class AnalyzeFragment : Fragment(R.layout.fragment_analyze) {
7777
enterProgressDisplayingMode()
7878
}
7979

80-
if (analyzeViewModel.clickedShowDetails) {
81-
enterProgressDetailsMode()
82-
}
83-
8480
b.analyzeButton.setOnClickListener {
8581
logToBoth(TAG, "Clicked \"analyze\" button")
8682
analyzeViewModel.clickedAnalyze = true
@@ -91,21 +87,8 @@ class AnalyzeFragment : Fragment(R.layout.fragment_analyze) {
9187

9288
private fun enterProgressDisplayingMode() {
9389
b.analyzeButton.visibility = View.INVISIBLE
94-
b.analyzingMessageThreadsTextView.visibility = View.VISIBLE
95-
b.threadsProgressBar.visibility = View.VISIBLE
96-
b.threadsProgressFractionTextView.visibility = View.VISIBLE
97-
b.threadsProgressPercentageTextView.visibility = View.VISIBLE
98-
b.threadsProgressFractionTextView.text =
99-
getString(R.string.x_out_of_y_message_threads, 0, "?")
100-
b.threadsProgressPercentageTextView.text = getString(R.string.x_percent, 0)
101-
102-
b.showDetailsButton.visibility = View.VISIBLE
103-
b.showDetailsButton.setOnClickListener {
104-
logToBoth(TAG, "Clicked \"show details\" button")
105-
analyzeViewModel.clickedShowDetails = true
106-
enterProgressDetailsMode()
107-
}
10890

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

119-
var threadsTotal = -1
120-
analyzeViewModel.threadsTotal.observe({ lifecycle }) { newThreadsTotal ->
121-
threadsTotal = newThreadsTotal
102+
b.threadsProgressBar.visibility = View.VISIBLE
103+
b.threadsProgressPercentageTextView.text = getString(R.string.x_percent, 0)
104+
b.threadsProgressPercentageTextView.visibility = View.VISIBLE
105+
b.threadsProgressFractionTextView.visibility = View.VISIBLE
106+
analyzeViewModel.threadsTotal.observe({ lifecycle }) { threadsTotal ->
122107
b.threadsProgressBar.max = threadsTotal
108+
b.threadsProgressFractionTextView.text = getString(
109+
R.string.x_out_of_y_message_threads,
110+
analyzeViewModel.threadsCompleted.value ?: 0,
111+
threadsTotal
112+
)
123113
}
124-
analyzeViewModel.threadsCompleted.observe({ lifecycle }) { newThreadsCompleted ->
125-
if (threadsTotal != -1) {
126-
b.threadsProgressBar.progress = newThreadsCompleted
114+
analyzeViewModel.threadsCompleted.observe({ lifecycle }) { threadsCompleted ->
115+
analyzeViewModel.threadsTotal.value?.let { threadsTotal ->
116+
b.threadsProgressBar.progress = threadsCompleted
117+
b.threadsProgressPercentageTextView.text = getString(
118+
R.string.x_percent,
119+
(100.0 * threadsCompleted / threadsTotal).roundToInt()
120+
)
127121
b.threadsProgressFractionTextView.text = getString(
128122
R.string.x_out_of_y_message_threads,
129-
newThreadsCompleted,
130-
threadsTotal.toString()
123+
threadsCompleted,
124+
threadsTotal
131125
)
132-
val percentDone = (100.0 * newThreadsCompleted / threadsTotal).roundToInt()
133-
b.threadsProgressPercentageTextView.text =
134-
getString(R.string.x_percent, percentDone)
135126
}
136127
}
137-
var messagesTotal = -1
138-
analyzeViewModel.messagesTotal.observe({ lifecycle }) { newMessagesTotal ->
139-
messagesTotal = newMessagesTotal
140-
b.messagesProgressBar.max = newMessagesTotal
128+
129+
b.forCurrentMessageThreadTextView.visibility = View.VISIBLE
130+
b.messagesProgressBar.visibility = View.VISIBLE
131+
b.messagesProgressPercentageTextView.text = getString(R.string.x_percent, 0)
132+
b.messagesProgressPercentageTextView.visibility = View.VISIBLE
133+
b.messagesProgressFractionTextView.visibility = View.VISIBLE
134+
analyzeViewModel.messagesTotal.observe({ lifecycle }) { messagesTotal ->
135+
b.messagesProgressBar.max = messagesTotal
136+
b.messagesProgressFractionTextView.text = getString(
137+
R.string.x_out_of_y_messages,
138+
analyzeViewModel.messagesCompleted.value ?: 0,
139+
messagesTotal
140+
)
141141
}
142-
analyzeViewModel.messagesCompleted.observe({ lifecycle }) { newMessagesCompleted ->
143-
if (messagesTotal != -1) {
144-
b.messagesProgressBar.progress = newMessagesCompleted
142+
analyzeViewModel.messagesCompleted.observe({ lifecycle }) { messagesCompleted ->
143+
analyzeViewModel.messagesTotal.value?.let { messagesTotal ->
144+
b.messagesProgressBar.progress = messagesCompleted
145+
b.messagesProgressPercentageTextView.text = getString(
146+
R.string.x_percent,
147+
(100.0 * messagesCompleted / messagesTotal).roundToInt()
148+
)
145149
b.messagesProgressFractionTextView.text = getString(
146150
R.string.x_out_of_y_messages,
147-
newMessagesCompleted,
148-
messagesTotal.toString()
151+
messagesCompleted,
152+
messagesTotal
149153
)
150-
val percentDone =
151-
if (messagesTotal == 0) 100
152-
else (100.0 * newMessagesCompleted / messagesTotal).roundToInt()
153-
b.messagesProgressPercentageTextView.text =
154-
getString(R.string.x_percent, percentDone)
155154
}
156155
}
157156
}
158157

159-
private fun enterProgressDetailsMode() {
160-
b.showDetailsButton.visibility = View.INVISIBLE
161-
b.messagesProgressFractionTextView.text = getString(R.string.x_out_of_y_messages, 0, "?")
162-
b.messagesProgressPercentageTextView.text = getString(R.string.x_percent, 0)
163-
b.forCurrentMessageThreadTextView.visibility = View.VISIBLE
164-
b.messagesProgressBar.visibility = View.VISIBLE
165-
b.messagesProgressPercentageTextView.visibility = View.VISIBLE
166-
b.messagesProgressFractionTextView.visibility = View.VISIBLE
167-
}
168-
169158
override fun onDestroyView() {
170159
super.onDestroyView()
171160
_binding = null

app/src/main/java/com/mileskrell/texttorch/analyze/AnalyzeViewModel.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@ class AnalyzeViewModel : ViewModel() {
3636
val messagesCompleted = MutableLiveData(0)
3737

3838
var clickedAnalyze = false
39-
var clickedShowDetails = false
4039

4140
fun initializeSocialRecordList(socialRecordsViewModel: SocialRecordsViewModel) {
4241
viewModelScope.launch(Dispatchers.IO) {

app/src/main/java/com/mileskrell/texttorch/stats/repo/ThreadGetter.kt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,6 @@ class ThreadGetter(val context: Context) {
156156
Telephony.Sms.DATE
157157
)?.use { messagesCursor ->
158158
messagesTotal.postValue(messagesCursor.count)
159-
messagesCompleted.postValue(0)
160159

161160
messagesCursorLoop@ while (messagesCursor.moveToNext()) {
162161
val messageId = messagesCursor.getLong(Telephony.MmsSms._ID)

app/src/main/res/layout/fragment_analyze.xml

Lines changed: 10 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,12 @@
3131
android:textAlignment="center"
3232
android:textAppearance="@style/TextAppearance.Material3.DisplaySmall"
3333
android:visibility="invisible"
34-
app:layout_constraintBottom_toTopOf="@id/analyze_button"
34+
app:layout_constraintBottom_toTopOf="@id/threads_progress_bar"
3535
app:layout_constraintEnd_toStartOf="@id/guideline_right"
3636
app:layout_constraintStart_toEndOf="@id/guideline_left"
37+
app:layout_constraintTop_toTopOf="parent"
38+
app:layout_constraintVertical_bias="0.4"
39+
app:layout_constraintVertical_chainStyle="packed"
3740
tools:visibility="visible" />
3841

3942
<androidx.constraintlayout.widget.Guideline
@@ -55,10 +58,10 @@
5558
android:layout_width="0dp"
5659
android:layout_height="wrap_content"
5760
android:visibility="invisible"
58-
app:layout_constraintBottom_toBottomOf="parent"
61+
app:layout_constraintBottom_toTopOf="@id/threads_progress_percentage_text_view"
5962
app:layout_constraintEnd_toStartOf="@id/guideline_right"
6063
app:layout_constraintStart_toEndOf="@id/guideline_left"
61-
app:layout_constraintTop_toTopOf="parent"
64+
app:layout_constraintTop_toBottomOf="@id/analyzing_message_threads_text_view"
6265
app:trackCornerRadius="2dp"
6366
tools:progress="19"
6467
tools:visibility="visible" />
@@ -70,6 +73,7 @@
7073
android:layout_marginTop="8dp"
7174
android:textStyle="bold"
7275
android:visibility="invisible"
76+
app:layout_constraintBottom_toTopOf="@id/for_current_message_thread_text_view"
7377
app:layout_constraintStart_toStartOf="@id/threads_progress_bar"
7478
app:layout_constraintTop_toBottomOf="@id/threads_progress_bar"
7579
tools:text="19%"
@@ -90,10 +94,11 @@
9094
android:id="@+id/for_current_message_thread_text_view"
9195
android:layout_width="wrap_content"
9296
android:layout_height="wrap_content"
93-
android:layout_marginTop="64dp"
97+
android:layout_marginTop="32dp"
9498
android:text="@string/for_current_message_thread"
9599
android:textAlignment="center"
96100
android:visibility="invisible"
101+
app:layout_constraintBottom_toTopOf="@id/messages_progress_bar"
97102
app:layout_constraintEnd_toStartOf="@id/guideline_right"
98103
app:layout_constraintStart_toEndOf="@id/guideline_left"
99104
app:layout_constraintTop_toBottomOf="@+id/threads_progress_percentage_text_view"
@@ -106,6 +111,7 @@
106111
android:layout_marginHorizontal="32dp"
107112
android:layout_marginTop="8dp"
108113
android:visibility="invisible"
114+
app:layout_constraintBottom_toTopOf="@id/messages_progress_percentage_text_view"
109115
app:layout_constraintEnd_toStartOf="@id/guideline_right"
110116
app:layout_constraintStart_toEndOf="@id/guideline_left"
111117
app:layout_constraintTop_toBottomOf="@id/for_current_message_thread_text_view"
@@ -118,13 +124,11 @@
118124
android:layout_width="wrap_content"
119125
android:layout_height="wrap_content"
120126
android:layout_marginTop="8dp"
121-
android:layout_marginBottom="16dp"
122127
android:textStyle="bold"
123128
android:visibility="invisible"
124129
app:layout_constraintBottom_toBottomOf="parent"
125130
app:layout_constraintStart_toStartOf="@id/messages_progress_bar"
126131
app:layout_constraintTop_toBottomOf="@id/messages_progress_bar"
127-
app:layout_constraintVertical_bias="0.0"
128132
tools:text="60%"
129133
tools:visibility="visible" />
130134

@@ -138,18 +142,5 @@
138142
app:layout_constraintTop_toBottomOf="@id/messages_progress_bar"
139143
tools:text="228/380 messages"
140144
tools:visibility="visible" />
141-
142-
<com.google.android.material.button.MaterialButton
143-
android:id="@+id/show_details_button"
144-
style="?attr/materialButtonOutlinedStyle"
145-
android:layout_width="wrap_content"
146-
android:layout_height="wrap_content"
147-
android:text="@string/show_details"
148-
android:textAppearance="@style/TextAppearance.Material3.LabelLarge"
149-
android:visibility="invisible"
150-
app:layout_constraintBottom_toBottomOf="@id/messages_progress_bar"
151-
app:layout_constraintEnd_toStartOf="@id/guideline_right"
152-
app:layout_constraintStart_toEndOf="@id/guideline_left"
153-
app:layout_constraintTop_toTopOf="@id/messages_progress_bar" />
154145
</androidx.constraintlayout.widget.ConstraintLayout>
155146
</ScrollView>

app/src/main/res/values/strings.xml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@
3636
<string name="analyze_my_texts">Analyze my texts!</string>
3737
<string name="analyzing">Analyzing…</string>
3838
<string name="x_percent">%d%%</string>
39-
<string name="x_out_of_y_message_threads">%1$d/%2$s message threads</string>
40-
<string name="show_details">Show details</string>
41-
<string name="x_out_of_y_messages">%1$d/%2$s messages</string>
39+
<string name="x_out_of_y_message_threads">%1$d/%2$d message threads</string>
40+
<string name="x_out_of_y_messages">%1$d/%2$d messages</string>
4241
<string name="for_current_message_thread">For current message thread:</string>
4342

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

0 commit comments

Comments
 (0)