From 52dc427deeeb3c52ec301f9a3d70ee0f7d40b472 Mon Sep 17 00:00:00 2001 From: Gustl22 Date: Thu, 19 Dec 2019 21:31:26 +0100 Subject: [PATCH] Room / building synonyms integration (#21) --- .../java/de/lmu/navigator/DataConfig.java | 2 +- app/src/main/AndroidManifest.xml | 5 ++ app/src/main/assets/data/23_building_syn.json | 30 +++++++ app/src/main/assets/data/26_room_syn.json | 78 +++++++++++++++++++ .../navigator/app/AllBuildingsAdapter.java | 4 +- .../navigator/app/BuildingDetailActivity.java | 8 +- .../lmu/navigator/app/BuildingsAdapter.java | 3 +- .../lmu/navigator/app/FavoritesAdapter.java | 2 +- .../de/lmu/navigator/app/LaunchActivity.java | 11 +++ .../de/lmu/navigator/app/MainActivity.java | 42 +++++++++- .../lmu/navigator/database/ModelHelper.java | 60 +++++++++++++- .../database/RealmDatabaseManager.java | 4 + .../lmu/navigator/database/UpdateService.java | 34 +++++++- .../navigator/database/model/Building.java | 32 ++++++-- .../database/model/BuildingSynonym.java | 50 ++++++++++++ .../navigator/database/model/RealmLeaf.java | 22 ++++++ .../de/lmu/navigator/database/model/Room.java | 22 +++++- .../navigator/database/model/RoomSynonym.java | 50 ++++++++++++ .../navigator/database/model/Synonymable.java | 21 +++++ .../navigator/indoor/FloorViewActivity.java | 3 +- .../navigator/indoor/TileViewFragment.java | 4 +- .../de/lmu/navigator/map/BuildingItem.java | 4 +- .../lmu/navigator/map/ClusterMapFragment.java | 3 +- .../navigator/preferences/Preferences.java | 4 + .../preferences/SettingsActivity.java | 16 +++- .../navigator/search/AbsSearchActivity.java | 2 + .../navigator/search/SearchAllActivity.java | 40 ++++++++++ .../navigator/search/SearchRoomActivity.java | 2 + .../de/lmu/navigator/search/Searchable.java | 2 + .../navigator/search/SearchableWrapper.java | 18 ++++- app/src/main/res/values-de/strings.xml | 4 + app/src/main/res/values/strings.xml | 4 + app/src/main/res/xml/preferences.xml | 12 +++ 33 files changed, 567 insertions(+), 31 deletions(-) create mode 100644 app/src/main/assets/data/23_building_syn.json create mode 100644 app/src/main/assets/data/26_room_syn.json create mode 100644 app/src/main/java/de/lmu/navigator/database/model/BuildingSynonym.java create mode 100644 app/src/main/java/de/lmu/navigator/database/model/RealmLeaf.java create mode 100644 app/src/main/java/de/lmu/navigator/database/model/RoomSynonym.java create mode 100644 app/src/main/java/de/lmu/navigator/database/model/Synonymable.java create mode 100644 app/src/main/java/de/lmu/navigator/search/SearchAllActivity.java diff --git a/app/src/debug/java/de/lmu/navigator/DataConfig.java b/app/src/debug/java/de/lmu/navigator/DataConfig.java index 18c1e24..de54c74 100644 --- a/app/src/debug/java/de/lmu/navigator/DataConfig.java +++ b/app/src/debug/java/de/lmu/navigator/DataConfig.java @@ -4,7 +4,7 @@ public final class DataConfig { private DataConfig() { } - public final static int SHIPPED_DATA_VERSION = 3; + public final static int SHIPPED_DATA_VERSION = 4; // public static final String TILES_BASE_PATH = "http://lm00000-rfinder.srv.mwn.de/files/tiles/v3/"; // public static final String PHOTO_BASE_PATH = "http://lm00000-rfinder.srv.mwn.de/files/photos/"; diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index e1ca6ab..64a3c21 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -36,6 +36,11 @@ android:name=".app.BuildingDetailActivity" android:screenOrientation="portrait" android:theme="@style/AppTheme.TransparentActionBar"/> + + FLOOR_ORDER = Arrays.asList("UG2", "UG1", "EG", "ZG", "OG1", "ZG1", "OG2", "ZG2", "OG3", "OG4", "OG5", "OG6"); + /** + * Display name synonyms, if available. + */ + public static boolean displaySynonyms = true; + private ModelHelper() { } + /** + * If set, display all synonyms instead of the name. + */ + public static > String getName(T synonymable) { + if(displaySynonyms && synonymable.hasSynonyms()) { + return getSynonymsString(synonymable); + } + return synonymable.getName(); + } + + /** + * Only add format, if synonyms are disabled. + * + * @param format a format string + */ + public static String getName(Room room, String format) { + if(displaySynonyms && room.hasSynonyms()) { + return getSynonymsString(room); + } + return String.format(format, room.getName()); + } + + public static > String getDescription(T synonymable, String descSuffix) { + if(synonymable.hasSynonyms()) { + if(displaySynonyms) { + return synonymable.getName() + ", " + descSuffix; + } + return getSynonymsString(synonymable) + ", " + descSuffix; + } + return descSuffix; + } + + public static String getDescription(Building building) { + return getDescription(building, building.getStreet().getCity().getName()); + } + + public static String getDescription(Room room) { + return getDescription(room, room.getFloor().getName()); + } + + public static > String getSynonymsString(T synonymable){ + if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.N) { + return synonymable.getSynonyms().stream().map(RealmLeaf::getName).collect(Collectors.joining(", ")); + } + return synonymable.getSynonyms().get(0).getName(); + } + public static String getBuildingNameFixed(String name) { String formattedName = name .replace("STR.", "STRASSE") diff --git a/app/src/main/java/de/lmu/navigator/database/RealmDatabaseManager.java b/app/src/main/java/de/lmu/navigator/database/RealmDatabaseManager.java index 8e385ca..1bfde94 100644 --- a/app/src/main/java/de/lmu/navigator/database/RealmDatabaseManager.java +++ b/app/src/main/java/de/lmu/navigator/database/RealmDatabaseManager.java @@ -102,6 +102,10 @@ public List getRoomsForBuilding(Building b, boolean includeSameMap, boolea return rooms; } + public List getRoomsWithSynonym() { + return mRealm.where(Room.class).isNotEmpty(ModelHelper.SYNONYMS).findAll(); + } + private List getFloorsForBuilding(Building b) { return mRealm.where(Floor.class) .equalTo(ModelHelper.FLOOR_BUILDING_CODE, b.getCode()) diff --git a/app/src/main/java/de/lmu/navigator/database/UpdateService.java b/app/src/main/java/de/lmu/navigator/database/UpdateService.java index ba91021..daa0d3d 100644 --- a/app/src/main/java/de/lmu/navigator/database/UpdateService.java +++ b/app/src/main/java/de/lmu/navigator/database/UpdateService.java @@ -20,9 +20,11 @@ import de.lmu.navigator.DataConfig; import de.lmu.navigator.database.model.Building; import de.lmu.navigator.database.model.BuildingPart; +import de.lmu.navigator.database.model.BuildingSynonym; import de.lmu.navigator.database.model.City; import de.lmu.navigator.database.model.Floor; import de.lmu.navigator.database.model.Room; +import de.lmu.navigator.database.model.RoomSynonym; import de.lmu.navigator.database.model.Street; import de.lmu.navigator.preferences.Preferences; import io.realm.Realm; @@ -117,6 +119,16 @@ public boolean shouldSkipClass(Class clazz) { List rooms = gson.fromJson(reader, new TypeToken>() {}.getType()); reader.close(); + in = assetManager.open("data/23_building_syn.json"); + reader = new InputStreamReader(in); + List buildingSynonyms = gson.fromJson(reader, new TypeToken>() {}.getType()); + reader.close(); + + in = assetManager.open("data/26_room_syn.json"); + reader = new InputStreamReader(in); + List roomSynonyms = gson.fromJson(reader, new TypeToken>() {}.getType()); + reader.close(); + // Setup relationships Log.d(LOG_TAG, "Setup relationships..."); for (Street s : streets) { @@ -148,6 +160,15 @@ public boolean shouldSkipClass(Class clazz) { } } } + for (BuildingSynonym s : buildingSynonyms) { + for (Building b : buildings) { + if (b.getCode().equals(s.getParentId())) { + b.getSynonyms().add(s); + //s.setBuilding(b); + break; + } + } + } for (Floor f : floors) { fixFloor(f); for (BuildingPart p : buildingParts) { @@ -168,6 +189,15 @@ public boolean shouldSkipClass(Class clazz) { } } } + for (RoomSynonym s : roomSynonyms) { + for (Room r : rooms) { + if (r.getCode().equals(s.getParentId())) { + r.getSynonyms().add(s); + //s.setParent(r); + break; + } + } + } // Update database Log.d(LOG_TAG, "Update database..."); @@ -178,8 +208,10 @@ public boolean shouldSkipClass(Class clazz) { realm.where(Street.class).findAll().deleteAllFromRealm(); realm.where(Building.class).findAll().deleteAllFromRealm(); realm.where(BuildingPart.class).findAll().deleteAllFromRealm(); + realm.where(BuildingSynonym.class).findAll().deleteAllFromRealm(); realm.where(Floor.class).findAll().deleteAllFromRealm(); realm.where(Room.class).findAll().deleteAllFromRealm(); + realm.where(RoomSynonym.class).findAll().deleteAllFromRealm(); // Save new data // Inserting cities will insert all data due to relationships @@ -219,7 +251,7 @@ private void fixBuilding(Building b) { if (mFavorites.isEmpty() && b.getCode().equals("bw0000")) { b.setStarred(true); } - b.setDisplayName(ModelHelper.getBuildingNameFixed(b.getDisplayName())); + b.setName(ModelHelper.getBuildingNameFixed(b.getName())); } private void fixBuildingPart(BuildingPart p) { diff --git a/app/src/main/java/de/lmu/navigator/database/model/Building.java b/app/src/main/java/de/lmu/navigator/database/model/Building.java index d5c885d..c47063c 100644 --- a/app/src/main/java/de/lmu/navigator/database/model/Building.java +++ b/app/src/main/java/de/lmu/navigator/database/model/Building.java @@ -2,13 +2,15 @@ import com.google.gson.annotations.SerializedName; +import java.util.List; + import io.realm.RealmList; import io.realm.RealmObject; import io.realm.annotations.Ignore; import io.realm.annotations.PrimaryKey; import io.realm.annotations.Required; -public class Building extends RealmObject { +public class Building extends RealmObject implements Synonymable { @Required @PrimaryKey @@ -20,7 +22,8 @@ public class Building extends RealmObject { private String streetCode; @Required - private String displayName; + @SerializedName("displayName") + private String name; @SerializedName("lat") private double coordLat; @@ -32,6 +35,8 @@ public class Building extends RealmObject { private RealmList buildingParts = new RealmList<>(); + private RealmList synonyms = new RealmList<>(); + public RealmList getBuildingParts() { return buildingParts; } @@ -56,12 +61,13 @@ public void setStreet(Street street) { this.street = street; } - public String getDisplayName() { - return displayName; + @Override + public String getName() { + return name; } - public void setDisplayName(String displayName) { - this.displayName = displayName; + public void setName(String name) { + this.name = name; } public double getCoordLat() { @@ -95,4 +101,18 @@ public String getStreetCode() { public void setStreetCode(String streetCode) { this.streetCode = streetCode; } + + @Override + public List getSynonyms() { + return synonyms; + } + + @Override + public boolean hasSynonyms() { + return synonyms.size() > 0; + } + + public void setSynonyms(RealmList synonyms) { + this.synonyms = synonyms; + } } diff --git a/app/src/main/java/de/lmu/navigator/database/model/BuildingSynonym.java b/app/src/main/java/de/lmu/navigator/database/model/BuildingSynonym.java new file mode 100644 index 0000000..a5d8b95 --- /dev/null +++ b/app/src/main/java/de/lmu/navigator/database/model/BuildingSynonym.java @@ -0,0 +1,50 @@ +package de.lmu.navigator.database.model; + +import com.google.gson.annotations.SerializedName; + +import io.realm.RealmObject; +import io.realm.annotations.Ignore; +import io.realm.annotations.Required; + +public class BuildingSynonym extends RealmObject implements RealmLeaf { + + protected Building parent; + + @Ignore + @SerializedName("bCode") + protected String parentId; + + @Required + @SerializedName("syn") + protected String name; + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Building getParent() { + return parent; + } + + @Override + public void setParent(Building parent) { + this.parent = parent; + } + + @Override + public String getParentId() { + return parentId; + } + + @Override + public void setParentId(String parentId) { + this.parentId = parentId; + } +} diff --git a/app/src/main/java/de/lmu/navigator/database/model/RealmLeaf.java b/app/src/main/java/de/lmu/navigator/database/model/RealmLeaf.java new file mode 100644 index 0000000..906f918 --- /dev/null +++ b/app/src/main/java/de/lmu/navigator/database/model/RealmLeaf.java @@ -0,0 +1,22 @@ +package de.lmu.navigator.database.model; + +/** + * This interface specifies the last element in a Realm tree, as it only has a parent, but no child elements. + * TODO make to abstract class if polymorphism is supported: https://github.com/realm/realm-java/issues/761 + * + * @param the type of the parent element. + */ +public interface RealmLeaf { + + String getName(); + + void setName(String name); + + T getParent(); + + void setParent(T parent); + + String getParentId(); + + void setParentId(String parentId); +} diff --git a/app/src/main/java/de/lmu/navigator/database/model/Room.java b/app/src/main/java/de/lmu/navigator/database/model/Room.java index 7361c34..3747873 100644 --- a/app/src/main/java/de/lmu/navigator/database/model/Room.java +++ b/app/src/main/java/de/lmu/navigator/database/model/Room.java @@ -1,11 +1,14 @@ package de.lmu.navigator.database.model; +import java.util.List; + +import io.realm.RealmList; import io.realm.RealmObject; import io.realm.annotations.Ignore; import io.realm.annotations.PrimaryKey; import io.realm.annotations.Required; -public class Room extends RealmObject { +public class Room extends RealmObject implements Synonymable{ @Required @PrimaryKey @@ -23,6 +26,8 @@ public class Room extends RealmObject { private int posY; + private RealmList synonyms = new RealmList<>(); + public String getCode() { return code; } @@ -39,6 +44,7 @@ public void setFloor(Floor floor) { this.floor = floor; } + @Override public String getName() { return name; } @@ -70,4 +76,18 @@ public String getFloorCode() { public void setFloorCode(String floorCode) { this.floorCode = floorCode; } + + @Override + public List getSynonyms() { + return synonyms; + } + + @Override + public boolean hasSynonyms() { + return synonyms.size() > 0; + } + + public void setSynonyms(RealmList synonyms) { + this.synonyms = synonyms; + } } diff --git a/app/src/main/java/de/lmu/navigator/database/model/RoomSynonym.java b/app/src/main/java/de/lmu/navigator/database/model/RoomSynonym.java new file mode 100644 index 0000000..aff9d07 --- /dev/null +++ b/app/src/main/java/de/lmu/navigator/database/model/RoomSynonym.java @@ -0,0 +1,50 @@ +package de.lmu.navigator.database.model; + +import com.google.gson.annotations.SerializedName; + +import io.realm.RealmObject; +import io.realm.annotations.Ignore; +import io.realm.annotations.Required; + +public class RoomSynonym extends RealmObject implements RealmLeaf { + + @Ignore + @SerializedName("rCode") + protected String parentId; + + @Required + @SerializedName("syn") + protected String name; + + protected Room parent; + + @Override + public String getName() { + return name; + } + + @Override + public void setName(String name) { + this.name = name; + } + + @Override + public Room getParent() { + return parent; + } + + @Override + public void setParent(Room parent) { + this.parent = parent; + } + + @Override + public String getParentId() { + return parentId; + } + + @Override + public void setParentId(String parentId) { + this.parentId = parentId; + } +} diff --git a/app/src/main/java/de/lmu/navigator/database/model/Synonymable.java b/app/src/main/java/de/lmu/navigator/database/model/Synonymable.java new file mode 100644 index 0000000..44737cb --- /dev/null +++ b/app/src/main/java/de/lmu/navigator/database/model/Synonymable.java @@ -0,0 +1,21 @@ +package de.lmu.navigator.database.model; + +import java.util.List; + +/** + * Interface to avoid duplicate code fragments for "synonymable" elements. + * + * @param The class of the database elements, which can have synonyms. + */ +public interface Synonymable> { + + boolean hasSynonyms(); + + /** + * @param the class of the synonym (of type T) + * @return + */ + > List getSynonyms(); + + String getName(); +} diff --git a/app/src/main/java/de/lmu/navigator/indoor/FloorViewActivity.java b/app/src/main/java/de/lmu/navigator/indoor/FloorViewActivity.java index 6163a2d..a4d23a4 100644 --- a/app/src/main/java/de/lmu/navigator/indoor/FloorViewActivity.java +++ b/app/src/main/java/de/lmu/navigator/indoor/FloorViewActivity.java @@ -10,6 +10,7 @@ import butterknife.ButterKnife; import de.lmu.navigator.R; import de.lmu.navigator.app.BaseActivity; +import de.lmu.navigator.database.ModelHelper; import de.lmu.navigator.database.model.Building; import de.lmu.navigator.database.model.Room; import de.lmu.navigator.search.AbsSearchActivity; @@ -60,7 +61,7 @@ protected void onCreate(Bundle savedInstanceState) { .commit(); } - setTitle(mBuilding.getDisplayName()); + setTitle(ModelHelper.getName(mBuilding)); } public TileViewFragment getTileViewFragment() { diff --git a/app/src/main/java/de/lmu/navigator/indoor/TileViewFragment.java b/app/src/main/java/de/lmu/navigator/indoor/TileViewFragment.java index 1148926..ee3813d 100644 --- a/app/src/main/java/de/lmu/navigator/indoor/TileViewFragment.java +++ b/app/src/main/java/de/lmu/navigator/indoor/TileViewFragment.java @@ -364,8 +364,8 @@ private void selectRoom(Room room) { mTileView.scrollToAndCenter(room.getPosX(), room.getPosY()); mRoomDetailView.setVisibility(View.VISIBLE); - mRoomDetailName.setText(getString(R.string.floorview_selected_room, room.getName())); - mRoomDetailFloor.setText(room.getFloor().getName()); + mRoomDetailName.setText(ModelHelper.getName(room, getString(R.string.floorview_selected_room))); + mRoomDetailFloor.setText(ModelHelper.getDescription(room)); mSelectedRoom = room; } diff --git a/app/src/main/java/de/lmu/navigator/map/BuildingItem.java b/app/src/main/java/de/lmu/navigator/map/BuildingItem.java index e6c3782..cd423f7 100644 --- a/app/src/main/java/de/lmu/navigator/map/BuildingItem.java +++ b/app/src/main/java/de/lmu/navigator/map/BuildingItem.java @@ -37,12 +37,12 @@ public LatLng getPosition() { @Override public String getTitle() { - return mBuilding.getDisplayName(); + return ModelHelper.getName(mBuilding); } @Override public String getSnippet() { - return mBuilding.getStreet().getCity().getName(); + return ModelHelper.getDescription(mBuilding); } @Override diff --git a/app/src/main/java/de/lmu/navigator/map/ClusterMapFragment.java b/app/src/main/java/de/lmu/navigator/map/ClusterMapFragment.java index 3059883..403210a 100644 --- a/app/src/main/java/de/lmu/navigator/map/ClusterMapFragment.java +++ b/app/src/main/java/de/lmu/navigator/map/ClusterMapFragment.java @@ -31,6 +31,7 @@ import de.lmu.navigator.R; import de.lmu.navigator.app.BuildingDetailActivity; import de.lmu.navigator.app.MainActivity; +import de.lmu.navigator.database.ModelHelper; import de.lmu.navigator.database.model.Building; import io.realm.RealmResults; @@ -201,7 +202,7 @@ public boolean onClusterClick(Cluster cluster) { mDialogClusterItems = Lists.newArrayList(cluster.getItems()); String[] items = new String[cluster.getSize()]; for (int i = 0; i < mDialogClusterItems.size(); i++) { - items[i] = mDialogClusterItems.get(i).getBuilding().getDisplayName(); + items[i] = ModelHelper.getName(mDialogClusterItems.get(i).getBuilding()); } new AlertDialog.Builder(getActivity()) diff --git a/app/src/main/java/de/lmu/navigator/preferences/Preferences.java b/app/src/main/java/de/lmu/navigator/preferences/Preferences.java index 8a41694..6eeba42 100644 --- a/app/src/main/java/de/lmu/navigator/preferences/Preferences.java +++ b/app/src/main/java/de/lmu/navigator/preferences/Preferences.java @@ -12,6 +12,10 @@ public final class Preferences { public static final String KEY_CRASH_REPORTS = "key_crash_reports"; + public static final String KEY_DISPLAY_SYNONYM = "key_display_synonym"; + + public static final String KEY_SEARCH_ADVANCED = "key_search_advanced"; + private Preferences() {} } diff --git a/app/src/main/java/de/lmu/navigator/preferences/SettingsActivity.java b/app/src/main/java/de/lmu/navigator/preferences/SettingsActivity.java index 873a75d..233448d 100644 --- a/app/src/main/java/de/lmu/navigator/preferences/SettingsActivity.java +++ b/app/src/main/java/de/lmu/navigator/preferences/SettingsActivity.java @@ -2,11 +2,16 @@ import android.content.Context; import android.content.Intent; +import android.content.SharedPreferences; import android.os.Bundle; import androidx.appcompat.app.AppCompatActivity; + +import android.preference.PreferenceManager; import android.view.MenuItem; -public class SettingsActivity extends AppCompatActivity { +import de.lmu.navigator.database.ModelHelper; + +public class SettingsActivity extends AppCompatActivity implements SharedPreferences.OnSharedPreferenceChangeListener { public static Intent newIntent(Context context) { return new Intent(context, SettingsActivity.class); @@ -15,6 +20,7 @@ public static Intent newIntent(Context context) { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); + PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this); getFragmentManager().beginTransaction() .replace(android.R.id.content, new SettingsFragment()) .commit(); @@ -29,4 +35,12 @@ public boolean onOptionsItemSelected(MenuItem item) { return super.onOptionsItemSelected(item); } } + + @Override + public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String key) { + if(Preferences.KEY_DISPLAY_SYNONYM.equals(key)){ + ModelHelper.displaySynonyms = sharedPreferences.getBoolean(key, true); + // TODO invalidate main view + } + } } diff --git a/app/src/main/java/de/lmu/navigator/search/AbsSearchActivity.java b/app/src/main/java/de/lmu/navigator/search/AbsSearchActivity.java index 20bfc10..7c894b3 100644 --- a/app/src/main/java/de/lmu/navigator/search/AbsSearchActivity.java +++ b/app/src/main/java/de/lmu/navigator/search/AbsSearchActivity.java @@ -46,6 +46,7 @@ public abstract class AbsSearchActivity extends BaseActivity private static final String LOG_TAG = AbsSearchActivity.class.getSimpleName(); public static final String KEY_SEARCH_RESULT = "KEY_SEARCH_RESULT"; + public static final String CLASS_NAME = "CLASS_NAME"; @BindView(R.id.recycler) RecyclerView mRecyclerView; @@ -120,6 +121,7 @@ public void onFailure(Throwable t) { public void onItemClick(Searchable item) { Intent result = new Intent(); result.putExtra(KEY_SEARCH_RESULT, item.getCode()); + result.putExtra(CLASS_NAME, item.getClassName()); setResult(RESULT_OK, result); finish(); diff --git a/app/src/main/java/de/lmu/navigator/search/SearchAllActivity.java b/app/src/main/java/de/lmu/navigator/search/SearchAllActivity.java new file mode 100644 index 0000000..3015ee5 --- /dev/null +++ b/app/src/main/java/de/lmu/navigator/search/SearchAllActivity.java @@ -0,0 +1,40 @@ +package de.lmu.navigator.search; + +import android.content.Context; +import android.content.Intent; + +import java.util.ArrayList; +import java.util.List; + +import de.lmu.navigator.R; +import de.lmu.navigator.database.RealmDatabaseManager; +import de.lmu.navigator.database.model.Building; +import de.lmu.navigator.database.model.Room; + +public class SearchAllActivity extends AbsSearchActivity { + + public static Intent newIntent(Context context) { + return new Intent(context, SearchAllActivity.class); + } + + @Override + public List getItems() { + List items = new ArrayList<>(); + RealmDatabaseManager databaseManager = new RealmDatabaseManager(); + // Search for buildings + for (Building b : databaseManager.getAllBuildings()) { + items.add(SearchableWrapper.wrap(b)); + } + // Search for named rooms + for (Room r : databaseManager.getRoomsWithSynonym()) { + items.add(SearchableWrapper.wrap(r, null)); + } + databaseManager.close(); + return items; + } + + @Override + public int getSearchHintResId() { + return R.string.search_hint_buildings; + } +} diff --git a/app/src/main/java/de/lmu/navigator/search/SearchRoomActivity.java b/app/src/main/java/de/lmu/navigator/search/SearchRoomActivity.java index 9143865..8fb00b2 100644 --- a/app/src/main/java/de/lmu/navigator/search/SearchRoomActivity.java +++ b/app/src/main/java/de/lmu/navigator/search/SearchRoomActivity.java @@ -31,6 +31,8 @@ public List getItems() { Building building = databaseManager.getBuilding(buildingCode); List rooms = databaseManager.getRoomsForBuilding(building, true, true); + + // If same parent exists in different building parts, add building part as hint in description SetMultimap roomNamesMap = HashMultimap.create(); for (Room r : rooms) { roomNamesMap.put(r.getName(), r.getFloor().getBuildingPart().getName()); diff --git a/app/src/main/java/de/lmu/navigator/search/Searchable.java b/app/src/main/java/de/lmu/navigator/search/Searchable.java index f3dd22f..764ab29 100644 --- a/app/src/main/java/de/lmu/navigator/search/Searchable.java +++ b/app/src/main/java/de/lmu/navigator/search/Searchable.java @@ -7,4 +7,6 @@ public interface Searchable { String getSecondaryText(); String getCode(); + + String getClassName(); } diff --git a/app/src/main/java/de/lmu/navigator/search/SearchableWrapper.java b/app/src/main/java/de/lmu/navigator/search/SearchableWrapper.java index 8e7be43..e018789 100644 --- a/app/src/main/java/de/lmu/navigator/search/SearchableWrapper.java +++ b/app/src/main/java/de/lmu/navigator/search/SearchableWrapper.java @@ -1,5 +1,6 @@ package de.lmu.navigator.search; +import de.lmu.navigator.database.ModelHelper; import de.lmu.navigator.database.model.Building; import de.lmu.navigator.database.model.Room; @@ -11,6 +12,8 @@ public class SearchableWrapper implements Searchable { private String mCode; + private String mClassName; + public static Searchable wrap(Room room, String buildingPartHint) { return new SearchableWrapper(room, buildingPartHint); } @@ -20,9 +23,10 @@ public static Searchable wrap(Building building) { } private SearchableWrapper(Room room, String buildingPartHint) { - mPrimaryText = room.getName(); - mSecondaryText = room.getFloor().getName(); + mPrimaryText = ModelHelper.getName(room); + mSecondaryText = ModelHelper.getDescription(room); mCode = room.getCode(); + mClassName = Room.class.getSimpleName(); if (buildingPartHint != null) { mSecondaryText = mSecondaryText + " (" + buildingPartHint + ")"; @@ -30,9 +34,10 @@ private SearchableWrapper(Room room, String buildingPartHint) { } private SearchableWrapper(Building building) { - mPrimaryText = building.getDisplayName(); - mSecondaryText = building.getStreet().getCity().getName(); + mPrimaryText = ModelHelper.getName(building); + mSecondaryText = ModelHelper.getDescription(building); mCode = building.getCode(); + mClassName = Building.class.getSimpleName(); } @@ -50,4 +55,9 @@ public String getSecondaryText() { public String getCode() { return mCode; } + + @Override + public String getClassName() { + return mClassName; + } } diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 1466399..7cac380 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -40,6 +40,10 @@ Allgemein Crash Logs und Statistiken senden Anonyme Absturzberichte und Statistiken helfen uns, Fehler schneller zu beseitigen und die App zu verbessern. Es werden keine privaten Daten gesammelt. + Namen im Titel anzeigen + Wenn Synonyme für Räume und Gebäude verfügbar sind, zeige diese als Titel und füge die Adressinformation der Beschreibung hinzu. + Erweiterte Suche + Auch benannte Räume in der Hauptsuche berücksichtigen Informationen Open-Source-Lizenzen Feedback geben diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 7ff345a..5251af0 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -41,6 +41,10 @@ General Send crash logs and statistics Anonymous crash reports and statistics help us to find bugs quicker and to improve the app. No private data is collected. + Display name in title + If synonyms of rooms and buildings are available, show them as title and add the address info to the description. + Advanced search + Also include named rooms in main search. Information Open-Source-Licences Give feedback diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 393fd0f..c3fbbf4 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -11,6 +11,18 @@ android:summary="@string/prefs_crash_logs_summary" android:defaultValue="true"/> + + + +