Skip to content

Commit

Permalink
fix: 修复长按非本周课程显示内容错误的问题
Browse files Browse the repository at this point in the history
  • Loading branch information
dujiajun committed Apr 11, 2019
1 parent 3d7772b commit c88c66d
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/com/dujiajun/courseblock/CourseManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,10 +212,10 @@ public void onResponse(Call call, Response response) throws IOException {
});
}

public Course findCourseByDayAndStart(int day, int start) {
public Course findCourseByDayAndStart(int week, int day, int start) {
for (Course s :
courseList) {
if (s.getDay() == day && s.getStart() <= start && (s.getStart() + s.getStep() - 1) >= start)
if (s.getWeekList().contains(week) && s.getDay() == day && s.getStart() <= start && (s.getStart() + s.getStep() - 1) >= start)
return s;
}
return null;
Expand Down
20 changes: 13 additions & 7 deletions app/src/main/java/com/dujiajun/courseblock/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ public class MainActivity extends AppCompatActivity {
private TimetableView timetableView;
private WeekView weekView;
private int selectWeek = 0;
private int showWeek = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -43,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
cur_year = preferences.getString("cur_year", "2018");
cur_term = preferences.getString("cur_term", "3");
cur_week = preferences.getInt("cur_week", 1);
showWeek = cur_week;

timetableView = findViewById(R.id.id_timetableView);
weekView = findViewById(R.id.id_weekview);
Expand All @@ -53,6 +55,7 @@ protected void onCreate(Bundle savedInstanceState) {
timetableView.onDateBuildListener()
.onUpdateDate(cur, week);
timetableView.changeWeekOnly(week);
showWeek = week;
})
.callback(this::showCurrentWeekDialog)
.itemCount(CourseManager.MAX_WEEKS)
Expand All @@ -75,16 +78,16 @@ public void onSpaceItemClick(int day, int start) {
intent.putExtra("week", timetableView.curWeek());
intent.putExtra("action", CourseActivity.ACTION_INSERT);
startActivity(intent);
//Toast.makeText(MainActivity.this, String.valueOf(day)+" "+String.valueOf(start), Toast.LENGTH_SHORT).show();
}
})
.callback((ISchedule.OnItemLongClickListener) (v, day, start) -> {
Course c = courseManager.findCourseByDayAndStart(day, start);
Intent intent = new Intent(MainActivity.this, CourseActivity.class);
intent.putExtra("action", CourseActivity.ACTION_DETAIL);
intent.putExtra("course", c);
startActivity(intent);
//Toast.makeText(MainActivity.this, c.getCourseId()+c.getCourseName(), Toast.LENGTH_SHORT).show();
Course c = courseManager.findCourseByDayAndStart(showWeek, day, start);
if (c != null) {
Intent intent = new Intent(MainActivity.this, CourseActivity.class);
intent.putExtra("action", CourseActivity.ACTION_DETAIL);
intent.putExtra("course", c);
startActivity(intent);
}
});
if (show_time)
showTime();
Expand Down Expand Up @@ -118,6 +121,7 @@ private void showCurrentWeekDialog() {
SharedPreferences.Editor editor = preferences.edit();
editor.putInt("cur_week", selectWeek);
cur_week = selectWeek;
showWeek = cur_week;
weekView.curWeek(selectWeek).updateView();
timetableView.changeWeekOnly(selectWeek);
editor.apply();
Expand All @@ -134,6 +138,8 @@ protected void onResume() {
cur_term = preferences.getString("cur_term", "12");
cur_week = preferences.getInt("cur_week", 1);
timetableView.source(courseManager.getCourseList()).updateView();
showWeek = timetableView.curWeek();
weekView.source(courseManager.getCourseList()).updateView();
}

@Override
Expand Down

0 comments on commit c88c66d

Please sign in to comment.