Skip to content

Commit ab043dd

Browse files
committed
Dropbox support
1 parent b69e064 commit ab043dd

File tree

10 files changed

+103
-44
lines changed

10 files changed

+103
-44
lines changed

java/AndroidManifest.xml

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,19 @@
2626
<category android:name="android.intent.category.LAUNCHER" />
2727
</intent-filter>
2828
</activity>
29+
<activity
30+
android:name="com.dropbox.core.android.AuthActivity"
31+
android:configChanges="orientation|keyboard"
32+
android:launchMode="singleTask">
33+
<intent-filter>
34+
<data android:scheme="db-7git6ovjwtdbfvm" />
35+
36+
<action android:name="android.intent.action.VIEW" />
37+
38+
<category android:name="android.intent.category.BROWSABLE" />
39+
<category android:name="android.intent.category.DEFAULT" />
40+
</intent-filter>
41+
</activity>
2942
</application>
3043

3144
</manifest>

java/pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
<android.plugin.version>4.1.1.4</android.plugin.version>
1717
<junit.version>3.8.1</junit.version>
1818
<maven.compiler.plugin.version>3.8.0</maven.compiler.plugin.version>
19+
<dropbox.version>3.0.11</dropbox.version>
1920
</properties>
2021

2122
<repositories>
@@ -43,6 +44,11 @@
4344
<artifactId>j4rs</artifactId>
4445
<version>0.6.0-java7</version>
4546
</dependency>
47+
<dependency>
48+
<groupId>com.dropbox.core</groupId>
49+
<artifactId>dropbox-core-sdk</artifactId>
50+
<version>${dropbox.version}</version>
51+
</dependency>
4652
<!-- Test dependencies -->
4753
<dependency>
4854
<groupId>junit</groupId>

java/res/layout/fragment_edit_configuration.xml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,41 @@
8484
android:layout_height="match_parent"
8585
android:text="Use self-signed certificate"/>
8686

87+
<TextView
88+
android:id="@+id/dropboxLabel"
89+
android:layout_width="wrap_content"
90+
android:layout_height="wrap_content"
91+
android:layout_marginTop="20sp"
92+
android:layout_gravity="left|center"
93+
android:text="Dropbox"
94+
android:textAppearance="?android:attr/textAppearanceMedium"/>
95+
<GridLayout
96+
android:layout_width="match_parent"
97+
android:layout_height="wrap_content"
98+
android:layout_gravity="center"
99+
android:layout_marginTop="20sp"
100+
android:columnCount="1"
101+
android:gravity="center|top"
102+
android:orientation="horizontal">
103+
104+
<TextView
105+
android:id="@+id/editConfigurationTokenLabel"
106+
android:layout_width="wrap_content"
107+
android:layout_height="wrap_content"
108+
android:layout_gravity="center"
109+
android:text=""
110+
android:textAppearance="?android:attr/textAppearanceSmall"/>
111+
112+
<Button
113+
android:id="@+id/editConfigurationGetTokenButton"
114+
android:layout_marginTop="18sp"
115+
android:layout_width="wrap_content"
116+
android:layout_height="wrap_content"
117+
android:layout_gravity="center"
118+
android:background="@android:color/transparent"
119+
android:drawableTop="@drawable/dropbox_circle_black_64"/>
120+
</GridLayout>
121+
87122
<GridLayout
88123
android:layout_width="match_parent"
89124
android:layout_height="wrap_content"
@@ -111,6 +146,8 @@
111146
android:drawableTop="@drawable/close"
112147
android:text="Cancel"/>
113148
</GridLayout>
149+
150+
114151
</LinearLayout>
115152
</ScrollView>
116153

java/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44
<string name="app_name">rust-keylock</string>
55
<string name="welcome">Welcome to rust-keylock</string>
66
<string name="action_settings">Settings</string>
7+
<string name="dbx_app_key">7git6ovjwtdbfvm</string>
78

89
</resources>

java/src/main/java/org/astonbitecode/rustkeylock/MainActivity.java

Lines changed: 1 addition & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public static MainActivity getActiveActivity() {
3232
private final String TAG = getClass().getName();
3333
private Thread rustThread = null;
3434
private BackButtonHandler backButtonHandler;
35-
private long savedStateAt = 0;
3635

3736
@Override
3837
protected void onCreate(Bundle savedInstanceState) {
@@ -42,26 +41,11 @@ protected void onCreate(Bundle savedInstanceState) {
4241
if (savedInstanceState == null) {
4342
initializeRust();
4443
} else {
45-
savedStateAt = savedInstanceState.getLong("saveStateAt");
46-
checkIdleTime();
4744
// Restore the back button handler
4845
backButtonHandler = (BackButtonHandler) savedInstanceState.get("backButtonHandler");
4946
}
5047
}
5148

52-
private void checkIdleTime() {
53-
if (savedStateAt > 0) {
54-
long now = System.currentTimeMillis();
55-
// If paused for more than 60 seconds, close the application for
56-
// security reasons
57-
if (now - savedStateAt > 60000) {
58-
Log.w(TAG, "Closing because of beeing idle for too long...");
59-
finish();
60-
System.exit(0);
61-
}
62-
}
63-
}
64-
6549
@Override
6650
protected void onSaveInstanceState(Bundle outState) {
6751
// Save the back button handler
@@ -75,36 +59,14 @@ protected void onSaveInstanceState(Bundle outState) {
7559
protected void onPause() {
7660
Log.i(TAG, "rust-keylock is being paused...");
7761
super.onPause();
78-
savedStateAt = System.currentTimeMillis();
7962
}
8063

8164
@Override
8265
protected void onResume() {
83-
Log.i(TAG, "resuming rust-keylock...");
8466
super.onResume();
85-
checkIdleTime();
86-
savedStateAt = 0;
67+
Log.i(TAG, "resuming rust-keylock...");
8768
}
8869

89-
// @Override
90-
// public boolean onCreateOptionsMenu(Menu menu) {
91-
// // Inflate the menu; this adds items to the action bar if it is present.
92-
// getMenuInflater().inflate(R.menu.main, menu);
93-
// return true;
94-
// }
95-
96-
// @Override
97-
// public boolean onOptionsItemSelected(MenuItem item) {
98-
// // Handle action bar item clicks here. The action bar will
99-
// // automatically handle clicks on the Home/Up button, so long
100-
// // as you specify a parent activity in AndroidManifest.xml.
101-
// int id = item.getItemId();
102-
// if (id == R.id.action_settings) {
103-
// return true;
104-
// }
105-
// return super.onOptionsItemSelected(item);
106-
// }
107-
10870
@Override
10971
public void onBackPressed() {
11072
if (backButtonHandler != null) {

java/src/main/java/org/astonbitecode/rustkeylock/fragments/EditConfiguration.java

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@
2525
import android.widget.Button;
2626
import android.widget.CheckBox;
2727
import android.widget.EditText;
28+
import android.widget.TextView;
29+
import com.dropbox.core.android.Auth;
2830
import org.astonbitecode.rustkeylock.R;
2931
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
3032
import 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

java/src/main/java/org/astonbitecode/rustkeylock/utils/Defs.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ public class Defs {
3030
public static final String MENU_EXPORT_ENTRIES = "ExportEntries";
3131
public static final String MENU_IMPORT_ENTRIES = "ImportEntries";
3232
public static final String MENU_SHOW_CONFIGURATION = "ShowConfiguration";
33+
public static final String MENU_SET_DB_TOKEN = "SetDbxToken";
3334
public static final String MENU_CURRENT = "Current";
3435
public static final String EMPTY_ARG = "null";
3536
}

rust/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@ name = "rustkeylockandroid"
99
crate-type = ["cdylib"]
1010

1111
[dependencies]
12-
rust_keylock = {git = "https://github.com/rust-keylock/rust-keylock-lib" }
13-
j4rs = "0.6"
12+
rust_keylock = {git = "https://github.com/rust-keylock/rust-keylock-lib"}
13+
j4rs = {git = "https://github.com/astonbitecode/j4rs.git"}
1414
libc = "0.2"
1515
jni-sys = "0.3"
1616
serde = "1.0"

rust/src/android_editor.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ use rust_keylock::{
2525
};
2626
use std::sync::mpsc::{self, Receiver};
2727
use super::japi;
28+
use rust_keylock::dropbox::DropboxConfiguration;
2829

2930
pub struct AndroidImpl {
3031
jvm: Jvm,
@@ -177,7 +178,10 @@ impl AsyncEditor for AndroidImpl {
177178
configuration.nextcloud.server_url.clone(),
178179
configuration.nextcloud.username.clone(),
179180
configuration.nextcloud.decrypted_password().unwrap(),
180-
configuration.nextcloud.use_self_signed_certificate.to_string()];
181+
configuration.nextcloud.use_self_signed_certificate.to_string(),
182+
DropboxConfiguration::dropbox_url(),
183+
configuration.dropbox.decrypted_token().unwrap(),
184+
];
181185
self.jvm.invoke_to_channel(
182186
&self.edit_configuration_cb,
183187
"apply",

rust/src/japi.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,10 @@ use std::thread;
33

44
use j4rs::{errors, Instance, InstanceReceiver};
55
use log::*;
6-
use rust_keylock::{Entry, Menu, UserOption, UserSelection};
6+
use rust_keylock::{Entry, Menu, UserOption, UserSelection, AllConfigurations};
77
use rust_keylock::nextcloud::NextcloudConfiguration;
88
use serde_derive::{Deserialize, Serialize};
9+
use rust_keylock::dropbox::DropboxConfiguration;
910

1011
pub fn handle_instance_receiver_result(instance_receiver_res: errors::Result<InstanceReceiver>) -> Receiver<UserSelection> {
1112
let (tx, rx) = mpsc::channel();
@@ -129,7 +130,13 @@ fn instance_to_gui_response(instance: Instance) -> UserSelection {
129130
false)
130131
};
131132

132-
UserSelection::UpdateConfiguration(ncc.unwrap())
133+
let dbxc = if strings.len() == 4 {
134+
DropboxConfiguration::new(strings[3].clone())
135+
} else {
136+
Ok(DropboxConfiguration::default())
137+
};
138+
139+
UserSelection::UpdateConfiguration(AllConfigurations::new(ncc.unwrap(), dbxc.unwrap()))
133140
}
134141
GuiResponse::UserOptionSelected { user_option } => {
135142
debug!("user_option_selected");

0 commit comments

Comments
 (0)