Skip to content

Commit 3da2046

Browse files
committed
added setUseValueAsPrefillText() to EditTextSettingsObject
1 parent 0c155db commit 3da2046

File tree

4 files changed

+36
-5
lines changed

4 files changed

+36
-5
lines changed

.idea/inspectionProfiles/Project_Default.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,9 @@ A settings object that when clicked opens a dialog containing an `EditText`.
316316
**Optional features:**
317317
- `setHint(String hint)`
318318
- `setPrefillText(String prefillText)`
319+
- `setUseValueAsPrefillText()`
320+
If used, this will override `setSummary(String summary)`
321+
319322

320323
**Events:**
321324
- `EditTextSettingsNeutralButtonClickedEvent`

easysettings-dialogs/src/main/java/com/hotmail/or_dvir/easysettings_dialogs/pojos/EditTextSettingsObject.java

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import android.widget.TextView;
99
import com.afollestad.materialdialogs.MaterialDialog;
1010
import com.hotmail.or_dvir.easysettings.enums.ESettingsTypes;
11+
import com.hotmail.or_dvir.easysettings.pojos.SettingsObject;
1112
import com.hotmail.or_dvir.easysettings_dialogs.R;
1213
import com.hotmail.or_dvir.easysettings_dialogs.events.EditTextSettingsValueChangedEvent;
1314
import org.greenrobot.eventbus.EventBus;
@@ -22,12 +23,14 @@ public class EditTextSettingsObject extends DialogSettingsObject<EditTextSetting
2223
{
2324
private String hint;
2425
private String prefillText;
26+
private boolean useValueAsPrefillText;
2527

2628
private EditTextSettingsObject(Builder builder)
2729
{
2830
super(builder);
2931
this.hint = builder.hint;
3032
this.prefillText = builder.prefillText;
33+
this.useValueAsPrefillText = builder.useValueAsPrefillText;
3134

3235
//todo if you don't want to use the builder pattern,
3336
//todo you can also use a regular constructor
@@ -82,7 +85,6 @@ public void initializeViews(View root)
8285
//todo because we are using the R.layout.layout basic_settings_object,
8386
//todo we need to call the super method here to initialize the title and summary text views.
8487
//todo if you are making a completely custom layout here, no need to call the super method
85-
String test = getValue();
8688
super.initializeViews(root);
8789

8890
//todo optional initialization of the summary:
@@ -134,7 +136,12 @@ private void showDialog(View root)
134136
localHint = getHint();
135137
}
136138

137-
if(getPrefillText().isEmpty() == false)
139+
if(useValueAsPrefillText)
140+
{
141+
localPrefillText = getValueHumanReadable();
142+
}
143+
144+
else if(getPrefillText().isEmpty() == false)
138145
{
139146
localPrefillText = getPrefillText();
140147
}
@@ -179,6 +186,7 @@ public static class Builder extends DialogSettingsObject.Builder<Builder, String
179186
{
180187
private String hint = "";
181188
private String prefillText = "";
189+
private boolean useValueAsPrefillText = false;
182190

183191
/**
184192
*
@@ -235,6 +243,19 @@ public Builder setPrefillText(String prefillText)
235243
return this;
236244
}
237245

246+
/**
247+
* if this method is called, the value of this {@link EditTextSettingsObject}
248+
* will be used as the pre-fill text of the {@link android.widget.EditText} inside the dialog.
249+
* this method overrides the value set in {@link SettingsObject.Builder#setUseValueAsSummary()}
250+
* @return
251+
*/
252+
public Builder setUseValueAsPrefillText()
253+
{
254+
this.useValueAsPrefillText = true;
255+
return this;
256+
}
257+
258+
238259
@Override
239260
public EditTextSettingsObject build()
240261
{

sample/src/main/java/or_dvir/hotmail/com/ActivityMain.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ protected void onCreate(Bundle savedInstanceState)
5959

6060
SharedPreferences settingsSharedPrefs = EasySettings.retrieveSettingsSharedPrefs(this);
6161

62-
String editTextPrefill = settingsSharedPrefs.getString(SETTINGS_KEY_EDIT_TEXT, DEFAULT_VALUE_EDIT_TEXT);
63-
6462
//todo in the case of "ListSettingsObject",
6563
//todo the default object must be obtained using this method
6664
String listMultiChoiceDefaultItems =
@@ -116,7 +114,8 @@ protected void onCreate(Bundle savedInstanceState)
116114
.setDialogContent("enter new value here")
117115
.setDialogTitle("my dialog title")
118116
.setHint("i am a hint")
119-
.setPrefillText(editTextPrefill)
117+
.setPrefillText("pre-fill text")
118+
.setUseValueAsPrefillText() //todo overrides the value set above!
120119
.setIcon(null)
121120
.setNegativeBtnText("cancel")
122121
.setNeutralBtnText("neutral")

0 commit comments

Comments
 (0)