Skip to content

Commit

Permalink
Show progress snackbar when exporting logs
Browse files Browse the repository at this point in the history
  • Loading branch information
darshanparajuli committed Mar 13, 2021
1 parent d48983c commit 61f2f06
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import android.widget.ProgressBar
import android.widget.TextView
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.widget.Toolbar
import androidx.core.content.ContextCompat.getColor
import androidx.core.net.toFile
import androidx.core.net.toUri
import androidx.documentfile.provider.DocumentFile
Expand All @@ -42,6 +43,9 @@ import com.dp.logcatapp.util.closeQuietly
import com.dp.logcatapp.util.getAndroidViewModel
import com.dp.logcatapp.util.inflateLayout
import com.dp.logcatapp.util.showToast
import com.dp.logcatapp.views.IndeterminateProgressSnackBar
import com.google.android.material.snackbar.Snackbar
import com.google.android.material.snackbar.Snackbar.LENGTH_SHORT
import kotlinx.coroutines.Dispatchers.IO
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
Expand All @@ -67,6 +71,7 @@ class SavedLogsFragment : BaseFragment(), View.OnClickListener, View.OnLongClick
private lateinit var recyclerViewAdapter: MyRecyclerViewAdapter
private lateinit var linearLayoutManager: LinearLayoutManager
private lateinit var progressBar: ProgressBar
private lateinit var snackBarProgress: IndeterminateProgressSnackBar

private var exportFormat: ExportFormat? = null

Expand Down Expand Up @@ -100,6 +105,7 @@ class SavedLogsFragment : BaseFragment(), View.OnClickListener, View.OnLongClick
recyclerView.itemAnimator = null
recyclerView.layoutManager = linearLayoutManager
recyclerView.adapter = recyclerViewAdapter
snackBarProgress = IndeterminateProgressSnackBar(view, getString(R.string.saving))

parentFragmentManager.findFragmentByTag(RenameDialogFragment.TAG)
?.setTargetFragment(this, 0)
Expand Down Expand Up @@ -522,7 +528,8 @@ class SavedLogsFragment : BaseFragment(), View.OnClickListener, View.OnLongClick
src: InputStream,
dest: OutputStream
) {
scope.launch {
scope.launchWhenResumed {
snackBarProgress.show()
val result = withContext(IO) {
try {
when (this@SavedLogsFragment.exportFormat ?: return@withContext false) {
Expand Down Expand Up @@ -554,11 +561,16 @@ class SavedLogsFragment : BaseFragment(), View.OnClickListener, View.OnLongClick
}
}

activity?.let {
snackBarProgress.dismiss()
view?.let {
if (result) {
it.showToast(it.getString(R.string.saved))
Snackbar.make(it, R.string.saved, LENGTH_SHORT)
.show()
(activity as? SavedLogsActivity)?.closeCabToolbar()
} else {
it.showToast(it.getString(R.string.error_saving))
Snackbar.make(it, R.string.error_saving, LENGTH_SHORT)
.setBackgroundTint(getColor(requireContext(), R.color.color_primary_error))
.show()
}
}
}
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<color name="color_primary_dark">#00796B</color>
<color name="color_primary_dark_mode">#00796B</color>
<color name="color_primary_dark_mode_dark">#004D40</color>
<color name="color_primary_error">#B00020</color>

<color name="toolbar_shadow_start_color_light">#4b000000</color>
<color name="toolbar_shadow_center_color_light">#1e000000</color>
Expand Down

0 comments on commit 61f2f06

Please sign in to comment.