refined recyclers. Opens on current day (yay!)
parent
3e51df6a87
commit
a4669716b0
|
|
@ -61,5 +61,6 @@
|
|||
"hour_end": "06:00"
|
||||
}
|
||||
],
|
||||
"regular_programme" : "Programmation habituelle"
|
||||
"regular_programme" : "Programmation habituelle",
|
||||
"timezone": "GMT+1"
|
||||
}
|
||||
|
|
@ -7,6 +7,19 @@ import java.util.*
|
|||
import kotlin.collections.ArrayList
|
||||
|
||||
class Programme (val title: String, private val periodicity: Int, private val hourBegin: Int, private val hourEnd: Int) {
|
||||
|
||||
fun isThisDay(day: Int): Boolean {
|
||||
|
||||
// 0 (Monday) to 5 (Saturday) + 6 (Sunday)
|
||||
|
||||
// this translates to "true" when:
|
||||
// - the currentDay is flagged in the "periodicity" bit array
|
||||
// OR
|
||||
// - Yesterday is flagged in the "periodicity" bit array AND the program does span over 2 days (night programs).
|
||||
// We'll check a after this whether the current hour is within the span.
|
||||
return (((0b1000000 shr day) and (periodicity)) != 0)
|
||||
}
|
||||
|
||||
fun isCurrent(): Boolean {
|
||||
val now = Calendar.getInstance(TimeZone.getTimeZone("GMT+1"))
|
||||
val currentDay =
|
||||
|
|
|
|||
|
|
@ -7,13 +7,18 @@ import android.widget.TextView
|
|||
import androidx.constraintlayout.widget.ConstraintLayout
|
||||
import androidx.recyclerview.widget.RecyclerView
|
||||
import fr.forum_thalie.tsumugi.R
|
||||
import fr.forum_thalie.tsumugi.colorBlue
|
||||
import fr.forum_thalie.tsumugi.planning.Programme
|
||||
import fr.forum_thalie.tsumugi.weekdays
|
||||
import fr.forum_thalie.tsumugi.weekdaysSundayFirst
|
||||
import java.util.*
|
||||
import kotlin.collections.ArrayList
|
||||
|
||||
class ProgrammeAdapter(private val dataSet: ArrayList<Programme>
|
||||
class ProgrammeAdapter(private val dataSet: ArrayList<Programme>, private val day: String
|
||||
/*,
|
||||
context: Context,
|
||||
resource: Int,
|
||||
objects: Array<out Song>*/
|
||||
objects: ArrayList<Programme>*/
|
||||
) : RecyclerView.Adapter<ProgrammeAdapter.MyViewHolder>() /*ArrayAdapter<Song>(context, resource, objects)*/ {
|
||||
|
||||
class MyViewHolder(view: ConstraintLayout) : RecyclerView.ViewHolder(view)
|
||||
|
|
@ -35,12 +40,17 @@ class ProgrammeAdapter(private val dataSet: ArrayList<Programme>
|
|||
val programmeStart = holder.itemView.findViewById<TextView>(R.id.programme_start)
|
||||
val programmeEnd = holder.itemView.findViewById<TextView>(R.id.programme_end)
|
||||
val programmeName = holder.itemView.findViewById<TextView>(R.id.programme_name)
|
||||
val programmeDays = holder.itemView.findViewById<TextView>(R.id.programme_days)
|
||||
|
||||
programmeStart.text = dataSet[position].begin()
|
||||
programmeName.text = dataSet[position].title
|
||||
programmeEnd.text = dataSet[position].end()
|
||||
programmeDays.text = dataSet[position].days()
|
||||
|
||||
if (dataSet[position].isCurrent() && (Calendar.getInstance(TimeZone.getTimeZone("GMT+1")).get(Calendar.DAY_OF_WEEK) - 1 == weekdaysSundayFirst.indexOf(day)))
|
||||
{
|
||||
programmeStart.setTextColor(colorBlue)
|
||||
programmeEnd.setTextColor(colorBlue)
|
||||
programmeName.setTextColor(colorBlue)
|
||||
}
|
||||
}
|
||||
|
||||
// Return the size of your dataset (invoked by the layout manager)
|
||||
|
|
|
|||
|
|
@ -10,12 +10,16 @@ import androidx.recyclerview.widget.LinearLayoutManager
|
|||
import androidx.recyclerview.widget.RecyclerView
|
||||
import fr.forum_thalie.tsumugi.R
|
||||
import fr.forum_thalie.tsumugi.planning.Planning
|
||||
import fr.forum_thalie.tsumugi.planning.Programme
|
||||
import fr.forum_thalie.tsumugi.weekdays
|
||||
import kotlinx.android.synthetic.main.fragment_programme.*
|
||||
|
||||
class ProgrammeDayFragment(day: String) : Fragment() {
|
||||
class ProgrammeDayFragment(private val day: String) : Fragment() {
|
||||
|
||||
private lateinit var recyclerView: RecyclerView
|
||||
private lateinit var viewAdapter: RecyclerView.Adapter<*>
|
||||
private lateinit var viewManager: RecyclerView.LayoutManager
|
||||
private val programmeOfTheDay: ArrayList<Programme> = ArrayList()
|
||||
|
||||
override fun onCreateView(
|
||||
inflater: LayoutInflater, container: ViewGroup?,
|
||||
|
|
@ -23,9 +27,13 @@ class ProgrammeDayFragment(day: String) : Fragment() {
|
|||
): View? {
|
||||
// Inflate the layout for this fragment
|
||||
val root = inflater.inflate(R.layout.fragment_programme_day, container, false)
|
||||
Planning.instance.programmes.forEach {
|
||||
if (it.isThisDay(day = weekdays.indexOf(day)))
|
||||
programmeOfTheDay.add(it)
|
||||
}
|
||||
viewManager = LinearLayoutManager(context)
|
||||
viewAdapter =
|
||||
ProgrammeAdapter(Planning.instance.programmes)
|
||||
ProgrammeAdapter(programmeOfTheDay, day)
|
||||
recyclerView = root.findViewById<RecyclerView>(R.id.programme_recycler).apply {
|
||||
// use this setting to improve performance if you know that changes
|
||||
// in content do not change the layout size of the RecyclerView
|
||||
|
|
@ -33,17 +41,22 @@ class ProgrammeDayFragment(day: String) : Fragment() {
|
|||
layoutManager = viewManager
|
||||
adapter = viewAdapter
|
||||
}
|
||||
Planning.instance.isProgrammeUpdated.observeForever(isProgrammeUpdatedObserver)
|
||||
Planning.instance.currentProgramme.observeForever(isProgrammeUpdatedObserver)
|
||||
return root
|
||||
}
|
||||
|
||||
private val isProgrammeUpdatedObserver = Observer<Boolean> {
|
||||
private val isProgrammeUpdatedObserver = Observer<String> {
|
||||
programmeOfTheDay.clear()
|
||||
Planning.instance.programmes.forEach {
|
||||
if (it.isThisDay(day = weekdays.indexOf(day)))
|
||||
programmeOfTheDay.add(it)
|
||||
}
|
||||
viewAdapter.notifyDataSetChanged()
|
||||
}
|
||||
|
||||
override fun onDestroyView() {
|
||||
super.onDestroyView()
|
||||
Planning.instance.isProgrammeUpdated.removeObserver(isProgrammeUpdatedObserver)
|
||||
Planning.instance.currentProgramme.removeObserver(isProgrammeUpdatedObserver)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
|
|
|||
|
|
@ -12,6 +12,8 @@ import com.google.android.material.tabs.TabLayout
|
|||
import fr.forum_thalie.tsumugi.R
|
||||
import fr.forum_thalie.tsumugi.ui.APagerAdapter
|
||||
import fr.forum_thalie.tsumugi.weekdays
|
||||
import fr.forum_thalie.tsumugi.weekdaysSundayFirst
|
||||
import java.util.*
|
||||
|
||||
class ProgrammeFragment : Fragment() {
|
||||
|
||||
|
|
@ -34,6 +36,8 @@ class ProgrammeFragment : Fragment() {
|
|||
}
|
||||
|
||||
viewPager.adapter = adapter
|
||||
val todaySundayFirst = Calendar.getInstance(TimeZone.getTimeZone("GMT+1")).get(Calendar.DAY_OF_WEEK) - 1
|
||||
viewPager.currentItem = (todaySundayFirst - 1)%7
|
||||
|
||||
val tabLayout : TabLayout = root.findViewById(R.id.dayTabLayout)
|
||||
tabLayout.setupWithViewPager(viewPager)
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="16dp">
|
||||
android:layout_marginTop="16dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/news_title"
|
||||
|
|
@ -76,6 +78,7 @@
|
|||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="16dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
app:layout_constraintTop_toBottomOf="@id/news_text"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
|
|||
|
|
@ -4,21 +4,15 @@
|
|||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||
android:orientation="vertical" android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_margin="8dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/programme_days"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
/>
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/programme_start"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
app:layout_constraintTop_toBottomOf="@id/programme_days"
|
||||
app:layout_constraintTop_toTopOf="parent"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
android:gravity="start"
|
||||
/>
|
||||
|
|
@ -26,12 +20,13 @@
|
|||
<TextView
|
||||
android:id="@+id/programme_name"
|
||||
android:layout_width="0dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_height="0dp"
|
||||
app:layout_constraintTop_toTopOf="@id/programme_start"
|
||||
app:layout_constraintBottom_toBottomOf="@id/programme_end"
|
||||
app:layout_constraintStart_toEndOf="@id/programme_start"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:gravity="end"
|
||||
android:textAlignment="textEnd"
|
||||
android:gravity="center"
|
||||
android:textAlignment="center"
|
||||
/>
|
||||
|
||||
<TextView
|
||||
|
|
@ -48,6 +43,7 @@
|
|||
android:id="@+id/divider"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="1dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:background="?android:attr/listDivider"
|
||||
app:layout_constraintTop_toBottomOf="@id/programme_end"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
|
|
|
|||
|
|
@ -4,8 +4,9 @@
|
|||
android:orientation="vertical"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginStart="8dp"
|
||||
android:layout_marginEnd="8dp"
|
||||
android:layout_marginTop="8dp"
|
||||
android:layout_marginStart="16dp"
|
||||
android:layout_marginEnd="16dp"
|
||||
>
|
||||
|
||||
<TextView
|
||||
|
|
@ -17,7 +18,6 @@
|
|||
app:layout_constraintBottom_toTopOf="@id/divider"
|
||||
app:layout_constraintStart_toStartOf="parent"
|
||||
app:layout_constraintEnd_toEndOf="parent"
|
||||
android:layout_marginTop="8dp"
|
||||
/>
|
||||
|
||||
<View
|
||||
|
|
|
|||
Loading…
Reference in New Issue