Skip to content

Commit

Permalink
Merge branch 'develop' into introduce-exploration-progress-controller
Browse files Browse the repository at this point in the history
Conflicts:
	domain/build.gradle
	domain/src/main/java/org/oppia/domain/exploration/ExplorationDataController.kt

Also, migrate the data controller to the retriever.
  • Loading branch information
BenHenning committed Sep 29, 2019
2 parents a0eb3ce + 4c92398 commit 1ea9d01
Show file tree
Hide file tree
Showing 34 changed files with 3,660 additions and 162 deletions.
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="org.oppia.app">

<uses-permission android:name="android.permission.INTERNET" />
<application
android:name=".application.OppiaApplication"
android:allowBackup="true"
Expand Down
33 changes: 17 additions & 16 deletions app/src/main/java/org/oppia/app/player/audio/AudioFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,13 @@ import android.view.ViewGroup
import org.oppia.app.fragment.InjectableFragment
import javax.inject.Inject

private const val TAG_DIALOG = "LANGUAGE_DIALOG"
private const val TAG_LANGUAGE_DIALOG = "LANGUAGE_DIALOG"

/** Fragment that controls audio for a state and content.*/
class AudioFragment : InjectableFragment() {
/** Fragment that controls audio for a content-card. */
class AudioFragment : InjectableFragment(), LanguageInterface {
@Inject
lateinit var audioFragmentPresenter: AudioFragmentPresenter

lateinit var languageInterface: LanguageInterface
private var selectedLanguageCode: String = "en"

override fun onAttach(context: Context?) {
super.onAttach(context)
Expand All @@ -27,22 +26,19 @@ class AudioFragment : InjectableFragment() {
}

fun languageSelectionClicked() {
languageInterface = object : LanguageInterface {
override fun onLanguageSelected(currentLanguageCode: String) {
audioFragmentPresenter.languageSelected(currentLanguageCode)
}
}
showLanguageDialogFragment()
}

val previousFragment = fragmentManager?.findFragmentByTag(TAG_DIALOG)
private fun showLanguageDialogFragment() {
val previousFragment = childFragmentManager.findFragmentByTag(TAG_LANGUAGE_DIALOG)
if (previousFragment != null) {
fragmentManager?.beginTransaction()?.remove(previousFragment)?.commitNow()
childFragmentManager.beginTransaction().remove(previousFragment).commitNow()
}
val dialogFragment = LanguageDialogFragment.newInstance(
languageInterface,
getDummyAudioLanguageList(),
"en"
getDummyAudioLanguageList() as ArrayList<String>,
selectedLanguageCode
)
dialogFragment.showNow(fragmentManager, TAG_DIALOG)
dialogFragment.showNow(childFragmentManager, TAG_LANGUAGE_DIALOG)
}

private fun getDummyAudioLanguageList(): List<String> {
Expand All @@ -52,4 +48,9 @@ class AudioFragment : InjectableFragment() {
languageCodeList.add("hi-en")
return languageCodeList
}

override fun onLanguageSelected(currentLanguageCode: String) {
selectedLanguageCode = currentLanguageCode
audioFragmentPresenter.languageSelected(currentLanguageCode)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import org.oppia.app.fragment.FragmentScope
import org.oppia.app.viewmodel.ViewModelProvider
import javax.inject.Inject

/** The controller for [AudioFragment]. */
/** The presenter for [AudioFragment]. */
@FragmentScope
class AudioFragmentPresenter @Inject constructor(
private val fragment: Fragment,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import javax.inject.Inject
@FragmentScope
class AudioViewModel @Inject constructor(
) : ViewModel() {

val currentLanguageCode = ObservableField<String>("en")

fun setAudioLanguageCode(languageCode: String) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package org.oppia.app.player.audio

import android.app.Dialog
import android.content.Context
import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import android.widget.CheckBox
import org.oppia.app.R
import org.oppia.app.player.state.StateFragment

/**
* DialogFragment that indicates to the user they are on cellular when trying to play an audio voiceover.
*/
class CellularDataDialogFragment : DialogFragment() {
companion object {
/**
* This function is responsible for displaying content in DialogFragment.
*
* @return [CellularDataDialogFragment]: DialogFragment
*/
fun newInstance(): CellularDataDialogFragment {
return CellularDataDialogFragment()
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val view = activity!!.layoutInflater.inflate(R.layout.cellular_data_dialog, null)
val checkBox = view.findViewById<CheckBox>(R.id.cellular_data_dialog_checkbox)

val cellularDataInterface: CellularDataInterface = parentFragment as StateFragment

return AlertDialog.Builder(activity as Context)
.setTitle(R.string.cellular_data_alert_dialog_title)
.setView(view)
.setMessage(R.string.cellular_data_alert_dialog_description)
.setPositiveButton(R.string.cellular_data_alert_dialog_okay_button) { dialog, whichButton ->
cellularDataInterface.enableAudioWhileOnCellular(checkBox.isChecked)
dismiss()
}
.setNegativeButton(R.string.cellular_data_alert_dialog_cancel_button) { dialog, whichButton ->
cellularDataInterface.disableAudioWhileOnCellular(checkBox.isChecked)
dismiss()
}
.create()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.oppia.app.player.audio

/** Interface to check the preference regarding alert for [CellularDataDialogFragment]. */
interface CellularDataInterface {
/**
* If saveUserChoice is true, show audio-player and save preference do not show dialog again.
* If saveUserChoice is false, show audio-player and do not save preference and show this dialog next time too.
*/
fun enableAudioWhileOnCellular(saveUserChoice: Boolean)

/**
* If saveUserChoice is true, do not show audio-player on cellular network and save preference.
* If saveUserChoice is false, do not show audio-player and do not save preference.
*/
fun disableAudioWhileOnCellular(saveUserChoice: Boolean)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,75 +6,58 @@ import android.os.Bundle
import androidx.appcompat.app.AlertDialog
import androidx.fragment.app.DialogFragment
import org.oppia.app.R
import java.util.ArrayList

private const val KEY_LANGUAGE_LIST = "LANGUAGE_LIST"
private const val KEY_CURRENT_LANGUAGE = "CURRENT_LANGUAGE"
private const val KEY_SELECTED_INDEX = "SELECTED_INDEX"

/**
* DialogFragment that controls language selection in audio and written translations
* DialogFragment that controls language selection in audio and written translations.
*/
class LanguageDialogFragment : DialogFragment() {
companion object {
lateinit var languageInterface1: LanguageInterface
/**
* This function is responsible for displaying content in DialogFragment
* @param languageInterface: [LanguageInterface] to send data back to parent
* @param languageCodeList: List of strings containing languages
* This function is responsible for displaying content in DialogFragment.
*
* @param languageArrayList: List of strings containing languages
* @param currentLanguageCode: Currently selected language code
* @return LanguageDialogFragment: DialogFragment
* @return [LanguageDialogFragment]: DialogFragment
*/
fun newInstance(
languageInterface: LanguageInterface,
languageCodeList: List<String>,
languageArrayList: ArrayList<String>,
currentLanguageCode: String
): LanguageDialogFragment {

languageInterface1 = languageInterface
val selectedIndex: Int = languageCodeList.indexOf(currentLanguageCode)
val fragment = LanguageDialogFragment()
val selectedIndex = languageArrayList.indexOf(currentLanguageCode)
val languageDialogFragment = LanguageDialogFragment()
val args = Bundle()
args.putStringArrayList(
KEY_LANGUAGE_LIST,
languageCodeList as ArrayList<String>
)
args.putInt(KEY_CURRENT_LANGUAGE, selectedIndex)
fragment.arguments = args
return fragment
args.putStringArrayList(KEY_LANGUAGE_LIST, languageArrayList)
args.putInt(KEY_SELECTED_INDEX, selectedIndex)
languageDialogFragment.arguments = args
return languageDialogFragment
}
}

override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
var languageList = savedInstanceState?.getStringArrayList(KEY_LANGUAGE_LIST)
var currentIndex = savedInstanceState?.getInt(KEY_CURRENT_LANGUAGE, 0)

if (languageList != null) {
// Not null
// Currently data is not getting transferred to LanguageDialogFragment.
} else {
// Null
// Error handling can be done here if needed.
languageList = ArrayList<String>()
languageList.add("en")
languageList.add("hi")
languageList.add("hi-en")
}
val args = checkNotNull(arguments) { "Expected arguments to be pass to LanguageDialogFragment" }

var selectedIndex = args.getInt(KEY_SELECTED_INDEX, 0)
val languageArrayList: ArrayList<String> = args.getStringArrayList(KEY_LANGUAGE_LIST)
val options = languageArrayList.toTypedArray<CharSequence>()

val options = languageList!!.toTypedArray<CharSequence>()
val languageInterface: LanguageInterface = parentFragment as AudioFragment

return AlertDialog.Builder(activity as Context)
.setTitle(R.string.audio_language_select_dialog_title)
.setSingleChoiceItems(options, 0) { dialog, which ->
currentIndex = which
.setSingleChoiceItems(options, selectedIndex) { dialog, which ->
selectedIndex = which
}
.setPositiveButton(R.string.audio_language_select_dialog_okay_button) { dialog, whichButton ->
languageInterface1.onLanguageSelected(languageList.get(currentIndex!!))
languageInterface.onLanguageSelected(languageArrayList[selectedIndex])
dismiss()
}
.setNegativeButton(R.string.audio_language_select_dialog_cancel_button) { dialog, whichButton ->
dismiss()
}
.setCancelable(true)
.create()
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.oppia.app.player.audio

/** Interface to receive selected language from [LanguageDialogFragment] */
/** Interface to receive selected language from [LanguageDialogFragment]. */
interface LanguageInterface {
/** Play the audio corresponding to the language-selected. */
fun onLanguageSelected(currentLanguageCode: String)
}
46 changes: 43 additions & 3 deletions app/src/main/java/org/oppia/app/player/state/StateFragment.kt
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,22 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.oppia.app.fragment.InjectableFragment
import org.oppia.app.player.audio.CellularDataDialogFragment
import org.oppia.app.player.audio.CellularDataInterface
import javax.inject.Inject

/** Fragment that represents the current state card of an exploration. */
class StateFragment : InjectableFragment() {
@Inject lateinit var stateFragmentPresenter: StateFragmentPresenter
private const val TAG_CELLULAR_DATA_DIALOG = "CELLULAR_DATA_DIALOG"

/** Fragment that represents the current state of an exploration. */
class StateFragment : InjectableFragment(), CellularDataInterface {
@Inject
lateinit var stateFragmentPresenter: StateFragmentPresenter
// Control this boolean value from controllers in domain module.
private var showCellularDataDialog = true

init {
// TODO(#116): Code to control the value of showCellularDataDialog using AudioController.
}

override fun onAttach(context: Context?) {
super.onAttach(context)
Expand All @@ -20,4 +31,33 @@ class StateFragment : InjectableFragment() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
return stateFragmentPresenter.handleCreateView(inflater, container)
}

fun dummyButtonClicked() {
if (showCellularDataDialog) {
stateFragmentPresenter.setAudioFragmentVisible(false)
showCellularDataDialogFragment()
} else {
stateFragmentPresenter.setAudioFragmentVisible(true)
}
}

private fun showCellularDataDialogFragment() {
val previousFragment = childFragmentManager.findFragmentByTag(TAG_CELLULAR_DATA_DIALOG)
if (previousFragment != null) {
childFragmentManager.beginTransaction().remove(previousFragment).commitNow()
}
val dialogFragment = CellularDataDialogFragment.newInstance()
dialogFragment.showNow(childFragmentManager, TAG_CELLULAR_DATA_DIALOG)
}

override fun enableAudioWhileOnCellular(saveUserChoice: Boolean) {
stateFragmentPresenter.setAudioFragmentVisible(true)
// saveUserChoice -> true -> save this preference
// saveUserChoice -> false -> do not save this preference
}

override fun disableAudioWhileOnCellular(saveUserChoice: Boolean) {
// saveUserChoice -> true -> save this preference
// saveUserChoice -> false -> do not save this preference
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,29 @@ import android.view.ViewGroup
import androidx.fragment.app.Fragment
import org.oppia.app.databinding.StateFragmentBinding
import org.oppia.app.fragment.FragmentScope
import org.oppia.app.viewmodel.ViewModelProvider
import javax.inject.Inject

/** The controller for [StateFragment]. */
/** The presenter for [StateFragment]. */
@FragmentScope
class StateFragmentPresenter @Inject constructor(
private val fragment: Fragment
private val fragment: Fragment,
private val viewModelProvider: ViewModelProvider<StateViewModel>
) {
fun handleCreateView(inflater: LayoutInflater, container: ViewGroup?): View? {
return StateFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false).root
val binding = StateFragmentBinding.inflate(inflater, container, /* attachToRoot= */ false)
binding.let {
it.stateFragment = fragment as StateFragment
it.viewModel = getStateViewModel()
}
return binding.root
}

private fun getStateViewModel(): StateViewModel {
return viewModelProvider.getForFragment(fragment, StateViewModel::class.java)
}

fun setAudioFragmentVisible(isVisible: Boolean) {
getStateViewModel().setAudioFragmentVisible(isVisible)
}
}
16 changes: 16 additions & 0 deletions app/src/main/java/org/oppia/app/player/state/StateViewModel.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.oppia.app.player.state

import androidx.databinding.ObservableField
import androidx.lifecycle.ViewModel
import org.oppia.app.fragment.FragmentScope
import javax.inject.Inject

/** [ViewModel] for state-fragment. */
@FragmentScope
class StateViewModel @Inject constructor() : ViewModel() {
var isAudioFragmentVisible = ObservableField<Boolean>(false)

fun setAudioFragmentVisible(isVisible: Boolean) {
isAudioFragmentVisible.set(isVisible)
}
}
14 changes: 14 additions & 0 deletions app/src/main/res/layout/cellular_data_dialog.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="@dimen/cellular_data_dialog_padding">
<CheckBox
android:id="@+id/cellular_data_dialog_checkbox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:text="@string/cellular_data_alert_dialog_checkbox">
</CheckBox>
</RelativeLayout>
Loading

0 comments on commit 1ea9d01

Please sign in to comment.