From e2da2aef84c6a55ab4ae8f51cfeba441aa0a4316 Mon Sep 17 00:00:00 2001 From: Kosh Sergani Date: Thu, 17 Aug 2017 23:21:17 +0800 Subject: [PATCH] this commit adds selecting github emoji from markdown editor (search functionality in progress) --- .../com/fastaccess/provider/emoji/Emoji.java | 375 +++++++++--------- .../provider/emoji/EmojiManager.java | 2 +- .../com/fastaccess/ui/adapter/EmojiAdapter.kt | 22 + .../ui/adapter/viewholder/EmojiViewHolder.kt | 29 ++ .../ui/modules/editor/EditorActivity.kt | 32 +- .../fastaccess/ui/modules/editor/EditorMvp.kt | 4 +- .../modules/editor/emoji/EmojiBottomSheet.kt | 70 ++++ .../ui/modules/editor/emoji/EmojiMvp.kt | 24 ++ .../ui/modules/editor/emoji/EmojiPresenter.kt | 29 ++ .../create/dialog/AddGistBottomSheetDialog.kt | 8 + .../modules/gists/create/dialog/AddGistMvp.kt | 3 +- .../ui/widgets/markdown/MarkDownLayout.kt | 17 +- .../recyclerview/BaseRecyclerAdapter.java | 5 + .../layout/emoji_popup_layout.xml | 75 ++++ .../layout/markdown_buttons_layout.xml | 18 +- .../row_layouts/layout/emoji_row_item.xml | 20 + 16 files changed, 526 insertions(+), 207 deletions(-) create mode 100644 app/src/main/java/com/fastaccess/ui/adapter/EmojiAdapter.kt create mode 100644 app/src/main/java/com/fastaccess/ui/adapter/viewholder/EmojiViewHolder.kt create mode 100644 app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiBottomSheet.kt create mode 100644 app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiMvp.kt create mode 100644 app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiPresenter.kt create mode 100644 app/src/main/res/layouts/main_layouts/layout/emoji_popup_layout.xml create mode 100644 app/src/main/res/layouts/row_layouts/layout/emoji_row_item.xml diff --git a/app/src/main/java/com/fastaccess/provider/emoji/Emoji.java b/app/src/main/java/com/fastaccess/provider/emoji/Emoji.java index f89944b5..3c6a3046 100644 --- a/app/src/main/java/com/fastaccess/provider/emoji/Emoji.java +++ b/app/src/main/java/com/fastaccess/provider/emoji/Emoji.java @@ -12,203 +12,208 @@ import java.util.List; * @author Vincent DURMONT [vdurmont@gmail.com] */ public class Emoji { - private final String description; - private final boolean supportsFitzpatrick; - private final List aliases; - private final List tags; - private final String unicode; - private final String htmlDec; - private final String htmlHex; + private final String description; + private final boolean supportsFitzpatrick; + private final List aliases; + private final List tags; + private final String unicode; + private final String htmlDec; + private final String htmlHex; - /** - * Constructor for the Emoji. - * - * @param description The description of the emoji - * @param supportsFitzpatrick Whether the emoji supports Fitzpatrick modifiers - * @param aliases the aliases for this emoji - * @param tags the tags associated with this emoji - * @param bytes the bytes that represent the emoji - */ - protected Emoji( - String description, - boolean supportsFitzpatrick, - List aliases, - List tags, - byte... bytes - ) { - this.description = description; - this.supportsFitzpatrick = supportsFitzpatrick; - this.aliases = Collections.unmodifiableList(aliases); - this.tags = Collections.unmodifiableList(tags); + /** + * Constructor for the Emoji. + * + * @param description + * The description of the emoji + * @param supportsFitzpatrick + * Whether the emoji supports Fitzpatrick modifiers + * @param aliases + * the aliases for this emoji + * @param tags + * the tags associated with this emoji + * @param bytes + * the bytes that represent the emoji + */ + protected Emoji( + String description, + boolean supportsFitzpatrick, + List aliases, + List tags, + byte... bytes + ) { + this.description = description; + this.supportsFitzpatrick = supportsFitzpatrick; + this.aliases = Collections.unmodifiableList(aliases); + this.tags = Collections.unmodifiableList(tags); - int count = 0; - try { - this.unicode = new String(bytes, "UTF-8"); - int stringLength = getUnicode().length(); - String[] pointCodes = new String[stringLength]; - String[] pointCodesHex = new String[stringLength]; + int count = 0; + try { + this.unicode = new String(bytes, "UTF-8"); + int stringLength = getUnicode().length(); + String[] pointCodes = new String[stringLength]; + String[] pointCodesHex = new String[stringLength]; - for (int offset = 0; offset < stringLength; ) { - final int codePoint = getUnicode().codePointAt(offset); + for (int offset = 0; offset < stringLength; ) { + final int codePoint = getUnicode().codePointAt(offset); - pointCodes[count] = String.format("&#%d;", codePoint); - pointCodesHex[count++] = String.format("&#x%x;", codePoint); + pointCodes[count] = String.format("&#%d;", codePoint); + pointCodesHex[count++] = String.format("&#x%x;", codePoint); - offset += Character.charCount(codePoint); - } - this.htmlDec = stringJoin(pointCodes, count); - this.htmlHex = stringJoin(pointCodesHex, count); - } catch (UnsupportedEncodingException e) { - throw new RuntimeException(e); + offset += Character.charCount(codePoint); + } + this.htmlDec = stringJoin(pointCodes, count); + this.htmlHex = stringJoin(pointCodesHex, count); + } catch (UnsupportedEncodingException e) { + throw new RuntimeException(e); + } } - } - /** - * Method to replace String.join, since it was only introduced in java8 - * @param array the array to be concatenated - * @return concatenated String - */ - private String stringJoin(String[] array, int count){ - String joined = ""; - for(int i = 0; i < count; i++) - joined += array[i]; - return joined; - } - - /** - * Returns the description of the emoji - * - * @return the description - */ - public String getDescription() { - return this.description; - } - - /** - * Returns wether the emoji supports the Fitzpatrick modifiers or not - * - * @return true if the emoji supports the Fitzpatrick modifiers - */ - public boolean supportsFitzpatrick() { - return this.supportsFitzpatrick; - } - - /** - * Returns the aliases of the emoji - * - * @return the aliases (unmodifiable) - */ - public List getAliases() { - return this.aliases; - } - - /** - * Returns the tags of the emoji - * - * @return the tags (unmodifiable) - */ - public List getTags() { - return this.tags; - } - - /** - * Returns the unicode representation of the emoji - * - * @return the unicode representation - */ - public String getUnicode() { - return this.unicode; - } - - /** - * Returns the unicode representation of the emoji associated with the - * provided Fitzpatrick modifier.
- * If the modifier is null, then the result is similar to - * {@link Emoji#getUnicode()} - * - * @param fitzpatrick the fitzpatrick modifier or null - * - * @return the unicode representation - * @throws UnsupportedOperationException if the emoji doesn't support the - * Fitzpatrick modifiers - */ - public String getUnicode(Fitzpatrick fitzpatrick) { - if (!this.supportsFitzpatrick()) { - throw new UnsupportedOperationException( - "Cannot get the unicode with a fitzpatrick modifier, " + - "the emoji doesn't support fitzpatrick." - ); - } else if (fitzpatrick == null) { - return this.getUnicode(); + /** + * Method to replace String.join, since it was only introduced in java8 + * + * @param array + * the array to be concatenated + * @return concatenated String + */ + private String stringJoin(String[] array, int count) { + String joined = ""; + for (int i = 0; i < count; i++) + joined += array[i]; + return joined; } - return this.getUnicode() + fitzpatrick.unicode; - } - /** - * Returns the HTML decimal representation of the emoji - * - * @return the HTML decimal representation - */ - public String getHtmlDecimal() { - return this.htmlDec; - } + /** + * Returns the description of the emoji + * + * @return the description + */ + public String getDescription() { + return this.description; + } - /** - * @deprecated identical to {@link #getHtmlHexadecimal()} for - * backwards-compatibility. Use that instead. - * - * @return the HTML hexadecimal representation - */ - public String getHtmlHexidecimal() { - return this.getHtmlHexadecimal(); - } + /** + * Returns wether the emoji supports the Fitzpatrick modifiers or not + * + * @return true if the emoji supports the Fitzpatrick modifiers + */ + public boolean supportsFitzpatrick() { + return this.supportsFitzpatrick; + } - /** - * Returns the HTML hexadecimal representation of the emoji - * - * @return the HTML hexadecimal representation - */ - public String getHtmlHexadecimal() { - return this.htmlHex; - } + /** + * Returns the aliases of the emoji + * + * @return the aliases (unmodifiable) + */ + public List getAliases() { + return this.aliases; + } - @Override - public boolean equals(Object other) { - return !(other == null || !(other instanceof Emoji)) && - ((Emoji) other).getUnicode().equals(getUnicode()); - } + /** + * Returns the tags of the emoji + * + * @return the tags (unmodifiable) + */ + public List getTags() { + return this.tags; + } - @Override - public int hashCode() { - return unicode.hashCode(); - } + /** + * Returns the unicode representation of the emoji + * + * @return the unicode representation + */ + public String getUnicode() { + return this.unicode; + } - /** - * Returns the String representation of the Emoji object.
- *
- * Example:
- * Emoji { - * description='smiling face with open mouth and smiling eyes', - * supportsFitzpatrick=false, - * aliases=[smile], - * tags=[happy, joy, pleased], - * unicode='😄', - * htmlDec='&#128516;', - * htmlHex='&#x1f604;' - * } - * - * @return the string representation - */ - @Override - public String toString() { - return "Emoji{" + - "description='" + description + '\'' + - ", supportsFitzpatrick=" + supportsFitzpatrick + - ", aliases=" + aliases + - ", tags=" + tags + - ", unicode='" + unicode + '\'' + - ", htmlDec='" + htmlDec + '\'' + - ", htmlHex='" + htmlHex + '\'' + - '}'; - } + /** + * Returns the unicode representation of the emoji associated with the + * provided Fitzpatrick modifier.
+ * If the modifier is null, then the result is similar to + * {@link Emoji#getUnicode()} + * + * @param fitzpatrick + * the fitzpatrick modifier or null + * @return the unicode representation + * @throws UnsupportedOperationException + * if the emoji doesn't support the Fitzpatrick modifiers + */ + public String getUnicode(Fitzpatrick fitzpatrick) { + if (!this.supportsFitzpatrick()) { + throw new UnsupportedOperationException( + "Cannot get the unicode with a fitzpatrick modifier, " + + "the emoji doesn't support fitzpatrick." + ); + } else if (fitzpatrick == null) { + return this.getUnicode(); + } + return this.getUnicode() + fitzpatrick.unicode; + } + + /** + * Returns the HTML decimal representation of the emoji + * + * @return the HTML decimal representation + */ + public String getHtmlDecimal() { + return this.htmlDec; + } + + /** + * @return the HTML hexadecimal representation + * @deprecated identical to {@link #getHtmlHexadecimal()} for backwards-compatibility. Use that instead. + */ + public String getHtmlHexidecimal() { + return this.getHtmlHexadecimal(); + } + + /** + * Returns the HTML hexadecimal representation of the emoji + * + * @return the HTML hexadecimal representation + */ + public String getHtmlHexadecimal() { + return this.htmlHex; + } + + @Override + public boolean equals(Object other) { + return !(other == null || !(other instanceof Emoji)) && + ((Emoji) other).getUnicode().equals(getUnicode()); + } + + @Override + public int hashCode() { + return unicode.hashCode(); + } + + /** + * Returns the String representation of the Emoji object.
+ *
+ * Example:
+ * Emoji { + * description='smiling face with open mouth and smiling eyes', + * supportsFitzpatrick=false, + * aliases=[smile], + * tags=[happy, joy, pleased], + * unicode='😄', + * htmlDec='&#128516;', + * htmlHex='&#x1f604;' + * } + * + * @return the string representation + */ + @Override + public String toString() { + return "Emoji{" + + "description='" + description + '\'' + + ", supportsFitzpatrick=" + supportsFitzpatrick + + ", aliases=" + aliases + + ", tags=" + tags + + ", unicode='" + unicode + '\'' + + ", htmlDec='" + htmlDec + '\'' + + ", htmlHex='" + htmlHex + '\'' + + '}'; + } } diff --git a/app/src/main/java/com/fastaccess/provider/emoji/EmojiManager.java b/app/src/main/java/com/fastaccess/provider/emoji/EmojiManager.java index 1430afa3..c8283bfc 100644 --- a/app/src/main/java/com/fastaccess/provider/emoji/EmojiManager.java +++ b/app/src/main/java/com/fastaccess/provider/emoji/EmojiManager.java @@ -87,7 +87,7 @@ public class EmojiManager { return EMOJI_TRIE.getEmoji(unicode); } - public static Collection getAll() { + public static List getAll() { return ALL_EMOJIS; } diff --git a/app/src/main/java/com/fastaccess/ui/adapter/EmojiAdapter.kt b/app/src/main/java/com/fastaccess/ui/adapter/EmojiAdapter.kt new file mode 100644 index 00000000..0722d473 --- /dev/null +++ b/app/src/main/java/com/fastaccess/ui/adapter/EmojiAdapter.kt @@ -0,0 +1,22 @@ +package com.fastaccess.ui.adapter + +import android.view.ViewGroup +import com.fastaccess.provider.emoji.Emoji +import com.fastaccess.ui.adapter.viewholder.EmojiViewHolder +import com.fastaccess.ui.widgets.recyclerview.BaseRecyclerAdapter +import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder + +/** + * Created by kosh on 17/08/2017. + */ +class EmojiAdapter(listener: BaseViewHolder.OnItemClickListener) + : BaseRecyclerAdapter>(listener) { + override fun viewHolder(parent: ViewGroup, viewType: Int): EmojiViewHolder { + return EmojiViewHolder.newInstance(parent, this) + } + + override fun onBindView(holder: EmojiViewHolder, position: Int) { + holder.bind(data[position]) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/fastaccess/ui/adapter/viewholder/EmojiViewHolder.kt b/app/src/main/java/com/fastaccess/ui/adapter/viewholder/EmojiViewHolder.kt new file mode 100644 index 00000000..c26bb6e2 --- /dev/null +++ b/app/src/main/java/com/fastaccess/ui/adapter/viewholder/EmojiViewHolder.kt @@ -0,0 +1,29 @@ +package com.fastaccess.ui.adapter.viewholder + +import android.view.View +import android.view.ViewGroup +import butterknife.BindView +import com.fastaccess.R +import com.fastaccess.provider.emoji.Emoji +import com.fastaccess.ui.widgets.FontTextView +import com.fastaccess.ui.widgets.recyclerview.BaseRecyclerAdapter +import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder + +/** + * Created by kosh on 17/08/2017. + */ +class EmojiViewHolder private constructor(view: View, adapter: BaseRecyclerAdapter<*, *, *>) + : BaseViewHolder(view, adapter) { + + @BindView(R.id.emoji) lateinit var emojiTextView: FontTextView + + override fun bind(t: Emoji) { + emojiTextView.text = t.unicode + } + + companion object { + fun newInstance(parent: ViewGroup, adapter: BaseRecyclerAdapter<*, *, *>): EmojiViewHolder { + return EmojiViewHolder(getView(parent, R.layout.emoji_row_item), adapter) + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fastaccess/ui/modules/editor/EditorActivity.kt b/app/src/main/java/com/fastaccess/ui/modules/editor/EditorActivity.kt index 7ad09865..d6afd3fa 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/editor/EditorActivity.kt +++ b/app/src/main/java/com/fastaccess/ui/modules/editor/EditorActivity.kt @@ -1,5 +1,6 @@ package com.fastaccess.ui.modules.editor +import android.annotation.SuppressLint import android.app.Activity import android.content.Intent import android.os.Bundle @@ -22,6 +23,7 @@ import com.fastaccess.R import com.fastaccess.data.dao.EditReviewCommentModel import com.fastaccess.data.dao.model.Comment import com.fastaccess.helper.* +import com.fastaccess.provider.emoji.Emoji import com.fastaccess.provider.markdown.CachedComments import com.fastaccess.provider.markdown.MarkDownProvider import com.fastaccess.ui.base.BaseActivity @@ -36,7 +38,7 @@ import java.util.* class EditorActivity : BaseActivity(), EditorMvp.View { - val sentFromFastHub: String by lazy { + private val sentFromFastHub: String by lazy { "\n\n_" + getString(R.string.sent_from_fasthub, AppHelper.getDeviceName(), "", "[" + getString(R.string.app_name) + "](https://play.google.com/store/apps/details?id=com.fastaccess.github)") + "_" } @@ -52,13 +54,21 @@ class EditorActivity : BaseActivity(), EditorMv @BindView(R.id.parentView) lateinit var parentView: View @BindView(R.id.autocomplete) lateinit var mention: ListView - @State @BundleConstant.ExtraTYpe var extraType: String? = null - @State var itemId: String? = null - @State var login: String? = null - @State var issueNumber: Int = 0 - @State var commentId: Long = 0 - @State var sha: String? = null - @State var reviewComment: EditReviewCommentModel? = null + @State + @BundleConstant.ExtraTYpe + var extraType: String? = null + @State + var itemId: String? = null + @State + var login: String? = null + @State + var issueNumber: Int = 0 + @State + var commentId: Long = 0 + @State + var sha: String? = null + @State + var reviewComment: EditReviewCommentModel? = null override fun layout(): Int = R.layout.editor_layout @@ -203,6 +213,12 @@ class EditorActivity : BaseActivity(), EditorMv override fun fragmentManager(): FragmentManager = supportFragmentManager + @SuppressLint("SetTextI18n") + override fun onEmojiAdded(emoji: Emoji) { + ViewHelper.showKeyboard(editText) + editText.setText("${editText.text} :${emoji.aliases[0]}:") + } + private fun onCreate() { val intent = intent if (intent != null && intent.extras != null) { diff --git a/app/src/main/java/com/fastaccess/ui/modules/editor/EditorMvp.kt b/app/src/main/java/com/fastaccess/ui/modules/editor/EditorMvp.kt index 1e028bdc..191e168e 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/editor/EditorMvp.kt +++ b/app/src/main/java/com/fastaccess/ui/modules/editor/EditorMvp.kt @@ -4,6 +4,7 @@ import com.fastaccess.data.dao.EditReviewCommentModel import com.fastaccess.data.dao.model.Comment import com.fastaccess.helper.BundleConstant import com.fastaccess.ui.base.mvp.BaseMvp +import com.fastaccess.ui.modules.editor.emoji.EmojiMvp import com.fastaccess.ui.modules.editor.popup.EditorLinkImageMvp import com.fastaccess.ui.widgets.markdown.MarkDownLayout @@ -13,7 +14,8 @@ import com.fastaccess.ui.widgets.markdown.MarkDownLayout interface EditorMvp { - interface View : BaseMvp.FAView, EditorLinkImageMvp.EditorLinkCallback, MarkDownLayout.MarkdownListener { + interface View : BaseMvp.FAView, EditorLinkImageMvp.EditorLinkCallback, + MarkDownLayout.MarkdownListener, EmojiMvp.EmojiCallback { fun onSendResultAndFinish(commentModel: Comment, isNew: Boolean) fun onSendMarkDownResult() diff --git a/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiBottomSheet.kt b/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiBottomSheet.kt new file mode 100644 index 00000000..b96d3cb5 --- /dev/null +++ b/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiBottomSheet.kt @@ -0,0 +1,70 @@ +package com.fastaccess.ui.modules.editor.emoji + +import android.content.Context +import android.os.Bundle +import android.view.View +import butterknife.BindView +import com.fastaccess.R +import com.fastaccess.provider.emoji.Emoji +import com.fastaccess.ui.adapter.EmojiAdapter +import com.fastaccess.ui.base.BaseMvpBottomSheetDialogFragment +import com.fastaccess.ui.widgets.recyclerview.DynamicRecyclerView +import com.fastaccess.ui.widgets.recyclerview.layout_manager.GridManager +import com.fastaccess.ui.widgets.recyclerview.scroll.RecyclerViewFastScroller + +/** + * Created by kosh on 17/08/2017. + */ +class EmojiBottomSheet : BaseMvpBottomSheetDialogFragment(), EmojiMvp.View { + + @BindView(R.id.recycler) lateinit var recycler: DynamicRecyclerView + @BindView(R.id.fastScroller) lateinit var fastScroller: RecyclerViewFastScroller + + val adapter: EmojiAdapter by lazy { EmojiAdapter(this) } + + var emojiCallback: EmojiMvp.EmojiCallback? = null + + override fun onAttach(context: Context) { + super.onAttach(context) + if (parentFragment is EmojiMvp.EmojiCallback) { + emojiCallback = parentFragment as EmojiMvp.EmojiCallback + } else if (context is EmojiMvp.EmojiCallback) { + emojiCallback = context + } else { + throw IllegalArgumentException("${context.javaClass.simpleName} must implement EmojiMvp.EmojiCallback") + } + } + + override fun onDetach() { + emojiCallback = null + super.onDetach() + } + + override fun fragmentLayout(): Int = R.layout.emoji_popup_layout + + override fun providePresenter(): EmojiPresenter = EmojiPresenter() + + override fun clearAdapter() { + adapter.clear() + } + + override fun onAddEmoji(emoji: Emoji) { + adapter.addItem(emoji) + } + + override fun onItemClick(position: Int, v: View?, item: Emoji) { + emojiCallback?.onEmojiAdded(item) + dismiss() + } + + override fun onItemLongClick(position: Int, v: View?, item: Emoji?) {} + + override fun onViewCreated(view: View?, savedInstanceState: Bundle?) { + super.onViewCreated(view, savedInstanceState) + recycler.adapter = adapter + fastScroller.attachRecyclerView(recycler) + presenter.onLoadEmoji() + val gridManager = recycler.layoutManager as GridManager + gridManager.iconSize = resources.getDimensionPixelSize(R.dimen.header_icon_zie) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiMvp.kt b/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiMvp.kt new file mode 100644 index 00000000..67cde670 --- /dev/null +++ b/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiMvp.kt @@ -0,0 +1,24 @@ +package com.fastaccess.ui.modules.editor.emoji + +import com.fastaccess.provider.emoji.Emoji +import com.fastaccess.ui.base.mvp.BaseMvp +import com.fastaccess.ui.widgets.recyclerview.BaseViewHolder + +/** + * Created by kosh on 17/08/2017. + */ +interface EmojiMvp { + + interface View : BaseMvp.FAView, BaseViewHolder.OnItemClickListener { + fun clearAdapter() + fun onAddEmoji(emoji: Emoji) + } + + interface Presenter { + fun onLoadEmoji() + } + + interface EmojiCallback { + fun onEmojiAdded(emoji: Emoji) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiPresenter.kt b/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiPresenter.kt new file mode 100644 index 00000000..3ae507b8 --- /dev/null +++ b/app/src/main/java/com/fastaccess/ui/modules/editor/emoji/EmojiPresenter.kt @@ -0,0 +1,29 @@ +package com.fastaccess.ui.modules.editor.emoji + +import com.fastaccess.provider.emoji.Emoji +import com.fastaccess.provider.emoji.EmojiManager +import com.fastaccess.ui.base.mvp.presenter.BasePresenter +import io.reactivex.Observable + +/** + * Created by kosh on 17/08/2017. + */ + +class EmojiPresenter : BasePresenter(), EmojiMvp.Presenter { + override fun onLoadEmoji() { + manageObservable(Observable.create { e -> + val emojies = EmojiManager.getAll() + emojies?.let { + it.onEach { + if (!e.isDisposed) { + e.onNext(it) + } + } + } + e.onComplete() + } + .doOnSubscribe { sendToView { it.clearAdapter() } } + .doOnNext { emoji -> sendToView { it.onAddEmoji(emoji) } }) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/fastaccess/ui/modules/gists/create/dialog/AddGistBottomSheetDialog.kt b/app/src/main/java/com/fastaccess/ui/modules/gists/create/dialog/AddGistBottomSheetDialog.kt index 42c94981..6ff958ff 100644 --- a/app/src/main/java/com/fastaccess/ui/modules/gists/create/dialog/AddGistBottomSheetDialog.kt +++ b/app/src/main/java/com/fastaccess/ui/modules/gists/create/dialog/AddGistBottomSheetDialog.kt @@ -1,5 +1,6 @@ package com.fastaccess.ui.modules.gists.create.dialog +import android.annotation.SuppressLint import android.content.Context import android.os.Bundle import android.os.Parcelable @@ -19,6 +20,7 @@ import com.fastaccess.helper.BundleConstant import com.fastaccess.helper.Bundler import com.fastaccess.helper.InputHelper import com.fastaccess.helper.ViewHelper +import com.fastaccess.provider.emoji.Emoji import com.fastaccess.provider.markdown.MarkDownProvider import com.fastaccess.ui.base.BaseDialogFragment import com.fastaccess.ui.modules.gists.create.dialog.AddGistMvp.AddGistFileListener @@ -114,6 +116,12 @@ class AddGistBottomSheetDialog : BaseDialogFragment if (!editText.isEnabled) { Snackbar.make(this, R.string.error_highlighting_editor, Snackbar.LENGTH_SHORT).show() } else { - if (v.id == R.id.link) { - EditorLinkImageDialogFragment.newInstance(true).show(it.fragmentManager(), "BannerDialogFragment") - } else if (v.id == R.id.image) { - EditorLinkImageDialogFragment.newInstance(false).show(it.fragmentManager(), "BannerDialogFragment") - } else { - onActionClicked(editText, v.id) + when { + v.id == R.id.link -> EditorLinkImageDialogFragment.newInstance(true).show(it.fragmentManager(), "BannerDialogFragment") + v.id == R.id.image -> EditorLinkImageDialogFragment.newInstance(false).show(it.fragmentManager(), "BannerDialogFragment") + v.id == R.id.addEmoji -> { + ViewHelper.hideKeyboard(it.getEditText()) + EmojiBottomSheet().show(it.fragmentManager(), "EmojiBottomSheet") + } + else -> onActionClicked(editText, v.id) } } } diff --git a/app/src/main/java/com/fastaccess/ui/widgets/recyclerview/BaseRecyclerAdapter.java b/app/src/main/java/com/fastaccess/ui/widgets/recyclerview/BaseRecyclerAdapter.java index f74eb388..e5c5c1b2 100644 --- a/app/src/main/java/com/fastaccess/ui/widgets/recyclerview/BaseRecyclerAdapter.java +++ b/app/src/main/java/com/fastaccess/ui/widgets/recyclerview/BaseRecyclerAdapter.java @@ -30,6 +30,7 @@ public abstract class BaseRecyclerAdapter()); } @@ -43,6 +44,10 @@ public abstract class BaseRecyclerAdapter(), listener); + } + protected abstract VH viewHolder(ViewGroup parent, int viewType); protected abstract void onBindView(VH holder, int position); diff --git a/app/src/main/res/layouts/main_layouts/layout/emoji_popup_layout.xml b/app/src/main/res/layouts/main_layouts/layout/emoji_popup_layout.xml new file mode 100644 index 00000000..e78cbb31 --- /dev/null +++ b/app/src/main/res/layouts/main_layouts/layout/emoji_popup_layout.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/layouts/main_layouts/layout/markdown_buttons_layout.xml b/app/src/main/res/layouts/main_layouts/layout/markdown_buttons_layout.xml index 8d986370..00e8e6e6 100644 --- a/app/src/main/res/layouts/main_layouts/layout/markdown_buttons_layout.xml +++ b/app/src/main/res/layouts/main_layouts/layout/markdown_buttons_layout.xml @@ -1,14 +1,14 @@ - @@ -183,6 +183,16 @@ + + + + + + \ No newline at end of file