-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
*.iml | ||
.gradle | ||
/local.properties | ||
/.idea/caches | ||
/.idea/libraries | ||
/.idea/modules.xml | ||
/.idea/workspace.xml | ||
/.idea/navEditor.xml | ||
/.idea/assetWizardSettings.xml | ||
.DS_Store | ||
/build | ||
/captures | ||
.externalNativeBuild | ||
.cxx | ||
local.properties |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
plugins { | ||
id("com.android.application") | ||
id("org.jetbrains.kotlin.android") | ||
} | ||
|
||
android { | ||
namespace = "com.uynaity.ezcc2" | ||
compileSdk = 33 | ||
|
||
defaultConfig { | ||
applicationId = "com.uynaity.ezcc2" | ||
minSdk = 26 | ||
targetSdk = 33 | ||
versionCode = 1 | ||
versionName = "1.0" | ||
|
||
testInstrumentationRunner = "androidx.test.runner.AndroidJUnitRunner" | ||
} | ||
|
||
buildTypes { | ||
release { | ||
isMinifyEnabled = false | ||
proguardFiles( | ||
getDefaultProguardFile("proguard-android-optimize.txt"), | ||
"proguard-rules.pro" | ||
) | ||
} | ||
} | ||
compileOptions { | ||
sourceCompatibility = JavaVersion.VERSION_1_8 | ||
targetCompatibility = JavaVersion.VERSION_1_8 | ||
} | ||
kotlinOptions { | ||
jvmTarget = "1.8" | ||
} | ||
} | ||
|
||
dependencies { | ||
|
||
implementation("androidx.core:core-ktx:1.9.0") | ||
implementation("androidx.appcompat:appcompat:1.6.1") | ||
implementation("com.google.android.material:material:1.9.0") | ||
implementation("androidx.constraintlayout:constraintlayout:2.1.4") | ||
implementation("org.jsoup:jsoup:1.16.1") | ||
testImplementation("junit:junit:4.13.2") | ||
androidTestImplementation("androidx.test.ext:junit:1.1.5") | ||
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1") | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Add project specific ProGuard rules here. | ||
# You can control the set of applied configuration files using the | ||
# proguardFiles setting in build.gradle. | ||
# | ||
# For more details, see | ||
# http://developer.android.com/guide/developing/tools/proguard.html | ||
|
||
# If your project uses WebView with JS, uncomment the following | ||
# and specify the fully qualified class name to the JavaScript interface | ||
# class: | ||
#-keepclassmembers class fqcn.of.javascript.interface.for.webview { | ||
# public *; | ||
#} | ||
|
||
# Uncomment this to preserve the line number information for | ||
# debugging stack traces. | ||
#-keepattributes SourceFile,LineNumberTable | ||
|
||
# If you keep the line number information, uncomment this to | ||
# hide the original source file name. | ||
#-renamesourcefileattribute SourceFile |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.uynaity.ezcc2 | ||
|
||
import androidx.test.platform.app.InstrumentationRegistry | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
|
||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
|
||
import org.junit.Assert.* | ||
|
||
/** | ||
* Instrumented test, which will execute on an Android device. | ||
* | ||
* See [testing documentation](http://d.android.com/tools/testing). | ||
*/ | ||
@RunWith(AndroidJUnit4::class) | ||
class ExampleInstrumentedTest { | ||
@Test | ||
fun useAppContext() { | ||
// Context of the app under test. | ||
val appContext = InstrumentationRegistry.getInstrumentation().targetContext | ||
assertEquals("com.uynaity.ezcc2", appContext.packageName) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="utf-8"?> | ||
<manifest xmlns:android="http://schemas.android.com/apk/res/android" | ||
xmlns:tools="http://schemas.android.com/tools"> | ||
<uses-permission android:name="android.permission.INTERNET" /> | ||
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" /> | ||
|
||
<application | ||
android:allowBackup="true" | ||
android:dataExtractionRules="@xml/data_extraction_rules" | ||
android:fullBackupContent="@xml/backup_rules" | ||
android:icon="@mipmap/ic_launcher" | ||
android:label="@string/app_name" | ||
android:roundIcon="@mipmap/ic_launcher_round" | ||
android:supportsRtl="true" | ||
android:theme="@style/Theme.EZCC2" | ||
tools:targetApi="31"> | ||
<activity | ||
android:name=".MainActivity" | ||
android:exported="true"> | ||
<intent-filter> | ||
<action android:name="android.intent.action.MAIN" /> | ||
|
||
<category android:name="android.intent.category.LAUNCHER" /> | ||
</intent-filter> | ||
</activity> | ||
</application> | ||
|
||
</manifest> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,162 @@ | ||
package com.uynaity.ezcc2 | ||
|
||
import android.annotation.SuppressLint | ||
import androidx.appcompat.app.AppCompatActivity | ||
import android.os.Bundle | ||
import android.widget.Button | ||
import android.widget.EditText | ||
import android.widget.TextView | ||
import android.widget.Toast | ||
import org.jsoup.Jsoup | ||
import java.net.HttpURLConnection | ||
import java.net.URL | ||
|
||
|
||
class MainActivity : AppCompatActivity() { | ||
private lateinit var courseCodeEditText: EditText | ||
private lateinit var searchButton: Button | ||
private lateinit var sem1Stat: TextView | ||
private lateinit var sem1Data: TextView | ||
private lateinit var sem2Stat: TextView | ||
private lateinit var sem2Data: TextView | ||
private var backPressedTime: Long = 0 | ||
private val backPressedInterval = 2000 | ||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
setContentView(R.layout.activity_main) | ||
courseCodeEditText = findViewById(R.id.courseCode) | ||
searchButton = findViewById(R.id.search) | ||
sem1Stat = findViewById(R.id.sem1Stat) | ||
sem1Data = findViewById(R.id.Sem1Data) | ||
sem2Stat = findViewById(R.id.Sem2Stat) | ||
sem2Data = findViewById(R.id.Sem2Data) | ||
searchButton.setOnClickListener { | ||
Thread { | ||
try { | ||
getTableData(courseCodeEditText.text.toString()) | ||
} catch (e: Exception) { | ||
sem1Stat.text = e.message | ||
} | ||
}.start() | ||
} | ||
} | ||
|
||
@Deprecated("Deprecated in Java") | ||
override fun onBackPressed() { | ||
if (System.currentTimeMillis() - backPressedTime < backPressedInterval) { | ||
super.onBackPressed() | ||
finishAffinity() | ||
} else { | ||
backPressedTime = System.currentTimeMillis() | ||
Toast.makeText(this, "再次点击返回键退出", Toast.LENGTH_SHORT).show() | ||
} | ||
} | ||
|
||
private fun getTableData(c: String?): MutableList<MutableList<Map<String, Any>>> { | ||
if (c == "") { | ||
runOnUiThread { | ||
Toast.makeText(this, "请输入课程代码", Toast.LENGTH_SHORT).show() | ||
} | ||
return mutableListOf() | ||
} | ||
val upC = c?.uppercase() | ||
val url = URL("https://sweb.hku.hk/ccacad/ccc_appl/enrol_stat.html") | ||
val conn = url.openConnection() as HttpURLConnection | ||
conn.requestMethod = "GET" | ||
val responseCode = conn.responseCode | ||
if (responseCode != 200) { | ||
runOnUiThread { | ||
sem1Stat.text = responseCode.toString() | ||
} | ||
return mutableListOf() | ||
} | ||
|
||
val doc = Jsoup.parse(url, 3000) | ||
val table = doc.select("table").first() | ||
|
||
val semList = mutableListOf( | ||
mutableListOf<Map<String, Any>>(), mutableListOf() | ||
) | ||
|
||
var sem = 0 | ||
|
||
for (row in table?.select("tr")!!) { | ||
val tds = row?.select("td") | ||
|
||
if (tds?.size!! < 6) { | ||
if (row.text() == "First Semester") { | ||
sem = 0 | ||
} else if (row.text() == "Second Semester") { | ||
sem = 1 | ||
} | ||
continue | ||
} | ||
|
||
if (!tds[0].text().contains(upC!!)) { | ||
continue | ||
} | ||
|
||
if (!tds[2].text().contains("X")) { | ||
val data1 = tds[0].text() | ||
val data2 = tds[4].text().toInt() | ||
val data3 = tds[5].text().toInt() | ||
var stat = "" | ||
|
||
if (data2 > data3) { | ||
stat = "尚有余,可选\n" | ||
} else if (data3 - data2 <= 3) { | ||
stat = "少量不足,可备选\n" | ||
} else if (data3 - data2 > 3) { | ||
stat = "严重不足,建议更换\n" | ||
} | ||
val dataSet = mapOf( | ||
"课程代码" to data1, | ||
"空余数量" to data2, | ||
"等待批准" to data3, | ||
"选课建议" to stat | ||
) | ||
semList[sem].add(dataSet) | ||
} | ||
} | ||
judgement(semList) | ||
return semList | ||
} | ||
|
||
|
||
@SuppressLint("SetTextI18n") | ||
private fun judgement(re: MutableList<MutableList<Map<String, Any>>>) { | ||
val semList = mutableListOf( | ||
sem1Data, sem2Data | ||
) | ||
val semStats = mutableListOf( | ||
sem1Stat, sem2Stat | ||
) | ||
for (index in re.indices) { | ||
val subList = re[index] | ||
if (subList.isEmpty()) { | ||
runOnUiThread { | ||
semStats[index].text = "未在Sem ${index + 1}中找到相关课程 :-(" | ||
} | ||
} else { | ||
runOnUiThread { | ||
semStats[index].text = "Sem ${index + 1}中找到以下相关课程:" | ||
} | ||
} | ||
runOnUiThread { | ||
semList[index].text = printSem(subList) | ||
} | ||
} | ||
} | ||
|
||
private fun printSem(sem: MutableList<Map<String, Any>>): String { | ||
var str = "" | ||
for (i in sem) { | ||
for (j in i) { | ||
str += "${j.key}: ${j.value}\n" | ||
} | ||
} | ||
str += "\n" | ||
return str | ||
} | ||
|
||
} |