Skip to content
This repository has been archived by the owner on Jan 10, 2024. It is now read-only.

Linting Part 1 #1618

Merged
merged 24 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from 15 commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@ package de.tum.`in`.tumcampusapp.api.app.model
import com.google.gson.annotations.SerializedName

/**
* @param fcmToken can be null/uploaded/invalid
* @param publicKey can be null/uploaded/verified
* @param studentId true if uploaded
* @param employeeId true if uploaded
* @param externalId true if uploaded
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class EscapedStringConverter : TypeConverter<String> {
return if (Build.VERSION.SDK_INT >= 24) {
Html.fromHtml(str, Html.FROM_HTML_MODE_LEGACY).toString()
} else {
@Suppress("DEPRECATION") // SDK version checked
Html.fromHtml(str).toString()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ class BaseNavigationActivity :
}

private val drawerLayout: DrawerLayout by lazy {
findViewById<DrawerLayout>(R.id.drawer_layout)
findViewById(R.id.drawer_layout)
}

private val navigationView: NavigationView by lazy {
findViewById<NavigationView>(R.id.left_drawer)
findViewById(R.id.left_drawer)
}

private val drawerMenuHelper: DrawerMenuHelper by lazy {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,35 +54,35 @@ abstract class ProgressActivity<T>(
}

protected val swipeRefreshLayout: SwipeRefreshLayout? by lazy {
findViewById<SwipeRefreshLayout>(R.id.swipeRefreshLayout)
findViewById(R.id.swipeRefreshLayout)
}

private val errorLayoutsContainer: FrameLayout by lazy {
findViewById<FrameLayout>(R.id.errors_layout)
findViewById(R.id.errors_layout)
}

private val errorLayout: LinearLayout by lazy {
findViewById<LinearLayout>(R.id.layout_error)
findViewById(R.id.layout_error)
}

private val errorIconImageView: ImageView by lazy {
findViewById<ImageView>(R.id.iconImageView)
findViewById(R.id.iconImageView)
}

private val errorHeaderTextView: TextView by lazy {
errorLayout.findViewById<TextView>(R.id.headerTextView)
errorLayout.findViewById(R.id.headerTextView)
}

private val errorMessageTextView: TextView by lazy {
errorLayout.findViewById<TextView>(R.id.messageTextView)
errorLayout.findViewById(R.id.messageTextView)
}

private val errorButton: MaterialButton by lazy {
errorLayout.findViewById<MaterialButton>(R.id.button)
errorLayout.findViewById(R.id.button)
}

private val progressLayout: FrameLayout by lazy {
findViewById<FrameLayout>(R.id.layout_progress)
findViewById(R.id.layout_progress)
}

private var registered: Boolean = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package de.tum.`in`.tumcampusapp.component.tumui.calendar

import android.app.Activity
import android.app.DatePickerDialog
import android.content.Context
import android.content.Intent
import android.content.res.ColorStateList
Expand Down Expand Up @@ -39,7 +38,6 @@ import retrofit2.Callback
import retrofit2.Response
import java.net.UnknownHostException
import java.util.Locale
import kotlin.collections.ArrayList

/**
* Allows the user to create (and edit) a private event in TUMonline.
Expand Down Expand Up @@ -184,7 +182,7 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R

binding.eventLastDateView.setOnClickListener {
hideKeyboard()
DatePickerDialog(this, { _, year, month, dayOfMonth ->
ThemedDatePickerDialog(this, { _, year, month, dayOfMonth ->
repeatHelper.end = repeatHelper.end?.withDate(year, month + 1, dayOfMonth)
updateDateViews()
}, repeatHelper.end?.year!!, repeatHelper.end?.monthOfYear!! - 1, repeatHelper.end?.dayOfMonth!!).show()
Expand All @@ -202,11 +200,7 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R
}

// We’re creating a new event, so we set the start and end time to the next full hour
start = initialDate.toDateTimeAtCurrentTime()
.plusHours(1)
.withMinuteOfHour(0)
.withSecondOfMinute(0)
.withMillisOfSecond(0)
start = initialDate.toDateTimeAtCurrentTime().plusHours(1).withMinuteOfHour(0).withSecondOfMinute(0).withMillisOfSecond(0)
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
end = start.plusHours(1)
repeatHelper.end = end.plusWeeks(1)
} else {
Expand All @@ -224,31 +218,19 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R
val eventTitle = extras?.getSerializable(Const.EVENT_TITLE) as String?
val startTime = extras?.getSerializable(Const.EVENT_START) as DateTime?

if (eventNr == null || eventTitle == null || startTime == null) {
return
}
if (eventNr == null || eventTitle == null || startTime == null) return

val calendarItem = CalendarItem(
nr = eventNr,
title = eventTitle,
dtstart = startTime,
url = ""
)
val calendarItem = CalendarItem(nr = eventNr, title = eventTitle, dtstart = startTime, url = "")

val currentColor = eventColorController.getResourceColor(calendarItem)
val colorText = getTextColorByColor(currentColor)
binding.colorChangeBtn?.text = getString(colorText)
binding.colorChangeBtn?.buttonTintList = ColorStateList.valueOf(ContextCompat.getColor(this, currentColor))

binding.colorChangeBtn?.setOnClickListener {
val dialog = ChangeEventColorDialog(
context = this,
calendarItem = calendarItem,
onColorChanged = { data ->
updateEventColorInput(data)
},
fromCreateEventActivity = true
)
val dialog = ChangeEventColorDialog(context = this, calendarItem = calendarItem, onColorChanged = { data ->
updateEventColorInput(data)
}, fromCreateEventActivity = true)
dialog.show()
dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
Expand All @@ -273,14 +255,9 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R

private fun initEventColorOnClickListener() {
binding.colorChangeBtn?.setOnClickListener {
val dialog = ChangeEventColorDialog(
context = this,
calendarItem = CalendarItem(),
onColorChanged = { data ->
updateEventColorInput(data)
},
fromCreateEventActivity = true
)
val dialog = ChangeEventColorDialog(context = this, calendarItem = CalendarItem(), onColorChanged = { data ->
updateEventColorInput(data)
}, fromCreateEventActivity = true)
dialog.show()
dialog.window?.setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT)
}
Expand Down Expand Up @@ -320,47 +297,35 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R
}

// TIME
binding.eventStartTimeView.setOnClickListener {
binding.eventStartTimeView.setOnClickListener { _ ->
hideKeyboard()
ThemedTimePickerDialog(
this,
{ timePicker, hour, minute ->
timePicker.layoutParams = LinearLayout.LayoutParams(
LinearLayout.LayoutParams.WRAP_CONTENT,
LinearLayout.LayoutParams.WRAP_CONTENT
)
val eventLength = end.millis - start.millis
start = start.withHourOfDay(hour).withMinuteOfHour(minute)
end = end.withMillis(start.millis + eventLength)
updateTimeViews()
},
start.hourOfDay,
start.minuteOfHour
).show()
}

binding.eventEndTimeView.setOnClickListener {
ThemedTimePickerDialog(this, { _, hour, minute ->
val eventLength = end.millis - start.millis
start = start.withHourOfDay(hour).withMinuteOfHour(minute)
end = end.withMillis(start.millis + eventLength)
updateTimeViews()
}, start.hourOfDay, start.minuteOfHour).show()
}

binding.eventEndTimeView.setOnClickListener { _ ->
hideKeyboard()
ThemedTimePickerDialog(this, { _, hour, minute ->
end = end.withHourOfDay(hour)
.withMinuteOfHour(minute)
end = end.withHourOfDay(hour).withMinuteOfHour(minute)
updateTimeViews()
}, end.hourOfDay, end.minuteOfHour).show()
}
}

private fun updateTimeViews() {
val format = DateTimeFormat.forPattern("HH:mm")
.withLocale(Locale.getDefault())
val format = DateTimeFormat.forPattern("HH:mm").withLocale(Locale.getDefault())
with(binding) {
eventStartTimeView.text = format.print(start)
eventEndTimeView.text = format.print(end)
}
}

private fun updateDateViews() {
val format = DateTimeFormat.forPattern("EEE, dd.MM.yyyy")
.withLocale(Locale.getDefault())
val format = DateTimeFormat.forPattern("EEE, dd.MM.yyyy").withLocale(Locale.getDefault())
with(binding) {
eventStartDateView.text = format.print(start)
eventEndDateView.text = format.print(end)
Expand All @@ -376,31 +341,23 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R
// request), we use a short Toast to let the user know that something is happening.
Toast.makeText(this, R.string.updating_event, Toast.LENGTH_SHORT).show()

apiClient
.deleteEvent(eventId)
.enqueue(object : Callback<DeleteEventResponse> {
override fun onResponse(
call: Call<DeleteEventResponse>,
response: Response<DeleteEventResponse>
) {
if (response.isSuccessful) {
Utils.log("Event successfully deleted (now creating the edited version)")
TcaDb.getInstance(this@CreateEventActivity).calendarDao().delete(eventId)
eventColorController.removeEventColor(eventId)
createEvent()
} else {
Utils.showToast(this@CreateEventActivity, R.string.error_unknown)
}
apiClient.deleteEvent(eventId).enqueue(object : Callback<DeleteEventResponse> {
override fun onResponse(call: Call<DeleteEventResponse>, response: Response<DeleteEventResponse>) {
if (response.isSuccessful) {
Utils.log("Event successfully deleted (now creating the edited version)")
TcaDb.getInstance(this@CreateEventActivity).calendarDao().delete(eventId)
eventColorController.removeEventColor(eventId)
createEvent()
} else {
Utils.showToast(this@CreateEventActivity, R.string.error_unknown)
}
}

override fun onFailure(
call: Call<DeleteEventResponse>,
t: Throwable
) {
Utils.log(t)
displayErrorMessage(t)
}
})
override fun onFailure(call: Call<DeleteEventResponse>, t: Throwable) {
Utils.log(t)
displayErrorMessage(t)
}
})
}

private fun displayErrorMessage(throwable: Throwable) {
Expand Down Expand Up @@ -473,19 +430,7 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R
// event ends after n times
if (repeatHelper.isRepeatingNTimes()) {
for (i in 1 until repeatHelper.times) {
events.add(
CalendarItem(
"",
"",
"",
baseEvent.title,
baseEvent.description,
baseEvent.dtstart.plusWeeks(i),
baseEvent.dtend.plusWeeks(i),
"",
false
)
)
events.add(CalendarItem("", "", "", baseEvent.title, baseEvent.description, baseEvent.dtstart.plusWeeks(i), baseEvent.dtend.plusWeeks(i), "", false))
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}
// event ends after "last" date
} else {
Expand Down Expand Up @@ -541,7 +486,6 @@ class CreateEventActivity : ActivityForAccessingTumOnline<CreateEventResponse>(R
finish()
}

@Deprecated("Deprecated in Java")
override fun onBackPressed() {
hideKeyboard()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,23 @@ import org.joda.time.DateTime
/**
* A class to represent events for the integrated WeekView calendar
*/
data class WidgetCalendarItem(
val id: String,
val title: String,
val startTime: DateTime,
val endTime: DateTime,
val location: String
) : WeekViewDisplayable<WidgetCalendarItem> {
data class WidgetCalendarItem(val id: String, val title: String, val startTime: DateTime, val endTime: DateTime, val location: String) : WeekViewDisplayable<WidgetCalendarItem> {

var color: Int = 0

var isFirstOnDay: Boolean = false

override fun toWeekViewEvent(): WeekViewEvent<WidgetCalendarItem> {
val style = WeekViewEvent.Style.Builder()
.setBackgroundColor(color)
.build()

return WeekViewEvent.Builder<WidgetCalendarItem>(this)
.setId(id.toLong())
.setTitle(title)
.setStartTime(startTime.toGregorianCalendar())
.setEndTime(endTime.toGregorianCalendar())
.setLocation(location)
.setAllDay(false)
.setStyle(style)
.build()
val style = WeekViewEvent.Style.Builder().setBackgroundColor(color).build()

return WeekViewEvent.Builder(this).setId(id.toLong()).setTitle(title).setStartTime(startTime.toGregorianCalendar()).setEndTime(endTime.toGregorianCalendar()).setLocation(location).setAllDay(false).setStyle(style).build()
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}

companion object {

@JvmStatic
fun create(calendarItem: CalendarItem): WidgetCalendarItem {
return WidgetCalendarItem(
calendarItem.nr,
calendarItem.getFormattedTitle(),
calendarItem.eventStart,
calendarItem.eventEnd,
calendarItem.getEventLocation()
)
return WidgetCalendarItem(calendarItem.nr, calendarItem.getFormattedTitle(), calendarItem.eventStart, calendarItem.eventEnd, calendarItem.getEventLocation())
CommanderStorm marked this conversation as resolved.
Show resolved Hide resolved
}

@JvmStatic
Expand Down
Loading