From cc613a2c67e9b800b07a3ba650d4b5baab065328 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Mon, 12 Apr 2021 00:31:01 +0200 Subject: [PATCH 1/4] #67 update content-provider --- app/build.gradle | 2 +- .../main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java | 6 +++--- .../java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java | 6 +++--- .../ai/elimu/vitabu/ui/storybook/StoryBookActivity.java | 4 ++-- .../ai/elimu/vitabu/ui/storybook/WordDialogFragment.java | 6 +++--- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 83344aa..24102d3 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -41,7 +41,7 @@ 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' diff --git a/app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java b/app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java index e91bb68..b283176 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java @@ -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; @@ -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()); } @@ -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() { diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java index 8e42b24..b97898d 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterFragment.java @@ -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; @@ -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); @@ -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); diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/StoryBookActivity.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/StoryBookActivity.java index 2257336..b20d544 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/StoryBookActivity.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/StoryBookActivity.java @@ -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; @@ -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 storyBookChapters = ContentProviderHelper.getStoryBookChapterGsons(storyBookId, getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID); + List storyBookChapters = ContentProviderUtil.getStoryBookChapterGsons(storyBookId, getApplicationContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID); ViewPager viewPager = findViewById(R.id.view_pager); diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordDialogFragment.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordDialogFragment.java index e642e3a..cec5fbf 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordDialogFragment.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordDialogFragment.java @@ -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; @@ -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 emojiGsons = ContentProviderHelper.getEmojiGsons(wordGson.getId(), getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID); + List emojiGsons = ContentProviderUtil.getAllEmojiGsons(wordGson.getId(), getContext(), BuildConfig.CONTENT_PROVIDER_APPLICATION_ID); if (!emojiGsons.isEmpty()) { textView.setText(textView.getText() + "\n"); for (EmojiGson emojiGson : emojiGsons) { From a874d4e179422e02f716a632cea2b82a7dc496d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Mon, 19 Apr 2021 00:03:50 +0200 Subject: [PATCH 2/4] #67 upgrade to java version 1.8 --- app/build.gradle | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/app/build.gradle b/app/build.gradle index 24102d3..d425072 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -35,6 +35,11 @@ android { buildConfigField("String", "ANALYTICS_APPLICATION_ID", '"ai.elimu.analytics"') } } + + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } } dependencies { From ebb2dbbcde7a37c55570026fe3c2c12f1e4b0692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Mon, 19 Apr 2021 00:05:34 +0200 Subject: [PATCH 3/4] #67 display emojis behind words --- .../vitabu/ui/storybook/WordViewAdapter.java | 31 ++++++++++++++----- app/src/main/res/layout/word_layout.xml | 10 ++++++ 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java index 2b32095..8a2e802 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java @@ -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; @@ -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) + ); } } } @@ -112,26 +113,40 @@ public EmptyViewHolder(@NonNull View itemView) { public static class WordViewHolder extends RecyclerView.ViewHolder { private final TextView wordText; + private final TextView wordEmoji; private final View wordUnderline; public WordViewHolder(@NonNull View itemView) { super(itemView); wordText = 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); + long wordId = -1; + if (wordWithAudio != null) + wordId = wordWithAudio.getId(); + + paintWord(wordId, word, readingLevelPosition); paintUnderline(wordWithAudio); } - private void paintWord(String word, int readingLevelPosition) { + private void paintWord(long wordId, String word, int readingLevelPosition) { wordText.setText(word); setTextSizeByLevel(wordText, readingLevelPosition); if (word.isEmpty()) { itemView.getLayoutParams().width = 0; } + + if (wordId != -1) { + List 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) { diff --git a/app/src/main/res/layout/word_layout.xml b/app/src/main/res/layout/word_layout.xml index 45d9335..7a16d12 100644 --- a/app/src/main/res/layout/word_layout.xml +++ b/app/src/main/res/layout/word_layout.xml @@ -31,4 +31,14 @@ app:layout_constraintStart_toStartOf="@id/word_text" app:layout_constraintEnd_toEndOf="@id/word_text" tools:visibility="visible"/> + + \ No newline at end of file From b946183f3a12c9ee51474be18f292fb1031913bd Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Tue, 20 Apr 2021 00:05:26 +0200 Subject: [PATCH 4/4] #67 rename word and wordText --- .../vitabu/ui/storybook/WordViewAdapter.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java index 8a2e802..2055cd1 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/WordViewAdapter.java @@ -112,31 +112,31 @@ 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) { + public void paintWordLayout(String wordText, WordGson wordWithAudio, int readingLevelPosition) { long wordId = -1; if (wordWithAudio != null) wordId = wordWithAudio.getId(); - paintWord(wordId, word, readingLevelPosition); + paintWord(wordId, wordText, readingLevelPosition); paintUnderline(wordWithAudio); } - private void paintWord(long wordId, 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; }