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

Replace anko (v2) #1615

Merged
merged 50 commits into from
Sep 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
2c86dab
Replaced Anko in NotificationScheduler.kt
kunzef May 25, 2023
b482241
Replaced Anko in NotificationUtils.kt
kunzef May 25, 2023
75c1e96
Added preference key replaced Anko in BaseNavigationActivity.kt
kunzef May 25, 2023
80662f3
Beautify by removing this
kunzef May 25, 2023
e3995d0
Replaced Anko ConnectivityManager in ProgressActivity.kt
kunzef May 25, 2023
81b5d30
Replaced Anko SearchManager in FragmentForSearching.kt
kunzef May 25, 2023
dc780b9
Replaced NotificationManager and SharedPreferences in SettingsFragment
kunzef May 25, 2023
0bab547
Removed unnecessary comment
kunzef May 25, 2023
53a4b5c
Replaced WifiManager in EduroamCard.kt
kunzef May 25, 2023
069036a
Replaced DefaultSharedPreferences and WifiManager in EduroamCard.kt
kunzef May 25, 2023
2526029
Replaced WifiManager in EduroamFixCardViewHolder.kt
kunzef May 25, 2023
c2b42bc
Replaced DefaultSharedPreferences in TopNewsCard.kt
kunzef May 25, 2023
37e8dc4
Replaced InputMethodManager in OnboardingStartFragment.kt
kunzef May 25, 2023
d210dc3
Replaced ConnectivityManager in MainFragment.kt
kunzef May 25, 2023
1cb1159
Replaced textColor in TicketAmountViewHolder.kt
kunzef May 25, 2023
2c86918
Replaced AlarmManager in MVVWidget.kt
kunzef May 25, 2023
035b496
Replaced NotificationManager in FcmReceiverService.kt
kunzef May 25, 2023
8b32b92
Replaced WifiManager in ScanResultsAvailableReceiver.kt
kunzef May 25, 2023
621c2b3
Replaced ConnectivityManager in NetUtils.kt
kunzef May 25, 2023
162e856
Replaced DefaultSharedPreferences in Utils.kt
kunzef May 25, 2023
65151b5
Replaced ConnectivityManager in BaseFragment.kt
kunzef May 25, 2023
919be86
Replaced DefaultSharedPreferences in OnboardingExtrasFragment.kt
kunzef May 25, 2023
1e62f5c
Removed unused import in BaseFragment.kt
kunzef May 25, 2023
2b6aff9
Replaced all android preference manager with android x
kunzef May 25, 2023
6434bc6
Replaced getSharedPreference with PreferenceManager default Preference
kunzef May 25, 2023
f59a449
Merge branch 'TUM-Dev:master' into replace-anko
kunzef May 28, 2023
b31ba30
Removed doAsyncs and replaced JobIntentService with WorkManager
kunzef May 28, 2023
1af8dce
Replaced doAsync with expedited WorkManager work
kunzef May 28, 2023
dbb2706
Replaced runOnUIThread with coroutines on main in BaseFragment.kt
kunzef May 28, 2023
a8f409f
Replaced doAsync with coroutine in LocationManager and calling Activity
kunzef May 28, 2023
5d5930a
Replaced anko.support.v4.defaultSharedPreferences in GradesFragment.kt
kunzef May 28, 2023
cef2302
Replaced doAsync with coroutines in StartupActivity.kt
kunzef May 28, 2023
a47d203
Replaced runOnUIThread with coroutines in MainFragment.kt
kunzef May 28, 2023
5ff77e7
Replaced doAsync in CardRepository
kunzef May 29, 2023
ff0de85
Replaced runOnUiThread with coroutines in StudyRoomsFragment.kt
kunzef May 30, 2023
092dbd1
Replace browse -> intent: CheckTokenFragment, OnboardingExtrasFragment
kunzef May 31, 2023
85e3205
Replaced textChangedListener -> KTX doAfterTextChanged
kunzef May 31, 2023
12f704f
Replaced onItemSelectedListener in NavigationDetailsFragment.kt
kunzef May 31, 2023
46804a5
Removed leftover code
kunzef May 31, 2023
4efa41e
Replaces doAsync by replacing callback with coroutines in StudyRooms
kunzef May 31, 2023
3ae3592
Removes unnecessary import
kunzef May 31, 2023
25a0ce2
Replaced doAsync with expedited WorkManager in CacheManager
kunzef May 31, 2023
da40239
Removed unnecessary import
kunzef May 31, 2023
036f1af
Fixed ktlint
kunzef May 31, 2023
6cdcf17
Fixed ktlint formatting
kunzef May 31, 2023
97033b5
Fixed ktlint formatting
kunzef May 31, 2023
ffc5f19
Updated build.gradle:app
kunzef May 31, 2023
e1cdf71
Merge branch 'master' into replace-anko
CommanderStorm Sep 17, 2023
337a82a
fixed problems in the merge
CommanderStorm Sep 17, 2023
02a274d
formatting fixes
CommanderStorm Sep 17, 2023
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
3 changes: 2 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ dependencies {
implementation "androidx.room:room-runtime:$room_version"
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.5.0'
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.0'
implementation 'android.arch.lifecycle:reactivestreams:1.1.1'
implementation 'android.arch.work:work-runtime-ktx:1.0.1'
implementation 'androidx.appcompat:appcompat:1.4.2'
Expand Down Expand Up @@ -136,11 +137,11 @@ dependencies {

// Kotlin
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
implementation "org.jetbrains.anko:anko:0.10.8"
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.fragment:fragment-ktx:1.4.1'
// Note: fix for internal androidx libraries using outdated WorkManager causing a crash
implementation "androidx.work:work-runtime-ktx:2.7.1"
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.6.1'

// RxJava
implementation 'io.reactivex.rxjava2:rxandroid:2.1.1'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.tum.`in`.tumcampusapp.api.tumonline.interceptors

import android.content.Context
import android.preference.PreferenceManager
import androidx.preference.PreferenceManager
import de.tum.`in`.tumcampusapp.utils.Const
import okhttp3.Interceptor
import okhttp3.Response
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.app.AlarmManager
import android.app.PendingIntent
import android.content.Context
import android.content.Intent
import androidx.core.app.NotificationManagerCompat
import de.tum.`in`.tumcampusapp.component.notifications.model.AppNotification
import de.tum.`in`.tumcampusapp.component.notifications.model.FutureNotification
import de.tum.`in`.tumcampusapp.component.notifications.model.InstantNotification
Expand All @@ -14,8 +15,6 @@ import de.tum.`in`.tumcampusapp.component.notifications.receivers.NotificationAl
import de.tum.`in`.tumcampusapp.component.notifications.receivers.NotificationReceiver
import de.tum.`in`.tumcampusapp.database.TcaDb
import de.tum.`in`.tumcampusapp.utils.Const
import org.jetbrains.anko.alarmManager
import org.jetbrains.anko.notificationManager
import org.joda.time.DateTime
import javax.inject.Inject

Expand All @@ -28,7 +27,7 @@ import javax.inject.Inject
*/
class NotificationScheduler @Inject constructor(private val context: Context) {

private val notificationManager = context.notificationManager
private val notificationManager = NotificationManagerCompat.from(context)

/**
* Schedules a list of [FutureNotification]s for the time specified by each notification.
Expand Down Expand Up @@ -89,7 +88,8 @@ class NotificationScheduler @Inject constructor(private val context: Context) {
fun cancel(globalId: Long, notification: FutureNotification) {
val pendingIntent = getAlarmIntent(notification, globalId)
pendingIntent.cancel()
context.alarmManager.cancel(pendingIntent)
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.cancel(pendingIntent)
}

/**
Expand Down Expand Up @@ -117,7 +117,7 @@ class NotificationScheduler @Inject constructor(private val context: Context) {
*/
fun scheduleAlarm(type: NotificationType, time: DateTime) {
val alarmIntent = getAlarmIntent(type)
val alarmManager = context.alarmManager
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager

// If the same alarm has already been scheduled, we cancel it.
alarmIntent.cancel()
Expand All @@ -134,7 +134,7 @@ class NotificationScheduler @Inject constructor(private val context: Context) {
*/
private fun scheduleAlarm(notification: FutureNotification, globalId: Long) {
val alarmIntent = getAlarmIntent(notification, globalId)
val alarmManager = context.alarmManager
val alarmManager = context.getSystemService(Context.ALARM_SERVICE) as AlarmManager
alarmManager.setExact(AlarmManager.RTC_WAKEUP, notification.time.millis, alarmIntent)
addActiveAlarm(context, globalId)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import android.app.NotificationManager
import android.content.Context
import android.graphics.Color
import android.os.Build
import androidx.core.app.NotificationManagerCompat
import de.tum.`in`.tumcampusapp.R
import de.tum.`in`.tumcampusapp.utils.Const
import org.jetbrains.anko.notificationManager

object NotificationUtils {

Expand Down Expand Up @@ -92,7 +92,7 @@ object NotificationUtils {
lightColor = Color.RED
}

val notificationManager = context.notificationManager
val notificationManager = NotificationManagerCompat.from(context)
val channels = listOf(default, chat, eduroam, cafeteria, mvv, emergency)

channels.forEach { notificationManager.createNotificationChannel(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ package de.tum.`in`.tumcampusapp.component.notifications.receivers
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import androidx.work.OneTimeWorkRequestBuilder
import androidx.work.OutOfQuotaPolicy
import androidx.work.WorkManager
import androidx.work.Worker
import androidx.work.WorkerParameters
import de.tum.`in`.tumcampusapp.component.notifications.NotificationScheduler
import de.tum.`in`.tumcampusapp.component.notifications.persistence.NotificationType
import de.tum.`in`.tumcampusapp.component.tumui.tutionfees.TuitionFeesNotificationProvider
import de.tum.`in`.tumcampusapp.component.ui.cafeteria.CafeteriaNotificationProvider
import de.tum.`in`.tumcampusapp.component.ui.transportation.TransportNotificationProvider
import de.tum.`in`.tumcampusapp.utils.Const
import org.jetbrains.anko.doAsync

class NotificationAlarmReceiver : BroadcastReceiver() {

Expand All @@ -23,11 +27,22 @@ class NotificationAlarmReceiver : BroadcastReceiver() {
else -> return
}

doAsync {
val notification = notificationProvider.buildNotification()
notification?.let {
NotificationScheduler(context).schedule(it)
// create subclass of Worker to enqueue with WorkManager
class WorkWhenReceived(appContext: Context, workerParams: WorkerParameters) :
Worker(appContext, workerParams) {
override fun doWork(): Result {
val notification = notificationProvider.buildNotification()
notification?.let {
NotificationScheduler(applicationContext).schedule(it)
}
return Result.success()
}
}
// start expedited background work
val request = OneTimeWorkRequestBuilder<WorkWhenReceived>()
.setExpedited(OutOfQuotaPolicy.RUN_AS_NON_EXPEDITED_WORK_REQUEST)
.build()
WorkManager.getInstance(context)
.enqueue(request)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_LOCKED_CLOSED
import androidx.drawerlayout.widget.DrawerLayout.LOCK_MODE_UNLOCKED
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.preference.PreferenceManager
import com.google.android.material.navigation.NavigationView
import de.tum.`in`.tumcampusapp.R
import de.tum.`in`.tumcampusapp.component.other.generic.drawer.DrawerHeaderInflater
Expand All @@ -22,7 +23,6 @@ import de.tum.`in`.tumcampusapp.component.ui.overview.CardManager
import de.tum.`in`.tumcampusapp.component.ui.overview.MainFragment
import de.tum.`in`.tumcampusapp.utils.Const
import de.tum.`in`.tumcampusapp.utils.closeDrawers
import org.jetbrains.anko.defaultSharedPreferences

class BaseNavigationActivity :
BaseActivity(
Expand Down Expand Up @@ -60,7 +60,8 @@ class BaseNavigationActivity :

initDrawer()
supportFragmentManager.registerFragmentLifecycleCallbacks(fragmentCallbacks, false)
defaultSharedPreferences.registerOnSharedPreferenceChangeListener(this)

PreferenceManager.getDefaultSharedPreferences(this).registerOnSharedPreferenceChangeListener(this)

if (savedInstanceState == null) {
supportFragmentManager
Expand Down Expand Up @@ -148,7 +149,7 @@ class BaseNavigationActivity :
}

override fun onDestroy() {
defaultSharedPreferences.unregisterOnSharedPreferenceChangeListener(this)
PreferenceManager.getDefaultSharedPreferences(this).unregisterOnSharedPreferenceChangeListener(this)
super.onDestroy()
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package de.tum.`in`.tumcampusapp.component.other.generic.activity

import android.content.Context
import android.graphics.Color
import android.net.ConnectivityManager
import android.net.ConnectivityManager.NetworkCallback
import android.net.Network
import android.net.NetworkRequest
Expand Down Expand Up @@ -29,7 +31,6 @@ import de.tum.`in`.tumcampusapp.utils.NetUtils.internetCapability
import de.tum.`in`.tumcampusapp.utils.Utils
import de.tum.`in`.tumcampusapp.utils.setImageResourceOrHide
import de.tum.`in`.tumcampusapp.utils.setTextOrHide
import org.jetbrains.anko.connectivityManager
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand Down Expand Up @@ -246,7 +247,8 @@ abstract class ProgressActivity<T>(
.build()

if (registered.not()) {
connectivityManager.registerNetworkCallback(request, networkCallback)
(getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
.registerNetworkCallback(request, networkCallback)
registered = true
}
}
Expand Down Expand Up @@ -289,7 +291,8 @@ abstract class ProgressActivity<T>(
*/
protected fun showLoadingStart() {
if (registered) {
connectivityManager.unregisterNetworkCallback(networkCallback)
(getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
.unregisterNetworkCallback(networkCallback)
registered = false
}

Expand Down Expand Up @@ -344,7 +347,8 @@ abstract class ProgressActivity<T>(
super.onDestroy()
apiCall?.cancel()
if (registered) {
connectivityManager.unregisterNetworkCallback(networkCallback)
(getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
.unregisterNetworkCallback(networkCallback)
registered = false
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package de.tum.`in`.tumcampusapp.component.other.generic.fragment

import android.content.Context
import android.graphics.Color
import android.net.ConnectivityManager
import android.net.Network
Expand All @@ -14,6 +15,7 @@ import androidx.annotation.LayoutRes
import androidx.annotation.StringRes
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.lifecycle.lifecycleScope
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout
import com.google.android.material.snackbar.Snackbar
import de.tum.`in`.tumcampusapp.R
Expand All @@ -33,8 +35,9 @@ import de.tum.`in`.tumcampusapp.utils.NetUtils
import de.tum.`in`.tumcampusapp.utils.Utils
import de.tum.`in`.tumcampusapp.utils.setImageResourceOrHide
import de.tum.`in`.tumcampusapp.utils.setTextOrHide
import org.jetbrains.anko.connectivityManager
import org.jetbrains.anko.support.v4.runOnUiThread
import kotlinx.coroutines.CoroutineDispatcher
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import retrofit2.Call
import retrofit2.Callback
import retrofit2.Response
Expand All @@ -45,6 +48,8 @@ abstract class BaseFragment<T>(
@StringRes private val titleResId: Int
) : Fragment(), SwipeRefreshLayout.OnRefreshListener {

private val mainDispatcher: CoroutineDispatcher = Dispatchers.Main

private var apiCall: Call<T>? = null
private var hadSuccessfulRequest = false

Expand All @@ -63,7 +68,7 @@ abstract class BaseFragment<T>(

private val networkCallback: ConnectivityManager.NetworkCallback = object : ConnectivityManager.NetworkCallback() {
override fun onAvailable(network: Network) {
runOnUiThread {
[email protected](mainDispatcher) {
[email protected]()
}
}
Expand Down Expand Up @@ -187,7 +192,7 @@ abstract class BaseFragment<T>(
* @param messageResId Resource id of the error text
*/
protected fun showError(messageResId: Int) {
runOnUiThread {
[email protected](mainDispatcher) {
showError(UnknownErrorViewState(messageResId))
}
}
Expand All @@ -207,7 +212,7 @@ abstract class BaseFragment<T>(
}

protected fun showErrorSnackbar(messageResId: Int) {
runOnUiThread {
[email protected](mainDispatcher) {
Snackbar.make(contentView, messageResId, Snackbar.LENGTH_LONG)
.setAction(R.string.retry) { retryRequest() }
.setActionTextColor(Color.WHITE)
Expand All @@ -228,13 +233,13 @@ abstract class BaseFragment<T>(
}

private fun showFailedTokenLayout(messageResId: Int = R.string.error_accessing_tumonline_body) {
runOnUiThread {
[email protected](mainDispatcher) {
showError(FailedTokenViewState(messageResId))
}
}

protected fun showNoInternetLayout() {
runOnUiThread {
[email protected](mainDispatcher) {
showError(NoInternetViewState())
}

Expand All @@ -243,25 +248,26 @@ abstract class BaseFragment<T>(
.build()

if (registered.not()) {
baseActivity.connectivityManager.registerNetworkCallback(request, networkCallback)
(baseActivity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
.registerNetworkCallback(request, networkCallback)
registered = true
}
}

protected fun showEmptyResponseLayout(messageResId: Int, iconResId: Int? = null) {
runOnUiThread {
[email protected](mainDispatcher) {
showError(EmptyViewState(iconResId, messageResId))
}
}

protected fun showContentLayout() {
runOnUiThread {
[email protected](mainDispatcher) {
layoutAllErrorsBinding.layoutError.errorLayout.visibility = View.GONE
}
}

protected fun showErrorLayout() {
runOnUiThread {
[email protected](mainDispatcher) {
layoutAllErrorsBinding.layoutError.errorLayout.visibility = View.VISIBLE
}
}
Expand Down Expand Up @@ -313,7 +319,8 @@ abstract class BaseFragment<T>(
*/
protected fun showLoadingStart() {
if (registered) {
baseActivity.connectivityManager.unregisterNetworkCallback(networkCallback)
(baseActivity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
.unregisterNetworkCallback(networkCallback)
registered = false
}

Expand Down Expand Up @@ -372,7 +379,8 @@ abstract class BaseFragment<T>(

override fun onDestroy() {
if (registered) {
baseActivity.connectivityManager.unregisterNetworkCallback(networkCallback)
(baseActivity.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager)
.unregisterNetworkCallback(networkCallback)
registered = false
}
super.onDestroy()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package de.tum.`in`.tumcampusapp.component.other.generic.fragment

import android.app.SearchManager
import android.content.Context
import android.content.SearchRecentSuggestionsProvider.DATABASE_MODE_QUERIES
import android.database.Cursor
import android.os.Bundle
Expand All @@ -16,7 +17,6 @@ import androidx.appcompat.widget.SearchView
import de.tum.`in`.tumcampusapp.R
import de.tum.`in`.tumcampusapp.component.other.generic.activity.BaseNavigationActivity
import de.tum.`in`.tumcampusapp.utils.Utils
import org.jetbrains.anko.searchManager

abstract class FragmentForSearching<T>(
@LayoutRes layoutId: Int,
Expand Down Expand Up @@ -61,7 +61,7 @@ abstract class FragmentForSearching<T>(
searchItem = checkNotNull(menu.findItem(R.id.action_search))
searchView = searchItem.actionView as SearchView

val searchManager = requireContext().searchManager
val searchManager = requireContext().getSystemService(Context.SEARCH_SERVICE) as SearchManager
val info = searchManager.getSearchableInfo(requireActivity().componentName)
searchView.setSearchableInfo(info)

Expand Down
Loading