Removed outdated Q1 Matchmaker easter egg, fixed a few warnings in the SettingsFragment

This commit is contained in:
Deniz Düzgören
2019-07-23 21:42:56 +02:00
parent 0576ca0d1a
commit 2b5d03093b
10 changed files with 34 additions and 263 deletions
@@ -25,6 +25,7 @@ import org.jsoup.select.Elements
import java.lang.IndexOutOfBoundsException
import java.net.URL
import java.net.URLConnection
import java.text.DateFormat
import java.text.SimpleDateFormat
import java.util.*
import kotlin.collections.ArrayList
@@ -35,7 +36,7 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
private var plan = isplan
private var menu = ismenu
/* booleans to improve performance when fetching data
/* booleans to improve speed when fetching data
"plan" = true is required to fetch the substitution data
"menu" = true is required to fetch the food menu
"jobservice" = true is required to send a notification
@@ -48,7 +49,6 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
private var priority = 200
private var notifText = ""
private var informational = ""
private var foodList = ArrayList<String>()
private lateinit var connection: URLConnection
private lateinit var rows: Elements
private lateinit var paragraphs: Elements
@@ -154,16 +154,16 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
doc = Jsoup.connect("https://djd4rkn355.github.io/subst").get()
connection = URL("https://djd4rkn355.github.io/subst").openConnection()
edit.putString("time", connection.getHeaderField("Last-Modified")).apply()
d = Date(connection.getHeaderField("Last-Modified"))
d = sdf.parse(connection.getHeaderField("Last-Modified"))
rows = doc.select("tr")
paragraphs = doc.select("p")
val groupS = arrayOfNulls<String>(rows.size)
val dateS = arrayOfNulls<String>(rows.size)
val timeS = arrayOfNulls<String>(rows.size)
val courseS = arrayOfNulls<String>(rows.size)
val roomS = arrayOfNulls<String>(rows.size)
val additionalS = arrayOfNulls<String>(rows.size)
val groupS = ArrayList<String>()
val dateS = ArrayList<String>()
val timeS = ArrayList<String>()
val courseS = ArrayList<String>()
val roomS = ArrayList<String>()
val additionalS = ArrayList<String>()
mView?.let {
progressBar.max = rows.size
@@ -186,38 +186,38 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
val row = rows[i]
val cols = row.select("th") as Elements
groupS[i] = cols[0].text()
dateS[i] = cols[1].text()
timeS[i] = cols[2].text()
courseS[i] = cols[3].text()
roomS[i] = cols[4].text()
additionalS[i] = cols[5].text()
groupS.add(cols[0].text())
dateS.add(cols[1].text())
timeS.add(cols[2].text())
courseS.add(cols[3].text())
roomS.add(cols[4].text())
additionalS.add(cols[5].text())
if (!jobservice) {
mView?.let {
progressBar.incrementProgressBy(1)
}
}
val drawable = md.getIcon(courseS[i].toString())
val subst = Subst(drawable, groupS[i].toString(), dateS[i].toString(), timeS[i].toString(), courseS[i].toString(),
roomS[i].toString(), additionalS[i].toString(), priority)
val drawable = md.getIcon(courseS[i])
val subst = Subst(drawable, groupS[i], dateS[i], timeS[i], courseS[i],
roomS[i], additionalS[i], priority)
priority--
substViewModel.insertSubst(subst)
if (jobservice) {
if (prefs.getString("courses", "").isEmpty() && prefs.getString("classes", "").isNotEmpty()) {
if (groupS[i].toString().isNotEmpty() && !groupS[i].equals("")) {
if (prefs.getString("classes", "").contains(groupS[i].toString()) || groupS[i].toString().contains(prefs.getString("classes", "").toString())) {
if ((prefs.getString("courses", "") ?: "").isEmpty() && (prefs.getString("classes", "") ?: "").isNotEmpty()) {
if (groupS[i].isNotEmpty() && groupS[i] != "") {
if ((prefs.getString("classes", "") ?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "") ?: "").toString())) {
if (notifText.isNotEmpty()) {
notifText += ", "
}
notifText += courseS[i] + ": " + additionalS[i]
}
}
} else if (prefs.getString("classes", "").isNotEmpty() && prefs.getString("courses", "").isNotEmpty()) {
if (!groupS[i].equals("") && !courseS[i].equals("")) {
if (prefs.getString("courses", "").contains(courseS[i].toString())) {
if (prefs.getString("classes", "").contains(groupS[i].toString()) || groupS[i].toString().contains(prefs.getString("classes", "").toString())) {
} else if ((prefs.getString("classes", "") ?: "").isNotEmpty() && (prefs.getString("courses", "") ?: "").isNotEmpty()) {
if (groupS[i] != "" && courseS[i] != "") {
if ((prefs.getString("courses", "") ?: "").contains(courseS[i])) {
if ((prefs.getString("classes", "") ?: "").contains(groupS[i]) || groupS[i].contains((prefs.getString("classes", "") ?: "").toString())) {
if (notifText.isNotEmpty()) {
notifText += ", "
}
@@ -242,11 +242,10 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
val manager = mContext.getSystemService(Context.NOTIFICATION_SERVICE) as NotificationManager
val channelId = "general"
val channelName = mContext.getString(R.string.general)
val importance = NotificationManager.IMPORTANCE_DEFAULT
lateinit var channel: NotificationChannel
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
channel = NotificationChannel(channelId, channelName, importance)
channel = NotificationChannel(channelId, channelName, NotificationManager.IMPORTANCE_DEFAULT)
channel.enableLights(true)
channel.lightColor = Color.BLUE
manager.createNotificationChannel(channel)
@@ -286,11 +285,11 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
})
pullToRefresh.isRefreshing = false
if (plan) {
val snackbarview = v.findViewById<View>(R.id.coordination)
val snackBarView = v.findViewById<View>(R.id.coordination)
sdf.applyPattern(newDateFormat)
val sb = StringBuilder()
val lastupdated = sb.append(mContext.getText(R.string.lastupdatedK)).append(sdf.format(d)).toString()
Snackbar.make(snackbarview, lastupdated, Snackbar.LENGTH_LONG).show()
val lastUpdated = sb.append(mContext.getText(R.string.lastupdatedK)).append(sdf.format(d)).toString()
Snackbar.make(snackBarView, lastUpdated, Snackbar.LENGTH_LONG).show()
}
}
}
@@ -300,8 +299,8 @@ class DataFetcher(isplan: Boolean, ismenu: Boolean, isjobservice: Boolean, conte
try {
pullToRefresh.isRefreshing = false
} catch (ignored: Exception) {}
val snackbarview = v.findViewById<View>(R.id.coordination)
Snackbar.make(snackbarview, mContext.getText(R.string.nointernet), Snackbar.LENGTH_LONG).show()
val snackBarView = v.findViewById<View>(R.id.coordination)
Snackbar.make(snackBarView, mContext.getText(R.string.nointernet), Snackbar.LENGTH_LONG).show()
}
}
return null
@@ -2,9 +2,6 @@ package com.denizd.substitutionplan
class MiscData {
var boy = arrayOf("Cedric Grislawski", "Dawid Kniola", "Jonas Köstergarten", "Jakob Moerschner", "Siamak Nemati", "Hendrik Plönnings", "Jan Rohmann", "Anton Rosenberger", "Christoph Senft", "Jan Mika Sieckendieck", "Alexander Sinaj", "Nico Tischer", "Nhat Vinh Tran", "Leon Becker", "Youssef Beltagi", "Erich Kerkesner", "Alex Lick", "Oskar Piskorz", "Theo Recktor", "Eray Vatansever", "Dennis Wojciechowski", "Übeydullah Alkan", "Yahya Almarashli", "Sinan Aydin", "Rick Büteröwe", "Levin Dropp", "Silvester Jermolajew", "Tolgay Kekilli", "Dennis Lange", "Aras Mahmoud", "Batuhan Özcan", "Michael Rek", "Khabat Sharif", "Anbinh Tran", "Bastian Westerboer", "Abdulwahab Alshebli", "Kelechi Gaius", "Armin Großmann", "Anes Halep", "Marco Jankowski", "Emirhan Kaplan", "Alexander Kofmann", "Tobi Derek Köhler", "Vasilije Nedeljkovic", "Batu Öcal", "Paul Rehbohm")
var girl = arrayOf("Mayra Dronia", "Shalin Ramadan", "Nigina Amin", "Mariya Kheder", "Niegen Khosrawi", "Dayana Osipova", "Julia Petri", "Laura Pister", "Dana Alyoussef", "Ilkem Kahramanoglu", "Rozita Amiri", "Mirja Arneke", "Nastasja Banik", "Anni Kienke", "Benedite Mateta", "Leonie Pohl", "Cecillia Sawires", "Patrycja Smółka", "Elif Zencirkiran", "Nusyba Al Semadi", "Vivien Bruns", "Yasemin Dal", "Svenja Demuth", "Nina Groß", "Kim Lahmeyer", "Luca Minschke", "Kim Reschke", "Amélie Schnellecke", "Delal Secer", "Xenia Segijanski", "Melisa Tas", "Kim Völker", "Banu Yari", "Zeinab Ali", "Mariam Bannout", "Stefanie Fahl", "Yamaty Gaye", "Anna-Sophia Haeberle", "Finja Hastedt", "Viktoria Hammermeister", "Isabel Horn", "Laura Kern", "Melanie Kleinermann", "Målin Kollhoff", "Darja Maier", "Lisa Maier", "Naura Nadzifah", "Janina Roelfs", "Vanessa Scheifler", "Mara Thies", "Lieli Umar", "Leonie Welk", "Betraben Yacoub")
fun emoji(unicode: Int): String { return String(Character.toChars(unicode)) }
fun getIcon(course: String): Int {
@@ -23,9 +23,6 @@ import com.google.android.material.bottomnavigation.BottomNavigationView
import com.google.android.material.button.MaterialButton
import com.google.android.material.textfield.TextInputEditText
import com.jaredrummler.android.device.DeviceName
import java.lang.NullPointerException
import java.text.DecimalFormat
import java.util.*
class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListener {
@@ -288,7 +285,7 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
val layout = item.findViewById<LinearLayout>(R.id.item_layout)
itemText.text = courses[i]
itemImage.setImageDrawable(resources.getDrawable(coursesIcons[i]))
itemImage.setImageDrawable(ContextCompat.getDrawable(mContext, coursesIcons[i]))
val courseNoLangTxt = coursesNoLang[i]
val courseTxt = courses[i]
@@ -393,54 +390,6 @@ class SettingsFragment : Fragment(R.layout.content_settings), View.OnClickListen
Toast.makeText(mContext, R.string.noyoutube, Toast.LENGTH_LONG).show()
}
}
"Q1 Matchmaker" -> {
val gen = Random()
val alertDialogDate = AlertDialog.Builder(mContext, R.style.AlertDialog)
val dateDialogView = LayoutInflater.from(mContext).inflate(R.layout.dating_dialog, null)
val datingBtn = dateDialogView.findViewById<Button>(R.id.dating_btn)
val boyTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt1)
val girlTxt = dateDialogView.findViewById<TextInputEditText>(R.id.dating_txt2)
val boyCb = dateDialogView.findViewById<CheckBox>(R.id.cb1)
val girlCb = dateDialogView.findViewById<CheckBox>(R.id.cb2)
val percentage = dateDialogView.findViewById<TextView>(R.id.dating_txtp)
datingBtn.setOnClickListener {
try {
val dg = MiscData()
if (boyTxt.text.toString().isEmpty() || boyCb.isChecked) {
boyTxt.setText(dg.boy[gen.nextInt(dg.boy.size)])
}
if (girlTxt.text.toString().isEmpty() || girlCb.isChecked) {
girlTxt.setText(dg.girl[gen.nextInt(dg.girl.size)])
}
val boyP = boyTxt.text!!.length.toDouble()
val girlP = girlTxt.text!!.length.toDouble()
var perc = when {
girlP < boyP -> (girlP / boyP) * 100
else -> (boyP / girlP) * 100
}
val boyChar = boyTxt.text.toString()[boyTxt.text.toString().length - 1]
val girlChar = girlTxt.text.toString()[girlTxt.text.toString().length - 1]
val multiply = (Character.getNumericValue(boyChar) + Character.getNumericValue(girlChar)) / 1.2
if (perc == 0.0) {
perc += 30.0
}
val df = DecimalFormat("#.##")
percentage.text = when {
perc * (multiply / 40) > 100 -> "100.00%"
else -> df.format(perc * (multiply / 40)) + "%"
}
} catch (e: NullPointerException) {
Toast.makeText(mContext, getString(R.string.error), Toast.LENGTH_SHORT).show()
}
}
alertDialogDate.setView(dateDialogView)
alertDialogDate.show()
}
"@NOTIFICATION" -> {
edit.putString("time", "").apply()
Toast.makeText(mContext, "Notification time cleared", Toast.LENGTH_LONG).show()
-151
View File
@@ -1,151 +0,0 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/textviewtitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_marginEnd="16dp"
android:layout_marginTop="16dp"
android:textSize="22sp"
android:layout_gravity="center_horizontal"
android:textColor="@color/datingPink"
android:text="@string/dating"
android:textAlignment="center"/>
<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingTop="8dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingStart="24dp"
android:paddingEnd="24dp"
android:paddingBottom="24dp"
android:paddingTop="8dp"
android:orientation="vertical">
<TextView
android:id="@+id/dating_txt"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:textColor="@color/textcolor"
android:text="@string/havefun"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/datingPink"
app:boxStrokeWidth="2dp"
android:layout_width="0px"
android:layout_weight="7"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:textColorHint="@color/hintcolor"
android:hint="@string/boy"
android:importantForAutofill="no">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/dating_txt1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:textColor="@color/textcolor"
android:singleLine="true"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:id="@+id/cb1"
android:layout_width="0px"
android:layout_weight="3"
android:layout_height="wrap_content"
android:textColor="@color/textcolor"
android:text="Shuffle"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<com.google.android.material.textfield.TextInputLayout
style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
app:boxStrokeColor="@color/datingPink"
app:boxStrokeWidth="2dp"
android:layout_width="0px"
android:layout_weight="7"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:layout_marginBottom="2dp"
android:textColorHint="@color/hintcolor"
android:hint="@string/girl"
android:importantForAutofill="no">
<com.google.android.material.textfield.TextInputEditText
android:id="@+id/dating_txt2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:inputType="textNoSuggestions"
android:textColor="@color/textcolor"
android:singleLine="true"/>
</com.google.android.material.textfield.TextInputLayout>
<CheckBox
android:id="@+id/cb2"
android:layout_width="0px"
android:layout_weight="3"
android:layout_height="wrap_content"
android:textColor="@color/textcolor"
android:text="Shuffle"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="@+id/dating_btn"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="wrap_content"
android:text="@string/calculate"
android:textColor="@color/datingPink"
app:strokeColor="@color/datingPink"
app:strokeWidth="2dp"
android:layout_gravity="start|center_vertical"
style="@style/Widget.MaterialComponents.Button.OutlinedButton"/>
<TextView
android:id="@+id/dating_txtp"
android:layout_width="0px"
android:layout_weight="5"
android:layout_height="wrap_content"
android:textSize="20sp"
android:textColor="@color/textcolor"
android:layout_marginStart="24dp"
android:layout_gravity="end|center_vertical"/>
</LinearLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>
</LinearLayout>
-3
View File
@@ -1,3 +0,0 @@
<resources>
</resources>
@@ -1,5 +0,0 @@
<resources>
<!-- Example customization of dimensions originally defined in res/values/dimens.xml
(such as screen margins) for screens with more than 820dp of available width. This
would include 7" and 10" devices in landscape (~960dp and ~1280dp respectively). -->
</resources>
-2
View File
@@ -8,8 +8,6 @@
<color name="hintcolor">#757575</color>
<color name="lighthintcolor">#bdbdbd</color>
<color name="datingPink">#d81b60</color>
<color name="bgred">#F28B82</color>
<color name="bgorange">#FBBC04</color>
<color name="bgyellow">#FFF475</color>
-5
View File
@@ -1,5 +0,0 @@
<resources>
<!-- Default screen margins, per the Android Design guidelines. -->
<!-- Default screen margins, per the Android Design guidelines. -->
</resources>
-8
View File
@@ -13,15 +13,7 @@
<item name="colorPrimary">@color/accent</item>
<item name="colorPrimaryDark">@color/background</item>
<item name="colorAccent">@color/accent</item>
<!-- <item name="colorBackground">#eeeeee</item>-->
<!-- <item name="colorBackgroundCard">#f5f5f5</item>-->
<!-- <item name="colorText">#212121</item>-->
<!-- <item name="colorHintLight">#212121</item>-->
<!-- <item name="colorHint">#9e9e9e</item>-->
<!-- <item name="colorHintDark">#000000</item>-->
<item name="android:fontFamily">@font/manrope_medium</item>
<!-- <item name="referenceTextColor">?attr/colorHint</item>-->
<!-- <item name="colorChip">#e0e0e0</item>-->
<item name="android:colorEdgeEffect">@color/accent</item>
</style>