From 326d29148b55e0c21d3456f09d2e3247633e11b0 Mon Sep 17 00:00:00 2001 From: Null Date: Wed, 1 Nov 2017 13:07:12 +0800 Subject: [PATCH] fix crash bug --- .idea/misc.xml | 2 +- .../schoolpower/activities/MainActivity.kt | 9 --------- .../schoolpower/data/AssignmentItem.kt | 8 ++++++-- .../schoolpower/fragments/AboutFragment.kt | 14 +++++++++++--- app/src/main/res/layout/about_content.xml | 1 + 5 files changed, 19 insertions(+), 15 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index d2e6725..ec177b1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -27,7 +27,7 @@ - + diff --git a/app/src/main/java/com/carbonylgroup/schoolpower/activities/MainActivity.kt b/app/src/main/java/com/carbonylgroup/schoolpower/activities/MainActivity.kt index 1cd79fe..dc3fdfd 100644 --- a/app/src/main/java/com/carbonylgroup/schoolpower/activities/MainActivity.kt +++ b/app/src/main/java/com/carbonylgroup/schoolpower/activities/MainActivity.kt @@ -227,15 +227,6 @@ class MainActivity : TransitionHelper.MainActivity(), NavigationView.OnNavigatio navigationView.getHeaderView(0).findViewById(R.id.nav_header_username).text = getUsername() navigationView.getHeaderView(0).findViewById(R.id.nav_header_id).text = getUserID() - - navigationView.getHeaderView(0).findViewById(R.id.SchoolPowerLogo).setOnLongClickListener { - val pref = getSharedPreferences("other", Activity.MODE_PRIVATE) - val spEditor = pref.edit() - spEditor.putBoolean("developer_mode", !pref.getBoolean("developer_mode", false)) - spEditor.apply() - utils.showSnackBar(this@MainActivity, findViewById(R.id.main_coordinate_layout), "Developer Mode: "+pref.getBoolean("developer_mode", false).toString(), false) - true - } } private fun initScheduler() { diff --git a/app/src/main/java/com/carbonylgroup/schoolpower/data/AssignmentItem.kt b/app/src/main/java/com/carbonylgroup/schoolpower/data/AssignmentItem.kt index a94dcc8..2f4c67a 100644 --- a/app/src/main/java/com/carbonylgroup/schoolpower/data/AssignmentItem.kt +++ b/app/src/main/java/com/carbonylgroup/schoolpower/data/AssignmentItem.kt @@ -38,7 +38,7 @@ Sample: */ class AssignmentItem(json: JSONObject) : Serializable { val title: String = json.getString("name") - val date: String = SimpleDateFormat("yyyy/MM/dd", Locale.CHINA).format(SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSSX", Locale.US).parse(json.getString("date"))) + var date: String val percentage: String = json.optString("percent", "--").replace("null", "--") // value like "86.96" or "--" val score: String = json.optString("score", "--").replace("null", "--") // value like "20" or "--" val maximumScore: String = json.getString("pointsPossible") // value like "23.0" @@ -47,7 +47,11 @@ class AssignmentItem(json: JSONObject) : Serializable { val includeInFinalGrade: Boolean = json.getString("includeInFinalGrade") == "1" val weight: String = json.getString("weight") //val term: String - + init{ + val temp = SimpleDateFormat("yyyy-MM-dd", Locale.CHINA).parse(json.getString("date").replace("T16:00:00.000Z", "")) + temp.time+=24*60*60*1000 + date = SimpleDateFormat("yyyy/MM/dd", Locale.CHINA).format(temp) + } var isNew = false fun getDividedScore() = "$score/$maximumScore" diff --git a/app/src/main/java/com/carbonylgroup/schoolpower/fragments/AboutFragment.kt b/app/src/main/java/com/carbonylgroup/schoolpower/fragments/AboutFragment.kt index a8a81a3..dbf6108 100644 --- a/app/src/main/java/com/carbonylgroup/schoolpower/fragments/AboutFragment.kt +++ b/app/src/main/java/com/carbonylgroup/schoolpower/fragments/AboutFragment.kt @@ -1,5 +1,6 @@ package com.carbonylgroup.schoolpower.fragments +import android.app.Activity import android.app.Fragment import android.content.Intent import android.graphics.Color @@ -9,6 +10,7 @@ import android.support.v4.content.ContextCompat import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.ImageView import android.widget.TextView import com.carbonylgroup.schoolpower.R import com.carbonylgroup.schoolpower.activities.MainActivity @@ -41,10 +43,16 @@ class AboutFragment : Fragment() { MainActivity.of(activity).expandToolBar(true, true) utils = Utils(activity) - (view.findViewById(R.id.about_version_label) as TextView) - .setText(activity.packageManager.getPackageInfo(activity.packageName, 0).versionName) + (view.findViewById(R.id.about_version_label) as TextView).text = activity.packageManager.getPackageInfo(activity.packageName, 0).versionName - view.findViewById(R.id.about_version_cell).setOnClickListener { } + view.findViewById(R.id.about_version_cell).setOnLongClickListener { + val pref = activity.getSharedPreferences("other", Activity.MODE_PRIVATE) + val spEditor = pref.edit() + spEditor.putBoolean("developer_mode", !pref.getBoolean("developer_mode", false)) + spEditor.apply() + utils.showSnackBar(activity, view.findViewById(R.id.about_content_parent), "Developer Mode: "+pref.getBoolean("developer_mode", false).toString(), false) + true + } view.findViewById(R.id.about_changelog_cell).setOnClickListener { startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.changelog_address)))) diff --git a/app/src/main/res/layout/about_content.xml b/app/src/main/res/layout/about_content.xml index fac9563..e298631 100644 --- a/app/src/main/res/layout/about_content.xml +++ b/app/src/main/res/layout/about_content.xml @@ -2,6 +2,7 @@