diff --git a/app/build.gradle b/app/build.gradle index 493a5473..c3070d7f 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -28,7 +28,8 @@ android { ] javaCompileOptions { annotationProcessorOptions { - arguments = ["room.schemaLocation": "$projectDir/schemas".toString()] + arguments = ["room.schemaLocation": "$projectDir/schemas".toString(), + "room.incremental" : "true"] } } } @@ -86,6 +87,10 @@ android { targetCompatibility JavaVersion.VERSION_1_8 } + kotlinOptions { + jvmTarget = "1.8" + } + packagingOptions { exclude 'META-INF/library_release.kotlin_module' exclude 'META-INF/library-core_release.kotlin_module' @@ -105,7 +110,7 @@ play { ext { work_manager = "2.2.0" - room = "2.1.0" + room = "2.2.0-beta01" dagger = "2.24" chucker = "2.0.4" mockk = "1.9.2" @@ -114,35 +119,38 @@ ext { configurations.all { resolutionStrategy.force "androidx.constraintlayout:constraintlayout:1.1.3" - resolutionStrategy.force "com.google.android.material:material:1.1.0-alpha07" } dependencies { - implementation "io.github.wulkanowy:api:0.9.4" + implementation "io.github.wulkanowy:api:4b50c79" implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version" - implementation "androidx.core:core:1.0.2" - implementation "androidx.appcompat:appcompat:1.0.2" - implementation "androidx.fragment:fragment:1.0.0" + implementation "androidx.core:core-ktx:1.1.0-rc03" + implementation "androidx.activity:activity-ktx:1.0.0-rc01" + implementation "androidx.appcompat:appcompat:1.1.0-rc01" + implementation "androidx.appcompat:appcompat-resources:1.1.0-rc01" + implementation "androidx.fragment:fragment-ktx:1.1.0-rc04" implementation "androidx.annotation:annotation:1.1.0" implementation "androidx.multidex:multidex:2.0.1" - implementation "androidx.preference:preference:1.1.0-rc01" - implementation "androidx.recyclerview:recyclerview:1.0.0" + implementation "androidx.preference:preference-ktx:1.1.0-rc01" + implementation "androidx.recyclerview:recyclerview:1.1.0-beta03" implementation "androidx.viewpager:viewpager:1.0.0" implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.0.0" implementation "androidx.constraintlayout:constraintlayout:1.1.3" - implementation "androidx.coordinatorlayout:coordinatorlayout:1.0.0" + implementation "androidx.coordinatorlayout:coordinatorlayout:1.1.0-beta01" implementation "com.google.android.material:material:1.1.0-alpha07" implementation "com.github.wulkanowy:material-chips-input:2.0.1" implementation "com.github.PhilJay:MPAndroidChart:v3.1.0" implementation "me.zhanghai.android.materialprogressbar:library:1.6.1" - implementation "androidx.work:work-runtime:$work_manager" + implementation "androidx.work:work-runtime-ktx:$work_manager" implementation "androidx.work:work-rxjava2:$work_manager" + implementation "androidx.work:work-gcm:$work_manager" implementation "androidx.room:room-runtime:$room" implementation "androidx.room:room-rxjava2:$room" + implementation "androidx.room:room-ktx:$room" kapt "androidx.room:room-compiler:$room" implementation "com.google.dagger:dagger-android-support:$dagger" diff --git a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/student/StudentLocalTest.kt b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/student/StudentLocalTest.kt index cecd8099..ee4c652f 100644 --- a/app/src/androidTest/java/io/github/wulkanowy/data/repositories/student/StudentLocalTest.kt +++ b/app/src/androidTest/java/io/github/wulkanowy/data/repositories/student/StudentLocalTest.kt @@ -5,7 +5,7 @@ import androidx.room.Room import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.runners.AndroidJUnit4 import io.github.wulkanowy.data.db.AppDatabase -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.Student import org.junit.After import org.junit.Before @@ -21,14 +21,14 @@ class StudentLocalTest { private lateinit var testDb: AppDatabase - private lateinit var sharedHelper: SharedPrefHelper + private lateinit var sharedProvider: SharedPrefProvider @Before fun createDb() { val context = ApplicationProvider.getApplicationContext() testDb = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java) .build() - sharedHelper = SharedPrefHelper(context.getSharedPreferences("TEST", Context.MODE_PRIVATE)) + sharedProvider = SharedPrefProvider(context.getSharedPreferences("TEST", Context.MODE_PRIVATE)) studentLocal = StudentLocal(testDb.studentDao, context) } diff --git a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt index e3047c7f..72969059 100644 --- a/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt +++ b/app/src/main/java/io/github/wulkanowy/WulkanowyApp.kt @@ -5,7 +5,6 @@ import android.util.Log.INFO import android.util.Log.VERBOSE import androidx.multidex.MultiDex import androidx.work.Configuration -import androidx.work.WorkManager import com.jakewharton.threetenabp.AndroidThreeTen import dagger.android.AndroidInjector import dagger.android.support.DaggerApplication @@ -25,7 +24,7 @@ import timber.log.Timber import java.io.IOException import javax.inject.Inject -class WulkanowyApp : DaggerApplication() { +class WulkanowyApp : DaggerApplication(), Configuration.Provider { @Inject lateinit var workerFactory: SyncWorkerFactory @@ -47,19 +46,10 @@ class WulkanowyApp : DaggerApplication() { RxJavaPlugins.setErrorHandler(::onError) themeManager.applyDefaultTheme() - initWorkManager() initLogging() initCrashlytics(this, appInfo) } - private fun initWorkManager() { - WorkManager.initialize(this, - Configuration.Builder() - .setWorkerFactory(workerFactory) - .setMinimumLoggingLevel(if (appInfo.isDebug) VERBOSE else INFO) - .build()) - } - private fun initLogging() { if (appInfo.isDebug) { Timber.plant(DebugLogTree()) @@ -81,4 +71,9 @@ class WulkanowyApp : DaggerApplication() { override fun applicationInjector(): AndroidInjector { return DaggerAppComponent.factory().create(this) } + + override fun getWorkManagerConfiguration() = Configuration.Builder() + .setWorkerFactory(workerFactory) + .setMinimumLoggingLevel(if (appInfo.isDebug) VERBOSE else INFO) + .build() } diff --git a/app/src/main/java/io/github/wulkanowy/data/db/SharedPrefHelper.kt b/app/src/main/java/io/github/wulkanowy/data/db/SharedPrefProvider.kt similarity index 59% rename from app/src/main/java/io/github/wulkanowy/data/db/SharedPrefHelper.kt rename to app/src/main/java/io/github/wulkanowy/data/db/SharedPrefProvider.kt index 74f9fa65..a6d0a067 100644 --- a/app/src/main/java/io/github/wulkanowy/data/db/SharedPrefHelper.kt +++ b/app/src/main/java/io/github/wulkanowy/data/db/SharedPrefProvider.kt @@ -1,18 +1,15 @@ package io.github.wulkanowy.data.db -import android.annotation.SuppressLint import android.content.SharedPreferences +import androidx.core.content.edit import javax.inject.Inject import javax.inject.Singleton @Singleton -@SuppressLint("ApplySharedPref") -class SharedPrefHelper @Inject constructor(private val sharedPref: SharedPreferences) { +class SharedPrefProvider @Inject constructor(private val sharedPref: SharedPreferences) { fun putLong(key: String, value: Long, sync: Boolean = false) { - sharedPref.edit().putLong(key, value).apply { - if (sync) commit() else apply() - } + sharedPref.edit(sync) { putLong(key, value) } } fun getLong(key: String, defaultValue: Long) = sharedPref.getLong(key, defaultValue) diff --git a/app/src/main/java/io/github/wulkanowy/di/AppComponent.kt b/app/src/main/java/io/github/wulkanowy/di/AppComponent.kt index 3ac3a525..c0329f7d 100644 --- a/app/src/main/java/io/github/wulkanowy/di/AppComponent.kt +++ b/app/src/main/java/io/github/wulkanowy/di/AppComponent.kt @@ -14,7 +14,7 @@ import javax.inject.Singleton AppModule::class, RepositoryModule::class, ServicesModule::class, - BuilderModule::class]) + BindingModule::class]) interface AppComponent : AndroidInjector { @Component.Factory diff --git a/app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt b/app/src/main/java/io/github/wulkanowy/di/BindingModule.kt similarity index 97% rename from app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt rename to app/src/main/java/io/github/wulkanowy/di/BindingModule.kt index 8926cdf4..98061e60 100644 --- a/app/src/main/java/io/github/wulkanowy/di/BuilderModule.kt +++ b/app/src/main/java/io/github/wulkanowy/di/BindingModule.kt @@ -16,7 +16,7 @@ import io.github.wulkanowy.ui.modules.timetablewidget.TimetableWidgetProvider @Suppress("unused") @Module -internal abstract class BuilderModule { +internal abstract class BindingModule { @PerActivity @ContributesAndroidInjector diff --git a/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt b/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt index 05f67454..3816856b 100644 --- a/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt +++ b/app/src/main/java/io/github/wulkanowy/services/ServicesModule.kt @@ -1,8 +1,6 @@ package io.github.wulkanowy.services -import android.app.NotificationManager import android.content.Context -import android.content.Context.NOTIFICATION_SERVICE import androidx.core.app.NotificationManagerCompat import androidx.work.WorkManager import com.squareup.inject.assisted.dagger2.AssistedModule @@ -38,17 +36,12 @@ abstract class ServicesModule { @JvmStatic @Provides - fun provideWorkManager() = WorkManager.getInstance() + fun provideWorkManager(context: Context) = WorkManager.getInstance(context) @JvmStatic @Singleton @Provides - fun provideNotificationManagerCompat(context: Context) = NotificationManagerCompat.from(context) - - @JvmStatic - @Singleton - @Provides - fun provideNotificationManager(context: Context) = context.getSystemService(NOTIFICATION_SERVICE) as NotificationManager + fun provideNotificationManager(context: Context) = NotificationManagerCompat.from(context) } @ContributesAndroidInjector diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/SyncManager.kt b/app/src/main/java/io/github/wulkanowy/services/sync/SyncManager.kt index d85c75c3..98fc3522 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/SyncManager.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/SyncManager.kt @@ -8,9 +8,9 @@ import androidx.work.ExistingPeriodicWorkPolicy.KEEP import androidx.work.ExistingPeriodicWorkPolicy.REPLACE import androidx.work.NetworkType.CONNECTED import androidx.work.NetworkType.UNMETERED -import androidx.work.PeriodicWorkRequest +import androidx.work.PeriodicWorkRequestBuilder import androidx.work.WorkManager -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.repositories.preferences.PreferencesRepository import io.github.wulkanowy.services.sync.channels.DebugChannel import io.github.wulkanowy.services.sync.channels.NewEntriesChannel @@ -26,14 +26,13 @@ import javax.inject.Singleton class SyncManager @Inject constructor( private val workManager: WorkManager, private val preferencesRepository: PreferencesRepository, - sharedPrefHelper: SharedPrefHelper, + sharedPrefProvider: SharedPrefProvider, newEntriesChannel: NewEntriesChannel, debugChannel: DebugChannel, appInfo: AppInfo ) { companion object { - private const val APP_VERSION_CODE_KEY = "app_version_code" } @@ -45,18 +44,18 @@ class SyncManager @Inject constructor( if (appInfo.isDebug) debugChannel.create() } - if (sharedPrefHelper.getLong(APP_VERSION_CODE_KEY, -1L) != appInfo.versionCode.toLong()) { + if (sharedPrefProvider.getLong(APP_VERSION_CODE_KEY, -1L) != appInfo.versionCode.toLong()) { startSyncWorker(true) - sharedPrefHelper.putLong(APP_VERSION_CODE_KEY, appInfo.versionCode.toLong(), true) + sharedPrefProvider.putLong(APP_VERSION_CODE_KEY, appInfo.versionCode.toLong(), true) } - Timber.i("SyncManager was initialized") } fun startSyncWorker(restart: Boolean = false) { if (preferencesRepository.isServiceEnabled && !now().isHolidays) { workManager.enqueueUniquePeriodicWork(SyncWorker::class.java.simpleName, if (restart) REPLACE else KEEP, - PeriodicWorkRequest.Builder(SyncWorker::class.java, preferencesRepository.servicesInterval, MINUTES, 10, MINUTES) + PeriodicWorkRequestBuilder(preferencesRepository.servicesInterval, MINUTES) + .setInitialDelay(10, MINUTES) .setBackoffCriteria(EXPONENTIAL, 30, MINUTES) .setConstraints(Constraints.Builder() .setRequiredNetworkType(if (preferencesRepository.isServicesOnlyWifi) UNMETERED else CONNECTED) diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/channels/DebugChannel.kt b/app/src/main/java/io/github/wulkanowy/services/sync/channels/DebugChannel.kt index 02fff569..166d3efc 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/channels/DebugChannel.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/channels/DebugChannel.kt @@ -3,15 +3,15 @@ package io.github.wulkanowy.services.sync.channels import android.annotation.TargetApi import android.app.Notification.VISIBILITY_PUBLIC import android.app.NotificationChannel -import android.app.NotificationManager import android.app.NotificationManager.IMPORTANCE_DEFAULT import android.content.Context +import androidx.core.app.NotificationManagerCompat import io.github.wulkanowy.R import javax.inject.Inject @TargetApi(26) class DebugChannel @Inject constructor( - private val notificationManager: NotificationManager, + private val notificationManager: NotificationManagerCompat, private val context: Context ) { @@ -21,8 +21,9 @@ class DebugChannel @Inject constructor( fun create() { notificationManager.createNotificationChannel( - NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_debug), IMPORTANCE_DEFAULT).apply { - lockscreenVisibility = VISIBILITY_PUBLIC - }) + NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_debug), IMPORTANCE_DEFAULT) + .apply { + lockscreenVisibility = VISIBILITY_PUBLIC + }) } } diff --git a/app/src/main/java/io/github/wulkanowy/services/sync/channels/NewEntriesChannel.kt b/app/src/main/java/io/github/wulkanowy/services/sync/channels/NewEntriesChannel.kt index 8e24a2a6..71624510 100644 --- a/app/src/main/java/io/github/wulkanowy/services/sync/channels/NewEntriesChannel.kt +++ b/app/src/main/java/io/github/wulkanowy/services/sync/channels/NewEntriesChannel.kt @@ -3,15 +3,15 @@ package io.github.wulkanowy.services.sync.channels import android.annotation.TargetApi import android.app.Notification.VISIBILITY_PUBLIC import android.app.NotificationChannel -import android.app.NotificationManager import android.app.NotificationManager.IMPORTANCE_HIGH import android.content.Context +import androidx.core.app.NotificationManagerCompat import io.github.wulkanowy.R import javax.inject.Inject @TargetApi(26) class NewEntriesChannel @Inject constructor( - private val notificationManager: NotificationManager, + private val notificationManager: NotificationManagerCompat, private val context: Context ) { @@ -21,10 +21,11 @@ class NewEntriesChannel @Inject constructor( fun create() { notificationManager.createNotificationChannel( - NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_new_entries), IMPORTANCE_HIGH).apply { - enableLights(true) - enableVibration(true) - lockscreenVisibility = VISIBILITY_PUBLIC - }) + NotificationChannel(CHANNEL_ID, context.getString(R.string.channel_new_entries), IMPORTANCE_HIGH) + .apply { + enableLights(true) + enableVibration(true) + lockscreenVisibility = VISIBILITY_PUBLIC + }) } } diff --git a/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt b/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt index f3429457..7c7e6710 100644 --- a/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt +++ b/app/src/main/java/io/github/wulkanowy/services/widgets/TimetableWidgetService.kt @@ -3,7 +3,7 @@ package io.github.wulkanowy.services.widgets import android.content.Intent import android.widget.RemoteViewsService import dagger.android.AndroidInjection -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.data.repositories.timetable.TimetableRepository @@ -23,7 +23,7 @@ class TimetableWidgetService : RemoteViewsService() { lateinit var semesterRepo: SemesterRepository @Inject - lateinit var sharedPref: SharedPrefHelper + lateinit var sharedPref: SharedPrefProvider @Inject lateinit var schedulers: SchedulersProvider diff --git a/app/src/main/java/io/github/wulkanowy/ui/base/BaseFragmentPagerAdapter.kt b/app/src/main/java/io/github/wulkanowy/ui/base/BaseFragmentPagerAdapter.kt index fcf7e980..5f8bf417 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/base/BaseFragmentPagerAdapter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/base/BaseFragmentPagerAdapter.kt @@ -4,14 +4,15 @@ import androidx.fragment.app.Fragment import androidx.fragment.app.FragmentManager import androidx.fragment.app.FragmentPagerAdapter -class BaseFragmentPagerAdapter(private val fragmentManager: FragmentManager) : FragmentPagerAdapter(fragmentManager) { +class BaseFragmentPagerAdapter(private val fragmentManager: FragmentManager) : + FragmentPagerAdapter(fragmentManager, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) { private val pages = mutableMapOf() var containerId = 0 fun getFragmentInstance(position: Int): Fragment? { - if (containerId == 0) throw IllegalArgumentException("Container id is 0") + require(containerId != 0) { "Container id is 0" } return fragmentManager.findFragmentByTag("android:switcher:$containerId:$position") } diff --git a/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt b/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt index db3918b9..b74af6c5 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/base/ErrorDialog.kt @@ -2,13 +2,13 @@ package io.github.wulkanowy.ui.base import android.content.ClipData import android.content.ClipboardManager -import android.content.Context.CLIPBOARD_SERVICE import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import android.widget.Toast import android.widget.Toast.LENGTH_LONG +import androidx.core.content.getSystemService import androidx.fragment.app.DialogFragment import io.github.wulkanowy.R import kotlinx.android.synthetic.main.dialog_error.* @@ -49,7 +49,7 @@ class ErrorDialog : DialogFragment() { errorDialogContent.text = writer.toString() errorDialogCopy.setOnClickListener { ClipData.newPlainText("wulkanowyError", writer.toString()).let { clip -> - (activity?.getSystemService(CLIPBOARD_SERVICE) as? ClipboardManager)?.primaryClip = clip + activity?.getSystemService()?.primaryClip = clip } Toast.makeText(context, R.string.all_copied, LENGTH_LONG).show() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/about/license/LicenseFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/about/license/LicenseFragment.kt index 19d1323a..2681680b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/about/license/LicenseFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/about/license/LicenseFragment.kt @@ -7,8 +7,7 @@ import android.view.View.GONE import android.view.View.VISIBLE import android.view.ViewGroup import androidx.appcompat.app.AlertDialog -import androidx.core.text.HtmlCompat -import androidx.core.text.HtmlCompat.FROM_HTML_MODE_LEGACY +import androidx.core.text.parseAsHtml import com.mikepenz.aboutlibraries.Libs import com.mikepenz.aboutlibraries.entity.Library import dagger.Lazy @@ -69,7 +68,7 @@ class LicenseFragment : BaseFragment(), LicenseView, MainView.TitledView { context?.let { AlertDialog.Builder(it).apply { setTitle(R.string.license_dialog_title) - setMessage(HtmlCompat.fromHtml(licenseHtml, FROM_HTML_MODE_LEGACY)) + setMessage(licenseHtml.parseAsHtml()) setPositiveButton(android.R.string.ok) { _, _ -> } show() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt index 54d369dc..ce6db1ca 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/form/LoginFormFragment.kt @@ -10,6 +10,7 @@ import android.view.ViewGroup import android.view.inputmethod.EditorInfo.IME_ACTION_DONE import android.view.inputmethod.EditorInfo.IME_NULL import android.widget.ArrayAdapter +import androidx.core.widget.doOnTextChanged import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.ui.base.BaseFragment @@ -17,7 +18,6 @@ import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.utils.AppInfo import io.github.wulkanowy.utils.hideSoftInput import io.github.wulkanowy.utils.openInternetBrowser -import io.github.wulkanowy.utils.setOnTextChangedListener import io.github.wulkanowy.utils.showSoftInput import kotlinx.android.synthetic.main.fragment_login_form.* import javax.inject.Inject @@ -60,8 +60,8 @@ class LoginFormFragment : BaseFragment(), LoginFormView { hostKeys = resources.getStringArray(R.array.endpoints_keys) hostValues = resources.getStringArray(R.array.endpoints_values) - loginFormName.setOnTextChangedListener { presenter.onNameTextChanged() } - loginFormPass.setOnTextChangedListener { presenter.onPassTextChanged() } + loginFormName.doOnTextChanged { _, _, _, _ -> presenter.onNameTextChanged() } + loginFormPass.doOnTextChanged { _, _, _, _ -> presenter.onPassTextChanged() } loginFormHost.setOnItemClickListener { _, _, _, _ -> presenter.onHostSelected() } loginFormSignIn.setOnClickListener { presenter.onSignInClick() } loginFormPrivacyLink.setOnClickListener { presenter.onPrivacyLinkClick() } diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt index 87de0a81..f4f0eb9e 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/login/symbol/LoginSymbolFragment.kt @@ -9,12 +9,12 @@ import android.view.ViewGroup import android.view.inputmethod.EditorInfo.IME_ACTION_DONE import android.view.inputmethod.EditorInfo.IME_NULL import android.widget.ArrayAdapter +import androidx.core.widget.doOnTextChanged import io.github.wulkanowy.R import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.ui.base.BaseFragment import io.github.wulkanowy.ui.modules.login.LoginActivity import io.github.wulkanowy.utils.hideSoftInput -import io.github.wulkanowy.utils.setOnTextChangedListener import io.github.wulkanowy.utils.showSoftInput import kotlinx.android.synthetic.main.fragment_login_symbol.* import javax.inject.Inject @@ -45,7 +45,7 @@ class LoginSymbolFragment : BaseFragment(), LoginSymbolView { override fun initView() { loginSymbolSignIn.setOnClickListener { presenter.attemptLogin(loginSymbolName.text.toString()) } - loginSymbolName.setOnTextChangedListener { presenter.onSymbolTextChanged() } + loginSymbolName.doOnTextChanged { _, _, _, _ -> presenter.onSymbolTextChanged() } loginSymbolName.apply { setOnEditorActionListener { _, id, _ -> diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigurePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigurePresenter.kt index 2ed0fa6f..6f4394ed 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigurePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetConfigurePresenter.kt @@ -1,7 +1,7 @@ package io.github.wulkanowy.ui.modules.luckynumberwidget import eu.davidea.flexibleadapter.items.AbstractFlexibleItem -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.ui.base.BasePresenter @@ -14,7 +14,7 @@ class LuckyNumberWidgetConfigurePresenter @Inject constructor( schedulers: SchedulersProvider, errorHandler: ErrorHandler, studentRepository: StudentRepository, - private val sharedPref: SharedPrefHelper + private val sharedPref: SharedPrefProvider ) : BasePresenter(errorHandler, studentRepository, schedulers) { private var appWidgetId: Int? = null diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt index 44d47d05..76bebe92 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/luckynumberwidget/LuckyNumberWidgetProvider.kt @@ -21,7 +21,7 @@ import android.view.View.VISIBLE import android.widget.RemoteViews import dagger.android.AndroidInjection import io.github.wulkanowy.R -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.LuckyNumber import io.github.wulkanowy.data.repositories.luckynumber.LuckyNumberRepository import io.github.wulkanowy.data.repositories.semester.SemesterRepository @@ -51,7 +51,7 @@ class LuckyNumberWidgetProvider : BroadcastReceiver() { lateinit var appWidgetManager: AppWidgetManager @Inject - lateinit var sharedPref: SharedPrefHelper + lateinit var sharedPref: SharedPrefProvider companion object { fun getStudentWidgetKey(appWidgetId: Int) = "lucky_number_widget_student_$appWidgetId" diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigurePresenter.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigurePresenter.kt index 60fd03aa..9c0202db 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigurePresenter.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetConfigurePresenter.kt @@ -1,7 +1,7 @@ package io.github.wulkanowy.ui.modules.timetablewidget import eu.davidea.flexibleadapter.items.AbstractFlexibleItem -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.ui.base.BasePresenter @@ -14,7 +14,7 @@ class TimetableWidgetConfigurePresenter @Inject constructor( schedulers: SchedulersProvider, errorHandler: ErrorHandler, studentRepository: StudentRepository, - private val sharedPref: SharedPrefHelper + private val sharedPref: SharedPrefProvider ) : BasePresenter(errorHandler, studentRepository, schedulers) { private var appWidgetId: Int? = null diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt index b288f7b7..4b47a08b 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetFactory.kt @@ -11,7 +11,7 @@ import android.widget.AdapterView.INVALID_POSITION import android.widget.RemoteViews import android.widget.RemoteViewsService import io.github.wulkanowy.R -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.Timetable import io.github.wulkanowy.data.repositories.semester.SemesterRepository import io.github.wulkanowy.data.repositories.student.StudentRepository @@ -28,7 +28,7 @@ class TimetableWidgetFactory( private val timetableRepository: TimetableRepository, private val studentRepository: StudentRepository, private val semesterRepository: SemesterRepository, - private val sharedPref: SharedPrefHelper, + private val sharedPref: SharedPrefProvider, private val schedulers: SchedulersProvider, private val context: Context, private val intent: Intent? diff --git a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt index add05895..2fe59ea8 100644 --- a/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt +++ b/app/src/main/java/io/github/wulkanowy/ui/modules/timetablewidget/TimetableWidgetProvider.kt @@ -15,7 +15,7 @@ import android.content.Intent.FLAG_ACTIVITY_NEW_TASK import android.widget.RemoteViews import dagger.android.AndroidInjection import io.github.wulkanowy.R -import io.github.wulkanowy.data.db.SharedPrefHelper +import io.github.wulkanowy.data.db.SharedPrefProvider import io.github.wulkanowy.data.db.entities.Student import io.github.wulkanowy.data.repositories.student.StudentRepository import io.github.wulkanowy.services.widgets.TimetableWidgetService @@ -43,7 +43,7 @@ class TimetableWidgetProvider : BroadcastReceiver() { lateinit var studentRepository: StudentRepository @Inject - lateinit var sharedPref: SharedPrefHelper + lateinit var sharedPref: SharedPrefProvider @Inject lateinit var schedulers: SchedulersProvider diff --git a/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt index 93781a9f..e9cac72e 100644 --- a/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt +++ b/app/src/main/java/io/github/wulkanowy/utils/ActivityExtension.kt @@ -1,17 +1,15 @@ package io.github.wulkanowy.utils import android.app.Activity -import android.content.Context.INPUT_METHOD_SERVICE import android.view.inputmethod.InputMethodManager +import androidx.core.content.getSystemService fun Activity.showSoftInput() { - (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager?)?.run { - if (currentFocus != null) showSoftInput(currentFocus, 0) + getSystemService()?.let { manager -> + currentFocus?.let { manager.showSoftInput(it, 0) } } } fun Activity.hideSoftInput() { - (getSystemService(INPUT_METHOD_SERVICE) as InputMethodManager?)?.run { - hideSoftInputFromWindow(window.decorView.applicationWindowToken, 0) - } + getSystemService()?.hideSoftInputFromWindow(window.decorView.applicationWindowToken, 0) } diff --git a/app/src/main/java/io/github/wulkanowy/utils/EditTextExtension.kt b/app/src/main/java/io/github/wulkanowy/utils/EditTextExtension.kt deleted file mode 100644 index caa977ec..00000000 --- a/app/src/main/java/io/github/wulkanowy/utils/EditTextExtension.kt +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.wulkanowy.utils - -import android.text.Editable -import android.text.TextWatcher -import android.widget.EditText - -inline fun EditText.setOnTextChangedListener(crossinline listener: () -> Unit) { - addTextChangedListener(object : TextWatcher { - override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) { - listener() - } - - override fun afterTextChanged(s: Editable?) {} - override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} - }) -} diff --git a/gradle.properties b/gradle.properties index 24e69b6a..44e7e13b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -13,6 +13,7 @@ android.enableJetifier=true android.useAndroidX=true android.enableR8=true org.gradle.jvmargs=-Xmx1536m +kapt.incremental.apt=true # When configured, Gradle will run in incubating parallel mode. # This option should only be used with decoupled projects. More details, visit