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 {
|
class CardViewHolder(view: View) : RecyclerView.ViewHolder(view), View.OnClickListener {
|
||||||
|
|
||||||
var mImageView: ImageView = itemView.findViewById(R.id.iconView)
|
var mImageView: ImageView = view.findViewById(R.id.iconView)
|
||||||
var mGroup: TextView = itemView.findViewById(R.id.group)
|
var mGroup: TextView = view.findViewById(R.id.group)
|
||||||
var mDate: TextView = itemView.findViewById(R.id.date)
|
var mDate: TextView = view.findViewById(R.id.date)
|
||||||
var mTime: TextView = itemView.findViewById(R.id.time)
|
var mTime: TextView = view.findViewById(R.id.time)
|
||||||
var mCourse: TextView = itemView.findViewById(R.id.course)
|
var mCourse: TextView = view.findViewById(R.id.course)
|
||||||
var mRoom: TextView = itemView.findViewById(R.id.room)
|
var mRoom: TextView = view.findViewById(R.id.room)
|
||||||
var mAdditional: TextView = itemView.findViewById(R.id.additional)
|
var mAdditional: TextView = view.findViewById(R.id.additional)
|
||||||
var mCard: MaterialCardView = itemView.findViewById(R.id.planCard)
|
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) }
|
init { view.setOnClickListener(this) }
|
||||||
override fun onClick(v: View?) {
|
override fun onClick(v: View?) {
|
||||||
if (mDate.text.toString().length > 7 && mDate.text.toString().substring(3, 7) == "http") {
|
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)
|
val prefs = PreferenceManager.getDefaultSharedPreferences(holder.mImageView.context)
|
||||||
var psa = false
|
var psa = false
|
||||||
val strings = arrayOf(SpannableString(currentItem.group), SpannableString(currentItem.time),
|
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) {
|
for (item in strings) {
|
||||||
val qmark = item.indexOf("?")
|
val qmark = item.indexOf("?")
|
||||||
if (qmark != -1) {
|
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")) {
|
if (contains("eigenverantwortliches arbeiten") || contains("entfall") || contains("fällt aus")) {
|
||||||
strings[2].setSpan(StrikethroughSpan(), 0, strings[2].length, 0)
|
strings[2].setSpan(StrikethroughSpan(), 0, strings[2].length, 0)
|
||||||
strings[3].setSpan(StrikethroughSpan(), 0, strings[3].length, 0)
|
strings[3].setSpan(StrikethroughSpan(), 0, strings[3].length, 0)
|
||||||
|
strings[4].setSpan(StrikethroughSpan(), 0, strings[4].length, 0)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
holder.mImageView.setImageResource(
|
holder.mImageView.setImageResource(HelperFunctions.getIconForCourse(currentItem.course))
|
||||||
HelperFunctions.getIconForCourse(
|
|
||||||
currentItem.course
|
|
||||||
)
|
|
||||||
)
|
|
||||||
holder.mGroup.setText(strings[0], TextView.BufferType.SPANNABLE)
|
holder.mGroup.setText(strings[0], TextView.BufferType.SPANNABLE)
|
||||||
holder.mTime.setText(strings[1], TextView.BufferType.SPANNABLE)
|
holder.mTime.setText(strings[1], TextView.BufferType.SPANNABLE)
|
||||||
holder.mCourse.setText(strings[2], TextView.BufferType.SPANNABLE)
|
holder.mCourse.setText(strings[2], TextView.BufferType.SPANNABLE)
|
||||||
holder.mRoom.setText(strings[3], TextView.BufferType.SPANNABLE)
|
holder.mRoom.setText(strings[3], TextView.BufferType.SPANNABLE)
|
||||||
|
holder.teacher.setText(strings[4], TextView.BufferType.SPANNABLE)
|
||||||
holder.mAdditional.text = currentItem.additional
|
holder.mAdditional.text = currentItem.additional
|
||||||
|
|
||||||
if (currentItem.date.isNotEmpty() && currentItem.date.substring(0, 3) == "psa") {
|
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) {
|
val textColor = ContextCompat.getColor(holder.mImageView.context, if (psa) {
|
||||||
R.color.colorBackground
|
R.color.colorBackground
|
||||||
} else {
|
} else {
|
||||||
@@ -131,6 +138,8 @@ internal class CardAdapter(private var mSubst: List<Subst>) : RecyclerView.Adapt
|
|||||||
holder.mCourse.setTextColor(textColor)
|
holder.mCourse.setTextColor(textColor)
|
||||||
holder.mRoom.setTextColor(textColor)
|
holder.mRoom.setTextColor(textColor)
|
||||||
holder.mAdditional.setTextColor(textColor)
|
holder.mAdditional.setTextColor(textColor)
|
||||||
|
holder.spacer.setTextColor(textColor)
|
||||||
|
holder.teacher.setTextColor(textColor)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getItemCount(): Int = mSubst.size
|
override fun getItemCount(): Int = mSubst.size
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.net.Uri
|
|||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.preference.PreferenceManager
|
import android.preference.PreferenceManager
|
||||||
|
import android.util.Log
|
||||||
import android.view.View
|
import android.view.View
|
||||||
import android.widget.RemoteViews
|
import android.widget.RemoteViews
|
||||||
import androidx.core.app.NotificationCompat
|
import androidx.core.app.NotificationCompat
|
||||||
@@ -98,7 +99,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
|||||||
private fun requestFoodMenuData() {
|
private fun requestFoodMenuData() {
|
||||||
val docFood = Jsoup.connect(foodUrl).get()
|
val docFood = Jsoup.connect(foodUrl).get()
|
||||||
currentFoodTime = docFood.select("h1")[0].text()
|
currentFoodTime = docFood.select("h1")[0].text()
|
||||||
if (currentFoodTime != prefs.getString("timeFoodNew", "")) {
|
if (currentFoodTime != prefs.getString("newFoodTime", "")) {
|
||||||
val foodRepository = FoodRepository(mApplication)
|
val foodRepository = FoodRepository(mApplication)
|
||||||
val foodElements = docFood.select("th")
|
val foodElements = docFood.select("th")
|
||||||
foodRepository.deleteAll()
|
foodRepository.deleteAll()
|
||||||
@@ -121,7 +122,7 @@ internal class DataFetcher(isPlan: Boolean, isMenu: Boolean, isJobService: Boole
|
|||||||
}
|
}
|
||||||
foodRepository.insert(Food(s, priority))
|
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 additional = cols[5].text()
|
||||||
val subst = Subst(
|
val subst = Subst(
|
||||||
group = group, date = cols[1].text(), time = cols[2].text(), course = course,
|
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)
|
substArray.add(subst)
|
||||||
substRepo.insert(subst)
|
substRepo.insert(subst)
|
||||||
priority--
|
priority--
|
||||||
|
|||||||
@@ -4,10 +4,12 @@ import android.content.Context
|
|||||||
import androidx.room.Database
|
import androidx.room.Database
|
||||||
import androidx.room.Room
|
import androidx.room.Room
|
||||||
import androidx.room.RoomDatabase
|
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.Food
|
||||||
import com.denizd.substitutionplan.models.Subst
|
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() {
|
internal abstract class SubstDatabase : RoomDatabase() {
|
||||||
|
|
||||||
abstract fun substDao(): SubstDao
|
abstract fun substDao(): SubstDao
|
||||||
@@ -15,6 +17,12 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
|||||||
companion object {
|
companion object {
|
||||||
|
|
||||||
private var instance: SubstDatabase? = null
|
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? {
|
fun getInstance(context: Context): SubstDatabase? {
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
@@ -22,7 +30,7 @@ internal abstract class SubstDatabase : RoomDatabase() {
|
|||||||
instance = Room.databaseBuilder(context.applicationContext,
|
instance = Room.databaseBuilder(context.applicationContext,
|
||||||
SubstDatabase::class.java,
|
SubstDatabase::class.java,
|
||||||
"subst_database")
|
"subst_database")
|
||||||
.fallbackToDestructiveMigration()
|
.addMigrations(addTeacherColumn)
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,7 @@ import androidx.room.Entity
|
|||||||
import androidx.room.PrimaryKey
|
import androidx.room.PrimaryKey
|
||||||
|
|
||||||
@Entity(tableName = "subst_table")
|
@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)
|
@PrimaryKey(autoGenerate = true)
|
||||||
var id: Int = 0
|
var id: Int = 0
|
||||||
|
|||||||
@@ -31,27 +31,48 @@
|
|||||||
app:layout_constraintTop_toTopOf="parent"
|
app:layout_constraintTop_toTopOf="parent"
|
||||||
android:textColor="@color/colorText"/>
|
android:textColor="@color/colorText"/>
|
||||||
|
|
||||||
<ImageView
|
<LinearLayout
|
||||||
android:id="@+id/iconView"
|
android:id="@+id/linearContainer"
|
||||||
android:layout_width="0dp"
|
|
||||||
android:layout_height="20dp"
|
|
||||||
android:layout_marginStart="16dp"
|
|
||||||
android:tint="@color/colorText"
|
|
||||||
app:layout_constraintBottom_toBottomOf="@+id/course"
|
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
|
||||||
app:layout_constraintTop_toTopOf="@+id/course" />
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/course"
|
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="4dp"
|
android:orientation="horizontal"
|
||||||
|
android:layout_marginStart="16dp"
|
||||||
android:layout_marginTop="8dp"
|
android:layout_marginTop="8dp"
|
||||||
android:layout_marginEnd="8dp"
|
android:gravity="start|center_vertical"
|
||||||
android:textColor="@color/colorText"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/time"
|
app:layout_constraintTop_toBottomOf="@+id/group"
|
||||||
app:layout_constraintStart_toEndOf="@+id/iconView"
|
app:layout_constraintEnd_toStartOf="@+id/time">
|
||||||
app:layout_constraintTop_toBottomOf="@+id/group" />
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/iconView"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="20dp"
|
||||||
|
android:tint="@color/colorText"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/course"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="4dp"
|
||||||
|
android:textColor="@color/colorText"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/spacer"
|
||||||
|
android:text="•"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_marginStart="2dp"
|
||||||
|
android:layout_marginEnd="2dp"
|
||||||
|
android:textColor="@color/colorText"/>
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/teacher"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textColor="@color/colorText"
|
||||||
|
android:layout_marginEnd="8dp"/>
|
||||||
|
|
||||||
|
</LinearLayout>
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/additional"
|
android:id="@+id/additional"
|
||||||
@@ -65,7 +86,7 @@
|
|||||||
app:layout_constraintBottom_toBottomOf="parent"
|
app:layout_constraintBottom_toBottomOf="parent"
|
||||||
app:layout_constraintEnd_toStartOf="@+id/room"
|
app:layout_constraintEnd_toStartOf="@+id/room"
|
||||||
app:layout_constraintStart_toStartOf="parent"
|
app:layout_constraintStart_toStartOf="parent"
|
||||||
app:layout_constraintTop_toBottomOf="@+id/course" />
|
app:layout_constraintTop_toBottomOf="@+id/linearContainer" />
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/date"
|
android:id="@+id/date"
|
||||||
|
|||||||
Reference in New Issue
Block a user