Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Commit

Permalink
Migration to Navigatum (#1462)
Browse files Browse the repository at this point in the history
* basic search

* add rooms & lectures

* design + fix search aggregation

* add result types

* improve user experience

* add search history

* adjustments + refactor

* remove legacy searches

* fix ktlint issues

* - migrate to NavigaTum
- new navigation details screen
- integrate NavigaTumApi to centralized search

* moved from roomfinder to navigatum

* - fix map rendering
- move to new navigation details view

* new navigation UI

* add room_code parameter and move to bindings

* adjustments after merge

* removed unused RoomFinder logic

* Update app/src/main/java/de/tum/in/tumcampusapp/api/app/TUMCabeClient.java

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/java/de/tum/in/tumcampusapp/api/app/TUMCabeClient.java

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/java/de/tum/in/tumcampusapp/api/navigatum/domain/NavigationMap.kt

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/java/de/tum/in/tumcampusapp/component/other/general/RecentsDao.java

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/java/de/tum/in/tumcampusapp/component/ui/search/SearchFragment.kt

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/res/values-de/strings.xml

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* Update app/src/main/java/de/tum/in/tumcampusapp/component/tumui/roomfinder/NavigationDetailsFragment.kt

Co-authored-by: Frank Elsinga <frank@elsinga.de>

* general fixes

* fix ordering

* fix lint

Co-authored-by: Frank Elsinga <frank@elsinga.de>
  • Loading branch information
PiotrKedra and CommanderStorm authored Aug 10, 2022
1 parent 0f27eb7 commit e697dd7
Show file tree
Hide file tree
Showing 50 changed files with 1,202 additions and 276 deletions.
10 changes: 10 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,16 @@
android:label="@string/roomfinder"
android:theme="@style/AppTheme.NoDrawerLayout">
</activity>
<activity
android:name=".component.ui.search.SearchActivity"
android:configChanges="orientation|screenSize"
android:label="@string/search">
</activity>
<activity
android:name=".component.tumui.roomfinder.NavigationDetailsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/location_details">
</activity>
<activity
android:name=".component.ui.studyroom.StudyRoomsActivity"
android:configChanges="orientation|screenSize"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,13 +171,6 @@ public interface TUMCabeAPIService {
@GET(API_ROOM_FINDER + API_ROOM_FINDER_AVAILABLE_MAPS + "{archId}")
Call<List<RoomFinderMap>> fetchAvailableMaps(@Path("archId") String archId);

//RoomFinder maps
@GET(API_ROOM_FINDER + API_ROOM_FINDER_SEARCH + "{searchStrings}")
Call<List<RoomFinderRoom>> fetchRooms(@Path("searchStrings") String searchStrings);

@GET(API_ROOM_FINDER + API_ROOM_FINDER_SEARCH + "{searchStrings}")
Single<List<RoomFinderRoom>> fetchRoomsSingle(@Path("searchStrings") String searchStrings);

//RoomFinder cordinates
@GET(API_ROOM_FINDER + API_ROOM_FINDER_COORDINATES + "{archId}")
Call<RoomFinderCoordinate> fetchCoordinates(@Path("archId") String archId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ public final class TUMCabeClient {
static final String API_NOTIFICATIONS = "notifications/";
static final String API_LOCATIONS = "locations/";
static final String API_DEVICE = "device/";
static final String API_WIFI_HEATMAP = "wifimap/";
static final String API_BARRIER_FREE = "barrierfree/";
static final String API_BARRIER_FREE_CONTACT = "contacts/";
static final String API_BARRIER_FREE_BUILDINGS_TO_GPS = "getBuilding2Gps/";
Expand Down Expand Up @@ -280,24 +279,12 @@ public List<BuildingToGps> getBuilding2Gps() throws IOException {
.body();
}

@Deprecated // This API has been deprecated. Use the equivalent NavigaTUM API instead
public Call<List<RoomFinderMap>> fetchAvailableMaps(final String archId) {
return service.fetchAvailableMaps(ApiHelper.encodeUrl(archId));
}

public List<RoomFinderRoom> fetchRooms(String searchStrings) throws IOException {
return service.fetchRooms(ApiHelper.encodeUrl(searchStrings))
.execute()
.body();
}

public Single<List<RoomFinderRoom>> fetchRoomsSingle(String searchStrings) throws IOException {
return service.fetchRoomsSingle(ApiHelper.encodeUrl(searchStrings));
}

public RoomFinderCoordinate fetchCoordinates(String archId) throws IOException {
return fetchRoomFinderCoordinates(archId).execute().body();
}

@Deprecated // This API has been deprecated. Use the equivalent NavigaTUM API instead
public Call<RoomFinderCoordinate> fetchRoomFinderCoordinates(String archId) {
return service.fetchCoordinates(archId);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package de.tum.`in`.tumcampusapp.api.navigatum

import android.content.Context
import de.tum.`in`.tumcampusapp.api.app.ApiHelper
import de.tum.`in`.tumcampusapp.api.navigatum.domain.NavigationDetails
import de.tum.`in`.tumcampusapp.api.navigatum.domain.toNavigationDetails
import de.tum.`in`.tumcampusapp.api.navigatum.model.details.NavigationDetailsDto
import de.tum.`in`.tumcampusapp.api.navigatum.model.search.NavigaTumSearchResponseDto
import de.tum.`in`.tumcampusapp.api.tumonline.interceptors.CacheResponseInterceptor
import de.tum.`in`.tumcampusapp.utils.CacheManager
import io.reactivex.Single
import retrofit2.Retrofit
import retrofit2.adapter.rxjava2.RxJava2CallAdapterFactory
import retrofit2.converter.gson.GsonConverterFactory

class NavigaTumAPIClient(private val apiService: NavigaTumAPIService) {

fun search(query: String): NavigaTumSearchResponseDto? {
return apiService.search(query)
.execute()
.body()
}

fun getNavigationDetails(id: String): NavigationDetails? {
return apiService.getNavigationDetails(id)
.execute()
.body()
?.toNavigationDetails()
}

fun searchSingle(query: String): Single<NavigaTumSearchResponseDto> {
return apiService.searchSingle(query)
}

fun getNavigationDetailsSingle(id: String): Single<NavigationDetailsDto> {
return apiService.getNavigationDetailsSingle(id)
}

companion object {
private const val BASE_URL = "https://nav.tum.sexy/"

private var apiClient: NavigaTumAPIClient? = null

@JvmStatic
@Synchronized
fun getInstance(context: Context): NavigaTumAPIClient {
if (apiClient == null) {
apiClient = buildAPIClient(context)
}
return apiClient!!
}

private fun buildAPIClient(context: Context): NavigaTumAPIClient {
val cacheManager = CacheManager(context)

val client = ApiHelper.getOkHttpClient(context)
.newBuilder()
.cache(cacheManager.cache)
.addNetworkInterceptor(CacheResponseInterceptor())
.build()

val apiService = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create())
.addCallAdapterFactory(RxJava2CallAdapterFactory.create())
.build()
.create(NavigaTumAPIService::class.java)

return NavigaTumAPIClient(apiService)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package de.tum.`in`.tumcampusapp.api.navigatum

import de.tum.`in`.tumcampusapp.api.navigatum.model.details.NavigationDetailsDto
import de.tum.`in`.tumcampusapp.api.navigatum.model.search.NavigaTumSearchResponseDto
import io.reactivex.Single
import retrofit2.Call
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

interface NavigaTumAPIService {

@GET(API_SEARCH)
fun search(
@Query(QUERY_PARAM) query: String
): Call<NavigaTumSearchResponseDto>

@GET(API_GET)
fun getNavigationDetails(
@Path(ID_PARAM) id: String
): Call<NavigationDetailsDto>

@GET(API_SEARCH)
fun searchSingle(
@Query(QUERY_PARAM) query: String
): Single<NavigaTumSearchResponseDto>

@GET(API_GET)
fun getNavigationDetailsSingle(
@Path(ID_PARAM) id: String
): Single<NavigationDetailsDto>

companion object {
private const val API_SEARCH = "api/search"
private const val QUERY_PARAM = "q"
private const val ID_PARAM = "id"
private const val API_GET = "api/get/{$ID_PARAM}"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package de.tum.`in`.tumcampusapp.api.navigatum.domain

import de.tum.`in`.tumcampusapp.api.navigatum.model.details.NavigationDetailsDto
import de.tum.`in`.tumcampusapp.component.other.locations.model.Geo

data class NavigationDetails(
val id: String,
val name: String,
val type: String,
val typeCommonName: String,
val geo: Geo,
val parentsList: List<String> = listOf(),
val properties: List<NavigationProperty> = listOf(),
val availableMaps: List<RoomfinderMap> = listOf()
) {
fun getFormattedParentNames(): String {
return parentsList.reduce { acc, parentName -> "$acc \\ $parentName" }
}
}

fun NavigationDetailsDto.toNavigationDetails(): NavigationDetails {

return NavigationDetails(
id = this.id,
name = this.name,
type = this.type,
typeCommonName = this.typeCommonName,
geo = Geo(this.cords.lat, this.cords.lon),
parentsList = this.parentNames,
properties = this.additionalProperties.propsList
.map { it.toNavigationProperty() },
availableMaps = this.maps.roomFinder.available
.map { it.toNavigationMap() }
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package de.tum.`in`.tumcampusapp.api.navigatum.domain

import com.google.gson.Gson
import com.google.gson.annotations.SerializedName
import de.tum.`in`.tumcampusapp.component.other.general.model.Recent
import java.io.Serializable

data class NavigationEntity(
@SerializedName("id")
var id: String = "",
@SerializedName("type")
var type: String = "",
@SerializedName("name")
var name: String = "",
@SerializedName("subtext")
var subtext: String = "",
@SerializedName("parsed_id")
var parsedId: String? = null
) : Serializable {

fun getFormattedName(): String {
return if (parsedId == null) removeHighlight(name)
else removeHighlight(parsedId!!) + "" + removeHighlight(name)
}

fun getFormattedSubtext(): String {
return removeHighlight(subtext)
}

private fun removeHighlight(field: String): String {
/***
* Info from NavigaTum swagger: https://editor.swagger.io/?url=https://raw.githubusercontent.com/TUM-Dev/navigatum/main/openapi.yaml
* In future maybe there will be query parameter for this
* "Some fields support highlighting the query terms and it uses DC3 (\x19 or \u{0019})
* and DC1 (\x17 or \u{0017}) to mark the beginning/end of a highlighted sequence"
*/
return field
.replace("\u0019", "")
.replace("\u0017", "")
.replace("\\x19", "")
.replace("\\x17", "")
}

companion object {
@JvmStatic fun toRecent(navigationEntity: NavigationEntity, type: Int): Recent {
val gson = Gson()
val jsonString = gson.toJson(navigationEntity)
return Recent(name = jsonString, type = type)
}

@JvmStatic
fun fromRecent(recent: Recent): NavigationEntity {
val gson = Gson()
return gson.fromJson(recent.name, NavigationEntity::class.java)
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.tum.`in`.tumcampusapp.api.navigatum.domain

import de.tum.`in`.tumcampusapp.api.navigatum.model.details.NavigationPropertyDto

data class NavigationProperty(
val title: String = "",
val value: String = ""
)

fun NavigationPropertyDto.toNavigationProperty(): NavigationProperty {
return NavigationProperty(
title = this.name,
value = this.text
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package de.tum.`in`.tumcampusapp.api.navigatum.domain

import de.tum.`in`.tumcampusapp.api.navigatum.model.details.RoomFinderMapDto

data class RoomfinderMap(
val mapId: String,
val mapName: String,
val mapImgUrl: String,
val pointerXCord: Int,
val pointerYCord: Int,
val mapImgWidth: Int,
val mapImgHeight: Int
)

fun RoomFinderMapDto.toNavigationMap(): RoomfinderMap {
val basicMapUrl = "https://nav.tum.sexy/cdn/maps/roomfinder/"
return RoomfinderMap(
mapId = this.id,
mapName = this.name,
mapImgUrl = "$basicMapUrl${this.imgUrl}",
pointerXCord = this.x,
pointerYCord = this.y,
mapImgWidth = this.width,
mapImgHeight = this.height
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

import com.google.gson.annotations.SerializedName

data class NavigationAdditionalPropsDto(
@SerializedName("computed")
var propsList: List<NavigationPropertyDto> = listOf()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

data class NavigationCordsDto(
var lat: Double = 0.0,
var lon: Double = 0.0
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

import com.google.gson.annotations.SerializedName

data class NavigationDetailsDto(
val id: String = "",
val name: String = "",
@SerializedName("parent_names")
val parentNames: List<String> = listOf(),
val type: String = "",
@SerializedName("type_common_name")
val typeCommonName: String = "",
@SerializedName("props")
val additionalProperties: NavigationAdditionalPropsDto = NavigationAdditionalPropsDto(),
@SerializedName("coords")
val cords: NavigationCordsDto = NavigationCordsDto(),
val maps: NavigationMapsDto = NavigationMapsDto()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

import com.google.gson.annotations.SerializedName

data class NavigationMapsDto(
var default: String = "",
@SerializedName("roomfinder")
var roomFinder: RoomFinderMapsDto = RoomFinderMapsDto()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

data class NavigationPropertyDto(
var name: String = "",
var text: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

import com.google.gson.annotations.SerializedName

data class RoomFinderMapDto(
var id: String = "",
var name: String = "",
@SerializedName("file")
var imgUrl: String = "",
var height: Int = 0,
var width: Int = 0,
var x: Int = 0,
var y: Int = 0,
var scale: String = ""
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package de.tum.`in`.tumcampusapp.api.navigatum.model.details

import com.google.gson.annotations.SerializedName

data class RoomFinderMapsDto(
var available: List<RoomFinderMapDto> = listOf(),
@SerializedName("default")
var defaultMapId: String = ""
)
Loading

0 comments on commit e697dd7

Please sign in to comment.