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

bumped gradle to the last version before 8.0.0 #1591

Merged
merged 8 commits into from
Aug 29, 2023
  •  
  •  
  •  
16 changes: 10 additions & 6 deletions app/src/main/java/de/tum/in/tumcampusapp/App.kt
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ open class App : Application() {
// We use Dagger 2 for dependency injection. The main AppModule and AppComponent can be
// found in the package "di".
appComponent = DaggerAppComponent.builder()
.context(this)
.build()
.context(this)
.build()
}

protected open fun setupPicasso() {
Expand All @@ -53,13 +53,16 @@ open class App : Application() {

protected fun setupStrictMode() {
if (BuildConfig.DEBUG) {
StrictMode.setThreadPolicy(StrictMode.ThreadPolicy.Builder()
StrictMode.setThreadPolicy(
StrictMode.ThreadPolicy.Builder()
.detectAll()
.permitDiskReads() // These are mainly caused by shared preferences and room. Probably enable
.permitDiskWrites() // this as soon as we don't call allowMainThreadQueries() in TcaDb
.penaltyLog()
.build())
StrictMode.setVmPolicy(StrictMode.VmPolicy.Builder()
.build()
)
StrictMode.setVmPolicy(
StrictMode.VmPolicy.Builder()
.detectActivityLeaks()
// .detectLeakedClosableObjects() // seems like room / DAOs leak
.detectLeakedRegistrationObjects()
Expand All @@ -68,7 +71,8 @@ open class App : Application() {
// .detectContentUriWithoutPermission()
// .detectUntaggedSockets()
.penaltyLog()
.build())
.build()
)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@ class BackendHelper {
println(newsSources.getSources(0))
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
package de.tum.`in`.tumcampusapp.api.app

import com.google.gson.*
import com.google.gson.JsonDeserializationContext
import com.google.gson.JsonDeserializer
import com.google.gson.JsonElement
import com.google.gson.JsonParseException
import com.google.gson.JsonPrimitive
import com.google.gson.JsonSerializationContext
import com.google.gson.JsonSerializer
import de.tum.`in`.tumcampusapp.utils.DateTimeUtils
import org.joda.time.DateTime
import org.joda.time.format.DateTimeFormat
Expand Down Expand Up @@ -49,4 +55,4 @@ class DateSerializer : JsonDeserializer<DateTime>, JsonSerializer<DateTime> {
): JsonElement {
return JsonPrimitive(DateTimeUtils.getDateString(time))
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ import java.io.InterruptedIOException
* Exception for resilience testing your network error handling
* If this exception crashes your app, you should feel bad and implement proper error handling
*/
class ChaosMonkeyException(url: String) : InterruptedIOException("Some requests might spontaneously fail ($url)")
class ChaosMonkeyException(url: String) : InterruptedIOException("Some requests might spontaneously fail ($url)")
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,18 @@ data class DeviceRegister(
val rand = BigInteger(130, SecureRandom()).toString(32)
val device = AuthenticationManager.getDeviceID(c)

return DeviceRegister(date = date, rand = rand, device = device, publicKey = publickey, member = member,
signature =
if (member == null)
am.sign(date + rand + device)
else
am.sign(date + rand + device + member.lrzId + member.id)
return DeviceRegister(
date = date,
rand = rand,
device = device,
publicKey = publickey,
member = member,
signature =
if (member == null) {
am.sign(date + rand + device)
} else {
am.sign(date + rand + device + member.lrzId + member.id)
}
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ data class DeviceUploadFcmToken(
fun getDeviceUploadFcmToken(c: Context, token: String): DeviceUploadFcmToken {
val verification = TUMCabeVerification.create(c) ?: throw NoPrivateKey()
return DeviceUploadFcmToken(
verification = verification,
token = token,
signature = AuthenticationManager(c).sign(token)
verification = verification,
token = token,
signature = AuthenticationManager(c).sign(token)
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ data class TUMCabeVerification(
return TUMCabeVerification(signature, date, rand, deviceID, data)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ class CafeteriaAPIClient(private val apiService: CafeteriaAPIService) {
val cacheManager = CacheManager(context)

val client = ApiHelper.getOkHttpClient(context)
.newBuilder()
.cache(cacheManager.cache)
.addNetworkInterceptor(CacheResponseInterceptor())
.build()
.newBuilder()
.cache(cacheManager.cache)
.addNetworkInterceptor(CacheResponseInterceptor())
.build()

val gson = GsonBuilder()
.registerTypeAdapter(DateTime::class.java, DateSerializer())
.create()
.registerTypeAdapter(DateTime::class.java, DateSerializer())
.create()

val apiService = Retrofit.Builder()
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
.create(CafeteriaAPIService::class.java)
.baseUrl(BASE_URL)
.client(client)
.addConverterFactory(GsonConverterFactory.create(gson))
.build()
.create(CafeteriaAPIService::class.java)

return CafeteriaAPIClient(apiService)
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ interface CafeteriaAPIService {
fun getMenus(
@Header("Cache-Control") cacheControl: String
): Call<CafeteriaResponse>
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ data class NavigationDetails(
}

fun NavigationDetailsDto.toNavigationDetails(): NavigationDetails {

return NavigationDetails(
id = this.id,
name = this.name,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,11 @@ data class NavigationEntity(
) : Serializable {

fun getFormattedName(): String {
return if (parsedId == null) removeHighlight(name)
else removeHighlight(parsedId!!) + " ➤ " + removeHighlight(name)
return if (parsedId == null) {
removeHighlight(name)
} else {
removeHighlight(parsedId!!) + " ➤ " + removeHighlight(name)
}
}

fun getFormattedSubtext(): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ package de.tum.`in`.tumcampusapp.api.tumonline
enum class CacheControl(val header: String) {
BYPASS_CACHE("no-cache"),
USE_CACHE("public")
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,21 @@ class TUMOnlineClient(private val apiService: TUMOnlineAPIService) {

fun getCalendar(cacheControl: CacheControl): Call<EventsResponse> {
return apiService.getCalendar(
Const.CALENDAR_MONTHS_BEFORE, Const.CALENDAR_MONTHS_AFTER, cacheControl.header
Const.CALENDAR_MONTHS_BEFORE,
Const.CALENDAR_MONTHS_AFTER,
cacheControl.header
)
}

fun createEvent(calendarItem: CalendarItem, eventId: String?): Call<CreateEventResponse> {
val start = DateTimeUtils.getDateTimeString(calendarItem.eventStart)
val end = DateTimeUtils.getDateTimeString(calendarItem.eventEnd)
return apiService.createCalendarEvent(
calendarItem.title, calendarItem.description, start, end, eventId
calendarItem.title,
calendarItem.description,
start,
end,
eventId
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ class EscapedStringConverter : TypeConverter<String> {
override fun write(value: String): String {
return value
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@ class FloatConverter : TypeConverter<Float> {
override fun read(value: String?): Float {
return try {
NumberFormat.getInstance(Locale.GERMAN)
.parse(value)
.toFloat()
.parse(value)
.toFloat()
} catch (e: ParseException) {
0f
}
}

override fun write(value: Float?) = value?.toString() ?: ""
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,4 @@ class NullableEscapedStringConverter : TypeConverter<String?> {
override fun write(value: String?): String? {
return value
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class InactiveTokenException : InterruptedIOException() {

override val message: String
get() = "The user’s access token is inactive"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class InvalidTokenException : InterruptedIOException() {

override val message: String
get() = "The user’s token is not confirmed or invalid"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class MissingPermissionException : InterruptedIOException() {

override val message: String
get() = "Token is active but specific permission not given"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class RequestLimitReachedException : InterruptedIOException() {

override val message: String
get() = "The user has made to many requests to TUMonline. Try again later."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class TokenLimitReachedException : InterruptedIOException() {

override val message: String
get() = "The user reached the limited of 10 active tokens"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ class UnknownErrorException : InterruptedIOException() {

override val message: String
get() = "Unknown Exception..."
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ class AddTokenInterceptor(private val context: Context) : Interceptor {

private fun loadAccessTokenFromPreferences(context: Context): String? {
return PreferenceManager
.getDefaultSharedPreferences(context)
.getString(Const.ACCESS_TOKEN, null)
.getDefaultSharedPreferences(context)
.getString(Const.ACCESS_TOKEN, null)
}

override fun intercept(chain: Interceptor.Chain): Response {
Expand All @@ -28,12 +28,12 @@ class AddTokenInterceptor(private val context: Context) : Interceptor {

accessToken?.let {
url = url
.newBuilder()
.addQueryParameter("pToken", it)
.build()
.newBuilder()
.addQueryParameter("pToken", it)
.build()
}

val modifiedRequest = request.newBuilder().url(url).build()
return chain.proceed(modifiedRequest)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,4 @@ class CacheResponseInterceptor : Interceptor {
response
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,36 +11,36 @@ class CachingHelper {

private fun getCachingDuration(url: String): Duration {
return cachingDurations
.filter { url.contains(it.first) }
.map { it.second }
.firstOrNull() ?: Duration.ZERO
.filter { url.contains(it.first) }
.map { it.second }
.firstOrNull() ?: Duration.ZERO
}

fun updateCacheControlHeader(url: String, response: Response): Response {
val duration = getCachingDuration(url)

val maxAge = duration.toStandardDays().days
val cacheControl = CacheControl.Builder()
.maxAge(maxAge, TimeUnit.DAYS)
.build()
.maxAge(maxAge, TimeUnit.DAYS)
.build()

return response.newBuilder()
.removeHeader("Cache-Control")
.addHeader("Cache-Control", cacheControl.toString())
.build()
.removeHeader("Cache-Control")
.addHeader("Cache-Control", cacheControl.toString())
.build()
}

companion object {

private val cachingDurations = listOf(
Pair("kalender", Duration.standardDays(1)),
Pair("studienbeitragsstatus", Duration.standardDays(1)),
Pair("veranstaltungenEigene", Duration.standardDays(1)),
Pair("veranstaltungenDetails", Duration.standardDays(5)),
Pair("veranstaltungenTermine", Duration.standardDays(5)),
Pair("personenDetails", Duration.standardDays(5)),
Pair("noten", Duration.standardDays(1)),
Pair("mensaapp", Duration.standardDays(1))
Pair("kalender", Duration.standardDays(1)),
Pair("studienbeitragsstatus", Duration.standardDays(1)),
Pair("veranstaltungenEigene", Duration.standardDays(1)),
Pair("veranstaltungenDetails", Duration.standardDays(5)),
Pair("veranstaltungenTermine", Duration.standardDays(5)),
Pair("personenDetails", Duration.standardDays(5)),
Pair("noten", Duration.standardDays(1)),
Pair("mensaapp", Duration.standardDays(1))
)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import java.io.InterruptedIOException
class CheckErrorInterceptor(private val context: Context) : Interceptor {

private val tikXml = TikXml.Builder()
.exceptionOnUnreadXml(false)
.build()
.exceptionOnUnreadXml(false)
.build()

@Throws(InterruptedIOException::class)
override fun intercept(chain: Interceptor.Chain): Response {
Expand Down Expand Up @@ -43,4 +43,4 @@ class CheckErrorInterceptor(private val context: Context) : Interceptor {

return response
}
}
}
Loading