[UI/Dialogs] Remove debug toasts. Remove old Event List Dialog.

This commit is contained in:
Kuba Szczodrzyński 2020-01-06 16:43:31 +01:00
parent ddf66ef061
commit ff0de8afc2
6 changed files with 12 additions and 155 deletions

View File

@ -5,7 +5,6 @@
package pl.szczodrzynski.edziennik.ui.dialogs.day package pl.szczodrzynski.edziennik.ui.dialogs.day
import android.view.View import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -88,7 +87,6 @@ class DayDialog(
adapter = EventListAdapter( adapter = EventListAdapter(
activity, activity,
onItemClick = { onItemClick = {
Toast.makeText(activity, "Event clicked ${it.topic}", Toast.LENGTH_SHORT).show()
EventDetailsDialog( EventDetailsDialog(
activity, activity,
it, it,

View File

@ -11,7 +11,6 @@ import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.* import kotlinx.coroutines.*
import pl.szczodrzynski.edziennik.* import pl.szczodrzynski.edziennik.*
import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi import pl.szczodrzynski.edziennik.data.api.szkolny.SzkolnyApi
import pl.szczodrzynski.edziennik.data.api.task.SzkolnyTask
import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull import pl.szczodrzynski.edziennik.data.db.modules.events.EventFull
import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding import pl.szczodrzynski.edziennik.databinding.DialogEventDetailsBinding
import pl.szczodrzynski.edziennik.utils.models.Date import pl.szczodrzynski.edziennik.utils.models.Date
@ -38,8 +37,6 @@ class EventDetailsDialog(
override val coroutineContext: CoroutineContext override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main get() = job + Dispatchers.Main
private lateinit var adapter: EventListAdapter
private val api by lazy { private val api by lazy {
SzkolnyApi(app) SzkolnyApi(app)
} }

View File

@ -1,141 +0,0 @@
/*
* Copyright (c) Kacper Ziubryniewicz 2019-11-30
*/
package pl.szczodrzynski.edziennik.ui.dialogs.event
import android.graphics.Typeface
import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.dialog.MaterialAlertDialogBuilder
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.Job
import pl.szczodrzynski.edziennik.App
import pl.szczodrzynski.edziennik.R
import pl.szczodrzynski.edziennik.data.db.modules.timetable.Lesson
import pl.szczodrzynski.edziennik.data.db.modules.timetable.LessonFull
import pl.szczodrzynski.edziennik.databinding.DialogEventListBinding
import pl.szczodrzynski.edziennik.utils.models.Date
import pl.szczodrzynski.edziennik.utils.models.Time
import kotlin.coroutines.CoroutineContext
class EventListDialog(
val activity: AppCompatActivity,
val profileId: Int,
val date: Date,
val time: Time? = null,
val onShowListener: ((tag: String) -> Unit)? = null,
val onDismissListener: ((tag: String) -> Unit)? = null
) : CoroutineScope {
companion object {
const val TAG = "EventListDialog"
}
private lateinit var job: Job
override val coroutineContext: CoroutineContext
get() = job + Dispatchers.Main
private val app by lazy { activity.application as App }
private lateinit var b: DialogEventListBinding
private lateinit var dialog: AlertDialog
private lateinit var adapter: EventListAdapter
private var lesson: LessonFull? = null
init {
run {
if (activity.isFinishing)
return@run
job = Job()
onShowListener?.invoke(TAG)
b = DialogEventListBinding.inflate(activity.layoutInflater)
dialog = MaterialAlertDialogBuilder(activity)
.setTitle(date.formattedString + (time?.let { ", " + it.stringHM } ?: ""))
.setView(b.root)
.setPositiveButton(R.string.close) { dialog, _ -> dialog.dismiss() }
.setNeutralButton(R.string.add) { _, _ ->
EventManualDialog(
activity,
lesson?.profileId ?: profileId,
lesson,
date,
time,
onShowListener = onShowListener,
onDismissListener = onDismissListener
)
}
.setOnDismissListener {
onDismissListener?.invoke(TAG)
}
.show()
app.db.timetableDao().getForDate(profileId, date).observe(activity, Observer { lessons ->
lesson = lessons.firstOrNull { it.displayStartTime == time }
update()
})
}
}
fun dismiss() = dialog.dismiss()
private fun update() {
b.eventListLessonDetails.visibility = if (lesson == null) View.GONE else View.VISIBLE
if (lesson != null) {
dialog.setTitle(if (time == null) date.formattedString else (lesson?.displaySubjectName
?: date.formattedString) + ", " + time.stringHM)
b.eventListLessonDate.text = app.getString(R.string.date_time_format, date.formattedString, "")
if (lesson?.type == Lesson.TYPE_CANCELLED) {
b.eventListLessonChange.text = app.getString(R.string.lesson_cancelled)
b.eventListLessonChange.setTypeface(null, Typeface.BOLD_ITALIC)
b.eventListTeacher.visibility = View.GONE
b.eventListClassroom.visibility = View.GONE
} else {
b.eventListLessonChange.text = lesson?.changeSubjectName
b.eventListLessonChange.setTypeface(null, Typeface.ITALIC)
b.eventListLessonChange.visibility = if (lesson?.isSubjectNameChanged == true) View.VISIBLE else View.GONE
b.eventListTeacher.text = lesson?.changeTeacherName
b.eventListTeacher.setTypeface(null, if (lesson?.isTeacherNameChanged == true) Typeface.ITALIC else Typeface.NORMAL)
b.eventListClassroom.text = lesson?.changeClassroom
b.eventListClassroom.setTypeface(null, if (lesson?.isClassroomChanged == true) Typeface.ITALIC else Typeface.NORMAL)
}
}
b.eventListView.apply {
setHasFixedSize(false)
isNestedScrollingEnabled = true
layoutManager = LinearLayoutManager(activity)
}
adapter = EventListAdapter(activity) {
Toast.makeText(activity, "Event clicked ${it.topic}", Toast.LENGTH_SHORT).show()
}
b.eventListView.adapter = adapter
app.db.eventDao().getAllByDateTime(profileId, date, time).observe(activity, Observer { events ->
if (events.isNullOrEmpty()) {
b.eventListView.visibility = View.GONE
b.textNoEvents.visibility = View.VISIBLE
} else {
adapter.run {
/*items.apply {
clear()
addAll(events)
}*/
notifyDataSetChanged()
}
}
})
}
}

View File

@ -611,15 +611,15 @@ class EventManualDialog(
val profile = app.db.profileDao().getByIdNow(profileId) val profile = app.db.profileDao().getByIdNow(profileId)
if (!share && !editingShared) { if (!share && !editingShared) {
Toast.makeText(activity, "Save without sharing", Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_saving, Toast.LENGTH_SHORT).show()
finishAdding(eventObject, metadataObject) finishAdding(eventObject, metadataObject)
} }
else if (editingShared && !editingOwn) { else if (editingShared && !editingOwn) {
Toast.makeText(activity, "Request editing somebody's event", Toast.LENGTH_SHORT).show() Toast.makeText(activity, "Opcja edycji wydarzeń innych uczniów nie została jeszcze zaimplementowana.", Toast.LENGTH_LONG).show()
// TODO // TODO
} }
else if (!share && editingShared) { else if (!share && editingShared) {
Toast.makeText(activity, "Unshare own event", Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_unshare, Toast.LENGTH_SHORT).show()
eventObject.apply { eventObject.apply {
sharedBy = null sharedBy = null
@ -639,7 +639,7 @@ class EventManualDialog(
finishAdding(eventObject, metadataObject) finishAdding(eventObject, metadataObject)
} }
else if (share) { else if (share) {
Toast.makeText(activity, "Share/update own event", Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_share, Toast.LENGTH_SHORT).show()
eventObject.apply { eventObject.apply {
sharedBy = profile?.userCode sharedBy = profile?.userCode
@ -669,7 +669,7 @@ class EventManualDialog(
private fun removeEvent() { private fun removeEvent() {
launch { launch {
if (editingShared && editingOwn) { if (editingShared && editingOwn) {
Toast.makeText(activity, "Unshare + remove own event", Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_unshare_remove, Toast.LENGTH_SHORT).show()
val response = withContext(Dispatchers.Default) { val response = withContext(Dispatchers.Default) {
api.unshareEvent(editingEvent!!) api.unshareEvent(editingEvent!!)
@ -682,10 +682,10 @@ class EventManualDialog(
finishRemoving() finishRemoving()
} else if (editingShared && !editingOwn) { } else if (editingShared && !editingOwn) {
Toast.makeText(activity, "Remove + blacklist somebody's event", Toast.LENGTH_SHORT).show() Toast.makeText(activity, "Nie zaimplementowana opcja :(", Toast.LENGTH_SHORT).show()
// TODO // TODO
} else { } else {
Toast.makeText(activity, "Remove event", Toast.LENGTH_SHORT).show() Toast.makeText(activity, R.string.event_manual_remove, Toast.LENGTH_SHORT).show()
finishRemoving() finishRemoving()
} }
} }

View File

@ -6,7 +6,6 @@ package pl.szczodrzynski.edziennik.ui.dialogs.timetable
import android.content.Intent import android.content.Intent
import android.view.View import android.view.View
import android.widget.Toast
import androidx.appcompat.app.AlertDialog import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.Observer import androidx.lifecycle.Observer
@ -166,7 +165,6 @@ class LessonDetailsDialog(
adapter = EventListAdapter( adapter = EventListAdapter(
activity, activity,
onItemClick = { onItemClick = {
Toast.makeText(activity, "Event clicked ${it.topic}", Toast.LENGTH_SHORT).show()
EventDetailsDialog( EventDetailsDialog(
activity, activity,
it, it,

View File

@ -1152,4 +1152,9 @@
<string name="timetable_generate_no_colors">Do wydruku (czarno-białe)</string> <string name="timetable_generate_no_colors">Do wydruku (czarno-białe)</string>
<string name="timetable_generate_selected_week">Na wybrany tydzień</string> <string name="timetable_generate_selected_week">Na wybrany tydzień</string>
<string name="edziennik_progress_endpoint_lessons">Pobieranie listy lekcji…</string> <string name="edziennik_progress_endpoint_lessons">Pobieranie listy lekcji…</string>
<string name="event_manual_saving">Zapisuję wydarzenie...</string>
<string name="event_manual_unshare">Usuwam wydarzenie u reszty klasy...</string>
<string name="event_manual_share">Udostępniam wydarzenie...</string>
<string name="event_manual_unshare_remove">Usuwam udostępnione wydarzenie...</string>
<string name="event_manual_remove">Usuwam wydarzenie...</string>
</resources> </resources>