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

Fixes #3641 Use finish() instead of intent for smoother navigation #5557

Merged
merged 8 commits into from
Nov 15, 2024
164 changes: 0 additions & 164 deletions .idea/codeStyles/Project.xml
adhiamboperes marked this conversation as resolved.
Outdated
Show resolved Hide resolved
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ class ExitProfileDialogFragment : InjectableDialogFragment() {
dialog.dismiss()
}
.setPositiveButton(R.string.home_activity_back_dialog_exit) { _, _ ->
// TODO(#3641): Investigate on using finish instead of intent.
val intent = ProfileChooserActivity.createProfileChooserActivity(activity!!)
if (!restoreLastCheckedItem) {
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,7 @@ class AddProfileActivity : InjectableAutoLocalizedAppCompatActivity() {
}

override fun onSupportNavigateUp(): Boolean {
// TODO(#3641): Investigate on using finish instead of intent.
val intent = Intent(this, ProfileChooserActivity::class.java)
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP)
startActivity(intent)
finish()
return false
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,11 @@ import android.content.res.Resources
import android.net.Uri
import android.provider.MediaStore
import androidx.appcompat.app.AppCompatActivity
import androidx.test.core.app.ActivityScenario
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
import androidx.test.core.app.ActivityScenario.launch
import androidx.test.core.app.ApplicationProvider
import androidx.test.espresso.Espresso.onView
import androidx.test.espresso.action.ViewActions
import androidx.test.espresso.action.ViewActions.click
import androidx.test.espresso.action.ViewActions.closeSoftKeyboard
import androidx.test.espresso.action.ViewActions.pressImeActionButton
Expand All @@ -38,6 +40,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.common.truth.Truth.assertThat
import dagger.Component
import javax.inject.Inject
import javax.inject.Singleton
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.not
Expand Down Expand Up @@ -125,8 +129,6 @@ import org.oppia.android.util.parser.image.GlideImageLoaderModule
import org.oppia.android.util.parser.image.ImageParsingModule
import org.robolectric.annotation.Config
import org.robolectric.annotation.LooperMode
import javax.inject.Inject
import javax.inject.Singleton

@RunWith(AndroidJUnit4::class)
@LooperMode(LooperMode.Mode.PAUSED)
Expand Down Expand Up @@ -1749,81 +1751,91 @@ class AddProfileActivityTest {
assertThat(currentScreenName).isEqualTo(ScreenName.ADD_PROFILE_ACTIVITY)
}

private fun createAddProfileActivityIntent(): Intent {
return AddProfileActivity.createAddProfileActivityIntent(
ApplicationProvider.getApplicationContext(),
colorRgb = -10710042
)
@Test
fun testAddProfileActivity_onBackPressed_finishActivity() {
val scenario = launch(AddProfileActivity::class.java)
onView(isRoot()).perform(ViewActions.pressBack())
testCoroutineDispatchers.runCurrent()
scenario.onActivity { activity ->
assertThat(activity.isFinishing).isTrue()
}
}

private fun createGalleryPickActivityResultStub(): ActivityResult {
val resources: Resources = context.resources
val imageUri = Uri.parse(
ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
resources.getResourcePackageName(R.mipmap.launcher_icon) + '/' +
resources.getResourceTypeName(R.mipmap.launcher_icon) + '/' +
resources.getResourceEntryName(R.mipmap.launcher_icon)
)
val resultIntent = Intent()
resultIntent.data = imageUri
return ActivityResult(RESULT_OK, resultIntent)
}
private fun createAddProfileActivityIntent(): Intent {
return AddProfileActivity.createAddProfileActivityIntent(
ApplicationProvider.getApplicationContext(),
colorRgb = -10710042
)
}

// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
modules = [
RobolectricModule::class, TestDispatcherModule::class, ApplicationModule::class,
TestPlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
DragDropSortInputModule::class, ImageClickInputModule::class, InteractionsModule::class,
GcsResourceModule::class, GlideImageLoaderModule::class, ImageParsingModule::class,
HtmlParserEntityTypeModule::class, QuestionModule::class, TestLogReportingModule::class,
AccessibilityTestModule::class, LogStorageModule::class, CachingTestModule::class,
ExpirationMetaDataRetrieverModule::class,
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class,
NumericExpressionInputModule::class, AlgebraicExpressionInputModule::class,
MathEquationInputModule::class, SplitScreenInteractionModule::class,
LoggingIdentifierModule::class, ApplicationLifecycleModule::class,
SyncStatusModule::class, MetricLogSchedulerModule::class, TestingBuildFlavorModule::class,
EventLoggingConfigurationModule::class, ActivityRouterModule::class,
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class,
TestAuthenticationModule::class
]
private fun createGalleryPickActivityResultStub(): ActivityResult {
val resources: Resources = context.resources
val imageUri = Uri.parse(
ContentResolver.SCHEME_ANDROID_RESOURCE + "://" +
resources.getResourcePackageName(R.mipmap.launcher_icon) + '/' +
resources.getResourceTypeName(R.mipmap.launcher_icon) + '/' +
resources.getResourceEntryName(R.mipmap.launcher_icon)
)
interface TestApplicationComponent : ApplicationComponent {
@Component.Builder
interface Builder : ApplicationComponent.Builder {
override fun build(): TestApplicationComponent
}
val resultIntent = Intent()
resultIntent.data = imageUri
return ActivityResult(RESULT_OK, resultIntent)
}

fun inject(addProfileActivityTest: AddProfileActivityTest)
// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
modules = [
RobolectricModule::class, TestDispatcherModule::class, ApplicationModule::class,
TestPlatformParameterModule::class, PlatformParameterSingletonModule::class,
LoggerModule::class, ContinueModule::class, FractionInputModule::class,
ItemSelectionInputModule::class, MultipleChoiceInputModule::class,
NumberWithUnitsRuleModule::class, NumericInputRuleModule::class, TextInputRuleModule::class,
DragDropSortInputModule::class, ImageClickInputModule::class, InteractionsModule::class,
GcsResourceModule::class, GlideImageLoaderModule::class, ImageParsingModule::class,
HtmlParserEntityTypeModule::class, QuestionModule::class, TestLogReportingModule::class,
AccessibilityTestModule::class, LogStorageModule::class, CachingTestModule::class,
ExpirationMetaDataRetrieverModule::class,
ViewBindingShimModule::class, RatioInputModule::class, WorkManagerConfigurationModule::class,
ApplicationStartupListenerModule::class, LogReportWorkerModule::class,
HintsAndSolutionConfigModule::class, HintsAndSolutionProdModule::class,
FirebaseLogUploaderModule::class, FakeOppiaClockModule::class,
DeveloperOptionsStarterModule::class, DeveloperOptionsModule::class,
ExplorationStorageModule::class, NetworkModule::class, NetworkConfigProdModule::class,
NetworkConnectionUtilDebugModule::class, NetworkConnectionDebugUtilModule::class,
AssetModule::class, LocaleProdModule::class, ActivityRecreatorTestModule::class,
NumericExpressionInputModule::class, AlgebraicExpressionInputModule::class,
MathEquationInputModule::class, SplitScreenInteractionModule::class,
LoggingIdentifierModule::class, ApplicationLifecycleModule::class,
SyncStatusModule::class, MetricLogSchedulerModule::class, TestingBuildFlavorModule::class,
EventLoggingConfigurationModule::class, ActivityRouterModule::class,
CpuPerformanceSnapshotterModule::class, ExplorationProgressModule::class,
TestAuthenticationModule::class
]
)
interface TestApplicationComponent : ApplicationComponent {
@Component.Builder
interface Builder : ApplicationComponent.Builder {
override fun build(): TestApplicationComponent
}

class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider {
private val component: TestApplicationComponent by lazy {
DaggerAddProfileActivityTest_TestApplicationComponent.builder()
.setApplication(this)
.build() as TestApplicationComponent
}
fun inject(addProfileActivityTest: AddProfileActivityTest)
}

fun inject(addProfileActivityTest: AddProfileActivityTest) {
component.inject(addProfileActivityTest)
}
class TestApplication : Application(), ActivityComponentFactory, ApplicationInjectorProvider {
private val component: TestApplicationComponent by lazy {
DaggerAddProfileActivityTest_TestApplicationComponent.builder()
.setApplication(this)
.build() as TestApplicationComponent
}

override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent {
return component.getActivityComponentBuilderProvider().get().setActivity(activity).build()
}
fun inject(addProfileActivityTest: AddProfileActivityTest) {
component.inject(addProfileActivityTest)
}

override fun getApplicationInjector(): ApplicationInjector = component
override fun createActivityComponent(activity: AppCompatActivity): ActivityComponent {
return component.getActivityComponentBuilderProvider().get().setActivity(activity).build()
}

override fun getApplicationInjector(): ApplicationInjector = component
}
}
Loading