Skip to content

Commit

Permalink
Fixes #1212: CompletedStoryList - Tablet (Portrait) (Lowfi) (#1419)
Browse files Browse the repository at this point in the history
* -Implemented low-fi UI for "CompletedStoryList" for landscape mode - tablet

* -Implemented low-fi UI for "CompletedStoryList" for portrait mode - tablet

* -added robolectric tests

* -some nit changes

Co-authored-by: Ben Henning <henning.benmax@gmail.com>
  • Loading branch information
MohamedMedhat1998 and BenHenning committed Aug 5, 2020
1 parent a099bfb commit ce6c082
Show file tree
Hide file tree
Showing 13 changed files with 261 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class CompletedStoryListActivityPresenter @Inject constructor(
.beginTransaction()
.add(
R.id.completed_story_list_fragment_placeholder,
CompletedStoryListFragment.newInstance(internalProfileId)
CompletedStoryListFragment.newInstance(internalProfileId),
CompletedStoryListFragment.COMPLETED_STORY_LIST_FRAGMENT_TAG
).commitNow()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import javax.inject.Inject
/** Fragment for displaying completed stories. */
class CompletedStoryListFragment : InjectableFragment() {
companion object {
internal const val COMPLETED_STORY_LIST_FRAGMENT_TAG = "COMPLETED_STORY_LIST_FRAGMENT_TAG"
internal const val COMPLETED_STORY_LIST_FRAGMENT_PROFILE_ID_KEY =
"CompletedStoryListFragment.profile_id"

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package org.oppia.app.completedstorylist

import android.content.res.Configuration
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.appcompat.app.AppCompatActivity
import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.GridLayoutManager
import org.oppia.app.R
import org.oppia.app.databinding.CompletedStoryItemBinding
import org.oppia.app.databinding.CompletedStoryListFragmentBinding
import org.oppia.app.recyclerview.BindableAdapter
Expand Down Expand Up @@ -40,12 +40,7 @@ class CompletedStoryListFragmentPresenter @Inject constructor(
(activity as CompletedStoryListActivity).finish()
}
binding.completedStoryList.apply {
val spanCount =
if (fragment.resources.configuration.orientation == Configuration.ORIENTATION_LANDSCAPE) {
3
} else {
2
}
val spanCount = activity.resources.getInteger(R.integer.completed_story_span_count)
layoutManager = GridLayoutManager(context, spanCount)
adapter = createRecyclerViewAdapter()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
android:paddingTop="28dp"
android:paddingBottom="88dp"
android:scrollbars="none"
android:tag="@string/completed_story_list_recyclerview_tag"
app:data="@{viewModel.completedStoryListLiveData}" />

<View
Expand Down
94 changes: 94 additions & 0 deletions app/src/main/res/layout-sw600dp-port/completed_story_item.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<import type="android.view.View" />

<variable
name="viewModel"
type="org.oppia.app.completedstorylist.CompletedStoryItemViewModel" />
</data>

<com.google.android.material.card.MaterialCardView
android:id="@+id/topic_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="12dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="12dp"
app:cardCornerRadius="4dp">

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true">

<ImageView
android:id="@+id/completed_story_lesson_thumbnail"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/topicThumbnailBackground"
android:importantForAccessibility="no"
android:contentDescription="@{viewModel.completedStory.storyName}"
android:scaleType="centerInside"
android:src="@{viewModel.completedStory.lessonThumbnail.thumbnailGraphic}"
app:layout_constraintDimensionRatio="4:3"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<androidx.constraintlayout.widget.ConstraintLayout
android:id="@+id/constraintLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/completed_story_lesson_thumbnail">

<TextView
android:id="@+id/completed_story_name_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:ellipsize="end"
android:fontFamily="sans-serif"
android:gravity="top"
android:maxLines="2"
android:minLines="2"
android:text="@{viewModel.completedStory.storyName}"
android:textColor="@color/oppiaPrimaryText"
android:textSize="14sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

<TextView
android:id="@+id/completed_story_topic_name_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="4dp"
android:layout_marginEnd="8dp"
android:fontFamily="sans-serif-light"
android:paddingBottom="12dp"
android:textAllCaps="true"
android:ellipsize="end"
android:text="@{viewModel.completedStory.topicName}"
android:textColor="@color/oppiaStrokeBlack"
android:textSize="14sp"
android:maxLines="1"
android:minLines="1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/completed_story_name_text_view" />
</androidx.constraintlayout.widget.ConstraintLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</com.google.android.material.card.MaterialCardView>
</layout>
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?xml version="1.0" encoding="utf-8"?>
<layout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">

<data>

<variable
name="viewModel"
type="org.oppia.app.completedstorylist.CompletedStoryListViewModel" />
</data>

<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white">

<com.google.android.material.appbar.AppBarLayout
android:id="@+id/completed_story_list_app_bar_layout"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">

<androidx.appcompat.widget.Toolbar
android:id="@+id/completed_story_list_toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
android:fontFamily="sans-serif"
android:minHeight="?attr/actionBarSize"
android:textSize="20sp"
app:navigationContentDescription="@string/go_to_previous_page"
app:navigationIcon="?attr/homeAsUpIndicator"
app:title="@string/stories_completed"
app:titleTextColor="@color/white" />
</com.google.android.material.appbar.AppBarLayout>

<FrameLayout
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@id/completed_story_list_app_bar_layout">

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/completed_story_list"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clipToPadding="false"
android:overScrollMode="never"
android:paddingStart="20dp"
android:paddingTop="20dp"
android:paddingEnd="20dp"
android:paddingBottom="144dp"
android:scrollbars="none"
android:tag="@string/completed_story_list_recyclerview_tag"
app:data="@{viewModel.completedStoryListLiveData}" />

<View
android:id="@+id/completed_story_list_shadow_view"
android:layout_width="match_parent"
android:layout_height="6dp"
android:background="@drawable/toolbar_drop_shadow" />
</FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>
</layout>
1 change: 1 addition & 0 deletions app/src/main/res/layout/completed_story_list_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
android:paddingEnd="20dp"
android:paddingBottom="144dp"
android:scrollbars="none"
android:tag="@string/completed_story_list_recyclerview_tag"
app:data="@{viewModel.completedStoryListLiveData}" />

<View
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values-land/integers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<integer name="profile_chooser_first_time_span_count">2</integer>
<integer name="topic_revision_span_count">3</integer>
<integer name="ongoing_topics_span_count">3</integer>
<integer name="completed_story_span_count">3</integer>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-sw600dp-land/integers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@
<integer name="recently_played_span_count">4</integer>
<integer name="topic_revision_span_count">4</integer>
<integer name="ongoing_topics_span_count">4</integer>
<integer name="completed_story_span_count">4</integer>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values-sw600dp-port/integers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@
<integer name="profile_chooser_span_count">3</integer>
<integer name="topic_revision_span_count">3</integer>
<integer name="ongoing_topics_span_count">3</integer>
<integer name="completed_story_span_count">3</integer>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/integers.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@
<integer name="recently_played_span_count">2</integer>
<integer name="topic_revision_span_count">2</integer>
<integer name="ongoing_topics_span_count">2</integer>
<integer name="completed_story_span_count">2</integer>
</resources>
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -360,4 +360,5 @@
<!-- ViewTags -->
<string name="topic_revision_recyclerview_tag">topic_revision_recyclerview_tag</string>
<string name="ongoing_recycler_view_tag">ongoing_recycler_view_tag</string>
<string name="completed_story_list_recyclerview_tag">completed_story_list_recyclerview_tag</string>
</resources>
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
package org.oppia.app.testing

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.RecyclerView
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.intent.Intents
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.google.firebase.FirebaseApp
import kotlinx.coroutines.ExperimentalCoroutinesApi
import org.junit.After
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.app.R
import org.oppia.app.completedstorylist.CompletedStoryListActivity
import org.oppia.app.completedstorylist.CompletedStoryListFragment.Companion.COMPLETED_STORY_LIST_FRAGMENT_TAG
import org.robolectric.annotation.Config

@RunWith(AndroidJUnit4::class)
class CompletedStoryListSpanTest {

@Before
@ExperimentalCoroutinesApi
fun setUp() {
Intents.init()
FirebaseApp.initializeApp(ApplicationProvider.getApplicationContext())
}

@After
fun tearDown() {
Intents.release()
}

private fun getCompletedStoryListSpanCount(activity: CompletedStoryListActivity): Int {
val completedStoryListFragment =
activity.supportFragmentManager.findFragmentByTag(COMPLETED_STORY_LIST_FRAGMENT_TAG)
val completedStoryListRecyclerVIew =
completedStoryListFragment?.view?.findViewWithTag<RecyclerView>(
activity.resources.getString(
R.string.completed_story_list_recyclerview_tag
)
)
return (completedStoryListRecyclerVIew?.layoutManager as GridLayoutManager).spanCount
}

@Test
fun testCompletedStoryList_checkRecyclerViewSpanCount_spanIsCorrect() {
launch(CompletedStoryListActivity::class.java).use {
it.onActivity { activity ->
assertThat(getCompletedStoryListSpanCount(activity)).isEqualTo(2)
}
}
}

@Test
@Config(qualifiers = "land")
fun testCompletedStoryList_checkRecyclerViewSpanCount_land_spanIsCorrect() {
launch(CompletedStoryListActivity::class.java).use {
it.onActivity { activity ->
assertThat(getCompletedStoryListSpanCount(activity)).isEqualTo(3)
}
}
}

@Test
@Config(qualifiers = "sw600dp-port")
fun testCompletedStoryList_checkRecyclerViewSpanCount_tabletPort_spanIsCorrect() {
launch(CompletedStoryListActivity::class.java).use {
it.onActivity { activity ->
assertThat(getCompletedStoryListSpanCount(activity)).isEqualTo(3)
}
}
}

@Test
@Config(qualifiers = "sw600dp-land")
fun testCompletedStoryList_checkRecyclerViewSpanCount_tabletLand_spanIsCorrect() {
launch(CompletedStoryListActivity::class.java).use {
it.onActivity { activity ->
assertThat(getCompletedStoryListSpanCount(activity)).isEqualTo(4)
}
}
}
}

0 comments on commit ce6c082

Please sign in to comment.