|
6 | 6 | import android.app.Activity; |
7 | 7 | import android.app.ProgressDialog; |
8 | 8 | import android.content.Context; |
| 9 | +import android.content.DialogInterface; |
| 10 | +import android.content.SharedPreferences; |
9 | 11 | import android.content.res.Resources; |
10 | 12 | import android.support.v7.app.ActionBarActivity; |
11 | 13 | import android.support.v4.app.Fragment; |
12 | 14 | import android.support.v4.app.FragmentManager; |
13 | 15 | import android.support.v4.app.FragmentPagerAdapter; |
14 | 16 | import android.os.Bundle; |
15 | 17 | import android.support.v4.view.ViewPager; |
| 18 | +import android.support.v7.app.AlertDialog; |
| 19 | +import android.text.InputType; |
16 | 20 | import android.view.Menu; |
17 | 21 | import android.view.MenuItem; |
18 | 22 | import android.view.inputmethod.InputMethodManager; |
|
24 | 28 | public class TagSwipeActivity extends ActionBarActivity { |
25 | 29 |
|
26 | 30 | private List<TagEdit> tagEdits; |
| 31 | + private SharedPreferences userNamePref; |
27 | 32 |
|
28 | 33 |
|
29 | 34 | private void setupModel() { |
30 | 35 | tagEdits = TagEdit.buildTagEdits(); |
| 36 | + userNamePref = getSharedPreferences("org.redcross.openmapkit.USER_NAME", Context.MODE_PRIVATE); |
31 | 37 | } |
32 | 38 |
|
33 | 39 |
|
@@ -93,17 +99,49 @@ public boolean onOptionsItemSelected(MenuItem item) { |
93 | 99 | return super.onOptionsItemSelected(item); |
94 | 100 | } |
95 | 101 |
|
| 102 | + /** |
| 103 | + * We check to see if there is a saved user name. If there is not, |
| 104 | + * we present a dialog to ask for it. Otherwise, we just use what |
| 105 | + * is saved for writing OSM XML and saving to ODK Collect. |
| 106 | + */ |
96 | 107 | public void saveToODKCollect() { |
97 | | - TagEdit.saveToODKCollect(); |
98 | | - setResult(Activity.RESULT_OK); |
99 | | - finish(); |
| 108 | + String userName = userNamePref.getString("userName", null); |
| 109 | + if (userName == null) { |
| 110 | + askForOSMUsername(); |
| 111 | + } else { |
| 112 | + TagEdit.saveToODKCollect(userName); |
| 113 | + setResult(Activity.RESULT_OK); |
| 114 | + finish(); |
| 115 | + } |
100 | 116 | } |
101 | 117 |
|
102 | 118 | public void cancel() { |
103 | 119 | setResult(Activity.RESULT_CANCELED); |
104 | 120 | finish(); |
105 | 121 | } |
106 | | - |
| 122 | + |
| 123 | + private void askForOSMUsername() { |
| 124 | + AlertDialog.Builder builder = new AlertDialog.Builder(this); |
| 125 | + builder.setTitle("OpenStreetMap User Name"); |
| 126 | + builder.setMessage("Please enter your OpenStreetMap user name."); |
| 127 | + final EditText input = new EditText(this); |
| 128 | + input.setInputType(InputType.TYPE_CLASS_TEXT | InputType.TYPE_TEXT_FLAG_NO_SUGGESTIONS); |
| 129 | + builder.setView(input); |
| 130 | + builder.setPositiveButton("OK", new DialogInterface.OnClickListener() { |
| 131 | + @Override |
| 132 | + public void onClick(DialogInterface dialog, int which) { |
| 133 | + String userName = input.getText().toString(); |
| 134 | + SharedPreferences.Editor editor = userNamePref.edit(); |
| 135 | + editor.putString("userName", userName); |
| 136 | + editor.apply(); |
| 137 | + TagEdit.saveToODKCollect(userName); |
| 138 | + setResult(Activity.RESULT_OK); |
| 139 | + finish(); |
| 140 | + } |
| 141 | + }); |
| 142 | + builder.show(); |
| 143 | + } |
| 144 | + |
107 | 145 | /** |
108 | 146 | * A {@link FragmentPagerAdapter} that returns a fragment corresponding to |
109 | 147 | * one of the sections/tabs/pages. |
|
0 commit comments