2525import android .widget .Button ;
2626import android .widget .CheckBox ;
2727import android .widget .EditText ;
28+ import android .widget .TextView ;
29+ import com .dropbox .core .android .Auth ;
2830import org .astonbitecode .rustkeylock .R ;
2931import org .astonbitecode .rustkeylock .api .InterfaceWithRust ;
3032import org .astonbitecode .rustkeylock .handlers .back .BackButtonHandler ;
@@ -77,6 +79,24 @@ public void onClick(View view) {
7779 } else if (view .getId () == R .id .editConfigurationCancelButton ) {
7880 Log .d (TAG , "Clicked Cancel in configuration" );
7981 InterfaceWithRust .INSTANCE .go_to_menu (Defs .MENU_MAIN );
82+ } else if (view .getId () == R .id .editConfigurationGetTokenButton ) {
83+ String appKey = getString (R .string .dbx_app_key );
84+ Log .d (TAG , "Clicked Get Dropbox token in configuration. App key: " + appKey );
85+ Auth .startOAuth2Authentication (getActivity (), appKey );
86+ }
87+ }
88+
89+ @ Override
90+ public void onResume () {
91+ super .onResume ();
92+ String token = strings .get (5 );
93+
94+ if (token == null || token .isEmpty ()) {
95+ String retrieved_token_from_shared_preferences = Auth .getOAuth2Token ();
96+ if (retrieved_token_from_shared_preferences != null ) {
97+ token = retrieved_token_from_shared_preferences ;
98+ InterfaceWithRust .INSTANCE .go_to_menu_plus_arg (Defs .MENU_SET_DB_TOKEN , Defs .EMPTY_ARG , token );
99+ }
80100 }
81101 }
82102
@@ -85,6 +105,8 @@ private void prepareUiElements(View v) {
85105 ob .setOnClickListener (this );
86106 Button cb = (Button ) v .findViewById (R .id .editConfigurationCancelButton );
87107 cb .setOnClickListener (this );
108+ Button gt = (Button ) v .findViewById (R .id .editConfigurationGetTokenButton );
109+ gt .setOnClickListener (this );
88110
89111 EditText urlText = (EditText ) v .findViewById (R .id .editNextcloudUrl );
90112 urlText .setText (strings .get (0 ));
@@ -98,6 +120,12 @@ private void prepareUiElements(View v) {
98120 CheckBox useSsc = (CheckBox ) v .findViewById (R .id .editNextcloudUseSelfSignedCert );
99121 useSsc .setChecked (new Boolean (strings .get (3 )));
100122 this .useSelfSignedCert = useSsc ;
123+
124+ TextView dbxTokenLabel = (TextView ) v .findViewById (R .id .editConfigurationTokenLabel );
125+ dbxTokenLabel .setText ((strings .get (5 ) == null || strings .get (5 ).isEmpty ()) ?
126+ "Press the button below to acquire a new authentication token." :
127+ "A token is acquired. Press the button below to renew."
128+ );
101129 }
102130
103131 @ Override
0 commit comments