Gif support for keyboard + bug fix
This commit is contained in:
parent
fd6028eaf9
commit
7f656e1ec1
|
@ -1,5 +1,5 @@
|
||||||
Changed:
|
Added:
|
||||||
|
- Gif support for some keyboards.
|
||||||
|
|
||||||
Fixed:
|
Fixed:
|
||||||
- Crash when Youtube videos in timelines
|
- Crash when Youtube videos in timelines
|
||||||
|
|
|
@ -805,6 +805,35 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
poll_action = findViewById(R.id.poll_action);
|
poll_action = findViewById(R.id.poll_action);
|
||||||
|
|
||||||
|
|
||||||
|
toot_content.setKeyBoardInputCallbackListener((inputContentInfo, flags, opts) -> {
|
||||||
|
SharedPreferences sharedpreferences1 = getSharedPreferences(Helper.APP_PREFS, MODE_PRIVATE);
|
||||||
|
boolean photo_editor = sharedpreferences1.getBoolean(Helper.SET_PHOTO_EDITOR, true);
|
||||||
|
|
||||||
|
if( inputContentInfo != null ) {
|
||||||
|
Uri uri = inputContentInfo.getContentUri();
|
||||||
|
String filename = Helper.getFileName(TootActivity.this, uri);
|
||||||
|
ContentResolver cr = getContentResolver();
|
||||||
|
String mime = cr.getType(uri);
|
||||||
|
if (mime != null && (mime.toLowerCase().contains("video") || mime.toLowerCase().contains("gif"))) {
|
||||||
|
prepareUpload(TootActivity.this, uri, filename, uploadReceiver);
|
||||||
|
} else if (mime != null && mime.toLowerCase().contains("image")) {
|
||||||
|
if (photo_editor) {
|
||||||
|
Intent intent = new Intent(TootActivity.this, PhotoEditorActivity.class);
|
||||||
|
Bundle b = new Bundle();
|
||||||
|
intent.putExtra("imageUri", uri.toString());
|
||||||
|
intent.putExtras(b);
|
||||||
|
startActivity(intent);
|
||||||
|
} else {
|
||||||
|
prepareUpload(TootActivity.this, uri, filename, uploadReceiver);
|
||||||
|
}
|
||||||
|
} else if (mime != null && mime.toLowerCase().contains("audio")) {
|
||||||
|
prepareUpload(TootActivity.this, uri, filename, uploadReceiver);
|
||||||
|
} else {
|
||||||
|
Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(TootActivity.this);
|
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(TootActivity.this);
|
||||||
int iconColor = prefs.getInt("theme_icons_color", -1);
|
int iconColor = prefs.getInt("theme_icons_color", -1);
|
||||||
if (iconColor != -1) {
|
if (iconColor != -1) {
|
||||||
|
@ -1513,6 +1542,7 @@ public class TootActivity extends BaseActivity implements UploadStatusDelegate,
|
||||||
Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
Toasty.error(TootActivity.this, getString(R.string.toot_select_image_error), Toast.LENGTH_LONG).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clipData != null) {
|
if (clipData != null) {
|
||||||
ArrayList<Uri> mArrayUri = new ArrayList<>();
|
ArrayList<Uri> mArrayUri = new ArrayList<>();
|
||||||
for (int i = 0; i < clipData.getItemCount(); i++) {
|
for (int i = 0; i < clipData.getItemCount(); i++) {
|
||||||
|
|
|
@ -5,12 +5,19 @@ import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.res.TypedArray;
|
import android.content.res.TypedArray;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
|
import android.os.Bundle;
|
||||||
import android.util.AttributeSet;
|
import android.util.AttributeSet;
|
||||||
import android.view.KeyEvent;
|
import android.view.KeyEvent;
|
||||||
|
import android.view.inputmethod.EditorInfo;
|
||||||
|
import android.view.inputmethod.InputConnection;
|
||||||
|
|
||||||
import androidx.annotation.CallSuper;
|
import androidx.annotation.CallSuper;
|
||||||
import androidx.annotation.DimenRes;
|
import androidx.annotation.DimenRes;
|
||||||
import androidx.annotation.Px;
|
import androidx.annotation.Px;
|
||||||
|
import androidx.core.os.BuildCompat;
|
||||||
|
import androidx.core.view.inputmethod.EditorInfoCompat;
|
||||||
|
import androidx.core.view.inputmethod.InputConnectionCompat;
|
||||||
|
import androidx.core.view.inputmethod.InputContentInfoCompat;
|
||||||
|
|
||||||
import com.vanniktech.emoji.EmojiManager;
|
import com.vanniktech.emoji.EmojiManager;
|
||||||
import com.vanniktech.emoji.emoji.Emoji;
|
import com.vanniktech.emoji.emoji.Emoji;
|
||||||
|
@ -26,6 +33,7 @@ public class MastalabAutoCompleteTextView extends androidx.appcompat.widget.AppC
|
||||||
|
|
||||||
public MastalabAutoCompleteTextView(Context context) {
|
public MastalabAutoCompleteTextView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MastalabAutoCompleteTextView(Context context, AttributeSet attrs) {
|
public MastalabAutoCompleteTextView(Context context, AttributeSet attrs) {
|
||||||
|
@ -48,12 +56,82 @@ public class MastalabAutoCompleteTextView extends androidx.appcompat.widget.AppC
|
||||||
}
|
}
|
||||||
|
|
||||||
setText(getText());
|
setText(getText());
|
||||||
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
public MastalabAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
public MastalabAutoCompleteTextView(Context context, AttributeSet attrs, int defStyleAttr) {
|
||||||
super(context, attrs, defStyleAttr);
|
super(context, attrs, defStyleAttr);
|
||||||
|
initView();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private String[] imgTypeString;
|
||||||
|
private KeyBoardInputCallbackListener keyBoardInputCallbackListener;
|
||||||
|
@Override
|
||||||
|
public InputConnection onCreateInputConnection(EditorInfo outAttrs) {
|
||||||
|
final InputConnection ic = super.onCreateInputConnection(outAttrs);
|
||||||
|
EditorInfoCompat.setContentMimeTypes(outAttrs,
|
||||||
|
imgTypeString);
|
||||||
|
return InputConnectionCompat.createWrapper(ic, outAttrs, callback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initView() {
|
||||||
|
imgTypeString = new String[]{"image/png",
|
||||||
|
"image/gif",
|
||||||
|
"image/jpeg",
|
||||||
|
"image/webp"};
|
||||||
|
}
|
||||||
|
final InputConnectionCompat.OnCommitContentListener callback =
|
||||||
|
new InputConnectionCompat.OnCommitContentListener() {
|
||||||
|
@Override
|
||||||
|
public boolean onCommitContent(InputContentInfoCompat inputContentInfo,
|
||||||
|
int flags, Bundle opts) {
|
||||||
|
|
||||||
|
// read and display inputContentInfo asynchronously
|
||||||
|
if (BuildCompat.isAtLeastNMR1() && (flags &
|
||||||
|
InputConnectionCompat.INPUT_CONTENT_GRANT_READ_URI_PERMISSION) != 0) {
|
||||||
|
try {
|
||||||
|
inputContentInfo.requestPermission();
|
||||||
|
} catch (Exception e) {
|
||||||
|
return false; // return false if failed
|
||||||
|
}
|
||||||
|
}
|
||||||
|
boolean supported = false;
|
||||||
|
for (final String mimeType : imgTypeString) {
|
||||||
|
if (inputContentInfo.getDescription().hasMimeType(mimeType)) {
|
||||||
|
supported = true;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!supported) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (keyBoardInputCallbackListener != null) {
|
||||||
|
keyBoardInputCallbackListener.onCommitContent(inputContentInfo, flags, opts);
|
||||||
|
}
|
||||||
|
return true; // return true if succeeded
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
public interface KeyBoardInputCallbackListener {
|
||||||
|
void onCommitContent(InputContentInfoCompat inputContentInfo,
|
||||||
|
int flags, Bundle opts);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setKeyBoardInputCallbackListener(KeyBoardInputCallbackListener keyBoardInputCallbackListener) {
|
||||||
|
this.keyBoardInputCallbackListener = keyBoardInputCallbackListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getImgTypeString() {
|
||||||
|
return imgTypeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImgTypeString(String[] imgTypeString) {
|
||||||
|
this.imgTypeString = imgTypeString;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@CallSuper
|
@CallSuper
|
||||||
protected void onTextChanged(final CharSequence text, final int start, final int lengthBefore, final int lengthAfter) {
|
protected void onTextChanged(final CharSequence text, final int start, final int lengthBefore, final int lengthAfter) {
|
||||||
|
|
|
@ -104,24 +104,24 @@ public class TimelineCacheDAO {
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Remove stored status
|
* Remove stored status
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
public int removeAfterDate(String date) {
|
public void removeAfterDate(String date) {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
String instance = Helper.getLiveInstance(context);
|
String instance = Helper.getLiveInstance(context);
|
||||||
return db.delete(Sqlite.TABLE_TIMELINE_CACHE, Sqlite.COL_DATE + " < \"" + date + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\"", null);
|
try {
|
||||||
|
db.delete(Sqlite.TABLE_TIMELINE_CACHE, Sqlite.COL_DATE + " < \"" + date + "\" AND " + Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\"", null);
|
||||||
|
}catch (Exception ignored){}
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* Remove stored status
|
* Remove stored status
|
||||||
* @return int
|
|
||||||
*/
|
*/
|
||||||
public int removeAllConnected() {
|
public void removeAllConnected() {
|
||||||
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
SharedPreferences sharedpreferences = context.getSharedPreferences(Helper.APP_PREFS, Context.MODE_PRIVATE);
|
||||||
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
String userId = sharedpreferences.getString(Helper.PREF_KEY_ID, null);
|
||||||
String instance = Helper.getLiveInstance(context);
|
String instance = Helper.getLiveInstance(context);
|
||||||
return db.delete(Sqlite.TABLE_TIMELINE_CACHE, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\"", null);
|
db.delete(Sqlite.TABLE_TIMELINE_CACHE, Sqlite.COL_INSTANCE + " = \"" + instance + "\" AND " + Sqlite.COL_USER_ID + " = \"" + userId + "\"", null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue