From 8203400101578e5a4fd8ac45df9834534a14f873 Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 26 Apr 2023 09:51:44 +0530 Subject: [PATCH 1/5] resurvey drop-down --- src/main/java/de/blau/android/osm/Server.java | 20 +++- .../validation/ValidatorRulesDatabase.java | 39 ++++-- .../ValidatorRulesDatabaseHelper.java | 29 +++-- .../android/validation/ValidatorRulesUI.java | 111 ++++++++++++++++-- .../res/layout/validator_ruleset_list.xml | 8 ++ .../validator_ruleset_list_resurvey_item.xml | 9 ++ .../validator_ruleset_resurvey_item.xml | 38 ++++-- .../validation/VlaidatorRulesUITest.java | 5 + 8 files changed, 213 insertions(+), 46 deletions(-) create mode 100644 src/test/java/de/blau/android/validation/VlaidatorRulesUITest.java diff --git a/src/main/java/de/blau/android/osm/Server.java b/src/main/java/de/blau/android/osm/Server.java index 94dfe90969..53eb6b3c03 100644 --- a/src/main/java/de/blau/android/osm/Server.java +++ b/src/main/java/de/blau/android/osm/Server.java @@ -38,6 +38,7 @@ import de.blau.android.App; import de.blau.android.Authorize; import de.blau.android.ErrorCodes; +import de.blau.android.Logic; import de.blau.android.PostAsyncActionHandler; import de.blau.android.R; import de.blau.android.contract.MimeTypes; @@ -54,6 +55,7 @@ import de.blau.android.tasks.Note; import de.blau.android.tasks.NoteComment; import de.blau.android.util.BasicAuthInterceptor; +import de.blau.android.util.ExecutorTask; import de.blau.android.util.Snack; import okhttp3.Call; import okhttp3.MediaType; @@ -679,7 +681,19 @@ public static InputStream openConnection(@Nullable final Context context, @NonNu // } OkHttpClient client = builder.build(); Call readCall = client.newCall(request); - Response readCallResponse = readCall.execute(); + Logic logic = App.getLogic(); + ExecutorTask loader = new ExecutorTask(logic.getExecutorService(), + logic.getHandler()) { + @Override + protected Response doInBackground(Call readCall) throws Exception { + return readCall.execute(); + } + protected void onPostExecute(Response result) { + Log.d(DEBUG_TAG, "onPostExecute"); + } + }; + loader.execute(readCall); + Response readCallResponse = loader.get(); if (readCallResponse.isSuccessful()) { ResponseBody responseBody = readCallResponse.body(); return responseBody.byteStream(); @@ -696,8 +710,8 @@ public static InputStream openConnection(@Nullable final Context context, @NonNu } throwOsmServerException(readCallResponse); } - } catch (IllegalArgumentException iaex) { - throw new IOException("Illegal argument", iaex); + } catch (Exception tr) { + tr.printStackTrace(); } throw new IOException("openCOnnection this can't happen"); // this is actually unreachable } diff --git a/src/main/java/de/blau/android/validation/ValidatorRulesDatabase.java b/src/main/java/de/blau/android/validation/ValidatorRulesDatabase.java index 722fccdbc8..e480995de8 100644 --- a/src/main/java/de/blau/android/validation/ValidatorRulesDatabase.java +++ b/src/main/java/de/blau/android/validation/ValidatorRulesDatabase.java @@ -19,7 +19,7 @@ public final class ValidatorRulesDatabase { /** * Table: rulesets (id INTEGER, name TEXT) Table: resurvey (ruleset INTEGER, key TEXT, value TEXT DEFAULT NULL, days - * INTEGER DEFAULT 365, FOREIGN KEY(ruleset) REFERENCES rulesets(id)) Table: check (ruleset INTEGER, key TEXT, + * INTEGER DEFAULT 365, selected INTEGER DEFAULT 1, FOREIGN KEY(ruleset) REFERENCES rulesets(id)) Table: check (ruleset INTEGER, key TEXT, * optional INTEGER DEFAULT 0, FOREIGN KEY(ruleset) REFERENCES rulesets(id)) */ @@ -36,11 +36,12 @@ public final class ValidatorRulesDatabase { static final String RULESET_FIELD = "ruleset"; private static final String CHECK_TABLE = "checktags"; static final String OPTIONAL_FIELD = "optional"; + static final String SELECTED_FIELD = "selected"; - static final String QUERY_RESURVEY_DEFAULT = "SELECT resurveytags.rowid as _id, key, value, is_regexp, days FROM resurveytags WHERE ruleset = " + static final String QUERY_RESURVEY_DEFAULT = "SELECT resurveytags.rowid as _id, key, value, is_regexp, days, selected FROM resurveytags WHERE ruleset = " + DEFAULT_RULESET + " ORDER BY key, value"; - static final String QUERY_RESURVEY_BY_ROWID = "SELECT key, value, is_regexp, days FROM resurveytags WHERE rowid=?"; - static final String QUERY_RESURVEY_BY_NAME = "SELECT resurveytags.rowid as _id, key, value, is_regexp, days FROM resurveytags, rulesets WHERE ruleset = rulesets.id and rulesets.name = ? ORDER BY key, value"; + static final String QUERY_RESURVEY_BY_ROWID = "SELECT key, value, is_regexp, days, selected FROM resurveytags WHERE rowid=?"; + static final String QUERY_RESURVEY_BY_NAME = "SELECT resurveytags.rowid as _id, key, value, is_regexp, days, selected FROM resurveytags, rulesets WHERE ruleset = rulesets.id and rulesets.name = ? ORDER BY key, value"; static final String QUERY_CHECK_DEFAULT = "SELECT checktags.rowid as _id, key, optional FROM checktags WHERE ruleset = " + DEFAULT_RULESET + " ORDER BY key"; @@ -77,18 +78,20 @@ public static void addRuleset(SQLiteDatabase db, int id, String name) { @Nullable public static MultiHashMap getDefaultResurvey(@NonNull SQLiteDatabase database) { MultiHashMap result = null; - Cursor dbresult = database.query(RESURVEY_TABLE, new String[] { KEY_FIELD, VALUE_FIELD, ISREGEXP_FIELD, DAYS_FIELD }, + Cursor dbresult = database.query(RESURVEY_TABLE, new String[] { KEY_FIELD, VALUE_FIELD, ISREGEXP_FIELD, DAYS_FIELD, SELECTED_FIELD }, RULESET_FIELD + " = " + DEFAULT_RULESET, null, null, null, KEY_FIELD + "," + VALUE_FIELD); if (dbresult.getCount() >= 1) { result = new MultiHashMap<>(); boolean haveEntry = dbresult.moveToFirst(); while (haveEntry) { - PatternAndAge v = new PatternAndAge(); - v.setValue(dbresult.getString(1)); - v.setIsRegexp(dbresult.getInt(2) == 1); - v.setAge(dbresult.getLong(3) * 24 * 3600); // days -> secs - result.add(dbresult.getString(0), v); + if (dbresult.getInt(dbresult.getColumnIndexOrThrow(ValidatorRulesDatabase.SELECTED_FIELD)) == 1){ + PatternAndAge v = new PatternAndAge(); + v.setValue(dbresult.getString(1)); + v.setIsRegexp(dbresult.getInt(2) == 1); + v.setAge(dbresult.getLong(3) * 24 * 3600); // days -> secs + result.add(dbresult.getString(0), v); + } haveEntry = dbresult.moveToNext(); } } @@ -121,13 +124,14 @@ public static Cursor queryResurveyByName(@NonNull SQLiteDatabase database, @Null * @param isRegexp if true the value is a regexp * @param days how man days old the object should max be */ - public static void addResurvey(@NonNull SQLiteDatabase db, int ruleSetId, @NonNull String key, @Nullable String value, boolean isRegexp, int days) { + public static void addResurvey(@NonNull SQLiteDatabase db, int ruleSetId, @NonNull String key, @Nullable String value, boolean isRegexp, int days, boolean selected) { ContentValues values = new ContentValues(); values.put(RULESET_FIELD, ruleSetId); values.put(KEY_FIELD, key); values.put(VALUE_FIELD, value); values.put(ISREGEXP_FIELD, isRegexp ? 1 : 0); values.put(DAYS_FIELD, days); + values.put(SELECTED_FIELD, selected ? 1 : 0); db.insert(RESURVEY_TABLE, null, values); } @@ -160,6 +164,19 @@ static void deleteResurvey(final SQLiteDatabase db, final int id) { db.delete(RESURVEY_TABLE, "rowid=?", new String[] { Integer.toString(id) }); } + /** + * Change the selected row of the resurvey table. + * + * @param db writable database + * @param id rowid of the entry + * @param isChecked state of the checkbox + */ + public static void resurveySelected(SQLiteDatabase db, int id, boolean isChecked) { + ContentValues values = new ContentValues(); + values.put(SELECTED_FIELD, isChecked ? 1 : 0); + db.update(RESURVEY_TABLE, values, "rowid=" + id, null); + } + /** * Return the default resurvey entries if any * diff --git a/src/main/java/de/blau/android/validation/ValidatorRulesDatabaseHelper.java b/src/main/java/de/blau/android/validation/ValidatorRulesDatabaseHelper.java index 439b00f92b..525ef403ac 100644 --- a/src/main/java/de/blau/android/validation/ValidatorRulesDatabaseHelper.java +++ b/src/main/java/de/blau/android/validation/ValidatorRulesDatabaseHelper.java @@ -12,7 +12,7 @@ public class ValidatorRulesDatabaseHelper extends SQLiteOpenHelper { private static final String DEBUG_TAG = "ValidatorRulesDatab..."; private static final String DATABASE_NAME = "validator_rules"; - private static final int DATABASE_VERSION = 3; + private static final int DATABASE_VERSION = 4; static final int ONE_YEAR = 365; /** @@ -31,18 +31,18 @@ public void onCreate(SQLiteDatabase db) { ValidatorRulesDatabase.addRuleset(db, ValidatorRulesDatabase.DEFAULT_RULESET, ValidatorRulesDatabase.DEFAULT_RULESET_NAME); db.execSQL( - "CREATE TABLE resurveytags (ruleset INTEGER, key TEXT, value TEXT DEFAULT NULL, is_regexp INTEGER DEFAULT 0, days INTEGER DEFAULT 365, FOREIGN KEY(ruleset) REFERENCES rulesets(id))"); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_SHOP, null, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_RESTAURANT, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_FAST_FOOD, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_CAFE, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_PUB, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_BAR, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_TOILETS, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_LANDUSE, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_HIGHWAY, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_RAILWAY, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR); - ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_BUILDING, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR); + "CREATE TABLE resurveytags (ruleset INTEGER, key TEXT, value TEXT DEFAULT NULL, is_regexp INTEGER DEFAULT 0, days INTEGER DEFAULT 365, selected INTEGER DEFAULT 1, FOREIGN KEY(ruleset) REFERENCES rulesets(id))"); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_SHOP, null, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_RESTAURANT, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_FAST_FOOD, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_CAFE, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_PUB, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_BAR, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_AMENITY, Tags.VALUE_TOILETS, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_LANDUSE, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_HIGHWAY, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_RAILWAY, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR, true); + ValidatorRulesDatabase.addResurvey(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_BUILDING, Tags.VALUE_CONSTRUCTION, false, ONE_YEAR, true); db.execSQL("CREATE TABLE checktags (ruleset INTEGER, key TEXT, optional INTEGER DEFAULT 0, FOREIGN KEY(ruleset) REFERENCES rulesets(id))"); ValidatorRulesDatabase.addCheck(db, ValidatorRulesDatabase.DEFAULT_RULESET, Tags.KEY_OPENING_HOURS, false); @@ -59,6 +59,9 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { if (oldVersion <= 1 && newVersion >= 2) { db.execSQL("ALTER TABLE resurveytags ADD COLUMN is_regexp INTEGER DEFAULT 0"); } + if (oldVersion <= 3 && newVersion >= 4) { + db.execSQL("ALTER TABLE resurveytags ADD COLUMN selected INTEGER DEFAULT 1"); + } if (oldVersion <= 2 && newVersion >= 3) { db.execSQL("UPDATE checktags SET key='name|ref' WHERE key='name'"); } diff --git a/src/main/java/de/blau/android/validation/ValidatorRulesUI.java b/src/main/java/de/blau/android/validation/ValidatorRulesUI.java index a741c9dc93..926d4ce7d4 100644 --- a/src/main/java/de/blau/android/validation/ValidatorRulesUI.java +++ b/src/main/java/de/blau/android/validation/ValidatorRulesUI.java @@ -1,7 +1,7 @@ package de.blau.android.validation; import com.google.android.material.floatingactionbutton.FloatingActionButton; - +import static de.blau.android.osm.Tags.IMPORTANT_TAGS; import android.content.Context; import android.database.Cursor; import android.database.sqlite.SQLiteDatabase; @@ -10,6 +10,9 @@ import android.view.MenuItem; import android.view.View; import android.view.ViewGroup; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.AutoCompleteTextView; import android.widget.CheckBox; import android.widget.EditText; import android.widget.ImageView; @@ -20,11 +23,16 @@ import androidx.appcompat.widget.PopupMenu; import androidx.cursoradapter.widget.CursorAdapter; import androidx.viewpager.widget.PagerTabStrip; +import java.util.ArrayList; +import java.util.Collections; +import java.util.List; import ch.poole.android.numberpicker.library.NumberPicker; import de.blau.android.App; import de.blau.android.R; import de.blau.android.dialogs.ViewPagerAdapter; import de.blau.android.filter.Filter; +import de.blau.android.presets.Preset; +import de.blau.android.util.StringWithDescription; import de.blau.android.util.ThemeUtils; import de.blau.android.views.ExtendedViewPager; @@ -67,6 +75,27 @@ public void manageRulesetContents(@NonNull final Context context) { Cursor checkCursor = ValidatorRulesDatabase.queryCheckByName(writableDb, ValidatorRulesDatabase.DEFAULT_RULESET_NAME); checkAdapter = new CheckAdapter(writableDb, context, checkCursor); checkList.setAdapter(checkAdapter); + CheckBox headerSelected = (CheckBox) rulesetView.findViewById(R.id.header_selected); + headerSelected.setOnClickListener(new View.OnClickListener() { + public void onClick(View v) { + boolean isChecked = ((CheckBox) v).isChecked(); + Cursor newCursor = resurveyCursor; + newCursor.moveToFirst(); + int i = 0; + do{ + if (i < resurveyList.getChildCount()) { + View childView = resurveyList.getChildAt(i); + Log.d(DEBUG_TAG, "---bindView childView == " + i); + CheckBox checkBox = (CheckBox) childView.findViewById(R.id.resurvey_selected); + checkBox.setChecked(isChecked); + } + int id = newCursor.getInt(resurveyCursor.getColumnIndexOrThrow("_id")); + ValidatorRulesDatabase.resurveySelected(writableDb, id, isChecked); + Log.d(DEBUG_TAG, "---bindView id ==" + id); + i++; + }while (newCursor.moveToNext()); + } + }); alertDialog.setNeutralButton(R.string.done, null); alertDialog.setOnDismissListener(dialog -> { resurveyCursor.close(); @@ -129,6 +158,17 @@ public void bindView(final View view, final Context context, Cursor cursor) { keyView.setText(key); TextView daysView = (TextView) view.findViewById(R.id.days); daysView.setText(Integer.toString(days)); + CheckBox selected = (CheckBox) view.findViewById(R.id.resurvey_selected); + Cursor newCursor = db.rawQuery(ValidatorRulesDatabase.QUERY_RESURVEY_BY_ROWID, new String[] { Integer.toString(id) }); + newCursor.moveToFirst(); + boolean isSelected = newCursor.getInt(newCursor.getColumnIndexOrThrow(ValidatorRulesDatabase.SELECTED_FIELD)) == 1; + selected.setChecked(isSelected); + newCursor.close(); + selected.setOnClickListener((v) -> { + boolean isChecked = selected.isChecked(); + ValidatorRulesDatabase.resurveySelected(db, id, isChecked); + selected.setChecked(isChecked); + }); view.setOnClickListener(v -> { Integer tag = (Integer) view.getTag(); showResurveyDialog(context, db, true, tag != null ? tag : -1); @@ -160,11 +200,12 @@ private void showResurveyDialog(@NonNull final Context context, @NonNull final S AlertDialog.Builder alertDialog = new AlertDialog.Builder(context); View templateView = LayoutInflater.from(context).inflate(R.layout.validator_ruleset_resurvey_item, null); alertDialog.setView(templateView); - - final EditText keyEdit = (EditText) templateView.findViewById(R.id.resurvey_key); - final EditText valueEdit = (EditText) templateView.findViewById(R.id.resurvey_value); + final AutoCompleteTextView keyEdit = (AutoCompleteTextView) templateView.findViewById(R.id.resurvey_key); + final AutoCompleteTextView valueEdit = (AutoCompleteTextView) templateView.findViewById(R.id.resurvey_value); final CheckBox regexpCheck = (CheckBox) templateView.findViewById(R.id.resurvey_is_regexp); final NumberPicker daysPicker = (NumberPicker) templateView.findViewById(R.id.resurvey_days); + List matchingKeys = new ArrayList<>(); + List matchingValues = new ArrayList<>(); if (existing) { Cursor cursor = db.rawQuery(ValidatorRulesDatabase.QUERY_RESURVEY_BY_ROWID, new String[] { Integer.toString(id) }); if (cursor.moveToFirst()) { @@ -192,14 +233,68 @@ private void showResurveyDialog(@NonNull final Context context, @NonNull final S alertDialog.setTitle(R.string.add_resurvey_title); daysPicker.setValue(ValidatorRulesDatabaseHelper.ONE_YEAR); } + Preset[] presets = App.getCurrentPresets(context); + matchingKeys.addAll(IMPORTANT_TAGS); //object-keys + if (matchingKeys.contains(keyEdit)) { + matchingKeys.remove(keyEdit); + } + Collections.sort(matchingKeys); + ArrayAdapter empty = new ArrayAdapter<>(context, R.layout.autocomplete_row, new String[0]); + keyEdit.setAdapter(empty); + valueEdit.setAdapter(empty); + View.OnClickListener autocompleteOnClick = v -> { + if (v.hasFocus()) { + ((AutoCompleteTextView) v).showDropDown(); + } + }; + keyEdit.setOnClickListener(autocompleteOnClick); + valueEdit.setOnClickListener(autocompleteOnClick); + keyEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + if (hasFocus) { + keyEdit.setAdapter(new ArrayAdapter<>(context, R.layout.autocomplete_row, matchingKeys)); + } + } + }); + keyEdit.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String selectedKey = parent.getItemAtPosition(position).toString(); + keyEdit.setText(selectedKey); + } + }); + valueEdit.setOnFocusChangeListener(new View.OnFocusChangeListener() { + @Override + public void onFocusChange(View v, boolean hasFocus) { + Log.d(DEBUG_TAG, "onFocusChange value"); + if (hasFocus) { + matchingValues.clear(); + for (StringWithDescription s : Preset.getAutocompleteValues(presets, null, keyEdit.getText().toString().trim())) { + String values = s.getValue(); + if (!matchingValues.contains(values)) { + matchingValues.add(values); + } + } + Collections.sort(matchingValues); + valueEdit.setAdapter(new ArrayAdapter<>(context, R.layout.autocomplete_row, matchingValues)); + } + } + }); + valueEdit.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView parent, View view, int position, long id) { + String selectedKey = parent.getItemAtPosition(position).toString(); + valueEdit.setText(selectedKey); + } + }); alertDialog.setNegativeButton(R.string.cancel, null); - alertDialog.setPositiveButton(R.string.save, (dialog, which) -> { if (!existing) { - ValidatorRulesDatabase.addResurvey(db, 0, keyEdit.getText().toString(), valueEdit.getText().toString(), regexpCheck.isChecked(), - daysPicker.getValue()); + ValidatorRulesDatabase.addResurvey(db, 0, keyEdit.getText().toString().trim(), valueEdit.getText().toString().trim(), regexpCheck.isChecked(), + daysPicker.getValue(), true); } else { - ValidatorRulesDatabase.updateResurvey(db, id, keyEdit.getText().toString(), valueEdit.getText().toString(), regexpCheck.isChecked(), + ValidatorRulesDatabase.updateResurvey(db, id, keyEdit.getText().toString().trim(), valueEdit.getText().toString().trim(), regexpCheck.isChecked(), daysPicker.getValue()); } newResurveyCursor(db); diff --git a/src/main/res/layout/validator_ruleset_list.xml b/src/main/res/layout/validator_ruleset_list.xml index 1da489a9cb..acf0066e77 100644 --- a/src/main/res/layout/validator_ruleset_list.xml +++ b/src/main/res/layout/validator_ruleset_list.xml @@ -32,6 +32,14 @@ android:layout_marginTop="5dp" android:layout_marginBottom="1dp" android:orientation="horizontal"> + + + @@ -14,18 +15,20 @@ android:layout_alignParentTop="true" android:textAppearance="?android:attr/textAppearanceMedium" android:text="@string/Key"/> - - - + android:layout_marginEnd="?attr/dialogPreferredPadding" + android:layout_marginRight="?attr/dialogPreferredPadding" + android:completionThreshold="1" + android:dropDownWidth="wrap_content" + android:dropDownHeight="300dp" + android:inputType="textNoSuggestions" + android:saveEnabled="false" /> - - + Date: Wed, 26 Apr 2023 13:32:25 +0530 Subject: [PATCH 2/5] rollback server changes --- src/main/java/de/blau/android/osm/Server.java | 18 +++--------------- 1 file changed, 3 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/blau/android/osm/Server.java b/src/main/java/de/blau/android/osm/Server.java index 53eb6b3c03..06b8d44c5b 100644 --- a/src/main/java/de/blau/android/osm/Server.java +++ b/src/main/java/de/blau/android/osm/Server.java @@ -681,19 +681,7 @@ public static InputStream openConnection(@Nullable final Context context, @NonNu // } OkHttpClient client = builder.build(); Call readCall = client.newCall(request); - Logic logic = App.getLogic(); - ExecutorTask loader = new ExecutorTask(logic.getExecutorService(), - logic.getHandler()) { - @Override - protected Response doInBackground(Call readCall) throws Exception { - return readCall.execute(); - } - protected void onPostExecute(Response result) { - Log.d(DEBUG_TAG, "onPostExecute"); - } - }; - loader.execute(readCall); - Response readCallResponse = loader.get(); + Response readCallResponse = readCall.execute(); if (readCallResponse.isSuccessful()) { ResponseBody responseBody = readCallResponse.body(); return responseBody.byteStream(); @@ -710,8 +698,8 @@ protected void onPostExecute(Response result) { } throwOsmServerException(readCallResponse); } - } catch (Exception tr) { - tr.printStackTrace(); + } catch (IllegalArgumentException iaex) { + throw new IOException("Illegal argument", iaex); } throw new IOException("openCOnnection this can't happen"); // this is actually unreachable } From 61b766839ead93e835010809763b4dfe35688d27 Mon Sep 17 00:00:00 2001 From: Aryan Date: Wed, 26 Apr 2023 13:33:29 +0530 Subject: [PATCH 3/5] rollback server changes --- src/main/java/de/blau/android/osm/Server.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/de/blau/android/osm/Server.java b/src/main/java/de/blau/android/osm/Server.java index 06b8d44c5b..94dfe90969 100644 --- a/src/main/java/de/blau/android/osm/Server.java +++ b/src/main/java/de/blau/android/osm/Server.java @@ -38,7 +38,6 @@ import de.blau.android.App; import de.blau.android.Authorize; import de.blau.android.ErrorCodes; -import de.blau.android.Logic; import de.blau.android.PostAsyncActionHandler; import de.blau.android.R; import de.blau.android.contract.MimeTypes; @@ -55,7 +54,6 @@ import de.blau.android.tasks.Note; import de.blau.android.tasks.NoteComment; import de.blau.android.util.BasicAuthInterceptor; -import de.blau.android.util.ExecutorTask; import de.blau.android.util.Snack; import okhttp3.Call; import okhttp3.MediaType; From e33923c215ed79d7252bac4bf1669a9a748cf330 Mon Sep 17 00:00:00 2001 From: Aryan Date: Tue, 20 Jun 2023 21:32:43 +0530 Subject: [PATCH 4/5] rollback server changes --- .../Validation/ValidatorRulesUITest.java | 141 ++++++++++++++++++ .../validation/VlaidatorRulesUITest.java | 5 - 2 files changed, 141 insertions(+), 5 deletions(-) create mode 100644 src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java delete mode 100644 src/test/java/de/blau/android/validation/VlaidatorRulesUITest.java diff --git a/src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java b/src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java new file mode 100644 index 0000000000..9bc0b0ca02 --- /dev/null +++ b/src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java @@ -0,0 +1,141 @@ +package de.blau.android.Validation; + + +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + +import android.app.Activity; +import android.app.Instrumentation; +import android.content.ContentValues; +import android.content.Context; +import android.database.sqlite.SQLiteDatabase; +import android.widget.CheckBox; + +import androidx.appcompat.app.AlertDialog; +import androidx.test.core.app.ApplicationProvider; +import androidx.test.ext.junit.runners.AndroidJUnit4; +import androidx.test.filters.LargeTest; +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.rule.ActivityTestRule; +import androidx.test.uiautomator.UiDevice; + +import org.junit.After; +import org.junit.Before; +import org.junit.Rule; +import org.junit.Test; +import org.junit.runner.RunWith; + +import de.blau.android.LayerUtils; +import de.blau.android.Main; +import de.blau.android.Map; +import de.blau.android.R; +import de.blau.android.TestUtils; +import de.blau.android.filter.PresetFilterActivity; +import de.blau.android.osm.Tags; +import de.blau.android.prefs.Preferences; +import de.blau.android.validation.ValidatorRulesDatabase; +import de.blau.android.validation.ValidatorRulesDatabaseHelper; +import de.blau.android.validation.ValidatorRulesUI; + +@RunWith(AndroidJUnit4.class) +@LargeTest +public class ValidatorRulesUITest { + + private Context context = null; + private Instrumentation.ActivityMonitor monitor = null; + private Instrumentation instrumentation = null; + private UiDevice device = null; + private Main main = null; + private Map map = null; + private ValidatorRulesUI validatorRulesUI; + private SQLiteDatabase testDb; + + @Rule + public ActivityTestRule
mActivityRule = new ActivityTestRule<>(Main.class); + + /** + * Pre-test setup + */ + @Before + public void setup() { + instrumentation = InstrumentationRegistry.getInstrumentation(); + device = UiDevice.getInstance(instrumentation); + context = instrumentation.getTargetContext(); + monitor = instrumentation.addMonitor(ValidatorRulesUI.class.getName(), null, false); + main = mActivityRule.getActivity(); + Preferences prefs = new Preferences(context); + LayerUtils.removeImageryLayers(context); + map = main.getMap(); + map.setPrefs(main, prefs); + + TestUtils.grantPermissons(device); + TestUtils.dismissStartUpDialogs(device, main); + TestUtils.stopEasyEdit(main); + TestUtils.loadTestData(main, "test2.osm"); +// solo = new Solo(getInstrumentation(), getActivity()) + + testDb = SQLiteDatabase.create(null); + // Initialize the test database + initTestDatabase(testDb); + // Create a new instance of the ValidatorRulesDatabaseHelper with the test database + ValidatorRulesDatabaseHelper testDbHelper = new ValidatorRulesDatabaseHelper(context) { + @Override + public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { + // Do nothing to prevent upgrades during testing + } + }; + // Create a new instance of the ValidatorRulesUI with the test database helper + validatorRulesUI = new ValidatorRulesUI(testDbHelper); + } + /** + * Post-test teardown + */ + @After + public void cleanup() { + testDb.close(); + instrumentation.removeMonitor(monitor); + } + @Test + public void testManageRulesetContents() { + // Create and show the dialog + validatorRulesUI.manageRulesetContents(context); + +//// Use Robotium to interact with UI and click on checkboxes +// CheckBox headerSelectedCheckbox = (CheckBox) solo.getView(R.id.header_selected); +// solo.clickOnView(headerSelectedCheckbox); +// +// Dialog dialog = ShadowDialog.getLatestDialog(); +// assertNotNull(dialog); +// +// // Click on the checkbox +// CheckBox headerSelected = dialog.findViewById(R.id.header_selected); +// assertNotNull(headerSelected); +// headerSelected.performClick(); +// +// // Dismiss the dialog +// dialog.dismiss(); + } + + private void initTestDatabase(SQLiteDatabase db) { + // Recreate necessary tables and data for test database + db.execSQL("DROP TABLE IF EXISTS rulesets"); + db.execSQL("CREATE TABLE rulesets (id INTEGER, name TEXT)"); + ValidatorRulesDatabase.addRuleset(db, 0, "Default"); + + db.execSQL("DROP TABLE IF EXISTS resurveytags"); + db.execSQL( + "CREATE TABLE resurveytags (ruleset INTEGER, key TEXT, value TEXT DEFAULT NULL, is_regexp INTEGER DEFAULT 0, days INTEGER DEFAULT 365, selected INTEGER DEFAULT 1, FOREIGN KEY(ruleset) REFERENCES rulesets(id))"); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_SHOP, null, false, 365, true); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_RESTAURANT, false,365, true); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_FAST_FOOD, false, 365, true); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_CAFE, false, 365, true); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_PUB, false, 365, true); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_BAR, false, 365, true); + ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_TOILETS, false, 365, true); + } +} + + + + + diff --git a/src/test/java/de/blau/android/validation/VlaidatorRulesUITest.java b/src/test/java/de/blau/android/validation/VlaidatorRulesUITest.java deleted file mode 100644 index 12c3dccd80..0000000000 --- a/src/test/java/de/blau/android/validation/VlaidatorRulesUITest.java +++ /dev/null @@ -1,5 +0,0 @@ -package de.blau.android.validation; - -public class VlaidatorRulesUITest { - -} \ No newline at end of file From 7d341ab5df1b285d53d67a18df0bb5d216195b6c Mon Sep 17 00:00:00 2001 From: Aryan Date: Mon, 3 Jul 2023 00:05:08 +0530 Subject: [PATCH 5/5] deleted test --- .../Validation/ValidatorRulesUITest.java | 141 ------------------ 1 file changed, 141 deletions(-) delete mode 100644 src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java diff --git a/src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java b/src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java deleted file mode 100644 index 9bc0b0ca02..0000000000 --- a/src/androidTest/java/de/blau/android/Validation/ValidatorRulesUITest.java +++ /dev/null @@ -1,141 +0,0 @@ -package de.blau.android.Validation; - - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import android.app.Activity; -import android.app.Instrumentation; -import android.content.ContentValues; -import android.content.Context; -import android.database.sqlite.SQLiteDatabase; -import android.widget.CheckBox; - -import androidx.appcompat.app.AlertDialog; -import androidx.test.core.app.ApplicationProvider; -import androidx.test.ext.junit.runners.AndroidJUnit4; -import androidx.test.filters.LargeTest; -import androidx.test.platform.app.InstrumentationRegistry; -import androidx.test.rule.ActivityTestRule; -import androidx.test.uiautomator.UiDevice; - -import org.junit.After; -import org.junit.Before; -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import de.blau.android.LayerUtils; -import de.blau.android.Main; -import de.blau.android.Map; -import de.blau.android.R; -import de.blau.android.TestUtils; -import de.blau.android.filter.PresetFilterActivity; -import de.blau.android.osm.Tags; -import de.blau.android.prefs.Preferences; -import de.blau.android.validation.ValidatorRulesDatabase; -import de.blau.android.validation.ValidatorRulesDatabaseHelper; -import de.blau.android.validation.ValidatorRulesUI; - -@RunWith(AndroidJUnit4.class) -@LargeTest -public class ValidatorRulesUITest { - - private Context context = null; - private Instrumentation.ActivityMonitor monitor = null; - private Instrumentation instrumentation = null; - private UiDevice device = null; - private Main main = null; - private Map map = null; - private ValidatorRulesUI validatorRulesUI; - private SQLiteDatabase testDb; - - @Rule - public ActivityTestRule
mActivityRule = new ActivityTestRule<>(Main.class); - - /** - * Pre-test setup - */ - @Before - public void setup() { - instrumentation = InstrumentationRegistry.getInstrumentation(); - device = UiDevice.getInstance(instrumentation); - context = instrumentation.getTargetContext(); - monitor = instrumentation.addMonitor(ValidatorRulesUI.class.getName(), null, false); - main = mActivityRule.getActivity(); - Preferences prefs = new Preferences(context); - LayerUtils.removeImageryLayers(context); - map = main.getMap(); - map.setPrefs(main, prefs); - - TestUtils.grantPermissons(device); - TestUtils.dismissStartUpDialogs(device, main); - TestUtils.stopEasyEdit(main); - TestUtils.loadTestData(main, "test2.osm"); -// solo = new Solo(getInstrumentation(), getActivity()) - - testDb = SQLiteDatabase.create(null); - // Initialize the test database - initTestDatabase(testDb); - // Create a new instance of the ValidatorRulesDatabaseHelper with the test database - ValidatorRulesDatabaseHelper testDbHelper = new ValidatorRulesDatabaseHelper(context) { - @Override - public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) { - // Do nothing to prevent upgrades during testing - } - }; - // Create a new instance of the ValidatorRulesUI with the test database helper - validatorRulesUI = new ValidatorRulesUI(testDbHelper); - } - /** - * Post-test teardown - */ - @After - public void cleanup() { - testDb.close(); - instrumentation.removeMonitor(monitor); - } - @Test - public void testManageRulesetContents() { - // Create and show the dialog - validatorRulesUI.manageRulesetContents(context); - -//// Use Robotium to interact with UI and click on checkboxes -// CheckBox headerSelectedCheckbox = (CheckBox) solo.getView(R.id.header_selected); -// solo.clickOnView(headerSelectedCheckbox); -// -// Dialog dialog = ShadowDialog.getLatestDialog(); -// assertNotNull(dialog); -// -// // Click on the checkbox -// CheckBox headerSelected = dialog.findViewById(R.id.header_selected); -// assertNotNull(headerSelected); -// headerSelected.performClick(); -// -// // Dismiss the dialog -// dialog.dismiss(); - } - - private void initTestDatabase(SQLiteDatabase db) { - // Recreate necessary tables and data for test database - db.execSQL("DROP TABLE IF EXISTS rulesets"); - db.execSQL("CREATE TABLE rulesets (id INTEGER, name TEXT)"); - ValidatorRulesDatabase.addRuleset(db, 0, "Default"); - - db.execSQL("DROP TABLE IF EXISTS resurveytags"); - db.execSQL( - "CREATE TABLE resurveytags (ruleset INTEGER, key TEXT, value TEXT DEFAULT NULL, is_regexp INTEGER DEFAULT 0, days INTEGER DEFAULT 365, selected INTEGER DEFAULT 1, FOREIGN KEY(ruleset) REFERENCES rulesets(id))"); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_SHOP, null, false, 365, true); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_RESTAURANT, false,365, true); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_FAST_FOOD, false, 365, true); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_CAFE, false, 365, true); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_PUB, false, 365, true); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_BAR, false, 365, true); - ValidatorRulesDatabase.addResurvey(db, 0, Tags.KEY_AMENITY, Tags.VALUE_TOILETS, false, 365, true); - } -} - - - - -