improved compose media picking
This commit is contained in:
parent
74ff9c4082
commit
4e47cbb387
|
@ -158,7 +158,7 @@ dependencies {
|
||||||
compile 'com.bluelinelabs:logansquare:1.3.7'
|
compile 'com.bluelinelabs:logansquare:1.3.7'
|
||||||
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
|
compile 'com.soundcloud.android:android-crop:1.0.1@aar'
|
||||||
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
|
compile 'com.hannesdorfmann.parcelableplease:annotation:1.0.2'
|
||||||
compile 'com.github.mariotaku:PickNCrop:0.9.13'
|
compile 'com.github.mariotaku:PickNCrop:0.9.15'
|
||||||
compile "com.github.mariotaku.RestFu:library:$mariotaku_restfu_version"
|
compile "com.github.mariotaku.RestFu:library:$mariotaku_restfu_version"
|
||||||
compile "com.github.mariotaku.RestFu:okhttp3:$mariotaku_restfu_version"
|
compile "com.github.mariotaku.RestFu:okhttp3:$mariotaku_restfu_version"
|
||||||
compile 'com.squareup.okhttp3:okhttp:3.5.0'
|
compile 'com.squareup.okhttp3:okhttp:3.5.0'
|
||||||
|
|
|
@ -29,7 +29,6 @@ import android.graphics.Rect
|
||||||
import android.location.*
|
import android.location.*
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.AsyncTask
|
import android.os.AsyncTask
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.Parcelable
|
import android.os.Parcelable
|
||||||
import android.provider.BaseColumns
|
import android.provider.BaseColumns
|
||||||
|
@ -331,6 +330,9 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
|
|
||||||
override fun onMenuItemClick(item: MenuItem): Boolean {
|
override fun onMenuItemClick(item: MenuItem): Boolean {
|
||||||
when (item.itemId) {
|
when (item.itemId) {
|
||||||
|
R.id.take_photo -> {
|
||||||
|
requestOrOpenCamera()
|
||||||
|
}
|
||||||
R.id.add_image, R.id.add_image_sub_item -> {
|
R.id.add_image, R.id.add_image_sub_item -> {
|
||||||
requestOrPickMedia()
|
requestOrPickMedia()
|
||||||
}
|
}
|
||||||
|
@ -928,7 +930,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
return handleReplyMultipleIntent(screenNames, accountKey, inReplyToStatus)
|
return handleReplyMultipleIntent(screenNames, accountKey, inReplyToStatus)
|
||||||
}
|
}
|
||||||
INTENT_ACTION_COMPOSE_TAKE_PHOTO -> {
|
INTENT_ACTION_COMPOSE_TAKE_PHOTO -> {
|
||||||
requestOrTakePhoto()
|
requestOrOpenCamera()
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
INTENT_ACTION_COMPOSE_PICK_IMAGE -> {
|
INTENT_ACTION_COMPOSE_PICK_IMAGE -> {
|
||||||
|
@ -1092,18 +1094,25 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
setMenu()
|
setMenu()
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun requestOrTakePhoto() {
|
private fun requestOrOpenCamera() {
|
||||||
if (checkAnySelfPermissionsGranted(AndroidPermission.WRITE_EXTERNAL_STORAGE)) {
|
if (checkAnySelfPermissionsGranted(AndroidPermission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
takePhoto()
|
openCamera()
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
ActivityCompat.requestPermissions(this, arrayOf(AndroidPermission.WRITE_EXTERNAL_STORAGE),
|
ActivityCompat.requestPermissions(this, arrayOf(AndroidPermission.WRITE_EXTERNAL_STORAGE),
|
||||||
REQUEST_TAKE_PHOTO_PERMISSION)
|
REQUEST_OPEN_CAMERA_PERMISSION)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun takePhoto(): Boolean {
|
private fun openCamera(): Boolean {
|
||||||
val intent = ThemedMediaPickerActivity.withThemed(this).takePhoto().build()
|
val builder = ThemedMediaPickerActivity.withThemed(this)
|
||||||
startActivityForResult(intent, REQUEST_TAKE_PHOTO)
|
if (intent.action == INTENT_ACTION_COMPOSE_TAKE_PHOTO) {
|
||||||
|
builder.takePhoto()
|
||||||
|
} else {
|
||||||
|
builder.pickSources(arrayOf(MediaPickerActivity.SOURCE_CAMERA, MediaPickerActivity.SOURCE_CAMCORDER))
|
||||||
|
builder.containsVideo(true)
|
||||||
|
builder.videoOnly(false)
|
||||||
|
}
|
||||||
|
startActivityForResult(builder.build(), REQUEST_TAKE_PHOTO)
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1118,10 +1127,10 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
|
|
||||||
private fun pickMedia(): Boolean {
|
private fun pickMedia(): Boolean {
|
||||||
val intent = ThemedMediaPickerActivity.withThemed(this)
|
val intent = ThemedMediaPickerActivity.withThemed(this)
|
||||||
|
.pickMedia()
|
||||||
.containsVideo(true)
|
.containsVideo(true)
|
||||||
.videoOnly(false)
|
.videoOnly(false)
|
||||||
.allowMultiple(true)
|
.allowMultiple(true)
|
||||||
.videoQuality(0) // Low quality
|
|
||||||
.build()
|
.build()
|
||||||
startActivityForResult(intent, REQUEST_PICK_MEDIA)
|
startActivityForResult(intent, REQUEST_PICK_MEDIA)
|
||||||
return true
|
return true
|
||||||
|
@ -1199,11 +1208,11 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_NONE)
|
locationSwitch.checkedPosition = LOCATION_OPTIONS.indexOf(LOCATION_VALUE_NONE)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
REQUEST_TAKE_PHOTO_PERMISSION -> {
|
REQUEST_OPEN_CAMERA_PERMISSION -> {
|
||||||
if (!checkAnySelfPermissionsGranted(AndroidPermission.WRITE_EXTERNAL_STORAGE)) {
|
if (!checkAnySelfPermissionsGranted(AndroidPermission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
Toast.makeText(this, R.string.message_compose_write_storage_permission_not_granted, Toast.LENGTH_SHORT).show()
|
Toast.makeText(this, R.string.message_compose_write_storage_permission_not_granted, Toast.LENGTH_SHORT).show()
|
||||||
}
|
}
|
||||||
takePhoto()
|
openCamera()
|
||||||
}
|
}
|
||||||
REQUEST_PICK_MEDIA_PERMISSION -> {
|
REQUEST_PICK_MEDIA_PERMISSION -> {
|
||||||
if (!checkAnySelfPermissionsGranted(AndroidPermission.WRITE_EXTERNAL_STORAGE)) {
|
if (!checkAnySelfPermissionsGranted(AndroidPermission.WRITE_EXTERNAL_STORAGE)) {
|
||||||
|
@ -1953,7 +1962,7 @@ class ComposeActivity : BaseActivity(), OnMenuItemClickListener, OnClickListener
|
||||||
|
|
||||||
private const val REQUEST_ATTACH_LOCATION_PERMISSION = 301
|
private const val REQUEST_ATTACH_LOCATION_PERMISSION = 301
|
||||||
private const val REQUEST_PICK_MEDIA_PERMISSION = 302
|
private const val REQUEST_PICK_MEDIA_PERMISSION = 302
|
||||||
private const val REQUEST_TAKE_PHOTO_PERMISSION = 303
|
private const val REQUEST_OPEN_CAMERA_PERMISSION = 303
|
||||||
|
|
||||||
internal fun getDraftAction(intentAction: String?): String {
|
internal fun getDraftAction(intentAction: String?): String {
|
||||||
if (intentAction == null) {
|
if (intentAction == null) {
|
||||||
|
|
|
@ -4,6 +4,12 @@
|
||||||
xmlns:app="http://schemas.android.com/apk/res-auto"
|
xmlns:app="http://schemas.android.com/apk/res-auto"
|
||||||
xmlns:tools="http://schemas.android.com/tools">
|
xmlns:tools="http://schemas.android.com/tools">
|
||||||
|
|
||||||
|
<item
|
||||||
|
android:id="@id/take_photo"
|
||||||
|
android:icon="@drawable/ic_action_camera"
|
||||||
|
android:title="@string/action_take_photo"
|
||||||
|
app:showAsAction="always"
|
||||||
|
tools:ignore="AlwaysShowAction"/>
|
||||||
<item
|
<item
|
||||||
android:id="@id/add_image"
|
android:id="@id/add_image"
|
||||||
android:icon="@drawable/ic_action_gallery"
|
android:icon="@drawable/ic_action_gallery"
|
||||||
|
|
Loading…
Reference in New Issue