From be739a67ae29999165def8ee9b7020618b8dff69 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gema=20S=C3=A1nchez?= Date: Fri, 11 Dec 2020 20:12:23 +0100 Subject: [PATCH] #35 text size by reading level --- .../elimu/vitabu/ui/StoryBooksActivity.java | 1 + .../vitabu/ui/storybook/ChapterFragment.java | 16 ++++++++++++-- .../ui/storybook/ChapterPagerAdapter.java | 8 +++++-- .../ui/storybook/StoryBookActivity.java | 5 ++++- app/src/main/res/values/dimens.xml | 21 +++++++++++++++++++ 5 files changed, 46 insertions(+), 5 deletions(-) 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 cdb03b3..4e95f08 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java @@ -142,6 +142,7 @@ public void onSingleClick(View v) { Intent intent = new Intent(getApplicationContext(), StoryBookActivity.class); intent.putExtra(StoryBookActivity.EXTRA_KEY_STORYBOOK_ID, finalStoryBook.getId()); + intent.putExtra(StoryBookActivity.EXTRA_KEY_STORYBOOK_LEVEL, finalStoryBook.getReadingLevel()); startActivity(intent); } }); 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 bb75c78..6f41712 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 @@ -19,7 +19,6 @@ import android.view.ViewGroup; import android.widget.ImageView; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.fragment.app.Fragment; @@ -33,6 +32,7 @@ import ai.elimu.analytics.utils.LearningEventUtil; import ai.elimu.content_provider.utils.ContentProviderHelper; +import ai.elimu.model.enums.ReadingLevel; import ai.elimu.model.enums.analytics.LearningEventType; import ai.elimu.model.v2.gson.content.AudioGson; import ai.elimu.model.v2.gson.content.ImageGson; @@ -46,6 +46,7 @@ public class ChapterFragment extends Fragment { private static final String ARG_CHAPTER_INDEX = "chapter_index"; + private static final String ARG_READING_LEVEL = "reading_level"; private StoryBookChapterGson storyBookChapter; @@ -53,10 +54,11 @@ public class ChapterFragment extends Fragment { private TextToSpeech tts; - public static ChapterFragment newInstance(int chapterIndex) { + public static ChapterFragment newInstance(int chapterIndex, ReadingLevel readingLevel) { ChapterFragment fragment = new ChapterFragment(); Bundle bundle = new Bundle(); bundle.putInt(ARG_CHAPTER_INDEX, chapterIndex); + bundle.putSerializable(ARG_READING_LEVEL, readingLevel); fragment.setArguments(bundle); return fragment; } @@ -110,8 +112,18 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, chapterText += storyBookParagraphGson.getOriginalText(); } + ReadingLevel readingLevel = (ReadingLevel) getArguments().get(ARG_READING_LEVEL); + int readingLevelPosition = (readingLevel == null) ? 0 : readingLevel.ordinal(); + + int[] fontSize = getResources().getIntArray(R.array.chapter_text_font_size); + String[] letterSpacing = getResources().getStringArray(R.array.chapter_text_letter_spacing); + String[] lineSpacing = getResources().getStringArray(R.array.chapter_text_line_spacing); + TextView textView = root.findViewById(R.id.chapter_text); textView.setText(chapterText); + textView.setTextSize(fontSize[readingLevelPosition]); + textView.setLetterSpacing(Float.parseFloat(letterSpacing[readingLevelPosition])); + textView.setLineSpacing(0, Float.parseFloat(lineSpacing[readingLevelPosition])); textView.setVisibility(View.VISIBLE); } diff --git a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterPagerAdapter.java b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterPagerAdapter.java index 38a56ae..bd62eb5 100644 --- a/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterPagerAdapter.java +++ b/app/src/main/java/ai/elimu/vitabu/ui/storybook/ChapterPagerAdapter.java @@ -9,6 +9,7 @@ import java.util.List; +import ai.elimu.model.enums.ReadingLevel; import ai.elimu.model.v2.gson.content.StoryBookChapterGson; public class ChapterPagerAdapter extends FragmentPagerAdapter { @@ -17,15 +18,18 @@ public class ChapterPagerAdapter extends FragmentPagerAdapter { public static List storyBookChapters; - public ChapterPagerAdapter(FragmentManager fm, Context context, List storyBookChapters) { + private ReadingLevel readingLevel; + + public ChapterPagerAdapter(FragmentManager fm, Context context, List storyBookChapters, ReadingLevel readingLevel) { super(fm); this.context = context; this.storyBookChapters = storyBookChapters; + this.readingLevel = readingLevel; } @Override public Fragment getItem(int position) { - return ChapterFragment.newInstance(position); + return ChapterFragment.newInstance(position, readingLevel); } @Nullable 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 0f7f8c7..7ad40d1 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 @@ -9,6 +9,7 @@ import java.util.List; import ai.elimu.content_provider.utils.ContentProviderHelper; +import ai.elimu.model.enums.ReadingLevel; import ai.elimu.model.v2.gson.content.StoryBookChapterGson; import ai.elimu.vitabu.BuildConfig; import ai.elimu.vitabu.R; @@ -17,6 +18,7 @@ public class StoryBookActivity extends AppCompatActivity { public static final String EXTRA_KEY_STORYBOOK_ID = "EXTRA_KEY_STORYBOOK_ID"; + public static final String EXTRA_KEY_STORYBOOK_LEVEL = "EXTRA_KEY_STORYBOOK_LEVEL"; @Override protected void onCreate(Bundle savedInstanceState) { @@ -27,13 +29,14 @@ protected void onCreate(Bundle savedInstanceState) { Long storyBookId = getIntent().getLongExtra(EXTRA_KEY_STORYBOOK_ID, 0); Log.i(getClass().getName(), "storyBookId: " + storyBookId); + ReadingLevel readingLevel = (ReadingLevel) getIntent().getSerializableExtra(EXTRA_KEY_STORYBOOK_LEVEL); // 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); ViewPager viewPager = findViewById(R.id.view_pager); - ChapterPagerAdapter chapterPagerAdapter = new ChapterPagerAdapter(getSupportFragmentManager(), this, storyBookChapters); + ChapterPagerAdapter chapterPagerAdapter = new ChapterPagerAdapter(getSupportFragmentManager(), this, storyBookChapters, readingLevel); viewPager.setAdapter(chapterPagerAdapter); ZoomOutPageTransformer zoomOutPageTransformer = new ZoomOutPageTransformer(); diff --git a/app/src/main/res/values/dimens.xml b/app/src/main/res/values/dimens.xml index fc5bbbe..96c2fc8 100644 --- a/app/src/main/res/values/dimens.xml +++ b/app/src/main/res/values/dimens.xml @@ -4,4 +4,25 @@ 16dp 16dp 16dp + + + 32 + 30 + 28 + 26 + + + + 0.2 + 0.15 + 0.1 + 0.05 + + + + 1.5 + 1.4 + 1.3 + 1.2 +