Commit 0e07d401 authored by Filip Wiesner's avatar Filip Wiesner

Event detail pin (pin state in SharedPrefs)

parent e638ff1b
......@@ -3,5 +3,5 @@ package com.cvut.blackbird.flows.search
import androidx.lifecycle.ViewModel;
class SearchViewModel : ViewModel() {
// TODO: Implement the ViewModel
}
package com.cvut.blackbird.flows.timetable
import android.content.res.ColorStateList
import android.os.Bundle
import android.view.LayoutInflater
import android.view.View
......@@ -9,10 +10,13 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.ViewModelProviders
import com.cvut.blackbird.R
import com.cvut.blackbird.extensions.getColor
import com.cvut.blackbird.extensions.lastIndexOfNumber
import com.cvut.blackbird.model.Success
import com.cvut.blackbird.model.entities.Event
import com.cvut.blackbird.model.entities.EventType
import com.cvut.blackbird.support.glue.bind
import com.cvut.blackbird.support.glue.clickTo
import com.cvut.blackbird.support.glue.observe
import kotlinx.android.synthetic.main.fragment_timetable_detail.*
......@@ -54,6 +58,11 @@ class TimetableDetailFragment : Fragment() {
detail_teachersContent.text = detail_teachersContent.text.dropLast(1)
}
}
bind(detail_pin) clickTo {
event.isPinned = !event.isPinned
refreshPinTint()
}
}
private fun setupEvent(event: Event) {
......@@ -73,12 +82,20 @@ class TimetableDetailFragment : Fragment() {
detail_parallelContent.text = if (event.parallel.isNotBlank()) event.parallel else "-"
detail_roomContent.text = event.linked?.room ?: "None"
detail_noteContent.text = event.note?.cs ?: "None"
if (event.isPinned) detail_pin.imageTintList = ColorStateList.valueOf(getColor(R.color.colorTextLight))
}
private fun refreshPinTint() {
detail_pin.imageTintList =
if (event.isPinned) ColorStateList.valueOf(getColor(R.color.colorTextLight))
else ColorStateList.valueOf(getColor(R.color.colorTextDark))
}
val String.courseAbbr get() = this.substring(
this.lastIndexOfNumber()
.coerceAtMost(this.length - 3)
.coerceAtLeast(0),
this.length
this.lastIndexOfNumber()
.coerceAtMost(this.length - 3)
.coerceAtLeast(0),
this.length
)
}
\ No newline at end of file
package com.cvut.blackbird.model.entities
import androidx.room.*
import com.cvut.blackbird.model.services.EventsMeta
import com.google.gson.annotations.SerializedName
import org.joda.time.DateTime
......@@ -46,10 +47,16 @@ data class Event(
@SerializedName("links")
val linked: Links?
) {
companion object {
val empty = Event(-1,null,0, DateTime.now(), DateTime.now(), true, 0,0,"", "", null)
companion object {
val empty = Event(-1,null,0, DateTime.now(), DateTime.now(), true, 0,0,"", "", null)
}
val eventType: EventType get() = EventType.parseLowerCase(eventTypeRaw)
var isPinned: Boolean
get() = EventsMeta.pinned.contains(id.toString())
set(value) {
if (value) EventsMeta.pinned.add(id.toString())
else EventsMeta.pinned.remove(id.toString())
}
val eventType: EventType get() = EventType.parseLowerCase(eventTypeRaw)
}
......@@ -75,17 +82,17 @@ data class Note(
)
enum class EventType(cs: String, en: String) {
EXAM("Zkouška","Exam"),
LECTURE("Přednáška","Lecture"),
TUTORIAL("Cvičení","Tutorial"),
UNDEFINED("Nedefinovaný","Undefined");
companion object {
fun parseLowerCase(string: String): EventType {
return EventType.values()
.find {
it.name.toLowerCase() == string
} ?: UNDEFINED
}
EXAM("Zkouška","Exam"),
LECTURE("Přednáška","Lecture"),
TUTORIAL("Cvičení","Tutorial"),
UNDEFINED("Nedefinovaný","Undefined");
companion object {
fun parseLowerCase(string: String): EventType {
return EventType.values()
.find {
it.name.toLowerCase() == string
} ?: UNDEFINED
}
}
}
\ No newline at end of file
......@@ -32,4 +32,13 @@ object UserInfo: KotprefModel() {
object AccountState: KotprefModel() {
var initialized by booleanPref()
}
object EventsMeta: KotprefModel() {
val pinned by stringSetPref()
fun togglePinned(event: String) {
if(pinned.contains(event)) pinned.remove(event)
else pinned.add(event)
}
}
\ No newline at end of file
......@@ -228,7 +228,7 @@ class Wobbly: ScrollView {
}
private lateinit var lineCheckpoint: WobblyElement
override fun onDraw(canvas: Canvas?) {
for (i in 0 until leads.size) { //TODO Fix ArrayList leak
for (i in 0 until leads.size) {
canvas?.drawLine(
headers[leads[i].first].centerX - headerScroll.scrollX,
......
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="24dp"
android:height="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path
android:pathData="M19.083,1c0,1.018 -1.424,1.907 -3.541,2.382V11c2.926,0.652 4.958,2.086 4.958,3.751h-7.792V23h-1.416v-8.25H3.5c0,-1.665 2.032,-3.1 4.958,-3.751V3.382C6.341,2.907 4.917,2.018 4.917,1h14.166z"
android:fillColor="#444"
android:fillType="evenOdd"/>
</vector>
......@@ -5,7 +5,8 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/transparent"
tools:context=".flows.timetable.TimetableDetailFragment">
tools:context=".flows.timetable.TimetableDetailFragment"
android:clipToPadding="false">
<androidx.constraintlayout.widget.ConstraintLayout
......@@ -15,14 +16,16 @@
android:background="@color/colorPrimaryDark"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
app:layout_constraintTop_toTopOf="parent"
android:clipToPadding="false">
<TextView
android:id="@+id/detail_timeTxt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-condensed"
android:paddingStart="6dp"
android:paddingTop="2dp"
......@@ -32,6 +35,7 @@
android:textSize="18sp"
android:textStyle="bold"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="12:34 - 13:56" />
......@@ -53,7 +57,7 @@
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="4dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-condensed"
android:text="{Course full name}"
......@@ -79,6 +83,19 @@
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/detail_fullName"
tools:text="EAR" />
<ImageButton
android:id="@+id/detail_pin"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="12dp"
android:background="?attr/selectableItemBackgroundBorderless"
android:scaleType="fitXY"
android:src="@drawable/ic_pin"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</androidx.constraintlayout.widget.ConstraintLayout>
<LinearLayout
......@@ -86,10 +103,13 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="32dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="32dp"
android:layout_marginBottom="6dp"
android:background="@drawable/rounded_corner"
android:backgroundTint="@color/colorAccent"
android:elevation="6dp"
android:outlineProvider="paddedBounds"
android:paddingStart="16dp"
android:paddingTop="2dp"
android:paddingEnd="16dp"
......@@ -213,7 +233,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-condensed"
android:gravity="end"
android:lineSpacingExtra="4sp"
android:textSize="22sp"
android:textStyle="bold"
......@@ -242,7 +264,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-condensed"
android:gravity="end"
android:textSize="22sp"
android:textStyle="bold"
tools:text="71" />
......@@ -270,7 +294,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-condensed"
android:gravity="end"
android:textSize="22sp"
android:textStyle="bold"
tools:text="T2:C3-337" />
......@@ -298,7 +324,9 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-condensed"
android:gravity="end"
android:textSize="22sp"
android:textStyle="bold"
tools:text="Posledni termin" />
......
......@@ -12,10 +12,8 @@
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="16dp"
android:layout_marginTop="32dp"
android:layout_marginEnd="8dp"
android:background="@drawable/rounded_corner"
android:backgroundTint="@color/colorAccent"
android:fontFamily="sans-serif-condensed"
android:gravity="center"
android:paddingStart="8dp"
......@@ -27,25 +25,26 @@
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
tools:text="Filip Wiesner" />
tools:text="Name Surname" />
<TextView
android:id="@+id/tasksDisclaimer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:gravity="center"
android:text="@string/under_development_disclaimer"
android:textAlignment="center"
android:textSize="42sp"
android:textStyle="bold"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<!--<TextView-->
<!--android:id="@+id/profileDisclaimer"-->
<!--android:layout_width="0dp"-->
<!--android:layout_height="0dp"-->
<!--android:layout_marginStart="8dp"-->
<!--android:layout_marginTop="8dp"-->
<!--android:layout_marginEnd="8dp"-->
<!--android:layout_marginBottom="8dp"-->
<!--android:fontFamily="sans-serif-condensed"-->
<!--android:gravity="center"-->
<!--android:text="@string/under_development_disclaimer"-->
<!--android:textAlignment="center"-->
<!--android:textSize="42sp"-->
<!--android:textStyle="bold"-->
<!--app:layout_constraintBottom_toBottomOf="parent"-->
<!--app:layout_constraintEnd_toEndOf="parent"-->
<!--app:layout_constraintStart_toStartOf="parent"-->
<!--app:layout_constraintTop_toTopOf="parent" />-->
<Button
android:id="@+id/logOutBtn"
......@@ -55,7 +54,7 @@
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Log Out"
app:layout_constraintBottom_toBottomOf="@+id/tasksDisclaimer"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent" />
......
......@@ -8,7 +8,7 @@
android:fillViewport="true">
<TextView
android:id="@+id/tasksDisclaimer"
android:id="@+id/profileDisclaimer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
......
......@@ -25,7 +25,7 @@
</androidx.recyclerview.widget.RecyclerView>
<TextView
android:id="@+id/tasksDisclaimer"
android:id="@+id/profileDisclaimer"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginStart="8dp"
......
......@@ -6,6 +6,5 @@
<string name="under_development_disclaimer">Under Development</string>
<!-- TODO: Remove or change this placeholder text -->
<string name="hello_blank_fragment">Hello blank fragment</string>
</resources>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment