Skip to content
This repository has been archived by the owner on Mar 4, 2022. It is now read-only.

Commit

Permalink
FIX:IndexOut Exception
Browse files Browse the repository at this point in the history
  • Loading branch information
itning committed Feb 27, 2019
1 parent cf71815 commit a99842d
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 5 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ android {
applicationId "top.itning.yunshuclassschedule"
minSdkVersion 21
targetSdkVersion 28
versionCode 56
versionName "2.5.0"
versionCode 57
versionName "2.5.1"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,12 @@ class CourseInfoService : Service(), SharedPreferences.OnSharedPreferenceChangeL
@CheckResult
get() {
val nowWeekNum = (PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsFragment.NOW_WEEK_NUM, "1")!!.toInt() - 1).toString()
val section = App.sharedPreferences.getInt(ConstantPool.Str.CLASS_SECTION.get(), 5)
return classScheduleDao
.queryBuilder()
.where(ClassScheduleDao.Properties.Week.eq(DateUtils.week))
.list()
.filter { it.section <= section }
.any { ClassScheduleUtils.isThisWeekOfClassSchedule(it, nowWeekNum) }
}

Expand Down Expand Up @@ -143,11 +145,13 @@ class CourseInfoService : Service(), SharedPreferences.OnSharedPreferenceChangeL
@CheckResult
get() {
val nowWeekNum = (PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsFragment.NOW_WEEK_NUM, "1")!!.toInt() - 1).toString()
val section = App.sharedPreferences.getInt(ConstantPool.Str.CLASS_SECTION.get(), 5)
val classScheduleList = classScheduleDao
.queryBuilder()
.where(ClassScheduleDao.Properties.Week.eq(DateUtils.week))
.list()
.filter { ClassScheduleUtils.isThisWeekOfClassSchedule(it, nowWeekNum) }
.filter { it.section <= section }
.toMutableList()
classScheduleList.sortWith(Comparator { a, b -> Integer.compare(a.section, b.section) })
return classScheduleList
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,12 +212,14 @@ class RemindService : Service(), SharedPreferences.OnSharedPreferenceChangeListe
Log.d(TAG, "init class schedule list data")
val nowWeekNum = (PreferenceManager.getDefaultSharedPreferences(this).getString(SettingsFragment.NOW_WEEK_NUM, "1")!!.toInt() - 1).toString()
val daoSession = (application as App).daoSession
val section = App.sharedPreferences.getInt(ConstantPool.Str.CLASS_SECTION.get(), 5)
classScheduleList = daoSession
.classScheduleDao
.queryBuilder()
.where(ClassScheduleDao.Properties.Week.eq(DateUtils.week))
.list()
.filter { ClassScheduleUtils.isThisWeekOfClassSchedule(it, nowWeekNum) }
.filter { it.section <= section }
.toMutableList()
Log.d(TAG, "init class schedule list size:" + classScheduleList.size)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,18 @@ class LoginActivity : BaseActivity() {
Toast.makeText(this, "解析失败", Toast.LENGTH_LONG).show()
return
}
val timeListSize = timeList.size
val classScheduleMaxSection = classScheduleList.map { it.section }.max() ?: 12
if (timeListSize > 12 || classScheduleMaxSection > 12) {
Toast.makeText(this, "最大课程数为12节课,解析失败", Toast.LENGTH_LONG).show()
return
}
Log.d(TAG, "classScheduleMaxSection: $classScheduleMaxSection timeListSize: $timeListSize")
val section = if (timeListSize < classScheduleMaxSection) {
classScheduleMaxSection
} else {
timeListSize
}
AlertDialog.Builder(this)
.setTitle("警告")
.setMessage("即将导入课程数据,这会将原有课程信息清空,确定导入吗?")
Expand Down Expand Up @@ -159,8 +171,15 @@ class LoginActivity : BaseActivity() {
classScheduleList.forEach { classScheduleDao.insert(it) }
EventBus.getDefault().post(EventEntity(ConstantPool.Int.TIME_TICK_CHANGE, ""))
if (classScheduleList.size.toLong() == classScheduleDao.count()) {
Toast.makeText(this, "导入成功", Toast.LENGTH_LONG).show()
enterMainActivity()
if (App.sharedPreferences.edit()
.putInt(ConstantPool.Str.CLASS_SECTION.get(), section)
.commit()) {
DateUtils.refreshTimeList()
Toast.makeText(this, "导入成功", Toast.LENGTH_LONG).show()
enterMainActivity()
} else {
Toast.makeText(this, "写入课程节数失败,请重试", Toast.LENGTH_LONG).show()
}
} else {
Toast.makeText(this, "写入数据库失败,请重试", Toast.LENGTH_LONG).show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,18 @@ class ShareActivity : BaseActivity() {
Toast.makeText(this, "解析失败", Toast.LENGTH_LONG).show()
return
}
val timeListSize = timeList.size
val classScheduleMaxSection = classScheduleList.map { it.section }.max() ?: 12
if (timeListSize > 12 || classScheduleMaxSection > 12) {
Toast.makeText(this, "最大课程数为12节课,解析失败", Toast.LENGTH_LONG).show()
return
}
Log.d(TAG, "classScheduleMaxSection: $classScheduleMaxSection timeListSize: $timeListSize")
val section = if (timeListSize < classScheduleMaxSection) {
classScheduleMaxSection
} else {
timeListSize
}
AlertDialog.Builder(this)
.setTitle("警告")
.setMessage("即将导入课程数据,这会将原有课程信息清空,确定导入吗?")
Expand Down Expand Up @@ -234,7 +246,14 @@ class ShareActivity : BaseActivity() {
classScheduleList.forEach { classScheduleDao.insert(it) }
EventBus.getDefault().post(EventEntity(ConstantPool.Int.TIME_TICK_CHANGE, ""))
if (classScheduleList.size.toLong() == classScheduleDao.count()) {
Toast.makeText(this, "导入成功", Toast.LENGTH_LONG).show()
if (App.sharedPreferences.edit()
.putInt(ConstantPool.Str.CLASS_SECTION.get(), section)
.commit()) {
DateUtils.refreshTimeList()
Toast.makeText(this, "导入成功", Toast.LENGTH_LONG).show()
} else {
Toast.makeText(this, "写入课程节数失败,请重试", Toast.LENGTH_LONG).show()
}
} else {
Toast.makeText(this, "写入数据库失败,请重试", Toast.LENGTH_LONG).show()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -219,13 +219,15 @@ class TodayFragment : Fragment() {
private fun initClassScheduleListData() {
val nowWeekNum = (PreferenceManager.getDefaultSharedPreferences(context).getString(SettingsFragment.NOW_WEEK_NUM, "1")!!.toInt() - 1).toString()
val daoSession = (requireActivity().application as App).daoSession
val section = App.sharedPreferences.getInt(ConstantPool.Str.CLASS_SECTION.get(), 5)
classScheduleList = ClassScheduleUtils
.orderListBySection(daoSession
.classScheduleDao
.queryBuilder()
.where(ClassScheduleDao.Properties.Week.eq(DateUtils.week))
.list()
.filter { ClassScheduleUtils.isThisWeekOfClassSchedule(it, nowWeekNum) }
.filter { it.section <= section }
.toMutableList())
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.core.content.ContextCompat
import androidx.preference.PreferenceManager
import top.itning.yunshuclassschedule.R
import top.itning.yunshuclassschedule.common.App
import top.itning.yunshuclassschedule.common.ConstantPool
import top.itning.yunshuclassschedule.entity.ClassSchedule
import top.itning.yunshuclassschedule.entity.ClassScheduleDao
import top.itning.yunshuclassschedule.ui.fragment.setting.SettingsFragment
Expand Down Expand Up @@ -49,13 +50,15 @@ class ToadyRemoteViewsFactory(val context: Context, val intent: Intent?) : Remot
override fun onDataSetChanged() {
Log.d(TAG, "onDataSetChanged")
val nowWeekNum = (PreferenceManager.getDefaultSharedPreferences(context).getString(SettingsFragment.NOW_WEEK_NUM, "1")!!.toInt() - 1).toString()
val section = App.sharedPreferences.getInt(ConstantPool.Str.CLASS_SECTION.get(), 5)
orderListBySection = ClassScheduleUtils
.orderListBySection(daoSession
.classScheduleDao
.queryBuilder()
.where(ClassScheduleDao.Properties.Week.eq(DateUtils.week))
.list()
.filter { ClassScheduleUtils.isThisWeekOfClassSchedule(it, nowWeekNum) }
.filter { it.section <= section }
.toMutableList())

}
Expand Down

0 comments on commit a99842d

Please sign in to comment.