3434import com .box .androidsdk .content .BoxConfig ;
3535import com .box .androidsdk .content .auth .BoxAuthentication ;
3636import com .box .androidsdk .content .models .BoxSession ;
37- import com .cloudrail . si . CloudRail ;
37+ import com .dropbox . core . android . Auth ;
3838import com .google .android .material .bottomnavigation .BottomNavigationView ;
39- import com .google .android .material .snackbar .Snackbar ;
4039import com .pinterest .android .pdk .PDKCallback ;
4140import com .pinterest .android .pdk .PDKClient ;
4241import com .pinterest .android .pdk .PDKException ;
@@ -74,8 +73,6 @@ public class AccountActivity extends ThemedActivity
7473 private static final int OWNCLOUD_REQUEST_CODE = 9 ;
7574 private static final int RESULT_OK = 1 ;
7675 public static final String BROWSABLE = "android.intent.category.BROWSABLE" ;
77- public static final String CLOUDRAIL_APP_KEY =
78- Constants .CLOUDRAIL_LICENSE_KEY ; // CloudRail_App-Key
7976
8077 @ BindView (R .id .accounts_parent )
8178 RelativeLayout parentLayout ;
@@ -101,7 +98,6 @@ public class AccountActivity extends ThemedActivity
10198 private AccountDatabase account ;
10299 private DatabaseHelper databaseHelper ;
103100 private Context context ;
104- private CloudRailServices cloudRailServices ;
105101 private PDKClient pdkClient ;
106102 // private GoogleApiClient mGoogleApiClient;
107103 private BoxSession sessionBox ;
@@ -129,7 +125,6 @@ public void onCreate(Bundle savedInstanceState) {
129125 accountPresenter .loadFromDatabase (); // Calling presenter function to load data from database
130126 getSupportActionBar ().setTitle (R .string .title_account );
131127 phimpmeProgressBarHandler .show ();
132- cloudRailServices = CloudRailServices .getInstance ();
133128 pdkClient = PDKClient .configureInstance (this , PINTEREST_APP_ID );
134129 pdkClient .onConnect (this );
135130 setDebugMode (true );
@@ -249,13 +244,7 @@ public void onItemClick(final View childView, final int position) {
249244 break ;
250245
251246 case DROPBOX :
252- if (CLOUDRAIL_APP_KEY == null || CLOUDRAIL_APP_KEY .equals ("" )) {
253- SnackBarHandler .create (
254- findViewById (android .R .id .content ),
255- getString (R .string .Cloudrail_License_key ),
256- Snackbar .LENGTH_SHORT )
257- .show ();
258- } else signInDropbox ();
247+ Auth .startOAuth2Authentication (this , Constants .DROPBOX_APP_KEY );
259248 break ;
260249
261250 case OWNCLOUD :
@@ -367,74 +356,6 @@ public void onLoginFailed(RuntimeException e) {
367356 .initiateInActivity(AccountActivity.this);
368357 }*/
369358
370- private void signInDropbox () {
371- if (accountPresenter .checkAlreadyExist (DROPBOX )) {
372- SnackBarHandler .create (coordinatorLayout , getString (R .string .already_signed_in )).show ();
373- } else cloudRailServices .prepare (this );
374- cloudRailServices .login ();
375- BasicCallBack basicCallBack =
376- new BasicCallBack () {
377- @ Override
378- public void callBack (int status , Object data ) {
379- if (status == 1 ) {
380- dropboxAuthentication (data .toString ());
381- }
382- }
383- };
384- CloudRailServices .setCallBack (basicCallBack );
385- }
386- /*
387- Catching the intent of the external browser login and getting that data
388- */
389-
390- @ Override
391- protected void onNewIntent (Intent intent ) {
392- try {
393-
394- if (intent .getCategories ().contains (BROWSABLE )) {
395- CloudRail .setAuthenticationResponse (intent );
396- }
397- } catch (Exception e ) {
398- // Nothing is to be done when the BROWSABLE Intent is null
399- }
400- super .onNewIntent (intent );
401- }
402-
403- /* private void signInGoogleDrive() {
404- if(accountPresenter.checkAlreadyExist(GOOGLEDRIVE))
405- SnackBarHandler.show(coordinatorLayout,"Already Signed In");
406- else
407- cloudRailServices.prepare(this);
408- cloudRailServices.googleDriveLogin();
409- BasicCallBack basicCallBack = new BasicCallBack() {
410- @Override
411- public void callBack(int status, Object data) {
412- if(status == 2){
413- Log.e("TAG", "callBack: GOOGLE DRIVE"+data.toString() );
414- googleDriveAuthentication(data.toString());
415- }
416- }
417- };
418- CloudRailServices.setCallBack(basicCallBack);
419- }*/
420-
421- /* private void signInOneDrive(){
422- if(accountPresenter.checkAlreadyExist(ONEDRIVE))
423- SnackBarHandler.show(coordinatorLayout,"Already Signed In");
424- else
425- cloudRailServices.prepare(this);
426- cloudRailServices.oneDriveLogin();
427- BasicCallBack basicCallBack = new BasicCallBack() {
428- @Override
429- public void callBack(int status, Object data) {
430- if(status==3){
431- oneDriveAuthentication(data.toString());
432- }
433- }
434- };
435- CloudRailServices.setCallBack(basicCallBack);
436- }*/
437-
438359 private void signInImgur () {
439360 BasicCallBack basicCallBack =
440361 new BasicCallBack () {
@@ -566,6 +487,9 @@ public void onResume() {
566487 toolbar .setBackgroundColor (ThemeHelper .getPrimaryColor (this ));
567488 // dropboxAuthentication();
568489 boxAuthentication ();
490+ if (Auth .getOAuth2Token () != null ) {
491+ dropBoxAuthentication (Auth .getOAuth2Token ());
492+ }
569493 setStatusBarColor ();
570494 setNavBarColor ();
571495 accountPresenter .loadFromDatabase ();
@@ -601,59 +525,6 @@ private void boxAuthentication() {
601525 }
602526 }
603527
604- private void dropboxAuthentication (String tokens ) {
605- try {
606- String result = cloudRailServices .db .saveAsString ();
607- Log .d (
608- getString (R .string .AccountsActivity ),
609- getString (R .string .dropboxAuthentication ) + tokens + " " + result );
610- String accessToken = cloudRailServices .getToken ();
611- realm .beginTransaction ();
612- account = realm .createObject (AccountDatabase .class , DROPBOX .toString ());
613- account .setUsername (DROPBOX .toString ());
614- account .setToken (String .valueOf (accessToken ));
615- realm .commitTransaction ();
616-
617- } catch (Exception e ) {
618- // catches exception dont need handling
619- }
620- accountPresenter .loadFromDatabase ();
621- }
622-
623- /* private void oneDriveAuthentication(String tokens){
624- try {
625- String result = cloudRailServices.oneDrive.saveAsString();
626- Log.d("AccountsActivity", "oneDriveAuthentication: "+tokens+" "+result );
627- String accessToken = cloudRailServices.getOneDriveToken();
628- realm.beginTransaction();
629- account = realm.createObject(AccountDatabase.class,ONEDRIVE.toString());
630- account.setUsername(ONEDRIVE.toString());
631- account.setToken(String.valueOf(accessToken));
632- realm.commitTransaction();
633- }
634- catch (Exception e){
635- //No need of handling it
636- }
637- accountPresenter.loadFromDatabase();
638- }*/
639-
640- /* private void googleDriveAuthentication(String tokens) {
641- try{
642- String token = cloudRailServices.googleDrive.saveAsString();
643- Log.e("AccountsActivity", "googleDriveAuthentication: "+token + "Matching Token "+tokens);
644- String accessToken = cloudRailServices.getGoogleDriveToken();
645- realm.beginTransaction();
646- account = realm.createObject(AccountDatabase.class,GOOGLEDRIVE.toString());
647- account.setUsername(GOOGLEDRIVE.toString());
648- account.setToken(String.valueOf(accessToken));
649- realm.commitTransaction();
650- }catch (Exception e)
651- {
652- //No need for handling
653- }
654- accountPresenter.loadFromDatabase();
655- }*/
656-
657528 @ Override
658529 protected void onActivityResult (int requestCode , int resultCode , Intent data ) {
659530 super .onActivityResult (requestCode , resultCode , data );
@@ -692,4 +563,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
692563 SnackBarHandler.show(parentLayout,R.string.google_auth_fail);
693564 }
694565 }*/
566+
567+ // Handles the Auth Activity result of DropBox signIn flow
568+ private void dropBoxAuthentication (String token ) {
569+ realm .beginTransaction ();
570+ account = realm .createObject (AccountDatabase .class , DROPBOX .toString ());
571+ account .setUsername (DROPBOX .toString ());
572+ account .setToken (token );
573+ realm .commitTransaction ();
574+ }
695575}
0 commit comments