]> gitweb.stoutner.com Git - PrivacyBrowserAndroid.git/blobdiff - app/src/main/java/com/stoutner/privacybrowser/dialogs/AddDomainDialog.java
Create a dark theme for the `AlertDialogs`.
[PrivacyBrowserAndroid.git] / app / src / main / java / com / stoutner / privacybrowser / dialogs / AddDomainDialog.java
index e4cf59f05d9a5da9c2f88da7245d55df7e57856b..9e63a9405207a97bfbdb9fe48b305af0736dc094 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright 2017 Soren Stoutner <soren@stoutner.com>.
+ * Copyright © 2017 Soren Stoutner <soren@stoutner.com>.
  *
  * This file is part of Privacy Browser <https://www.stoutner.com/privacy-browser>.
  *
@@ -24,6 +24,7 @@ import android.app.AlertDialog;
 import android.app.Dialog;
 import android.content.Context;
 import android.content.DialogInterface;
+import android.net.Uri;
 import android.os.Bundle;
 // We have to use `AppCompatDialogFragment` instead of `DialogFragment` or an error is produced on API <= 22.
 import android.support.annotation.NonNull;
@@ -34,6 +35,7 @@ import android.view.WindowManager;
 import android.widget.EditText;
 
 import com.stoutner.privacybrowser.R;
+import com.stoutner.privacybrowser.activities.MainWebViewActivity;
 
 public class AddDomainDialog extends AppCompatDialogFragment {
     // The public interface is used to send information back to the parent activity.
@@ -61,10 +63,20 @@ public class AddDomainDialog extends AppCompatDialogFragment {
     @Override
     @NonNull
     public Dialog onCreateDialog(Bundle savedInstanceState) {
-        // Use `AlertDialog.Builder` to create the `AlertDialog`.  The style formats the color of the button text.
-        AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.LightAlertDialog);
+        // Use `AlertDialog.Builder` to create the `AlertDialog`.
+        AlertDialog.Builder dialogBuilder;
+
+        // Set the style according to the theme.
+        if (MainWebViewActivity.darkTheme) {
+            dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogDark);
+        } else {
+            dialogBuilder = new AlertDialog.Builder(getActivity(), R.style.PrivacyBrowserAlertDialogLight);
+        }
+
+        // Set the title.
         dialogBuilder.setTitle(R.string.add_domain);
-        // The parent view is `null` because it will be assigned by the `AlertDialog`.
+
+        // Set the view.  The parent view is `null` because it will be assigned by the `AlertDialog`.
         dialogBuilder.setView(getActivity().getLayoutInflater().inflate(R.layout.add_domain_dialog, null));
 
         // Set an `onClick()` listener for the negative button.
@@ -93,11 +105,17 @@ public class AddDomainDialog extends AppCompatDialogFragment {
         // Show the keyboard when the `AlertDialog` is displayed on the screen.
         alertDialog.getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
 
-        // We need to show the `AlertDialog` before w3e can call `setOnKeyListener()` below.
+        // We need to show the `AlertDialog` before we can edit the contents.
         alertDialog.show();
 
-        // Allow the `enter` key on the keyboard to create the domain from `add_domain_edittext`.
+        // Get a handle for `domain_name_edittext`.
         EditText addDomainEditText = (EditText) alertDialog.findViewById(R.id.domain_name_edittext);
+
+        // Get the current domain from `formattedUrlString`.
+        Uri currentUri = Uri.parse(MainWebViewActivity.formattedUrlString);
+        addDomainEditText.setText(currentUri.getHost());
+
+        // Allow the `enter` key on the keyboard to create the domain from `add_domain_edittext`.
         addDomainEditText.setOnKeyListener(new View.OnKeyListener() {
             public boolean onKey(View view, int keyCode, KeyEvent event) {
                 // If the event is a key-down on the `enter` key, select the `PositiveButton` `Add`.