From 0961e674fd7738d7a7ff6d76179677bc3779d535 Mon Sep 17 00:00:00 2001 From: pacien Date: Sun, 5 Aug 2018 21:04:19 +0200 Subject: Replace deprecated progress dialog --- .../org/pacien/tincapp/activities/BaseActivity.kt | 4 +- .../org/pacien/tincapp/activities/StartActivity.kt | 3 +- .../pacien/tincapp/activities/StatusActivity.kt | 3 +- .../java/org/pacien/tincapp/utils/ProgressModal.kt | 47 ++++++++++++++++++++++ app/src/main/res/layout/common_progress_dialog.xml | 40 ++++++++++++++++++ 5 files changed, 91 insertions(+), 6 deletions(-) create mode 100644 app/src/main/java/org/pacien/tincapp/utils/ProgressModal.kt create mode 100644 app/src/main/res/layout/common_progress_dialog.xml diff --git a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt index 7b9c202..fde99d0 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/BaseActivity.kt @@ -18,7 +18,6 @@ package org.pacien.tincapp.activities -import android.app.ProgressDialog import android.os.Bundle import android.support.annotation.StringRes import android.support.design.widget.Snackbar @@ -33,6 +32,7 @@ import org.pacien.tincapp.context.App import org.pacien.tincapp.context.AppInfo import org.pacien.tincapp.context.AppPaths import org.pacien.tincapp.context.CrashRecorder +import org.pacien.tincapp.utils.ProgressModal /** * @author pacien @@ -109,7 +109,7 @@ abstract class BaseActivity : AppCompatActivity() { protected fun notify(@StringRes msg: Int) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() protected fun notify(msg: String) = Snackbar.make(activity_base, msg, Snackbar.LENGTH_LONG).show() - protected fun showProgressDialog(@StringRes msg: Int): ProgressDialog = ProgressDialog.show(this, null, getString(msg), true, false) + protected fun showProgressDialog(@StringRes msg: Int): AlertDialog = ProgressModal.show(this, getString(msg)) protected fun showErrorDialog(msg: String): AlertDialog = AlertDialog.Builder(this) .setTitle(R.string.title_error).setMessage(msg) .setPositiveButton(R.string.action_close, { _, _ -> Unit }).show() diff --git a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt index c775618..fbcde81 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StartActivity.kt @@ -19,7 +19,6 @@ package org.pacien.tincapp.activities import android.app.Activity -import android.app.ProgressDialog import android.content.Intent import android.net.VpnService import android.os.Bundle @@ -137,7 +136,7 @@ class StartActivity : BaseActivity() { Actions.EVENT_CONNECTED to this::onVpnStart, Actions.EVENT_ABORTED to this::onVpnStartError)) - private var connectDialog: ProgressDialog? = null + private var connectDialog: AlertDialog? = null override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) diff --git a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt index a7a1853..cd64355 100644 --- a/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt +++ b/app/src/main/java/org/pacien/tincapp/activities/StatusActivity.kt @@ -18,7 +18,6 @@ package org.pacien.tincapp.activities -import android.app.ProgressDialog import android.content.Intent import android.os.Bundle import android.support.v4.widget.SwipeRefreshLayout @@ -51,7 +50,7 @@ import kotlin.concurrent.timerTask */ class StatusActivity : BaseActivity(), AdapterView.OnItemClickListener, SwipeRefreshLayout.OnRefreshListener { private val broadcastMapper = BroadcastMapper(mapOf(Actions.EVENT_DISCONNECTED to this::onVpnShutdown)) - private var shutdownDialog: ProgressDialog? = null + private var shutdownDialog: AlertDialog? = null private var nodeListAdapter: ArrayAdapter? = null private var refreshTimer: Timer? = null private var listNetworksAfterExit = true diff --git a/app/src/main/java/org/pacien/tincapp/utils/ProgressModal.kt b/app/src/main/java/org/pacien/tincapp/utils/ProgressModal.kt new file mode 100644 index 0000000..379e3af --- /dev/null +++ b/app/src/main/java/org/pacien/tincapp/utils/ProgressModal.kt @@ -0,0 +1,47 @@ +/* + * tinc app, an Android binding and user interface for the tinc mesh VPN daemon + * Copyright (C) 2017-2018 Pacien TRAN-GIRARD + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +package org.pacien.tincapp.utils + +import android.annotation.SuppressLint +import android.app.Activity +import android.support.v7.app.AlertDialog +import android.view.LayoutInflater +import android.view.View +import android.widget.TextView +import org.pacien.tincapp.R + +/** + * @author pacien + */ +object ProgressModal { + fun show(context: Activity, text: String): AlertDialog { + return AlertDialog.Builder(context) + .setView(newDialogView(context.layoutInflater, text)) + .setCancelable(false) + .show() + } + + @SuppressLint("InflateParams") + private fun newDialogView(inflater: LayoutInflater, text: String): View { + val view = inflater.inflate(R.layout.common_progress_dialog, null) + val textView: TextView = view.findViewById(R.id.common_progress_dialog_text) + textView.text = text + return view + } +} diff --git a/app/src/main/res/layout/common_progress_dialog.xml b/app/src/main/res/layout/common_progress_dialog.xml new file mode 100644 index 0000000..a55834d --- /dev/null +++ b/app/src/main/res/layout/common_progress_dialog.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + -- cgit v1.2.3