Skip to content

Commit

Permalink
add week changing
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Mar 8, 2022
1 parent fb9659a commit 1e06222
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 3 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

30 changes: 30 additions & 0 deletions app/src/main/java/com/ethosa/ktc/ui/fragments/TimetableFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,14 @@ class TimetableFragment : Fragment() {
private var state = 0
var branch: Branch? = null
var group: Group? = null
var week: Int = 0

companion object {
const val STATE = "state"
const val BRANCH = "branch"
const val GROUP = "group"
const val GROUP_TITLE = "group_title"
const val WEEK = "week"
}

override fun onCreateView(
Expand All @@ -65,6 +67,7 @@ class TimetableFragment : Fragment() {
preferences.getInt(GROUP, 0),
preferences.getString(GROUP_TITLE, "")!!
)
week = preferences.getInt(WEEK, 0)
loadState()

// Analog for back button
Expand All @@ -73,6 +76,18 @@ class TimetableFragment : Fragment() {
binding.back.isEnabled = !backState()
}

// Next week
binding.next.setOnClickListener {
if (week < 57)
changeWeek(1)
}

// previous week
binding.previous.setOnClickListener {
if (week > 1)
changeWeek(-1)
}

return binding.root
}

Expand All @@ -96,6 +111,13 @@ class TimetableFragment : Fragment() {
})
}

private fun changeWeek(i: Int) {
week += i
binding.next.isEnabled = false
binding.previous.isEnabled = false
fetchTimetable(group!!.id, week)
}

private fun loadState() {
// Fetches timetable from loaded state.
when (state) {
Expand Down Expand Up @@ -154,6 +176,8 @@ class TimetableFragment : Fragment() {
requireActivity().runOnUiThread {
binding.back.isEnabled = true
binding.timetableToolbar.visibility = View.VISIBLE
binding.next.visibility = View.GONE
binding.previous.visibility = View.GONE
binding.timetableTitle.text = "Курсы"
binding.timetable.adapter = CourseAdapter(this@TimetableFragment, courses)
preferences.edit().putInt(STATE, state).apply()
Expand All @@ -177,14 +201,20 @@ class TimetableFragment : Fragment() {
// Parse JSON
val json = response.body?.string()
val timetable = Gson().fromJson(json, Week::class.java)
this@TimetableFragment.week = timetable.week_number

requireActivity().runOnUiThread {
binding.back.isEnabled = true
binding.next.isEnabled = true
binding.previous.isEnabled = true
binding.timetableTitle.text = "${group!!.title}\n${timetable.week_number} неделя"
binding.timetableToolbar.visibility = View.VISIBLE
binding.next.visibility = View.VISIBLE
binding.previous.visibility = View.VISIBLE
binding.timetable.adapter = TimetableAdapter(this@TimetableFragment, timetable)
preferences.edit().putInt(STATE, state).apply()
preferences.edit().putInt(GROUP, group!!.id).apply()
preferences.edit().putInt(WEEK, timetable.week_number).apply()
preferences.edit().putString(GROUP_TITLE, group!!.title).apply()
}
}
Expand Down
27 changes: 26 additions & 1 deletion app/src/main/res/layout/fragment_timetable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/primary"
tools:ignore="ContentDescription" />
tools:ignore="ContentDescription,ImageContrastCheck" />

<TextView
android:id="@+id/timetable_title"
Expand All @@ -52,6 +52,31 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<ImageView
android:id="@+id/previous"
android:layout_width="32dp"
android:layout_height="0dp"
android:scaleType="centerInside"
android:src="@drawable/img_arrow"
app:layout_constraintBottom_toBottomOf="@+id/timetable_title"
app:layout_constraintEnd_toStartOf="@+id/timetable_title"
app:layout_constraintTop_toTopOf="@+id/timetable_title"
app:tint="@color/text"
tools:ignore="ContentDescription" />

<ImageView
android:id="@+id/next"
android:layout_width="32dp"
android:layout_height="0dp"
android:rotation="180"
android:scaleType="centerInside"
android:src="@drawable/img_arrow"
app:layout_constraintBottom_toBottomOf="@+id/timetable_title"
app:layout_constraintStart_toEndOf="@+id/timetable_title"
app:layout_constraintTop_toTopOf="@+id/timetable_title"
app:tint="@color/text"
tools:ignore="ContentDescription" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#Sat Mar 05 14:15:16 NOVT 2022
#Tue Mar 08 22:48:41 NOVT 2022
Binary file modified shared/build/kotlin/compileDebugKotlinAndroid/build-history.bin
Binary file not shown.
Binary file modified shared/build/kotlin/compileDebugKotlinAndroid/last-build.bin
Binary file not shown.

0 comments on commit 1e06222

Please sign in to comment.