Skip to content

Commit a1f8296

Browse files
author
Dan Oprea
committed
Small visual changes
1 parent c7f5ffe commit a1f8296

File tree

2 files changed

+34
-19
lines changed

2 files changed

+34
-19
lines changed

app/src/main/java/com/dan/timelapse/BusyDialog.kt

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import android.view.ViewGroup
88
import androidx.fragment.app.DialogFragment
99
import com.dan.timelapse.databinding.BusyDialogBinding
1010

11-
class BusyDialog( private var message: String): DialogFragment() {
11+
class BusyDialog( private var message: String, private var progress: Int, private var total: Int): DialogFragment() {
1212

1313
companion object {
1414
private const val FRAGMENT_TAG = "busy"
@@ -29,27 +29,15 @@ class BusyDialog( private var message: String): DialogFragment() {
2929
}
3030
}
3131

32-
fun show(message: String) {
32+
fun show(message: String, progress: Int = -1, total: Int = -1) {
3333
runSafe {
3434
if (null == currentDialog) {
35-
val dialog = BusyDialog(message)
35+
val dialog = BusyDialog(message, progress, total)
3636
dialog.isCancelable = false
3737
dialog.show(activity.supportFragmentManager, FRAGMENT_TAG)
3838
currentDialog = dialog
3939
} else {
40-
currentDialog?.binding?.textBusyMessage?.text = message
41-
}
42-
}
43-
}
44-
45-
fun updateProgress(progress: Int, total: Int) {
46-
if (total <= 0 || progress < 0 || progress > total) return
47-
48-
runSafe {
49-
currentDialog?.binding?.progressBar?.apply {
50-
this.max = total
51-
this.progress = progress
52-
this.isIndeterminate = false
40+
currentDialog?.update(message, progress, total)
5341
}
5442
}
5543
}
@@ -64,10 +52,34 @@ class BusyDialog( private var message: String): DialogFragment() {
6452

6553
private var binding: BusyDialogBinding? = null
6654

55+
fun update(message: String, progress: Int = -1, total: Int = -1) {
56+
this.message = message
57+
this.progress = progress
58+
this.total = total
59+
update()
60+
}
61+
62+
private fun update() {
63+
val infinite = progress < 0 || total <= 0 || progress > total
64+
val title = if (progress < 0) message else "$message ($progress)"
65+
binding?.let {
66+
it.textBusyMessage.text = title
67+
if (infinite) {
68+
it.progressBar.isIndeterminate = true
69+
} else {
70+
it.progressBar.progress = 0
71+
it.progressBar.max = total
72+
it.progressBar.progress = progress
73+
it.progressBar.isIndeterminate = false
74+
}
75+
}
76+
}
77+
6778
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View {
6879
val binding = BusyDialogBinding.inflate( inflater )
6980
binding.textBusyMessage.text = message
7081
this.binding = binding
82+
update()
7183
return binding.root
7284
}
7385
}

app/src/main/java/com/dan/timelapse/MainFragment.kt

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class MainFragment(activity: MainActivity) : AppFragment(activity) {
2020
const val INTENT_OPEN_IMAGES = 3
2121
const val INTENT_OPEN_FOLDER = 4
2222

23+
const val TITLE_GENERATE = "Generate"
24+
const val TITLE_SAVE = "Save"
25+
2326
fun show(activity: MainActivity) {
2427
activity.pushView("TimeLapse", MainFragment(activity))
2528
}
@@ -239,13 +242,13 @@ class MainFragment(activity: MainActivity) : AppFragment(activity) {
239242
videoStop()
240243
videoUri = null
241244
binding.video.setVideoURI(null)
242-
runAsync("Generate") {
245+
runAsync(TITLE_GENERATE) {
243246
generateAsync()
244247
}
245248
}
246249

247250
private fun handleSave() {
248-
runAsync("Save") {
251+
runAsync(TITLE_SAVE) {
249252
saveAsync()
250253
}
251254
}
@@ -341,7 +344,7 @@ class MainFragment(activity: MainActivity) : AppFragment(activity) {
341344

342345
frameConsumer.start()
343346
framesInput.forEachFrame { index, size, frame ->
344-
BusyDialog.updateProgress(index, size)
347+
BusyDialog.show(TITLE_GENERATE, index, size)
345348
frameConsumer.consume(frame)
346349
}
347350
frameConsumer.stop()

0 commit comments

Comments
 (0)