Skip to content

Commit f5cbb2e

Browse files
committed
Refactor: Extract take a photo method for media picker activity
1 parent 956253a commit f5cbb2e

File tree

1 file changed

+24
-23
lines changed

1 file changed

+24
-23
lines changed

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

Lines changed: 24 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -191,29 +191,8 @@ 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-
}
194+
TAKE_PHOTO -> takeAPhoto()
195+
217196
IMAGE_EDITOR_EDIT_IMAGE -> {
218197
data?.let {
219198
val intent = Intent()
@@ -240,6 +219,28 @@ class MediaPickerActivity : LocaleAwareActivity(), MediaPickerListener {
240219
}
241220
}
242221

222+
private fun takeAPhoto() = try {
223+
val intent = Intent()
224+
mediaCapturePath!!.let {
225+
WPMediaUtils.scanMediaFile(this, it)
226+
val f = File(it)
227+
val capturedImageUri = listOf(Uri.fromFile(f))
228+
if (mediaPickerSetup.queueResults) {
229+
intent.putQueuedUris(capturedImageUri)
230+
} else {
231+
intent.putUris(capturedImageUri)
232+
}
233+
intent.putExtra(
234+
EXTRA_MEDIA_SOURCE,
235+
ANDROID_CAMERA.name
236+
)
237+
}
238+
intent
239+
} catch (e: RuntimeException) {
240+
AppLog.e(MEDIA, e)
241+
null
242+
}
243+
243244
private fun launchChooserWithContext(openSystemPicker: OpenSystemPicker, uiHelpers: UiHelpers) {
244245
WPMediaUtils.launchChooserWithContext(this, openSystemPicker, uiHelpers, MEDIA_LIBRARY)
245246
}

0 commit comments

Comments
 (0)