Skip to content

Commit

Permalink
Merge pull request #2 from oppia/develop
Browse files Browse the repository at this point in the history
Merge
  • Loading branch information
PrarabdhGarg authored Jan 29, 2020
2 parents 710093a + 3cf1964 commit dc7bbbb
Show file tree
Hide file tree
Showing 24 changed files with 86 additions and 84 deletions.
4 changes: 2 additions & 2 deletions app/src/main/java/org/oppia/app/fragment/FragmentComponent.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import org.oppia.app.testing.BindableAdapterTestFragment
import org.oppia.app.topic.TopicFragment
import org.oppia.app.topic.conceptcard.ConceptCardFragment
import org.oppia.app.topic.info.TopicInfoFragment
import org.oppia.app.topic.play.TopicPlayFragment
import org.oppia.app.topic.lessons.TopicLessonsFragment
import org.oppia.app.topic.questionplayer.QuestionPlayerFragment
import org.oppia.app.topic.review.TopicReviewFragment
import org.oppia.app.topic.practice.TopicPracticeFragment
Expand Down Expand Up @@ -61,7 +61,7 @@ interface FragmentComponent {
fun inject(storyFragment: StoryFragment)
fun inject(topicFragment: TopicFragment)
fun inject(topicInfoFragment: TopicInfoFragment)
fun inject(topicPlayFragment: TopicPlayFragment)
fun inject(topicLessonsFragment: TopicLessonsFragment)
fun inject(topicReviewFragment: TopicReviewFragment)
fun inject(topicPracticeFragment: TopicPracticeFragment)
fun inject(updatesTabFragment: UpdatesTabFragment)
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/oppia/app/topic/TopicActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class TopicActivity : InjectableAppCompatActivity(), RouteToQuestionPlayerListen
return intent
}

/** Returns a new [Intent] to route to [TopicPlayFragment] for a specified story ID. */
/** Returns a new [Intent] to route to [TopicLessonsFragment] for a specified story ID. */
fun createTopicPlayStoryActivityIntent(context: Context, topicId: String, storyId: String): Intent {
val intent = Intent(context, TopicActivity::class.java)
intent.putExtra(TOPIC_ACTIVITY_TOPIC_ID_ARGUMENT_KEY, topicId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class TopicFragmentPresenter @Inject constructor(
private val tabIcons =
intArrayOf(
R.drawable.ic_info_icon_24dp,
R.drawable.ic_play_icon_24dp,
R.drawable.ic_lessons_icon_24dp,
R.drawable.ic_practice_icon_24dp,
R.drawable.ic_review_icon_24dp
)
Expand Down Expand Up @@ -65,11 +65,11 @@ class TopicFragmentPresenter @Inject constructor(
viewPager.adapter = adapter
tabLayout.setupWithViewPager(viewPager)
tabLayout.getTabAt(0)!!.setText(fragment.getString(R.string.info)).setIcon(tabIcons[0])
tabLayout.getTabAt(1)!!.setText(fragment.getString(R.string.play)).setIcon(tabIcons[1])
tabLayout.getTabAt(1)!!.setText(fragment.getString(R.string.lessons)).setIcon(tabIcons[1])
tabLayout.getTabAt(2)!!.setText(fragment.getString(R.string.practice)).setIcon(tabIcons[2])
tabLayout.getTabAt(3)!!.setText(fragment.getString(R.string.review)).setIcon(tabIcons[3])
if (topicId.isNotEmpty() && storyId.isNotEmpty())
setCurrentTab(TopicTab.PLAY)
setCurrentTab(TopicTab.LESSONS)
}

private val topicLiveData: LiveData<Topic> by lazy { getTopic() }
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/org/oppia/app/topic/TopicTab.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package org.oppia.app.topic
/** Enum to store the tabs of [TopicFragment] and get tab by position. */
enum class TopicTab(private var position: Int) {
INFO(position = 0),
PLAY(position = 1),
LESSONS(position = 1),
PRACTICE(position = 2),
REVIEW(position = 3);

Expand Down
6 changes: 3 additions & 3 deletions app/src/main/java/org/oppia/app/topic/ViewPagerAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentStatePagerAdapter
import org.oppia.app.topic.info.TopicInfoFragment
import org.oppia.app.topic.play.TopicPlayFragment
import org.oppia.app.topic.lessons.TopicLessonsFragment
import org.oppia.app.topic.review.TopicReviewFragment
import org.oppia.app.topic.practice.TopicPracticeFragment

Expand All @@ -26,8 +26,8 @@ class ViewPagerAdapter(
topicInfoTab.arguments = args
return topicInfoTab
}
TopicTab.PLAY -> {
val topicPlayTab = TopicPlayFragment()
TopicTab.LESSONS -> {
val topicPlayTab = TopicLessonsFragment()
if (storyId.isNotEmpty())
args.putString(STORY_ID_ARGUMENT_KEY, storyId)
topicPlayTab.arguments = args
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,25 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.databinding.DataBindingUtil
import androidx.recyclerview.widget.RecyclerView
import org.oppia.app.R
import org.oppia.app.databinding.PlayChapterViewBinding
import org.oppia.app.databinding.LessonsChapterViewBinding
import org.oppia.app.model.ChapterSummary

// TODO(#216): Make use of generic data-binding-enabled RecyclerView adapter.

/** Adapter to bind ChapterSummary to [RecyclerView] inside [TopicPlayFragment]. */
/** Adapter to bind ChapterSummary to [RecyclerView] inside [TopicLessonsFragment]. */
class ChapterSummaryAdapter(
private val chapterList: List<ChapterSummary>,
private val chapterSummarySelector: ChapterSummarySelector
) :
RecyclerView.Adapter<ChapterSummaryAdapter.ChapterSummaryViewHolder>() {
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ChapterSummaryViewHolder {
val chapterSummaryListItemBinding = DataBindingUtil.inflate<PlayChapterViewBinding>(
val chapterSummaryListItemBinding = DataBindingUtil.inflate<LessonsChapterViewBinding>(
LayoutInflater.from(parent.context),
R.layout.play_chapter_view, parent,
R.layout.lessons_chapter_view, parent,
/* attachToRoot= */ false
)
return ChapterSummaryViewHolder(chapterSummaryListItemBinding)
Expand All @@ -33,7 +33,7 @@ class ChapterSummaryAdapter(
chapterSummaryViewHolder.bind(chapterList[position], position)
}

inner class ChapterSummaryViewHolder(private val binding: PlayChapterViewBinding) :
inner class ChapterSummaryViewHolder(private val binding: LessonsChapterViewBinding) :
RecyclerView.ViewHolder(binding.root) {
internal fun bind(chapterSummary: ChapterSummary, position: Int) {
binding.chapterSummary = chapterSummary
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import org.oppia.app.model.ChapterSummary

/** Interface to transfer the selected chapter summary to [TopicPlayFragmentPresenter]. */
/** Interface to transfer the selected chapter summary to [TopicLessonsFragmentPresenter]. */
interface ChapterSummarySelector {
fun selectChapterSummary(chapterSummary: ChapterSummary)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

/**
* Interface to keep track of story-index for which ChapterList is visible/expanded.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.recyclerview.widget.RecyclerView
import org.oppia.app.databinding.TopicPlayStorySummaryBinding
import org.oppia.app.databinding.TopicPlayTitleBinding
import org.oppia.app.databinding.TopicLessonsStorySummaryBinding
import org.oppia.app.databinding.TopicLessonsTitleBinding
import org.oppia.app.model.ChapterPlayState
import org.oppia.app.model.ChapterSummary

Expand All @@ -13,9 +14,9 @@ import org.oppia.app.model.ChapterSummary
private const val VIEW_TYPE_TITLE_TEXT = 1
private const val VIEW_TYPE_STORY_ITEM = 2

/** Adapter to bind StorySummary to [RecyclerView] inside [TopicPlayFragment]. */
/** Adapter to bind StorySummary to [RecyclerView] inside [TopicLessonsFragment]. */
class StorySummaryAdapter(
private val itemList: MutableList<TopicPlayItemViewModel>,
private val itemList: MutableList<TopicLessonsItemViewModel>,
private val chapterSummarySelector: ChapterSummarySelector,
private val expandedChapterListIndexListener: ExpandedChapterListIndexListener,
private var currentExpandedChapterListIndex: Int?
Expand All @@ -28,7 +29,7 @@ class StorySummaryAdapter(
VIEW_TYPE_TITLE_TEXT -> {
val inflater = LayoutInflater.from(parent.context)
val binding =
TopicPlayTitleBinding.inflate(
TopicLessonsTitleBinding.inflate(
inflater,
parent,
/* attachToParent= */ false
Expand All @@ -38,7 +39,7 @@ class StorySummaryAdapter(
VIEW_TYPE_STORY_ITEM -> {
val inflater = LayoutInflater.from(parent.context)
val binding =
TopicPlayStorySummaryBinding.inflate(
TopicLessonsStorySummaryBinding.inflate(
inflater,
parent,
/* attachToParent= */ false
Expand All @@ -63,7 +64,7 @@ class StorySummaryAdapter(

override fun getItemViewType(position: Int): Int {
return when (itemList[position]) {
is TopicPlayTitleViewModel -> {
is TopicLessonsTitleViewModel -> {
VIEW_TYPE_TITLE_TEXT
}
is StorySummaryViewModel -> {
Expand All @@ -78,12 +79,12 @@ class StorySummaryAdapter(
}

private class TopicPlayTitleViewHolder(
binding: TopicPlayTitleBinding
binding: TopicLessonsTitleBinding
) : RecyclerView.ViewHolder(binding.root) {
internal fun bind() {}
}

inner class StorySummaryViewHolder(private val binding: TopicPlayStorySummaryBinding) :
inner class StorySummaryViewHolder(private val binding: TopicLessonsStorySummaryBinding) :
RecyclerView.ViewHolder(binding.root) {
internal fun bind(storySummaryViewModel: StorySummaryViewModel, position: Int) {
var isChapterListVisible = false
Expand All @@ -106,7 +107,7 @@ class StorySummaryAdapter(
storySummaryViewModel.storySummary.chapterCount,
completedChapterCount
)

binding.topicPlayStoryDashedLineView.setLayerType(View.LAYER_TYPE_SOFTWARE, /* paint= */ null)
val chapterList = storySummaryViewModel.storySummary.chapterList
binding.chapterRecyclerView.adapter = ChapterSummaryAdapter(chapterList, chapterSummarySelector)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import org.oppia.app.model.StorySummary

/** Interface to transfer the selected story summary to [TopicPlayFragmentPresenter]. */
/** Interface to transfer the selected story summary to [TopicLessonsFragmentPresenter]. */
interface StorySummarySelector {
fun selectStorySummary(storySummary: StorySummary)
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import androidx.lifecycle.ViewModel
import org.oppia.app.model.StorySummary
Expand All @@ -7,7 +7,7 @@ import org.oppia.app.model.StorySummary
class StorySummaryViewModel(
val storySummary: StorySummary,
private val storySummarySelector: StorySummarySelector
) : TopicPlayItemViewModel() {
) : TopicLessonsItemViewModel() {

fun clickOnStorySummaryTitle() {
storySummarySelector.selectStorySummary(storySummary)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import android.content.Context
import android.os.Bundle
Expand All @@ -11,9 +11,9 @@ import javax.inject.Inject

private const val KEY_CURRENT_EXPANDED_LIST_INDEX = "CURRENT_EXPANDED_LIST_INDEX"

/** Fragment that contains subtopic list for play mode. */
class TopicPlayFragment : InjectableFragment(), ExpandedChapterListIndexListener, StorySummarySelector {
@Inject lateinit var topicPlayFragmentPresenter: TopicPlayFragmentPresenter
/** Fragment that contains subtopic list for lessons mode. */
class TopicLessonsFragment : InjectableFragment(), ExpandedChapterListIndexListener, StorySummarySelector {
@Inject lateinit var topicLessonsFragmentPresenter: TopicLessonsFragmentPresenter

private var currentExpandedChapterListIndex: Int? = null

Expand All @@ -29,7 +29,7 @@ class TopicPlayFragment : InjectableFragment(), ExpandedChapterListIndexListener
currentExpandedChapterListIndex = null
}
}
return topicPlayFragmentPresenter.handleCreateView(
return topicLessonsFragmentPresenter.handleCreateView(
inflater,
container,
currentExpandedChapterListIndex,
Expand All @@ -49,6 +49,6 @@ class TopicPlayFragment : InjectableFragment(), ExpandedChapterListIndexListener
}

override fun selectStorySummary(storySummary: StorySummary) {
topicPlayFragmentPresenter.storySummaryClicked(storySummary)
topicLessonsFragmentPresenter.storySummaryClicked(storySummary)
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.oppia.app.topic.play
package org.oppia.app.topic.lessons

import android.view.LayoutInflater
import android.view.View
Expand All @@ -8,7 +8,7 @@ import androidx.fragment.app.Fragment
import androidx.lifecycle.LiveData
import androidx.lifecycle.Observer
import androidx.lifecycle.Transformations
import org.oppia.app.databinding.TopicPlayFragmentBinding
import org.oppia.app.databinding.TopicLessonsFragmentBinding
import org.oppia.app.fragment.FragmentScope
import org.oppia.app.home.RouteToExplorationListener
import org.oppia.app.model.ChapterSummary
Expand All @@ -23,9 +23,9 @@ import org.oppia.util.data.AsyncResult
import org.oppia.util.logging.Logger
import javax.inject.Inject

/** The presenter for [TopicPlayFragment]. */
/** The presenter for [TopicLessonsFragment]. */
@FragmentScope
class TopicPlayFragmentPresenter @Inject constructor(
class TopicLessonsFragmentPresenter @Inject constructor(
activity: AppCompatActivity,
private val fragment: Fragment,
private val logger: Logger,
Expand All @@ -37,13 +37,13 @@ class TopicPlayFragmentPresenter @Inject constructor(

private var currentExpandedChapterListIndex: Int? = null

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

private lateinit var expandedChapterListIndexListener: ExpandedChapterListIndexListener

private val itemList: MutableList<TopicPlayItemViewModel> = ArrayList()
private val itemList: MutableList<TopicLessonsItemViewModel> = ArrayList()

fun handleCreateView(
inflater: LayoutInflater,
Expand All @@ -52,12 +52,12 @@ class TopicPlayFragmentPresenter @Inject constructor(
expandedChapterListIndexListener: ExpandedChapterListIndexListener
): View? {
topicId = checkNotNull(fragment.arguments?.getString(TOPIC_ID_ARGUMENT_KEY)) {
"Expected topic ID to be included in arguments for TopicPlayFragment."
"Expected topic ID to be included in arguments for TopicLessonsFragment."
}
storyId = fragment.arguments?.getString(STORY_ID_ARGUMENT_KEY) ?: ""
this.currentExpandedChapterListIndex = currentExpandedChapterListIndex
this.expandedChapterListIndexListener = expandedChapterListIndexListener
binding = TopicPlayFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding = TopicLessonsFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.let {
it.lifecycleOwner = fragment
}
Expand All @@ -80,7 +80,7 @@ class TopicPlayFragmentPresenter @Inject constructor(
currentExpandedChapterListIndex = index + 1
}
}
itemList.add(TopicPlayTitleViewModel())
itemList.add(TopicLessonsTitleViewModel())
for (storySummary in it.storyList) {
itemList.add(StorySummaryViewModel(storySummary, fragment as StorySummarySelector))
}
Expand All @@ -106,7 +106,7 @@ class TopicPlayFragmentPresenter @Inject constructor(

private fun processTopicResult(topic: AsyncResult<Topic>): Topic {
if (topic.isFailure()) {
logger.e("TopicPlayFragment", "Failed to retrieve topic", topic.getErrorOrNull()!!)
logger.e("TopicLessonsFragment", "Failed to retrieve topic", topic.getErrorOrNull()!!)
}
return topic.getOrDefault(Topic.getDefaultInstance())
}
Expand All @@ -124,10 +124,10 @@ class TopicPlayFragmentPresenter @Inject constructor(
explorationId
).observe(fragment, Observer<AsyncResult<Any?>> { result ->
when {
result.isPending() -> logger.d("TopicPlayFragment", "Loading exploration")
result.isFailure() -> logger.e("TopicPlayFragment", "Failed to load exploration", result.getErrorOrNull()!!)
result.isPending() -> logger.d("TopicLessonsFragment", "Loading exploration")
result.isFailure() -> logger.e("TopicLessonsFragment", "Failed to load exploration", result.getErrorOrNull()!!)
else -> {
logger.d("TopicPlayFragment", "Successfully loaded exploration")
logger.d("TopicLessonsFragment", "Successfully loaded exploration")
routeToExplorationListener.routeToExploration(explorationId, topicId)
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.oppia.app.topic.lessons

import org.oppia.app.viewmodel.ObservableViewModel

/** The root [ViewModel] for all individual items that may be displayed in [TopicLessonsFragment] recycler view. */
abstract class TopicLessonsItemViewModel: ObservableViewModel()
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package org.oppia.app.topic.lessons

import androidx.lifecycle.ViewModel

/** [ViewModel] for title in [TopicLessonsFragment]. */
class TopicLessonsTitleViewModel : TopicLessonsItemViewModel()

This file was deleted.

This file was deleted.

File renamed without changes.
Loading

0 comments on commit dc7bbbb

Please sign in to comment.