Skip to content

Migrated nearby parent fragments from java to kotlin #6149

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Changes from 1 commit
Commits
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
Next Next commit
fix/handle-shared-files-and-error-handling
  • Loading branch information
Sujal-Gupta-SG committed Jan 17, 2025
commit c4147a8e8718be9a3c264f66da5f8f25824811c0
66 changes: 58 additions & 8 deletions app/src/main/java/fr/free/nrw/commons/upload/UploadActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -684,17 +684,66 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C

private fun receiveInternalSharedItems() {
val intent = intent
Timber.d("Intent has EXTRA_FILES: ${EXTRA_FILES}")

Timber.d("Received intent %s with action %s", intent.toString(), intent.action)

uploadableFiles = mutableListOf<UploadableFile>().apply {
addAll(intent.getParcelableArrayListExtra(EXTRA_FILES) ?: emptyList())
uploadableFiles = try {
// Check if intent has the extra before trying to read it
if (!intent.hasExtra(EXTRA_FILES)) {
Timber.w("No EXTRA_FILES found in intent")
mutableListOf()
} else {
// Try to get the files as Parcelable array
val files = if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
intent.getParcelableArrayListExtra(EXTRA_FILES, UploadableFile::class.java)
} else {
@Suppress("DEPRECATION")
intent.getParcelableArrayListExtra<UploadableFile>(EXTRA_FILES)
}

// Convert to mutable list or return empty list if null
files?.toMutableList() ?: run {
Timber.w("Files array was null")
mutableListOf()
}
}
} catch (e: Exception) {
Timber.e(e, "Error reading files from intent")
mutableListOf()
}

// Log the result for debugging
isMultipleFilesSelected = uploadableFiles.size > 1
Timber.i("Received files count: ${uploadableFiles.size}")
uploadableFiles.forEachIndexed { index, file ->
Timber.d("File $index path: ${file.getFilePath()}")
}

// Handle other extras with null safety
place = try {
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra(PLACE_OBJECT, Place::class.java)
} else {
@Suppress("DEPRECATION")
intent.getParcelableExtra(PLACE_OBJECT)
}
} catch (e: Exception) {
Timber.e(e, "Error reading place")
null
}

prevLocation = try {
if (VERSION.SDK_INT >= VERSION_CODES.TIRAMISU) {
intent.getParcelableExtra(LOCATION_BEFORE_IMAGE_CAPTURE, LatLng::class.java)
} else {
@Suppress("DEPRECATION")
intent.getParcelableExtra(LOCATION_BEFORE_IMAGE_CAPTURE)
}
} catch (e: Exception) {
Timber.e(e, "Error reading location")
null
}
isMultipleFilesSelected = uploadableFiles!!.size > 1
Timber.i("Received multiple upload %s", uploadableFiles!!.size)

place = intent.getParcelableExtra<Place>(PLACE_OBJECT)
prevLocation = intent.getParcelableExtra(LOCATION_BEFORE_IMAGE_CAPTURE)
isInAppCameraUpload = intent.getBooleanExtra(IN_APP_CAMERA_UPLOAD, false)
resetDirectPrefs()
}
Expand Down Expand Up @@ -803,6 +852,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C
/**
* Overrides the back button to make sure the user is prepared to lose their progress
*/
@SuppressLint("MissingSuperCall")
override fun onBackPressed() {
showAlertDialog(
this,
Expand Down Expand Up @@ -920,7 +970,7 @@ class UploadActivity : BaseActivity(), UploadContract.View, UploadBaseFragment.C

companion object {
private var uploadIsOfAPlace = false
const val EXTRA_FILES: String = "commons_image_exta"
const val EXTRA_FILES: String = "commons_image_extra"
const val LOCATION_BEFORE_IMAGE_CAPTURE: String = "user_location_before_image_capture"
const val IN_APP_CAMERA_UPLOAD: String = "in_app_camera_upload"

Expand Down