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

Fix #1587 : Made intent/bundle/saved/tags instance keys consistent #1717

Closed

Conversation

The-Pascal
Copy link

@The-Pascal The-Pascal commented Aug 26, 2020

Explanation

Fix #1587 : Made intent/bundle/saved/tags instance keys consistent
For fragments:
<PROPERTY_NAME>_ARGUMENT_KEY = ".<property_name>"
Example: INTERNAL_PROFILE_ID_ARGUMENT_KEY = "SampleFragment.internal_profile_id"

For activities:
<PROPERTY_NAME>_EXTRA_KEY = ".<property_name>"
Example: INTERNAL_PROFILE_ID_EXTRA_KEY = "SampleActivity.internal_profile_id"

For saved instances:
<PROPERTY_NAME>_SAVED_KEY = ".<property_name>"
Example: INTERNAL_PROFILE_ID_SAVED_KEY = "SampleActivity.internal_profile_id"

Checklist

  • The PR title starts with "Fix #bugnum: ", followed by a short, clear summary of the changes. (If this PR fixes part of an issue, prefix the title with "Fix part of #bugnum: ...".)
  • The PR explanation includes the words "Fixes #bugnum: ..." (or "Fixes part of #bugnum" if the PR only partially fixes an issue).
  • The PR follows the style guide.
  • The PR does not contain any unnecessary auto-generated code from Android Studio.
  • The PR is made from a branch that's not called "develop".
  • The PR is made from a branch that is up-to-date with "develop".
  • The PR's branch is based on "develop" and not on any other branch.
  • The PR is assigned to an appropriate reviewer in both the Assignees and the Reviewers sections.

@anandwana001
Copy link
Contributor

@The-Pascal You can have a look at this wiki page, this will help you out in passing the ktlint check.
You can also run the ktlint on your machine before commit, just to ensure this will not fail here at GitHub action checks.

@anandwana001
Copy link
Contributor

🎉 Congratulations on your first PR 🎉

Few general points:

  1. You will be able to access the Assignees and Reviewers section once your two PRs gets merged. By the time you can mention me or @rt4914 in your PR description so that we can review your PR.
  2. In future make sure that your branch name is of lower case characters separated by underscore like made_intent_keys_consistent
  3. Commit message should be something which helps in understanding what that particular commit does
  4. In the PR description, if you think any point is missing or undone you can leave it unmarked and mention the cause in the PR description which helps us to resolve. Also, currently, there is a space between x which a markdown failure. You can follow [x] ->
  • The PR is made from a branch that's not called "develop".

@anandwana001 anandwana001 self-requested a review August 27, 2020 12:14
@anandwana001 anandwana001 self-assigned this Aug 27, 2020
Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Few nit changes.

@rt4914 What about key's like

const val LAST_LOADED_FRAGMENT_KEY = "LAST_LOADED_FRAGMENT_KEY"
    internal const val KEY_APP_LANGUAGE_PREFERENCE_TITLE = "APP_LANGUAGE_PREFERENCE"
    internal const val KEY_APP_LANGUAGE_PREFERENCE_SUMMARY_VALUE =
      "APP_LANGUAGE_PREFERENCE_SUMMARY_VALUE"
    internal const val KEY_SELECTED_LANGUAGE = "SELECTED_LANGUAGE"
private const val KEY_APP_LANGUAGE_PREFERENCE_TITLE = "APP_LANGUAGE_PREFERENCE"
private const val KEY_APP_LANGUAGE_PREFERENCE_SUMMARY_VALUE =
  "APP_LANGUAGE_PREFERENCE_SUMMARY_VALUE"
private const val KEY_SELECTED_LANGUAGE = "SELECTED_LANGUAGE"

and others like the same

@@ -20,7 +20,8 @@ class TestFontScaleConfigurationUtilActivity : InjectableAppCompatActivity() {
}

companion object {
private const val FONT_SCALE_EXTRA_KEY = "FONT_SCALE_EXTRA_KEY"
private const val FONT_SCALE_EXTRA_KEY =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No single space needed after =

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

internal const val SUBTOPIC_ID_EXTRA_KEY = "SUBTOPIC_ID_EXTRA_KEY"
internal const val INTERNAL_PROFILE_ID_EXTRA_KEY =
"RevisionCardActivity.internal_profile_id"
internal const val TOPIC_ID_EXTRA_KEY =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, no single space needed after =

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"RevisionCardActivity.internal_profile_id"
internal const val TOPIC_ID_EXTRA_KEY =
"RevisionCardActivity.topic_id"
internal const val SUBTOPIC_ID_EXTRA_KEY =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here, no single space needed after =

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

private const val SOLUTION_INDEX_SAVED_KEY =
"HintsAndSolutionDialogFragment.solution_index"
private const val IS_SOLUTION_REVEALED_SAVED_KEY =
"HintsAndSolutionDialogFragment.is_solution_revealed"

/* Fragment that displays a fullscreen dialog for Hints and Solutions. */
class HintsAndSolutionDialogFragment :
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Below key is left untouched

  internal const val ID_ARGUMENT_KEY = "ID"
    internal const val NEW_AVAILABLE_HINT_INDEX_ARGUMENT_KEY = "NEW_AVAILABLE_HINT_INDEX"
    internal const val ALL_HINTS_EXHAUSTED_ARGUMENT_KEY = "ALL_HINTS_EXHAUSTED"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

const val STATE_FRAGMENT_PROFILE_ID_ARGUMENT_KEY = "StateFragmentPresenter.profile_id"
const val STATE_FRAGMENT_TOPIC_ID_ARGUMENT_KEY = "StateFragmentPresenter.topic_id"
const val STATE_FRAGMENT_STORY_ID_ARGUMENT_KEY = "StateFragmentPresenter.story_id"
const val STATE_FRAGMENT_EXPLORATION_ID_ARGUMENT_KEY = "StateFragmentPresenter.exploration_id"
private const val TAG_AUDIO_FRAGMENT = "AUDIO_FRAGMENT"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TAG should be changed too!!
as per the pr title says about Tags

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rt4914 please confirm here, as tags are not mentioned in the description.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tags related to fragment / activities should be mentioned in their respective companion objects.

Example: internal const val TAG = "AudioFragment.tag"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rt4914
Copy link
Contributor

rt4914 commented Aug 27, 2020

const val LAST_LOADED_FRAGMENT_KEY = "LAST_LOADED_FRAGMENT_KEY"

@anandwana001 @The-Pascal

Because the LAST_LOADED_FRAGMENT_KEY is actually getting saved/fetched in onSaveInstance, we should name them like this

LAST_LOADED_FRAGMENT_SAVED_KEY = "AdministratorControlsActivity.last_loaded_fragment"

This should be inside a companion object.

Copy link
Contributor

@rt4914 rt4914 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@The-Pascal
Please take a look at comments by @anandwana001 . Also, make sure that you check corresponding test cases files too because most of these keys are used in test cases too especially during intent.

Thanks.

@The-Pascal
Copy link
Author

@anandwana001 Thank you so much for your advice. I will always remember that and hope to go a long way contributing in open source community.

@rt4914 Thank you for providing me the opportunity.

I have made changes considering all the previous comments. Please review these changes.

@rt4914 rt4914 assigned rt4914 and anandwana001 and unassigned The-Pascal Aug 28, 2020
Copy link
Contributor

@rt4914 rt4914 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@The-Pascal I have left some comments but those comments apply to your entire PR.

You should follow these rules:

  1. TAG, EXTRA, ARGUMENT, SAVED_KEY all these types of keys should be mentioned in the activity/fragment's companion object.
  2. If you are mentioning them in companion object make sure that they are internal, like : internal const val TAG = "HomeFragment.tag"
  3. For tags you can directly write TAG instead of HOME_FRAGMENT_TAG.
  4. Make sure you follow other rules too which are mentioned in the issue itself.

Also, please make sure that you reply to comments also, like "DONE", "Mention what change you have done", etc.

Thanks.

@@ -12,7 +12,8 @@ import org.oppia.app.settings.profile.ProfileListActivity
import javax.inject.Inject

const val SELECTED_CONTROLS_TITLE_KEY = "SELECTED_CONTROLS_TITLE_KEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This need to be changed because this one is also getting used in savedInstanceState, check line 34 in code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -12,7 +12,8 @@ import org.oppia.app.settings.profile.ProfileListActivity
import javax.inject.Inject

const val SELECTED_CONTROLS_TITLE_KEY = "SELECTED_CONTROLS_TITLE_KEY"
const val LAST_LOADED_FRAGMENT_KEY = "LAST_LOADED_FRAGMENT_KEY"
const val LAST_LOADED_FRAGMENT_SAVED_KEY =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This string is correct but it should be mentioned in the companion object.

  companion object {
    internal const val LAST_LOADED_FRAGMENT_SAVED_KEY =
      "AdministratorControlsActivity.last_loaded_fragment"
    fun createAdministratorControlsActivityIntent(context: Context, profileId: Int?): Intent {
      val intent = Intent(context, AdministratorControlsActivity::class.java)
      intent.putExtra(KEY_NAVIGATION_PROFILE_ID, profileId)
      return intent
    }

    fun getIntentKey(): String {
      return KEY_NAVIGATION_PROFILE_ID
    }
  }

Once you have mentioned it in companion object you can use it anywhere like this:
AdministratorControlsActivity.LAST_LOADED_FRAGMENT_SAVED_KEY

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -28,7 +28,7 @@ class HelpActivity : InjectableAppCompatActivity(), RouteToFAQListListener {
companion object {
// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
const val BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY =
"BOOL_IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rename this to

const val IS_FROM_NAVIGATION_DRAWER_EXTRA_KEY = "HelpActivity.is_from_navigation_drawer"

else everything is correct.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

"HintsAndSolutionDialogFragment.is_hint_revealed"
private const val SOLUTION_INDEX_SAVED_KEY =
"HintsAndSolutionDialogFragment.solution_index"
private const val IS_SOLUTION_REVEALED_SAVED_KEY =
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shift all these private keys to companion object, similar to what I mentioned for AdministratorControlsActivity.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
But I have used private keys only inside companion object also, so please check if I need to make those keys internal or not.

@@ -9,7 +9,7 @@ import org.oppia.app.activity.ActivityScope
import org.oppia.app.drawer.NavigationDrawerFragment
import javax.inject.Inject

const val TAG_HOME_FRAGMENT = "HOME_FRAGMENT"
const val TAG_HOME_FRAGMENT = "HomeFragment.tag"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shift to companion object on HomeFragment.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also please check this comment:
#1717 (comment)

As per this comment it should be named like this:
internal const val TAG = "HomeFragment.tag"

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done
But am not sure the way I did it. So please check it and guide me if am wrong in this.

@@ -15,7 +15,7 @@ private const val RECENTLY_PLAYED_FRAGMENT_INTERNAL_PROFILE_ID_KEY =
/** Fragment that contains all recently played stories. */
class RecentlyPlayedFragment : InjectableFragment(), OngoingStoryClickListener {
companion object {
const val TAG_RECENTLY_PLAYED_FRAGMENT = "TAG_RECENTLY_PLAYED_FRAGMENT"
const val TAG_RECENTLY_PLAYED_FRAGMENT = "RecentlyPlayedFragment.tag"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at this comment:
#1717 (comment)

As per this comment, you should rename like this:
internal const val TAG = "RecentlyPlayedFragment.tag

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -13,7 +13,7 @@ class OngoingTopicListFragment : InjectableFragment() {

companion object {
// TODO(#1655): Re-restrict access to fields in tests post-Gradle.
const val ONGOING_TOPIC_LIST_FRAGMENT_TAG = "TAG_ONGOING_TOPIC_LIST_FRAGMENT"
const val ONGOING_TOPIC_LIST_FRAGMENT_TAG = "OngoingTopicListFragment.tag"
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please take a look at this comment:
#1717 (comment)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@rt4914 rt4914 assigned The-Pascal and unassigned rt4914 and anandwana001 Aug 28, 2020
@anandwana001
Copy link
Contributor

@The-Pascal Any update on this?

@The-Pascal
Copy link
Author

I have committed changes according to the suggestions. Please have a look.

@rt4914 and @anandwana001 I really appreciate your time and support for guiding me.

@anandwana001
Copy link
Contributor

I have committed changes according to the suggestions. Please have a look.

@rt4914 and @anandwana001 I really appreciate your time and support for guiding me.

You can comment on requested changes comment which helps me to understand things are solved and then I can resolve those comments.
You can say something like solved or done in comments.

@The-Pascal
Copy link
Author

You can comment on requested changes comment which helps me to understand things are solved and then I can resolve those comments.
You can say something like solved or done in comments.

Thanks @anandwana001 I have done the same.

Copy link
Contributor

@anandwana001 anandwana001 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good so far @The-Pascal
I found a couple of arguments like

private const val IS_MULTIPANE_KEY = "IS_MULTIPANE_KEY" in AdministratorControlsFragment,

const val KEY_NAVIGATION_PROFILE_ID = "KEY_NAVIGATION_PROFILE_ID" in NavigationDrawerFragmentPresenter,

intent.putExtra(KEY_NAVIGATION_PROFILE_ID, profileId) in HelpActivity (this can be same as
intent.putExtra(COMPLETED_STORY_LIST_ACTIVITY_PROFILE_ID_KEY, internalProfileId)) and for all others internalProfileId,

intent.putExtra(KEY_NAVIGATION_PROFILE_ID, profileId) in HomeActivity, MyDownloadsActivity, OptionsActivity, TopicActivity and other places too.

To keep the track and make this work easier, I suggest creating a list of packages in the PR descriptions and make changes.
Let me know for any other assistance.

@anandwana001
Copy link
Contributor

@The-Pascal You need to update the branch with develop before working more on this PR as we had updated the package names.

@The-Pascal The-Pascal closed this Oct 3, 2020
@The-Pascal The-Pascal removed their assignment Oct 3, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make intent/bundle/saved/tags instance keys consistent.
3 participants