Browse Source

Cleaning up dialogs throughout the app

master
anthony restaino 8 years ago
parent
commit
06069770cb
  1. 17
      app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java
  2. 34
      app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java
  3. 105
      app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java
  4. 6
      app/src/main/java/acr/browser/lightning/view/LightningWebClient.java
  5. 24
      app/src/main/res/layout/dialog_edit_bookmark.xml
  6. 16
      app/src/main/res/layout/dialog_edit_text.xml
  7. 10
      app/src/main/res/layout/dialog_manual_proxy.xml

17
app/src/main/java/acr/browser/lightning/activity/ReadingActivity.java

@ -30,12 +30,14 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants; import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.dialog.BrowserDialog; import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.preference.PreferenceManager; import acr.browser.lightning.preference.PreferenceManager;
import com.anthonycr.bonsai.Schedulers; import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Single; import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction; import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe; import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.bonsai.SingleSubscriber; import com.anthonycr.bonsai.SingleSubscriber;
import com.anthonycr.bonsai.Subscription; import com.anthonycr.bonsai.Subscription;
import acr.browser.lightning.reading.HtmlFetcher; import acr.browser.lightning.reading.HtmlFetcher;
import acr.browser.lightning.reading.JResult; import acr.browser.lightning.reading.JResult;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
@ -287,9 +289,8 @@ public class ReadingActivity extends AppCompatActivity {
finish(); finish();
break; break;
case R.id.text_size_item: case R.id.text_size_item:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater(); View view = LayoutInflater.from(this).inflate(R.layout.seek_layout, null);
View view = inflater.inflate(R.layout.seek_layout, null);
final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar); final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar);
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() { bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@ -309,12 +310,14 @@ public class ReadingActivity extends AppCompatActivity {
}); });
bar.setMax(5); bar.setMax(5);
bar.setProgress(mTextSize); bar.setProgress(mTextSize);
builder.setView(view);
builder.setTitle(R.string.size); AlertDialog.Builder builder = new AlertDialog.Builder(this)
builder.setPositiveButton(android.R.string.ok, new OnClickListener() { .setView(view)
.setTitle(R.string.size)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override @Override
public void onClick(DialogInterface arg0, int arg1) { public void onClick(DialogInterface dialog, int arg1) {
mTextSize = bar.getProgress(); mTextSize = bar.getProgress();
mBody.setTextSize(getTextSize(mTextSize)); mBody.setTextSize(getTextSize(mTextSize));
mPreferences.setReadingTextSize(bar.getProgress()); mPreferences.setReadingTextSize(bar.getProgress());

34
app/src/main/java/acr/browser/lightning/dialog/BrowserDialog.java

@ -123,30 +123,32 @@ public class BrowserDialog {
}); });
} }
public static void showEditText(@NonNull Activity activity, @StringRes int title, public static void showEditText(@NonNull Activity activity,
@StringRes int hint, @StringRes int action, @StringRes int title,
@StringRes int hint,
@StringRes int action,
@NonNull final EditorListener listener) { @NonNull final EditorListener listener) {
showEditText(activity, title, hint, null, action, listener); showEditText(activity, title, hint, null, action, listener);
} }
public static void showEditText(@NonNull Activity activity, @StringRes int title, public static void showEditText(@NonNull Activity activity,
@StringRes int hint, @Nullable String currentText, @StringRes int title,
@StringRes int action, @NonNull final EditorListener listener) { @StringRes int hint,
final AlertDialog.Builder editorDialog = new AlertDialog.Builder(activity); @Nullable String currentText,
editorDialog.setTitle(title); @StringRes int action,
final EditText editText = new EditText(activity); @NonNull final EditorListener listener) {
View dialogView = LayoutInflater.from(activity).inflate(R.layout.dialog_edit_text, null);
final EditText editText = (EditText) dialogView.findViewById(R.id.dialog_edit_text);
editText.setHint(hint); editText.setHint(hint);
if (currentText != null) { if (currentText != null) {
editText.setText(currentText); editText.setText(currentText);
} }
editText.setSingleLine();
LinearLayout layout = new LinearLayout(activity); final AlertDialog.Builder editorDialog = new AlertDialog.Builder(activity)
layout.setOrientation(LinearLayout.VERTICAL); .setTitle(title)
int padding = Utils.dpToPx(10); .setView(dialogView)
layout.setPadding(padding, padding, padding, padding); .setPositiveButton(action,
layout.addView(editText);
editorDialog.setView(layout);
editorDialog.setPositiveButton(action,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override

105
app/src/main/java/acr/browser/lightning/fragment/GeneralSettingsFragment.java

@ -17,10 +17,9 @@ import android.support.v7.app.AlertDialog;
import android.text.Editable; import android.text.Editable;
import android.text.InputFilter; import android.text.InputFilter;
import android.text.TextWatcher; import android.text.TextWatcher;
import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup;
import android.widget.EditText; import android.widget.EditText;
import android.widget.LinearLayout;
import acr.browser.lightning.BuildConfig; import acr.browser.lightning.BuildConfig;
import acr.browser.lightning.R; import acr.browser.lightning.R;
@ -31,7 +30,7 @@ import acr.browser.lightning.utils.ProxyUtils;
import acr.browser.lightning.utils.ThemeUtils; import acr.browser.lightning.utils.ThemeUtils;
import acr.browser.lightning.utils.Utils; import acr.browser.lightning.utils.Utils;
import static acr.browser.lightning.preference.PreferenceManager.*; import static acr.browser.lightning.preference.PreferenceManager.Suggestion;
public class GeneralSettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener { public class GeneralSettingsFragment extends LightningPreferenceFragment implements Preference.OnPreferenceClickListener, Preference.OnPreferenceChangeListener {
@ -163,24 +162,20 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
} }
private void searchUrlPicker() { private void searchUrlPicker() {
final AlertDialog.Builder urlPicker = new AlertDialog.Builder(mActivity);
urlPicker.setTitle(getResources().getString(R.string.custom_url)); BrowserDialog.showEditText(mActivity,
final EditText getSearchUrl = new EditText(mActivity); R.string.custom_url,
String mSearchUrl = mPreferenceManager.getSearchUrl(); R.string.custom_url,
getSearchUrl.setText(mSearchUrl); mPreferenceManager.getSearchUrl(),
urlPicker.setView(getSearchUrl); R.string.action_ok,
urlPicker.setPositiveButton(getResources().getString(R.string.action_ok), new BrowserDialog.EditorListener() {
new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(String text) {
String text = getSearchUrl.getText().toString();
mPreferenceManager.setSearchUrl(text); mPreferenceManager.setSearchUrl(text);
searchengine.setSummary(getResources().getString(R.string.custom_url) + ": " searchengine.setSummary(mActivity.getString(R.string.custom_url) + ": " + text);
+ text);
} }
}); });
Dialog dialog = urlPicker.show();
BrowserDialog.setDialogSize(mActivity, dialog);
} }
private void getFlashChoice() { private void getFlashChoice() {
@ -217,7 +212,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
private void proxyChoicePicker() { private void proxyChoicePicker() {
AlertDialog.Builder picker = new AlertDialog.Builder(mActivity); AlertDialog.Builder picker = new AlertDialog.Builder(mActivity);
picker.setTitle(getResources().getString(R.string.http_proxy)); picker.setTitle(R.string.http_proxy);
picker.setSingleChoiceItems(mProxyChoices, mPreferenceManager.getProxyChoice(), picker.setSingleChoiceItems(mProxyChoices, mPreferenceManager.getProxyChoice(),
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@ -226,7 +221,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
setProxyChoice(which); setProxyChoice(which);
} }
}); });
picker.setPositiveButton(getResources().getString(R.string.action_ok), null); picker.setPositiveButton(R.string.action_ok, null);
Dialog dialog = picker.show(); Dialog dialog = picker.show();
BrowserDialog.setDialogSize(mActivity, dialog); BrowserDialog.setDialogSize(mActivity, dialog);
} }
@ -252,7 +247,7 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
} }
private void manualProxyPicker() { private void manualProxyPicker() {
View v = mActivity.getLayoutInflater().inflate(R.layout.picker_manual_proxy, null); View v = mActivity.getLayoutInflater().inflate(R.layout.dialog_manual_proxy, null);
final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost); final EditText eProxyHost = (EditText) v.findViewById(R.id.proxyHost);
final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort); final EditText eProxyPort = (EditText) v.findViewById(R.id.proxyPort);
@ -405,28 +400,26 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
} }
private void homePicker() { private void homePicker() {
final AlertDialog.Builder homePicker = new AlertDialog.Builder(mActivity); String currentHomepage;
homePicker.setTitle(getResources().getString(R.string.title_custom_homepage));
final EditText getHome = new EditText(mActivity);
mHomepage = mPreferenceManager.getHomepage(); mHomepage = mPreferenceManager.getHomepage();
if (!mHomepage.startsWith(Constants.ABOUT)) { if (!mHomepage.startsWith(Constants.ABOUT)) {
getHome.setText(mHomepage); currentHomepage = mHomepage;
} else { } else {
String defaultUrl = "https://www.google.com"; currentHomepage = "https://www.google.com";
getHome.setText(defaultUrl);
} }
homePicker.setView(getHome);
homePicker.setPositiveButton(getResources().getString(R.string.action_ok), BrowserDialog.showEditText(mActivity,
new DialogInterface.OnClickListener() { R.string.title_custom_homepage,
R.string.title_custom_homepage,
currentHomepage,
R.string.action_ok,
new BrowserDialog.EditorListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(String text) {
String text = getHome.getText().toString();
mPreferenceManager.setHomepage(text); mPreferenceManager.setHomepage(text);
home.setSummary(text); home.setSummary(text);
} }
}); });
Dialog dialog = homePicker.show();
BrowserDialog.setDialogSize(mActivity, dialog);
} }
private void downloadLocDialog() { private void downloadLocDialog() {
@ -492,40 +485,36 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
} }
private void agentPicker() { private void agentPicker() {
final AlertDialog.Builder agentStringPicker = new AlertDialog.Builder(mActivity);
agentStringPicker.setTitle(getResources().getString(R.string.title_user_agent)); BrowserDialog.showEditText(mActivity,
final EditText getAgent = new EditText(mActivity); R.string.title_user_agent,
agentStringPicker.setView(getAgent); R.string.title_user_agent,
agentStringPicker.setPositiveButton(getResources().getString(R.string.action_ok), mPreferenceManager.getUserAgentString(""),
new DialogInterface.OnClickListener() { R.string.action_ok,
new BrowserDialog.EditorListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(String text) {
String text = getAgent.getText().toString();
mPreferenceManager.setUserAgentString(text); mPreferenceManager.setUserAgentString(text);
useragent.setSummary(getResources().getString(R.string.agent_custom)); useragent.setSummary(mActivity.getString(R.string.agent_custom));
} }
}); });
Dialog dialog = agentStringPicker.show();
BrowserDialog.setDialogSize(mActivity, dialog);
} }
private void downPicker() { private void downPicker() {
final AlertDialog.Builder downLocationPicker = new AlertDialog.Builder(mActivity);
LinearLayout layout = new LinearLayout(mActivity); View dialogView = LayoutInflater.from(mActivity).inflate(R.layout.dialog_edit_text, null);
downLocationPicker.setTitle(getResources().getString(R.string.title_download_location)); final EditText getDownload = (EditText) dialogView.findViewById(R.id.dialog_edit_text);
final EditText getDownload = new EditText(mActivity);
getDownload.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, final int errorColor = ContextCompat.getColor(mActivity, R.color.error_red);
ViewGroup.LayoutParams.WRAP_CONTENT)); final int regularColor = ThemeUtils.getTextColor(mActivity);
getDownload.setText(mPreferenceManager.getDownloadDirectory());
final int errorColor = ContextCompat.getColor(getActivity(), R.color.error_red);
final int regularColor = ThemeUtils.getTextColor(getActivity());
getDownload.setTextColor(regularColor); getDownload.setTextColor(regularColor);
getDownload.addTextChangedListener(new DownloadLocationTextWatcher(getDownload, errorColor, regularColor)); getDownload.addTextChangedListener(new DownloadLocationTextWatcher(getDownload, errorColor, regularColor));
getDownload.setText(mPreferenceManager.getDownloadDirectory()); getDownload.setText(mPreferenceManager.getDownloadDirectory());
layout.addView(getDownload); AlertDialog.Builder downLocationPicker = new AlertDialog.Builder(mActivity)
downLocationPicker.setView(layout); .setTitle(R.string.title_download_location)
downLocationPicker.setPositiveButton(getResources().getString(R.string.action_ok), .setView(dialogView)
.setPositiveButton(R.string.action_ok,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int which) { public void onClick(DialogInterface dialog, int which) {
@ -640,11 +629,11 @@ public class GeneralSettingsFragment extends LightningPreferenceFragment impleme
} }
private static class DownloadLocationTextWatcher implements TextWatcher { private static class DownloadLocationTextWatcher implements TextWatcher {
private final EditText getDownload; @NonNull private final EditText getDownload;
private final int errorColor; private final int errorColor;
private final int regularColor; private final int regularColor;
public DownloadLocationTextWatcher(EditText getDownload, int errorColor, int regularColor) { public DownloadLocationTextWatcher(@NonNull EditText getDownload, int errorColor, int regularColor) {
this.getDownload = getDownload; this.getDownload = getDownload;
this.errorColor = errorColor; this.errorColor = errorColor;
this.regularColor = regularColor; this.regularColor = regularColor;

6
app/src/main/java/acr/browser/lightning/view/LightningWebClient.java

@ -141,9 +141,9 @@ public class LightningWebClient extends WebViewClient {
realmLabel.setText(mActivity.getString(R.string.label_realm, realm)); realmLabel.setText(mActivity.getString(R.string.label_realm, realm));
builder.setView(dialogView) builder.setView(dialogView)
.setTitle(mActivity.getString(R.string.title_sign_in)) .setTitle(R.string.title_sign_in)
.setCancelable(true) .setCancelable(true)
.setPositiveButton(mActivity.getString(R.string.title_sign_in), .setPositiveButton(R.string.title_sign_in,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {
@ -153,7 +153,7 @@ public class LightningWebClient extends WebViewClient {
Log.d(TAG, "Attempting HTTP Authentication"); Log.d(TAG, "Attempting HTTP Authentication");
} }
}) })
.setNegativeButton(mActivity.getString(R.string.action_cancel), .setNegativeButton(R.string.action_cancel,
new DialogInterface.OnClickListener() { new DialogInterface.OnClickListener() {
@Override @Override
public void onClick(DialogInterface dialog, int id) { public void onClick(DialogInterface dialog, int id) {

24
app/src/main/res/layout/dialog_edit_bookmark.xml

@ -1,29 +1,33 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
android:orientation="vertical" xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:padding="10dp"> android:orientation="vertical"
android:padding="@dimen/dialog_padding">
<EditText <EditText
android:id="@+id/bookmark_title"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/bookmark_title" android:hint="@string/hint_title"
android:singleLine="true" android:maxLines="1"
android:hint="@string/hint_title"/> android:singleLine="true"/>
<EditText <EditText
android:id="@+id/bookmark_url"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/bookmark_url"
android:hint="@string/hint_url" android:hint="@string/hint_url"
android:singleLine="true" android:inputType="textUri"
android:inputType="textUri"/> android:maxLines="1"
android:singleLine="true"/>
<AutoCompleteTextView <AutoCompleteTextView
android:id="@+id/bookmark_folder"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:id="@+id/bookmark_folder"
android:hint="@string/folder" android:hint="@string/folder"
android:maxLines="1"
android:singleLine="true"/> android:singleLine="true"/>
</LinearLayout> </LinearLayout>

16
app/src/main/res/layout/dialog_edit_text.xml

@ -0,0 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:padding="@dimen/dialog_padding">
<EditText
android:id="@+id/dialog_edit_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLines="1"/>
</LinearLayout>

10
app/src/main/res/layout/picker_manual_proxy.xml → app/src/main/res/layout/dialog_manual_proxy.xml

@ -1,12 +1,10 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" <LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:orientation="vertical"
android:paddingEnd="4dp" android:padding="@dimen/dialog_padding">
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingStart="4dp">
<LinearLayout <LinearLayout
android:layout_width="match_parent" android:layout_width="match_parent"
@ -15,6 +13,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="@dimen/default_padding"
android:text="@string/host"/> android:text="@string/host"/>
<EditText <EditText
@ -32,6 +31,7 @@
<TextView <TextView
android:layout_width="wrap_content" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:layout_height="wrap_content"
android:layout_marginRight="@dimen/default_padding"
android:text="@string/port"/> android:text="@string/port"/>
<EditText <EditText
Loading…
Cancel
Save