Fenix: Use R.id for request codes

Created on 7 Oct 2019  ·  11Comments  ·  Source: mozilla-mobile/fenix

We hardcode many request codes (for PendingIntent, onRequestPermissionsResult, etc), but we can take advantage of resources to generate unique codes for us. ID resources can be used whereever we need a unique integer.

  1. Create a res/values/ids.xml file.
  2. Create xml tags (<item name="{request-code-name}" type="id"/>) for each request code.
  3. Add comments above the xml tags describing their purpose (similar to the strings.xml files).
  4. Use these ids where we currently hardcode integers. (i.e.: Replace REQUEST_CODE_PROMPT_PERMISSIONS with R.id.permissions_prompt_request_code)
Hacktoberfest health good first issue

Most helpful comment

Here's a tip:

  1. Fork this repository (from mozilla-mobile/fenix to <your GitHub username>/fenix
  2. Set up Git Remote to the <your GitHub username/fenix repository (e.g. git remote add origin https://github.com/<your username>/fenix.git)
    EDIT: using git clone https://github.com/<your username>/fenix.git is already enough
  3. Create a new Commit for that repository (git add * then git commit -m "Commit message here")
  4. Upload to GitHub (e.g. git push origin master)
  5. Create a new Pull Request from your repository to mozilla-mobile/fenix (mozilla-mobile/fenix ⬅️ <your GitHub username>/fenix)

There's always a bunch of online how-tos and demos on Git and GitHub during Hacktoberfest, such as:

Note that many of those tutorials refer to Git CLI (command-line) instead of GUI (graphical) equivalents such as Git GUI and GitHub Desktop. The Git CLI is accessible from the Command Prompt / Terminal once after installing Git from the official website

All 11 comments

I would like to try this if its still available

In progress

Hey,
There are more hard-coded values along with the request codes like custom_tab_session_id, shared_transition_ms etc. I don't have to include them?

No, only include the values where a static random integer makes sense. shared_transition_ms should always be the same number of milliseconds, and custom_tab_session_id needs to a random UUID string for different tabs.

ok

Hello,
I have done this but i can't push the branch I created as I don't have access. How do I push my changes and create a PR? :'D Sorry, a noob here

Here's a tip:

  1. Fork this repository (from mozilla-mobile/fenix to <your GitHub username>/fenix
  2. Set up Git Remote to the <your GitHub username/fenix repository (e.g. git remote add origin https://github.com/<your username>/fenix.git)
    EDIT: using git clone https://github.com/<your username>/fenix.git is already enough
  3. Create a new Commit for that repository (git add * then git commit -m "Commit message here")
  4. Upload to GitHub (e.g. git push origin master)
  5. Create a new Pull Request from your repository to mozilla-mobile/fenix (mozilla-mobile/fenix ⬅️ <your GitHub username>/fenix)

There's always a bunch of online how-tos and demos on Git and GitHub during Hacktoberfest, such as:

Note that many of those tutorials refer to Git CLI (command-line) instead of GUI (graphical) equivalents such as Git GUI and GitHub Desktop. The Git CLI is accessible from the Command Prompt / Terminal once after installing Git from the official website

git push origin master is giving me Permission to mozilla-mobile/fenix.git denied to Apoorv-Gaurav-Agarwal.

I have created PR but they got created separately for the edited files ;-;

Ok. I did it in a single pull request. I have closed the prior ones.

Thanks for the help

Thanks so much for the detailed PR guide @reinhart1010!

Unfortunately we have to close this issue, this change is causing crashes when the generated ID has more than 16 bits. (mozilla-mobile/android-components#4854)

Was this page helpful?
0 / 5 - 0 ratings