リファクタ
This commit is contained in:
parent
a48298ffb6
commit
854d1507ec
|
@ -1158,7 +1158,7 @@ class ActAccountSetting
|
|||
}
|
||||
|
||||
val a = ActionsDialog()
|
||||
a.addAction(getString(R.string.image_pick)) {
|
||||
a.addAction(getString(R.string.pick_image)) {
|
||||
performAttachment(
|
||||
if(permission_request_code == PERMISSION_REQUEST_AVATAR)
|
||||
REQUEST_CODE_AVATAR_ATTACHMENT
|
||||
|
|
|
@ -81,6 +81,7 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
|||
private const val REQUEST_CODE_CAMERA = 2
|
||||
private const val REQUEST_CODE_MUSHROOM = 3
|
||||
private const val REQUEST_CODE_VIDEO = 4
|
||||
private const val REQUEST_CODE_ATTACHMENT_OLD = 5
|
||||
|
||||
private const val PERMISSION_REQUEST_CODE = 1
|
||||
|
||||
|
@ -294,7 +295,19 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
|||
}
|
||||
|
||||
override fun onActivityResult(requestCode : Int, resultCode : Int, data : Intent?) {
|
||||
if(requestCode == REQUEST_CODE_ATTACHMENT && resultCode == Activity.RESULT_OK) {
|
||||
if(requestCode == REQUEST_CODE_ATTACHMENT_OLD && resultCode == Activity.RESULT_OK) {
|
||||
if( data != null) {
|
||||
// 単一選択
|
||||
data.data?.let { addAttachment(it, data.type) }
|
||||
// 複数選択
|
||||
val cd = data.clipData
|
||||
if(cd != null) {
|
||||
for(i in 0 until cd.itemCount) {
|
||||
cd.getItemAt(i)?.uri?.let { addAttachment(it) }
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(requestCode == REQUEST_CODE_ATTACHMENT && resultCode == Activity.RESULT_OK) {
|
||||
if(data != null) {
|
||||
// 単一選択
|
||||
data.data?.let { addAttachment(it, data.type) }
|
||||
|
@ -1333,6 +1346,17 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
|||
}
|
||||
|
||||
private fun openAttachment() {
|
||||
|
||||
if(attachment_list.size >= 4) {
|
||||
showToast(this, false, R.string.attachment_too_many)
|
||||
return
|
||||
}
|
||||
|
||||
if(account == null) {
|
||||
showToast(this, false, R.string.account_select_please)
|
||||
return
|
||||
}
|
||||
|
||||
val permissionCheck =
|
||||
ContextCompat.checkSelfPermission(this, Manifest.permission.WRITE_EXTERNAL_STORAGE)
|
||||
if(permissionCheck != PackageManager.PERMISSION_GRANTED) {
|
||||
|
@ -1347,7 +1371,8 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
|||
// }
|
||||
|
||||
val a = ActionsDialog()
|
||||
a.addAction(getString(R.string.image_pick)) { performAttachment() }
|
||||
a.addAction(getString(R.string.pick_images_saf)) { performAttachmentSaf() }
|
||||
a.addAction(getString(R.string.pick_images_old)) { performAttachmentOld() }
|
||||
a.addAction(getString(R.string.image_capture)) { performCamera() }
|
||||
|
||||
// a.addAction( getString( R.string.video_capture ), new Runnable() {
|
||||
|
@ -1359,17 +1384,36 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
|||
|
||||
}
|
||||
|
||||
private fun performAttachment() {
|
||||
|
||||
if(attachment_list.size >= 4) {
|
||||
showToast(this, false, R.string.attachment_too_many)
|
||||
return
|
||||
private fun performAttachmentOld() {
|
||||
// SAFのIntentで開く
|
||||
try {
|
||||
val intent = Intent(Intent.ACTION_GET_CONTENT , MediaStore.Images.Media.EXTERNAL_CONTENT_URI)
|
||||
intent.addCategory( Intent.CATEGORY_OPENABLE )
|
||||
|
||||
// EXTRA_ALLOW_MULTIPLE は API 18 (4.3)以降。ACTION_GET_CONTENT でも ACTION_OPEN_DOCUMENT でも指定できる
|
||||
intent.putExtra( Intent.EXTRA_ALLOW_MULTIPLE, true );
|
||||
|
||||
// EXTRA_MIME_TYPES は API 19以降。ACTION_GET_CONTENT でも ACTION_OPEN_DOCUMENT でも指定できる
|
||||
intent.putExtra( "android.intent.extra.MIME_TYPES", arrayOf("image/*", "video/*") )
|
||||
|
||||
if( Build.VERSION.SDK_INT >= 23){
|
||||
// On Android 6.0 and above using "video/* image/" or "image/ video/*" type doesn't work
|
||||
// it only recognizes the first filter you specify.
|
||||
intent.type = "*/*"
|
||||
}else {
|
||||
intent.type = "image/* video/*"
|
||||
}
|
||||
|
||||
startActivityForResult(Intent.createChooser( intent, getString(R.string.pick_images_old) ), REQUEST_CODE_ATTACHMENT_OLD)
|
||||
} catch(ex : Throwable) {
|
||||
log.trace(ex)
|
||||
showToast(this, ex, "ACTION_GET_CONTENT failed.")
|
||||
}
|
||||
|
||||
if(account == null) {
|
||||
showToast(this, false, R.string.account_select_please)
|
||||
return
|
||||
}
|
||||
}
|
||||
private fun performAttachmentSaf() {
|
||||
|
||||
|
||||
|
||||
// SAFのIntentで開く
|
||||
try {
|
||||
|
@ -1385,7 +1429,6 @@ class ActPost : AppCompatActivity(), View.OnClickListener, PostAttachment.Callba
|
|||
}
|
||||
|
||||
}
|
||||
|
||||
internal interface InputStreamOpener {
|
||||
|
||||
val mimeType : String
|
||||
|
|
|
@ -168,7 +168,8 @@
|
|||
<string name="image">Image</string>
|
||||
<string name="image_alpha">Transparence de l\'image</string>
|
||||
<string name="image_capture">Utiliser l\'appareil photo</string>
|
||||
<string name="image_pick">Choisir une image</string>
|
||||
<string name="pick_image">Choisir une image</string>
|
||||
<string name="pick_images">Choisir une image</string>
|
||||
<string name="instance">Instance</string>
|
||||
<string name="instance_hint">Ex) mastodon.social</string>
|
||||
<string name="instance_not_need_slash">Veuillez entrer seulement le nom de l\'hôte de l\'instance, sans « / » ni « \@ ».</string>
|
||||
|
|
|
@ -350,7 +350,6 @@
|
|||
<string name="image">画像</string>
|
||||
<string name="image_alpha">画像の不透明度</string>
|
||||
<string name="image_capture">カメラで撮影</string>
|
||||
<string name="image_pick">画像を選択</string>
|
||||
<string name="in_reply_to_id_conversion_failed">アカウント切り替えできません。in_reply_toのID変換に失敗しました。</string>
|
||||
<string name="input_access_token">アクセストークンを指定する(上級者向け)</string>
|
||||
<string name="input_url_and_secret_then_test">URLとシークレットを入力してテストボタンを押してください</string>
|
||||
|
@ -508,7 +507,12 @@
|
|||
<string name="password_not_specified">パスワードを指定してください</string>
|
||||
<string name="people_talking">%1$d(%2$d)人がトゥート</string>
|
||||
<string name="performance">性能</string>
|
||||
<string name="pick_image">画像の選択</string>
|
||||
|
||||
<string name="pick_image">画像を選択</string>
|
||||
<string name="pick_images">画像を選択</string>
|
||||
<string name="pick_images_saf">画像を選択(SAF)</string>
|
||||
<string name="pick_images_old">画像を選択(旧式)</string>
|
||||
|
||||
<string name="please_add_account">アカウントがありません。事前にアカウントの追加を行ってください</string>
|
||||
<string name="please_donate">開発継続のために寄付をお願いします!</string>
|
||||
<string name="please_rate">ストアで評価やレビューをお願いします!</string>
|
||||
|
|
|
@ -224,7 +224,6 @@
|
|||
<string name="resize_image">Resize attachment image (JPEG,PNG)</string>
|
||||
<string name="dont_resize">Don\'t resize</string>
|
||||
<string name="long_side_pixel">Resize to %1$d pixels</string>
|
||||
<string name="image_pick">Pick an image</string>
|
||||
<string name="image_capture">Take a picture</string>
|
||||
<string name="missing_permission_to_access_media">Missing app permission to access media.</string>
|
||||
<string name="attachment_uploading">Media attachment is uploading…</string>
|
||||
|
@ -295,6 +294,10 @@
|
|||
<string name="color_and_background">Color and Background…</string>
|
||||
<string name="column_background">Column\'s background</string>
|
||||
<string name="pick_image">Pick an image</string>
|
||||
<string name="pick_images">Pick image(s)</string>
|
||||
<string name="pick_images_saf">Pick image… (SAF)</string>
|
||||
<string name="pick_images_old">Pick image… (old apps)</string>
|
||||
|
||||
<string name="image_alpha">Image alpha</string>
|
||||
<string name="image">Image</string>
|
||||
<string name="column_header">Column header</string>
|
||||
|
|
Loading…
Reference in New Issue