Skip to content

Commit

Permalink
redesign, fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethosa committed Mar 5, 2022
1 parent b72d2f1 commit 99bac6e
Show file tree
Hide file tree
Showing 13 changed files with 130 additions and 33 deletions.
1 change: 1 addition & 0 deletions .idea/misc.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class BranchAdapter(

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
return ViewHolder(
LayoutInflater.from(parent.context).inflate(R.layout.layout_branch, parent, false)
LayoutInflater.from(parent.context)
.inflate(R.layout.layout_branch, parent, false)
)
}

Expand All @@ -39,6 +40,7 @@ class BranchAdapter(
binding.button.text = branch.title
binding.button.setOnClickListener {
timetableFragment.fetchCourses(branch.id)
timetableFragment.branch = branch
}
}

Expand Down
12 changes: 9 additions & 3 deletions app/src/main/java/com/ethosa/ktc/ui/adapters/CourseAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class CourseAdapter(
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
return ViewHolder(LayoutInflater.from(parent.context)
.inflate(R.layout.layout_course, parent, false)
return ViewHolder(inflater)
)
}

/**
* Builds groups for every course.
*/
@SuppressLint("SetTextI18n")
@SuppressLint("SetTextI18n", "NewApi")
override fun onBindViewHolder(holder: ViewHolder, position: Int) {
val binding = holder.binding
val item = items[position]
Expand All @@ -44,8 +44,14 @@ class CourseAdapter(
val chip = Button(timetableFragment.context)
chip.text = group.title
chip.setPadding(2, 2, 2, 2)
chip.setBackgroundResource(R.drawable.button)
chip.setTextColor(
timetableFragment.resources.getColor(
R.color.btn_text, timetableFragment.requireContext().theme)
)
chip.setOnClickListener {
timetableFragment.fetchTimetable(group.id)
timetableFragment.group = group
}
binding.courseGroup.addView(chip)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class TimetableAdapter(
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolder {
val inflater = LayoutInflater.from(parent.context)
return ViewHolder(LayoutInflater.from(parent.context)
.inflate(R.layout.layout_timetable, parent, false)
return ViewHolder(inflater)
)
}

/**
Expand Down
36 changes: 30 additions & 6 deletions app/src/main/java/com/ethosa/ktc/ui/fragments/TimetableFragment.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.ethosa.ktc.ui.fragments

import android.annotation.SuppressLint
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
Expand All @@ -9,9 +10,7 @@ import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.ethosa.ktc.college.CollegeApi
import com.ethosa.ktc.college.CollegeCallback
import com.ethosa.ktc.college.timetable.Branches
import com.ethosa.ktc.college.timetable.Courses
import com.ethosa.ktc.college.timetable.Week
import com.ethosa.ktc.college.timetable.*
import com.ethosa.ktc.databinding.FragmentTimetableBinding
import com.ethosa.ktc.ui.adapters.BranchAdapter
import com.ethosa.ktc.ui.adapters.CourseAdapter
Expand All @@ -27,11 +26,14 @@ import okhttp3.Response
*/
class TimetableFragment : Fragment() {
private var _binding: FragmentTimetableBinding? = null
private lateinit var itemDecoration: RecyclerView.ItemDecoration

private val binding get() = _binding!!
private val college = CollegeApi()

private lateinit var itemDecoration: RecyclerView.ItemDecoration
private val binding get() = _binding!!
// 0 - branches, 1 - courses, 2 - timetable.
private var state = 0
var branch: Branch? = null
var group: Group? = null

override fun onCreateView(
inflater: LayoutInflater,
Expand All @@ -44,6 +46,15 @@ class TimetableFragment : Fragment() {
itemDecoration = SpacingItemDecoration(0, 32)
binding.timetable.addItemDecoration(itemDecoration)

binding.back.setOnClickListener {
when (state) {
1 -> fetchBranches()
2 -> fetchCourses(branch!!.id)
else -> return@setOnClickListener
}
binding.back.isEnabled = false
}

fetchBranches()

return binding.root
Expand All @@ -62,6 +73,7 @@ class TimetableFragment : Fragment() {
*/
@Suppress("MemberVisibilityCanBePrivate")
fun fetchBranches() {
state = 0
college.fetchBranches(object : CollegeCallback {
override fun onResponse(call: Call, response: Response) {
if (_binding == null) return
Expand All @@ -70,6 +82,8 @@ class TimetableFragment : Fragment() {
val branches = Gson().fromJson(json, Branches::class.java)

requireActivity().runOnUiThread {
binding.back.isEnabled = true
binding.timetableToolbar.visibility = View.GONE
binding.timetable.adapter = BranchAdapter(this@TimetableFragment, branches)
}
}
Expand All @@ -81,14 +95,19 @@ class TimetableFragment : Fragment() {
* @param branchId unique branch ID.
*/
fun fetchCourses(branchId: Int) {
state = 1
college.fetchCourses(branchId, object : CollegeCallback {
@SuppressLint("SetTextI18n")
override fun onResponse(call: Call, response: Response) {
if (_binding == null) return
// Parse JSON
val json = response.body?.string()
val courses = Gson().fromJson(json, Courses::class.java)

requireActivity().runOnUiThread {
binding.back.isEnabled = true
binding.timetableToolbar.visibility = View.VISIBLE
binding.timetableTitle.text = "Курсы"
binding.timetable.adapter = CourseAdapter(this@TimetableFragment, courses)
}
}
Expand All @@ -101,14 +120,19 @@ class TimetableFragment : Fragment() {
* @param week by default is current week.
*/
fun fetchTimetable(groupId: Int, week: Int? = null) {
state = 2
college.fetchTimetable(groupId, object : CollegeCallback {
@SuppressLint("SetTextI18n")
override fun onResponse(call: Call, response: Response) {
if (_binding == null) return
// Parse JSON
val json = response.body?.string()
val timetable = Gson().fromJson(json, Week::class.java)

requireActivity().runOnUiThread {
binding.back.isEnabled = true
binding.timetableTitle.text = "${timetable.week_number} неделя"
binding.timetableToolbar.visibility = View.VISIBLE
binding.timetable.adapter = TimetableAdapter(this@TimetableFragment, timetable)
}
}
Expand Down
Binary file added app/src/main/res/drawable/arrow.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
15 changes: 15 additions & 0 deletions app/src/main/res/drawable/button.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape>
<solid android:color="@color/primary" />
<corners android:radius="16dp" />
</shape>
</item>
<item>
<shape>
<solid android:color="@color/primary2" />
<corners android:radius="16dp" />
</shape>
</item>
</selector>
8 changes: 8 additions & 0 deletions app/src/main/res/drawable/top_toolbar.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android">
<solid android:color="@color/background1" />
<corners
android:bottomLeftRadius="16dp"
android:bottomRightRadius="16dp"
/>
</shape>
39 changes: 37 additions & 2 deletions app/src/main/res/layout/fragment_timetable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,47 @@
<androidx.recyclerview.widget.RecyclerView
android:id="@+id/timetable"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toBottomOf="@+id/timetable_toolbar">

</androidx.recyclerview.widget.RecyclerView>

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/timetable_toolbar"
android:layout_width="0dp"
android:layout_height="56dp"
android:background="@drawable/top_toolbar"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<ImageView
android:id="@+id/back"
android:layout_width="48dp"
android:layout_height="48dp"
android:scaleType="fitCenter"
android:src="@drawable/arrow"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:tint="@color/primary"
tools:ignore="ContentDescription" />

<TextView
android:id="@+id/timetable_title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/title"
android:textSize="20sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>

</androidx.constraintlayout.widget.ConstraintLayout>
5 changes: 3 additions & 2 deletions app/src/main/res/layout/layout_course.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
android:layout_marginStart="8dp"
android:clipChildren="false"
app:chipSpacingHorizontal="2dp"
app:chipSpacingVertical="1dp"
app:chipSpacingVertical="2dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
Expand All @@ -22,7 +22,8 @@
<TextView
android:id="@+id/course_title"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_height="wrap_content"
android:padding="10dp"
android:text="@string/course_string"
android:textSize="20sp"
android:textStyle="bold" />
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/layout_timetable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
android:id="@+id/day_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/date"
android:text="@string/news_date"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/res/layout/layout_wall.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
android:ellipsize="end"
android:maxLength="35"
android:maxLines="1"
android:text="@string/postTitle"
android:text="@string/news_title"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/left_padding"
app:layout_constraintTop_toTopOf="parent" />
Expand All @@ -26,7 +26,7 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="-4dp"
android:text="@string/date"
android:text="@string/news_date"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/wall_title"
app:layout_constraintTop_toBottomOf="@+id/wall_title"
Expand All @@ -37,7 +37,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="12dp"
android:text="@string/postDescription"
android:text="@string/news_description"
app:layout_constraintEnd_toStartOf="@+id/right_padding"
app:layout_constraintStart_toStartOf="@+id/wall_title"
app:layout_constraintTop_toBottomOf="@+id/wall_date"
Expand Down
31 changes: 18 additions & 13 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,11 +1,26 @@
<resources>
<string name="app_name">KTC</string>

<string name="title">Заголовок</string>
<string name="title_news">Новости</string>
<string name="title_timetable">Расписание</string>
<string name="title_gallery">Галерея</string>
<string name="postTitle">Название поста</string>
<string name="date">19 апр</string>
<string name="postDescription">Краткое описание поста</string>
<string name="title_activity_album">Альбом</string>
<string name="title_activity_wall_post">Новость</string>

<string name="news_title">Название поста</string>
<string name="news_date">19 апр</string>
<string name="news_description">Краткое описание поста</string>
<string name="action_settings">Settings</string>
<string name="course_string">1 Курс</string>

<string name="lesson_title">Проектирование и дизайн информационных систем</string>
<string name="lesson_number">1</string>
<string name="lesson_time">00:00</string>
<string name="lesson_classroom">3.10</string>
<string name="lesson_teacher">Гринь Д. Х.</string>

<string name="lorem_ipsum_title">Lorem ipsum</string>
<string name="lorem_ipsum">
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, "
"sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. "
Expand All @@ -15,14 +30,4 @@
"Excepteur sint occaecat cupidatat non proident, sunt in culpa qui "
"officia deserunt mollit anim id est laborum."
</string>
<string name="lorem_ipsum_title">Lorem ipsum</string>
<string name="title_activity_wall_post">Новость</string>
<string name="action_settings">Settings</string>
<string name="title_activity_album">AlbumActivity</string>
<string name="course_string">1 Курс</string>
<string name="lesson_number">1</string>
<string name="lesson_time">00:00</string>
<string name="lesson_classroom">3.10</string>
<string name="lesson_title">Проектирование и дизайн информационных систем</string>
<string name="lesson_teacher">Гринь Д. Х.</string>
</resources>

0 comments on commit 99bac6e

Please sign in to comment.