Skip to content

Commit

Permalink
Replace !! with checkNotNull
Browse files Browse the repository at this point in the history
  • Loading branch information
ztimms73 committed Jul 15, 2023
1 parent 2f41549 commit 086da0d
Show file tree
Hide file tree
Showing 40 changed files with 92 additions and 93 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ internal class AppUpdateNotifier(private val context: Context) {
addAction(
R.drawable.ic_close,
context.getString(R.string.action_cancel),
NotificationReceiver.cancelUpdateDownloadPendingBroadcast(context),
NotificationReceiver.cancelUpdateDownloadPendingBroadcast(context)
)
}
notificationBuilder.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import logcat.LogPriority
import okhttp3.internal.http2.ErrorCode
import okhttp3.internal.http2.StreamResetException
import org.xtimms.ridebus.BuildConfig
Expand All @@ -24,12 +23,10 @@ import org.xtimms.ridebus.network.NetworkHelper
import org.xtimms.ridebus.network.ProgressListener
import org.xtimms.ridebus.network.await
import org.xtimms.ridebus.network.newCallWithProgress
import org.xtimms.ridebus.util.lang.launchIO
import org.xtimms.ridebus.util.storage.getUriCompat
import org.xtimms.ridebus.util.storage.saveTo
import org.xtimms.ridebus.util.system.acquireWakeLock
import org.xtimms.ridebus.util.system.isServiceRunning
import org.xtimms.ridebus.util.system.logcat
import uy.kohesive.injekt.injectLazy
import java.io.File

Expand Down Expand Up @@ -117,7 +114,7 @@ class AppUpdateService : Service() {
notifier.onDownloadFinished(apkFile.getUriCompat(this))
} catch (e: Exception) {
val shouldCancel = e is CancellationException ||
(e is StreamResetException && e.errorCode == ErrorCode.CANCEL)
(e is StreamResetException && e.errorCode == ErrorCode.CANCEL)
if (shouldCancel) {
notifier.cancel()
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class DatabaseUpdateNotifier(private val context: Context) {
addAction(
R.drawable.ic_close,
context.getString(R.string.action_cancel),
NotificationReceiver.cancelUpdateDownloadPendingBroadcast(context),
NotificationReceiver.cancelUpdateDownloadPendingBroadcast(context)
)
}
notificationBuilder.show()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,14 @@ class DatabaseUpdateService : Service() {
notifier.onDownloadFinished(title)
} catch (e: Exception) {
val shouldCancel = e is CancellationException ||
(e is StreamResetException && e.errorCode == ErrorCode.CANCEL)
(e is StreamResetException && e.errorCode == ErrorCode.CANCEL)
if (shouldCancel) {
notifier.cancel()
} else {
notifier.onDownloadError(url, version)
}
} finally {
database.openHelper.writableDatabase.endTransaction()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,37 +37,37 @@ abstract class DialogController : Controller {

override fun onCreateView(inflater: LayoutInflater, container: ViewGroup, savedViewState: Bundle?): View {
dialog = onCreateDialog(savedViewState)
dialog!!.setOwnerActivity(activity!!)
dialog!!.setOnDismissListener { dismissDialog() }
checkNotNull(dialog).setOwnerActivity(checkNotNull(activity))
checkNotNull(dialog).setOnDismissListener { dismissDialog() }
if (savedViewState != null) {
val dialogState = savedViewState.getBundle(SAVED_DIALOG_STATE_TAG)
if (dialogState != null) {
dialog!!.onRestoreInstanceState(dialogState)
checkNotNull(dialog).onRestoreInstanceState(dialogState)
}
}
return View(activity) // stub view
}

override fun onSaveViewState(view: View, outState: Bundle) {
super.onSaveViewState(view, outState)
val dialogState = dialog!!.onSaveInstanceState()
val dialogState = checkNotNull(dialog).onSaveInstanceState()
outState.putBundle(SAVED_DIALOG_STATE_TAG, dialogState)
}

override fun onAttach(view: View) {
super.onAttach(view)
dialog!!.show()
checkNotNull(dialog).show()
}

override fun onDetach(view: View) {
super.onDetach(view)
dialog!!.hide()
checkNotNull(dialog).hide()
}

override fun onDestroyView(view: View) {
super.onDestroyView(view)
dialog!!.setOnDismissListener(null)
dialog!!.dismiss()
checkNotNull(dialog).setOnDismissListener(null)
checkNotNull(dialog).dismiss()
dialog = null
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ abstract class NucleusController<VB : ViewBinding, P : Presenter<*>>(val bundle:
private val delegate = NucleusConductorDelegate(this)

val presenter: P
get() = delegate.presenter!!
get() = checkNotNull(delegate.presenter)

init {
addLifecycleListener(NucleusConductorLifecycleListener(delegate))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class NucleusConductorDelegate<P : Presenter<*>>(private val factory: PresenterF
get() {
if (field == null) {
field = factory.createPresenter()
field!!.create(bundle)
checkNotNull(field).create(bundle)
bundle = null
}
return field
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ class FavouriteOptionsDialog(bundle: Bundle? = null) : DialogController(bundle)
}

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialAlertDialogBuilder(activity!!)
return MaterialAlertDialogBuilder(checkNotNull(activity))
.setTitle(favourite)
.setItems(items.map { it.first }.toTypedArray()) { dialog, which ->
items[which].second()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ class FavouritesController :

override fun onPinClick(position: Int) {
val item = adapter?.getItem(position) as? FavouriteItem ?: return
toggleFavouritePin(item.route!!)
toggleFavouritePin(checkNotNull(item.route))
}

override fun onItemClick(view: View, position: Int): Boolean {
Expand All @@ -105,11 +105,11 @@ class FavouritesController :
val isPinned = item.header?.type?.equals(FavouritesPresenter.PINNED_KEY) ?: false

val items = mutableListOf(
activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin) to { toggleFavouritePin(item.route!!) },
activity.getString(R.string.action_remove) to { removeFavouriteItem(item.route!!) }
activity.getString(if (isPinned) R.string.action_unpin else R.string.action_pin) to { toggleFavouritePin(checkNotNull(item.route)) },
activity.getString(R.string.action_remove) to { removeFavouriteItem(checkNotNull(item.route)) }
)

FavouriteOptionsDialog(item.route!!.title, items).showDialog(router)
FavouriteOptionsDialog(checkNotNull(item.route).title, items).showDialog(router)
}

private fun toggleFavouritePin(favourite: Route) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class FavouritesPresenter(
val byType = favourites.sortedWith(object : Comparator<Route?> {

override fun compare(o1: Route?, o2: Route?): Int {
return extractInt(o1!!) - extractInt(o2!!)
return extractInt(checkNotNull(o1)) - extractInt(checkNotNull(o2))
}

fun extractInt(s: Route): Int {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ class MainActivity : BaseActivity() {
}

private val nav: NavigationBarView
get() = binding.bottomNav ?: binding.sideNav!!
get() = binding.bottomNav ?: checkNotNull(binding.sideNav)

private fun setNavLabelVisibility() {
if (preferences.bottomBarLabels().get()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ import org.xtimms.ridebus.ui.base.controller.openInBrowser
class WhatsNewDialogController(bundle: Bundle? = null) : DialogController(bundle) {

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
return MaterialAlertDialogBuilder(activity!!)
.setTitle(activity!!.getString(R.string.updated_version, BuildConfig.VERSION_NAME))
return MaterialAlertDialogBuilder(checkNotNull(activity))
.setTitle(checkNotNull(activity).getString(R.string.updated_version, BuildConfig.VERSION_NAME))
.setPositiveButton(android.R.string.ok, null)
.setNeutralButton(R.string.whats_new) { _, _ ->
openInBrowser(RELEASE_URL)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class WelcomeDialogController :
private var binding: WelcomeDialogControllerBinding? = null

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = WelcomeDialogControllerBinding.inflate(activity!!.layoutInflater)
binding = WelcomeDialogControllerBinding.inflate(checkNotNull(activity).layoutInflater)

adapter = CityAdapter(this)

binding?.recyclerView?.layoutManager = LinearLayoutManager(view?.context)
binding?.recyclerView?.adapter = adapter

return RideBusFullscreenDialog(activity!!, binding!!.root).apply {
return RideBusFullscreenDialog(checkNotNull(activity), checkNotNull(binding).root).apply {
val typedValue = TypedValue()
val theme = context.theme
theme.resolveAttribute(android.R.attr.colorBackground, typedValue, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,11 +110,11 @@ class AboutController : SettingsController(), NoAppBarElevationController {
private fun checkVersion() {
if (activity == null) return

activity!!.toast(R.string.update_check_look_for_updates)
checkNotNull(activity).toast(R.string.update_check_look_for_updates)

launchNow {
try {
when (val result = updateChecker.checkForUpdate(activity!!, isUserPrompt = true)) {
when (val result = updateChecker.checkForUpdate(checkNotNull(activity), isUserPrompt = true)) {
is AppUpdateResult.NewUpdate -> {
NewUpdateDialogController(result).showDialog(router)
}
Expand Down Expand Up @@ -142,7 +142,7 @@ class AboutController : SettingsController(), NoAppBarElevationController {
)
outputDf.timeZone = TimeZone.getDefault()

buildTime!!.toDateTimestampString(dateFormat)
checkNotNull(buildTime).toDateTimestampString(dateFormat)
} catch (e: Exception) {
BuildConfig.BUILD_TIME
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class MoreController :

onChange { newValue ->
val checked = newValue as Boolean
DatabaseUpdateJob.setupTask(activity!!, checked)
DatabaseUpdateJob.setupTask(checkNotNull(activity), checked)
true
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundl
)

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val releaseBody = args.getString(BODY_KEY)!!
val releaseBody = checkNotNull(args.getString(BODY_KEY))
.replace("""---(\R|.)*Checksums(\R|.)*""".toRegex(), "")
val info = Markwon.create(activity!!).toMarkdown(releaseBody)
val info = Markwon.create(checkNotNull(activity)).toMarkdown(releaseBody)

return MaterialAlertDialogBuilder(
activity!!,
checkNotNull(activity),
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
)
.setTitle(R.string.update_check_notification_update_available)
Expand All @@ -44,12 +44,12 @@ class NewUpdateDialogController(bundle: Bundle? = null) : DialogController(bundl
.setPositiveButton(R.string.update_check_confirm) { _, _ ->
applicationContext?.let { context ->
// Start download
val url = args.getString(DOWNLOAD_URL_KEY)!!
val url = checkNotNull(args.getString(DOWNLOAD_URL_KEY))
AppUpdateService.start(context, url)
}
}
.setNeutralButton(R.string.update_check_open) { _, _ ->
openInBrowser(args.getString(RELEASE_URL_KEY)!!)
openInBrowser(checkNotNull(args.getString(RELEASE_URL_KEY)))
}
.setNeutralButton(R.string.action_postpone) { _, _ ->
dialog?.dismiss()
Expand Down Expand Up @@ -81,18 +81,18 @@ class NewScheduleDialogController(bundle: Bundle? = null) : DialogController(bun
)

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val infoBody = args.getString(NEW_SCHEDULE_BODY_KEY)!!
val version = args.getString(NEW_SCHEDULE_VERSION_KEY)!!
val infoBody = checkNotNull(args.getString(NEW_SCHEDULE_BODY_KEY))
val version = checkNotNull(args.getString(NEW_SCHEDULE_VERSION_KEY))

val message = buildString {
append(activity!!.getString(R.string.new_version_s, version))
append(checkNotNull(activity).getString(R.string.new_version_s, version))
appendLine()
appendLine()
append(infoBody)
}

return MaterialAlertDialogBuilder(
activity!!,
checkNotNull(activity),
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
)
.setTitle(R.string.update_check_notification_database_update_available)
Expand All @@ -101,8 +101,8 @@ class NewScheduleDialogController(bundle: Bundle? = null) : DialogController(bun
.setPositiveButton(R.string.update_check_confirm) { _, _ ->
applicationContext?.let { context ->
// Start download
val url = args.getString(NEW_SCHEDULE_DOWNLOAD_URL_KEY)!!
val version = args.getString(NEW_SCHEDULE_VERSION_KEY)!!
val url = checkNotNull(args.getString(NEW_SCHEDULE_DOWNLOAD_URL_KEY))
val version = checkNotNull(args.getString(NEW_SCHEDULE_VERSION_KEY))
DatabaseUpdateService.start(context, url, title = infoBody, version = version)
}
}
Expand Down Expand Up @@ -134,10 +134,10 @@ class CriticalDatabaseUpdateDialogController(bundle: Bundle? = null) : DialogCon
)

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
val infoBody = args.getString(CRITICAL_DATABASE_UPDATE_BODY_KEY)!!
val infoBody = checkNotNull(args.getString(CRITICAL_DATABASE_UPDATE_BODY_KEY))

return MaterialAlertDialogBuilder(
activity!!,
checkNotNull(activity),
materialR.style.ThemeOverlay_Material3_MaterialAlertDialog_Centered
)
.setTitle(R.string.critical_database_update_title)
Expand All @@ -146,8 +146,8 @@ class CriticalDatabaseUpdateDialogController(bundle: Bundle? = null) : DialogCon
.setPositiveButton(R.string.update_check_confirm) { _, _ ->
applicationContext?.let { context ->
// Start download
val url = args.getString(CRITICAL_DATABASE_UPDATE_DOWNLOAD_URL_KEY)!!
val version = args.getString(CRITICAL_DATABASE_UPDATE_VERSION_KEY)!!
val url = checkNotNull(args.getString(CRITICAL_DATABASE_UPDATE_DOWNLOAD_URL_KEY))
val version = checkNotNull(args.getString(CRITICAL_DATABASE_UPDATE_VERSION_KEY))
DatabaseUpdateService.start(context, url, title = infoBody, version = version)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ class MapStopsDialog :
private val points = mutableListOf<Point>()

override fun onCreateDialog(savedViewState: Bundle?): Dialog {
binding = MapStopsDialogBinding.inflate(activity!!.layoutInflater)
binding = MapStopsDialogBinding.inflate(checkNotNull(activity).layoutInflater)

MapKitFactory.initialize(activity!!)
MapKitFactory.initialize(checkNotNull(activity))

val cityPoint = db.cityDao().getCityCoordinates(preferences.city().get().toInt()).map {
Point(
Expand Down Expand Up @@ -80,14 +80,14 @@ class MapStopsDialog :
)
map?.mapObjects?.addCollection()?.addPlacemarks(
points,
ImageProvider.fromResource(activity!!, R.drawable.ic_stop_bitmap),
ImageProvider.fromResource(checkNotNull(activity), R.drawable.ic_stop_bitmap),
IconStyle()
)
}

binding?.mapView?.map?.isNightModeEnabled = activity!!.isNightMode()
binding?.mapView?.map?.isNightModeEnabled = checkNotNull(activity).isNightMode()

return RideBusFullscreenDialog(activity!!, binding!!.root).apply {
return RideBusFullscreenDialog(checkNotNull(activity), checkNotNull(binding).root).apply {
val typedValue = TypedValue()
val theme = context.theme
theme.resolveAttribute(android.R.attr.colorBackground, typedValue, true)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class RouteController :
override fun createBinding(inflater: LayoutInflater) = TransportControllerBinding.inflate(inflater)

override fun createPresenter(): RoutePresenter {
return RoutePresenter(transportType!!)
return RoutePresenter(checkNotNull(transportType))
}

override fun onViewCreated(view: View) {
Expand Down Expand Up @@ -141,7 +141,7 @@ class RouteController :

override fun onItemClick(position: Int) {
val route = (adapter?.getItem(position) as? RouteItem)?.route?.routeId ?: return
parentController!!.router.pushController(RouteDetailsController(route).withFadeTransaction())
checkNotNull(parentController).router.pushController(RouteDetailsController(route).withFadeTransaction())
}

override fun onUpdateEmptyView(size: Int) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ import uy.kohesive.injekt.injectLazy
class RoutesSettingsSheet(
router: Router,
onGroupClickListener: (ExtendedNavigationView.Group) -> Unit
) : TabbedBottomSheetDialog(router.activity!!) {
) : TabbedBottomSheetDialog(checkNotNull(router.activity)) {

private val display: Display

init {
display = Display(router.activity!!)
display = Display(checkNotNull(router.activity))
display.onGroupClicked = onGroupClickListener
}

Expand Down
Loading

0 comments on commit 086da0d

Please sign in to comment.