Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Room / building synonyms integration (#21) #24

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion app/src/debug/java/de/lmu/navigator/DataConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -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/";
Expand Down
5 changes: 5 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@
android:name=".app.BuildingDetailActivity"
android:screenOrientation="portrait"
android:theme="@style/AppTheme.TransparentActionBar"/>
<activity
android:name=".search.SearchAllActivity"
android:label="@string/search_label"
android:screenOrientation="portrait">
</activity>
<activity
android:name=".search.SearchBuildingActivity"
android:label="@string/search_label"
Expand Down
30 changes: 30 additions & 0 deletions app/src/main/assets/data/23_building_syn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[
{
"bCode": "bw0000",
"syn": "Hauptgebäude"
},
{
"bCode": "bw1003",
"syn": "Mathebau"
},
{
"bCode": "bw0601",
"syn": "Fakultät für Psychologie und Pädagogik"
},
{
"bCode": "bw0601",
"syn": "Schweinchenbau"
},
{
"bCode": "bw1715",
"syn": "Pathologisches Institut"
},
{
"bCode": "TODO",
"syn": "Philologicum"
},
{
"bCode": "bw0120",
"syn": "Institut für Statistik"
}
]
78 changes: 78 additions & 0 deletions app/src/main/assets/data/26_room_syn.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
[
{
"rCode": "000000100_",
"syn": "Audimax"
},
{
"rCode": "000000027_",
"syn": "Lichthof"
},
{
"rCode": "0010-1097_",
"syn": "Stucafé"
},
{
"rCode": "001900001_",
"syn": "Studienkanzlei"
},
{
"rCode": "001901226_",
"syn": "Große Aula"
},
{
"rCode": "001901238_",
"syn": "Senatssaal"
},
{
"rCode": "002000020_",
"syn": "Kleiner Physikhörsaal"
},
{
"rCode": "002001120_",
"syn": "Großer Physikhörsaal"
},
{
"rCode": "TODO",
"syn": "Universitätsbibliothek"
},
{
"rCode": "100200029_",
"syn": "Café Gumbel"
},
{
"rCode": "100200038_",
"syn": "GAF"
},
{
"rCode": "7078-1014_",
"syn": "CIP-Pool Sibirien"
},
{
"rCode": "7078-1012_",
"syn": "CIP-Pool Gobi"
},
{
"rCode": "7078-1017_",
"syn": "CIP-Pool Takla-Makan"
},
{
"rCode": "7080-1102_",
"syn": "CIP-Pool Kalahari"
},
{
"rCode": "708100001_",
"syn": "CIP-Pool Antarktis"
},
{
"rCode": "708100005_",
"syn": "CIP-Pool Arktis"
},
{
"rCode": "100201015_",
"syn": "CIP-Pool Proxima"
},
{
"rCode": "102000001_",
"syn": "CIP-Pool Luna"
}
]
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
protected void onBindBilduing(RecyclerView.ViewHolder vh, Building building) {
AllBuildingsAdapter.ViewHolder holder = (AllBuildingsAdapter.ViewHolder) vh;
holder.city.setText(building.getStreet().getCity().getName());
holder.street.setText(building.getDisplayName());
holder.city.setText(ModelHelper.getDescription(building));
holder.street.setText(ModelHelper.getName(building));

int imageSize = mContext.getResources().getDimensionPixelSize(R.dimen.image_size_all);
Picasso.get()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ protected void onCreate(Bundle savedInstanceState) {
mBuilding = mDatabaseManager.getBuilding(extraBuildingCode);

setTitle(null);
mBuildingName.setText(mBuilding.getDisplayName());
mBuildingCity.setText(mBuilding.getStreet().getCity().getName());
mBuildingName.setText(ModelHelper.getName(mBuilding));
mBuildingCity.setText(ModelHelper.getDescription(mBuilding));

final Drawable placeholder = TextDrawable.builder()
.beginConfig()
Expand All @@ -69,7 +69,7 @@ protected void onCreate(Bundle savedInstanceState) {
.getDimensionPixelSize(R.dimen.building_placeholder_font_size))
.toUpperCase()
.endConfig()
.buildRect(mBuilding.getDisplayName().substring(0, 1),
.buildRect(ModelHelper.getName(mBuilding).substring(0, 1),
ColorGenerator.MATERIAL.getColor(mBuilding));

Picasso.get()
Expand All @@ -94,7 +94,7 @@ void showFloorView() {
@OnClick(R.id.layout_map)
void showMap() {
String url = String.format("http://maps.google.com/maps?geo:%s%s&q=%s",
mBuilding.getCoordLat(), mBuilding.getCoordLong(), mBuilding.getDisplayName());
mBuilding.getCoordLat(), mBuilding.getCoordLong(), mBuilding.getName());
Intent intent = new Intent(android.content.Intent.ACTION_VIEW, Uri.parse(url));
startActivity(intent);
}
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/java/de/lmu/navigator/app/BuildingsAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.amulyakhare.textdrawable.TextDrawable;
import com.amulyakhare.textdrawable.util.ColorGenerator;

import de.lmu.navigator.database.ModelHelper;
import de.lmu.navigator.database.model.Building;
import de.lmu.navigator.view.RealmAdapter;
import io.realm.RealmResults;
Expand Down Expand Up @@ -56,6 +57,6 @@ public Drawable getPlaceholderDrawable(Building b, int size) {
.width(size)
.height(size)
.endConfig()
.buildRound(b.getDisplayName().substring(0, 1), color);
.buildRound(ModelHelper.getName(b).substring(0, 1), color);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
@Override
protected void onBindBilduing(RecyclerView.ViewHolder vh, Building building) {
FavoritesAdapter.ViewHolder holder = (FavoritesAdapter.ViewHolder) vh;
holder.name.setText(building.getDisplayName());
holder.name.setText(ModelHelper.getName(building));

int imageSize = mContext.getResources().getDimensionPixelSize(R.dimen.image_size_favorite);
Picasso.get()
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/java/de/lmu/navigator/app/LaunchActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
import de.lmu.navigator.R;
import de.lmu.navigator.database.UpdateService;
import de.lmu.navigator.preferences.Preferences;
import io.realm.Realm;
import io.realm.RealmConfiguration;
import me.alexrs.prefs.lib.Prefs;

public class LaunchActivity extends AppCompatActivity {
Expand Down Expand Up @@ -49,6 +51,15 @@ public void onReceive(Context context, Intent intent) {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

// Always set realm schema version
RealmConfiguration config = new RealmConfiguration.Builder()
.name("default.realm")
.schemaVersion(DataConfig.SHIPPED_DATA_VERSION)
.deleteRealmIfMigrationNeeded()
.build();
Realm.setDefaultConfiguration(config);
// TODO add migration, if don't want to delete old db.

if (shouldUpdate()) {
setContentView(R.layout.activity_launch);
ButterKnife.bind(this);
Expand Down
42 changes: 40 additions & 2 deletions app/src/main/java/de/lmu/navigator/app/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,26 @@
import butterknife.BindView;
import butterknife.ButterKnife;
import de.lmu.navigator.R;
import de.lmu.navigator.database.ModelHelper;
import de.lmu.navigator.database.model.Building;
import de.lmu.navigator.database.model.Room;
import de.lmu.navigator.indoor.FloorViewActivity;
import de.lmu.navigator.map.ClusterMapFragment;
import de.lmu.navigator.preferences.Preferences;
import de.lmu.navigator.preferences.SettingsActivity;
import de.lmu.navigator.search.AbsSearchActivity;
import de.lmu.navigator.search.SearchAllActivity;
import de.lmu.navigator.search.SearchBuildingActivity;
import io.realm.RealmResults;
import me.alexrs.prefs.lib.Prefs;

public class MainActivity extends BaseActivity {

private static final String LOG_TAG = MainActivity.class.getSimpleName();

public static final int REQUEST_CODE_SEARCH_BUILDING = 1;
public static final int REQUEST_CODE_ADD_FAVORITE = 2;
public static final int REQUEST_CODE_SEARCH_ALL = 3;

@BindView(R.id.tabs)
PagerSlidingTabStrip mTabs;
Expand Down Expand Up @@ -65,8 +72,13 @@ public boolean onCreateOptionsMenu(Menu menu) {
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.search:
startActivityForResult(SearchBuildingActivity.newIntent(this),
REQUEST_CODE_SEARCH_BUILDING);
if (Prefs.with(this).getBoolean(Preferences.KEY_SEARCH_ADVANCED, true)) {
startActivityForResult(SearchAllActivity.newIntent(this),
REQUEST_CODE_SEARCH_ALL);
} else {
startActivityForResult(SearchBuildingActivity.newIntent(this),
REQUEST_CODE_SEARCH_BUILDING);
}
return true;

case R.id.settings:
Expand All @@ -87,6 +99,19 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
startActivity(BuildingDetailActivity.newIntent(this, buildingCode));
}
break;
case REQUEST_CODE_SEARCH_ALL:
if (resultCode == RESULT_OK) {
String code = data.getStringExtra(AbsSearchActivity.KEY_SEARCH_RESULT);
String className = data.getStringExtra(AbsSearchActivity.CLASS_NAME);
if(Building.class.getSimpleName().equals(className)) {
startActivity(BuildingDetailActivity.newIntent(this, code));
} else if (Room.class.getSimpleName().equals(className)) {
Building building = mDatabaseManager.getRoom(code).getFloor().getBuildingPart().getBuilding();
startActivity(BuildingDetailActivity.newIntent(this, building.getCode()));
startActivity(FloorViewActivity.newIntent(this, building, code));
}
}
break;

case REQUEST_CODE_ADD_FAVORITE:
if (resultCode == RESULT_OK) {
Expand All @@ -105,6 +130,19 @@ private void onAddFavoriteResult(Intent data) {
mDatabaseManager.setBuildingStarred(building, true);
}

@Override
protected void onResume(){
super.onResume();

// Display synonym name instead of address
if (Prefs.with(this).getBoolean(Preferences.KEY_DISPLAY_SYNONYM, true)) {
ModelHelper.displaySynonyms = true;
} else {
ModelHelper.displaySynonyms = false;
}

}

private enum Tabs {

FAVORITES(FavoritesFragment.class, R.string.tab_favorites),
Expand Down
60 changes: 59 additions & 1 deletion app/src/main/java/de/lmu/navigator/database/ModelHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,20 @@
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;

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.Floor;
import de.lmu.navigator.database.model.RealmLeaf;
import de.lmu.navigator.database.model.Room;
import de.lmu.navigator.database.model.Synonymable;

public class ModelHelper {

public static final String BUILDING_CODE = "code";
public static final String BUILDING_NAME = "displayName";
public static final String BUILDING_NAME = "name";
public static final String BUILDING_STARRED = "starred";

public static final String BUILDING_PART_CODE = "code";
Expand All @@ -29,12 +33,66 @@ public class ModelHelper {
public static final String ROOM_FLOOR_MAP_URI = "floor.mapUri";
public static final String ROOM_BUILDING_CODE = "floor.buildingPart.building.code";

public static final String SYNONYMS = "synonyms";

public static final List<String> 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 <T extends Synonymable<T>> 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 <T extends Synonymable<T>> 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 <T extends Synonymable<T>> 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")
Expand Down
Loading