Merge remote-tracking branch 'upstream/master'
This commit is contained in:
@@ -5,6 +5,7 @@ import static org.joinmastodon.android.api.requests.statuses.CreateStatus.DRAFTS
|
|||||||
import static org.joinmastodon.android.api.requests.statuses.CreateStatus.getDraftInstant;
|
import static org.joinmastodon.android.api.requests.statuses.CreateStatus.getDraftInstant;
|
||||||
import static org.joinmastodon.android.utils.MastodonLanguage.allLanguages;
|
import static org.joinmastodon.android.utils.MastodonLanguage.allLanguages;
|
||||||
import static org.joinmastodon.android.utils.MastodonLanguage.defaultRecentLanguages;
|
import static org.joinmastodon.android.utils.MastodonLanguage.defaultRecentLanguages;
|
||||||
|
import static android.os.ext.SdkExtensions.getExtensionVersion;
|
||||||
|
|
||||||
import android.animation.ObjectAnimator;
|
import android.animation.ObjectAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
@@ -29,6 +30,7 @@ import android.net.Uri;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Parcelable;
|
import android.os.Parcelable;
|
||||||
|
import android.provider.MediaStore;
|
||||||
import android.provider.OpenableColumns;
|
import android.provider.OpenableColumns;
|
||||||
import android.text.Editable;
|
import android.text.Editable;
|
||||||
import android.text.InputFilter;
|
import android.text.InputFilter;
|
||||||
@@ -504,6 +506,8 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||||||
|
|
||||||
mainEditText.setSelectionListener(this);
|
mainEditText.setSelectionListener(this);
|
||||||
mainEditText.addTextChangedListener(new TextWatcher(){
|
mainEditText.addTextChangedListener(new TextWatcher(){
|
||||||
|
private int lastChangeStart, lastChangeCount;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void beforeTextChanged(CharSequence s, int start, int count, int after){
|
public void beforeTextChanged(CharSequence s, int start, int count, int after){
|
||||||
|
|
||||||
@@ -513,6 +517,14 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||||||
public void onTextChanged(CharSequence s, int start, int before, int count){
|
public void onTextChanged(CharSequence s, int start, int before, int count){
|
||||||
if(s.length()==0)
|
if(s.length()==0)
|
||||||
return;
|
return;
|
||||||
|
lastChangeStart=start;
|
||||||
|
lastChangeCount=count;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void afterTextChanged(Editable s){
|
||||||
|
int start=lastChangeStart;
|
||||||
|
int count=lastChangeCount;
|
||||||
// offset one char back to catch an already typed '@' or '#' or ':'
|
// offset one char back to catch an already typed '@' or '#' or ':'
|
||||||
int realStart=start;
|
int realStart=start;
|
||||||
start=Math.max(0, start-1);
|
start=Math.max(0, start-1);
|
||||||
@@ -558,10 +570,7 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||||||
editable.removeSpan(span);
|
editable.removeSpan(span);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable s){
|
|
||||||
updateCharCounter();
|
updateCharCounter();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@@ -1128,15 +1137,51 @@ public class ComposeFragment extends MastodonToolbarFragment implements OnBackPr
|
|||||||
.show();
|
.show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check to see if Android platform photopicker is available on the device\
|
||||||
|
* @return whether the device supports photopicker intents.
|
||||||
|
*/
|
||||||
|
private boolean isPhotoPickerAvailable() {
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||||
|
return true;
|
||||||
|
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
return getExtensionVersion(Build.VERSION_CODES.R) >= 2;
|
||||||
|
} else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Builds the correct intent for the device version to select media.
|
||||||
|
*
|
||||||
|
* <p>For Device version > T or R_SDK_v2, use the android platform photopicker via
|
||||||
|
* {@link MediaStore#ACTION_PICK_IMAGES}
|
||||||
|
*
|
||||||
|
* <p>For earlier versions use the built in docs ui via {@link Intent#ACTION_GET_CONTENT}
|
||||||
|
*/
|
||||||
private void openFilePicker(){
|
private void openFilePicker(){
|
||||||
Intent intent=new Intent(Intent.ACTION_GET_CONTENT);
|
Intent intent;
|
||||||
|
boolean usePhotoPicker = isPhotoPickerAvailable();
|
||||||
|
if (usePhotoPicker) {
|
||||||
|
intent = new Intent(MediaStore.ACTION_PICK_IMAGES);
|
||||||
|
intent.putExtra(MediaStore.EXTRA_PICK_IMAGES_MAX, MediaStore.getPickImagesMaxLimit());
|
||||||
|
} else {
|
||||||
|
intent = new Intent(Intent.ACTION_GET_CONTENT);
|
||||||
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
intent.addCategory(Intent.CATEGORY_OPENABLE);
|
||||||
intent.setType("*/*");
|
intent.setType("*/*");
|
||||||
if(instance.configuration!=null && instance.configuration.mediaAttachments!=null && instance.configuration.mediaAttachments.supportedMimeTypes!=null && !instance.configuration.mediaAttachments.supportedMimeTypes.isEmpty()){
|
}
|
||||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, instance.configuration.mediaAttachments.supportedMimeTypes.toArray(new String[0]));
|
if (!usePhotoPicker && instance.configuration != null &&
|
||||||
|
instance.configuration.mediaAttachments != null &&
|
||||||
|
instance.configuration.mediaAttachments.supportedMimeTypes != null &&
|
||||||
|
!instance.configuration.mediaAttachments.supportedMimeTypes.isEmpty()) {
|
||||||
|
intent.putExtra(Intent.EXTRA_MIME_TYPES,
|
||||||
|
instance.configuration.mediaAttachments.supportedMimeTypes.toArray(
|
||||||
|
new String[0]));
|
||||||
} else {
|
} else {
|
||||||
|
if (!usePhotoPicker) {
|
||||||
|
// If photo picker is being used these are the default mimetypes.
|
||||||
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*"});
|
intent.putExtra(Intent.EXTRA_MIME_TYPES, new String[]{"image/*", "video/*"});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
intent.putExtra(Intent.EXTRA_ALLOW_MULTIPLE, true);
|
||||||
startActivityForResult(intent, MEDIA_RESULT);
|
startActivityForResult(intent, MEDIA_RESULT);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user