From c193e9369815d23e5872ee04c414280ff5712d52 Mon Sep 17 00:00:00 2001 From: veena Date: Tue, 15 Oct 2019 17:47:50 +0530 Subject: [PATCH 01/16] fetching exploration id from exploration fragment --- .../player/exploration/ExplorationActivity.kt | 4 +++- .../ExplorationActivityPresenter.kt | 10 ++++++--- .../ExplorationFragmentPresenter.kt | 21 ++++++++++++++++++- .../player/state/StateFragmentPresenter.kt | 4 +++- .../main/res/layout/exploration_fragment.xml | 7 ++----- 5 files changed, 35 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivity.kt b/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivity.kt index caf6374f3ed..5b24ae5a83b 100755 --- a/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivity.kt +++ b/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivity.kt @@ -12,11 +12,13 @@ const val EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY = "ExplorationActivity.expl class ExplorationActivity : InjectableAppCompatActivity() { @Inject lateinit var explorationActivityPresenter: ExplorationActivityPresenter + var explorationId: String = "" override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) activityComponent.inject(this) - explorationActivityPresenter.handleOnCreate() + explorationId = intent.getStringExtra(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY) + explorationActivityPresenter.handleOnCreate(explorationId) } companion object { diff --git a/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivityPresenter.kt b/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivityPresenter.kt index 0541e00e35b..f80d15a0978 100755 --- a/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivityPresenter.kt +++ b/app/src/main/java/org/oppia/app/player/exploration/ExplorationActivityPresenter.kt @@ -1,20 +1,24 @@ package org.oppia.app.player.exploration +import android.os.Bundle import androidx.appcompat.app.AppCompatActivity import org.oppia.app.R import org.oppia.app.activity.ActivityScope -import org.oppia.app.home.HomeFragment import javax.inject.Inject /** The controller for [ExplorationActivity]. */ @ActivityScope class ExplorationActivityPresenter @Inject constructor(private val activity: AppCompatActivity) { - fun handleOnCreate() { + fun handleOnCreate(explorationId: String) { activity.setContentView(R.layout.exploration_activity) if (getExplorationFragment() == null) { + val explorationFragment = ExplorationFragment() + val args = Bundle() + args.putString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY, explorationId) + explorationFragment.arguments = args activity.supportFragmentManager.beginTransaction().add( R.id.exploration_fragment_placeholder, - ExplorationFragment() + explorationFragment ).commitNow() } } diff --git a/app/src/main/java/org/oppia/app/player/exploration/ExplorationFragmentPresenter.kt b/app/src/main/java/org/oppia/app/player/exploration/ExplorationFragmentPresenter.kt index 8fc0223f7fa..a7c6ef7a828 100755 --- a/app/src/main/java/org/oppia/app/player/exploration/ExplorationFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/player/exploration/ExplorationFragmentPresenter.kt @@ -1,11 +1,14 @@ package org.oppia.app.player.exploration +import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup import androidx.fragment.app.Fragment +import org.oppia.app.R import org.oppia.app.databinding.ExplorationFragmentBinding import org.oppia.app.fragment.FragmentScope +import org.oppia.app.player.state.StateFragment import javax.inject.Inject /** The controller for [ExplorationFragment]. */ @@ -14,6 +17,22 @@ class ExplorationFragmentPresenter @Inject constructor( private val fragment: Fragment ) { fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { - return ExplorationFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false).root + val binding = ExplorationFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false).root + + if (getStateFragment() == null) { + val stateFragment = StateFragment() + val args = Bundle() + args.putString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY, fragment.arguments!!.getString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY)) + stateFragment.arguments = args + fragment.childFragmentManager.beginTransaction().add( + R.id.state_fragment_placeholder, + stateFragment + ).commitNow() + } + return binding + } + + private fun getStateFragment(): StateFragment? { + return fragment.childFragmentManager.findFragmentById(R.id.state_fragment_placeholder) as StateFragment? } } diff --git a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt index 45a30923e1a..83b9acc80c8 100755 --- a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt @@ -12,6 +12,7 @@ import org.oppia.app.fragment.FragmentScope import org.oppia.app.model.CellularDataPreference import org.oppia.app.model.EphemeralState import org.oppia.app.player.audio.CellularDataDialogFragment +import org.oppia.app.player.exploration.EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY import org.oppia.app.viewmodel.ViewModelProvider import org.oppia.domain.audio.CellularDialogController import org.oppia.domain.exploration.ExplorationProgressController @@ -33,6 +34,7 @@ class StateFragmentPresenter @Inject constructor( private var showCellularDataDialog = true private var useCellularData = false + private var explorationId: String = "" fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? { cellularDialogController.getCellularDataPreference() @@ -49,7 +51,7 @@ class StateFragmentPresenter @Inject constructor( it.stateFragment = fragment as StateFragment it.viewModel = getStateViewModel() } - + explorationId = fragment.arguments!!.getString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY) subscribeToCurrentState() return binding.root diff --git a/app/src/main/res/layout/exploration_fragment.xml b/app/src/main/res/layout/exploration_fragment.xml index 231f8162b38..618f7f3da10 100755 --- a/app/src/main/res/layout/exploration_fragment.xml +++ b/app/src/main/res/layout/exploration_fragment.xml @@ -5,16 +5,13 @@ - - - From 33ddb3352d17dda435849687504c2adc76e18329 Mon Sep 17 00:00:00 2001 From: veena Date: Tue, 15 Oct 2019 17:54:04 +0530 Subject: [PATCH 02/16] added framelayout for audiofragment --- .../oppia/app/player/state/StateFragmentPresenter.kt | 9 +++++++++ app/src/main/res/layout/state_fragment.xml | 10 +++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt index 83b9acc80c8..8b11b8bdca5 100755 --- a/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt +++ b/app/src/main/java/org/oppia/app/player/state/StateFragmentPresenter.kt @@ -1,5 +1,6 @@ package org.oppia.app.player.state +import android.os.Bundle import android.view.LayoutInflater import android.view.View import android.view.ViewGroup @@ -7,10 +8,12 @@ import androidx.fragment.app.Fragment import androidx.lifecycle.LiveData import androidx.lifecycle.Observer import androidx.lifecycle.Transformations +import org.oppia.app.R import org.oppia.app.databinding.StateFragmentBinding import org.oppia.app.fragment.FragmentScope import org.oppia.app.model.CellularDataPreference import org.oppia.app.model.EphemeralState +import org.oppia.app.player.audio.AudioFragment import org.oppia.app.player.audio.CellularDataDialogFragment import org.oppia.app.player.exploration.EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY import org.oppia.app.viewmodel.ViewModelProvider @@ -52,11 +55,17 @@ class StateFragmentPresenter @Inject constructor( it.viewModel = getStateViewModel() } explorationId = fragment.arguments!!.getString(EXPLORATION_ACTIVITY_TOPIC_ID_ARGUMENT_KEY) + + getAudioFragment() subscribeToCurrentState() return binding.root } + private fun getAudioFragment(): AudioFragment? { + return fragment.childFragmentManager.findFragmentById(R.id.audio_fragment_placeholder) as AudioFragment? + } + fun handleAudioClick() { if (showCellularDataDialog) { setAudioFragmentVisible(false) diff --git a/app/src/main/res/layout/state_fragment.xml b/app/src/main/res/layout/state_fragment.xml index d1cff627ed7..c72a00d28fa 100755 --- a/app/src/main/res/layout/state_fragment.xml +++ b/app/src/main/res/layout/state_fragment.xml @@ -14,7 +14,8 @@ - - - +