Skip to content

Commit

Permalink
Merge pull request #6 from oppia/develop
Browse files Browse the repository at this point in the history
Develop (fork) Branch Update
  • Loading branch information
subhajitxyz authored Sep 27, 2024
2 parents 56af5ae + 8d44bf7 commit 3883f70
Show file tree
Hide file tree
Showing 13 changed files with 112 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.administratorcontrols
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
Expand Down Expand Up @@ -83,6 +84,15 @@ class AdministratorControlsActivity :
isProfileDeletionDialogVisible
)
title = resourceHandler.getStringInLocale(R.string.administrator_controls)

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
this@AdministratorControlsActivity.handleBackPress()
}
}
)
}

override fun routeToAppVersion() {
Expand Down Expand Up @@ -121,7 +131,7 @@ class AdministratorControlsActivity :
}
}

override fun onBackPressed() {
private fun handleBackPress() {
val fragment =
supportFragmentManager.findFragmentById(
R.id.administrator_controls_fragment_multipane_placeholder
Expand All @@ -134,8 +144,7 @@ class AdministratorControlsActivity :
if (fragment is ProfileEditFragment) {
administratorControlsActivityPresenter.handleOnBackPressed()
} else {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
super.onBackPressed()
finish()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ScreenName.APP_VERSION_ACTIVITY
Expand All @@ -19,12 +20,20 @@ class AppVersionActivity : InjectableAutoLocalizedAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
appVersionActivityPresenter.handleOnCreate()

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
finish()
}
}
)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
onBackPressed()
onBackPressedDispatcher.onBackPressed()
}
return super.onOptionsItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ScreenName.PROFILE_AND_DEVICE_ID_ACTIVITY
Expand All @@ -18,18 +19,27 @@ import javax.inject.Inject
* a particular user or group.
*/
class ProfileAndDeviceIdActivity : InjectableAutoLocalizedAppCompatActivity() {
@Inject lateinit var profileAndDeviceIdActivityPresenter: ProfileAndDeviceIdActivityPresenter
@Inject
lateinit var profileAndDeviceIdActivityPresenter: ProfileAndDeviceIdActivityPresenter

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
profileAndDeviceIdActivityPresenter.handleOnCreate()

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
finish()
}
}
)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
onBackPressed()
onBackPressedDispatcher.onBackPressed()
}
return super.onOptionsItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,15 +68,14 @@ public static void setDrawableEndCompat(
}

private static String getTimeAgo(View view, long lastVisitedTimestamp) {
long timeStampMillis = ensureTimestampIsInMilliseconds(lastVisitedTimestamp);
long currentTimeMillis = getOppiaClock(view).getCurrentTimeMs();
AppLanguageResourceHandler resourceHandler = getResourceHandler(view);

if (timeStampMillis > currentTimeMillis || timeStampMillis <= 0) {
if (lastVisitedTimestamp > currentTimeMillis || lastVisitedTimestamp <= 0) {
return resourceHandler.getStringInLocale(R.string.last_logged_in_recently);
}

long timeDifferenceMillis = currentTimeMillis - timeStampMillis;
long timeDifferenceMillis = currentTimeMillis - lastVisitedTimestamp;

if (timeDifferenceMillis < (int) TimeUnit.MINUTES.toMillis(1)) {
return resourceHandler.getStringInLocale(R.string.just_now);
Expand Down Expand Up @@ -112,15 +111,6 @@ private static String getPluralString(
);
}

private static long ensureTimestampIsInMilliseconds(long lastVisitedTimestamp) {
// TODO(#3842): Investigate & remove this check.
if (lastVisitedTimestamp < 1000000000000L) {
// If timestamp is given in seconds, convert that to milliseconds.
return TimeUnit.SECONDS.toMillis(lastVisitedTimestamp);
}
return lastVisitedTimestamp;
}

private static AppLanguageResourceHandler getResourceHandler(View view) {
AppLanguageActivityInjectorProvider provider =
(AppLanguageActivityInjectorProvider) getAttachedActivity(view);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
Expand Down Expand Up @@ -37,12 +38,20 @@ class MarkChaptersCompletedActivity : InjectableAutoLocalizedAppCompatActivity()
val showConfirmationNotice = args?.showConfirmationNotice ?: false
markChaptersCompletedActivityPresenter.handleOnCreate(internalProfileId, showConfirmationNotice)
title = resourceHandler.getStringInLocale(R.string.mark_chapters_completed_activity_title)

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
finish()
}
}
)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
onBackPressed()
onBackPressedDispatcher.onBackPressed()
}
return super.onOptionsItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
Expand Down Expand Up @@ -34,12 +35,20 @@ class MarkStoriesCompletedActivity : InjectableAutoLocalizedAppCompatActivity()
internalProfileId = profileId?.internalId ?: -1
markStoriesCompletedActivityPresenter.handleOnCreate(internalProfileId)
title = resourceHandler.getStringInLocale(R.string.mark_stories_completed_activity_title)

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
finish()
}
}
)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
onBackPressed()
onBackPressedDispatcher.onBackPressed()
}
return super.onOptionsItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.MenuItem
import androidx.activity.OnBackPressedCallback
import org.oppia.android.R
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
Expand Down Expand Up @@ -34,12 +35,20 @@ class MarkTopicsCompletedActivity : InjectableAutoLocalizedAppCompatActivity() {
internalProfileId = profileId?.internalId ?: -1
markTopicsCompletedActivityPresenter.handleOnCreate(internalProfileId)
title = resourceHandler.getStringInLocale(R.string.mark_topics_completed_activity_title)

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
finish()
}
}
)
}

override fun onOptionsItemSelected(item: MenuItem): Boolean {
if (item.itemId == android.R.id.home) {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
onBackPressed()
onBackPressedDispatcher.onBackPressed()
}
return super.onOptionsItemSelected(item)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.options
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.model.ReadingTextSize
Expand Down Expand Up @@ -34,6 +35,22 @@ class ReadingTextSizeActivity : InjectableAutoLocalizedAppCompatActivity() {
savedInstanceState?.retrieveStateBundle()?.selectedReadingTextSize
?: retrieveActivityParams().readingTextSize
readingTextSizeActivityPresenter.handleOnCreate(readingTextSize)

onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
val resultBundle = ReadingTextSizeActivityResultBundle.newBuilder().apply {
selectedReadingTextSize = readingTextSizeActivityPresenter.getSelectedReadingTextSize()
}.build()
val intent = Intent().apply {
putProtoExtra(MESSAGE_READING_TEXT_SIZE_RESULTS_KEY, resultBundle)
}
setResult(RESULT_OK, intent)
finish()
}
}
)
}

companion object {
Expand All @@ -60,17 +77,6 @@ class ReadingTextSizeActivity : InjectableAutoLocalizedAppCompatActivity() {
outState.putProto(ACTIVITY_SAVED_STATE_KEY, stateBundle)
}

override fun onBackPressed() {
val resultBundle = ReadingTextSizeActivityResultBundle.newBuilder().apply {
selectedReadingTextSize = readingTextSizeActivityPresenter.getSelectedReadingTextSize()
}.build()
val intent = Intent().apply {
putProtoExtra(MESSAGE_READING_TEXT_SIZE_RESULTS_KEY, resultBundle)
}
setResult(RESULT_OK, intent)
finish()
}

private fun retrieveActivityParams() =
intent.getProtoExtra(ACTIVITY_PARAMS_KEY, ReadingTextSizeActivityParams.getDefaultInstance())

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ class ReadingTextSizeActivityPresenter @Inject constructor(
private fun setToolbar() {
val readingTextSizeToolbar: Toolbar = activity.findViewById(R.id.reading_text_size_toolbar)
readingTextSizeToolbar.setNavigationOnClickListener {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.player.exploration
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.hintsandsolution.HintsAndSolutionDialogFragment
Expand Down Expand Up @@ -48,7 +49,8 @@ class ExplorationActivity :
BottomSheetOptionsMenuItemClickListener,
RequestVoiceOverIconSpotlightListener {

@Inject lateinit var explorationActivityPresenter: ExplorationActivityPresenter
@Inject
lateinit var explorationActivityPresenter: ExplorationActivityPresenter
private lateinit var state: State
private lateinit var writtenTranslationContext: WrittenTranslationContext

Expand All @@ -67,6 +69,14 @@ class ExplorationActivity :
params.parentScreen,
params.isCheckpointingEnabled
)
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
explorationActivityPresenter.backButtonPressed()
}
}
)
}

// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
Expand Down Expand Up @@ -114,10 +124,6 @@ class ExplorationActivity :
getProtoExtra(PARAMS_KEY, ExplorationActivityParams.getDefaultInstance())
}

override fun onBackPressed() {
explorationActivityPresenter.backButtonPressed()
}

override fun deleteCurrentProgressAndStopSession(isCompletion: Boolean) {
explorationActivityPresenter.deleteCurrentProgressAndStopExploration(isCompletion)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,8 +113,7 @@ class ExplorationActivityPresenter @Inject constructor(
}

binding.explorationToolbar.setNavigationOnClickListener {
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}

binding.actionAudioPlayer.setOnClickListener {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.oppia.android.app.resumelesson
import android.content.Context
import android.content.Intent
import android.os.Bundle
import androidx.activity.OnBackPressedCallback
import org.oppia.android.app.activity.ActivityComponentImpl
import org.oppia.android.app.activity.InjectableAutoLocalizedAppCompatActivity
import org.oppia.android.app.home.RouteToExplorationListener
Expand Down Expand Up @@ -41,6 +42,15 @@ class ResumeLessonActivity :
params.parentScreen,
params.checkpoint
)
onBackPressedDispatcher.addCallback(
this,
object : OnBackPressedCallback(/* enabled = */ true) {
override fun handleOnBackPressed() {
resumeLessonActivityPresenter.setReadingTextSizeNormal()
finish()
}
}
)
}

// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
Expand Down Expand Up @@ -113,9 +123,4 @@ class ResumeLessonActivity :
override fun onDefaultFontSizeLoaded(readingTextSize: ReadingTextSize) {
resumeLessonActivityPresenter.loadResumeLessonFragment(readingTextSize)
}

override fun onBackPressed() {
resumeLessonActivityPresenter.setReadingTextSizeNormal()
finish()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,7 @@ class ResumeLessonActivityPresenter @Inject constructor(
context = activity,
ReadingTextSize.MEDIUM_TEXT_SIZE
)
@Suppress("DEPRECATION") // TODO(#5404): Migrate to a back pressed dispatcher.
activity.onBackPressed()
activity.onBackPressedDispatcher.onBackPressed()
}
}

Expand Down

0 comments on commit 3883f70

Please sign in to comment.