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

Commit

Permalink
Centralized search v2 (#1457)
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

* clear history dialog

* search-as-you-type
  • Loading branch information
PiotrKedra authored Jul 13, 2022
1 parent bee5844 commit 2c10c84
Show file tree
Hide file tree
Showing 69 changed files with 1,606 additions and 686 deletions.
55 changes: 1 addition & 54 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,6 @@
</intent-filter>
</receiver>

<provider
android:name=".component.tumui.roomfinder.RoomFinderSuggestionProvider"
android:authorities="de.tum.in.tumcampusapp.component.tumui.roomfinder.RoomFinderSuggestionProvider"
android:exported="false" />
<provider
android:name=".component.tumui.person.PersonSearchSuggestionProvider"
android:authorities="de.tum.in.tumcampusapp.component.tumui.person.PersonSearchSuggestionProvider"
android:exported="false" />
<provider
android:name=".component.ui.transportation.MVVStationSuggestionProvider"
android:authorities="de.tum.in.tumcampusapp.component.ui.transportation.MVVStationSuggestionProvider"
Expand Down Expand Up @@ -253,61 +245,16 @@
android:name="android.support.PARENT_ACTIVITY"
android:value=".component.ui.overview.MainActivity" />
</activity>
<activity
android:name=".component.tumui.person.PersonSearchActivity"
android:configChanges="orientation|screenSize"
android:label="@string/person_search"
android:launchMode="singleTop"
android:parentActivityName=".component.ui.overview.MainActivity"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable_persons" />
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".component.ui.overview.MainActivity" />
</activity>
<activity
android:name=".component.tumui.person.PersonDetailsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/person_information"
android:parentActivityName=".component.tumui.person.PersonSearchActivity">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.tum.in.tumcampusapp.component.tumui.person.PersonSearchActivity" />
</activity>
<activity
android:name=".component.tumui.roomfinder.RoomFinderActivity"
android:configChanges="orientation|screenSize"
android:label="@string/roomfinder"
android:launchMode="singleTop"
android:parentActivityName=".component.ui.overview.MainActivity"
android:exported="true">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".component.ui.overview.MainActivity" />

<intent-filter>
<action android:name="android.intent.action.SEARCH" />
</intent-filter>

<meta-data
android:name="android.app.searchable"
android:resource="@xml/searchable_rooms" />
android:label="@string/person_information">
</activity>
<activity
android:name=".component.tumui.roomfinder.RoomFinderDetailsActivity"
android:configChanges="orientation|screenSize"
android:label="@string/roomfinder"
android:parentActivityName=".component.tumui.roomfinder.RoomFinderActivity"
android:theme="@style/AppTheme.NoDrawerLayout">
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value="de.tum.in.tumcampusapp.component.tumui.roomfinder.RoomFinderActivity" />
</activity>
<activity
android:name=".component.ui.studyroom.StudyRoomsActivity"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ public interface TUMCabeAPIService {
@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 @@ -290,6 +290,10 @@ public List<RoomFinderRoom> fetchRooms(String searchStrings) throws IOException
.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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,11 @@ interface TUMOnlineAPIService {
@Query("pSuche") query: String
): Call<LecturesResponse>

@GET("wbservicesbasic.veranstaltungenSuche")
fun searchLecturesSingle(
@Query("pSuche") query: String
): Single<LecturesResponse>

@GET("wbservicesbasic.personenDetails")
fun getPersonDetails(
@Query("pIdentNr") id: String,
Expand All @@ -78,7 +83,7 @@ interface TUMOnlineAPIService {
@GET("wbservicesbasic.personenSuche")
fun searchPerson(
@Query("pSuche") query: String
): Call<PersonList>
): Single<PersonList>

@GET("wbservicesbasic.noten")
fun getGrades(
Expand All @@ -99,4 +104,4 @@ interface TUMOnlineAPIService {
@Query("pToken") token: String,
@Query("pSecret") secret: String
): Call<TokenConfirmation>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,16 @@ class TUMOnlineClient(private val apiService: TUMOnlineAPIService) {

fun getCalendar(cacheControl: CacheControl): Call<EventsResponse> {
return apiService.getCalendar(
Const.CALENDAR_MONTHS_BEFORE, Const.CALENDAR_MONTHS_AFTER, cacheControl.header)
Const.CALENDAR_MONTHS_BEFORE, Const.CALENDAR_MONTHS_AFTER, cacheControl.header
)
}

fun createEvent(calendarItem: CalendarItem, eventId: String?): Call<CreateEventResponse> {
val start = DateTimeUtils.getDateTimeString(calendarItem.eventStart)
val end = DateTimeUtils.getDateTimeString(calendarItem.eventEnd)
return apiService.createCalendarEvent(
calendarItem.title, calendarItem.description, start, end, eventId)
calendarItem.title, calendarItem.description, start, end, eventId
)
}

fun deleteEvent(eventId: String): Call<DeleteEventResponse> {
Expand All @@ -68,11 +70,15 @@ class TUMOnlineClient(private val apiService: TUMOnlineAPIService) {
return apiService.searchLectures(query)
}

fun searchLecturesSingle(query: String): Single<LecturesResponse> {
return apiService.searchLecturesSingle(query)
}

fun getPersonDetails(id: String, cacheControl: CacheControl): Call<Employee> {
return apiService.getPersonDetails(id, cacheControl.header)
}

fun searchPerson(query: String): Call<PersonList> {
fun searchPerson(query: String): Single<PersonList> {
return apiService.searchPerson(query)
}

Expand Down Expand Up @@ -112,17 +118,17 @@ class TUMOnlineClient(private val apiService: TUMOnlineAPIService) {
val cacheManager = CacheManager(context)

val client = ApiHelper.getOkHttpClient(context)
.newBuilder()
.cache(cacheManager.cache)
.addInterceptor(AddTokenInterceptor(context))
.addInterceptor(CheckTokenInterceptor(context))
.addNetworkInterceptor(CacheResponseInterceptor())
.addNetworkInterceptor(CheckErrorInterceptor(context))
.build()
.newBuilder()
.cache(cacheManager.cache)
.addInterceptor(AddTokenInterceptor(context))
.addInterceptor(CheckTokenInterceptor(context))
.addNetworkInterceptor(CacheResponseInterceptor())
.addNetworkInterceptor(CheckErrorInterceptor(context))
.build()

val tikXml = TikXml.Builder()
.exceptionOnUnreadXml(false)
.build()
.exceptionOnUnreadXml(false)
.build()
val xmlConverterFactory = TikXmlConverterFactory.create(tikXml)

val apiService = Retrofit.Builder()
Expand All @@ -135,4 +141,4 @@ class TUMOnlineClient(private val apiService: TUMOnlineAPIService) {
return TUMOnlineClient(apiService)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,18 @@ public interface RecentsDao {
int STATIONS = 1;
int ROOMS = 2;
int PERSONS = 3;
int LECTURES = 4;

@Nullable
@Query("SELECT * FROM recent WHERE type=:type")
List<Recent> getAll(Integer type);

@Query("SELECT * FROM recent")
List<Recent> getAllRecentSearches();

@Query("DELETE FROM recent WHERE name=:name")
void deleteByName(String name);

@Insert(onConflict = OnConflictStrategy.IGNORE)
void insert(Recent recent);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ import de.tum.`in`.tumcampusapp.component.tumui.calendar.CalendarFragment
import de.tum.`in`.tumcampusapp.component.tumui.feedback.FeedbackActivity
import de.tum.`in`.tumcampusapp.component.tumui.grades.GradesFragment
import de.tum.`in`.tumcampusapp.component.tumui.lectures.fragment.LecturesFragment
import de.tum.`in`.tumcampusapp.component.tumui.person.PersonSearchFragment
import de.tum.`in`.tumcampusapp.component.tumui.roomfinder.RoomFinderFragment
import de.tum.`in`.tumcampusapp.component.tumui.tutionfees.TuitionFeesFragment
import de.tum.`in`.tumcampusapp.component.ui.barrierfree.BarrierFreeInfoFragment
import de.tum.`in`.tumcampusapp.component.ui.cafeteria.fragment.CafeteriaFragment
Expand All @@ -22,6 +20,7 @@ import de.tum.`in`.tumcampusapp.component.ui.news.NewsFragment
import de.tum.`in`.tumcampusapp.component.ui.openinghour.OpeningHoursListFragment
import de.tum.`in`.tumcampusapp.component.ui.overview.InformationActivity
import de.tum.`in`.tumcampusapp.component.ui.overview.MainFragment
import de.tum.`in`.tumcampusapp.component.ui.search.SearchFragment
import de.tum.`in`.tumcampusapp.component.ui.studyroom.StudyRoomsFragment
import de.tum.`in`.tumcampusapp.component.ui.ticket.activity.EventsFragment
import de.tum.`in`.tumcampusapp.utils.Const
Expand Down Expand Up @@ -51,7 +50,10 @@ class DrawerMenuHelper(
allItems.clear()

navigationMenu += HOME
navigationMenu += SEARCH

allItems += HOME
allItems += SEARCH

val myTumMenu = navigationMenu.addSubMenu(R.string.my_tum)
if (hasTumOnlineAccess) {
Expand Down Expand Up @@ -86,6 +88,10 @@ class DrawerMenuHelper(
return HOME
}

if (menuItem.title == activity.getString(SEARCH.titleRes)) {
return SEARCH
}

for (item in MY_TUM + GENERAL) {
if (menuItem.title == activity.getString(item.titleRes)) {
return item
Expand Down Expand Up @@ -122,6 +128,7 @@ class DrawerMenuHelper(
private companion object {

private val HOME = NavItem.FragmentDestination(R.string.home, R.drawable.ic_outline_home_24px, MainFragment::class.java)
private val SEARCH = NavItem.FragmentDestination(R.string.search, R.drawable.ic_action_search, SearchFragment::class.java, true)

private val MY_TUM = arrayOf(
NavItem.FragmentDestination(R.string.calendar, R.drawable.ic_outline_event_24px, CalendarFragment::class.java, true),
Expand All @@ -134,8 +141,6 @@ class DrawerMenuHelper(
private val GENERAL = arrayOf(
NavItem.FragmentDestination(R.string.menues, R.drawable.ic_cutlery, CafeteriaFragment::class.java),
NavItem.FragmentDestination(R.string.study_rooms, R.drawable.ic_outline_group_work_24px, StudyRoomsFragment::class.java),
NavItem.FragmentDestination(R.string.roomfinder, R.drawable.ic_outline_location_on_24px, RoomFinderFragment::class.java),
NavItem.FragmentDestination(R.string.person_search, R.drawable.ic_outline_people_outline_24px, PersonSearchFragment::class.java, true),
NavItem.FragmentDestination(R.string.news, R.drawable.ic_rss, NewsFragment::class.java),
NavItem.FragmentDestination(R.string.events_tickets, R.drawable.tickets, EventsFragment::class.java),
NavItem.FragmentDestination(R.string.barrier_free, R.drawable.ic_outline_accessible_24px, BarrierFreeInfoFragment::class.java),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class CalendarDetailsFragment : RoundedBottomSheetDialogFragment() {

private val isShownInCalendarActivity: Boolean by lazy {
arguments?.getBoolean(CALENDAR_SHOWN_IN_CALENDAR_ACTIVITY_PARAM)
?: throw IllegalStateException("Incomplete Bundle when opening calendar details fragment")
?: throw IllegalStateException("Incomplete Bundle when opening calendar details fragment")
}

private var deleteApiCall: Call<DeleteEventResponse>? = null
Expand Down Expand Up @@ -84,7 +84,7 @@ class CalendarDetailsFragment : RoundedBottomSheetDialogFragment() {
continue
}
val locationText: TextView = layoutInflater
.inflate(R.layout.calendar_location_text, locationLinearLayout, false) as TextView
.inflate(R.layout.calendar_location_text, locationLinearLayout, false) as TextView
if (item.isCanceled) {
locationText.setTextColor(ContextCompat.getColor(requireContext(), R.color.event_canceled))
val textForCancelledEvent = "${item.location} (${R.string.event_canceled})"
Expand Down Expand Up @@ -134,10 +134,10 @@ class CalendarDetailsFragment : RoundedBottomSheetDialogFragment() {
private fun displayDeleteDialog(eventId: String) {
val s = TcaDb.getInstance(requireContext()).calendarDao().getSeriesIdForEvent(eventId)
val alertDialog = AlertDialog.Builder(requireContext())
.setTitle(R.string.event_delete_title)
.setMessage(R.string.delete_event_info)
.setPositiveButton(R.string.delete) { _, _ -> deleteEvent(eventId) }
.setNeutralButton(R.string.cancel, null)
.setTitle(R.string.event_delete_title)
.setMessage(R.string.delete_event_info)
.setPositiveButton(R.string.delete) { _, _ -> deleteEvent(eventId) }
.setNeutralButton(R.string.cancel, null)
if (s != null) { // a event series
alertDialog.setNegativeButton(R.string.delete_series) { _, _ -> deleteEventSeries(s) }
}
Expand Down Expand Up @@ -186,8 +186,8 @@ class CalendarDetailsFragment : RoundedBottomSheetDialogFragment() {
}

private fun onLocationClicked(location: String) {
val sendIntent: Intent = Intent(getContext(),NavigaTUMActivity::class.java).apply {
putExtra("location",location)
val sendIntent: Intent = Intent(getContext(), NavigaTUMActivity::class.java).apply {
putExtra("location", location)
}
startActivity(sendIntent)
}
Expand Down Expand Up @@ -219,4 +219,4 @@ class CalendarDetailsFragment : RoundedBottomSheetDialogFragment() {
fun onEventDeleted(eventId: String)
fun onEditEvent(calendarItem: CalendarItem)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package de.tum.`in`.tumcampusapp.component.tumui.calendar

import android.annotation.SuppressLint
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.webkit.WebView
import androidx.appcompat.app.AppCompatActivity

class NavigaTUMActivity : AppCompatActivity() {
@SuppressLint("SetJavaScriptEnabled")
Expand All @@ -12,10 +12,10 @@ class NavigaTUMActivity : AppCompatActivity() {
val intent = getIntent()
val location = intent.getStringExtra("location")
val encoded_location = java.net.URLEncoder.encode(location, "utf-8")
val url = "https://nav.tum.sexy/search?q=${encoded_location}"
val url = "https://nav.tum.sexy/search?q=$encoded_location"
val webview = WebView(this)
setContentView(webview)
webview.settings.javaScriptEnabled = true
webview.loadUrl(url)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import de.tum.`in`.tumcampusapp.component.notifications.model.FutureNotification
import de.tum.`in`.tumcampusapp.component.notifications.persistence.NotificationType
import de.tum.`in`.tumcampusapp.component.other.locations.model.Geo
import de.tum.`in`.tumcampusapp.component.tumui.calendar.CalendarActivity
import de.tum.`in`.tumcampusapp.component.ui.overview.MainActivity
import de.tum.`in`.tumcampusapp.utils.Const
import de.tum.`in`.tumcampusapp.utils.DateTimeUtils
import de.tum.`in`.tumcampusapp.utils.Utils
Expand Down Expand Up @@ -43,9 +42,9 @@ data class Event(
*/
fun toCalendarItem(): CalendarItem {
return CalendarItem(
id ?: "", status ?: "", url ?: "", title,
description ?: "", getStartTimeInDeviceTimezone() ?: DateTime(),
getEndTimeInDeviceTimezone() ?: DateTime(), Utils.stripHtml(location ?: ""), false
id ?: "", status ?: "", url ?: "", title,
description ?: "", getStartTimeInDeviceTimezone() ?: DateTime(),
getEndTimeInDeviceTimezone() ?: DateTime(), Utils.stripHtml(location ?: ""), false
)
}

Expand All @@ -64,15 +63,15 @@ data class Event(
val pending = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_IMMUTABLE or PendingIntent.FLAG_UPDATE_CURRENT)

val notification = NotificationCompat.Builder(context, Const.NOTIFICATION_CHANNEL_DEFAULT)
.setContentTitle(title)
.setContentText(timestamp)
.setContentIntent(pending)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_outline_event_24px)
.setShowWhen(false)
.setColor(ContextCompat.getColor(context, R.color.color_primary))
.setTimeoutAfter(duration)
.build()
.setContentTitle(title)
.setContentText(timestamp)
.setContentIntent(pending)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ic_outline_event_24px)
.setShowWhen(false)
.setColor(ContextCompat.getColor(context, R.color.color_primary))
.setTimeoutAfter(duration)
.build()

val notificationTime = startTimeInDeviceTimeZone.minusMinutes(15)
return FutureNotification(NotificationType.CALENDAR, id.toInt(), notification, notificationTime)
Expand Down
Loading

0 comments on commit 2c10c84

Please sign in to comment.