Skip to content

Commit

Permalink
change Accessibility service from constructor injection to field inje…
Browse files Browse the repository at this point in the history
…ction
  • Loading branch information
XichengSpencer committed Jul 12, 2023
1 parent 02e96f9 commit 5325740
Show file tree
Hide file tree
Showing 5 changed files with 82 additions and 67 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,20 @@ package org.oppia.android.app.help.thirdparty

import androidx.appcompat.app.AppCompatActivity
import androidx.databinding.DataBindingUtil
import javax.inject.Inject
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.LicenseTextViewerActivityBinding
import org.oppia.android.util.accessibility.AccessibilityService
import javax.inject.Inject

/** The presenter for [LicenseTextViewerActivity]. */
@ActivityScope
class LicenseTextViewerActivityPresenter @Inject constructor(
private val activity: AppCompatActivity,
private val accessibilityService: AccessibilityService,
private val resourceHandler: AppLanguageResourceHandler
) {
@Inject lateinit var accessibilityService: AccessibilityService

/** Handles onCreate() method of the [LicenseTextViewerActivity]. */
fun handleOnCreate(dependencyIndex: Int, licenseIndex: Int) {
Expand Down Expand Up @@ -46,11 +46,9 @@ class LicenseTextViewerActivityPresenter @Inject constructor(
(activity as LicenseTextViewerActivity).finish()
}

activity.applicationContext?.let {
if (!accessibilityService.isScreenReaderEnabled()) {
binding.licenseTextViewerActivityToolbarTitle.setOnClickListener {
binding.licenseTextViewerActivityToolbarTitle.isSelected = true
}
if (!accessibilityService.isScreenReaderEnabled()) {
binding.licenseTextViewerActivityToolbarTitle.setOnClickListener {
binding.licenseTextViewerActivityToolbarTitle.isSelected = true
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import androidx.core.view.doOnPreDraw
import androidx.databinding.DataBindingUtil
import androidx.lifecycle.LiveData
import androidx.lifecycle.Transformations
import javax.inject.Inject
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityScope
import org.oppia.android.app.help.HelpActivity
Expand All @@ -35,9 +34,10 @@ import org.oppia.android.databinding.ExplorationActivityBinding
import org.oppia.android.domain.exploration.ExplorationDataController
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.translation.TranslationController
import org.oppia.android.util.accessibility.AccessibilityService
import org.oppia.android.util.data.AsyncResult
import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.accessibility.AccessibilityService
import javax.inject.Inject

private const val TAG_UNSAVED_EXPLORATION_DIALOG = "UNSAVED_EXPLORATION_DIALOG"
private const val TAG_STOP_EXPLORATION_DIALOG = "STOP_EXPLORATION_DIALOG"
Expand All @@ -54,10 +54,11 @@ class ExplorationActivityPresenter @Inject constructor(
private val viewModelProvider: ViewModelProvider<ExplorationViewModel>,
private val fontScaleConfigurationUtil: FontScaleConfigurationUtil,
private val translationController: TranslationController,
private val accessibilityService: AccessibilityService,
private val oppiaLogger: OppiaLogger,
private val resourceHandler: AppLanguageResourceHandler
) {
@Inject lateinit var accessibilityService: AccessibilityService

private lateinit var explorationToolbar: Toolbar
private lateinit var explorationToolbarTitle: TextView
private lateinit var profileId: ProfileId
Expand Down Expand Up @@ -182,7 +183,11 @@ class ExplorationActivityPresenter @Inject constructor(
activity.supportFragmentManager.beginTransaction().add(
R.id.exploration_fragment_placeholder,
ExplorationFragment.newInstance(
profileId, topicId, storyId, explorationId, readingTextSize
profileId,
topicId,
storyId,
explorationId,
readingTextSize
),
TAG_EXPLORATION_FRAGMENT
).commitNow()
Expand Down Expand Up @@ -212,7 +217,8 @@ class ExplorationActivityPresenter @Inject constructor(
}
R.id.action_help -> {
val intent = HelpActivity.createHelpActivityIntent(
activity, profileId.internalId,
activity,
profileId.internalId,
/* isFromNavigationDrawer= */false
)
fontScaleConfigurationUtil.adjustFontScale(activity, ReadingTextSize.MEDIUM_TEXT_SIZE)
Expand Down Expand Up @@ -267,30 +273,30 @@ class ExplorationActivityPresenter @Inject constructor(
// without deleting any checkpoints.
if (::oldestCheckpointExplorationId.isInitialized) {
explorationDataController.deleteExplorationProgressById(
profileId, oldestCheckpointExplorationId
profileId,
oldestCheckpointExplorationId
)
}
stopExploration(isCompletion = false)
}

fun stopExploration(isCompletion: Boolean) {
private fun stopExploration(isCompletion: Boolean) {
fontScaleConfigurationUtil.adjustFontScale(activity, ReadingTextSize.MEDIUM_TEXT_SIZE)
explorationDataController.stopPlayingExploration(isCompletion).toLiveData()
.observe(
activity,
{
when (it) {
is AsyncResult.Pending -> oppiaLogger.d("ExplorationActivity", "Stopping exploration")
is AsyncResult.Failure ->
oppiaLogger.e("ExplorationActivity", "Failed to stop exploration", it.error)
is AsyncResult.Success -> {
oppiaLogger.d("ExplorationActivity", "Successfully stopped exploration")
backPressActivitySelector()
(activity as ExplorationActivity).finish()
}
activity
) {
when (it) {
is AsyncResult.Pending -> oppiaLogger.d("ExplorationActivity", "Stopping exploration")
is AsyncResult.Failure ->
oppiaLogger.e("ExplorationActivity", "Failed to stop exploration", it.error)
is AsyncResult.Success -> {
oppiaLogger.d("ExplorationActivity", "Successfully stopped exploration")
backPressActivitySelector()
(activity as ExplorationActivity).finish()
}
}
)
}
}

fun onKeyboardAction(actionCode: Int) {
Expand Down Expand Up @@ -338,7 +344,8 @@ class ExplorationActivityPresenter @Inject constructor(
explorationLiveData.observe(activity) {
explorationToolbarTitle.text =
translationController.extractString(
it.exploration.translatableTitle, it.writtenTranslationContext
it.exploration.translatableTitle,
it.writtenTranslationContext
)
}
}
Expand All @@ -361,7 +368,9 @@ class ExplorationActivityPresenter @Inject constructor(
return when (ephemeralExpResult) {
is AsyncResult.Failure -> {
oppiaLogger.e(
"ExplorationActivity", "Failed to retrieve answer outcome", ephemeralExpResult.error
"ExplorationActivity",
"Failed to retrieve answer outcome",
ephemeralExpResult.error
)
EphemeralExploration.getDefaultInstance()
}
Expand Down Expand Up @@ -470,7 +479,9 @@ class ExplorationActivityPresenter @Inject constructor(
}
is AsyncResult.Failure -> {
oppiaLogger.e(
"ExplorationActivity", "Failed to retrieve oldest saved checkpoint details.", it.error
"ExplorationActivity",
"Failed to retrieve oldest saved checkpoint details.",
it.error
)
}
is AsyncResult.Pending -> {} // Wait for an actual result.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import androidx.fragment.app.Fragment
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.LinearSmoothScroller
import androidx.recyclerview.widget.RecyclerView
import javax.inject.Inject
import org.oppia.android.R
import org.oppia.android.app.home.RouteToExplorationListener
import org.oppia.android.app.model.ChapterPlayState
Expand All @@ -43,6 +42,7 @@ import org.oppia.android.util.data.DataProviders.Companion.toLiveData
import org.oppia.android.util.gcsresource.DefaultResourceBucketName
import org.oppia.android.util.parser.html.HtmlParser
import org.oppia.android.util.parser.html.TopicHtmlParserEntityType
import javax.inject.Inject

/** The presenter for [StoryFragment]. */
class StoryFragmentPresenter @Inject constructor(
Expand All @@ -65,16 +65,17 @@ class StoryFragmentPresenter @Inject constructor(
private lateinit var linearSmoothScroller: RecyclerView.SmoothScroller
private lateinit var profileId: ProfileId

@Inject lateinit var storyViewModel: StoryViewModel
@Inject lateinit var accessibilityService: AccessibilityService

@Inject lateinit var storyViewModel: StoryViewModel

fun handleCreateView(
inflater: LayoutInflater,
container: ViewGroup?,
internalProfileId: Int,
topicId: String,
storyId: String
): View? {
): View {
binding = StoryFragmentBinding.inflate(
inflater,
container,
Expand All @@ -90,11 +91,9 @@ class StoryFragmentPresenter @Inject constructor(
(activity as StoryActivity).finish()
}

activity.applicationContext?.let {
if (!accessibilityService.isScreenReaderEnabled()) {
binding.storyToolbarTitle.setOnClickListener {
binding.storyToolbarTitle.isSelected = true
}
if (!accessibilityService.isScreenReaderEnabled()) {
binding.storyToolbarTitle.setOnClickListener {
binding.storyToolbarTitle.isSelected = true
}
}

Expand Down Expand Up @@ -278,11 +277,17 @@ class StoryFragmentPresenter @Inject constructor(
// one.
val startPlayingProvider = if (canHavePartialProgressSaved) {
explorationDataController.startPlayingNewExploration(
profileId.internalId, topicId, storyId, explorationId
profileId.internalId,
topicId,
storyId,
explorationId
)
} else {
explorationDataController.replayExploration(
profileId.internalId, topicId, storyId, explorationId
profileId.internalId,
topicId,
storyId,
explorationId
)
}
startPlayingProvider.toLiveData().observe(fragment) { result ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import androidx.fragment.app.Fragment
import androidx.viewpager2.widget.ViewPager2
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayoutMediator
import javax.inject.Inject
import org.oppia.android.R
import org.oppia.android.app.fragment.FragmentScope
import org.oppia.android.app.model.ProfileId
Expand All @@ -21,9 +20,10 @@ import org.oppia.android.app.translation.AppLanguageResourceHandler
import org.oppia.android.databinding.TopicFragmentBinding
import org.oppia.android.domain.oppialogger.OppiaLogger
import org.oppia.android.domain.oppialogger.analytics.AnalyticsController
import org.oppia.android.util.accessibility.AccessibilityService
import org.oppia.android.util.platformparameter.EnableExtraTopicTabsUi
import org.oppia.android.util.platformparameter.PlatformParameterValue
import org.oppia.android.util.accessibility.AccessibilityService
import javax.inject.Inject

/** The presenter for [TopicFragment]. */
@FragmentScope
Expand All @@ -32,11 +32,12 @@ class TopicFragmentPresenter @Inject constructor(
private val fragment: Fragment,
private val viewModel: TopicViewModel,
private val oppiaLogger: OppiaLogger,
private val accessibilityService: AccessibilityService,
private val analyticsController: AnalyticsController,
@EnableExtraTopicTabsUi private val enableExtraTopicTabsUi: PlatformParameterValue<Boolean>,
private val resourceHandler: AppLanguageResourceHandler
) {
@Inject lateinit var accessibilityService: AccessibilityService

private lateinit var tabLayout: TabLayout
private var internalProfileId: Int = -1
private lateinit var topicId: String
Expand All @@ -50,7 +51,7 @@ class TopicFragmentPresenter @Inject constructor(
topicId: String,
storyId: String,
isConfigChanged: Boolean
): View? {
): View {
val binding = TopicFragmentBinding.inflate(
inflater,
container,
Expand All @@ -67,12 +68,9 @@ class TopicFragmentPresenter @Inject constructor(
(activity as TopicActivity).finish()
}

activity.applicationContext?.let {

if (!accessibilityService.isScreenReaderEnabled()) {
binding.topicToolbar.setOnClickListener {
binding.topicToolbarTitle.isSelected = true
}
if (!accessibilityService.isScreenReaderEnabled()) {
binding.topicToolbar.setOnClickListener {
binding.topicToolbarTitle.isSelected = true
}
}

Expand Down Expand Up @@ -159,7 +157,8 @@ class TopicFragmentPresenter @Inject constructor(
TopicTab.REVISION -> oppiaLogger.createOpenRevisionTabContext(topicId)
}
analyticsController.logImportantEvent(
eventContext, ProfileId.newBuilder().apply { internalId = internalProfileId }.build()
eventContext,
ProfileId.newBuilder().apply { internalId = internalProfileId }.build()
)
}
}
Loading

0 comments on commit 5325740

Please sign in to comment.