Skip to content

Commit 4910b60

Browse files
authored
Merge pull request #17355 from Hoossayn/issue/17010_Detekt_Resolve_Suppress_All_Baseline_Warnings_long_method_media_picker
Detekt - Resolve/Suppress All Baseline Warnings - Long methods warnings_ MediaPickerActivity
2 parents f0dc9da + 8594712 commit 4910b60

File tree

1 file changed

+42
-43
lines changed

1 file changed

+42
-43
lines changed

WordPress/src/main/java/org/wordpress/android/ui/mediapicker/MediaPickerActivity.kt

Lines changed: 42 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ class MediaPickerActivity : LocaleAwareActivity(), MediaPickerListener {
173173
return super.onOptionsItemSelected(item)
174174
}
175175

176-
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION", "LongMethod", "NestedBlockDepth")
176+
@Suppress("DEPRECATION", "OVERRIDE_DEPRECATION")
177177
override fun onActivityResult(
178178
requestCode: Int,
179179
resultCode: Int,
@@ -191,55 +191,54 @@ class MediaPickerActivity : LocaleAwareActivity(), MediaPickerListener {
191191
return
192192
}
193193
}
194-
TAKE_PHOTO -> {
195-
try {
196-
val intent = Intent()
197-
mediaCapturePath!!.let {
198-
WPMediaUtils.scanMediaFile(this, it)
199-
val f = File(it)
200-
val capturedImageUri = listOf(Uri.fromFile(f))
201-
if (mediaPickerSetup.queueResults) {
202-
intent.putQueuedUris(capturedImageUri)
203-
} else {
204-
intent.putUris(capturedImageUri)
205-
}
206-
intent.putExtra(
207-
EXTRA_MEDIA_SOURCE,
208-
ANDROID_CAMERA.name
209-
)
210-
}
211-
intent
212-
} catch (e: RuntimeException) {
213-
AppLog.e(MEDIA, e)
214-
null
215-
}
216-
}
217-
IMAGE_EDITOR_EDIT_IMAGE -> {
218-
data?.let {
219-
val intent = Intent()
220-
val uris = WPMediaUtils.retrieveImageEditorResult(data)
221-
if (mediaPickerSetup.queueResults) {
222-
intent.putQueuedUris(uris)
223-
} else {
224-
intent.putUris(uris)
225-
}
226-
intent.putExtra(
227-
EXTRA_MEDIA_SOURCE,
228-
APP_PICKER.name
229-
)
230-
intent
231-
}
232-
}
233-
else -> {
234-
data
235-
}
194+
TAKE_PHOTO -> takeAPhoto()
195+
IMAGE_EDITOR_EDIT_IMAGE -> data?.let { editImageIntent(it) }
196+
else -> data
236197
}
198+
237199
intent?.let {
238200
setResult(Activity.RESULT_OK, intent)
239201
finish()
240202
}
241203
}
242204

205+
private fun editImageIntent(data: Intent?): Intent {
206+
val intent = Intent()
207+
val uris = WPMediaUtils.retrieveImageEditorResult(data)
208+
if (mediaPickerSetup.queueResults) {
209+
intent.putQueuedUris(uris)
210+
} else {
211+
intent.putUris(uris)
212+
}
213+
intent.putExtra(
214+
EXTRA_MEDIA_SOURCE,
215+
APP_PICKER.name
216+
)
217+
return intent
218+
}
219+
220+
private fun takeAPhoto() = try {
221+
val intent = Intent()
222+
mediaCapturePath!!.let {
223+
WPMediaUtils.scanMediaFile(this, it)
224+
val f = File(it)
225+
val capturedImageUri = listOf(Uri.fromFile(f))
226+
if (mediaPickerSetup.queueResults) {
227+
intent.putQueuedUris(capturedImageUri)
228+
} else {
229+
intent.putUris(capturedImageUri)
230+
}
231+
intent.putExtra(
232+
EXTRA_MEDIA_SOURCE,
233+
ANDROID_CAMERA.name
234+
)
235+
}
236+
intent
237+
} catch (e: RuntimeException) {
238+
AppLog.e(MEDIA, e)
239+
null
240+
}
241+
243242
private fun launchChooserWithContext(openSystemPicker: OpenSystemPicker, uiHelpers: UiHelpers) {
244243
WPMediaUtils.launchChooserWithContext(this, openSystemPicker, uiHelpers, MEDIA_LIBRARY)
245244
}

0 commit comments

Comments
 (0)