From dba34c99994371d4f2a8a7ae25fe9a054e0aeb6d Mon Sep 17 00:00:00 2001 From: irshad Date: Thu, 29 Nov 2018 14:30:51 +0800 Subject: [PATCH] fix the wrong order bug on renderer view, make links clickable --- .idea/misc.xml | 2 +- laser-native-editor/laser-native-editor.iml | 8 +---- .../irshulx/Components/ImageExtensions.java | 29 ++++++++++++++----- .../irshulx/Components/InputExtensions.java | 3 ++ .../Components/ListItemExtensions.java | 4 ++- .../main/java/com/github/irshulx/Editor.java | 2 +- .../java/com/github/irshulx/EditorCore.java | 19 ++++++++++-- .../irshulx/wysiwyg/EditorTestActivity.java | 17 ++++++++++- .../irshulx/wysiwyg/RenderTestActivity.java | 4 +-- .../src/main/res/layout/fragment_preview.xml | 27 ----------------- 10 files changed, 64 insertions(+), 51 deletions(-) diff --git a/.idea/misc.xml b/.idea/misc.xml index 26dc4f5..80c79a1 100644 --- a/.idea/misc.xml +++ b/.idea/misc.xml @@ -25,5 +25,5 @@ - + \ No newline at end of file diff --git a/laser-native-editor/laser-native-editor.iml b/laser-native-editor/laser-native-editor.iml index 2da0ae8..f1754fc 100644 --- a/laser-native-editor/laser-native-editor.iml +++ b/laser-native-editor/laser-native-editor.iml @@ -85,31 +85,25 @@ - - - - - + - - diff --git a/laser-native-editor/src/main/java/com/github/irshulx/Components/ImageExtensions.java b/laser-native-editor/src/main/java/com/github/irshulx/Components/ImageExtensions.java index 0ee6433..dfb692f 100644 --- a/laser-native-editor/src/main/java/com/github/irshulx/Components/ImageExtensions.java +++ b/laser-native-editor/src/main/java/com/github/irshulx/Components/ImageExtensions.java @@ -23,6 +23,7 @@ import android.graphics.Rect; import android.os.AsyncTask; import android.text.TextUtils; +import android.text.util.Linkify; import android.util.Log; import android.view.MotionEvent; import android.view.View; @@ -72,7 +73,7 @@ public void openImageGallery() { ((Activity) editorCore.getContext()).startActivityForResult(Intent.createChooser(intent, "Select an image"), editorCore.PICK_IMAGE_REQUEST); } - public void insertImage(Bitmap image, String url, int index, String subTitle) { + public void insertImage(Bitmap image, String url, int index, String subTitle, boolean appendTextline) { boolean hasUploaded = false; if(!TextUtils.isEmpty(url)) hasUploaded = true; @@ -81,7 +82,11 @@ public void insertImage(Bitmap image, String url, int index, String subTitle) { ImageView imageView = (ImageView) childLayout.findViewById(R.id.imageView); final TextView lblStatus = (TextView) childLayout.findViewById(R.id.lblStatus); CustomEditText desc = (CustomEditText)childLayout.findViewById(R.id.desc); - imageView.setImageBitmap(image); + if(!TextUtils.isEmpty(url)){ + Picasso.with(editorCore.getContext()).load(url).into(imageView); + }else { + imageView.setImageBitmap(image); + } final String uuid = generateUUID(); if (index == -1) { index = editorCore.determineIndex(EditorType.img); @@ -90,12 +95,14 @@ public void insertImage(Bitmap image, String url, int index, String subTitle) { editorCore.getParentView().addView(childLayout, index); // _Views.add(childLayout); - if (editorCore.isLastRow(childLayout)) { - editorCore.getInputExtensions().insertEditText(index + 1, null, null); - } + EditorControl control = editorCore.createTag(EditorType.img); control.path = hasUploaded ? url : uuid; // set the imageId,so we can recognize later after upload childLayout.setTag(control); + + if (editorCore.isLastRow(childLayout) && appendTextline) { + editorCore.getInputExtensions().insertEditText(index + 1, null, null); + } if(!TextUtils.isEmpty(subTitle)) desc.setText(subTitle); if(editorCore.getRenderType()== RenderType.Editor) { @@ -118,6 +125,7 @@ private void showNextInputHint(int index) { return; TextView tv = (TextView) view; tv.setHint(editorCore.placeHolder); + Linkify.addLinks(tv,Linkify.ALL); } private void hideInputHint(int index) { @@ -150,8 +158,13 @@ public String generateUUID() { */ public void loadImage(String _path, String desc) { final View childLayout = ((Activity) editorCore.getContext()).getLayoutInflater().inflate(this.editorImageLayout, null); - ImageView imageView = (ImageView) childLayout.findViewById(R.id.imageView); - CustomEditText text = (CustomEditText) childLayout.findViewById(R.id.desc); + ImageView imageView = childLayout.findViewById(R.id.imageView); + CustomEditText text = childLayout.findViewById(R.id.desc); + + EditorControl control = editorCore.createTag(EditorType.img); + control.path = _path; + childLayout.setTag(control); + if (TextUtils.isEmpty(desc)) { text.setVisibility(View.GONE); } else { @@ -222,7 +235,7 @@ protected Bitmap doInBackground(String... urls) { return mIcon11; } protected void onPostExecute(Bitmap result) { - insertImage(result, url, this.InsertIndex,subTitle); + insertImage(result, url, this.InsertIndex,subTitle, true); } } diff --git a/laser-native-editor/src/main/java/com/github/irshulx/Components/InputExtensions.java b/laser-native-editor/src/main/java/com/github/irshulx/Components/InputExtensions.java index 9728b94..8ba8022 100644 --- a/laser-native-editor/src/main/java/com/github/irshulx/Components/InputExtensions.java +++ b/laser-native-editor/src/main/java/com/github/irshulx/Components/InputExtensions.java @@ -29,6 +29,8 @@ import android.text.Spanned; import android.text.TextUtils; import android.text.TextWatcher; +import android.text.method.LinkMovementMethod; +import android.text.util.Linkify; import android.util.Log; import android.util.TypedValue; import android.view.KeyEvent; @@ -176,6 +178,7 @@ private TextView getNewTextView(CharSequence text) { Spanned __ = Html.fromHtml(text.toString()); CharSequence toReplace = noTrailingwhiteLines(__); textView.setText(toReplace); + Linkify.addLinks(textView,Linkify.ALL); } return textView; } diff --git a/laser-native-editor/src/main/java/com/github/irshulx/Components/ListItemExtensions.java b/laser-native-editor/src/main/java/com/github/irshulx/Components/ListItemExtensions.java index 5fee40a..7fb2f9d 100644 --- a/laser-native-editor/src/main/java/com/github/irshulx/Components/ListItemExtensions.java +++ b/laser-native-editor/src/main/java/com/github/irshulx/Components/ListItemExtensions.java @@ -26,6 +26,7 @@ import android.text.Spanned; import android.text.TextUtils; import android.text.TextWatcher; +import android.text.util.Linkify; import android.util.TypedValue; import android.view.KeyEvent; import android.view.View; @@ -185,7 +186,7 @@ public void run() { } }, 0); } else { - final TextView textView = (TextView) childLayout.findViewById(R.id.lblText); + final TextView textView = childLayout.findViewById(R.id.lblText); textView.setTypeface(editorCore.getInputExtensions().getTypeface(CONTENT, Typeface.NORMAL)); /* @@ -196,6 +197,7 @@ public void run() { } textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, editorCore.getInputExtensions().getNormalTextSize()); textView.setVisibility(View.VISIBLE); + Linkify.addLinks(textView,Linkify.ALL); editText.setVisibility(View.GONE); } layout.addView(childLayout); diff --git a/laser-native-editor/src/main/java/com/github/irshulx/Editor.java b/laser-native-editor/src/main/java/com/github/irshulx/Editor.java index fdfab73..d7814d0 100644 --- a/laser-native-editor/src/main/java/com/github/irshulx/Editor.java +++ b/laser-native-editor/src/main/java/com/github/irshulx/Editor.java @@ -264,7 +264,7 @@ public void openImagePicker() { } public void insertImage(Bitmap bitmap) { - getImageExtensions().insertImage(bitmap,null, -1,null); + getImageExtensions().insertImage(bitmap,null, -1,null, true); } public void onImageUploadComplete(String url, String imageId) { diff --git a/laser-native-editor/src/main/java/com/github/irshulx/EditorCore.java b/laser-native-editor/src/main/java/com/github/irshulx/EditorCore.java index ecf5c16..447fda3 100644 --- a/laser-native-editor/src/main/java/com/github/irshulx/EditorCore.java +++ b/laser-native-editor/src/main/java/com/github/irshulx/EditorCore.java @@ -16,7 +16,9 @@ import android.view.KeyEvent; import android.view.View; import android.widget.EditText; +import android.widget.ImageView; import android.widget.LinearLayout; +import android.widget.RelativeLayout; import android.widget.TableLayout; import android.widget.TextView; import android.widget.Toast; @@ -258,7 +260,7 @@ public int determineIndex(EditorType type) { return currentIndex; } } else if (tag == EditorType.UL_LI || tag == EditorType.OL_LI) { - EditText _text = (EditText) _view.findViewById(R.id.txtText); + EditText _text = _view.findViewById(R.id.txtText); if (_text.getText().length() > 0) { } @@ -298,6 +300,13 @@ public EditorControl updateTagStyle(EditorControl controlTag, EditorTextStyle st public EditorType getControlType(View _view) { if (_view == null) return null; + + if(_view instanceof RelativeLayout){ + ImageView imageView = _view.findViewById(R.id.imageView); + if(imageView != null){ + Log.e(TAG, "imageview this is"); + } + } EditorControl _control = (EditorControl) _view.getTag(); return _control.Type; } @@ -513,7 +522,7 @@ public void renderEditor(EditorContent _state) { switch (item.type) { case INPUT: String text = item.content.get(0); - TextView view = __inputExtensions.insertEditText(0, this.placeHolder, text); + TextView view = __inputExtensions.insertEditText(getChildCount(), this.placeHolder, text); if (item.contentStyles != null) { for (EditorTextStyle style : item.contentStyles) { __inputExtensions.UpdateTextStyle(style, view); @@ -530,7 +539,11 @@ public void renderEditor(EditorContent _state) { case img: String path = item.content.get(0); String desc = item.content.get(1); - __imageExtensions.loadImage(path, desc); + if(getRenderType() == RenderType.Renderer) { + __imageExtensions.loadImage(path, desc); + }else{ + __imageExtensions.insertImage(null,path,getChildCount(),desc, false); + } break; case ul: case ol: diff --git a/sample/src/main/java/com/github/irshulx/wysiwyg/EditorTestActivity.java b/sample/src/main/java/com/github/irshulx/wysiwyg/EditorTestActivity.java index 3aaf310..056b097 100644 --- a/sample/src/main/java/com/github/irshulx/wysiwyg/EditorTestActivity.java +++ b/sample/src/main/java/com/github/irshulx/wysiwyg/EditorTestActivity.java @@ -20,6 +20,7 @@ import com.github.irshulx.Editor; import com.github.irshulx.EditorListener; +import com.github.irshulx.models.EditorContent; import com.github.irshulx.models.EditorTextStyle; import java.io.IOException; @@ -197,7 +198,21 @@ public void onUpload(Bitmap image, String uuid) { // editor.onImageUploadFailed(uuid); } }); - render(); + + String serialized = "{\"nodes\":[{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eline 1 next is image 1\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"http://www.videogamesblogger.com/wp-content/uploads/2015/08/metal-gear-solid-5-the-phantom-pain-cheats-640x325.jpg\",\"image 1 caption\"],\"type\":\"img\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003etext line 2 next is image 2\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"http://www.videogamesblogger.com/wp-content/uploads/2015/08/metal-gear-solid-5-the-phantom-pain-cheats-640x325.jpg\",\"image 2 caption\"],\"type\":\"img\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003etext line 3\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"}]}"; + + //String serialized = "{\"nodes\":[{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eline 1\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eline 2\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"},{\"content\":[\"\\u003cp dir\\u003d\\\"ltr\\\"\\u003eline 3\\u003c/p\\u003e\\n\"],\"contentStyles\":[],\"textSettings\":{\"textColor\":\"#000000\"},\"type\":\"INPUT\"}]}"; + + EditorContent des = editor.getContentDeserialized(serialized); + editor.render(des); + + +// Intent intent = new Intent(getApplicationContext(), RenderTestActivity.class); +// intent.putExtra("content", serialized); +// startActivity(intent); + + + //render(); //editor.render(); // this method must be called to start the editor //editor.render("

Hello man, whats up!

"); diff --git a/sample/src/main/java/com/github/irshulx/wysiwyg/RenderTestActivity.java b/sample/src/main/java/com/github/irshulx/wysiwyg/RenderTestActivity.java index 290f469..fe110a1 100644 --- a/sample/src/main/java/com/github/irshulx/wysiwyg/RenderTestActivity.java +++ b/sample/src/main/java/com/github/irshulx/wysiwyg/RenderTestActivity.java @@ -14,10 +14,10 @@ public class RenderTestActivity extends AppCompatActivity { protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_render_test); - Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); + Toolbar toolbar = findViewById(R.id.toolbar); setSupportActionBar(toolbar); String serialized= getIntent().getStringExtra("content"); - ViewPager viewPager = (ViewPager) findViewById(R.id.viewpager); + ViewPager viewPager = findViewById(R.id.viewpager); viewPager.setAdapter(new RendererPagerAdapter(getSupportFragmentManager(), RenderTestActivity.this,serialized)); diff --git a/sample/src/main/res/layout/fragment_preview.xml b/sample/src/main/res/layout/fragment_preview.xml index fc6f78c..67b10ad 100644 --- a/sample/src/main/res/layout/fragment_preview.xml +++ b/sample/src/main/res/layout/fragment_preview.xml @@ -1,7 +1,6 @@ @@ -10,20 +9,6 @@ android:layout_width="match_parent" android:scrollbarStyle="insideOverlay" android:layout_height="wrap_content"> - - - - - - - - - - - - - -