refactor: resolve compiler warnings

This commit is contained in:
Rohit Verma 2025-01-14 10:04:40 +05:30
parent 50096cc433
commit a182741588
No known key found for this signature in database
3 changed files with 51 additions and 48 deletions

View file

@ -122,7 +122,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
/** /**
* Set the value of the showPermissionDialog variable. * Set the value of the showPermissionDialog variable.
* *
* @param showPermissionsDialog `true` to indicate to show * @property isShowPermissionsDialog `true` to indicate to show
* Permissions Dialog if permissions are missing, `false` otherwise. * Permissions Dialog if permissions are missing, `false` otherwise.
*/ */
/** /**
@ -187,7 +187,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
} }
init() init()
binding.rlContainerTitle.setOnClickListener { v: View? -> onRlContainerTitleClicked() } binding.rlContainerTitle.setOnClickListener { _: View? -> onRlContainerTitleClicked() }
nearbyPopupAnswers = mutableMapOf() nearbyPopupAnswers = mutableMapOf()
//getting the current dpi of the device and if it is less than 320dp i.e. overlapping //getting the current dpi of the device and if it is less than 320dp i.e. overlapping
//threshold, thumbnails automatically minimizes //threshold, thumbnails automatically minimizes
@ -201,7 +201,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
} }
locationManager!!.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER) locationManager!!.requestLocationUpdatesFromProvider(LocationManager.GPS_PROVIDER)
locationManager!!.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER) locationManager!!.requestLocationUpdatesFromProvider(LocationManager.NETWORK_PROVIDER)
store = BasicKvStore(this, storeNameForCurrentUploadImagesSize).apply { store = BasicKvStore(this, STORE_NAME_FOR_CURRENT_UPLOAD_IMAGE_SIZE).apply {
clearAll() clearAll()
} }
checkStoragePermissions() checkStoragePermissions()
@ -241,7 +241,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
override fun onPageSelected(position: Int) { override fun onPageSelected(position: Int) {
currentSelectedPosition = position currentSelectedPosition = position
if (position >= uploadableFiles!!.size) { if (position >= uploadableFiles.size) {
binding.cvContainerTopCard.visibility = View.GONE binding.cvContainerTopCard.visibility = View.GONE
} else { } else {
thumbnailsAdapter!!.notifyDataSetChanged() thumbnailsAdapter!!.notifyDataSetChanged()
@ -274,7 +274,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
.subscribeOn(Schedulers.io()) .subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread()) .observeOn(AndroidSchedulers.mainThread())
.filter { result: Boolean? -> result!! } .filter { result: Boolean? -> result!! }
.subscribe { result: Boolean? -> .subscribe { _: Boolean? ->
showAlertDialog( showAlertDialog(
this, this,
getString(R.string.block_notification_title), getString(R.string.block_notification_title),
@ -284,7 +284,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
}) })
} }
fun checkStoragePermissions() { private fun checkStoragePermissions() {
// Check if all required permissions are granted // Check if all required permissions are granted
val hasAllPermissions = hasPermission(this, PERMISSIONS_STORAGE) val hasAllPermissions = hasPermission(this, PERMISSIONS_STORAGE)
val hasPartialAccess = hasPartialAccess(this) val hasPartialAccess = hasPartialAccess(this)
@ -355,7 +355,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
showLongToast(this, messageResourceId) showLongToast(this, messageResourceId)
} }
override fun getUploadableFiles(): List<UploadableFile>? { override fun getUploadableFiles(): List<UploadableFile> {
return uploadableFiles return uploadableFiles
} }
@ -375,8 +375,8 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
binding.tvTopCardTitle.text = resources binding.tvTopCardTitle.text = resources
.getQuantityString( .getQuantityString(
R.plurals.upload_count_title, R.plurals.upload_count_title,
uploadableFiles!!.size, uploadableFiles.size,
uploadableFiles!!.size uploadableFiles.size
) )
} }
@ -444,15 +444,16 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
receiveInternalSharedItems() receiveInternalSharedItems()
} }
if (uploadableFiles == null || uploadableFiles!!.isEmpty()) { if (uploadableFiles.isEmpty()) {
handleNullMedia() handleNullMedia()
} else { } else {
//Show thumbnails //Show thumbnails
if (uploadableFiles!!.size > 1) { if (uploadableFiles.size > 1) {
if (!defaultKvStore.getBoolean("hasAlreadyLaunchedCategoriesDialog")) { //If there is only file, no need to show the image thumbnails if (!defaultKvStore.getBoolean("hasAlreadyLaunchedCategoriesDialog")) {
// If there is only file, no need to show the image thumbnails
showAlertDialogForCategories() showAlertDialogForCategories()
} }
if (uploadableFiles!!.size > 3 && if (uploadableFiles.size > 3 &&
!defaultKvStore.getBoolean("hasAlreadyLaunchedBigMultiupload") !defaultKvStore.getBoolean("hasAlreadyLaunchedBigMultiupload")
) { ) {
showAlertForBattery() showAlertForBattery()
@ -464,8 +465,8 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
binding.tvTopCardTitle.text = resources binding.tvTopCardTitle.text = resources
.getQuantityString( .getQuantityString(
R.plurals.upload_count_title, R.plurals.upload_count_title,
uploadableFiles!!.size, uploadableFiles.size,
uploadableFiles!!.size uploadableFiles.size
) )
@ -474,7 +475,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
} }
for (uploadableFile in uploadableFiles!!) { for (uploadableFile in uploadableFiles) {
val uploadMediaDetailFragment = UploadMediaDetailFragment() val uploadMediaDetailFragment = UploadMediaDetailFragment()
if (!uploadIsOfAPlace) { if (!uploadIsOfAPlace) {
@ -497,8 +498,8 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
object : UploadMediaDetailFragmentCallback { object : UploadMediaDetailFragmentCallback {
override fun deletePictureAtIndex(index: Int) { override fun deletePictureAtIndex(index: Int) {
store!!.putInt( store!!.putInt(
keyForCurrentUploadImagesSize, KEY_FOR_CURRENT_UPLOAD_IMAGE_SIZE,
(store!!.getInt(keyForCurrentUploadImagesSize) - 1) (store!!.getInt(KEY_FOR_CURRENT_UPLOAD_IMAGE_SIZE) - 1)
) )
presenter!!.deletePictureAtIndex(index) presenter!!.deletePictureAtIndex(index)
} }
@ -576,11 +577,11 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
fragments!!.add(mediaLicenseFragment!!) fragments!!.add(mediaLicenseFragment!!)
} else { } else {
for (i in 1 until fragments!!.size) { for (i in 1 until fragments!!.size) {
fragments!![i]!!.callback = object : UploadBaseFragment.Callback { fragments!![i].callback = object : UploadBaseFragment.Callback {
override fun onNextButtonClicked(index: Int) { override fun onNextButtonClicked(index: Int) {
if (index < fragments!!.size - 1) { if (index < fragments!!.size - 1) {
binding.vpUpload.setCurrentItem(index + 1, false) binding.vpUpload.setCurrentItem(index + 1, false)
fragments!![index + 1]!!.onBecameVisible() fragments!![index + 1].onBecameVisible()
(binding.rvThumbnails.layoutManager as LinearLayoutManager) (binding.rvThumbnails.layoutManager as LinearLayoutManager)
.scrollToPositionWithOffset( .scrollToPositionWithOffset(
if ((index > 0)) index - 1 else 0, if ((index > 0)) index - 1 else 0,
@ -594,7 +595,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
override fun onPreviousButtonClicked(index: Int) { override fun onPreviousButtonClicked(index: Int) {
if (index != 0) { if (index != 0) {
binding.vpUpload.setCurrentItem(index - 1, true) binding.vpUpload.setCurrentItem(index - 1, true)
fragments!![index - 1]!!.onBecameVisible() fragments!![index - 1].onBecameVisible()
(binding.rvThumbnails.layoutManager as LinearLayoutManager) (binding.rvThumbnails.layoutManager as LinearLayoutManager)
.scrollToPositionWithOffset( .scrollToPositionWithOffset(
if ((index > 3)) index - 2 else 0, if ((index > 3)) index - 2 else 0,
@ -632,11 +633,12 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
binding.vpUpload.offscreenPageLimit = fragments!!.size binding.vpUpload.offscreenPageLimit = fragments!!.size
} }
// Saving size of uploadableFiles // Saving size of uploadableFiles
store!!.putInt(keyForCurrentUploadImagesSize, uploadableFiles!!.size) store!!.putInt(KEY_FOR_CURRENT_UPLOAD_IMAGE_SIZE, uploadableFiles.size)
} }
/** /**
* Changes current image when one image upload is cancelled, to highlight next image in the top thumbnail. * Changes current image when one image upload is cancelled, to highlight next image in the top
* thumbnail.
* Fixes: [Issue](https://github.com/commons-app/apps-android-commons/issues/5511) * Fixes: [Issue](https://github.com/commons-app/apps-android-commons/issues/5511)
* *
* @param index Index of image to be removed * @param index Index of image to be removed
@ -690,10 +692,10 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
uploadableFiles = mutableListOf<UploadableFile>().apply { uploadableFiles = mutableListOf<UploadableFile>().apply {
addAll(intent.getParcelableArrayListExtra(EXTRA_FILES) ?: emptyList()) addAll(intent.getParcelableArrayListExtra(EXTRA_FILES) ?: emptyList())
} }
isMultipleFilesSelected = uploadableFiles!!.size > 1 isMultipleFilesSelected = uploadableFiles.size > 1
Timber.i("Received multiple upload %s", uploadableFiles!!.size) Timber.i("Received multiple upload %s", uploadableFiles.size)
place = intent.getParcelableExtra<Place>(PLACE_OBJECT) place = intent.getParcelableExtra(PLACE_OBJECT)
prevLocation = intent.getParcelableExtra(LOCATION_BEFORE_IMAGE_CAPTURE) prevLocation = intent.getParcelableExtra(LOCATION_BEFORE_IMAGE_CAPTURE)
isInAppCameraUpload = intent.getBooleanExtra(IN_APP_CAMERA_UPLOAD, false) isInAppCameraUpload = intent.getBooleanExtra(IN_APP_CAMERA_UPLOAD, false)
resetDirectPrefs() resetDirectPrefs()
@ -724,7 +726,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
override fun onNextButtonClicked(index: Int) { override fun onNextButtonClicked(index: Int) {
if (index < fragments!!.size - 1) { if (index < fragments!!.size - 1) {
binding.vpUpload.setCurrentItem(index + 1, false) binding.vpUpload.setCurrentItem(index + 1, false)
fragments!![index + 1]!!.onBecameVisible() fragments!![index + 1].onBecameVisible()
(binding.rvThumbnails.layoutManager as LinearLayoutManager) (binding.rvThumbnails.layoutManager as LinearLayoutManager)
.scrollToPositionWithOffset(if ((index > 0)) index - 1 else 0, 0) .scrollToPositionWithOffset(if ((index > 0)) index - 1 else 0, 0)
if (index < fragments!!.size - 4) { if (index < fragments!!.size - 4) {
@ -739,10 +741,10 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
override fun onPreviousButtonClicked(index: Int) { override fun onPreviousButtonClicked(index: Int) {
if (index != 0) { if (index != 0) {
binding.vpUpload.setCurrentItem(index - 1, true) binding.vpUpload.setCurrentItem(index - 1, true)
fragments!![index - 1]!!.onBecameVisible() fragments!![index - 1].onBecameVisible()
(binding.rvThumbnails.layoutManager as LinearLayoutManager) (binding.rvThumbnails.layoutManager as LinearLayoutManager)
.scrollToPositionWithOffset(if ((index > 3)) index - 2 else 0, 0) .scrollToPositionWithOffset(if ((index > 3)) index - 2 else 0, 0)
if ((index != 1) && ((index - 1) < uploadableFiles!!.size)) { if ((index != 1) && ((index - 1) < uploadableFiles.size)) {
// Shows the top card if it was hidden because of the last image being deleted and // Shows the top card if it was hidden because of the last image being deleted and
// now the user has hit previous button to go back to the media details // now the user has hit previous button to go back to the media details
showHideTopCard(true) showHideTopCard(true)
@ -780,11 +782,11 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
} }
fun onRlContainerTitleClicked() { private fun onRlContainerTitleClicked() {
binding.rvThumbnails.visibility = binding.rvThumbnails.visibility =
if (isTitleExpanded) View.GONE else View.VISIBLE if (isTitleExpanded) View.GONE else View.VISIBLE
isTitleExpanded = !isTitleExpanded isTitleExpanded = !isTitleExpanded
binding.ibToggleTopCard.rotation = binding.ibToggleTopCard.rotation + 180 binding.ibToggleTopCard.rotation += 180
} }
override fun onDestroy() { override fun onDestroy() {
@ -834,7 +836,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
.setView(view) .setView(view)
.setTitle(getString(R.string.multiple_files_depiction_header)) .setTitle(getString(R.string.multiple_files_depiction_header))
.setMessage(getString(R.string.multiple_files_depiction)) .setMessage(getString(R.string.multiple_files_depiction))
.setPositiveButton("OK") { dialog: DialogInterface?, which: Int -> .setPositiveButton("OK") { _: DialogInterface?, _: Int ->
if (checkBox.isChecked) { if (checkBox.isChecked) {
// Save the user's choice to not show the dialog again // Save the user's choice to not show the dialog again
defaultKvStore.putBoolean("hasAlreadyLaunchedCategoriesDialog", true) defaultKvStore.putBoolean("hasAlreadyLaunchedCategoriesDialog", true)
@ -868,14 +870,14 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
getString(R.string.cancel), getString(R.string.cancel),
{ {
/* Since opening the right settings page might be device dependent, using /* Since opening the right settings page might be device dependent, using
https://github.com/WaseemSabir/BatteryPermissionHelper https://github.com/WaseemSabir/BatteryPermissionHelper
directly appeared like a promising idea. directly appeared like a promising idea.
However, this simply closed the popup and did not make However, this simply closed the popup and did not make
the settings page appear on a Pixel as well as a Xiaomi device. the settings page appear on a Pixel as well as a Xiaomi device.
Used the standard intent instead of using this library as Used the standard intent instead of using this library as
it shows a list of all the apps on the device and allows users to it shows a list of all the apps on the device and allows users to
turn battery optimisation off. turn battery optimisation off.
*/ */
val batteryOptimisationSettingsIntent = Intent( val batteryOptimisationSettingsIntent = Intent(
Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS
) )
@ -913,7 +915,8 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
Also, location information is discarded if the difference between Also, location information is discarded if the difference between
current location and location recorded just before capturing the image current location and location recorded just before capturing the image
is greater than 100 meters */ is greater than 100 meters */
if (isLocationTagUnchecked || locationDifference > 100 || !defaultKvStore.getBoolean("inAppCameraLocationPref") if (isLocationTagUnchecked || locationDifference > 100
|| !defaultKvStore.getBoolean("inAppCameraLocationPref")
|| !isInAppCameraUpload || !isInAppCameraUpload
) { ) {
currLocation = null currLocation = null
@ -934,8 +937,8 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
@JvmField @JvmField
var nearbyPopupAnswers: MutableMap<Place, Boolean>? = null var nearbyPopupAnswers: MutableMap<Place, Boolean>? = null
const val keyForCurrentUploadImagesSize: String = "CurrentUploadImagesSize" const val KEY_FOR_CURRENT_UPLOAD_IMAGE_SIZE: String = "CurrentUploadImagesSize"
const val storeNameForCurrentUploadImagesSize: String = "CurrentUploadImageQualities" const val STORE_NAME_FOR_CURRENT_UPLOAD_IMAGE_SIZE: String = "CurrentUploadImageQualities"
/** /**
* Sets the flag indicating whether the upload is of a specific place. * Sets the flag indicating whether the upload is of a specific place.

View file

@ -528,7 +528,7 @@ class UploadMediaDetailFragment : UploadBaseFragment(), UploadMediaDetailsContra
basicKvStore!!.putBoolean(keyForShowingAlertDialog, false) basicKvStore!!.putBoolean(keyForShowingAlertDialog, false)
if (isInternetConnectionEstablished(requireActivity())) { if (isInternetConnectionEstablished(requireActivity())) {
val sizeOfUploads = basicKvStore!!.getInt( val sizeOfUploads = basicKvStore!!.getInt(
UploadActivity.keyForCurrentUploadImagesSize UploadActivity.KEY_FOR_CURRENT_UPLOAD_IMAGE_SIZE
) )
for (i in indexOfFragment until sizeOfUploads) { for (i in indexOfFragment until sizeOfUploads) {
presenter.getImageQuality( presenter.getImageQuality(

View file

@ -310,7 +310,7 @@ class UploadMediaPresenter @Inject constructor(
private fun storeImageQuality( private fun storeImageQuality(
imageResult: Int, uploadItemIndex: Int, activity: Activity, uploadItem: UploadItem imageResult: Int, uploadItemIndex: Int, activity: Activity, uploadItem: UploadItem
) { ) {
val store = BasicKvStore(activity, UploadActivity.storeNameForCurrentUploadImagesSize) val store = BasicKvStore(activity, UploadActivity.STORE_NAME_FOR_CURRENT_UPLOAD_IMAGE_SIZE)
val value = store.getString(UPLOAD_QUALITIES_KEY, null) val value = store.getString(UPLOAD_QUALITIES_KEY, null)
try { try {
val jsonObject = value.asJsonObject().apply { val jsonObject = value.asJsonObject().apply {
@ -339,7 +339,7 @@ class UploadMediaPresenter @Inject constructor(
*/ */
override fun checkImageQuality(uploadItem: UploadItem, index: Int) { override fun checkImageQuality(uploadItem: UploadItem, index: Int) {
if ((uploadItem.imageQuality != IMAGE_OK) && (uploadItem.imageQuality != IMAGE_KEEP)) { if ((uploadItem.imageQuality != IMAGE_OK) && (uploadItem.imageQuality != IMAGE_KEEP)) {
val value = basicKvStoreFactory(UploadActivity.storeNameForCurrentUploadImagesSize) val value = basicKvStoreFactory(UploadActivity.STORE_NAME_FOR_CURRENT_UPLOAD_IMAGE_SIZE)
.getString(UPLOAD_QUALITIES_KEY, null) .getString(UPLOAD_QUALITIES_KEY, null)
try { try {
val imageQuality = value.asJsonObject()["UploadItem$index"] as Int val imageQuality = value.asJsonObject()["UploadItem$index"] as Int
@ -363,7 +363,7 @@ class UploadMediaPresenter @Inject constructor(
* @param index Index of the UploadItem which was deleted * @param index Index of the UploadItem which was deleted
*/ */
override fun updateImageQualitiesJSON(size: Int, index: Int) { override fun updateImageQualitiesJSON(size: Int, index: Int) {
val value = basicKvStoreFactory(UploadActivity.storeNameForCurrentUploadImagesSize) val value = basicKvStoreFactory(UploadActivity.STORE_NAME_FOR_CURRENT_UPLOAD_IMAGE_SIZE)
.getString(UPLOAD_QUALITIES_KEY, null) .getString(UPLOAD_QUALITIES_KEY, null)
try { try {
val jsonObject = value.asJsonObject().apply { val jsonObject = value.asJsonObject().apply {
@ -372,7 +372,7 @@ class UploadMediaPresenter @Inject constructor(
} }
remove("UploadItem" + (size - 1)) remove("UploadItem" + (size - 1))
} }
basicKvStoreFactory(UploadActivity.storeNameForCurrentUploadImagesSize) basicKvStoreFactory(UploadActivity.STORE_NAME_FOR_CURRENT_UPLOAD_IMAGE_SIZE)
.putString(UPLOAD_QUALITIES_KEY, jsonObject.toString()) .putString(UPLOAD_QUALITIES_KEY, jsonObject.toString())
} catch (e: Exception) { } catch (e: Exception) {
Timber.e(e) Timber.e(e)