Skip to content

Commit

Permalink
fixed repo setup
Browse files Browse the repository at this point in the history
  • Loading branch information
lhns committed Aug 2, 2021
1 parent 4e6b421 commit b1abbb8
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 17 deletions.
4 changes: 3 additions & 1 deletion app/src/main/java/de/lolhens/resticui/BackupManager.kt
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,9 @@ class BackupManager private constructor(context: Context) {
notificationManager(context).notify(
activeBackup.notificationId,
NotificationCompat.Builder(context, notificationChannelId)
.setContentTitle("${context.resources.getString(R.string.notification_backup_failed_message)}\n${activeBackup.error}")
.setContentTitle(
"${context.resources.getString(R.string.notification_backup_failed_message)}\n${activeBackup.error}"
)
.setSmallIcon(R.drawable.outline_cloud_error_24)
.build()
)
Expand Down
46 changes: 31 additions & 15 deletions app/src/main/java/de/lolhens/resticui/ui/repo/RepoEditFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import de.lolhens.resticui.R
import de.lolhens.resticui.config.*
import de.lolhens.resticui.databinding.FragmentRepoEditBinding
import java.net.URI
import java.util.concurrent.CompletionException

class RepoEditFragment : Fragment() {
private var _binding: FragmentRepoEditBinding? = null
Expand Down Expand Up @@ -103,15 +104,16 @@ class RepoEditFragment : Fragment() {

val resticRepo = repo.repo(backupManager.restic)
resticRepo.stats().handle { _, throwable ->
if (throwable == null) {
saveRepo()
} else {
throwable.printStackTrace()
requireActivity().runOnUiThread {
if (throwable == null) {
saveRepo()
} else {
System.err.println("Error saving repository!")
throwable.printStackTrace()

item.isEnabled = true
binding.progressRepoSave.visibility = INVISIBLE
item.isEnabled = true
binding.progressRepoSave.visibility = INVISIBLE

requireActivity().runOnUiThread {
AlertDialog.Builder(requireActivity())
.setTitle(R.string.alert_init_repo_title)
.setMessage(R.string.alert_init_repo_message)
Expand All @@ -120,18 +122,32 @@ class RepoEditFragment : Fragment() {
binding.progressRepoSave.visibility = VISIBLE

resticRepo.init().handle { _, throwable ->
if (throwable == null) {
saveRepo()
} else {
throwable.printStackTrace()
requireActivity().runOnUiThread {
if (throwable == null) {
saveRepo()
} else {
val throwable =
if (throwable is CompletionException && throwable.cause != null) throwable.cause!!
else throwable

item.isEnabled = true
binding.progressRepoSave.visibility = INVISIBLE
throwable.printStackTrace()

item.isEnabled = true
binding.progressRepoSave.visibility = INVISIBLE

requireActivity().runOnUiThread {
AlertDialog.Builder(requireActivity())
.setTitle(R.string.alert_save_repo_title)
.setMessage(R.string.alert_save_repo_message)
.setMessage(
"${
requireContext().resources.getString(
R.string.alert_save_repo_message
)
}\n\n${throwable.message}\n\n${
requireContext().resources.getString(
R.string.alert_save_repo_question
)
}"
)
.setPositiveButton(android.R.string.ok) { _, _ ->
saveRepo()
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@
<string name="alert_init_repo_title">Initialize Repository</string>
<string name="alert_init_repo_message">No repository found. Do you want to initialize a new Repository at this location?</string>
<string name="alert_save_repo_title">Failed to initialize Repository</string>
<string name="alert_save_repo_message">Failed to initialize Repository. Do you want to save anyway?</string>
<string name="alert_save_repo_message">Failed to initialize Repository!</string>
<string name="alert_save_repo_question">Do you want to save anyway?</string>
<string name="alert_delete_folder_title">Delete Folder Configuration</string>
<string name="alert_delete_folder_message">Do you want to delete this Folder configuration?</string>
<string name="alert_backup_cancel_title">Cancel Backup</string>
Expand Down

0 comments on commit b1abbb8

Please sign in to comment.