Archived
Adapter now accepts "type" strings from database and can display information accordingly; app bar title font enlargened
This commit is contained in:
@@ -65,11 +65,11 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
FirebaseApp.initializeApp(this)
|
||||
pingFirebaseTopics()
|
||||
|
||||
val appbarlayout = findViewById<AppBarLayout>(R.id.appbarlayout)
|
||||
val appBarLayout = findViewById<AppBarLayout>(R.id.appbarlayout)
|
||||
val toolbarTxt = findViewById<TextView>(R.id.toolbarTxt)
|
||||
val bottomNav = findViewById<BottomNavigationView>(R.id.bottom_nav)
|
||||
val contextView = findViewById<View>(R.id.coordination)
|
||||
val window = this.window as Window
|
||||
val window = this.window
|
||||
|
||||
setTheme(R.style.AppTheme0)
|
||||
|
||||
@@ -106,12 +106,11 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
|
||||
val textViewGreeting = findViewById<TextView>(R.id.text_greeting)
|
||||
if (prefs.getBoolean("greeting", true)) {
|
||||
if ((prefs.getString("username", "") ?: "").isNotEmpty()) {
|
||||
textViewGreeting.text = getGreetingString()
|
||||
}
|
||||
textViewGreeting.text = if (prefs.getBoolean("greeting", true) && (prefs.getString("username", "") ?: "").isNotEmpty()) {
|
||||
getGreetingString()
|
||||
} else {
|
||||
textViewGreeting.visibility = View.GONE
|
||||
// textViewGreeting.visibility = View.GONE
|
||||
""
|
||||
}
|
||||
|
||||
if (prefs.getInt("firstTimeOpening", 0) == 0) {
|
||||
@@ -122,7 +121,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
if (prefs.getBoolean("defaultPersonalised", false)) {
|
||||
defaultFragment = PersonalPlanFragment()
|
||||
bottomNav.selectedItemId = R.id.personal
|
||||
toolbarTxt.text = getString(R.string.yourPlan)
|
||||
toolbarTxt.text = personalPlanTitle()
|
||||
} else {
|
||||
defaultFragment = GeneralPlanFragment()
|
||||
bottomNav.selectedItemId = R.id.plan
|
||||
@@ -140,7 +139,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
R.id.personal -> {
|
||||
fragment = PersonalPlanFragment()
|
||||
toolbarTxt.text = getString(R.string.yourPlan)
|
||||
toolbarTxt.text = personalPlanTitle()
|
||||
}
|
||||
R.id.menu -> {
|
||||
fragment = FoodFragment()
|
||||
@@ -156,7 +155,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
}
|
||||
}
|
||||
if (fragmentLoading) {
|
||||
appbarlayout.setExpanded(true)
|
||||
appBarLayout.setExpanded(true)
|
||||
loadFragment(fragment)
|
||||
} else {
|
||||
false
|
||||
@@ -171,7 +170,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
recyclerView.post {
|
||||
recyclerView.smoothScrollToPosition(0)
|
||||
}
|
||||
appbarlayout.setExpanded(true)
|
||||
appBarLayout.setExpanded(true)
|
||||
} catch (e: NullPointerException) {}
|
||||
}
|
||||
R.id.menu -> {
|
||||
@@ -180,7 +179,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
recyclerView.post {
|
||||
recyclerView.smoothScrollToPosition(0)
|
||||
}
|
||||
appbarlayout.setExpanded(true)
|
||||
appBarLayout.setExpanded(true)
|
||||
} catch (e: NullPointerException) {}
|
||||
}
|
||||
R.id.settings -> {
|
||||
@@ -189,7 +188,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
nsv.post {
|
||||
nsv.smoothScrollTo(0, 0)
|
||||
}
|
||||
appbarlayout.setExpanded(true)
|
||||
appBarLayout.setExpanded(true)
|
||||
} catch (e: NullPointerException) {}
|
||||
}
|
||||
}
|
||||
@@ -199,7 +198,6 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
|
||||
private fun getGreetingString(): String {
|
||||
val gen = Random()
|
||||
|
||||
return String.format(when (Calendar.getInstance().get(Calendar.HOUR_OF_DAY)) {
|
||||
in 5..10 -> resources.getStringArray(R.array.greetingsMorning)[gen.nextInt(resources.getStringArray(
|
||||
R.array.greetingsMorning
|
||||
@@ -219,7 +217,7 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
dialogView.findViewById<TextView>(R.id.textviewtitle).text = getString(
|
||||
R.string.information
|
||||
)
|
||||
val dialogText = "${getString(R.string.lastUpdated)} ${prefs.getString("timeNew", "")}.\n\n${prefs.getString("informational", "")}"
|
||||
val dialogText = "${getString(R.string.lastUpdated)} ${prefs.getString("timeNew", "")}.\n\n${prefs.getString("informational", "")}".trim()
|
||||
dialogView.findViewById<TextView>(R.id.dialogtext).text = dialogText
|
||||
dialog.setView(dialogView).show()
|
||||
}
|
||||
@@ -239,4 +237,17 @@ internal class Main : AppCompatActivity(R.layout.app_bar_main) {
|
||||
val scheduler = getSystemService(JOB_SCHEDULER_SERVICE) as JobScheduler
|
||||
scheduler.schedule(info)
|
||||
}
|
||||
|
||||
private fun personalPlanTitle(): String {
|
||||
return if (prefs.getBoolean("greeting", true)) {
|
||||
getString(R.string.yourPlan)
|
||||
} else {
|
||||
val user = (prefs.getString("username", "") ?: "").toString()
|
||||
if (user.endsWith("s", true) || user.endsWith("x", true) || user.endsWith("z", true)) {
|
||||
"$user${getString(R.string.noSPlan)}"
|
||||
} else {
|
||||
"$user${getString(R.string.SPlan)}"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ internal class CardAdapter(private var mSubst: List<Subst>, private val prefs: S
|
||||
private var colour = 0
|
||||
private var colourString = ""
|
||||
private var colorCheck = ""
|
||||
private val cancellations = arrayOf("eigenverantwortliches arbeiten", "entfall", "entfällt", "fällt aus", "freisetzung", "vtr. ohne lehrer")
|
||||
|
||||
class CardViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
|
||||
|
||||
@@ -61,7 +62,8 @@ internal class CardAdapter(private var mSubst: List<Subst>, private val prefs: S
|
||||
val currentItem = mSubst[position]
|
||||
var psa = false
|
||||
val strings = arrayOf(SpannableString(currentItem.group), SpannableString(currentItem.time),
|
||||
SpannableString(currentItem.course), SpannableString(currentItem.room), SpannableString(currentItem.teacher))
|
||||
SpannableString(currentItem.course), SpannableString(currentItem.room),
|
||||
SpannableString(currentItem.teacher))
|
||||
var cardBackgroundColour = 0
|
||||
|
||||
for (string in strings) {
|
||||
@@ -70,9 +72,16 @@ internal class CardAdapter(private var mSubst: List<Subst>, private val prefs: S
|
||||
string.setSpan(StrikethroughSpan(), 0, questionMarkIndex, 0)
|
||||
}
|
||||
}
|
||||
with (currentItem.additional.toLowerCase(Locale.ROOT)) {
|
||||
if (contains("eigenverantwortliches arbeiten") || contains("entfall") || contains("fällt aus")) {
|
||||
for (i in 2..4) { strings[i].setSpan(StrikethroughSpan(), 0, strings[i].length, 0) }
|
||||
|
||||
val add = currentItem.additional.toLowerCase(Locale.ROOT)
|
||||
val type = currentItem.type.toLowerCase(Locale.ROOT)
|
||||
if (add.isNotEmpty()) {
|
||||
if (HelperFunctions.checkStringForArray(add, cancellations)) {
|
||||
strikeThrough(strings)
|
||||
}
|
||||
} else {
|
||||
if (HelperFunctions.checkStringForArray(type, cancellations)) {
|
||||
strikeThrough(strings)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +91,7 @@ internal class CardAdapter(private var mSubst: List<Subst>, private val prefs: S
|
||||
holder.course.setText(strings[2], TextView.BufferType.SPANNABLE)
|
||||
holder.room.setText(strings[3], TextView.BufferType.SPANNABLE)
|
||||
holder.teacher.setText(strings[4], TextView.BufferType.SPANNABLE)
|
||||
holder.additional.text = currentItem.additional
|
||||
holder.additional.text = if (currentItem.additional.isNotEmpty()) currentItem.additional else currentItem.type
|
||||
|
||||
holder.date.visibility = if (currentItem.date.isNotEmpty() && currentItem.date.substring(0, 3) == "psa") {
|
||||
psa = true
|
||||
@@ -186,4 +195,7 @@ internal class CardAdapter(private var mSubst: List<Subst>, private val prefs: S
|
||||
}
|
||||
}
|
||||
|
||||
private fun strikeThrough(strings: Array<SpannableString>) {
|
||||
for (i in 2..4) { strings[i].setSpan(StrikethroughSpan(), 0, strings[i].length, 0) }
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import android.net.Uri
|
||||
import android.os.AsyncTask
|
||||
import android.os.Build
|
||||
import android.preference.PreferenceManager
|
||||
import android.util.Log
|
||||
import android.view.View
|
||||
import android.widget.RemoteViews
|
||||
import androidx.core.app.NotificationCompat
|
||||
@@ -62,7 +61,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
}
|
||||
|
||||
if (forceRefresh) {
|
||||
edit.putString("timeNew", "").putString("timeFoodNew", "").apply()
|
||||
edit.putString("timeNew", "").putString("newFoodTime", "").apply()
|
||||
}
|
||||
|
||||
if (menu) {
|
||||
@@ -114,7 +113,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
val indices = ArrayList<Int>()
|
||||
val daysAndVon = arrayOf("Montag", "Dienstag", "Mittwoch", "Donnerstag", "Freitag", "von")
|
||||
for (i in 0 until foodElements.size) {
|
||||
if (checkStringForArray(foodElements[i].text(), daysAndVon)) indices.add(i)
|
||||
if (HelperFunctions.checkStringForArray(foodElements[i].text(), daysAndVon)) indices.add(i)
|
||||
}
|
||||
indices.add(foodElements.size)
|
||||
|
||||
@@ -160,14 +159,17 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
val row = rows[i]
|
||||
val cols = row.select("th")
|
||||
|
||||
val group = cols[0].text()
|
||||
val course = cols[3].text()
|
||||
val additional = cols[5].text()
|
||||
val subst = Subst(
|
||||
group = group, date = cols[1].text(), time = cols[2].text(), course = course,
|
||||
room = cols[4].text(), additional = additional, teacher = cols[6].text(), priority = priority
|
||||
group = cols[0].text(),
|
||||
date = cols[1].text(),
|
||||
time = cols[2].text(),
|
||||
course = cols[3].text(),
|
||||
room = cols[4].text(),
|
||||
additional = cols[5].text(),
|
||||
teacher = cols[6].text(),
|
||||
type = cols[7].text(),
|
||||
priority = priority
|
||||
)
|
||||
Log.d("AAAA", cols[6].text())
|
||||
substArray.add(subst)
|
||||
substRepo.insert(subst)
|
||||
priority--
|
||||
@@ -200,11 +202,8 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
openApp.flags += Intent.FLAG_ACTIVITY_CLEAR_TASK
|
||||
val openAppPending = PendingIntent.getActivity(mContext, 0, openApp, 0)
|
||||
|
||||
val notificationLayout = RemoteViews(mContext.packageName,
|
||||
R.layout.notification
|
||||
)
|
||||
notificationLayout.setTextViewText(
|
||||
R.id.notification_title, mContext.getString(
|
||||
val notificationLayout = RemoteViews(mContext.packageName, R.layout.notification)
|
||||
notificationLayout.setTextViewText(R.id.notification_title, mContext.getString(
|
||||
R.string.substitutionPlan
|
||||
))
|
||||
notificationLayout.setTextViewText(R.id.notification_textview, notifText)
|
||||
@@ -221,9 +220,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
.setSmallIcon(R.drawable.ic_avh)
|
||||
.setContentIntent(openAppPending)
|
||||
.setAutoCancel(true)
|
||||
.setColor(ContextCompat.getColor(mContext,
|
||||
R.color.colorAccent
|
||||
))
|
||||
.setColor(ContextCompat.getColor(mContext, R.color.colorAccent))
|
||||
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.O) {
|
||||
val sound = if ((prefs.getString("ringtoneUri", "") ?: "").isNotEmpty()) {
|
||||
@@ -236,13 +233,4 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
|
||||
manager.notify(1, notification.build())
|
||||
}
|
||||
|
||||
private fun checkStringForArray(s: String, checking: Array<String>): Boolean {
|
||||
for (i in checking.indices) {
|
||||
if (s.contains(checking[i])) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
@@ -257,4 +257,11 @@ internal object HelperFunctions {
|
||||
requestPermissions(activity, arrayOf(Manifest.permission.WRITE_EXTERNAL_STORAGE), 42)
|
||||
}
|
||||
}
|
||||
|
||||
fun checkStringForArray(s: String, checking: Array<String>): Boolean {
|
||||
checking.forEach { check ->
|
||||
if (s.contains(check)) return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@ import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.denizd.substitutionplan.models.Food
|
||||
import com.denizd.substitutionplan.models.Subst
|
||||
|
||||
@Database(entities = [Subst::class, Food::class], version = 6, exportSchema = false)
|
||||
@Database(entities = [Subst::class, Food::class], version = 7, exportSchema = false)
|
||||
internal abstract class SubstDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun substDao(): SubstDao
|
||||
@@ -22,6 +22,11 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
database.execSQL("ALTER TABLE subst_table ADD COLUMN teacher TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
private val addTypeColumn = object : Migration(6, 7) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL("ALTER TABLE subst_table ADD COLUMN type TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
|
||||
fun getInstance(context: Context): SubstDatabase? {
|
||||
if (instance == null) {
|
||||
@@ -29,7 +34,7 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
instance = Room.databaseBuilder(context.applicationContext,
|
||||
SubstDatabase::class.java,
|
||||
"subst_database")
|
||||
.addMigrations(addTeacherColumn)
|
||||
.addMigrations(addTeacherColumn, addTypeColumn)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
@@ -45,6 +50,7 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
foodInstance = Room.databaseBuilder(context.applicationContext,
|
||||
SubstDatabase::class.java,
|
||||
"food_database")
|
||||
.fallbackToDestructiveMigrationFrom(5, 6)
|
||||
.fallbackToDestructiveMigration()
|
||||
.build()
|
||||
}
|
||||
|
||||
@@ -101,7 +101,7 @@ internal class SettingsFragment : Fragment(R.layout.content_settings), View.OnCl
|
||||
btnVersion.setOnClickListener(this)
|
||||
btnForceRefresh.setOnClickListener(this)
|
||||
btnForceRefresh.setOnLongClickListener {
|
||||
edit.putString("timeNew", "").putString("timeFoodNew", "").apply()
|
||||
edit.putString("timeNew", "").putString("newFoodTime", "").apply()
|
||||
makeToast(mContext.getString(R.string.forcedRefreshTimes))
|
||||
true
|
||||
}
|
||||
|
||||
@@ -4,7 +4,17 @@ import androidx.room.Entity
|
||||
import androidx.room.PrimaryKey
|
||||
|
||||
@Entity(tableName = "subst_table")
|
||||
internal data class Subst(val group: String, val date: String, val time: String, val course: String, val room: String, val additional: String, val teacher: String, val priority: Int) {
|
||||
internal data class Subst(
|
||||
val group: String,
|
||||
val date: String,
|
||||
val time: String,
|
||||
val course: String,
|
||||
val room: String,
|
||||
val additional: String,
|
||||
val teacher: String,
|
||||
val type: String,
|
||||
val priority: Int
|
||||
) {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Int = 0
|
||||
|
||||
Reference in New Issue
Block a user