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

Commit

Permalink
Fix code warnings and deprecations
Browse files Browse the repository at this point in the history
  • Loading branch information
msasikanth committed Feb 10, 2024
1 parent b5dad24 commit fe89a47
Show file tree
Hide file tree
Showing 25 changed files with 93 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.sasikanth.pinnit

import android.content.Intent
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.navigation.NavDeepLinkBuilder
Expand Down
16 changes: 0 additions & 16 deletions app/src/main/java/dev/sasikanth/pinnit/about/AboutBottomSheet.kt
Original file line number Diff line number Diff line change
Expand Up @@ -68,22 +68,6 @@ class AboutBottomSheet : BottomSheetDialogFragment() {
binding.appVersionTextView.text = getString(R.string.app_version, versionName)
}

private fun sendSupportEmail() {
val emailAddresses = arrayOf(getString(R.string.dev_email_address))
val emailSubject = getString(R.string.support_subject, BuildConfig.VERSION_NAME)
val deviceInfo = getString(R.string.support_content, Build.MANUFACTURER, Build.MODEL, Build.VERSION.SDK_INT.toString())
val intent = Intent(Intent.ACTION_SENDTO).apply {
data = Uri.parse("mailto:")
putExtra(Intent.EXTRA_EMAIL, emailAddresses)
putExtra(Intent.EXTRA_SUBJECT, emailSubject)
putExtra(Intent.EXTRA_TEXT, deviceInfo)
}

startActivity(
Intent.createChooser(intent, getString(R.string.send_email))
)
}

private fun openGitHubProject() {
val intent = Intent(Intent.ACTION_VIEW, Uri.parse(PINNIT_PROJECT_URL))
startActivity(intent)
Expand Down
13 changes: 9 additions & 4 deletions app/src/main/java/dev/sasikanth/pinnit/activity/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import android.os.Build
import android.os.Bundle
import androidx.appcompat.app.AppCompatActivity
import androidx.datastore.core.DataStore
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.navigation.NavController
import androidx.navigation.fragment.NavHostFragment
import dagger.hilt.android.AndroidEntryPoint
Expand All @@ -16,6 +18,7 @@ import dev.sasikanth.pinnit.oemwarning.OemWarningDialog
import dev.sasikanth.pinnit.oemwarning.shouldShowWarningForOEM
import dev.sasikanth.pinnit.utils.DispatcherProvider
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import java.util.Locale
import javax.inject.Inject
Expand Down Expand Up @@ -44,11 +47,13 @@ class MainActivity : AppCompatActivity() {
val navHostFragment = supportFragmentManager.findFragmentById(R.id.nav_host_fragment_container) as NavHostFragment
navController = navHostFragment.navController

lifecycleScope.launchWhenResumed {
val isOemWarningDialogShown = withContext(dispatcherProvider.io) {
appPreferencesStore.data.first().oemWarningDialog
lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
val isOemWarningDialogShown = withContext(dispatcherProvider.io) {
appPreferencesStore.data.first().oemWarningDialog
}
showOemWarningDialog(isOemWarningDialogShown)
}
showOemWarningDialog(isOemWarningDialogShown)
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package dev.sasikanth.pinnit.background.services

import android.annotation.SuppressLint
import android.app.PendingIntent
import android.content.Intent
import android.os.Build
import android.service.quicksettings.TileService
Expand All @@ -9,10 +11,18 @@ import dev.sasikanth.pinnit.qspopup.QsPopupActivity
@RequiresApi(Build.VERSION_CODES.N)
class QsPopupService : TileService() {

@Suppress("DEPRECATION")
@SuppressLint("StartActivityAndCollapseDeprecated")
override fun onClick() {
val intent = Intent(this, QsPopupActivity::class.java).apply {
addFlags(Intent.FLAG_ACTIVITY_NEW_TASK)
}
startActivityAndCollapse(intent)
val pi = PendingIntent.getActivity(this, 0, intent, PendingIntent.FLAG_IMMUTABLE)

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.UPSIDE_DOWN_CAKE) {
startActivityAndCollapse(pi)
} else {
startActivityAndCollapse(intent)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import dev.sasikanth.pinnit.utils.inTransaction
@Suppress("ClassName")
object Migration_1_2 : Migration(1, 2) {

override fun migrate(database: SupportSQLiteDatabase) {
with(database) {
override fun migrate(db: SupportSQLiteDatabase) {
with(db) {
inTransaction {
execSQL(""" ALTER TABLE PinnitNotification ADD COLUMN scheduleDate TEXT DEFAULT NULL """)
execSQL(""" ALTER TABLE PinnitNotification ADD COLUMN scheduleTime TEXT DEFAULT NULL """)
Expand Down
1 change: 0 additions & 1 deletion app/src/main/java/dev/sasikanth/pinnit/di/AppModule.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.sasikanth.pinnit.di

import android.content.Context
import android.text.format.DateFormat
import androidx.room.Room
import com.spotify.mobius.android.runners.MainThreadWorkRunner
import com.spotify.mobius.runners.WorkRunner
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import dagger.hilt.components.SingletonComponent
import dev.sasikanth.pinnit.di.DateTimeFormat.Type.ScheduleDateFormat
import dev.sasikanth.pinnit.di.DateTimeFormat.Type.ScheduleTimeFormat
import java.time.format.DateTimeFormatter
import javax.inject.Qualifier

@InstallIn(SingletonComponent::class)
@Module
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package dev.sasikanth.pinnit.editor

import android.os.Parcel
import android.os.Parcelable
import com.google.android.material.datepicker.CalendarConstraints
import dev.sasikanth.pinnit.utils.RealUserClock
import dev.sasikanth.pinnit.utils.UserClock
import dev.sasikanth.pinnit.utils.UtcClock
import java.time.Instant
import java.time.LocalDate
import java.time.ZoneId
import javax.inject.Inject

/**
Expand Down Expand Up @@ -33,4 +36,18 @@ class CurrentDateValidator @Inject constructor(

return localDate >= currentDate
}

companion object CREATOR : Parcelable.Creator<CurrentDateValidator> {

override fun createFromParcel(parcel: Parcel): CurrentDateValidator {
return CurrentDateValidator(
userClock = RealUserClock(ZoneId.systemDefault()),
utcClock = UtcClock()
)
}

override fun newArray(size: Int): Array<CurrentDateValidator?> {
return arrayOfNulls(size)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ data class UpdateNotification(
val schedule: Schedule?
) : EditorScreenEffect()

object CloseEditor : EditorScreenEffect()
data object CloseEditor : EditorScreenEffect()

object ShowConfirmExitEditor : EditorScreenEffect()
data object ShowConfirmExitEditor : EditorScreenEffect()

data class DeleteNotification(val notification: PinnitNotification) : EditorScreenEffect()

object ShowConfirmDelete : EditorScreenEffect()
data object ShowConfirmDelete : EditorScreenEffect()

data class ShowDatePicker(val date: LocalDate) : EditorScreenEffect()

Expand Down
20 changes: 10 additions & 10 deletions app/src/main/java/dev/sasikanth/pinnit/editor/EditorScreenEvent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,27 @@ data class TitleChanged(val title: String) : EditorScreenEvent()

data class ContentChanged(val content: String?) : EditorScreenEvent()

object SaveClicked : EditorScreenEvent()
data object SaveClicked : EditorScreenEvent()

object BackClicked : EditorScreenEvent()
data object BackClicked : EditorScreenEvent()

object ConfirmedExit : EditorScreenEvent()
data object ConfirmedExit : EditorScreenEvent()

object DeleteNotificationClicked : EditorScreenEvent()
data object DeleteNotificationClicked : EditorScreenEvent()

object ConfirmDeleteNotification : EditorScreenEvent()
data object ConfirmDeleteNotification : EditorScreenEvent()

data class AddScheduleClicked(val schedule: Schedule) : EditorScreenEvent()

object RemoveScheduleClicked : EditorScreenEvent()
data object RemoveScheduleClicked : EditorScreenEvent()

object ScheduleRepeatUnchecked : EditorScreenEvent()
data object ScheduleRepeatUnchecked : EditorScreenEvent()

object ScheduleRepeatChecked : EditorScreenEvent()
data object ScheduleRepeatChecked : EditorScreenEvent()

object ScheduleDateClicked : EditorScreenEvent()
data object ScheduleDateClicked : EditorScreenEvent()

object ScheduleTimeClicked : EditorScreenEvent()
data object ScheduleTimeClicked : EditorScreenEvent()

data class ScheduleDateChanged(val date: LocalDate) : EditorScreenEvent()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import java.time.LocalTime

sealed class EditorScreenViewEffect

object CloseEditorView : EditorScreenViewEffect()
data object CloseEditorView : EditorScreenViewEffect()

data class SetTitle(val title: String?) : EditorScreenViewEffect()

data class SetContent(val content: String?) : EditorScreenViewEffect()

object ShowConfirmExitEditorDialog : EditorScreenViewEffect()
data object ShowConfirmExitEditorDialog : EditorScreenViewEffect()

object ShowConfirmDeleteDialog : EditorScreenViewEffect()
data object ShowConfirmDeleteDialog : EditorScreenViewEffect()

data class ShowDatePickerDialog(val date: LocalDate) : EditorScreenViewEffect()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import com.spotify.mobius.android.MobiusLoopViewModel
import com.spotify.mobius.runners.WorkRunner
import dagger.hilt.android.lifecycle.HiltViewModel
import dev.sasikanth.pinnit.utils.MAX_VIEW_EFFECTS_QUEUE_SIZE
import java.util.UUID
import javax.inject.Inject

@HiltViewModel
Expand Down Expand Up @@ -41,7 +40,7 @@ class EditorScreenViewModel @Inject constructor(
}

override fun onClearedInternal() {
savedStateHandle.set(MODEL_KEY, model)
savedStateHandle[MODEL_KEY] = model
super.onClearedInternal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import kotlinx.parcelize.Parcelize
sealed class EditorTransition : Parcelable {

@Parcelize
object SharedAxis : EditorTransition()
data object SharedAxis : EditorTransition()

@Parcelize
data class ContainerTransform(val transitionName: String) : EditorTransition()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@ class ScheduleValidator @Inject constructor(val userClock: UserClock) {
sealed class Result : Parcelable {

@Parcelize
object Valid : Result()
data object Valid : Result()

@Parcelize
object ScheduleInPastError : Result()
data object ScheduleInPastError : Result()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ sealed class NotificationScreenViewEffect

data class UndoNotificationDeleteViewEffect(val notificationUuid: UUID) : NotificationScreenViewEffect()

object RequestNotificationPermissionViewEffect : NotificationScreenViewEffect()
data object RequestNotificationPermissionViewEffect : NotificationScreenViewEffect()
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@ class NotificationsScreen : Fragment(), NotificationsScreenUi {

viewModel.viewEffects.setObserver(
viewLifecycleOwner,
::viewEffectsHandler,
{ pausedViewEffects -> pausedViewEffects.forEach(::viewEffectsHandler) })
::viewEffectsHandler
) { pausedViewEffects -> pausedViewEffects.forEach(::viewEffectsHandler) }

binding.bottomBar.setNavigationOnClickListener {
OptionsBottomSheet.show(requireActivity().supportFragmentManager)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,15 @@ import java.util.UUID

sealed class NotificationsScreenEffect

object LoadNotifications : NotificationsScreenEffect()
data object LoadNotifications : NotificationsScreenEffect()

data class ToggleNotificationPinStatus(val notification: PinnitNotification) : NotificationsScreenEffect()

data class DeleteNotification(val notification: PinnitNotification) : NotificationsScreenEffect()

data class UndoDeletedNotification(val notificationUuid: UUID) : NotificationsScreenEffect()

object CheckNotificationsVisibility : NotificationsScreenEffect()
data object CheckNotificationsVisibility : NotificationsScreenEffect()

data class ShowUndoDeleteNotification(val notification: PinnitNotification) : NotificationsScreenEffect()

Expand All @@ -23,6 +23,6 @@ data class RemoveSchedule(val notificationId: UUID) : NotificationsScreenEffect(

data class ScheduleNotification(val notification: PinnitNotification) : NotificationsScreenEffect()

object CheckPermissionToPostNotification : NotificationsScreenEffect()
data object CheckPermissionToPostNotification : NotificationsScreenEffect()

object RequestNotificationPermission : NotificationsScreenEffect()
data object RequestNotificationPermission : NotificationsScreenEffect()
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class NotificationsScreenViewModel @Inject constructor(
}

override fun onClearedInternal() {
savedStateHandle.set(MODEL_KEY, model)
savedStateHandle[MODEL_KEY] = model
super.onClearedInternal()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class OemWarningDialog : DialogFragment() {

@SuppressLint("InflateParams")
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val layoutInflater = LayoutInflater.from(requireContext())
_binding = PinnitOemWarningDialogBinding.inflate(layoutInflater, null, false)

return MaterialAlertDialogBuilder(requireContext())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,19 @@ import android.view.ViewGroup
import androidx.annotation.IdRes
import androidx.datastore.core.DataStore
import androidx.fragment.app.FragmentManager
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import com.google.android.material.bottomsheet.BottomSheetDialogFragment
import dagger.hilt.android.AndroidEntryPoint
import dev.sasikanth.pinnit.R
import dev.sasikanth.pinnit.data.preferences.AppPreferences
import dev.sasikanth.pinnit.databinding.ThemeSelectionSheetBinding
import dev.sasikanth.pinnit.utils.DispatcherProvider
import kotlinx.coroutines.flow.collect
import kotlinx.coroutines.flow.filter
import kotlinx.coroutines.flow.first
import kotlinx.coroutines.flow.map
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
import reactivecircus.flowbinding.material.buttonCheckedChanges
import javax.inject.Inject
Expand Down Expand Up @@ -51,17 +53,19 @@ class OptionsBottomSheet : BottomSheetDialogFragment() {
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

viewLifecycleOwner.lifecycleScope.launchWhenResumed {
val theme = withContext(dispatcherProvider.io) {
appPreferencesStore.data.first().theme
viewLifecycleOwner.lifecycleScope.launch {
repeatOnLifecycle(Lifecycle.State.RESUMED) {
val theme = withContext(dispatcherProvider.io) {
appPreferencesStore.data.first().theme
}
checkThemeSelection(theme)

binding.themeButtonGroup
.buttonCheckedChanges()
.filter { it.checked }
.map { it.checkedId }
.collect { updateTheme(it) }
}
checkThemeSelection(theme)

binding.themeButtonGroup
.buttonCheckedChanges()
.filter { it.checked }
.map { it.checkedId }
.collect { updateTheme(it) }
}
}

Expand Down
Loading

0 comments on commit fe89a47

Please sign in to comment.