From ce6c082df80234b12e1b980c2ab305a789592bea Mon Sep 17 00:00:00 2001 From: Mohamed Medhat Date: Wed, 5 Aug 2020 21:05:37 +0200 Subject: [PATCH] Fixes #1212: CompletedStoryList - Tablet (Portrait) (Lowfi) (#1419) * -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 --- .../CompletedStoryListActivityPresenter.kt | 3 +- .../CompletedStoryListFragment.kt | 1 + .../CompletedStoryListFragmentPresenter.kt | 9 +- .../completed_story_list_fragment.xml | 1 + .../completed_story_item.xml | 94 +++++++++++++++++++ .../completed_story_list_fragment.xml | 69 ++++++++++++++ .../layout/completed_story_list_fragment.xml | 1 + app/src/main/res/values-land/integers.xml | 1 + .../main/res/values-sw600dp-land/integers.xml | 1 + .../main/res/values-sw600dp-port/integers.xml | 1 + app/src/main/res/values/integers.xml | 1 + app/src/main/res/values/strings.xml | 1 + .../app/testing/CompletedStoryListSpanTest.kt | 86 +++++++++++++++++ 13 files changed, 261 insertions(+), 8 deletions(-) create mode 100644 app/src/main/res/layout-sw600dp-port/completed_story_item.xml create mode 100644 app/src/main/res/layout-sw600dp-port/completed_story_list_fragment.xml create mode 100644 app/src/test/java/org/oppia/app/testing/CompletedStoryListSpanTest.kt diff --git a/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListActivityPresenter.kt b/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListActivityPresenter.kt index 6de7c74bddf..ea8886caab6 100644 --- a/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListActivityPresenter.kt +++ b/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListActivityPresenter.kt @@ -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() } } diff --git a/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragment.kt b/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragment.kt index 2d0e6a6128b..0e103d615eb 100644 --- a/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragment.kt +++ b/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragment.kt @@ -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" diff --git a/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragmentPresenter.kt b/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragmentPresenter.kt index 85456168a76..e1f54da4ead 100644 --- a/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/completedstorylist/CompletedStoryListFragmentPresenter.kt @@ -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 @@ -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() } diff --git a/app/src/main/res/layout-land/completed_story_list_fragment.xml b/app/src/main/res/layout-land/completed_story_list_fragment.xml index 504f0b8fefe..12065a959a6 100644 --- a/app/src/main/res/layout-land/completed_story_list_fragment.xml +++ b/app/src/main/res/layout-land/completed_story_list_fragment.xml @@ -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}" /> + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout-sw600dp-port/completed_story_list_fragment.xml b/app/src/main/res/layout-sw600dp-port/completed_story_list_fragment.xml new file mode 100644 index 00000000000..1e1eda0f294 --- /dev/null +++ b/app/src/main/res/layout-sw600dp-port/completed_story_list_fragment.xml @@ -0,0 +1,69 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/completed_story_list_fragment.xml b/app/src/main/res/layout/completed_story_list_fragment.xml index 5ea960c604d..1e1eda0f294 100644 --- a/app/src/main/res/layout/completed_story_list_fragment.xml +++ b/app/src/main/res/layout/completed_story_list_fragment.xml @@ -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}" /> 2 3 3 + 3 diff --git a/app/src/main/res/values-sw600dp-land/integers.xml b/app/src/main/res/values-sw600dp-land/integers.xml index 2ecc318b2a6..aab20513dfc 100644 --- a/app/src/main/res/values-sw600dp-land/integers.xml +++ b/app/src/main/res/values-sw600dp-land/integers.xml @@ -5,4 +5,5 @@ 4 4 4 + 4 diff --git a/app/src/main/res/values-sw600dp-port/integers.xml b/app/src/main/res/values-sw600dp-port/integers.xml index edeecb6b27d..1266046bb71 100644 --- a/app/src/main/res/values-sw600dp-port/integers.xml +++ b/app/src/main/res/values-sw600dp-port/integers.xml @@ -6,4 +6,5 @@ 3 3 3 + 3 diff --git a/app/src/main/res/values/integers.xml b/app/src/main/res/values/integers.xml index 8dcc06fa9d2..5a16533a267 100644 --- a/app/src/main/res/values/integers.xml +++ b/app/src/main/res/values/integers.xml @@ -10,4 +10,5 @@ 2 2 2 + 2 diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 0dd6c5c0aff..9b120625c9d 100755 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -360,4 +360,5 @@ topic_revision_recyclerview_tag ongoing_recycler_view_tag + completed_story_list_recyclerview_tag diff --git a/app/src/test/java/org/oppia/app/testing/CompletedStoryListSpanTest.kt b/app/src/test/java/org/oppia/app/testing/CompletedStoryListSpanTest.kt new file mode 100644 index 00000000000..eca0de7520d --- /dev/null +++ b/app/src/test/java/org/oppia/app/testing/CompletedStoryListSpanTest.kt @@ -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( + 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) + } + } + } +}