Skip to content

Commit

Permalink
Fixed bug with overlapping labs in courses
Browse files Browse the repository at this point in the history
  • Loading branch information
Jean Luis Urena committed Aug 28, 2018
1 parent 924e937 commit fb52d4a
Show file tree
Hide file tree
Showing 10 changed files with 72 additions and 36 deletions.
1 change: 1 addition & 0 deletions ritscheduler/release/output.json
Original file line number Diff line number Diff line change
@@ -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":{}}]
23 changes: 12 additions & 11 deletions ritscheduler/src/main/java/me/jlurena/ritscheduler/Home.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -163,13 +165,7 @@ public void getResult(List<Course> 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();
Expand Down Expand Up @@ -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);
}
}
}

Expand Down Expand Up @@ -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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
}
Expand All @@ -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);
}
}
}
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;

Expand All @@ -37,8 +36,8 @@ public class WidgetRemoteViewsFactory extends BroadcastReceiver implements Remot

private final Context context;
private final DataManager dataManager;
private final HashSet<Course> courses;
private final SettingsManager settings;
private List<Course> courses;
private WeekView weekView;
private Calendar currentDay;
private int width;
Expand All @@ -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();
Expand All @@ -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<List<Course>>) courses::addAll);
dataManager.getModels(Course.TYPE, Course.class, (DataManager.DocumentParser<List<Course>>) models -> courses = models);

} catch (CouchbaseLiteException e) {
// Can't really do anything but crash gracefully
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -21,6 +22,7 @@
*/

@SuppressWarnings("ConstantConditions")
@JsonIgnoreProperties(ignoreUnknown = true)
public class Meeting {

private String[] days;
Expand Down Expand Up @@ -204,7 +206,8 @@ public boolean isTimeTBA() {
public List<WeekViewEvent> 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<WeekViewEvent> events = new ArrayList<>();

Expand All @@ -214,11 +217,13 @@ public List<WeekViewEvent> 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);

Expand Down
Original file line number Diff line number Diff line change
@@ -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();
Expand Down Expand Up @@ -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[]{"[email protected]"});
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);
}

}
5 changes: 1 addition & 4 deletions ritscheduler/src/main/res/layout/preference_about_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -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" />

<TextView
Expand All @@ -68,7 +67,6 @@
android:autoLink="email"
android:lines="2"
android:text="@string/report_bugs_features"
android:textColorLink="@android:color/holo_blue_dark"
android:textSize="12sp"
app:layout_constraintTop_toBottomOf="@+id/developer_name" />
</android.support.constraint.ConstraintLayout>
Expand All @@ -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" />
</FrameLayout>


Expand Down
3 changes: 1 addition & 2 deletions ritscheduler/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@
<!--Errors-->
<string name="error">Error</string>
<string name="no_results_error">No results found.</string>
<string name="generic_error">Something weird happened. Try again later.</string>
<string name="save_error">Unable to save this course. Please try again later.</string>
<string name="error_retrieving_saved_courses">Error retrieving saved courses.</string>
<string name="confirm">Confirm</string>
<string name="delete_course_error">Unable to delete this course. Please try again later.</string>
Expand Down Expand Up @@ -83,6 +81,7 @@
<string name="open_sourced_at">Open Sourced At</string>
<string name="report_bugs_features">Report bugs and new features:\n<a href="[email protected]">[email protected]</a></string>
<string name="close">Close</string>
<string name="generic_error">Something weird happened. Please try again later. If the issue persists, please submit a report</string>

<!-- TODO: Remove or change this placeholder text -->

Expand Down
1 change: 1 addition & 0 deletions ritscheduler/src/main/res/values/styles.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<item name="colorPrimary">@color/color_primary</item>
<item name="colorPrimaryDark">@color/color_primary_dark</item>
<item name="colorAccent">@color/color_accent</item>
<item name="android:textColorLink">@android:color/holo_blue_dark</item>
<!--Spinner Items-->
<item name="android:spinnerItemStyle" parent="Base.Widget.AppCompat.Spinner.Underlined">
@style/spinnerItemStyle
Expand Down

0 comments on commit fb52d4a

Please sign in to comment.