Skip to content
This repository has been archived by the owner on Jul 25, 2021. It is now read-only.

Commit

Permalink
fix the wrong order bug on renderer view, make links clickable
Browse files Browse the repository at this point in the history
  • Loading branch information
irshu355 committed Nov 29, 2018
1 parent 2405674 commit dba34c9
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 1 addition & 7 deletions laser-native-editor/laser-native-editor.iml
Original file line number Diff line number Diff line change
Expand Up @@ -85,31 +85,25 @@
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
<excludeFolder url="file://$MODULE_DIR$/build/docs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/annotations" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/attr" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/check-manifest" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/extractedTypedefs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/incremental" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/intermediate-jars" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/javaPrecompile" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/library_and_local_jars_jni" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged-aidl" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged-classes" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packagedAssets" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/packaged_res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/proguard-rules" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/public_res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/rs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/shaders" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/symbols" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/transforms" />
<excludeFolder url="file://$MODULE_DIR$/build/libs" />
<excludeFolder url="file://$MODULE_DIR$/build/outputs" />
<excludeFolder url="file://$MODULE_DIR$/build/poms" />
<excludeFolder url="file://$MODULE_DIR$/build/tmp" />
</content>
<orderEntry type="jdk" jdkName="Android API 27 Platform" jdkType="Android SDK" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;

Expand All @@ -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);
Expand All @@ -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) {
Expand All @@ -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) {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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));

/*
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {

}
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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);
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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("<p>Hello man, whats up!</p>");

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
27 changes: 0 additions & 27 deletions sample/src/main/res/layout/fragment_preview.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
xmlns:card_view="http://schemas.android.com/tools"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
tools:context="com.github.irshulx.wysiwyg.PreviewFragment">
Expand All @@ -10,20 +9,6 @@
android:layout_width="match_parent"
android:scrollbarStyle="insideOverlay"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<android.support.v7.widget.CardView
android:foreground="?android:attr/selectableItemBackground"
android:clickable="true"
card_view:cardUseCompatPadding="true"
android:id="@+id/card_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="3dp"
card_view:cardElevation="3dp"
android:paddingBottom="30dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_marginTop="4dp"
Expand Down Expand Up @@ -57,19 +42,7 @@
android:paddingBottom="10dp"
/>
</LinearLayout>


</RelativeLayout>




</LinearLayout>
</android.support.v7.widget.CardView>




</LinearLayout>
</ScrollView>

Expand Down

0 comments on commit dba34c9

Please sign in to comment.