Archived
Added support for teacher column
This commit is contained in:
@@ -28,14 +28,17 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
|
||||
|
||||
class CardViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
|
||||
|
||||
var mImageView: ImageView = itemView.findViewById(R.id.iconView)
|
||||
var mGroup: TextView = itemView.findViewById(R.id.group)
|
||||
var mDate: TextView = itemView.findViewById(R.id.date)
|
||||
var mTime: TextView = itemView.findViewById(R.id.time)
|
||||
var mCourse: TextView = itemView.findViewById(R.id.course)
|
||||
var mRoom: TextView = itemView.findViewById(R.id.room)
|
||||
var mAdditional: TextView = itemView.findViewById(R.id.additional)
|
||||
var mCard: MaterialCardView = itemView.findViewById(R.id.planCard)
|
||||
var mImageView: ImageView = view.findViewById(R.id.iconView)
|
||||
var mGroup: TextView = view.findViewById(R.id.group)
|
||||
var mDate: TextView = view.findViewById(R.id.date)
|
||||
var mTime: TextView = view.findViewById(R.id.time)
|
||||
var mCourse: TextView = view.findViewById(R.id.course)
|
||||
var mRoom: TextView = view.findViewById(R.id.room)
|
||||
var mAdditional: TextView = view.findViewById(R.id.additional)
|
||||
var spacer: TextView = view.findViewById(R.id.spacer)
|
||||
var teacher: TextView = view.findViewById(R.id.teacher)
|
||||
|
||||
var mCard: MaterialCardView = view.findViewById(R.id.planCard)
|
||||
init { view.setOnClickListener(this) }
|
||||
override fun onClick(v: View?) {
|
||||
if (mDate.text.toString().length > 7 && mDate.text.toString().substring(3, 7) == "http") {
|
||||
@@ -59,7 +62,7 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
|
||||
val prefs = PreferenceManager.getDefaultSharedPreferences(holder.mImageView.context)
|
||||
var psa = false
|
||||
val strings = arrayOf(SpannableString(currentItem.group), SpannableString(currentItem.time),
|
||||
SpannableString(currentItem.course), SpannableString(currentItem.room))
|
||||
SpannableString(currentItem.course), SpannableString(currentItem.room), SpannableString(currentItem.teacher))
|
||||
for (item in strings) {
|
||||
val qmark = item.indexOf("?")
|
||||
if (qmark != -1) {
|
||||
@@ -70,18 +73,16 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
|
||||
if (contains("eigenverantwortliches arbeiten") || contains("entfall") || contains("fällt aus")) {
|
||||
strings[2].setSpan(StrikethroughSpan(), 0, strings[2].length, 0)
|
||||
strings[3].setSpan(StrikethroughSpan(), 0, strings[3].length, 0)
|
||||
strings[4].setSpan(StrikethroughSpan(), 0, strings[4].length, 0)
|
||||
}
|
||||
}
|
||||
|
||||
holder.mImageView.setImageResource(
|
||||
HelperFunctions.getIconForCourse(
|
||||
currentItem.course
|
||||
)
|
||||
)
|
||||
holder.mImageView.setImageResource(HelperFunctions.getIconForCourse(currentItem.course))
|
||||
holder.mGroup.setText(strings[0], TextView.BufferType.SPANNABLE)
|
||||
holder.mTime.setText(strings[1], TextView.BufferType.SPANNABLE)
|
||||
holder.mCourse.setText(strings[2], TextView.BufferType.SPANNABLE)
|
||||
holder.mRoom.setText(strings[3], TextView.BufferType.SPANNABLE)
|
||||
holder.teacher.setText(strings[4], TextView.BufferType.SPANNABLE)
|
||||
holder.mAdditional.text = currentItem.additional
|
||||
|
||||
if (currentItem.date.isNotEmpty() && currentItem.date.substring(0, 3) == "psa") {
|
||||
@@ -115,6 +116,12 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
|
||||
}
|
||||
}
|
||||
|
||||
holder.spacer.visibility = if (strings[2].isEmpty() || strings[4].isEmpty()) {
|
||||
View.GONE
|
||||
} else {
|
||||
View.VISIBLE
|
||||
}
|
||||
|
||||
val textColor = ContextCompat.getColor(holder.mImageView.context, if (psa) {
|
||||
R.color.colorBackground
|
||||
} else {
|
||||
@@ -131,6 +138,8 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
|
||||
holder.mCourse.setTextColor(textColor)
|
||||
holder.mRoom.setTextColor(textColor)
|
||||
holder.mAdditional.setTextColor(textColor)
|
||||
holder.spacer.setTextColor(textColor)
|
||||
holder.teacher.setTextColor(textColor)
|
||||
}
|
||||
|
||||
override fun getItemCount(): Int = mSubst.size
|
||||
|
||||
@@ -8,6 +8,7 @@ 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
|
||||
@@ -98,7 +99,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
private fun requestFoodMenuData() {
|
||||
val docFood = Jsoup.connect(foodUrl).get()
|
||||
currentFoodTime = docFood.select("h1")[0].text()
|
||||
if (currentFoodTime != prefs.getString("timeFoodNew", "")) {
|
||||
if (currentFoodTime != prefs.getString("newFoodTime", "")) {
|
||||
val foodRepository = FoodRepository(mApplication)
|
||||
val foodElements = docFood.select("th")
|
||||
foodRepository.deleteAll()
|
||||
@@ -121,7 +122,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
}
|
||||
foodRepository.insert(Food(s, priority))
|
||||
}
|
||||
edit.putString("timeFoodNew", currentFoodTime).apply()
|
||||
edit.putString("newFoodTime", currentFoodTime).apply()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -157,8 +158,9 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
||||
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, priority = priority
|
||||
room = cols[4].text(), additional = additional, teacher = cols[6].text(), priority = priority
|
||||
)
|
||||
Log.d("AAAA", cols[6].text())
|
||||
substArray.add(subst)
|
||||
substRepo.insert(subst)
|
||||
priority--
|
||||
|
||||
@@ -4,10 +4,12 @@ import android.content.Context
|
||||
import androidx.room.Database
|
||||
import androidx.room.Room
|
||||
import androidx.room.RoomDatabase
|
||||
import androidx.room.migration.Migration
|
||||
import androidx.sqlite.db.SupportSQLiteDatabase
|
||||
import com.denizd.substitutionplan.models.Food
|
||||
import com.denizd.substitutionplan.models.Subst
|
||||
|
||||
@Database(entities = [Subst::class, Food::class], version = 5, exportSchema = false)
|
||||
@Database(entities = [Subst::class, Food::class], version = 6, exportSchema = false)
|
||||
internal abstract class SubstDatabase : RoomDatabase() {
|
||||
|
||||
abstract fun substDao(): SubstDao
|
||||
@@ -15,6 +17,12 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
companion object {
|
||||
|
||||
private var instance: SubstDatabase? = null
|
||||
private val addTeacherColumn = object : Migration(5, 6) {
|
||||
override fun migrate(database: SupportSQLiteDatabase) {
|
||||
database.execSQL(
|
||||
"ALTER TABLE subst_table ADD COLUMN teacher TEXT NOT NULL DEFAULT ''")
|
||||
}
|
||||
}
|
||||
|
||||
fun getInstance(context: Context): SubstDatabase? {
|
||||
if (instance == null) {
|
||||
@@ -22,7 +30,7 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
||||
instance = Room.databaseBuilder(context.applicationContext,
|
||||
SubstDatabase::class.java,
|
||||
"subst_database")
|
||||
.fallbackToDestructiveMigration()
|
||||
.addMigrations(addTeacherColumn)
|
||||
.build()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ 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 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 priority: Int) {
|
||||
|
||||
@PrimaryKey(autoGenerate = true)
|
||||
var id: Int = 0
|
||||
|
||||
Reference in New Issue
Block a user