Skip to content

Commit

Permalink
Crash early. (#89)
Browse files Browse the repository at this point in the history
  • Loading branch information
vanniktech authored Feb 14, 2017
1 parent 6e11413 commit be5db45
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 3 deletions.
4 changes: 4 additions & 0 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiEditText.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ public EmojiEditText(final Context context, final AttributeSet attrs) {
}

private void init(@Nullable final AttributeSet attrs) {
if (!isInEditMode()) {
EmojiManager.getInstance().verifyInstalled();
}

if (attrs == null) {
emojiSize = (int) getTextSize();
} else {
Expand Down
14 changes: 12 additions & 2 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@

import static com.vanniktech.emoji.Utils.checkNotNull;

/**
* EmojiManager where an EmojiProvider can be installed for further usage.
*/
public final class EmojiManager {
private static final EmojiManager INSTANCE = new EmojiManager();

Expand All @@ -22,6 +25,13 @@ static EmojiManager getInstance() {
return INSTANCE;
}

/**
* Installs the given EmojiProvider.
*
* NOTE: That only one can be present at any time.
*
* @param provider the provider that should be installed.
*/
public static void install(@NonNull final EmojiProvider provider) {
INSTANCE.categories = checkNotNull(provider.getCategories(), "categories == null");
INSTANCE.emojiTree.clear();
Expand All @@ -47,9 +57,9 @@ EmojiCategory[] getCategories() {
return emojiTree.findEmoji(candiate);
}

private void verifyInstalled() {
void verifyInstalled() {
if (categories == null) {
throw new IllegalStateException("Please install an EmojiProvider through the install method first.");
throw new IllegalStateException("Please install an EmojiProvider through the EmojiManager.install() method first.");
}
}
}
3 changes: 2 additions & 1 deletion emoji/src/main/java/com/vanniktech/emoji/EmojiPopup.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ private Builder(final View rootView) {

/**
* allows you to pass your own implementation of recent emojis. If not provided the default one
* ({@link RecentEmojiManager} will be used
* {@link RecentEmojiManager} will be used
*
* @since 0.2.0
*/
Expand All @@ -262,6 +262,7 @@ private Builder(final View rootView) {
}

@CheckResult public EmojiPopup build(@NonNull final EmojiEditText emojiEditText) {
EmojiManager.getInstance().verifyInstalled();
checkNotNull(emojiEditText, "EmojiEditText can't be null");

final EmojiPopup emojiPopup = new EmojiPopup(rootView, emojiEditText, recentEmoji);
Expand Down
4 changes: 4 additions & 0 deletions emoji/src/main/java/com/vanniktech/emoji/EmojiTextView.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ public EmojiTextView(final Context context, final AttributeSet attrs) {
}

private void init(@Nullable final AttributeSet attrs) {
if (!isInEditMode()) {
EmojiManager.getInstance().verifyInstalled();
}

if (attrs == null) {
emojiSize = (int) getTextSize();
} else {
Expand Down

0 comments on commit be5db45

Please sign in to comment.