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

Commit

Permalink
Linting Part 1 (#1618)
Browse files Browse the repository at this point in the history
* variable renaming to _

* removed unused qualifier names

* removed unused qualifier types

* removed unnecessary init block

* annotations, imports, monochrome icon

* automated cleanup

* app:tint & plurals in string.xml

* faulty linting

* removed observer wrapper

* remaining ktlintMainSourceChecks

indentations & newlines at the end of files

* code review feedback

Co-authored-by: Frank Elsinga <[email protected]>

* Whitespace fix

---------

Co-authored-by: Frank Elsinga <[email protected]>
  • Loading branch information
tobiasjungmann and CommanderStorm authored Sep 20, 2023
1 parent 456f51e commit cd13ff2
Show file tree
Hide file tree
Showing 32 changed files with 116 additions and 172 deletions.
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 Down Expand Up @@ -224,31 +222,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 +259,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 +301,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()
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 {
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 +345,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 @@ -541,7 +502,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,24 +10,16 @@ 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()
val style = WeekViewEvent.Style.Builder().setBackgroundColor(color).build()

return WeekViewEvent.Builder<WidgetCalendarItem>(this)
return WeekViewEvent.Builder(this)
.setId(id.toLong())
.setTitle(title)
.setStartTime(startTime.toGregorianCalendar())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,7 @@ data class CalendarItem(
}

fun isSameEventButForLocation(other: CalendarItem): Boolean {
return title == other.title &&
dtstart == other.dtstart &&
dtend == other.dtend
return title == other.title && dtstart == other.dtstart && dtend == other.dtend
}

override fun toWeekViewEvent(): WeekViewEvent<CalendarItem> {
Expand All @@ -132,7 +130,7 @@ data class CalendarItem(
.setBorderColor(color)
.build()

return WeekViewEvent.Builder<CalendarItem>(this)
return WeekViewEvent.Builder(this)
.setId(nr.toLong())
.setTitle(title)
.setStartTime(eventStart.toGregorianCalendar())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -182,7 +182,7 @@ class ExamListAdapter(context: Context, results: List<Exam>, gradesFragment: Gra
private fun initCheckBoxUsedInAverage(exam: Exam, holder: ViewHolder) {
holder.checkBoxUseGradeForAverage.isChecked = exam.gradeUsedInAverage
adaptUIToCheckboxStatus(holder, exam)
holder.checkBoxUseGradeForAverage.setOnClickListener() {
holder.checkBoxUseGradeForAverage.setOnClickListener {
exam.gradeUsedInAverage = holder.checkBoxUseGradeForAverage.isChecked
adaptUIToCheckboxStatus(holder, exam)
localGradesFragment.storeExamListInSharedPreferences()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ class GradesFragment : FragmentForAccessingTumOnline<ExamList>(
val desc = Description()
desc.text = context.getString(R.string.grade_percentages)

desc.setTextSize(11f)
desc.textSize = 11f
desc.setPosition(540F, 50F)
description = desc
axisRight.disableGridDashedLine()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ import android.view.View
import android.view.ViewGroup
import androidx.core.view.isVisible
import androidx.fragment.app.Fragment
import androidx.lifecycle.Observer
import androidx.lifecycle.ViewModelProvider
import androidx.recyclerview.widget.DefaultItemAnimator
import androidx.recyclerview.widget.LinearLayoutManager
import com.zhuinden.fragmentviewbindingdelegatekt.viewBinding
import de.tum.`in`.tumcampusapp.R
import de.tum.`in`.tumcampusapp.component.ui.cafeteria.model.CafeteriaMenu
import de.tum.`in`.tumcampusapp.databinding.FragmentCafeteriadetailsSectionBinding
import de.tum.`in`.tumcampusapp.di.ViewModelFactory
import de.tum.`in`.tumcampusapp.di.injector
Expand Down Expand Up @@ -93,9 +91,8 @@ class CafeteriaDetailsSectionFragment : Fragment() {
menusRecyclerView.adapter = adapter

cafeteriaViewModel.cafeteriaMenus.observe(
viewLifecycleOwner,
Observer<List<CafeteriaMenu>> { adapter.update(it) }
)
viewLifecycleOwner
) { adapter.update(it) }
cafeteriaViewModel.fetchCafeteriaMenus(cafeteriaId, menuDate)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ class NewsNotificationProvider(

override fun buildNotification(): AppNotification {
val summaryTitle = context.getString(R.string.news)
val summaryText = context.getString(R.string.new_items_format_string, newsItems.size)

val summaryText = context.resources.getQuantityString(R.plurals.new_items_format_string, newsItems.size, newsItems.size)
val inboxStyle = NotificationCompat.InboxStyle()
newsItems.forEach { inboxStyle.addLine(it.title) }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ class NewsViewHolder(
private val showOptionsButton: Boolean = true
) : CardViewHolder(itemView, interactionListener) {

private val optionsButtonGroup: Group by lazy { itemView.findViewById<Group>(R.id.cardMoreIconGroup) }
private val imageView: ImageView? by lazy { itemView.findViewById<ImageView>(R.id.news_img) }
private val titleTextView: TextView? by lazy { itemView.findViewById<TextView>(R.id.news_title) }
private val dateTextView: TextView by lazy { itemView.findViewById<TextView>(R.id.news_src_date) }
private val sourceTextView: TextView by lazy { itemView.findViewById<TextView>(R.id.news_src_title) }
private val ticketsIcon: ImageView? by lazy { itemView.findViewById<ImageView>(R.id.tickets_icon) }
private val ticketsTextView: TextView? by lazy { itemView.findViewById<TextView>(R.id.tickets_available) }
private val optionsButtonGroup: Group by lazy { itemView.findViewById(R.id.cardMoreIconGroup) }
private val imageView: ImageView? by lazy { itemView.findViewById(R.id.news_img) }
private val titleTextView: TextView? by lazy { itemView.findViewById(R.id.news_title) }
private val dateTextView: TextView by lazy { itemView.findViewById(R.id.news_src_date) }
private val sourceTextView: TextView by lazy { itemView.findViewById(R.id.news_src_title) }
private val ticketsIcon: ImageView? by lazy { itemView.findViewById(R.id.tickets_icon) }
private val ticketsTextView: TextView? by lazy { itemView.findViewById(R.id.tickets_available) }

fun bind(newsItem: News, newsSource: NewsSources, hasEvent: Boolean) = with(itemView) {
val card = if (newsItem.isFilm) FilmCard(context, newsItem) else NewsCard(context = context, news = newsItem)
Expand Down
Loading

0 comments on commit cd13ff2

Please sign in to comment.