X-Git-Url: https://gitweb.stoutner.com/?p=PrivacyBrowserAndroid.git;a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fcom%2Fstoutner%2Fprivacybrowser%2Fdialogs%2FSaveWebpageDialog.kt;h=3906078402abaaf078ffdd5261ecf15e38b33c87;hp=b27e1703b6537b04022560eada2122b9f4556f6d;hb=bda37dc9784e900cb64b87af3e221e11320d9d01;hpb=031def95c6d9bfc14113fe86b4a5690233d93ce2 diff --git a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.kt b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.kt index b27e1703..39060784 100644 --- a/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.kt +++ b/app/src/main/java/com/stoutner/privacybrowser/dialogs/SaveWebpageDialog.kt @@ -24,7 +24,7 @@ import android.app.Dialog import android.content.Context import android.content.DialogInterface import android.content.Intent -import android.content.res.Configuration +import android.net.Uri import android.os.AsyncTask import android.os.Bundle import android.text.Editable @@ -63,7 +63,7 @@ class SaveWebpageDialog : DialogFragment() { // The public interface is used to send information back to the parent activity. interface SaveWebpageListener { - fun onSaveWebpage(saveType: Int, originalUrlString: String?, dialogFragment: DialogFragment) + fun onSaveWebpage(saveType: Int, originalUrlString: String, dialogFragment: DialogFragment) } override fun onAttach(context: Context) { @@ -77,11 +77,12 @@ class SaveWebpageDialog : DialogFragment() { companion object { // Define the companion object constants. These can be moved to class constants once all of the code has transitioned to Kotlin. const val SAVE_URL = 0 - const val SAVE_IMAGE = 1 + const val SAVE_ARCHIVE = 1 + const val SAVE_IMAGE = 2 // `@JvmStatic` will no longer be required once all the code has transitioned to Kotlin. @JvmStatic - fun saveWebpage(saveType: Int, urlString: String?, fileSizeString: String?, fileNameString: String, userAgentString: String?, cookiesEnabled: Boolean): SaveWebpageDialog { + fun saveWebpage(saveType: Int, urlString: String, fileSizeString: String?, fileNameString: String?, userAgentString: String?, cookiesEnabled: Boolean): SaveWebpageDialog { // Create an arguments bundle. val argumentsBundle = Bundle() @@ -109,30 +110,37 @@ class SaveWebpageDialog : DialogFragment() { override fun onCreateDialog(savedInstanceState: Bundle?): Dialog { // Get the arguments from the bundle. val saveType = requireArguments().getInt(SAVE_TYPE) - val originalUrlString = requireArguments().getString(URL_STRING) + val originalUrlString = requireArguments().getString(URL_STRING)!! val fileSizeString = requireArguments().getString(FILE_SIZE_STRING) - val fileNameString = requireArguments().getString(FILE_NAME_STRING)!! + var fileNameString = requireArguments().getString(FILE_NAME_STRING) val userAgentString = requireArguments().getString(USER_AGENT_STRING) val cookiesEnabled = requireArguments().getBoolean(COOKIES_ENABLED) // Use an alert dialog builder to create the alert dialog. val dialogBuilder = AlertDialog.Builder(requireContext(), R.style.PrivacyBrowserAlertDialog) - // Get the current theme status. - val currentThemeStatus = resources.configuration.uiMode and Configuration.UI_MODE_NIGHT_MASK - - // Set the title and icon according to the save type. + // Configure the dialog according to the save type. when (saveType) { SAVE_URL -> { // Set the title. dialogBuilder.setTitle(R.string.save_url) // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - dialogBuilder.setIcon(R.drawable.copy_enabled_day) - } else { - dialogBuilder.setIcon(R.drawable.copy_enabled_night) - } + dialogBuilder.setIconAttribute(R.attr.copyBlueIcon) + } + + SAVE_ARCHIVE -> { + // Set the title. + dialogBuilder.setTitle(R.string.save_archive) + + // Set the icon according to the theme. + dialogBuilder.setIconAttribute(R.attr.domStorageBlueIcon) + + // Convert the URL to a URI. + val uri = Uri.parse(originalUrlString) + + // Build a file name string based on the host from the URI. + fileNameString = uri.host + ".mht" } SAVE_IMAGE -> { @@ -140,11 +148,13 @@ class SaveWebpageDialog : DialogFragment() { dialogBuilder.setTitle(R.string.save_image) // Set the icon according to the theme. - if (currentThemeStatus == Configuration.UI_MODE_NIGHT_NO) { - dialogBuilder.setIcon(R.drawable.images_enabled_day) - } else { - dialogBuilder.setIcon(R.drawable.images_enabled_night) - } + dialogBuilder.setIconAttribute(R.attr.imagesBlueIcon) + + // Convert the URL to a URI. + val uri = Uri.parse(originalUrlString) + + // Build a file name string based on the host from the URI. + fileNameString = uri.host + ".png" } } @@ -191,7 +201,7 @@ class SaveWebpageDialog : DialogFragment() { // Modify the layout based on the save type. if (saveType == SAVE_URL) { // A URL is being saved. // Populate the URL edit text according to the type. This must be done before the text change listener is created below so that the file size isn't requested again. - if (originalUrlString!!.startsWith("data:")) { // The URL contains the entire data of an image. + if (originalUrlString.startsWith("data:")) { // The URL contains the entire data of an image. // Get a substring of the data URL with the first 100 characters. Otherwise, the user interface will freeze while trying to layout the edit text. val urlSubstring = originalUrlString.substring(0, 100) + "…"