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

Migrate TUMOnlineRequest to Retrofit #940

Merged
merged 83 commits into from Jul 23, 2018

Conversation

thellmund
Copy link
Contributor

@thellmund thellmund commented Jun 30, 2018

This is work in progress

This pull request replaces TUMOnlineRequest with TUMOnlineClient, which uses Retrofit. The steps we took:

  1. We replaced SimpleXML with TikXML due to improved performance, smaller memory footprint and cleaner API.
  2. We added TUMOnlineClient and TUMOnlineAPIService for API access.
  3. We added TUMOnlineInterceptor to intercept requests, append the token parameter and throw exceptions in case of errors. This is necessary because TUMonline always returns 200, even in case of errors.
  4. We removed TumLock and its associated DAO.

Building on these changes, we should do these things next:

  1. Update string resources with more appropriate naming.
  2. Update design of error layouts (nicer icons, larger text, proper headers).
  3. Add TypeConverters (e.g. convert date strings to DateTime objects).

Issues: #544 #674 #388

thellmund and others added 29 commits June 22, 2018 12:21
It offers a cleaner API and is much faster than SimpleXML.
Reasons:
1. Cleaner API
2. Much faster
3. SimpleXML is no longer being developed
…o th/migrate-tumonlinerequest-to-retrofit
@kordianbruck
Copy link
Member

@thellmund still WIP or Ready to review?

@thellmund
Copy link
Contributor Author

@kordianbruck Basically done, but I want to do some more testing before submitting it for review. Will likely do that tomorrow.

@thellmund
Copy link
Contributor Author

@kordianbruck Ready for review

@@ -80,7 +80,7 @@ public static OkHttpClient getOkHttpClient(Context c) {
builder.connectTimeout(Helper.HTTP_TIMEOUT, TimeUnit.MILLISECONDS);
builder.readTimeout(Helper.HTTP_TIMEOUT, TimeUnit.MILLISECONDS);

builder.addNetworkInterceptor(new TumHttpLoggingInterceptor(message -> Utils.logwithTag(TAG, message)));
//builder.addNetworkInterceptor(new TumHttpLoggingInterceptor(message -> Utils.logwithTag(TAG, message)));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please remove commented code

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commented this for testing. Will re-enable.

*/
public boolean hasValidAccessToken() {
public static boolean hasValidAccessToken(Context context) {
final String oldAccessToken = Utils.getSetting(context, Const.ACCESS_TOKEN, "");
return oldAccessToken != null && oldAccessToken.length() > 2;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the only remaining method in AccessTokenManager?
Probably completely remove the class in favor of Utils or something


class TUMOnlineClient(private val apiService: TUMOnlineAPIService) {

fun getCalendar(force: Boolean = false): Call<Events> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I really don't like boolean parameters.
From looking at a function call, one can't tell WTH this means.

getCalendar(true);

Without looking at the function definition, that parameter could be anything.
Please consider a proper Enum as parameter, which might even directly reference the underlying String.

getCalendar(CacheControl.doNotCache)

Is much nicer to read

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Android Studio displays the parameter name, but I agree with your feedback. Will adapt this accordingly.


companion object {

private val cachingDurations = mapOf(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When we're not actually using the Map capabilities of that map, because we always linearly search the map, please use a List of tuples instead of a Map.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

TokenLimitReachedException::class,
InvalidTokenException::class,
MissingPermissionException::class,
UnknownErrorException::class)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If only there was a common exception type to be declared 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔

holder.tvTypeSWSSemester.setText(String.format("%s - %s - %s SWS", lvItem.getStp_lv_art_name(), lvItem.getSemester_id(), lvItem.getDauer_info()));
holder.tvDozent.setText(lvItem.getVortragende_mitwirkende());
holder.tvLectureName.setText(lvItem.getTitle());
holder.tvTypeSWSSemester.setText(String.format("%s - %s - %s SWS",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i18n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.

@PropertyElement(name = "sj_name") val semesterYears: String,
@PropertyElement(name = "stp_lv_art_kurz") val shortLectureType: String,
@PropertyElement(name = "stp_lv_art_name") val lectureType: String,
@PropertyElement(name = "stp_lv_nr") val stp_lv_nr: String, // TODO: Rename valiables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you still want to do this?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At least fix the typo in the TODO 🙈

@PropertyElement(name = "sj_name") val semesterYears: String? = null,
@PropertyElement(name = "stp_lv_art_kurz") val shortLectureType: String? = null,
@PropertyElement(name = "stp_lv_art_name") val lectureType: String? = null,
@PropertyElement(name = "stp_lv_nr") val stp_lv_nr: String, // TODO: Rename variables
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover TODO

@Xml(name = "row")
data class LectureDetails(
@PropertyElement(name = "dauer_info") val duration: String? = null,
@PropertyElement(name = "ersttermin") val firstAppointment: String? = null, // TODO: TypeConverters
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover TODO

Copy link
Contributor Author

@thellmund thellmund Jul 21, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further inspection, I saw that the value can also be “geplant” (“planned”). For that reason, I’ll remove the to-do.


return infoText + name + ' ' + surname
return arrayOf(title, name, surname)
.filterNotNull()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aren't you missing empty strings for titles then?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Upon further inspection, I don’t believe that the string representation of Employee is used anywhere (we use getNameWithTitle(Context)). I’ve removed it now.

@@ -92,7 +83,7 @@
<string name="licences_summary">Rechtliche Hinweise zu Lizenzen</string>

<!-- Startup Wizard -->
<string name="token_not_enabled">Nicht angemeldet</string>
<string name="not_connected_to_tumonline">Nicht angemeldet</string>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a proper translation of "Not connected"

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think “angemeldet” fits better than “verbunden”, but since we seem to use the latter throughout the app, I’ve changed this translation.

compareTo(other)
} else {
-1
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is quite literally compareValues

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I only learned about compareValues() through your comment today – thanks btw, @pfent 😊
Given that I stopped using this extension with the last commit, I’ll remove the entire file.

private fun syncPersonalLectures() {
TUMOnlineClient
.getInstance(context)
.getPersonalLectures(CacheControl.NO_CACHE)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It his correct?
We call this in fillCache(), but then set NO_CACHE?

Ok, I still think this is confusing...
This should probably be called BYPASS_CACHE

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I changed the naming accordingly and changed the method to CacheControl.USE_CACHE, because we only want to refresh the content in the background if it’s past its max-age (same behavior as before the refactoring).

@thellmund thellmund requested a review from pfent July 23, 2018 08:01
Copy link
Contributor

@pfent pfent left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let the merge conflicts begin!

@thellmund thellmund merged commit f023a70 into master Jul 23, 2018
@thellmund thellmund deleted the th/migrate-tumonlinerequest-to-retrofit branch July 23, 2018 09:44
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants