Skip to content

Conversation

@addiegupta
Copy link
Contributor

@addiegupta addiegupta commented Apr 8, 2019

Fixes: #1535

Changes:
Smart Lock features added for Play Store Build Variant

  • At Login, an account is chosen. After entering password, Google Smart Lock prompts user to save password for future use
  • On next login, account and password data is entered automatically
  • In the previous implementation of this feature, viewmodel classes had some Android classes being used which is restricted
    Now all classes related to android imports are being handled in LoginFragment and MainActivity, keeping ViewModel android import free
  • A SmartAuthUtil class has been made to keep LoginFragment and MainActivity free of Google Play Services imports so that FDroid can be supported
  • SmartAuthUtil and SmartAuthViewModel classes for FDroid have also been made which don't do anything
  • Build Flavor is being checked before using smart lock features

The need for creating SmartAuthUtil arises as the other alternative is to create 2 files each of LoginFragment and MainActivity for both buildFlavors which might be undesirable

Screenshots for the change:

First Login
smartlocklogin

Second Login:
smartloginsave
As I have disabled the AutoLogin in my Google Account settings, therefore I need to select 2 more things in the second GIF(first account and then password). This setting is enabled by default for all accounts and for those accounts, email and password will be added automatically.

Additional context:

Implementing these Google APIs has to be done in this scattered manner as it has been designed to used callbacks like onActivityResult which are not very suitable for the architecture of this project. I have tried quite a few things but the best solution I could arrive at was this. Please guide me in improving this if you have any suggestions.

@auto-label auto-label bot added the feature label Apr 8, 2019
@addiegupta addiegupta force-pushed the 1535-googlesignin branch 3 times, most recently from 3ffb471 to 86900cb Compare April 14, 2019 14:21
@addiegupta
Copy link
Contributor Author

@iamareebjamal please review

@fossasia fossasia deleted a comment Apr 14, 2019
@fossasia fossasia deleted a comment Apr 14, 2019
@fossasia fossasia deleted a comment Apr 14, 2019
@iamareebjamal
Copy link
Member

Peer reviews first please

@addiegupta
Copy link
Contributor Author

@liveHarshit @angmas1 please review

@addiegupta
Copy link
Contributor Author

Peer reviews first please

As you had asked me to work on this, I thought it best to directly ask you for a review as you would have the best insight on this

@iamareebjamal
Copy link
Member

Peer Reviews teach the reviewing peers on how to review. If they approve and I request some changes, then it means they missed something


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

if (BuildConfig.FLAVOR == "playStore" && requestCode == RC_CREDENTIALS_READ) {
Copy link
Member

Choose a reason for hiding this comment

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

Declare string as constant.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@liveHarshit updated

smartAuthViewModel.resolvableApiException.nonNull().observe(viewLifecycleOwner, Observer {
if (smartAuthViewModel.requestCode.value != null) {
SmartAuthUtil.handleResolvableApiException(
it, requireActivity(), smartAuthViewModel.requestCode.value!!)
Copy link
Member

Choose a reason for hiding this comment

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

Do not use non-null assertions

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In latest commit: As resolvableApiException and requestCode are always updated together, I have put them together in a Pair in the ViewModel and the null case is thus avoided.

@liveHarshit
Copy link
Member

Build is failing

@angmas1
Copy link
Contributor

angmas1 commented Apr 15, 2019

Run gradlew spotlessApply


override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {

if (BuildConfig.FLAVOR == getString(R.string.playStore) && requestCode == RC_CREDENTIALS_READ) {
Copy link
Member

Choose a reason for hiding this comment

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

Define as const in the class itself, not in the resources file.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@fossasia fossasia deleted a comment Apr 15, 2019
@fossasia fossasia deleted a comment Apr 15, 2019
@addiegupta
Copy link
Contributor Author

@liveHarshit any other changes that I should make? Or should I proceed with squashing commits?

import org.koin.androidx.viewmodel.ext.android.sharedViewModel
import org.koin.androidx.viewmodel.ext.android.viewModel

const val PLAY_STORE_BUILD_FLAVOR = "playStore"
Copy link
Member

Choose a reason for hiding this comment

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

Declare it once. It is public value, you can use it in different class also.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated. will squash once you approve

@fossasia fossasia deleted a comment Apr 17, 2019
@fossasia fossasia deleted a comment Apr 17, 2019
liveHarshit
liveHarshit previously approved these changes Apr 17, 2019
Fixes: fossasia#1535

Changes:
- Smart Lock features added for Play Store Build Variant
	- At Login, an account is chosen. After entering password, Google Smart Lock prompts user to save password for future use
	- On next login, account and password data is entered automatically
	- In the previous implementation of this feature, viewmodel classes had some restricted classes being used
	  Now all classes related to android imports are being handled in LoginFragment and MainActivity, keeping ViewModel android import free
	- A SmartAuthUtil class has been made to keep LoginFragment and MainActivity free of Google Play Services imports so that FDroid can be supported
	- SmartAuthUtil and SmartAuthViewModel classes for FDroid have also been made which don't do anything
	- Build Flavor is being checked before using smart lock features
@addiegupta
Copy link
Contributor Author

Travis build was failing. removed unnecessary blank line

@iamareebjamal iamareebjamal merged commit 58a0164 into fossasia:development Apr 17, 2019
@addiegupta addiegupta deleted the 1535-googlesignin branch April 17, 2019 13:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Reimplement Google Sign in features in playstore version

4 participants