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

Commit

Permalink
fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
itning committed Feb 10, 2019
1 parent 1f01cf8 commit cc6635a
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 52 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 46
versionName "2.4.1-BETA"
versionCode 47
versionName "2.4.2-BETA"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
javaCompileOptions {
annotationProcessorOptions {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {

private lateinit var msg: String
private var classSchedule = 5
private var timeMap: TreeMap<String, String> = TreeMap()
private var timeMap: TreeMap<Int, String> = TreeMap()

override fun onCreate(savedInstanceState: Bundle?) {
ThemeChangeUtil.changeTheme(this)
Expand All @@ -59,17 +59,17 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {
App.sharedPreferences.edit().putString("3", "12:55-14:25").commit()
App.sharedPreferences.edit().putString("4", "14:40-16:10").commit()
App.sharedPreferences.edit().putString("5", "17:30-20:00").commit()
App.sharedPreferences.edit().putString("6", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("7", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("8", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("9", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("10", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("11", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("12", "12:00-12:01").commit()
App.sharedPreferences.edit().putString("6", "20:05-20:08").commit()
App.sharedPreferences.edit().putString("7", "20:10-20:15").commit()
App.sharedPreferences.edit().putString("8", "20:18-20:20").commit()
App.sharedPreferences.edit().putString("9", "20:30-20:35").commit()
App.sharedPreferences.edit().putString("10", "20:40-20:45").commit()
App.sharedPreferences.edit().putString("11", "20:50-21:01").commit()
App.sharedPreferences.edit().putString("12", "21:10-21:15").commit()
}
timeMap.clear()
for (i in 1..classSchedule) {
timeMap[i.toString()] = App.sharedPreferences.getString(i.toString(), "12:00-12:01")!!
timeMap[i] = App.sharedPreferences.getString(i.toString(), "12:00-12:01")!!
}
}

Expand All @@ -79,16 +79,16 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {
private fun setText(key: String = "") {
if (key == "") {
for (i in 1..classSchedule) {
val a = timeMap[i.toString()]!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
val a = timeMap[i]!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
getOneClass(i.toString(), a[0], a[1])
}
} else {
val up = ll.findViewWithTag<RelativeLayout>("$key-s")
val down = ll.findViewWithTag<RelativeLayout>("$key-x")
val upView: AppCompatTextView = up.getChildAt(1) as AppCompatTextView
val downView: AppCompatTextView = down.getChildAt(1) as AppCompatTextView
upView.text = timeMap[key]!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0]
downView.text = timeMap[key]!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
upView.text = timeMap[key.toInt()]!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0]
downView.text = timeMap[key.toInt()]!!.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
}
}

Expand Down Expand Up @@ -125,8 +125,8 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {
}

private fun getOneClass(classText: CharSequence, upTime: CharSequence, downTime: CharSequence) {
val up = getOneRowRelativeLayout("${classText}节上课", upTime, View.OnClickListener { onViewClicked("$classText-s", it) })
val down = getOneRowRelativeLayout("${classText}节下课", downTime, View.OnClickListener { onViewClicked("$classText-x", it) })
val up = getOneRowRelativeLayout("${classText}节上课", upTime, View.OnClickListener { onViewClicked("$classText-s") })
val down = getOneRowRelativeLayout("${classText}节下课", downTime, View.OnClickListener { onViewClicked("$classText-x") })
up.tag = "$classText-s"
down.tag = "$classText-x"
ll.addView(up)
Expand Down Expand Up @@ -209,7 +209,7 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {
private fun updateSharedPreferences() {
val edit = App.sharedPreferences.edit()
for ((key, value) in timeMap) {
edit.putString(key, value)
edit.putString(key.toString(), value)
}
edit.apply()
DateUtils.refreshTimeList()
Expand All @@ -220,7 +220,7 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {

}

private fun onViewClicked(id: String, view: View) {
private fun onViewClicked(id: String) {
this.msg = id
showTimePickerDialog()
}
Expand All @@ -236,7 +236,7 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {
} else {
stringBuilder.append("下课")
}
val timePickerDialog = getTimePickerDialog(type[1], timeMap[type[0]]!!)
val timePickerDialog = getTimePickerDialog(type[1], timeMap[type[0].toInt()]!!)
timePickerDialog.title = stringBuilder.toString()
timePickerDialog.show(fragmentManager, "TimePickerDialog")
}
Expand Down Expand Up @@ -285,15 +285,15 @@ class CustomActivity : BaseActivity(), TimePickerDialog.OnTimeSetListener {
m = "0$m"
}
val time = "$h:$m"
val s = timeMap[typeInfo[0]] ?: return
val s = timeMap[typeInfo[0].toInt()] ?: return
if ("" != s) {
val insertStr: String = if (CLASS_UP == typeInfo[1]) {
time + "-" + s.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[1]
} else {
s.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()[0] + "-" + time
}
Log.d(TAG, "insert :$insertStr")
timeMap[typeInfo[0]] = insertStr
timeMap[typeInfo[0].toInt()] = insertStr
setText(typeInfo[0])
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,23 +125,19 @@ class LoginActivity : BaseActivity() {
.setTitle("警告")
.setMessage("即将导入课程数据,这会将原有课程信息清空,确定导入吗?")
.setPositiveButton("确定") { _, _ ->
val timeMap = TreeMap<String, String>()
timeMap["1"] = timeList[0]
timeMap["2"] = timeList[1]
timeMap["3"] = timeList[2]
timeMap["4"] = timeList[3]
timeMap["5"] = timeList[4]
val timeMap = TreeMap<Int, String>()
for ((index, value) in timeList.withIndex()) {
timeMap[index + 1] = value
}
if (!DateUtils.isDataLegitimate(timeMap, this)) {
Toast.makeText(this, "解析失败", Toast.LENGTH_LONG).show()
return@setPositiveButton
}
if (App.sharedPreferences.edit()
.putString("1", timeList[0])
.putString("2", timeList[1])
.putString("3", timeList[2])
.putString("4", timeList[3])
.putString("5", timeList[4])
.commit()) {
val edit = App.sharedPreferences.edit()
for ((index, value) in timeList.withIndex()) {
edit.putString((index + 1).toString(), value)
}
if (edit.commit()) {
DateUtils.refreshTimeList()
} else {
Toast.makeText(this, "解析失败", Toast.LENGTH_LONG).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,23 +211,19 @@ class ShareActivity : BaseActivity() {
.setTitle("警告")
.setMessage("即将导入课程数据,这会将原有课程信息清空,确定导入吗?")
.setPositiveButton("确定") { _, _ ->
val timeMap = TreeMap<String, String>()
timeMap["1"] = timeList[0]
timeMap["2"] = timeList[1]
timeMap["3"] = timeList[2]
timeMap["4"] = timeList[3]
timeMap["5"] = timeList[4]
val timeMap = TreeMap<Int, String>()
for ((index, value) in timeList.withIndex()) {
timeMap[index + 1] = value
}
if (!DateUtils.isDataLegitimate(timeMap, this)) {
Toast.makeText(this, "解析失败", Toast.LENGTH_LONG).show()
return@setPositiveButton
}
if (App.sharedPreferences.edit()
.putString("1", timeList[0])
.putString("2", timeList[1])
.putString("3", timeList[2])
.putString("4", timeList[3])
.putString("5", timeList[4])
.commit()) {
val edit = App.sharedPreferences.edit()
for ((index, value) in timeList.withIndex()) {
edit.putString((index + 1).toString(), value)
}
if (edit.commit()) {
DateUtils.refreshTimeList()
} else {
Toast.makeText(this, "解析失败", Toast.LENGTH_LONG).show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.content.Context
import android.util.Log
import androidx.annotation.CheckResult
import androidx.appcompat.app.AlertDialog
import androidx.preference.PreferenceManager
import top.itning.yunshuclassschedule.common.App
import top.itning.yunshuclassschedule.common.ConstantPool
import top.itning.yunshuclassschedule.entity.ClassSchedule
import top.itning.yunshuclassschedule.ui.fragment.setting.SettingsFragment
import java.text.ParseException
import java.text.SimpleDateFormat
import java.util.*
Expand Down Expand Up @@ -220,21 +222,23 @@ object DateUtils {
*
* @return 合法返回真
*/
fun isDataLegitimate(timeMap: TreeMap<String, String>, context: Context): Boolean {
var lastEntry: Map.Entry<String, String>? = null
fun isDataLegitimate(timeMap: TreeMap<Int, String>, context: Context): Boolean {
val nowWeekNum = PreferenceManager.getDefaultSharedPreferences(context).getString(SettingsFragment.NOW_WEEK_NUM, "1")
var lastEntry: Map.Entry<Int, String>? = null
for (entry in timeMap.entries) {
val timeArray = entry.value.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
//检查每节课上下课时间合法性
Log.e(TAG, "${timeArray[0]} ${timeArray[1]}")
if (DateUtils.isTimeIintervalLegitimate(timeArray[0], timeArray[1])) {
Log.d(TAG, "error1: " + timeArray[0] + "-->" + timeArray[1])
showTimeErrorDialog(entry.key, 1, context)
showTimeErrorDialog(entry.key.toString(), 1, context)
return false
}
if (lastEntry != null && "5" != entry.key) {
if (lastEntry != null && nowWeekNum != entry.key.toString()) {
val lastTimeArray = lastEntry.value.split("-".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray()
if (DateUtils.isTimeIintervalLegitimate(lastTimeArray[1], timeArray[0])) {
Log.d(TAG, "error2: " + lastTimeArray[1] + "-->" + timeArray[0])
showTimeErrorDialog(lastEntry.key, 2, context)
showTimeErrorDialog(lastEntry.key.toString(), 2, context)
return false
}
}
Expand Down

0 comments on commit cc6635a

Please sign in to comment.