Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Delta Between Two Patch Sets: mobile/android/thirdparty/org/adblockplus/browser/UrlInputDialog.java

Issue 29322610: Issue 2720 - [Adblocking settings] Add the other filter lists category (Closed)
Left Patch Set: Changed screen title Created July 20, 2015, 5 p.m.
Right Patch Set: Last naming nit Created July 31, 2015, 9:36 a.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
LEFTRIGHT
1 /* 1 /*
2 * This file is part of Adblock Plus <https://adblockplus.org/>, 2 * This file is part of Adblock Plus <https://adblockplus.org/>,
3 * Copyright (C) 2006-2015 Eyeo GmbH 3 * Copyright (C) 2006-2015 Eyeo GmbH
4 * 4 *
5 * Adblock Plus is free software: you can redistribute it and/or modify 5 * Adblock Plus is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 3 as 6 * it under the terms of the GNU General Public License version 3 as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
8 * 8 *
9 * Adblock Plus is distributed in the hope that it will be useful, 9 * Adblock Plus is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
(...skipping 19 matching lines...) Expand all
30 import android.view.View.OnClickListener; 30 import android.view.View.OnClickListener;
31 import android.view.inputmethod.EditorInfo; 31 import android.view.inputmethod.EditorInfo;
32 import android.widget.Button; 32 import android.widget.Button;
33 import android.widget.EditText; 33 import android.widget.EditText;
34 import android.widget.TextView; 34 import android.widget.TextView;
35 import android.widget.TextView.OnEditorActionListener; 35 import android.widget.TextView.OnEditorActionListener;
36 36
37 public class UrlInputDialog extends Dialog implements TextWatcher, 37 public class UrlInputDialog extends Dialog implements TextWatcher,
38 OnEditorActionListener, OnClickListener 38 OnEditorActionListener, OnClickListener
39 { 39 {
40 private static final int BUTTON_ENABLED_COLOR = 0xff0099cc;
Felix Dahlke 2015/07/26 17:06:23 As you know, I don't think we should have hard cod
René Jeschke 2015/07/28 10:55:27 Done.
41 private static final int BUTTON_DISABLED_COLOR = 0xffc5dfe8;
42 private final Type type; 40 private final Type type;
43 private final UrlReadyCallback callback; 41 private final UrlReadyCallback callback;
44 42
45 private EditText editText = null; 43 private EditText editText = null;
46 private Button button = null; 44 private Button button = null;
47 45
48 private boolean submitEnabled = false; 46 private boolean submitEnabled = false;
49 private boolean triedSubmit = false; 47 private boolean triedSubmit = false;
50 private String currentEditTextValue = null; 48 private String currentEditTextValue = null;
51 49
52 public enum Type 50 public enum Type
53 { 51 {
54 ADD_BLOCKING_LIST, 52 ADD_SUBSCRIPTION,
Felix Dahlke 2015/07/29 20:32:07 Nit: As said elsewhere, we should avoid hard codin
René Jeschke 2015/07/30 09:26:44 Done.
55 ADD_WHITELIST 53 ADD_WHITELISTED_SITE
Felix Dahlke 2015/07/26 17:06:22 It seems to me we're not using ADD_WHITELIST, nor
René Jeschke 2015/07/28 10:55:27 Because the same dialogue will be needed to implem
Felix Dahlke 2015/07/29 20:32:07 Acknowledged. Nit then though: Maybe call it ADD_W
René Jeschke 2015/07/30 09:26:44 Done.
56 } 54 }
57 55
58 public UrlInputDialog(final Context context, final Type type, final UrlReadyCa llback callback) 56 public UrlInputDialog(final Context context, final Type type, final UrlReadyCa llback callback)
59 { 57 {
60 super(context); 58 super(context);
61 this.type = type; 59 this.type = type;
62 this.callback = callback; 60 this.callback = callback;
63 } 61 }
64 62
65 @Override 63 @Override
(...skipping 15 matching lines...) Expand all
81 this.button.setOnClickListener(this); 79 this.button.setOnClickListener(this);
82 80
83 if (this.currentEditTextValue != null) 81 if (this.currentEditTextValue != null)
84 { 82 {
85 this.editText.setText(this.currentEditTextValue); 83 this.editText.setText(this.currentEditTextValue);
86 } 84 }
87 this.updateButtonState(); 85 this.updateButtonState();
88 86
89 switch (this.type) 87 switch (this.type)
90 { 88 {
91 case ADD_BLOCKING_LIST: 89 case ADD_SUBSCRIPTION:
92 this.button.setText(R.string.abb_block_list_button); 90 this.button.setText(R.string.abb_add_subscription_button);
93 this.editText.setHint(R.string.abb_block_list_url); 91 this.editText.setHint(R.string.abb_add_subscription_url);
94 this.setTitle(R.string.abb_pref_category_add_other_list); 92 this.setTitle(R.string.abb_pref_category_add_other_list);
95 break; 93 break;
96 default: 94 default:
97 break; 95 break;
98 } 96 }
99 } 97 }
100 98
101 private void updateButtonState() 99 private void updateButtonState()
102 { 100 {
103 this.button.setEnabled(this.submitEnabled); 101 this.button.setEnabled(this.submitEnabled);
104 this.button.setBackgroundColor(this.submitEnabled 102 this.button.setBackgroundColor(this.submitEnabled
105 ? BUTTON_ENABLED_COLOR 103 ? this.getContext().getResources().getColor(R.color.abb_url_input_button _enabled)
106 : BUTTON_DISABLED_COLOR); 104 : this.getContext().getResources().getColor(R.color.abb_url_input_button _disabled));
107 this.button.invalidate(); 105 this.button.invalidate();
108 } 106 }
109 107
110 @Override 108 @Override
111 public void afterTextChanged(final Editable s) 109 public void afterTextChanged(final Editable s)
112 { 110 {
113 this.currentEditTextValue = s.toString(); 111 this.currentEditTextValue = s.toString();
114 this.submitEnabled = this.validateUrl(this.currentEditTextValue) != null; 112 this.submitEnabled = this.validateUrl(this.currentEditTextValue) != null;
115 if (this.submitEnabled) 113 if (this.submitEnabled)
116 { 114 {
(...skipping 19 matching lines...) Expand all
136 // ignored 134 // ignored
137 } 135 }
138 136
139 private String validateUrl(final String possibleUrl) 137 private String validateUrl(final String possibleUrl)
140 { 138 {
141 String url = possibleUrl.trim(); 139 String url = possibleUrl.trim();
142 if (Patterns.WEB_URL.matcher(url).matches()) 140 if (Patterns.WEB_URL.matcher(url).matches())
143 { 141 {
144 return url; 142 return url;
145 } 143 }
146 url = "http://" + url; 144 url = "http://" + url;
Felix Dahlke 2015/07/26 17:06:22 IMHO we should just consider URLs without the prot
René Jeschke 2015/07/28 10:55:26 Do you really want to force all Android users, to
Felix Dahlke 2015/07/29 20:32:07 Hm, fair enough with the typing... Maybe it'd be s
147 if (Patterns.WEB_URL.matcher(url).matches()) 145 if (Patterns.WEB_URL.matcher(url).matches())
148 { 146 {
149 return url; 147 return url;
150 } 148 }
151 return null; 149 return null;
152 } 150 }
153 151
154 private void validateAndSubmit(final String inputText) 152 private void validateAndSubmit(final String inputText)
155 { 153 {
156 final String url = this.validateUrl(inputText); 154 final String url = this.validateUrl(inputText);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
188 186
189 @Override 187 @Override
190 public void onClick(final View v) 188 public void onClick(final View v)
191 { 189 {
192 if (this.currentEditTextValue != null) 190 if (this.currentEditTextValue != null)
193 { 191 {
194 this.validateAndSubmit(this.currentEditTextValue); 192 this.validateAndSubmit(this.currentEditTextValue);
195 } 193 }
196 } 194 }
197 } 195 }
LEFTRIGHT

Powered by Google App Engine
This is Rietveld