Skip to content

Commit

Permalink
#26 group storyBooks by readingLevel
Browse files Browse the repository at this point in the history
  • Loading branch information
gscdev committed Dec 10, 2020
1 parent 5073861 commit 7042065
Show file tree
Hide file tree
Showing 7 changed files with 67 additions and 5 deletions.
45 changes: 40 additions & 5 deletions app/src/main/java/ai/elimu/vitabu/ui/StoryBooksActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,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.ImageGson;
import ai.elimu.model.v2.gson.content.StoryBookGson;
Expand Down Expand Up @@ -68,12 +69,45 @@ protected void onStart() {
((BaseApplication) getApplication()).getExecutor().execute(new Runnable() {
@Override
public void run() {

StoryBookGson storyBook;
ReadingLevel readingLevel;

// Create a View for each StoryBook in the list
for (final StoryBookGson storyBook : storyBooks) {
for (int index = 0; index < storyBooks.size(); index++) {
storyBook = storyBooks.get(index);
readingLevel = storyBook.getReadingLevel();

Log.i(getClass().getName(), "storyBook.getId(): " + storyBook.getId());
Log.i(getClass().getName(), "storyBook.getTitle(): \"" + storyBook.getTitle() + "\"");
Log.i(getClass().getName(), "storyBook.getDescription(): \"" + storyBook.getDescription() + "\"");

if (index == 0 || readingLevel != storyBooks.get(index - 1).getReadingLevel()) {
final View levelLayout = LayoutInflater.from(StoryBooksActivity.this).inflate(R.layout.activity_storybooks_level, storyBooksGridLayout, false);

GridLayout.LayoutParams layoutParams = new GridLayout.LayoutParams();
layoutParams.columnSpec = GridLayout.spec(0, getResources().getInteger(R.integer.gridlayout_column_count));
levelLayout.setLayoutParams(layoutParams);

final TextView levelTextView = levelLayout.findViewById(R.id.levelName);
if (readingLevel == null) {
levelTextView.setVisibility(View.GONE);
} else {
levelTextView.setText(String.format(getResources().getString(R.string.level), readingLevel.ordinal()+1));
}

runOnUiThread(new Runnable() {
@Override
public void run() {
storyBooksGridLayout.addView(levelLayout);
if (storyBooksGridLayout.getChildCount() == storyBooks.size()) {
storyBooksProgressBar.setVisibility(View.GONE);
storyBooksGridLayout.setVisibility(View.VISIBLE);
}
}
});
}

final View storyBookView = LayoutInflater.from(StoryBooksActivity.this).inflate(R.layout.activity_storybooks_cover_view, storyBooksGridLayout, false);

// Fetch Image from the elimu.ai Content Provider (see https://github.com/elimu-ai/content-provider)
Expand All @@ -94,19 +128,20 @@ public void run() {
TextView coverTitleTextView = storyBookView.findViewById(R.id.coverTitleTextView);
coverTitleTextView.setText(storyBook.getTitle());

final StoryBookGson finalStoryBook = storyBook;
storyBookView.setOnClickListener(new SingleClickListener() {
@Override
public void onSingleClick(View v) {
Log.i(getClass().getName(), "onClick");

Log.i(getClass().getName(), "storyBook.getId(): " + storyBook.getId());
Log.i(getClass().getName(), "storyBook.getTitle(): " + storyBook.getTitle());
Log.i(getClass().getName(), "storyBook.getId(): " + finalStoryBook.getId());
Log.i(getClass().getName(), "storyBook.getTitle(): " + finalStoryBook.getTitle());

// Report learning event to the Analytics application (https://github.com/elimu-ai/analytics)
LearningEventUtil.reportStoryBookLearningEvent(storyBook, LearningEventType.STORYBOOK_OPENED, getApplicationContext(), BuildConfig.ANALYTICS_APPLICATION_ID);
LearningEventUtil.reportStoryBookLearningEvent(finalStoryBook, LearningEventType.STORYBOOK_OPENED, getApplicationContext(), BuildConfig.ANALYTICS_APPLICATION_ID);

Intent intent = new Intent(getApplicationContext(), StoryBookActivity.class);
intent.putExtra(StoryBookActivity.EXTRA_KEY_STORYBOOK_ID, storyBook.getId());
intent.putExtra(StoryBookActivity.EXTRA_KEY_STORYBOOK_ID, finalStoryBook.getId());
startActivity(intent);
}
});
Expand Down
22 changes: 22 additions & 0 deletions app/src/main/res/layout/activity_storybooks_level.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
xmlns:app="http://schemas.android.com/apk/res-auto">

<TextView
android:id="@+id/levelName"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
android:layout_marginTop="16dp"
android:layout_marginBottom="8dp"
android:padding="8dp"
android:background="@android:color/darker_gray"
android:textColor="@android:color/white"
android:textAppearance="?android:attr/textAppearanceMedium"
tools:text="LEVEL 1"/>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions app/src/main/res/values-bn/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">বই</string>
<string name="level">LEVEL %d</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-fil/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Mga Libro</string>
<string name="level">LEVEL %d</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-hi/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">पुस्तकें</string>
<string name="level">LEVEL %d</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-sw/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Vitabu</string>
<string name="level">LEVEL %d</string>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
<resources>
<string name="app_name">Books</string>
<string name="level">LEVEL %d</string>
</resources>

0 comments on commit 7042065

Please sign in to comment.