From fb52d4adc17e1337e71ef0219c41ac9059c76002 Mon Sep 17 00:00:00 2001 From: Jean Luis Urena Date: Tue, 28 Aug 2018 12:55:03 -0400 Subject: [PATCH] Fixed bug with overlapping labs in courses --- ritscheduler/release/output.json | 1 + .../java/me/jlurena/ritscheduler/Home.java | 23 +++++----- .../fragments/CourseCardFragment.java | 11 ++--- .../homescreen/WidgetProvider.java | 2 +- .../homescreen/WidgetRemoteViewsFactory.java | 6 +-- .../jlurena/ritscheduler/models/Meeting.java | 13 ++++-- .../me/jlurena/ritscheduler/utils/Utils.java | 43 ++++++++++++++++++- .../res/layout/preference_about_dialog.xml | 5 +-- ritscheduler/src/main/res/values/strings.xml | 3 +- ritscheduler/src/main/res/values/styles.xml | 1 + 10 files changed, 72 insertions(+), 36 deletions(-) create mode 100644 ritscheduler/release/output.json diff --git a/ritscheduler/release/output.json b/ritscheduler/release/output.json new file mode 100644 index 0000000..4507469 --- /dev/null +++ b/ritscheduler/release/output.json @@ -0,0 +1 @@ +[{"outputType":{"type":"APK"},"apkInfo":{"type":"MAIN","splits":[],"versionCode":1,"versionName":"1.0","enabled":true,"outputFile":"ritscheduler-release.apk","fullName":"release","baseName":"release"},"path":"ritscheduler-release.apk","properties":{}}] \ No newline at end of file diff --git a/ritscheduler/src/main/java/me/jlurena/ritscheduler/Home.java b/ritscheduler/src/main/java/me/jlurena/ritscheduler/Home.java index 401abc3..fa3ae60 100644 --- a/ritscheduler/src/main/java/me/jlurena/ritscheduler/Home.java +++ b/ritscheduler/src/main/java/me/jlurena/ritscheduler/Home.java @@ -6,6 +6,7 @@ import android.app.FragmentManager; import android.app.FragmentTransaction; import android.content.Context; +import android.content.Intent; import android.graphics.Rect; import android.os.Bundle; import android.os.Handler; @@ -51,6 +52,7 @@ import me.jlurena.ritscheduler.database.DataManager; import me.jlurena.ritscheduler.fragments.CourseCardFragment; import me.jlurena.ritscheduler.fragments.SettingsFragment; +import me.jlurena.ritscheduler.homescreen.WidgetProvider; import me.jlurena.ritscheduler.models.Course; import me.jlurena.ritscheduler.models.Term; import me.jlurena.ritscheduler.networking.NetworkManager; @@ -163,13 +165,7 @@ public void getResult(List courses, int errorCode, VolleyError error) { mBoomMenuButton.reboom(); } } else { - AlertDialog.Builder dialog = Utils.alertDialogFactory(Home.this, R.string.error, null); - - if (error != null) { - dialog.setMessage(error.getMessage()).show(); - } else { - dialog.setMessage(R.string.generic_error).show(); - } + Utils.genericAlertDialogError(Home.this, error); queryResult.clear(); } image.clearAnimation(); @@ -201,7 +197,12 @@ private void initCalendar() { if (courses != null && !courses.isEmpty()) { for (Course course : courses) { - events.addAll(course.toWeekViewEvents()); + try { + events.addAll(course.toWeekViewEvents()); + } catch (Exception e) { + AlertDialog.Builder dialogBuilder = Utils.alertDialogFactory(Home.this, R.string.error, null); + Utils.genericAlertDialogError(Home.this, e); + } } } @@ -509,10 +510,10 @@ public void addCourseButton(Course course) { dataManager.addModel(course); courses.add(course); mWeekView.notifyDatasetChanged(); + sendBroadcast(new Intent(WidgetProvider.ACTION_REFRESH)); removeFragment(course.getModelId()); - } catch (CouchbaseLiteException e) { - Utils.alertDialogFactory(this, R.string.error, getString(R.string.save_error)).show(); - } finally { + } catch (Exception e) { + Utils.genericAlertDialogError(this, e); enableBackground(); queryResult.clear(); } diff --git a/ritscheduler/src/main/java/me/jlurena/ritscheduler/fragments/CourseCardFragment.java b/ritscheduler/src/main/java/me/jlurena/ritscheduler/fragments/CourseCardFragment.java index 0ead66f..cc95eed 100644 --- a/ritscheduler/src/main/java/me/jlurena/ritscheduler/fragments/CourseCardFragment.java +++ b/ritscheduler/src/main/java/me/jlurena/ritscheduler/fragments/CourseCardFragment.java @@ -216,11 +216,6 @@ private void initCourseCardDetails() { } else { tv.setText(Html.fromHtml(professors, Html.FROM_HTML_MODE_COMPACT)); } - if (Build.VERSION.SDK_INT > 22) { - tv.setLinkTextColor(getResources().getColor(android.R.color.holo_blue_dark, null)); - } else { - tv.setLinkTextColor(getResources().getColor(android.R.color.holo_blue_dark)); - } tv.setMovementMethod(LinkMovementMethod.getInstance()); this.mCourseDetailsLayout.addView(tv); @@ -277,7 +272,7 @@ public static CourseCardFragment newInstance(Context context, Course course, boo args.putBoolean(ARG_PARAM2, isSavedCourse); fragment.setArguments(args); } catch (JsonProcessingException e) { - Utils.alertDialogFactory(context, R.string.error, context.getString(R.string.generic_error)).show(); + Utils.genericAlertDialogError(context, e); } return fragment; } @@ -302,7 +297,7 @@ public void onCreate(Bundle savedInstanceState) { this.currentColor = this.course.getColor(); } } catch (IOException e) { - Utils.alertDialogFactory(getActivity(), R.string.error, getString(R.string.generic_error)).show(); + Utils.genericAlertDialogError(getActivity(), e); } } } @@ -317,7 +312,7 @@ public View onCreateView(LayoutInflater inflater, ViewGroup container, this.isSavedCourse = getArguments().getBoolean(ARG_PARAM2); } } catch (IOException e) { - Utils.alertDialogFactory(getActivity(), R.string.error, getString(R.string.generic_error)).show(); + Utils.genericAlertDialogError(getActivity(), e); } this.currentColor = this.course.getColor() != 0 ? this.course.getColor() : getResources().getColor(R.color.color_primary); diff --git a/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetProvider.java b/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetProvider.java index 605b3f8..72288d3 100644 --- a/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetProvider.java +++ b/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetProvider.java @@ -22,7 +22,7 @@ */ public class WidgetProvider extends AppWidgetProvider { - static final String ACTION_REFRESH = "me.jlurena.ritscheduler.action.ACTION_REFRESH"; + public static final String ACTION_REFRESH = "me.jlurena.ritscheduler.action.ACTION_REFRESH"; static final String ACTION_NEXT = "me.jlurena.ritscheduler.action.ACTION_NEXT"; static final String ACTION_PREVIOUS = "me.jlurena.ritscheduler.action.ACTION_PREVIOUS"; static final String KEY_SIZE_CHANGE = "size_change"; diff --git a/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetRemoteViewsFactory.java b/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetRemoteViewsFactory.java index ac68e93..275746c 100644 --- a/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetRemoteViewsFactory.java +++ b/ritscheduler/src/main/java/me/jlurena/ritscheduler/homescreen/WidgetRemoteViewsFactory.java @@ -21,7 +21,6 @@ import java.util.ArrayList; import java.util.Calendar; -import java.util.HashSet; import java.util.List; import java.util.Locale; @@ -37,8 +36,8 @@ public class WidgetRemoteViewsFactory extends BroadcastReceiver implements Remot private final Context context; private final DataManager dataManager; - private final HashSet courses; private final SettingsManager settings; + private List courses; private WeekView weekView; private Calendar currentDay; private int width; @@ -47,7 +46,6 @@ public class WidgetRemoteViewsFactory extends BroadcastReceiver implements Remot this.context = context; this.dataManager = DataManager.getInstance(context); this.currentDay = Calendar.getInstance(); - this.courses = new HashSet<>(); this.width = Util.dp2px(110); IntentFilter filter = new IntentFilter(); @@ -61,7 +59,7 @@ public class WidgetRemoteViewsFactory extends BroadcastReceiver implements Remot private void updateCourseList(@Nullable String action) { try { - dataManager.getModels(Course.TYPE, Course.class, (DataManager.DocumentParser>) courses::addAll); + dataManager.getModels(Course.TYPE, Course.class, (DataManager.DocumentParser>) models -> courses = models); } catch (CouchbaseLiteException e) { // Can't really do anything but crash gracefully diff --git a/ritscheduler/src/main/java/me/jlurena/ritscheduler/models/Meeting.java b/ritscheduler/src/main/java/me/jlurena/ritscheduler/models/Meeting.java index aeb52a3..e98662f 100644 --- a/ritscheduler/src/main/java/me/jlurena/ritscheduler/models/Meeting.java +++ b/ritscheduler/src/main/java/me/jlurena/ritscheduler/models/Meeting.java @@ -1,6 +1,7 @@ package me.jlurena.ritscheduler.models; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonProperty; import org.threeten.bp.DayOfWeek; @@ -21,6 +22,7 @@ */ @SuppressWarnings("ConstantConditions") +@JsonIgnoreProperties(ignoreUnknown = true) public class Meeting { private String[] days; @@ -204,7 +206,8 @@ public boolean isTimeTBA() { public List toWeekViewEvents() { - int length = this.days.length; + int daysLen = this.daysFull.length; + int timesLen = this.times.length; // Days length will always equal the number of times meeting takes place ArrayList events = new ArrayList<>(); @@ -214,11 +217,13 @@ public List toWeekViewEvents() { DayTime start, end; WeekViewEvent event; String[] locations = getLocationsShortForEachDayTime(); - for (int i = 0; i < length; i++) { + for (int i = 0, j = 0; i < daysLen; i++, j++) { String[] days = this.daysFull[i].split(" "); - + if (j >= timesLen) { + j--; + } // Parse hours - splitTime = this.times[i].split(" - "); + splitTime = this.times[j].split(" - "); startTime = LocalTime.parse(splitTime[0], Utils.STANDARD_TIME_FORMAT); endTime = LocalTime.parse(splitTime[1], Utils.STANDARD_TIME_FORMAT); diff --git a/ritscheduler/src/main/java/me/jlurena/ritscheduler/utils/Utils.java b/ritscheduler/src/main/java/me/jlurena/ritscheduler/utils/Utils.java index 7592e8f..3c3ffe7 100644 --- a/ritscheduler/src/main/java/me/jlurena/ritscheduler/utils/Utils.java +++ b/ritscheduler/src/main/java/me/jlurena/ritscheduler/utils/Utils.java @@ -1,22 +1,29 @@ package me.jlurena.ritscheduler.utils; import android.app.AlertDialog; +import android.content.ActivityNotFoundException; import android.content.Context; +import android.content.Intent; import android.content.res.ColorStateList; import android.graphics.Color; import android.graphics.drawable.ColorDrawable; import android.graphics.drawable.Drawable; import android.graphics.drawable.RippleDrawable; +import android.net.Uri; +import android.os.Build; import android.support.annotation.ColorInt; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; +import android.text.TextUtils; import android.view.ViewGroup; import android.view.ViewGroupOverlay; import org.threeten.bp.LocalDateTime; import org.threeten.bp.format.DateTimeFormatter; +import me.jlurena.ritscheduler.R; + public class Utils { public static final LocalDateTime now = LocalDateTime.now(); @@ -51,12 +58,44 @@ public static void clearDim(@NonNull ViewGroup parent) { overlay.clear(); } - public static RippleDrawable getPressedColorRippleDrawable(@ColorInt int pressedColor) { - return new RippleDrawable(new ColorStateList(new int[][]{new int[]{}}, new int[]{pressedColor}), new ColorDrawable(pressedColor), null); + public static void genericAlertDialogError(Context context, Exception exc) { + String body = "Phone: " + Build.MODEL + + "\nBuild Version: " + Build.VERSION.SDK_INT; + if (exc != null) { + body += "\nError: " + exc.getMessage() + + " \nError Log:\n\n\n\t\t" + TextUtils.join("\n\t\t", exc.getStackTrace()); + } + final Intent intent = new Intent(Intent.ACTION_SEND); + intent.setData(Uri.parse("mailto:")); + intent.putExtra(Intent.EXTRA_EMAIL, new String[]{"eljean@live.com"}); + intent.putExtra(Intent.EXTRA_SUBJECT, "RIT Scheduler Error Report"); + intent.putExtra(Intent.EXTRA_TEXT, body); + + new AlertDialog.Builder(context) + .setTitle(R.string.error) + .setMessage(R.string.generic_error) + .setPositiveButton(R.string.close, (d, which) -> d.dismiss()) + .setNeutralButton("Report", (d, which) -> { + try { + context.startActivity(intent); + } catch (ActivityNotFoundException e) { + try { + intent.setAction(Intent.ACTION_SENDTO); + context.startActivity(intent); + } catch (ActivityNotFoundException ex) { + context.startActivity(Intent.createChooser(intent, "Send Report Using:")); + } + } + }) + .show(); } public static RippleDrawable getPressedColorRippleDrawable(@ColorInt int pressedColor, Drawable drawable) { return new RippleDrawable(new ColorStateList(new int[][]{new int[]{}}, new int[]{pressedColor}), drawable, null); } + public static RippleDrawable getPressedColorRippleDrawable(@ColorInt int pressedColor) { + return new RippleDrawable(new ColorStateList(new int[][]{new int[]{}}, new int[]{pressedColor}), new ColorDrawable(pressedColor), null); + } + } diff --git a/ritscheduler/src/main/res/layout/preference_about_dialog.xml b/ritscheduler/src/main/res/layout/preference_about_dialog.xml index 253479b..a63f07d 100644 --- a/ritscheduler/src/main/res/layout/preference_about_dialog.xml +++ b/ritscheduler/src/main/res/layout/preference_about_dialog.xml @@ -59,7 +59,6 @@ android:layout_gravity="end" android:linksClickable="true" android:text="@string/developer_name" - android:textColorLink="@android:color/holo_blue_dark" app:layout_constraintEnd_toEndOf="parent" /> @@ -90,8 +88,7 @@ android:layout_height="wrap_content" android:layout_gravity="end" android:linksClickable="true" - android:text="@string/github_repo" - android:textColorLink="@android:color/holo_blue_dark" /> + android:text="@string/github_repo" /> diff --git a/ritscheduler/src/main/res/values/strings.xml b/ritscheduler/src/main/res/values/strings.xml index 54ab20e..340fc83 100644 --- a/ritscheduler/src/main/res/values/strings.xml +++ b/ritscheduler/src/main/res/values/strings.xml @@ -13,8 +13,6 @@ Error No results found. - Something weird happened. Try again later. - Unable to save this course. Please try again later. Error retrieving saved courses. Confirm Unable to delete this course. Please try again later. @@ -83,6 +81,7 @@ Open Sourced At Report bugs and new features:\neljean@live.com Close + Something weird happened. Please try again later. If the issue persists, please submit a report diff --git a/ritscheduler/src/main/res/values/styles.xml b/ritscheduler/src/main/res/values/styles.xml index e91b65d..6064b84 100644 --- a/ritscheduler/src/main/res/values/styles.xml +++ b/ritscheduler/src/main/res/values/styles.xml @@ -5,6 +5,7 @@ @color/color_primary @color/color_primary_dark @color/color_accent + @android:color/holo_blue_dark @style/spinnerItemStyle