Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finalize language selector #5

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ class AdministratorControlsDownloadPermissionsViewModel(
private val userProfileId: ProfileId,
deviceSettings: DeviceSettings
) : AdministratorControlsItemViewModel() {
/** [Boolean] observable value showing if topic downloads and updates should happen only on Wifi. */
/**
* [Boolean] observable value showing if topic downloads and updates should happen only on Wifi.
*/
val isTopicWifiUpdatePermission =
ObservableField<Boolean>(deviceSettings.allowDownloadAndUpdateOnlyOnWifi)
/** [Boolean] observable value showing if topic updates should happen automatically. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@ package org.oppia.android.app.administratorcontrols.administratorcontrolsitemvie
import androidx.databinding.ObservableField
import org.oppia.android.app.viewmodel.ObservableViewModel

/** Super-class for generalising different views for the recyclerView in [AdministratorControlsFragment] */
/**
* Super-class for generalising different views for the recyclerView in
* [AdministratorControlsFragment].
*/
abstract class AdministratorControlsItemViewModel : ObservableViewModel() {
/** [Boolean] observable value showing if [View] is multipane. */
val isMultipane = ObservableField<Boolean>(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class AdministratorControlsProfileViewModel(
private val loadProfileListListener: LoadProfileListListener
) : AdministratorControlsItemViewModel() {

/** Called when user clicks on EditProfiles in [AdministratorControlsActivity]. */
/** Called when a user clicks on EditProfiles in [AdministratorControlsActivity]. */
fun onEditProfilesClicked() {
if (isMultipane.get()!!) {
loadProfileListListener.loadProfileList()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import org.oppia.android.app.utility.getVersionName
import org.oppia.android.app.viewmodel.ObservableViewModel
import javax.inject.Inject

/** [ViewModel] for [AppVersionFragment] */
/** [ViewModel] for [AppVersionFragment]. */
@FragmentScope
class AppVersionViewModel @Inject constructor(
private val resourceHandler: AppLanguageResourceHandler,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,11 @@ private const val STROKE_DASH_GAP_IN_DEGREE = 12
*
* Reference: // https://stackoverflow.com/a/39210676
*/
class SegmentedCircularProgressView : View {
class SegmentedCircularProgressView @JvmOverloads constructor(
context: Context,
attrs: AttributeSet? = null,
defStyleAttr: Int = 0
) : View(context, attrs, defStyleAttr) {
@Inject
lateinit var resourceHandler: AppLanguageResourceHandler

Expand Down Expand Up @@ -63,23 +67,6 @@ class SegmentedCircularProgressView : View {
}
}

/** Constructor for creating an instance of this view.
* @param context */
constructor(context: Context) : super(context)
/** Constructor for creating an instance of this view.
* @param context
* @param attrs */
constructor(context: Context, attrs: AttributeSet) : super(context, attrs)
/** Constructor for creating an instance of this view.
* @param context
* @param attrs
* @param defStyleAttr */
constructor(context: Context, attrs: AttributeSet, defStyleAttr: Int) : super(
context,
attrs,
defStyleAttr
)

private fun initialise() {
chaptersNotStarted = totalChapters - chaptersFinished - chaptersInProgress
strokeWidth = dpToPx(4)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class DeveloperOptionsActivity :
}

companion object {
/** Function to create intent for DeveloperOptionsActivity */
/** Function to create intent for DeveloperOptionsActivity. */
fun createDeveloperOptionsActivityIntent(context: Context, internalProfileId: Int): Intent {
return Intent(context, DeveloperOptionsActivity::class.java).apply {
putExtra(NAVIGATION_PROFILE_ID_ARGUMENT_KEY, internalProfileId)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package org.oppia.android.app.help

/** Listener for when a selection should result to [FAQListFragment] in tablet devices. */
interface LoadFaqListFragmentListener {
/** Called when the user wants to open the list of FAQs in tablet devices. */
/** Called when the user wants to open the list of FAQs in tablet devices. */
fun loadFaqListFragment()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ import org.oppia.android.app.model.PolicyPage
* on tablet.
*/
interface LoadPoliciesFragmentListener {
/** Called when the user wants to view an app policy. */
/** Called when the user wants to view an app policy. */
fun loadPoliciesFragment(policyPage: PolicyPage)
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ package org.oppia.android.app.help
* devices.
*/
interface LoadThirdPartyDependencyListFragmentListener {
/** Called when the user wants to open the list of third-party dependencies in tablet devices. */
/** Called when the user wants to open the list of third-party dependencies in tablet devices. */
fun loadThirdPartyDependencyListFragment()
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ package org.oppia.android.app.help

/** Listener for when a selection should result to [ThirdPartyDependencyListActivity]. */
interface RouteToThirdPartyDependencyListListener {
/** Called when the user wants to open the list of third-party dependencies. */
/** Called when the user wants to open the list of third-party dependencies. */
fun onRouteToThirdPartyDependencyList()
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ package org.oppia.android.app.hintsandsolution
*/
interface ExpandedHintListIndexListener {

/** Manage expanded list icon */
/** Manage expanded list icon. */
fun onExpandListIconClicked(expandedItemsList: ArrayList<Int>)

/** Manage reveal hint button visibility while orientation change */
/** Manage reveal hint button visibility while orientation change. */
fun onRevealHintClicked(index: Int?, isHintRevealed: Boolean?)

/** Manage reveal solution button visibility while orientation change */
/** Manage reveal solution button visibility while orientation change. */
fun onRevealSolutionClicked(solutionIndex: Int?, isSolutionRevealed: Boolean?)
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.oppia.android.app.hintsandsolution

/** Allows parent activity to dismiss the [HintsAndSolutionFragmentt] */
/** Allows parent activity to dismiss the [HintsAndSolutionFragment]. */
interface HintsAndSolutionListener {
/** Called when the hints and solution dialog should be dismissed. */
fun dismiss()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ class PromotedStoryViewModel(
)
}

/** Starts [ResumeLessonActivity] if a saved exploration is selected
* or [ExplorationActivity] if an un-started recommended story is selected.
*/
/**
* Starts [ResumeLessonActivity] if a saved exploration is selected or [ExplorationActivity] if an
* un-started recommended story is selected. */
fun clickOnPromotedStoryTile(@Suppress("UNUSED_PARAMETER") v: View) {
promotedStoryClickListener.promotedStoryClicked(promotedStory)
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package org.oppia.android.app.onboarding

/** Listener for buttons in OnboardingFragment */
/** Listener for buttons in OnboardingFragment. */
interface OnboardingNavigationListener {

/** Skips onboarding slide. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.drawer.NAVIGATION_PROFILE_ID_ARGUMENT_KEY
import org.oppia.android.app.model.AppLanguageActivityParams
import org.oppia.android.app.model.AppLanguageActivityResultBundle
import org.oppia.android.app.model.AppLanguageActivityStateBundle
import org.oppia.android.app.model.OppiaLanguage
import org.oppia.android.app.model.ScreenName.APP_LANGUAGE_ACTIVITY
Expand Down Expand Up @@ -67,16 +66,7 @@ class AppLanguageActivity : InjectableAutoLocalizedAppCompatActivity() {
}
}

override fun onBackPressed() {
val resultBundle = AppLanguageActivityResultBundle.newBuilder().apply {
oppiaLanguage = appLanguageActivityPresenter.getLanguageSelected()
}.build()
val intent = Intent().apply {
putProtoExtra(MESSAGE_APP_LANGUAGE_ARGUMENT_KEY, resultBundle)
}
setResult(REQUEST_CODE_APP_LANGUAGE, intent)
finish()
}
override fun onBackPressed() = finish()

override fun onSaveInstanceState(outState: Bundle) {
super.onSaveInstanceState(outState)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package org.oppia.android.app.options

import android.content.Intent
import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import org.oppia.android.R
Expand All @@ -12,21 +11,15 @@ import javax.inject.Inject
/** The presenter for [AppLanguageActivity]. */
@ActivityScope
class AppLanguageActivityPresenter @Inject constructor(private val activity: AppCompatActivity) {
private lateinit var oppiaLangauge: OppiaLanguage
private lateinit var oppiaLanguage: OppiaLanguage

/** Initializes and creates the views for [AppLanguageActivity]. */
fun handleOnCreate(oppiaLanguage: OppiaLanguage, profileId: Int) {
val binding: AppLanguageActivityBinding = DataBindingUtil.setContentView(
activity,
R.layout.app_language_activity,
)
binding.appLanguageToolbar.setNavigationOnClickListener {
val intent = Intent().apply {
putExtra(MESSAGE_APP_LANGUAGE_ARGUMENT_KEY, oppiaLanguage)
}
(activity as AppLanguageActivity).setResult(REQUEST_CODE_APP_LANGUAGE, intent)
activity.finish()
}
binding.appLanguageToolbar.setNavigationOnClickListener { activity.finish() }
setLanguageSelected(oppiaLanguage)
if (getAppLanguageFragment() == null) {
val appLanguageFragment = AppLanguageFragment.newInstance(oppiaLanguage, profileId)
Expand All @@ -37,13 +30,11 @@ class AppLanguageActivityPresenter @Inject constructor(private val activity: App

/** Set the selected language for this Activity. */
fun setLanguageSelected(oppiaLanguage: OppiaLanguage) {
this.oppiaLangauge = oppiaLanguage
this.oppiaLanguage = oppiaLanguage
}

/** Return's the selected language for this Activity. */
fun getLanguageSelected(): OppiaLanguage {
return oppiaLangauge
}
fun getLanguageSelected(): OppiaLanguage = oppiaLanguage

private fun getAppLanguageFragment(): AppLanguageFragment? {
return activity.supportFragmentManager
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class AppLanguageFragmentPresenter @Inject constructor(
private val oppiaLogger: OppiaLogger
) {
private lateinit var appLanguage: OppiaLanguage
private var profileId: Int? = -1
private lateinit var profileId: ProfileId

/** Initializes and creates the views for [AppLanguageFragment]. */
fun handleOnCreateView(
Expand All @@ -40,7 +40,7 @@ class AppLanguageFragmentPresenter @Inject constructor(
/* attachToRoot= */ false
)
this.appLanguage = prefSummaryValue
this.profileId = profileId
this.profileId = ProfileId.newBuilder().apply { internalId = profileId }.build()
appLanguageSelectionViewModel.selectedLanguage.value = prefSummaryValue
binding.viewModel = appLanguageSelectionViewModel
binding.lifecycleOwner = fragment
Expand Down Expand Up @@ -84,26 +84,22 @@ class AppLanguageFragmentPresenter @Inject constructor(
}

private fun updateAppLanguageSelection(oppiaLanguage: OppiaLanguage) {
val appLanguageSelection = AppLanguageSelection.newBuilder().apply {
val selection = AppLanguageSelection.newBuilder().apply {
selectedLanguage = oppiaLanguage
}.build()

val userProfileId = ProfileId.newBuilder().apply { internalId = profileId!! }.build()

translationController.updateAppLanguage(
userProfileId, appLanguageSelection
).toLiveData().observe(
fragment,
{
when (it) {
is AsyncResult.Success -> {
appLanguage = oppiaLanguage
}
is AsyncResult.Failure ->
oppiaLogger.e("APP_LANGUAGE_TAG", it.error.toString())
is AsyncResult.Pending -> {} // Wait for a result.
translationController.updateAppLanguage(profileId, selection).toLiveData().observe(fragment) {
when (it) {
is AsyncResult.Success -> appLanguage = oppiaLanguage
is AsyncResult.Failure -> {
oppiaLogger.e(
"AppLanguageFragmentPresenter",
"Failed to update language to: $oppiaLanguage.",
it.error
)
}
is AsyncResult.Pending -> {} // Wait for a result.
}
)
}
}
}
Loading