Skip to content

Commit

Permalink
Merge pull request #82 from elimu-ai/67-display-emojis-behind-words
Browse files Browse the repository at this point in the history
67 display emojis behind words
  • Loading branch information
gscdev authored Apr 20, 2021
2 parents 8515a50 + b946183 commit 7ca9210
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 26 deletions.
7 changes: 6 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ android {
buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics"')
}
}

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])

implementation 'com.github.elimu-ai:model:model-2.0.33' // See https://jitpack.io/#elimu-ai/model
implementation 'com.github.elimu-ai:content-provider:1.2.1@aar' // See https://jitpack.io/#elimu-ai/content-provider
implementation 'com.github.elimu-ai:content-provider:1.2.7@aar' // See https://jitpack.io/#elimu-ai/content-provider
implementation 'com.github.elimu-ai:analytics:3.1.5@aar' // See https://jitpack.io/#elimu-ai/analytics
implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'com.google.android.material:material:1.3.0'
Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.List;

import ai.elimu.analytics.utils.LearningEventUtil;
import ai.elimu.content_provider.utils.ContentProviderHelper;
import ai.elimu.content_provider.utils.ContentProviderUtil;
import ai.elimu.model.enums.ReadingLevel;
import ai.elimu.model.enums.analytics.LearningEventType;
import ai.elimu.model.v2.gson.content.ImageGson;
Expand Down Expand Up @@ -52,7 +52,7 @@ protected void onCreate(Bundle savedInstanceState) {
storyBooksProgressBar = findViewById(R.id.storybooks_progress_bar);

// Fetch StoryBooks from the elimu.ai Content Provider (see https://github.com/elimu-ai/content-provider)
storyBooks = ContentProviderHelper.getStoryBookGsons(getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
storyBooks = ContentProviderUtil.getAllStoryBookGsons(getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
Log.i(getClass().getName(), "storyBooks.size(): " + storyBooks.size());
}

Expand Down Expand Up @@ -112,7 +112,7 @@ public void run() {

// Fetch Image from the elimu.ai Content Provider (see https://github.com/elimu-ai/content-provider)
Log.i(getClass().getName(), "storyBook.getCoverImage(): " + storyBook.getCoverImage());
final ImageGson coverImage = ContentProviderHelper.getImageGson(storyBook.getCoverImage().getId(), getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
final ImageGson coverImage = ContentProviderUtil.getImageGson(storyBook.getCoverImage().getId(), getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
if (coverImage != null) {
final ImageView coverImageView = storyBookView.findViewById(R.id.coverImageView);
runOnUiThread(new Runnable() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
import java.util.List;

import ai.elimu.analytics.utils.LearningEventUtil;
import ai.elimu.content_provider.utils.ContentProviderHelper;
import ai.elimu.content_provider.utils.ContentProviderUtil;
import ai.elimu.model.enums.ReadingLevel;
import ai.elimu.model.enums.analytics.LearningEventType;
import ai.elimu.model.v2.gson.content.AudioGson;
Expand Down Expand Up @@ -132,7 +132,7 @@ public void onItemClick(WordGson wordWithAudio, View view, int position) {

WordDialogFragment.newInstance(wordWithAudio.getId()).show(getActivity().getSupportFragmentManager(), "dialog");

AudioGson audioGson = ContentProviderHelper.getAudioGsonByTranscription(wordWithAudio.getText().toLowerCase(), getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
AudioGson audioGson = ContentProviderUtil.getAudioGsonByTranscription(wordWithAudio.getText().toLowerCase(), getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
Log.i(getClass().getName(), "audioGson: " + audioGson);
if (audioGson != null) {
playAudioFile(audioGson);
Expand Down Expand Up @@ -194,7 +194,7 @@ public void playAudio(final String chapterText, final AudioListener audioListene
StoryBookParagraphGson storyBookParagraphGson = storyBookParagraphs.get(0);
String transcription = storyBookParagraphGson.getOriginalText();
Log.i(getClass().getName(), "transcription: \"" + transcription + "\"");
AudioGson audioGson = ContentProviderHelper.getAudioGsonByTranscription(transcription, getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
AudioGson audioGson = ContentProviderUtil.getAudioGsonByTranscription(transcription, getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
Log.i(getClass().getName(), "audioGson: " + audioGson);
if (audioGson != null) {
playAudioFile(audioGson);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import java.util.List;

import ai.elimu.content_provider.utils.ContentProviderHelper;
import ai.elimu.content_provider.utils.ContentProviderUtil;
import ai.elimu.model.enums.ReadingLevel;
import ai.elimu.model.v2.gson.content.StoryBookChapterGson;
import ai.elimu.vitabu.BuildConfig;
Expand All @@ -34,7 +34,7 @@ protected void onCreate(Bundle savedInstanceState) {
String description = getIntent().getStringExtra(EXTRA_KEY_STORYBOOK_DESCRIPTION);

// Fetch StoryBookChapters from the elimu.ai Content Provider (see https://github.com/elimu-ai/content-provider)
List<StoryBookChapterGson> storyBookChapters = ContentProviderHelper.getStoryBookChapterGsons(storyBookId, getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
List<StoryBookChapterGson> storyBookChapters = ContentProviderUtil.getStoryBookChapterGsons(storyBookId, getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);

ViewPager viewPager = findViewById(R.id.view_pager);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

import java.util.List;

import ai.elimu.content_provider.utils.ContentProviderHelper;
import ai.elimu.content_provider.utils.ContentProviderUtil;
import ai.elimu.model.v2.gson.content.EmojiGson;
import ai.elimu.model.v2.gson.content.WordGson;
import ai.elimu.vitabu.BuildConfig;
Expand Down Expand Up @@ -52,14 +52,14 @@ public void onViewCreated(View view, Bundle savedInstanceState) {
Long wordId = getArguments().getLong(ARG_WORD_ID);
Log.i(WordDialogFragment.class.getName(), "wordId: " + wordId);

WordGson wordGson = ContentProviderHelper.getWordGson(wordId, getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
WordGson wordGson = ContentProviderUtil.getWordGson(wordId, getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
Log.i(WordDialogFragment.class.getName(), "wordGson: " + wordGson);

TextView textView = view.findViewById(R.id.wordTextView);
textView.setText(wordGson.getText());

// Append Emojis (if any) below the Word
List<EmojiGson> emojiGsons = ContentProviderHelper.getEmojiGsons(wordGson.getId(), getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
List<EmojiGson> emojiGsons = ContentProviderUtil.getAllEmojiGsons(wordGson.getId(), getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
if (!emojiGsons.isEmpty()) {
textView.setText(textView.getText() + "\n");
for (EmojiGson emojiGson : emojiGsons) {
Expand Down
43 changes: 29 additions & 14 deletions app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

import ai.elimu.content_provider.utils.ContentProviderUtil;
import ai.elimu.model.v2.gson.content.EmojiGson;
import ai.elimu.model.v2.gson.content.WordGson;
import ai.elimu.vitabu.BuildConfig;
import ai.elimu.vitabu.R;

import static android.view.View.GONE;
Expand Down Expand Up @@ -59,12 +63,9 @@ public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, final int
((WordViewHolder) holder).paintWordLayout(wordsInOriginalText.get(position), words.get(position), readingLevelPosition);

if (words.get(position) != null) {
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
listener.onItemClick(words.get(position), v, position);
}
});
holder.itemView.setOnClickListener(v ->
listener.onItemClick(words.get(position), v, position)
);
}
}
}
Expand Down Expand Up @@ -111,27 +112,41 @@ public EmptyViewHolder(@NonNull View itemView) {

public static class WordViewHolder extends RecyclerView.ViewHolder {

private final TextView wordText;
private final TextView wordTextView;
private final TextView wordEmoji;
private final View wordUnderline;

public WordViewHolder(@NonNull View itemView) {
super(itemView);
wordText = itemView.findViewById(R.id.word_text);
wordTextView = itemView.findViewById(R.id.word_text);
wordUnderline = itemView.findViewById(R.id.word_underline);
wordEmoji = itemView.findViewById(R.id.word_emoji);
}

public void paintWordLayout(String word, WordGson wordWithAudio, int readingLevelPosition) {
paintWord(word, readingLevelPosition);
public void paintWordLayout(String wordText, WordGson wordWithAudio, int readingLevelPosition) {
long wordId = -1;
if (wordWithAudio != null)
wordId = wordWithAudio.getId();

paintWord(wordId, wordText, readingLevelPosition);
paintUnderline(wordWithAudio);
}

private void paintWord(String word, int readingLevelPosition) {
wordText.setText(word);
setTextSizeByLevel(wordText, readingLevelPosition);
private void paintWord(long wordId, String wordText, int readingLevelPosition) {
wordTextView.setText(wordText);
setTextSizeByLevel(wordTextView, readingLevelPosition);

if (word.isEmpty()) {
if (wordText.isEmpty()) {
itemView.getLayoutParams().width = 0;
}

if (wordId != -1) {
List<EmojiGson> emojiGsons = ContentProviderUtil.getAllEmojiGsons(wordId, itemView.getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID);
if (!emojiGsons.isEmpty()) {
wordEmoji.setText(emojiGsons.stream().map(EmojiGson::getGlyph).collect(Collectors.joining("")));
setTextSizeByLevel(wordEmoji, readingLevelPosition);
}
}
}

private void setTextSizeByLevel(TextView textView, int readingLevelPosition) {
Expand Down
10 changes: 10 additions & 0 deletions app/src/main/res/layout/word_layout.xml
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,14 @@
app:layout_constraintStart_toStartOf="@id/word_text"
app:layout_constraintEnd_toEndOf="@id/word_text"
tools:visibility="visible"/>

<TextView
android:id="@+id/word_emoji"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:textSize="32sp"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintStart_toEndOf="@id/word_text"
tools:text="emoji" />
</androidx.constraintlayout.widget.ConstraintLayout>

0 comments on commit 7ca9210

Please sign in to comment.