编辑框增加插入链接(文章,回答,游戏)
This commit is contained in:
@ -1,8 +1,10 @@
|
||||
package com.gh.base
|
||||
|
||||
import android.annotation.SuppressLint
|
||||
import android.app.Activity
|
||||
import android.content.ClipboardManager
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.os.Bundle
|
||||
import android.text.TextUtils
|
||||
import android.view.View
|
||||
@ -10,9 +12,12 @@ import android.webkit.JavascriptInterface
|
||||
import butterknife.OnClick
|
||||
import com.gh.common.view.RichEditor
|
||||
import com.gh.gamecenter.R
|
||||
import com.gh.gamecenter.entity.GameEntity
|
||||
import com.gh.gamecenter.qa.editor.GameActivity
|
||||
import com.gh.gamecenter.qa.editor.InsertAnswerWrapperActivity
|
||||
import com.gh.gamecenter.qa.editor.InsertArticleWrapperActivity
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity
|
||||
import com.halo.assistant.HaloApp
|
||||
import com.lightgame.utils.Utils
|
||||
import com.lightgame.view.CheckableImageView
|
||||
@ -39,12 +44,29 @@ abstract class BaseRichEditorActivity : BaseActivity() {
|
||||
private val mEditorInsertDetail by bindView<View>(R.id.editor_insert_detail)
|
||||
|
||||
|
||||
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
|
||||
super.onActivityResult(requestCode, resultCode, data)
|
||||
if (resultCode != Activity.RESULT_OK) return
|
||||
when (requestCode) {
|
||||
INSERT_ANSWER_CODE -> {
|
||||
mRichEditor.insertAnswerLink(data?.getParcelableExtra(AnswerEntity::class.java.simpleName))
|
||||
}
|
||||
INSERT_ARTICLE_CODE -> {
|
||||
mRichEditor.insertCommunityArticleLink(data?.getParcelableExtra(ArticleEntity::class.java.simpleName))
|
||||
}
|
||||
INSERT_GAME_CODE -> {
|
||||
mRichEditor.insertGameLink(data?.getParcelableExtra(GameEntity::class.java.simpleName))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("AddJavascriptInterface")
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
// 防止个别手机在Js里无法获取粘贴内容
|
||||
mRichEditor.addJavascriptInterface(OnPasteListener(), "onPasteListener")
|
||||
mRichEditor.addJavascriptInterface(OnCursorChangeListener(), "OnCursorChangeListener")
|
||||
mRichEditor.addJavascriptInterface(OnLinkClickListener(), "OnLinkClickListener")
|
||||
}
|
||||
|
||||
@OnClick(R.id.editor_image, R.id.editor_font, R.id.editor_link, R.id.editor_paragraph,
|
||||
@ -135,13 +157,13 @@ abstract class BaseRichEditorActivity : BaseActivity() {
|
||||
mEditorParagraphQuote.isChecked = !mEditorParagraphQuote.isChecked
|
||||
}
|
||||
R.id.editor_link_answer -> {
|
||||
startActivity(InsertAnswerWrapperActivity.getIntent(this))
|
||||
startActivityForResult(InsertAnswerWrapperActivity.getIntent(this), INSERT_ANSWER_CODE)
|
||||
}
|
||||
R.id.editor_link_article -> {
|
||||
startActivity(InsertArticleWrapperActivity.getIntent(this))
|
||||
startActivityForResult(InsertArticleWrapperActivity.getIntent(this), INSERT_ARTICLE_CODE)
|
||||
}
|
||||
R.id.editor_link_game -> {
|
||||
startActivity(GameActivity.getIntent(this))
|
||||
startActivityForResult(GameActivity.getIntent(this), INSERT_GAME_CODE)
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -181,6 +203,12 @@ abstract class BaseRichEditorActivity : BaseActivity() {
|
||||
}
|
||||
}
|
||||
|
||||
private inner class OnLinkClickListener {
|
||||
@JavascriptInterface
|
||||
fun onClick(content: String) {
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val ELEMENT_NAME_BOLD = " b "
|
||||
const val ELEMENT_NAME_ITALIC = " i "
|
||||
@ -190,5 +218,8 @@ abstract class BaseRichEditorActivity : BaseActivity() {
|
||||
const val ELEMENT_PARAGRAPH_H3 = " h3 "
|
||||
const val ELEMENT_PARAGRAPH_H4 = " h4 "
|
||||
const val ELEMENT_PARAGRAPH_QUOTE = " blockquote "
|
||||
const val INSERT_ANSWER_CODE = 411
|
||||
const val INSERT_ARTICLE_CODE = 412
|
||||
const val INSERT_GAME_CODE = 413
|
||||
}
|
||||
}
|
||||
@ -15,10 +15,14 @@ import android.webkit.WebViewClient;
|
||||
|
||||
import com.gh.common.util.AskUtils;
|
||||
import com.gh.common.util.DisplayUtils;
|
||||
import com.gh.common.util.GsonUtils;
|
||||
import com.gh.common.util.ImageUtils;
|
||||
import com.gh.common.util.NetworkUtils;
|
||||
import com.gh.common.util.RichEditorUtils;
|
||||
import com.gh.gamecenter.BuildConfig;
|
||||
import com.gh.gamecenter.entity.GameEntity;
|
||||
import com.gh.gamecenter.qa.entity.AnswerEntity;
|
||||
import com.gh.gamecenter.qa.entity.ArticleEntity;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLDecoder;
|
||||
@ -241,6 +245,39 @@ public class RichEditor extends WebView {
|
||||
return TextUtils.isEmpty(mContents) ? "" : mContents;
|
||||
}
|
||||
|
||||
public void insertAnswerLink(AnswerEntity entity) {
|
||||
if (entity == null) return;
|
||||
exec("javascript:RE.insertCustomStyleLink('"
|
||||
+ "answer" + "', '"
|
||||
+ "javascript:void(0);" + "', '"
|
||||
+ entity.getQuestions().getTitle() + "', '"
|
||||
+ entity.getBrief() + "', '"
|
||||
+ "file:///android_asset/editor_insert_answer_icon.png" + "', '"
|
||||
+ entity.getId() + "');");
|
||||
}
|
||||
|
||||
public void insertCommunityArticleLink(ArticleEntity entity) {
|
||||
if (entity == null) return;
|
||||
exec("javascript:RE.insertCustomStyleLink('"
|
||||
+ "community_article" + "', '"
|
||||
+ "javascript:void(0);" + "', '"
|
||||
+ entity.getTitle() + "', '"
|
||||
+ entity.getBrief() + "', '"
|
||||
+ "file:///android_asset/editor_insert_article_icon.png" + "', '"
|
||||
+ entity.getId() + "');");
|
||||
}
|
||||
|
||||
public void insertGameLink(GameEntity entity) {
|
||||
if (entity == null) return;
|
||||
exec("javascript:RE.insertCustomStyleLink('"
|
||||
+ "game" + "', '"
|
||||
+ "javascript:void(0);" + "', '"
|
||||
+ entity.getName() + "', '"
|
||||
+ GsonUtils.toJson(entity.getTag()) + "', '"
|
||||
+ entity.getIcon() + "', '"
|
||||
+ entity.getId() + "');");
|
||||
}
|
||||
|
||||
public void setEditorFontColor(int color) {
|
||||
String hex = convertHexColorString(color);
|
||||
exec("javascript:RE.setBaseTextColor('" + hex + "');");
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -34,7 +36,19 @@ class AnswerAdapter(context: Context, private val mEntrance: String?) : ListAdap
|
||||
|
||||
override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
|
||||
when (getItemViewType(position)) {
|
||||
ItemViewType.ITEM_BODY -> (holder as AnswerViewHolder).initCollectionAnswerViewHolder(mEntityList[position], mEntrance)
|
||||
ItemViewType.ITEM_BODY -> {
|
||||
val answerViewHolder = holder as AnswerViewHolder
|
||||
val entity = mEntityList[position]
|
||||
answerViewHolder.initCollectionAnswerViewHolder(entity, mEntrance)
|
||||
answerViewHolder.itemView.setOnClickListener {
|
||||
if (mContext is Activity) {
|
||||
val intent = Intent()
|
||||
intent.putExtra(AnswerEntity::class.java.simpleName, entity)
|
||||
(mContext as Activity).setResult(Activity.RESULT_OK, intent)
|
||||
(mContext as Activity).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemViewType.ITEM_FOOTER -> {
|
||||
val footerViewHolder = holder as FooterViewHolder
|
||||
footerViewHolder.initItemPadding()
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -39,6 +41,14 @@ class ArticleAdapter(context: Context, private val mEntrance: String?) : ListAda
|
||||
val articleHolder = holder as CollectionCommunityArticleViewHolder
|
||||
val entity = mEntityList[position]
|
||||
articleHolder.binding.data = entity
|
||||
articleHolder.itemView.setOnClickListener {
|
||||
if (mContext is Activity) {
|
||||
val intent = Intent()
|
||||
intent.putExtra(ArticleEntity::class.java.simpleName, entity)
|
||||
(mContext as Activity).setResult(Activity.RESULT_OK, intent)
|
||||
(mContext as Activity).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
ItemViewType.ITEM_FOOTER -> {
|
||||
val footerViewHolder = holder as FooterViewHolder
|
||||
|
||||
@ -1,6 +1,8 @@
|
||||
package com.gh.gamecenter.qa.editor
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.Context
|
||||
import android.content.Intent
|
||||
import android.support.v7.widget.RecyclerView
|
||||
import android.view.View
|
||||
import android.view.ViewGroup
|
||||
@ -30,6 +32,14 @@ class GameAdapter(context: Context) : ListAdapter<GameEntity>(context) {
|
||||
holder.binding.game = entity
|
||||
holder.binding.subjectTag = "type"
|
||||
holder.binding.downloadBtn.visibility = View.GONE
|
||||
holder.itemView.setOnClickListener {
|
||||
if (mContext is Activity) {
|
||||
val intent = Intent()
|
||||
intent.putExtra(GameEntity::class.java.simpleName, entity)
|
||||
(mContext as Activity).setResult(Activity.RESULT_OK, intent)
|
||||
(mContext as Activity).finish()
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ import com.gh.gamecenter.entity.UserEntity
|
||||
import com.google.gson.annotations.SerializedName
|
||||
import kotlinx.android.parcel.Parcelize
|
||||
|
||||
@Parcelize
|
||||
data class ArticleEntity(@SerializedName("_id")
|
||||
val id: String = "",
|
||||
val title: String = "",
|
||||
@ -15,11 +16,12 @@ data class ArticleEntity(@SerializedName("_id")
|
||||
val count: Count = Count(),
|
||||
val community: CommunityEntity = CommunityEntity(),
|
||||
val time: TimeEntity? = TimeEntity(),
|
||||
val user: UserEntity = UserEntity()) {
|
||||
val user: UserEntity = UserEntity()) : Parcelable {
|
||||
|
||||
@Parcelize
|
||||
data class TimeEntity(var create: Long? = 0,
|
||||
var update: Long? = 0,
|
||||
var edit: Long? = 0)
|
||||
var edit: Long? = 0) : Parcelable
|
||||
}
|
||||
|
||||
@Parcelize
|
||||
|
||||
Reference in New Issue
Block a user