-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix part of #137: Topic-play-tab low-fi (part-1) (Without expandable …
…list) (#260) * Topic-play-tab basic implementation * Added test cases * Nit changes * Id rename * StoryActivity introduced * Nit changes * New test cases added * Nit changes
- Loading branch information
Showing
22 changed files
with
514 additions
and
33 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package org.oppia.app.story | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import android.os.Bundle | ||
import org.oppia.app.activity.InjectableAppCompatActivity | ||
import javax.inject.Inject | ||
|
||
/** Activity for stories. */ | ||
class StoryActivity : InjectableAppCompatActivity() { | ||
@Inject lateinit var storyActivityPresenter: StoryActivityPresenter | ||
|
||
override fun onCreate(savedInstanceState: Bundle?) { | ||
super.onCreate(savedInstanceState) | ||
activityComponent.inject(this) | ||
storyActivityPresenter.handleOnCreate() | ||
} | ||
|
||
companion object { | ||
const val STORY_ACTIVITY_STORY_ID_ARGUMENT_KEY = "StoryActivity.story_id" | ||
|
||
/** Returns a new [Intent] to route to [StoryActivity] for a specified story ID. */ | ||
fun createStoryActivityIntent(context: Context, storyId: String): Intent { | ||
val intent = Intent(context, StoryActivity::class.java) | ||
intent.putExtra(STORY_ACTIVITY_STORY_ID_ARGUMENT_KEY, storyId) | ||
return intent | ||
} | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
app/src/main/java/org/oppia/app/story/StoryActivityPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.oppia.app.story | ||
|
||
import androidx.appcompat.app.AppCompatActivity | ||
import org.oppia.app.R | ||
import org.oppia.app.activity.ActivityScope | ||
import javax.inject.Inject | ||
|
||
/** The presenter for [StoryActivity]. */ | ||
@ActivityScope | ||
class StoryActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { | ||
fun handleOnCreate() { | ||
activity.setContentView(R.layout.story_activity) | ||
if (getStoryFragment() == null) { | ||
activity.supportFragmentManager.beginTransaction().add( | ||
R.id.story_fragment_placeholder, | ||
StoryFragment() | ||
).commitNow() | ||
} | ||
} | ||
|
||
private fun getStoryFragment(): StoryFragment? { | ||
return activity.supportFragmentManager.findFragmentById(R.id.story_fragment_placeholder) as StoryFragment? | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package org.oppia.app.story | ||
|
||
import android.content.Context | ||
import android.os.Bundle | ||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import org.oppia.app.fragment.InjectableFragment | ||
import javax.inject.Inject | ||
|
||
/** Fragment that displays story with chapter list. */ | ||
class StoryFragment : InjectableFragment() { | ||
@Inject | ||
lateinit var storyFragmentPresenter: StoryFragmentPresenter | ||
|
||
override fun onAttach(context: Context?) { | ||
super.onAttach(context) | ||
fragmentComponent.inject(this) | ||
} | ||
|
||
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? { | ||
return storyFragmentPresenter.handleCreateView(inflater, container) | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
app/src/main/java/org/oppia/app/story/StoryFragmentPresenter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package org.oppia.app.story | ||
|
||
import android.view.LayoutInflater | ||
import android.view.View | ||
import android.view.ViewGroup | ||
import androidx.fragment.app.Fragment | ||
import org.oppia.app.databinding.StoryFragmentBinding | ||
import org.oppia.app.fragment.FragmentScope | ||
import javax.inject.Inject | ||
|
||
/** The presenter for [StoryFragment]. */ | ||
@FragmentScope | ||
class StoryFragmentPresenter @Inject constructor( | ||
private val fragment: Fragment | ||
) { | ||
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { | ||
val binding = StoryFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false) | ||
binding.let { | ||
it.lifecycleOwner = fragment | ||
} | ||
return binding.root | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
app/src/main/java/org/oppia/app/topic/RouteToStoryListener.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package org.oppia.app.topic | ||
|
||
/** Listener for when an [TopicActivity] should route to a [StoryActivity]. */ | ||
interface RouteToStoryListener { | ||
fun routeToStory(storyId: String) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
app/src/main/java/org/oppia/app/topic/play/StorySummaryAdapter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package org.oppia.app.topic.play | ||
|
||
import android.view.LayoutInflater | ||
import android.view.ViewGroup | ||
import androidx.databinding.DataBindingUtil | ||
import androidx.databinding.library.baseAdapters.BR | ||
import androidx.recyclerview.widget.RecyclerView | ||
import org.oppia.app.R | ||
import org.oppia.app.databinding.TopicPlayStorySummaryBinding | ||
import org.oppia.app.model.StorySummary | ||
|
||
// TODO(#216): Make use of generic data-binding-enabled RecyclerView adapter. | ||
/** Adapter to bind StorySummary to [RecyclerView] inside [TopicPlayFragment]. */ | ||
class StorySummaryAdapter( | ||
private var storyList: MutableList<StorySummary>, | ||
private val storySummarySelector: StorySummarySelector | ||
) : | ||
RecyclerView.Adapter<StorySummaryAdapter.StorySummaryViewHolder>() { | ||
|
||
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): StorySummaryViewHolder { | ||
val storySummaryListItemBinding = DataBindingUtil.inflate<TopicPlayStorySummaryBinding>( | ||
LayoutInflater.from(parent.context), | ||
R.layout.topic_play_story_summary, parent, | ||
/* attachToRoot= */ false | ||
) | ||
return StorySummaryViewHolder(storySummaryListItemBinding) | ||
} | ||
|
||
override fun onBindViewHolder(storySummaryViewHolder: StorySummaryViewHolder, i: Int) { | ||
storySummaryViewHolder.bind(storyList[i], i) | ||
} | ||
|
||
override fun getItemCount(): Int { | ||
return storyList.size | ||
} | ||
|
||
inner class StorySummaryViewHolder(private val binding: TopicPlayStorySummaryBinding) : | ||
RecyclerView.ViewHolder(binding.root) { | ||
internal fun bind(storySummary: StorySummary, @Suppress("UNUSED_PARAMETER") position: Int) { | ||
binding.setVariable(BR.storySummary, storySummary) | ||
binding.root.setOnClickListener { | ||
storySummarySelector.selectedStorySummary(storySummary) | ||
} | ||
} | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
app/src/main/java/org/oppia/app/topic/play/StorySummarySelector.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package org.oppia.app.topic.play | ||
|
||
import org.oppia.app.model.StorySummary | ||
|
||
/** Interface to transfer the selected story summary to [TopicPlayFragmentPresenter]. */ | ||
interface StorySummarySelector { | ||
fun selectedStorySummary(storySummary: StorySummary) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.