Browse Source

Cleaning up dialogs throughout the app

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

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

@ -30,12 +30,14 @@ import acr.browser.lightning.app.BrowserApp; @@ -30,12 +30,14 @@ import acr.browser.lightning.app.BrowserApp;
import acr.browser.lightning.constant.Constants;
import acr.browser.lightning.dialog.BrowserDialog;
import acr.browser.lightning.preference.PreferenceManager;
import com.anthonycr.bonsai.Schedulers;
import com.anthonycr.bonsai.Single;
import com.anthonycr.bonsai.SingleAction;
import com.anthonycr.bonsai.SingleOnSubscribe;
import com.anthonycr.bonsai.SingleSubscriber;
import com.anthonycr.bonsai.Subscription;
import acr.browser.lightning.reading.HtmlFetcher;
import acr.browser.lightning.reading.JResult;
import acr.browser.lightning.utils.ThemeUtils;
@ -148,45 +150,45 @@ public class ReadingActivity extends AppCompatActivity { @@ -148,45 +150,45 @@ public class ReadingActivity extends AppCompatActivity {
if (getSupportActionBar() != null)
getSupportActionBar().setTitle(Utils.getDomainName(mUrl));
mPageLoaderSubscription = loadPage(mUrl).subscribeOn(Schedulers.worker())
.observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<ReaderInfo>() {
@Override
public void onStart() {
mProgressDialog = new ProgressDialog(ReadingActivity.this);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setMessage(getString(R.string.loading));
mProgressDialog.show();
BrowserDialog.setDialogSize(ReadingActivity.this, mProgressDialog);
}
.observeOn(Schedulers.main())
.subscribe(new SingleOnSubscribe<ReaderInfo>() {
@Override
public void onStart() {
mProgressDialog = new ProgressDialog(ReadingActivity.this);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setCancelable(false);
mProgressDialog.setIndeterminate(true);
mProgressDialog.setMessage(getString(R.string.loading));
mProgressDialog.show();
BrowserDialog.setDialogSize(ReadingActivity.this, mProgressDialog);
}
@Override
public void onItem(@Nullable ReaderInfo item) {
if (item == null || item.getTitle().isEmpty() || item.getBody().isEmpty()) {
setText(getString(R.string.untitled), getString(R.string.loading_failed));
} else {
setText(item.getTitle(), item.getBody());
}
@Override
public void onItem(@Nullable ReaderInfo item) {
if (item == null || item.getTitle().isEmpty() || item.getBody().isEmpty()) {
setText(getString(R.string.untitled), getString(R.string.loading_failed));
} else {
setText(item.getTitle(), item.getBody());
}
}
@Override
public void onError(@NonNull Throwable throwable) {
setText(getString(R.string.untitled), getString(R.string.loading_failed));
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
@Override
public void onError(@NonNull Throwable throwable) {
setText(getString(R.string.untitled), getString(R.string.loading_failed));
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
}
@Override
public void onComplete() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
@Override
public void onComplete() {
if (mProgressDialog != null && mProgressDialog.isShowing()) {
mProgressDialog.dismiss();
mProgressDialog = null;
}
});
}
});
return true;
}
@ -287,9 +289,8 @@ public class ReadingActivity extends AppCompatActivity { @@ -287,9 +289,8 @@ public class ReadingActivity extends AppCompatActivity {
finish();
break;
case R.id.text_size_item:
AlertDialog.Builder builder = new AlertDialog.Builder(this);
LayoutInflater inflater = this.getLayoutInflater();
View view = inflater.inflate(R.layout.seek_layout, null);
View view = LayoutInflater.from(this).inflate(R.layout.seek_layout, null);
final SeekBar bar = (SeekBar) view.findViewById(R.id.text_size_seekbar);
bar.setOnSeekBarChangeListener(new OnSeekBarChangeListener() {
@ -309,18 +310,20 @@ public class ReadingActivity extends AppCompatActivity { @@ -309,18 +310,20 @@ public class ReadingActivity extends AppCompatActivity {
});
bar.setMax(5);
bar.setProgress(mTextSize);
builder.setView(view);
builder.setTitle(R.string.size);
builder.setPositiveButton(android.R.string.ok, new OnClickListener() {
@Override
public void onClick(DialogInterface arg0, int arg1) {
mTextSize = bar.getProgress();
mBody.setTextSize(getTextSize(mTextSize));
mPreferences.setReadingTextSize(bar.getProgress());
}
AlertDialog.Builder builder = new AlertDialog.Builder(this)
.setView(view)
.setTitle(R.string.size)
.setPositiveButton(android.R.string.ok, new OnClickListener() {
});
@Override
public void onClick(DialogInterface dialog, int arg1) {
mTextSize = bar.getProgress();
mBody.setTextSize(getTextSize(mTextSize));
mPreferences.setReadingTextSize(bar.getProgress());
}
});
Dialog dialog = builder.show();
BrowserDialog.setDialogSize(this, dialog);
break;

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

@ -123,37 +123,39 @@ public class BrowserDialog { @@ -123,37 +123,39 @@ public class BrowserDialog {
});
}
public static void showEditText(@NonNull Activity activity, @StringRes int title,
@StringRes int hint, @StringRes int action,
public static void showEditText(@NonNull Activity activity,
@StringRes int title,
@StringRes int hint,
@StringRes int action,
@NonNull final EditorListener listener) {
showEditText(activity, title, hint, null, action, listener);
}
public static void showEditText(@NonNull Activity activity, @StringRes int title,
@StringRes int hint, @Nullable String currentText,
@StringRes int action, @NonNull final EditorListener listener) {
final AlertDialog.Builder editorDialog = new AlertDialog.Builder(activity);
editorDialog.setTitle(title);
final EditText editText = new EditText(activity);
public static void showEditText(@NonNull Activity activity,
@StringRes int title,
@StringRes int hint,
@Nullable String currentText,
@StringRes int action,
@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);
if (currentText != null) {
editText.setText(currentText);
}
editText.setSingleLine();
LinearLayout layout = new LinearLayout(activity);
layout.setOrientation(LinearLayout.VERTICAL);
int padding = Utils.dpToPx(10);
layout.setPadding(padding, padding, padding, padding);
layout.addView(editText);
editorDialog.setView(layout);
editorDialog.setPositiveButton(action,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listener.onClick(editText.getText().toString());
}
});
final AlertDialog.Builder editorDialog = new AlertDialog.Builder(activity)
.setTitle(title)
.setView(dialogView)
.setPositiveButton(action,
new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
listener.onClick(editText.getText().toString());
}
});
Dialog dialog = editorDialog.show();
setDialogSize(activity, dialog);

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

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

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

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

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

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

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

@ -0,0 +1,16 @@ @@ -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>

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

@ -1,12 +1,10 @@ @@ -1,12 +1,10 @@
<?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_height="match_parent"
android:orientation="vertical"
android:paddingEnd="4dp"
android:paddingLeft="4dp"
android:paddingRight="4dp"
android:paddingStart="4dp">
android:padding="@dimen/dialog_padding">
<LinearLayout
android:layout_width="match_parent"
@ -15,14 +13,15 @@ @@ -15,14 +13,15 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/host" />
android:layout_marginRight="@dimen/default_padding"
android:text="@string/host"/>
<EditText
android:id="@+id/proxyHost"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="text" />
android:inputType="text"/>
</LinearLayout>
<LinearLayout
@ -32,14 +31,15 @@ @@ -32,14 +31,15 @@
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/port" />
android:layout_marginRight="@dimen/default_padding"
android:text="@string/port"/>
<EditText
android:id="@+id/proxyPort"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:inputType="number" />
android:inputType="number"/>
</LinearLayout>
</LinearLayout>
Loading…
Cancel
Save