diff --git a/app/build.gradle b/app/build.gradle index 14c8956851..bc894e2310 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -9,8 +9,8 @@ android { applicationId "org.ole.planet.myplanet" minSdkVersion 21 targetSdkVersion 34 - versionCode 1252 - versionName "0.12.52" + versionCode 1253 + versionName "0.12.53" ndkVersion '21.3.6528147' testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" vectorDrawables.useSupportLibrary = true diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.java b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.java deleted file mode 100644 index 352c1e9e7c..0000000000 --- a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.java +++ /dev/null @@ -1,120 +0,0 @@ -package org.ole.planet.myplanet.utilities; - -import android.app.Activity; -import android.app.ProgressDialog; -import android.content.Context; -import android.content.DialogInterface; -import android.content.Intent; -import android.provider.Settings; -import android.view.View; - -import androidx.appcompat.app.AlertDialog; - -import com.google.android.material.snackbar.Snackbar; - -import org.ole.planet.myplanet.MainApplication; -import org.ole.planet.myplanet.R; -import org.ole.planet.myplanet.datamanager.MyDownloadService; -import org.ole.planet.myplanet.datamanager.Service; -import org.ole.planet.myplanet.model.MyPlanet; - -import java.util.ArrayList; - -public class DialogUtils { - - public static ProgressDialog getProgressDialog(final Context context) { - final ProgressDialog prgDialog = new ProgressDialog(context); - prgDialog.setTitle(context.getString(R.string.downloading_file)); - prgDialog.setMax(100); - prgDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); - prgDialog.setCancelable(false); - prgDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.finish), (dialogInterface, i) -> prgDialog.dismiss()); - prgDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.stop_download), (dialogInterface, i) -> context.stopService(new Intent(context, MyDownloadService.class))); - return prgDialog; - } - - public static void showError(ProgressDialog prgDialog, String message) { - prgDialog.setTitle(message); - if (prgDialog.getButton(ProgressDialog.BUTTON_NEGATIVE) != null) - prgDialog.getButton(ProgressDialog.BUTTON_NEGATIVE).setEnabled(false); - } - - public static void showWifiSettingDialog(final Context context) { - if (!NetworkUtils.isWifiBluetoothEnabled()) return; - showDialog(context); - } - - private static void showDialog(final Context context) { - if (MainApplication.syncFailedCount > 3) { - AlertDialog.Builder pd = new AlertDialog.Builder(context); - String message = NetworkUtils.isBluetoothEnabled() ? "Bluetooth " : ""; - message += NetworkUtils.isWifiEnabled() ? "Wifi " : ""; - message += R.string.is_on_please_turn_of_to_save_battery; - pd.setMessage(message); - pd.setPositiveButton(R.string.go_to_settings, (dialogInterface, i) -> { - MainApplication.syncFailedCount = 0; - Intent intent = new Intent(Settings.ACTION_WIFI_SETTINGS); - context.startActivity(intent); - }).setNegativeButton(context.getString(R.string.cancel), null); - pd.setCancelable(false); - AlertDialog d = pd.create(); - d.show(); - } - } - - public static void showSnack(View v, String s) { - if (v != null) Snackbar.make(v, s, Snackbar.LENGTH_LONG).show(); - } - - public static void showAlert(Context context, String title, String message) { - if (context instanceof Activity && !((Activity) context).isFinishing()) { - new AlertDialog.Builder(context) - .setTitle(title) - .setMessage(message) - .setPositiveButton(R.string.finish, null) - .show(); - } - } - - public static AlertDialog getAlertDialog(Context context, String message, String pos, DialogInterface.OnClickListener listener) { - return new AlertDialog.Builder(context).setMessage(message).setIcon(R.drawable.courses).setPositiveButton(pos, listener).setNegativeButton("Cancel", null).show(); - } - - public static void showCloseAlert(Context context, String title, String message) { - new AlertDialog.Builder(context).setTitle(title).setMessage(message).setPositiveButton(R.string.close, null).show(); - } - - public static AlertDialog getAlertDialog(Context context, String title, View v) { - return new AlertDialog.Builder(context).setTitle(title).setIcon(R.drawable.ic_edit).setView(v).setPositiveButton(R.string.submit, null).setNegativeButton(R.string.cancel, null).show(); - } - - public static AlertDialog.Builder getUpdateDialog(Context context, MyPlanet info, ProgressDialog progressDialog) { - return new AlertDialog.Builder(context).setTitle(R.string.new_version_of_my_planet_available).setMessage(R.string.download_first_to_continue).setNeutralButton(R.string.upgrade_local, (dialogInterface, i) -> { - startDownloadUpdate(context, Utilities.getApkUpdateUrl(info.localapkpath), progressDialog); - }).setPositiveButton(R.string.upgrade, (dialogInterface, i) -> { - startDownloadUpdate(context, info.apkpath, progressDialog); - }); - } - - public static void startDownloadUpdate(Context context, String path, ProgressDialog progressDialog) { - new Service(MainApplication.context).checkCheckSum(new Service.ChecksumCallback() { - @Override - public void onMatch() { - Utilities.toast(MainApplication.context, String.valueOf(R.string.apk_already_exists)); - FileUtils.installApk(context, path); - } - - @Override - public void onFail() { - ArrayList url = new ArrayList(); - url.add(path); - if (progressDialog != null) { - progressDialog.setMessage(String.valueOf(R.string.downloading_file)); - progressDialog.setCancelable(false); - progressDialog.show(); - } - Utilities.openDownloadService(context, url); - } - }, path); - } -} diff --git a/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt new file mode 100644 index 0000000000..faeb2a810c --- /dev/null +++ b/app/src/main/java/org/ole/planet/myplanet/utilities/DialogUtils.kt @@ -0,0 +1,142 @@ +package org.ole.planet.myplanet.utilities + +import android.app.Activity +import android.app.ProgressDialog +import android.content.Context +import android.content.DialogInterface +import android.content.Intent +import android.provider.Settings +import androidx.appcompat.app.AlertDialog +import android.view.View +import com.google.android.material.snackbar.Snackbar +import org.ole.planet.myplanet.MainApplication +import org.ole.planet.myplanet.R +import org.ole.planet.myplanet.datamanager.MyDownloadService +import org.ole.planet.myplanet.datamanager.Service +import org.ole.planet.myplanet.model.MyPlanet + +object DialogUtils { + @JvmStatic + fun getProgressDialog(context: Context): ProgressDialog { + val prgDialog = ProgressDialog(context) + prgDialog.setTitle(context.getString(R.string.downloading_file)) + prgDialog.max = 100 + prgDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL) + prgDialog.setCancelable(false) + prgDialog.setButton(DialogInterface.BUTTON_POSITIVE, context.getString(R.string.finish)) { _, _ -> prgDialog.dismiss() } + prgDialog.setButton(DialogInterface.BUTTON_NEGATIVE, context.getString(R.string.stop_download)) { _, _ -> + context.stopService(Intent(context, MyDownloadService::class.java)) + } + return prgDialog + } + + @JvmStatic + fun showError(prgDialog: ProgressDialog, message: String) { + prgDialog.setTitle(message) + prgDialog.getButton(ProgressDialog.BUTTON_NEGATIVE)?.isEnabled = false + } + + @JvmStatic + fun showWifiSettingDialog(context: Context) { + if (!NetworkUtils.isWifiBluetoothEnabled()) return + showDialog(context) + } + + private fun showDialog(context: Context) { + if (MainApplication.syncFailedCount > 3) { + val pd = AlertDialog.Builder(context) + var message = if (NetworkUtils.isBluetoothEnabled()) "Bluetooth " else "" + message += if (NetworkUtils.isWifiEnabled()) "Wifi " else "" + message += context.getString(R.string.is_on_please_turn_of_to_save_battery) + pd.setMessage(message) + pd.setPositiveButton(context.getString(R.string.go_to_settings)) { _, _ -> + MainApplication.syncFailedCount = 0 + val intent = Intent(Settings.ACTION_WIFI_SETTINGS) + context.startActivity(intent) + }.setNegativeButton(context.getString(R.string.cancel), null) + pd.setCancelable(false) + val d = pd.create() + d.show() + } + } + + @JvmStatic + fun showSnack(v: View?, s: String) { + if (v != null) Snackbar.make(v, s, Snackbar.LENGTH_LONG).show() + } + + @JvmStatic + fun showAlert(context: Context, title: String?, message: String?) { + if (context is Activity && !(context as Activity).isFinishing) { + AlertDialog.Builder(context) + .setTitle(title) + .setMessage(message) + .setPositiveButton(R.string.finish, null) + .show() + } + } + + @JvmStatic + fun getAlertDialog(context: Context, message: String, pos: String, listener: DialogInterface.OnClickListener?): AlertDialog { + return AlertDialog.Builder(context) + .setMessage(message) + .setIcon(R.drawable.courses) + .setPositiveButton(pos, listener) + .setNegativeButton("Cancel", null) + .show() + } + + @JvmStatic + fun showCloseAlert(context: Context, title: String, message: String) { + AlertDialog.Builder(context) + .setTitle(title) + .setMessage(message) + .setPositiveButton(R.string.close, null) + .show() + } + + @JvmStatic + fun getAlertDialog(context: Context, title: String, v: View): AlertDialog { + return AlertDialog.Builder(context) + .setTitle(title) + .setIcon(R.drawable.ic_edit) + .setView(v) + .setPositiveButton(R.string.submit, null) + .setNegativeButton(R.string.cancel, null) + .show() + } + + @JvmStatic + fun getUpdateDialog(context: Context, info: MyPlanet, progressDialog: ProgressDialog): AlertDialog.Builder { + return AlertDialog.Builder(context) + .setTitle(R.string.new_version_of_my_planet_available) + .setMessage(R.string.download_first_to_continue) + .setNeutralButton(R.string.upgrade_local) { _, _ -> + startDownloadUpdate(context, Utilities.getApkUpdateUrl(info.localapkpath), progressDialog) + } + .setPositiveButton(R.string.upgrade) { _, _ -> + startDownloadUpdate(context, info.apkpath!!, progressDialog) + } + } + + @JvmStatic + fun startDownloadUpdate(context: Context, path: String, progressDialog: ProgressDialog) { + Service(MainApplication.context).checkCheckSum(object : Service.ChecksumCallback { + override fun onMatch() { + Utilities.toast(MainApplication.context, context.getString(R.string.apk_already_exists)) + FileUtils.installApk(context, path) + } + + override fun onFail() { + val url = ArrayList() + url.add(path) + if (progressDialog != null) { + progressDialog.setMessage(context.getString(R.string.downloading_file)) + progressDialog.setCancelable(false) + progressDialog.show() + } + Utilities.openDownloadService(context, url) + } + }, path) + } +}