Skip to content

Commit

Permalink
Topic issues fixs (#321)
Browse files Browse the repository at this point in the history
* multiple tabs

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* cust_args

* test cases,multiple tabs will getting topic id from home
Merge branch 'develop' of https://github.com/oppia/oppia-android into topic-player-multiple-tabs

# Conflicts:
#	app/src/main/AndroidManifest.xml
#	app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt
#	domain/src/main/java/org/oppia/domain/exploration/ExplorationRetriever.kt

* nit

* nit

* nit

* nit

* nit

* separate test cases for all four tabs

* nit

* nit

* nit

* nit

* nit

* nit

* nit

* nit

* Topic Overview see more click and tab switch

* Topic Overview see more click and tab switch

* Topic Overview see more click and tab switch

* topic id todo's are implemented, test cases updated as per new data through topic id

* Topic Overview see more click and tab switch

* nit

* nit

* merged with base branch

* nit

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* revert back to develop

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* nit changes

* set title on the basis of selected topic in topic screen.other nit changes

* nit

* Merge branches 'develop' and 'topic-player-multiple-tabs' of https://github.com/oppia/oppia-android into topic-player-multiple-tabs

# Conflicts:
#	app/src/main/java/org/oppia/app/home/HomeActivity.kt
#	app/src/main/java/org/oppia/app/home/HomeFragmentPresenter.kt
#	app/src/main/java/org/oppia/app/topic/TopicActivity.kt
#	app/src/main/res/layout/home_fragment.xml

* nit

* nit

* nit

* nit

* Merge branches 'develop' and 'topic-player-multiple-tabs' of https://github.com/oppia/oppia-android into topic-player-multiple-tabs

# Conflicts:
#	app/src/main/AndroidManifest.xml

* nit in TopicFragmentPresenter changed var to val in line number 69

* nit

* shorten stackoverflow link,testcase method name change

* nit changes suggested by Rajat

* nit

* nit

* used enum to set current tab in TopicFragmentPresenter.
other nit changes.

* nit

* nit

* nit

* nit

* nit

* nit

* nit

* nit

* Fix #135:Topic issues fixes part 2 (#318)

* nit

* TopicTestActivityTest,TopicTestActivityForStory and TopicTestActivityForStoryTest
introdused for testing topic multiple tabs

* TopicTestActivityTest,TopicTestActivityForStory and TopicTestActivityForStoryTest
introdused for testing topic multiple tabs

* Removed Topic and Exploration Button from HomeFragment, Removed topicButtonClick Implementation

* nit

* nit

* test cases fix due to change in data.

* nit

* nit

* nit

* nit
  • Loading branch information
nikitamarysolomanpvt authored Nov 11, 2019
1 parent adebdf4 commit ed6aa46
Show file tree
Hide file tree
Showing 14 changed files with 311 additions and 59 deletions.
6 changes: 6 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<activity android:name=".testing.ContentCardTestActivity" />
<activity android:name=".testing.HtmlParserTestActivity" />
<activity android:name=".testing.InputInteractionViewTestActivity" />
<activity
android:name=".testing.TopicTestActivity"
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".testing.TopicTestActivityForStory"
android:theme="@style/OppiaThemeWithoutActionBar" />
<activity
android:name=".topic.TopicActivity"
android:theme="@style/OppiaThemeWithoutActionBar" />
Expand Down
4 changes: 4 additions & 0 deletions app/src/main/java/org/oppia/app/activity/ActivityComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import org.oppia.app.testing.BindableAdapterTestActivity
import org.oppia.app.testing.ContentCardTestActivity
import org.oppia.app.testing.ContinuePlayingFragmentTestActivity
import org.oppia.app.testing.HtmlParserTestActivity
import org.oppia.app.testing.TopicTestActivity
import org.oppia.app.testing.TopicTestActivityForStory
import org.oppia.app.topic.TopicActivity
import org.oppia.app.topic.conceptcard.testing.ConceptCardFragmentTestActivity
import org.oppia.app.topic.questionplayer.QuestionPlayerActivity
Expand Down Expand Up @@ -49,5 +51,7 @@ interface ActivityComponent {
fun inject(stateFragmentTestActivity: StateFragmentTestActivity)
fun inject(storyActivity: StoryActivity)
fun inject(topicActivity: TopicActivity)
fun inject(topicTestActivity: TopicTestActivity)
fun inject(topicTestActivityForStory: TopicTestActivityForStory)
fun inject(storyFragmentTestActivity: StoryFragmentTestActivity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ import org.oppia.app.model.UserAppHistory
import org.oppia.domain.UserAppHistoryController
import org.oppia.domain.exploration.ExplorationDataController
import org.oppia.domain.exploration.TEST_EXPLORATION_ID_30
import org.oppia.domain.topic.TEST_TOPIC_ID_0
import org.oppia.domain.topic.TopicListController
import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
Expand All @@ -44,7 +43,6 @@ class HomeFragmentPresenter @Inject constructor(
private val routeToExplorationListener = activity as RouteToExplorationListener
private val routeToTopicListener = activity as RouteToTopicListener
private val itemList: MutableList<HomeItemViewModel> = ArrayList()

private lateinit var topicListAdapter: TopicListAdapter
private lateinit var binding: HomeFragmentBinding
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
Expand Down Expand Up @@ -97,11 +95,6 @@ class HomeFragmentPresenter @Inject constructor(
})
}

fun handleTopicButtonClicked(v: View) {
logger.d(TAG_HOME_FRAGMENT, "Successfully loaded topic")
routeToTopicListener.routeToTopic(TEST_TOPIC_ID_0)
}

private val topicListSummaryResultLiveData: LiveData<AsyncResult<TopicList>> by lazy {
topicListController.getTopicList()
}
Expand All @@ -112,7 +105,7 @@ class HomeFragmentPresenter @Inject constructor(
val promotedStoryViewModel = PromotedStoryViewModel(activity)
promotedStoryViewModel.setPromotedStory(result.promotedStory)
itemList.add(promotedStoryViewModel)
if(result.topicSummaryList.isNotEmpty()){
if (result.topicSummaryList.isNotEmpty()) {
val allTopicsViewModel = AllTopicsViewModel()
itemList.add(allTopicsViewModel)
}
Expand Down
64 changes: 64 additions & 0 deletions app/src/main/java/org/oppia/app/testing/TopicTestActivity.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package org.oppia.app.testing

import android.os.Bundle
import org.oppia.app.activity.InjectableAppCompatActivity
import org.oppia.app.home.RouteToExplorationListener
import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.story.StoryActivity
import org.oppia.app.topic.RouteToConceptCardListener
import org.oppia.app.topic.RouteToQuestionPlayerListener
import org.oppia.app.topic.RouteToStoryListener
import org.oppia.app.topic.RouteToTopicPlayListener
import org.oppia.app.topic.TOPIC_FRAGMENT_TAG
import org.oppia.app.topic.TopicActivityPresenter
import org.oppia.app.topic.TopicFragment
import org.oppia.app.topic.TopicTab
import org.oppia.app.topic.conceptcard.ConceptCardFragment
import org.oppia.app.topic.questionplayer.QuestionPlayerActivity
import org.oppia.domain.topic.TEST_TOPIC_ID_0
import javax.inject.Inject

/** The activity for testing [TopicFragment]. */
class TopicTestActivity : InjectableAppCompatActivity(), RouteToQuestionPlayerListener, RouteToConceptCardListener,
RouteToTopicPlayListener, RouteToStoryListener, RouteToExplorationListener {
@Inject
lateinit var topicActivityPresenter: TopicActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
topicActivityPresenter.handleOnCreate(topicId = TEST_TOPIC_ID_0, storyId = "")
}

override fun routeToQuestionPlayer(skillIdList: ArrayList<String>) {
startActivity(QuestionPlayerActivity.createQuestionPlayerActivityIntent(this, skillIdList))
}

override fun routeToStory(storyId: String) {
startActivity(StoryActivity.createStoryActivityIntent(this, storyId))
}

override fun routeToTopicPlayFragment() {
val topicFragment = supportFragmentManager.findFragmentByTag(TOPIC_FRAGMENT_TAG) as TopicFragment
topicFragment.topicFragmentPresenter.setCurrentTab(TopicTab.PLAY)
}

override fun routeToConceptCard(skillId: String) {
if (getConceptCardFragment() == null) {
val conceptCardFragment: ConceptCardFragment = ConceptCardFragment.newInstance(skillId)
conceptCardFragment.showNow(supportFragmentManager, TAG_CONCEPT_CARD_DIALOG)
}
}

override fun routeToExploration(explorationId: String) {
startActivity(ExplorationActivity.createExplorationActivityIntent(this, explorationId))
}

private fun getConceptCardFragment(): ConceptCardFragment? {
return supportFragmentManager.findFragmentByTag(TAG_CONCEPT_CARD_DIALOG) as ConceptCardFragment?
}

companion object {
internal const val TAG_CONCEPT_CARD_DIALOG = "CONCEPT_CARD_DIALOG"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package org.oppia.app.testing

import android.os.Bundle
import org.oppia.app.activity.InjectableAppCompatActivity
import org.oppia.app.home.RouteToExplorationListener
import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.story.StoryActivity
import org.oppia.app.topic.RouteToConceptCardListener
import org.oppia.app.topic.RouteToQuestionPlayerListener
import org.oppia.app.topic.RouteToStoryListener
import org.oppia.app.topic.RouteToTopicPlayListener
import org.oppia.app.topic.TOPIC_FRAGMENT_TAG
import org.oppia.app.topic.TopicActivityPresenter
import org.oppia.app.topic.TopicFragment
import org.oppia.app.topic.TopicTab
import org.oppia.app.topic.conceptcard.ConceptCardFragment
import org.oppia.app.topic.questionplayer.QuestionPlayerActivity
import org.oppia.domain.topic.TEST_STORY_ID_1
import org.oppia.domain.topic.TEST_TOPIC_ID_0
import javax.inject.Inject

/** The test activity for [TopicFragment] to test displaying story by storyId. */
class TopicTestActivityForStory : InjectableAppCompatActivity(), RouteToQuestionPlayerListener,
RouteToConceptCardListener,
RouteToTopicPlayListener, RouteToStoryListener, RouteToExplorationListener {
@Inject
lateinit var topicActivityPresenter: TopicActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
activityComponent.inject(this)
topicActivityPresenter.handleOnCreate(topicId = TEST_TOPIC_ID_0, storyId = TEST_STORY_ID_1)
}

override fun routeToQuestionPlayer(skillIdList: ArrayList<String>) {
startActivity(QuestionPlayerActivity.createQuestionPlayerActivityIntent(this, skillIdList))
}

override fun routeToStory(storyId: String) {
startActivity(StoryActivity.createStoryActivityIntent(this, storyId))
}

override fun routeToTopicPlayFragment() {
val topicFragment = supportFragmentManager.findFragmentByTag(TOPIC_FRAGMENT_TAG) as TopicFragment
topicFragment.topicFragmentPresenter.setCurrentTab(TopicTab.PLAY)
}

override fun routeToConceptCard(skillId: String) {
if (getConceptCardFragment() == null) {
val conceptCardFragment: ConceptCardFragment = ConceptCardFragment.newInstance(skillId)
conceptCardFragment.showNow(supportFragmentManager, TAG_CONCEPT_CARD_DIALOG)
}
}

override fun routeToExploration(explorationId: String) {
startActivity(ExplorationActivity.createExplorationActivityIntent(this, explorationId))
}

private fun getConceptCardFragment(): ConceptCardFragment? {
return supportFragmentManager.findFragmentByTag(TAG_CONCEPT_CARD_DIALOG) as ConceptCardFragment?
}

companion object {
internal const val TAG_CONCEPT_CARD_DIALOG = "CONCEPT_CARD_DIALOG"
}
}
3 changes: 1 addition & 2 deletions app/src/main/java/org/oppia/app/topic/TopicActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import org.oppia.app.player.exploration.ExplorationActivity
import org.oppia.app.story.StoryActivity
import org.oppia.app.topic.conceptcard.ConceptCardFragment
import org.oppia.app.topic.questionplayer.QuestionPlayerActivity
import org.oppia.domain.topic.TEST_TOPIC_ID_0
import javax.inject.Inject

const val TOPIC_ACTIVITY_TOPIC_ID_ARGUMENT_KEY = "TopicActivity.topic_id"
Expand All @@ -30,7 +29,7 @@ class TopicActivity : InjectableAppCompatActivity(), RouteToQuestionPlayerListen
"Expected topic ID to be included in intent for TopicActivity."
}
storyId = intent?.getStringExtra(TOPIC_ACTIVITY_STORY_ID_ARGUMENT_KEY) ?: ""
topicActivityPresenter.handleOnCreate(topicId)
topicActivityPresenter.handleOnCreate(topicId, storyId)
}

override fun routeToQuestionPlayer(skillIdList: ArrayList<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,20 @@ import javax.inject.Inject

const val TOPIC_FRAGMENT_TAG = "TopicFragment"
const val TOPIC_ID_ARGUMENT_KEY = "topic_id"
const val STORY_ID_ARGUMENT_KEY = "story_id"

/** The presenter for [TopicActivity]. */
@ActivityScope
class TopicActivityPresenter @Inject constructor(private val activity: AppCompatActivity) {
fun handleOnCreate(topicId: String) {

fun handleOnCreate(topicId: String, storyId: String) {
activity.setContentView(R.layout.topic_activity)
if (getTopicFragment() == null) {
val topicFragment = TopicFragment()
val args = Bundle()
args.putString(TOPIC_ID_ARGUMENT_KEY, topicId)
if (topicId.isNotEmpty() && storyId.isNotEmpty())
args.putString(STORY_ID_ARGUMENT_KEY, storyId)
topicFragment.arguments = args
activity.supportFragmentManager.beginTransaction().add(
R.id.topic_fragment_placeholder,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ class TopicFragmentPresenter @Inject constructor(
private lateinit var tabLayout: TabLayout
private lateinit var toolbar: Toolbar
private lateinit var topicId: String
lateinit var storyId: String
private lateinit var viewPager: ViewPager
private val tabIcons =
intArrayOf(
Expand All @@ -45,6 +46,7 @@ class TopicFragmentPresenter @Inject constructor(
): View? {
val binding = TopicFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.lifecycleOwner = fragment
storyId = fragment.arguments?.getString(STORY_ID_ARGUMENT_KEY) ?: ""
viewPager = binding.root.findViewById(R.id.topic_tabs_viewpager) as ViewPager
tabLayout = binding.root.findViewById(R.id.topic_tabs_container) as TabLayout
toolbar = binding.root.findViewById(R.id.toolbar) as Toolbar
Expand All @@ -59,13 +61,15 @@ class TopicFragmentPresenter @Inject constructor(
}

private fun setUpViewPager(viewPager: ViewPager, topicId: String?) {
val adapter = ViewPagerAdapter(fragment.fragmentManager!!, topicId!!)
val adapter = ViewPagerAdapter(fragment.fragmentManager!!, topicId!!, storyId)
viewPager.adapter = adapter
tabLayout.setupWithViewPager(viewPager)
tabLayout.getTabAt(0)!!.setText(fragment.getString(R.string.overview)).setIcon(tabIcons[0])
tabLayout.getTabAt(1)!!.setText(fragment.getString(R.string.play)).setIcon(tabIcons[1])
tabLayout.getTabAt(2)!!.setText(fragment.getString(R.string.train)).setIcon(tabIcons[2])
tabLayout.getTabAt(3)!!.setText(fragment.getString(R.string.review)).setIcon(tabIcons[3])
if (topicId.isNotEmpty() && storyId.isNotEmpty())
setCurrentTab(TopicTab.PLAY)
}

private val topicLiveData: LiveData<Topic> by lazy { getTopic() }
Expand Down
8 changes: 7 additions & 1 deletion app/src/main/java/org/oppia/app/topic/ViewPagerAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,11 @@ import org.oppia.app.topic.review.TopicReviewFragment
import org.oppia.app.topic.train.TopicTrainFragment

/** Adapter to bind fragments to [FragmentStatePagerAdapter] inside [TopicFragment]. */
class ViewPagerAdapter(fragmentManager: FragmentManager, private val topicId: String) :
class ViewPagerAdapter(
fragmentManager: FragmentManager,
private val topicId: String,
private val storyId: String
) :
FragmentStatePagerAdapter(fragmentManager) {

override fun getItem(position: Int): Fragment {
Expand All @@ -24,6 +28,8 @@ class ViewPagerAdapter(fragmentManager: FragmentManager, private val topicId: St
}
TopicTab.PLAY -> {
val topicPlayTab = TopicPlayFragment()
if (storyId.isNotEmpty())
args.putString(STORY_ID_ARGUMENT_KEY, storyId)
topicPlayTab.arguments = args
return topicPlayTab
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import org.oppia.app.model.ChapterSummary
import org.oppia.app.model.StorySummary
import org.oppia.app.model.Topic
import org.oppia.app.topic.RouteToStoryListener
import org.oppia.app.topic.STORY_ID_ARGUMENT_KEY
import org.oppia.app.topic.TOPIC_ID_ARGUMENT_KEY
import org.oppia.domain.exploration.ExplorationDataController
import org.oppia.domain.topic.TopicController
Expand All @@ -38,6 +39,7 @@ class TopicPlayFragmentPresenter @Inject constructor(

private lateinit var binding: TopicPlayFragmentBinding
private lateinit var topicId: String
private lateinit var storyId: String

private lateinit var expandedChapterListIndexListener: ExpandedChapterListIndexListener

Expand All @@ -50,6 +52,7 @@ class TopicPlayFragmentPresenter @Inject constructor(
topicId = checkNotNull(fragment.arguments?.getString(TOPIC_ID_ARGUMENT_KEY)) {
"Expected topic ID to be included in arguments for TopicPlayFragment."
}
storyId = fragment.arguments?.getString(STORY_ID_ARGUMENT_KEY) ?: ""
this.currentExpandedChapterListIndex = currentExpandedChapterListIndex
this.expandedChapterListIndexListener = expandedChapterListIndexListener
binding = TopicPlayFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
Expand All @@ -68,6 +71,12 @@ class TopicPlayFragmentPresenter @Inject constructor(

private fun subscribeToTopicLiveData() {
topicLiveData.observe(fragment, Observer<Topic> {
it.storyList!!.forEach { storySummary ->
if (storySummary.storyId.equals(storyId)) {
val index = it.storyList.indexOf(storySummary)
currentExpandedChapterListIndex = index
}
}
val storySummaryAdapter =
StorySummaryAdapter(
it.storyList,
Expand All @@ -79,6 +88,8 @@ class TopicPlayFragmentPresenter @Inject constructor(
binding.storySummaryRecyclerView.apply {
adapter = storySummaryAdapter
}
if (storyId.isNotEmpty())
binding.storySummaryRecyclerView.layoutManager!!.scrollToPosition(currentExpandedChapterListIndex!!)
})
}

Expand Down
32 changes: 8 additions & 24 deletions app/src/main/res/layout/home_fragment.xml
Original file line number Diff line number Diff line change
Expand Up @@ -14,33 +14,17 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical">

<LinearLayout
android:layout_width="match_parent"
<Button
android:id="@+id/play_exploration_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@color/white"
android:gravity="center"
android:orientation="vertical">

<Button
android:id="@+id/play_exploration_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="@{presenter::playExplorationButton}"
android:text="Play exploration"
android:visibility="gone" />

<Button
android:id="@+id/topic_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:onClick="@{presenter::handleTopicButtonClicked}"
android:text="Go to topic"
android:visibility="gone" />
</LinearLayout>
android:layout_marginTop="16dp"
android:onClick="@{presenter::playExplorationButton}"
android:text="Play exploration"
android:visibility="visible" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/home_recycler_view"
Expand Down
Loading

0 comments on commit ed6aa46

Please sign in to comment.