Skip to content

Commit

Permalink
Merge pull request #261 from ZeusWPI/hotfix
Browse files Browse the repository at this point in the history
Fix for null end date
  • Loading branch information
niknetniko authored Apr 24, 2018
2 parents 2c5f389 + a48413d commit eaa4b50
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "be.ugent.zeus.hydra"
minSdkVersion 16
targetSdkVersion 27
versionCode 274
versionName "2.7.1"
versionCode 275
versionName "2.7.2"
vectorDrawables.useSupportLibrary = true
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"

Expand Down
12 changes: 10 additions & 2 deletions app/src/main/java/be/ugent/zeus/hydra/association/event/Event.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import android.os.Parcel;
import android.os.Parcelable;
import android.support.annotation.Nullable;

import be.ugent.zeus.hydra.association.Association;
import be.ugent.zeus.hydra.common.converter.BooleanJsonAdapter;
Expand All @@ -27,6 +28,7 @@ public final class Event implements Parcelable, Serializable {
private String title;
@JsonAdapter(ZonedThreeTenAdapter.class)
private ZonedDateTime start;
@Nullable
@JsonAdapter(ZonedThreeTenAdapter.class)
private ZonedDateTime end;
private String location;
Expand Down Expand Up @@ -60,7 +62,11 @@ public LocalDateTime getLocalStart() {
*
* @return The converted end date.
*/
@Nullable
public LocalDateTime getLocalEnd() {
if (getEnd() == null) {
return null;
}
return DateUtils.toLocalDateTime(getEnd());
}

Expand All @@ -80,11 +86,12 @@ public void setStart(ZonedDateTime start) {
this.start = start;
}

@Nullable
public ZonedDateTime getEnd() {
return end;
}

public void setEnd(ZonedDateTime end) {
public void setEnd(@Nullable ZonedDateTime end) {
this.end = end;
}

Expand Down Expand Up @@ -243,6 +250,7 @@ public int hashCode() {
* @return The identifier.
*/
public String getIdentifier() {
return title + start.toString() + end.toString() + latitude + longitude + url + association.getName();
String endDate = end == null ? "" : end.toString();
return title + start.toString() + endDate + latitude + longitude + url + association.getName();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,12 @@ protected void onCreate(Bundle savedInstanceState) {
TextView endTime = findViewById(R.id.time_end);

startTime.setText(event.getLocalStart().format(format));
endTime.setText(event.getLocalEnd().format(format));

if (event.getLocalEnd() != null) {
endTime.setText(event.getLocalEnd().format(format));
} else {
endTime.setText(R.string.date_unknown);
}

if (event.getAssociation() != null && event.getAssociation().getImageLink() != null) {
Picasso.with(this).load(event.getAssociation().getImageLink()).into(organisatorImage, new Callback.EmptyCallback() {
Expand Down Expand Up @@ -156,12 +161,15 @@ private void addToCalendar() {
Intent intent = new Intent(Intent.ACTION_INSERT)
.setData(CalendarContract.Events.CONTENT_URI)
.putExtra(CalendarContract.EXTRA_EVENT_BEGIN_TIME, event.getStart().toInstant().toEpochMilli())
.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.getEnd().toInstant().toEpochMilli())
.putExtra(CalendarContract.Events.TITLE, event.getTitle())
.putExtra(CalendarContract.Events.EVENT_LOCATION, event.getLocation())
.putExtra(CalendarContract.Events.DESCRIPTION, event.getDescription())
.putExtra(CalendarContract.Events.AVAILABILITY, CalendarContract.Events.AVAILABILITY_TENTATIVE);

if (event.getEnd() != null) {
intent.putExtra(CalendarContract.EXTRA_EVENT_END_TIME, event.getEnd().toInstant().toEpochMilli());
}

NetworkUtils.maybeLaunchIntent(this, intent);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package be.ugent.zeus.hydra.common.converter;

import android.arch.persistence.room.TypeConverter;
import android.support.annotation.Nullable;

import com.google.gson.TypeAdapter;
import com.google.gson.stream.JsonReader;
Expand Down Expand Up @@ -33,8 +34,9 @@ public class DateTypeConverters {
*
* @return The instance or {@code null} if the input was {@code null}.
*/
@Nullable
@TypeConverter
public static OffsetDateTime toOffsetDateTime(String sqlValue) {
public static OffsetDateTime toOffsetDateTime(@Nullable String sqlValue) {
if (sqlValue == null) {
return null;
} else {
Expand All @@ -49,8 +51,9 @@ public static OffsetDateTime toOffsetDateTime(String sqlValue) {
*
* @return The string or {@code null} if the input was {@code null}.
*/
@Nullable
@TypeConverter
public static String fromOffsetDateTime(OffsetDateTime dateTime) {
public static String fromOffsetDateTime(@Nullable OffsetDateTime dateTime) {
if (dateTime == null) {
return null;
} else {
Expand Down
3 changes: 2 additions & 1 deletion app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
<string name="channel_sko_desc">Meldingen over de Student Kick-Off</string>
<string name="channel_urgent">Urgent.fm</string>
<string name="channel_urgent_desc">Meldingen over Urgent.fm, inclusief de mediamelding voor de radiospeler.</string>

<string name="minerva_course_details_tabs_overview">Info</string>
<string name="minerva_course_details_tabs_announcements">Aankondigingen</string>
<string name="minerva_course_details_tabs_calendar">Agenda</string>
Expand Down Expand Up @@ -435,4 +435,5 @@
<string name="minerva_exporting_account_desc">De details van uw Minerva-account worden geëxporteerd.</string>
<string name="card_title_hide_card">Alleen deze kaart verbergen</string>
<string name="card_title_hide_single_type">Deze kaart verbergen</string>
<string name="date_unknown">Onbekend</string>
</resources>

0 comments on commit eaa4b50

Please sign in to comment.