Browse Source

Suppressed redundant color selection fix for newer devices

increased OkHttp timeouts, up libs
pull/61/merge
Ezerous 6 years ago
parent
commit
2ebff4eda8
  1. 8
      app/build.gradle
  2. 6
      app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java
  3. 221
      app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

8
app/build.gradle

@ -70,23 +70,23 @@ dependencies {
implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0' implementation 'androidx.lifecycle:lifecycle-extensions:2.0.0'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3' implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0' implementation 'com.google.android.material:material:1.0.0'
implementation 'com.google.firebase:firebase-core:16.0.5' implementation 'com.google.firebase:firebase-core:16.0.6'
implementation 'com.google.firebase:firebase-messaging:17.3.4' implementation 'com.google.firebase:firebase-messaging:17.3.4'
implementation 'com.crashlytics.sdk.android:crashlytics:2.9.6' implementation 'com.crashlytics.sdk.android:crashlytics:2.9.7'
implementation 'com.squareup.okhttp3:okhttp:3.12.0' implementation 'com.squareup.okhttp3:okhttp:3.12.0'
implementation 'com.squareup.picasso:picasso:2.5.2' implementation 'com.squareup.picasso:picasso:2.5.2'
implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' implementation 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0'
implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff! implementation 'org.jsoup:jsoup:1.10.3' //TODO: Warning: upgrading from 1.10.3 will break stuff!
implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1' implementation 'com.github.franmontiel:PersistentCookieJar:v1.0.1'
implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3' implementation 'com.github.PhilJay:MPAndroidChart:v3.0.3'
implementation "com.mikepenz:materialdrawer:6.1.1" implementation 'com.mikepenz:materialdrawer:6.1.1'
implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar'
implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar'
implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.15'
implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated! implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'//TODO: deprecated!
implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2'
implementation 'com.jakewharton.timber:timber:4.7.1' implementation 'com.jakewharton.timber:timber:4.7.1'
implementation "ru.noties:markwon:2.0.0" implementation 'ru.noties:markwon:2.0.0'
implementation 'net.gotev:uploadservice:3.4.2' implementation 'net.gotev:uploadservice:3.4.2'
implementation 'net.gotev:uploadservice-okhttp:3.4.2' implementation 'net.gotev:uploadservice-okhttp:3.4.2'
debugImplementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler debugImplementation 'com.itkacher.okhttpprofiler:okhttpprofiler:1.0.4' //Plugin: https://plugins.jetbrains.com/plugin/11249-okhttp-profiler

6
app/src/main/java/gr/thmmy/mthmmy/base/BaseApplication.java

@ -110,9 +110,9 @@ public class BaseApplication extends Application {
} }
return chain.proceed(request); return chain.proceed(request);
}) })
.connectTimeout(30, TimeUnit.SECONDS) .connectTimeout(40, TimeUnit.SECONDS)
.writeTimeout(30, TimeUnit.SECONDS) .writeTimeout(40, TimeUnit.SECONDS)
.readTimeout(30, TimeUnit.SECONDS); .readTimeout(40, TimeUnit.SECONDS);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { // Just for KitKats
// Necessary because our servers don't have the right cipher suites. // Necessary because our servers don't have the right cipher suites.

221
app/src/main/java/gr/thmmy/mthmmy/editorview/EditorView.java

@ -8,6 +8,7 @@ import android.content.Context;
import android.content.res.TypedArray; import android.content.res.TypedArray;
import android.graphics.drawable.Drawable; import android.graphics.drawable.Drawable;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.text.Editable; import android.text.Editable;
import android.text.TextUtils; import android.text.TextUtils;
import android.util.AttributeSet; import android.util.AttributeSet;
@ -126,58 +127,79 @@ public class EditorView extends LinearLayout implements EmojiInputField {
getResources().getDimension(R.dimen.editor_format_button_margin_between); getResources().getDimension(R.dimen.editor_format_button_margin_between);
int columns = (int) Math.floor(displayMetrics.widthPixels / itemWidth); int columns = (int) Math.floor(displayMetrics.widthPixels / itemWidth);
formatButtonsRecyclerview.setLayoutManager(new GridLayoutManager(context, columns)); formatButtonsRecyclerview.setLayoutManager(new GridLayoutManager(context, columns));
formatButtonsRecyclerview.setAdapter(new FormatButtonsAdapter((view, drawableId) -> { formatButtonsRecyclerview.setAdapter(
new FormatButtonsAdapter(
(view, drawableId) -> {
boolean hadTextSelection;
switch (drawableId) { switch (drawableId) {
case R.drawable.ic_format_bold: { case R.drawable.ic_format_bold:
boolean hadTextSelection = editText.hasSelection(); hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[b]"); getText().insert(editText.getSelectionStart(), "[b]");
getText().insert(editText.getSelectionEnd(), "[/b]"); getText().insert(editText.getSelectionEnd(), "[/b]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 4);
break; break;
} case R.drawable.ic_format_italic:
case R.drawable.ic_format_italic: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[i]"); getText().insert(editText.getSelectionStart(), "[i]");
getText().insert(editText.getSelectionEnd(), "[/i]"); getText().insert(editText.getSelectionEnd(), "[/i]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 4);
break; break;
} case R.drawable.ic_format_underlined:
case R.drawable.ic_format_underlined: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[u]"); getText().insert(editText.getSelectionStart(), "[u]");
getText().insert(editText.getSelectionEnd(), "[/u]"); getText().insert(editText.getSelectionEnd(), "[/u]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 4);
break; break;
} case R.drawable.ic_strikethrough_s:
case R.drawable.ic_strikethrough_s: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[s]"); getText().insert(editText.getSelectionStart(), "[s]");
getText().insert(editText.getSelectionEnd(), "[/s]"); getText().insert(editText.getSelectionEnd(), "[/s]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 4); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 4);
break; break;
} case R.drawable.ic_format_color_text:
case R.drawable.ic_format_color_text: {
boolean hadTextSelection = editText.hasSelection();
int selectionStart = editText.getSelectionStart(); int selectionStart = editText.getSelectionStart();
int selectionEnd = editText.getSelectionEnd(); int selectionEnd = editText.getSelectionEnd();
PopupWindow popupWindow = new PopupWindow(view.getContext()); PopupWindow popupWindow = new PopupWindow(view.getContext());
popupWindow.setHeight(LayoutParams.WRAP_CONTENT); popupWindow.setHeight(LayoutParams.WRAP_CONTENT);
popupWindow.setWidth(LayoutParams.WRAP_CONTENT); popupWindow.setWidth(LayoutParams.WRAP_CONTENT);
popupWindow.setFocusable(true); popupWindow.setFocusable(true);
ScrollView colorPickerScrollview = (ScrollView) LayoutInflater.from(context).inflate(R.layout.editor_view_color_picker, null); ScrollView colorPickerScrollview =
(ScrollView)
LayoutInflater.from(context)
.inflate(R.layout.editor_view_color_picker, null);
LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0); LinearLayout colorPicker = (LinearLayout) colorPickerScrollview.getChildAt(0);
popupWindow.setContentView(colorPickerScrollview); popupWindow.setContentView(colorPickerScrollview);
for (int i = 0; i < colorPicker.getChildCount(); i++) { for (int i = 0; i < colorPicker.getChildCount(); i++) {
TextView child = (TextView) colorPicker.getChildAt(i); TextView child = (TextView) colorPicker.getChildAt(i);
child.setOnClickListener(v -> { child.setOnClickListener(
v -> {
boolean hadTextSelection2 = editText.hasSelection(); boolean hadTextSelection2 = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[color=" + colors.get(v.getId()) + "]"); getText()
.insert(
editText.getSelectionStart(),
"[color=" + colors.get(v.getId()) + "]");
getText().insert(editText.getSelectionEnd(), "[/color]"); getText().insert(editText.getSelectionEnd(), "[/color]");
editText.setSelection(hadTextSelection2 ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); editText.setSelection(
hadTextSelection2
? editText.getSelectionEnd()
: editText.getSelectionStart() - 8);
popupWindow.dismiss(); popupWindow.dismiss();
}); });
} }
popupWindow.showAsDropDown(view); popupWindow.showAsDropDown(view);
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
new AsyncTask<Void, Void, Void>() { new AsyncTask<Void, Void, Void>() {
@Override @Override
protected Void doInBackground(Void... voids) { protected Void doInBackground(Void... voids) {
@ -194,114 +216,153 @@ public class EditorView extends LinearLayout implements EmojiInputField {
editText.setSelection(selectionStart, selectionEnd); editText.setSelection(selectionStart, selectionEnd);
} }
}.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); }.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
break;
} }
case R.drawable.ic_format_size: { break;
boolean hadTextSelection = editText.hasSelection(); case R.drawable.ic_format_size:
hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[size=10pt]"); getText().insert(editText.getSelectionStart(), "[size=10pt]");
getText().insert(editText.getSelectionEnd(), "[/size]"); getText().insert(editText.getSelectionEnd(), "[/size]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 7);
break; break;
} case R.drawable.ic_text_format:
case R.drawable.ic_text_format: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[font=Verdana]"); getText().insert(editText.getSelectionStart(), "[font=Verdana]");
getText().insert(editText.getSelectionEnd(), "[/font]"); getText().insert(editText.getSelectionEnd(), "[/font]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 7);
break; break;
} case R.drawable.ic_format_list_bulleted:
case R.drawable.ic_format_list_bulleted: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[list]\n[li]"); getText().insert(editText.getSelectionStart(), "[list]\n[li]");
getText().insert(editText.getSelectionEnd(), "[/li]\n[li][/li]\n[/list]"); getText().insert(editText.getSelectionEnd(), "[/li]\n[li][/li]\n[/list]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() - 13 : editText.getSelectionStart() - 23); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd() - 13
: editText.getSelectionStart() - 23);
break; break;
} case R.drawable.ic_format_align_left:
case R.drawable.ic_format_align_left: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[left]"); getText().insert(editText.getSelectionStart(), "[left]");
getText().insert(editText.getSelectionEnd(), "[/left]"); getText().insert(editText.getSelectionEnd(), "[/left]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 7);
break; break;
} case R.drawable.ic_format_align_center:
case R.drawable.ic_format_align_center: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[center]"); getText().insert(editText.getSelectionStart(), "[center]");
getText().insert(editText.getSelectionEnd(), "[/center]"); getText().insert(editText.getSelectionEnd(), "[/center]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 9); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 9);
break; break;
} case R.drawable.ic_format_align_right:
case R.drawable.ic_format_align_right: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[right]"); getText().insert(editText.getSelectionStart(), "[right]");
getText().insert(editText.getSelectionEnd(), "[/right]"); getText().insert(editText.getSelectionEnd(), "[/right]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 8);
break; break;
} case R.drawable.ic_insert_link:
case R.drawable.ic_insert_link: { LinearLayout dialogBody =
LinearLayout dialogBody = (LinearLayout) LayoutInflater.from(context) (LinearLayout)
.inflate(R.layout.dialog_create_link, null); LayoutInflater.from(context).inflate(R.layout.dialog_create_link, null);
TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input); TextInputLayout linkUrl = dialogBody.findViewById(R.id.link_url_input);
linkUrl.setOnClickListener(view1 -> linkUrl.setError(null)); linkUrl.setOnClickListener(view1 -> linkUrl.setError(null));
TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input); TextInputLayout linkText = dialogBody.findViewById(R.id.link_text_input);
linkText.setOnClickListener(view2 -> linkText.setError(null)); linkText.setOnClickListener(view2 -> linkText.setError(null));
boolean hadTextSelection = editText.hasSelection(); hadTextSelection = editText.hasSelection();
int start = editText.getSelectionStart(), end = editText.getSelectionEnd(); int start = editText.getSelectionStart(), end = editText.getSelectionEnd();
if (editText.hasSelection()) { if (editText.hasSelection()) {
linkText.getEditText().setText( linkText
editText.getText().toString().substring(editText.getSelectionStart(), editText.getSelectionEnd())); .getEditText()
} .setText(
AlertDialog linkDialog = new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog) editText
.getText()
.toString()
.substring(
editText.getSelectionStart(), editText.getSelectionEnd()));
}
AlertDialog linkDialog =
new AlertDialog.Builder(context, R.style.AppTheme_Dark_Dialog)
.setTitle(R.string.dialog_create_link_title) .setTitle(R.string.dialog_create_link_title)
.setView(dialogBody) .setView(dialogBody)
.setPositiveButton(R.string.ok, null) .setPositiveButton(R.string.ok, null)
.setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss()) .setNegativeButton(R.string.cancel, (dialog, which) -> dialog.dismiss())
.create(); .create();
linkDialog.setOnShowListener(dialogInterface -> { linkDialog.setOnShowListener(
dialogInterface -> {
Button button = linkDialog.getButton(AlertDialog.BUTTON_POSITIVE); Button button = linkDialog.getButton(AlertDialog.BUTTON_POSITIVE);
button.setOnClickListener(view12 -> { button.setOnClickListener(
if (TextUtils.isEmpty(Objects.requireNonNull(linkUrl.getEditText()).getText().toString())) { view12 -> {
if (TextUtils.isEmpty(
Objects.requireNonNull(linkUrl.getEditText())
.getText()
.toString())) {
linkUrl.setError(context.getString(R.string.input_field_required)); linkUrl.setError(context.getString(R.string.input_field_required));
return; return;
} }
if (hadTextSelection) editText.getText().delete(start, end); if (hadTextSelection) editText.getText().delete(start, end);
if (!TextUtils.isEmpty(linkText.getEditText().getText())) { if (!TextUtils.isEmpty(linkText.getEditText().getText())) {
getText().insert(editText.getSelectionStart(), "[url=" + getText()
linkUrl.getEditText().getText().toString() + "]" + .insert(
linkText.getEditText().getText().toString() + "[/url]"); editText.getSelectionStart(),
} "[url="
else + linkUrl.getEditText().getText().toString()
getText().insert(editText.getSelectionStart(), "[url]" + + "]"
linkUrl.getEditText().getText().toString() + "[/url]"); + linkText.getEditText().getText().toString()
+ "[/url]");
} else
getText()
.insert(
editText.getSelectionStart(),
"[url]"
+ linkUrl.getEditText().getText().toString()
+ "[/url]");
linkDialog.dismiss(); linkDialog.dismiss();
}); });
}); });
linkDialog.show(); linkDialog.show();
break; break;
} case R.drawable.ic_format_quote:
case R.drawable.ic_format_quote: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[quote]"); getText().insert(editText.getSelectionStart(), "[quote]");
getText().insert(editText.getSelectionEnd(), "[/quote]"); getText().insert(editText.getSelectionEnd(), "[/quote]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 8); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 8);
break; break;
} case R.drawable.ic_code:
case R.drawable.ic_code: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[code]"); getText().insert(editText.getSelectionStart(), "[code]");
getText().insert(editText.getSelectionEnd(), "[/code]"); getText().insert(editText.getSelectionEnd(), "[/code]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 7); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 7);
break; break;
} case R.drawable.ic_functions:
case R.drawable.ic_functions: { hadTextSelection = editText.hasSelection();
boolean hadTextSelection = editText.hasSelection();
getText().insert(editText.getSelectionStart(), "[tex]"); getText().insert(editText.getSelectionStart(), "[tex]");
getText().insert(editText.getSelectionEnd(), "[/tex]"); getText().insert(editText.getSelectionEnd(), "[/tex]");
editText.setSelection(hadTextSelection ? editText.getSelectionEnd() : editText.getSelectionStart() - 6); editText.setSelection(
hadTextSelection
? editText.getSelectionEnd()
: editText.getSelectionStart() - 6);
break; break;
} default:
default: throw new IllegalArgumentException("Unknown format button click"); throw new IllegalArgumentException("Unknown format button click");
} }
})); }));

Loading…
Cancel
Save