Skip to content

Commit

Permalink
Fix #1587: Made intent/bundle/saved/tags instance keys consistent. (#…
Browse files Browse the repository at this point in the history
…3880)

* renaming keys

* linting fix

* fixed more files

* linting fix

* fixing errors

* requested changes

* commit

* linting fix

* reverted a change
  • Loading branch information
ayush0402 committed Oct 7, 2021
1 parent daf4716 commit 8eabe16
Show file tree
Hide file tree
Showing 15 changed files with 42 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@ class CompletedStoryListActivity : InjectableAppCompatActivity() {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
val internalProfileId: Int =
intent.getIntExtra(COMPLETED_STORY_LIST_ACTIVITY_PROFILE_ID_KEY, -1)
intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
completedStoryListActivityPresenter.handleOnCreate(internalProfileId)
}

companion object {
// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
const val COMPLETED_STORY_LIST_ACTIVITY_PROFILE_ID_KEY =
const val PROFILE_ID_EXTRA_KEY =
"CompletedStoryListActivity.profile_id"

/** Returns a new [Intent] to route to [CompletedStoryListActivity] for a specified profile ID. */
fun createCompletedStoryListActivityIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, CompletedStoryListActivity::class.java)
intent.putExtra(COMPLETED_STORY_LIST_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MarkChaptersCompletedActivity : InjectableAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
internalProfileId = intent.getIntExtra(MARK_CHAPTERS_COMPLETED_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
markChaptersCompletedActivityPresenter.handleOnCreate(internalProfileId)
title = resourceHandler.getStringInLocale(R.string.mark_chapters_completed_activity_title)
}
Expand All @@ -37,12 +37,11 @@ class MarkChaptersCompletedActivity : InjectableAppCompatActivity() {
}

companion object {
const val MARK_CHAPTERS_COMPLETED_ACTIVITY_PROFILE_ID_KEY =
"MarkChaptersCompletedActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "MarkChaptersCompletedActivity.profile_id"

fun createMarkChaptersCompletedIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, MarkChaptersCompletedActivity::class.java)
intent.putExtra(MARK_CHAPTERS_COMPLETED_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ class MarkChaptersCompletedFragment : InjectableFragment() {
lateinit var markChaptersCompletedFragmentPresenter: MarkChaptersCompletedFragmentPresenter

companion object {
internal const val MARK_CHAPTERS_COMPLETED_FRAGMENT_PROFILE_ID_KEY =
"MarkChaptersCompletedFragment.internal_profile_id"
internal const val PROFILE_ID_ARGUMENT_KEY =
"MarkChaptersCompletedFragment.profile_id"

private const val EXPLORATION_ID_LIST_ARGUMENT_KEY =
"MarkChaptersCompletedFragment.exploration_id_list"
Expand All @@ -25,7 +25,7 @@ class MarkChaptersCompletedFragment : InjectableFragment() {
fun newInstance(internalProfileId: Int): MarkChaptersCompletedFragment {
val markChaptersCompletedFragment = MarkChaptersCompletedFragment()
val args = Bundle()
args.putInt(MARK_CHAPTERS_COMPLETED_FRAGMENT_PROFILE_ID_KEY, internalProfileId)
args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId)
markChaptersCompletedFragment.arguments = args
return markChaptersCompletedFragment
}
Expand All @@ -44,7 +44,7 @@ class MarkChaptersCompletedFragment : InjectableFragment() {
val args =
checkNotNull(arguments) { "Expected arguments to be passed to MarkChaptersCompletedFragment" }
val internalProfileId = args
.getInt(MARK_CHAPTERS_COMPLETED_FRAGMENT_PROFILE_ID_KEY, -1)
.getInt(PROFILE_ID_ARGUMENT_KEY, -1)
var selectedExplorationIdList = ArrayList<String>()
if (savedInstanceState != null) {
selectedExplorationIdList =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MarkChaptersCompletedTestActivity : InjectableAppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp)
setContentView(R.layout.mark_chapters_completed_activity)
internalProfileId = intent.getIntExtra(MARK_CHAPTERS_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
if (getMarkChaptersCompletedFragment() == null) {
val markChaptersCompletedFragment = MarkChaptersCompletedFragment
.newInstance(internalProfileId)
Expand All @@ -36,13 +36,12 @@ class MarkChaptersCompletedTestActivity : InjectableAppCompatActivity() {
}

companion object {
const val MARK_CHAPTERS_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY =
"MarkChaptersCompletedTestActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "MarkChaptersCompletedTestActivity.profile_id"

/** Returns an [Intent] for [MarkChaptersCompletedTestActivity]. */
fun createMarkChaptersCompletedTestIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, MarkChaptersCompletedTestActivity::class.java)
intent.putExtra(MARK_CHAPTERS_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MarkStoriesCompletedActivity : InjectableAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
internalProfileId = intent.getIntExtra(MARK_STORIES_COMPLETED_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
markStoriesCompletedActivityPresenter.handleOnCreate(internalProfileId)
title = resourceHandler.getStringInLocale(R.string.mark_stories_completed_activity_title)
}
Expand All @@ -37,12 +37,11 @@ class MarkStoriesCompletedActivity : InjectableAppCompatActivity() {
}

companion object {
const val MARK_STORIES_COMPLETED_ACTIVITY_PROFILE_ID_KEY =
"MarkStoriesCompletedActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "MarkStoriesCompletedActivity.profile_id"

fun createMarkStoriesCompletedIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, MarkStoriesCompletedActivity::class.java)
intent.putExtra(MARK_STORIES_COMPLETED_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ class MarkStoriesCompletedFragment : InjectableFragment() {
lateinit var markStoriesCompletedFragmentPresenter: MarkStoriesCompletedFragmentPresenter

companion object {
internal const val MARK_STORIES_COMPLETED_FRAGMENT_PROFILE_ID_KEY =
"MarkStoriesCompletedFragment.internal_profile_id"
internal const val PROFILE_ID_ARGUMENT_KEY = "MarkStoriesCompletedFragment.profile_id"

private const val STORY_ID_LIST_ARGUMENT_KEY = "MarkStoriesCompletedFragment.story_id_list"

/** Returns a new [MarkStoriesCompletedFragment]. */
fun newInstance(internalProfileId: Int): MarkStoriesCompletedFragment {
val markStoriesCompletedFragment = MarkStoriesCompletedFragment()
val args = Bundle()
args.putInt(MARK_STORIES_COMPLETED_FRAGMENT_PROFILE_ID_KEY, internalProfileId)
args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId)
markStoriesCompletedFragment.arguments = args
return markStoriesCompletedFragment
}
Expand All @@ -43,7 +42,7 @@ class MarkStoriesCompletedFragment : InjectableFragment() {
val args =
checkNotNull(arguments) { "Expected arguments to be passed to MarkStoriesCompletedFragment" }
val internalProfileId = args
.getInt(MARK_STORIES_COMPLETED_FRAGMENT_PROFILE_ID_KEY, -1)
.getInt(PROFILE_ID_ARGUMENT_KEY, -1)
var selectedStoryIdList = ArrayList<String>()
if (savedInstanceState != null) {
selectedStoryIdList = savedInstanceState.getStringArrayList(STORY_ID_LIST_ARGUMENT_KEY)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MarkStoriesCompletedTestActivity : InjectableAppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp)
setContentView(R.layout.mark_stories_completed_activity)
internalProfileId = intent.getIntExtra(MARK_STORIES_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
if (getMarkStoriesCompletedFragment() == null) {
val markStoriesCompletedFragment = MarkStoriesCompletedFragment.newInstance(internalProfileId)
supportFragmentManager.beginTransaction().add(
Expand All @@ -35,13 +35,12 @@ class MarkStoriesCompletedTestActivity : InjectableAppCompatActivity() {
}

companion object {
const val MARK_STORIES_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY =
"MarkStoriesCompletedTestActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "MarkStoriesCompletedTestActivity.profile_id"

/** Returns an [Intent] for [MarkStoriesCompletedTestActivity]. */
fun createMarkStoriesCompletedTestIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, MarkStoriesCompletedTestActivity::class.java)
intent.putExtra(MARK_STORIES_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class MarkTopicsCompletedActivity : InjectableAppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
internalProfileId = intent.getIntExtra(MARK_TOPICS_COMPLETED_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
markTopicsCompletedActivityPresenter.handleOnCreate(internalProfileId)
title = resourceHandler.getStringInLocale(R.string.mark_topics_completed_activity_title)
}
Expand All @@ -37,12 +37,11 @@ class MarkTopicsCompletedActivity : InjectableAppCompatActivity() {
}

companion object {
const val MARK_TOPICS_COMPLETED_ACTIVITY_PROFILE_ID_KEY =
"MarkTopicsCompletedActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "MarkTopicsCompletedActivity.profile_id"

fun createMarkTopicsCompletedIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, MarkTopicsCompletedActivity::class.java)
intent.putExtra(MARK_TOPICS_COMPLETED_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,15 @@ class MarkTopicsCompletedFragment : InjectableFragment() {
lateinit var markTopicsCompletedFragmentPresenter: MarkTopicsCompletedFragmentPresenter

companion object {
internal const val MARK_TOPICS_COMPLETED_FRAGMENT_PROFILE_ID_KEY =
"MarkTopicsCompletedFragment.internal_profile_id"
internal const val PROFILE_ID_ARGUMENT_KEY = "MarkTopicsCompletedFragment.profile_id"

private const val TOPIC_ID_LIST_ARGUMENT_KEY = "MarkTopicsCompletedFragment.topic_id_list"

/** Returns a new [MarkTopicsCompletedFragment]. */
fun newInstance(internalProfileId: Int): MarkTopicsCompletedFragment {
val markTopicsCompletedFragment = MarkTopicsCompletedFragment()
val args = Bundle()
args.putInt(MARK_TOPICS_COMPLETED_FRAGMENT_PROFILE_ID_KEY, internalProfileId)
args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId)
markTopicsCompletedFragment.arguments = args
return markTopicsCompletedFragment
}
Expand All @@ -43,7 +42,7 @@ class MarkTopicsCompletedFragment : InjectableFragment() {
val args =
checkNotNull(arguments) { "Expected arguments to be passed to MarkTopicsCompletedFragment" }
val internalProfileId = args
.getInt(MARK_TOPICS_COMPLETED_FRAGMENT_PROFILE_ID_KEY, -1)
.getInt(PROFILE_ID_ARGUMENT_KEY, -1)
var selectedTopicIdList = ArrayList<String>()
if (savedInstanceState != null) {
selectedTopicIdList = savedInstanceState.getStringArrayList(TOPIC_ID_LIST_ARGUMENT_KEY)!!
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class MarkTopicsCompletedTestActivity : InjectableAppCompatActivity() {
supportActionBar?.setDisplayHomeAsUpEnabled(true)
supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_arrow_back_white_24dp)
setContentView(R.layout.mark_topics_completed_activity)
internalProfileId = intent.getIntExtra(MARK_TOPICS_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
if (getMarkTopicsCompletedFragment() == null) {
val markTopicsCompletedFragment = MarkTopicsCompletedFragment.newInstance(internalProfileId)
supportFragmentManager.beginTransaction().add(
Expand All @@ -35,13 +35,12 @@ class MarkTopicsCompletedTestActivity : InjectableAppCompatActivity() {
}

companion object {
const val MARK_TOPICS_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY =
"MarkTopicsCompletedTestActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "MarkTopicsCompletedTestActivity.profile_id"

/** Returns an [Intent] for [MarkTopicsCompletedTestActivity]. */
fun createMarkTopicsCompletedTestIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, MarkTopicsCompletedTestActivity::class.java)
intent.putExtra(MARK_TOPICS_COMPLETED_TEST_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class DeveloperOptionsTestActivity :
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
setContentView(R.layout.developer_options_activity)
internalProfileId = intent.getIntExtra(DEVELOPER_OPTIONS_TEST_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
if (getDeveloperOptionsFragment() == null) {
supportFragmentManager.beginTransaction().add(
R.id.developer_options_fragment_placeholder,
Expand Down Expand Up @@ -78,13 +78,12 @@ class DeveloperOptionsTestActivity :
}

companion object {
const val DEVELOPER_OPTIONS_TEST_ACTIVITY_PROFILE_ID_KEY =
"DeveloperOptionsTestActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "DeveloperOptionsTestActivity.profile_id"

/** Returns [Intent] for [DeveloperOptionsTestActivity]. */
fun createDeveloperOptionsTestIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, DeveloperOptionsActivity::class.java)
intent.putExtra(DEVELOPER_OPTIONS_TEST_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class ProfileProgressActivity :
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
(activityComponent as ActivityComponentImpl).inject(this)
internalProfileId = intent.getIntExtra(PROFILE_PROGRESS_ACTIVITY_PROFILE_ID_KEY, -1)
internalProfileId = intent.getIntExtra(PROFILE_ID_EXTRA_KEY, -1)
profileProgressActivityPresenter.handleOnCreate(internalProfileId)
}

Expand Down Expand Up @@ -59,12 +59,11 @@ class ProfileProgressActivity :

companion object {
// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
const val PROFILE_PROGRESS_ACTIVITY_PROFILE_ID_KEY =
"ProfileProgressActivity.internal_profile_id"
const val PROFILE_ID_EXTRA_KEY = "ProfileProgressActivity.profile_id"

fun createProfileProgressActivityIntent(context: Context, internalProfileId: Int): Intent {
val intent = Intent(context, ProfileProgressActivity::class.java)
intent.putExtra(PROFILE_PROGRESS_ACTIVITY_PROFILE_ID_KEY, internalProfileId)
intent.putExtra(PROFILE_ID_EXTRA_KEY, internalProfileId)
return intent
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,13 @@ class ProfileProgressFragment :
InjectableFragment(),
ProfilePictureClickListener {
companion object {
internal const val PROFILE_PROGRESS_FRAGMENT_PROFILE_ID_KEY =
"ProfileProgressFragment.internal_profile_id"
internal const val PROFILE_ID_ARGUMENT_KEY = "ProfileProgressFragment.profile_id"

/** Returns a new [ProfileProgressFragment] to display the progress for a specified profile ID. */
fun newInstance(internalProfileId: Int): ProfileProgressFragment {
val profileProgressFragment = ProfileProgressFragment()
val args = Bundle()
args.putInt(PROFILE_PROGRESS_FRAGMENT_PROFILE_ID_KEY, internalProfileId)
args.putInt(PROFILE_ID_ARGUMENT_KEY, internalProfileId)
profileProgressFragment.arguments = args
return profileProgressFragment
}
Expand All @@ -42,7 +41,7 @@ class ProfileProgressFragment :
): View? {
val args =
checkNotNull(arguments) { "Expected arguments to be passed to ProfileProgressFragment" }
val internalProfileId = args.getInt(PROFILE_PROGRESS_FRAGMENT_PROFILE_ID_KEY, -1)
val internalProfileId = args.getInt(PROFILE_ID_ARGUMENT_KEY, -1)
return profileProgressFragmentPresenter.handleCreateView(inflater, container, internalProfileId)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -658,7 +658,7 @@ class ProfileProgressFragmentTest {
intended(hasComponent(CompletedStoryListActivity::class.java.name))
intended(
hasExtra(
CompletedStoryListActivity.COMPLETED_STORY_LIST_ACTIVITY_PROFILE_ID_KEY,
CompletedStoryListActivity.PROFILE_ID_EXTRA_KEY,
internalProfileId
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ class NavigationDrawerActivityProdTest {
intended(hasComponent(ProfileProgressActivity::class.java.name))
intended(
hasExtra(
ProfileProgressActivity.PROFILE_PROGRESS_ACTIVITY_PROFILE_ID_KEY,
ProfileProgressActivity.PROFILE_ID_EXTRA_KEY,
internalProfileId
)
)
Expand Down

0 comments on commit 8eabe16

Please sign in to comment.