Skip to content
This repository has been archived by the owner on Dec 12, 2020. It is now read-only.

Dropbox v2 - Beta #509

Open
wants to merge 25 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
7c30127
Adding Dockerfile for standardized build process
beavel Jul 1, 2018
282ecb0
Add back jars and config modifications to allow successful compile in…
beavel Jul 1, 2018
7f0eb98
Check for errors on release & don't fail;
beavel Jul 1, 2018
bdacbb4
Upgrading gradle to 4.4
beavel Jul 1, 2018
f0e7970
Updated Android Gradle plugin to 3.1.3
beavel Jul 1, 2018
46e5b57
Added exclusions for VS Code
beavel Jun 17, 2018
5c2c3de
Moved DropboxAPI.Entry to FileMetadata; only .rev property used from …
beavel Jun 17, 2018
a2bd965
Added .gitignore entry for dropbox.xml configuration
beavel Jun 17, 2018
47a1748
Updated auth activity for v2 SDK
beavel Jun 17, 2018
d22c9a8
Updated the auth flow for v2
beavel Jun 17, 2018
2ef362f
Added DropboxClientFactory from sample and wired up init
beavel Jun 18, 2018
42c6f50
Updated DropboxRemoteClient.getSubFolders() to use v2 FolderMetadata
beavel Jun 18, 2018
a9abb3f
Updated DropboxFileDownloader for v2
beavel Jun 18, 2018
bb47dbf
Updated uploader to v2
beavel Jun 18, 2018
1bbecc4
Fixed up build issues from missed variable renames
beavel Jun 18, 2018
f19faf5
Suppress error message
beavel Jun 18, 2018
de63407
Updated versions to make multiDex support easier;
beavel Jul 1, 2018
81110ee
Updated DropboxRemoteClient to fix app load & auth issue
beavel Jul 6, 2018
427813a
Added informational logging around login/client initialization
beavel Jul 6, 2018
02075ec
Fixed uploade method with sample for small files
beavel Jul 6, 2018
0bed830
Fixed root path BadRequest
beavel Jul 6, 2018
e92f4a6
Fixed error on initial load; client wasn't getting set
beavel Jul 6, 2018
b1fa3c9
Fixed string comparison to be on value instead of object
beavel Jul 6, 2018
434b703
Added new method that initialized and returned client in one step
beavel Jul 6, 2018
6695c6d
Added appKey handling so full key could be used in dropbox resource f…
beavel Jul 6, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
.git
.idea
.gradle
.settings

local.properties

**build/**

**/*.zip
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,11 @@ fastlane/Preview.html
fastlane/screenshots
fastlane/test_output
fastlane/readme.md

# VS Code
**/.project
**/.settings/
**/.classpath

# Exclude local configurations
**/dropbox.xml
2 changes: 1 addition & 1 deletion ActionBar-PullToRefresh/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ android {
buildTypes {
release {
minifyEnabled false
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}

Expand Down
31 changes: 31 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# docker build -t android-build .

FROM openjdk:8

ENV SDK_URL="https://dl.google.com/android/repository/sdk-tools-linux-4333796.zip" \
ANDROID_HOME="/usr/local/android-sdk" \
ANDROID_VERSION=26 \
ANDROID_BUILD_TOOLS_VERSION=26.0.2

WORKDIR /usr/src/app

RUN mkdir "$ANDROID_HOME" .android \
&& cd "$ANDROID_HOME" \
&& curl -o sdk.zip $SDK_URL \
&& unzip sdk.zip \
&& rm sdk.zip \
&& yes | $ANDROID_HOME/tools/bin/sdkmanager --licenses

ENV PATH ${PATH}:${ANDROID_HOME}/tools:${ANDROID_HOME}/tools/bin:${ANDROID_HOME}/platform-tools

RUN sdkmanager --update
RUN sdkmanager "build-tools;${ANDROID_BUILD_TOOLS_VERSION}" \
"platforms;android-${ANDROID_VERSION}" \
"platform-tools"

COPY gradlew build.gradle ./
COPY gradle/ ./gradle/

RUN ./gradlew

COPY . .
20 changes: 15 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,21 @@ android {
defaultConfig {

applicationId 'com.todotxt.todotxttouch'
minSdkVersion 14
targetSdkVersion 17
minSdkVersion 21
targetSdkVersion 21
versionCode 35
versionName "release35"

multiDexEnabled true

}

lintOptions {
checkReleaseBuilds true
// Or, if you prefer, you can continue to check for errors in release builds,
// but continue the build even when errors are found:
abortOnError false
}

buildTypes {

Expand All @@ -23,8 +32,8 @@ android {
}

release {
minifyEnabled true // Enables code shrinking for the release build type.
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
// minifyEnabled true // Enables code shrinking for the release build type.
// proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
}
}
flavorDimensions "free"
Expand Down Expand Up @@ -73,7 +82,8 @@ dependencies {
compile 'com.actionbarsherlock:actionbarsherlock:4.4.0@aar'
compile 'com.android.support:support-v4:26.1.0'
compile 'com.dropbox.core:dropbox-core-sdk:3.0.6'
// compile 'net.sf.proguard:proguard-gradle:6.0.3'
compile fileTree(dir: 'libs', include: ['*.jar'])
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.15.0'
}
}
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ You should have received a copy of the GNU General Public License along with Tod
android:label="@string/app_label"
android:theme="@style/Theme.TodoTxt">
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:name="com.dropbox.core.android.AuthActivity"
android:configChanges="orientation|keyboard"
android:launchMode="singleTask">
<intent-filter>
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/java/com/todotxt/todotxttouch/LoginScreen.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
*/
package com.todotxt.todotxttouch;

import android.annotation.SuppressLint;
import android.app.Activity;
import android.content.BroadcastReceiver;
import android.content.Context;
Expand All @@ -45,6 +46,7 @@ public class LoginScreen extends Activity {
private Button m_LoginButton;
private BroadcastReceiver m_broadcastReceiver;

@SuppressLint("WrongViewCast")
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ public String getAccessTokenSecret() {
return m_prefs.getString(PREF_ACCESSTOKEN_SECRET, null);
}

public void storeAccessToken(String accessTokenKey) {
storeAccessToken(accessTokenKey, null);
}

public void storeAccessToken(String accessTokenKey, String accessTokenSecret) {
Editor editor = m_prefs.edit();
editor.putString(PREF_ACCESSTOKEN_KEY, accessTokenKey);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.todotxt.todotxttouch.remote;

import com.dropbox.core.DbxHost;
import com.dropbox.core.DbxRequestConfig;
import com.dropbox.core.http.OkHttp3Requestor;
import com.dropbox.core.v2.DbxClientV2;

public class DropboxClientFactory {

private static DbxClientV2 sDbxClient;
private static String clientId = "todo.txt-android";

public static void init(String accessToken) {
if (sDbxClient == null) {
DbxRequestConfig requestConfig = new DbxRequestConfig(clientId);

sDbxClient = new DbxClientV2(requestConfig, accessToken);
}
}

public static DbxClientV2 getClient() {
if (sDbxClient == null) {
throw new IllegalStateException("Client not initialized.");
}
return sDbxClient;
}

public static DbxClientV2 initAndGetClient(String accessToken) {
init(accessToken);
return getClient();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@

package com.todotxt.todotxttouch.remote;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.core.v2.files.FileMetadata;

import java.io.File;

public class DropboxFile {
private String remoteFile;
private File localFile;
private String originalRev;
private DropboxAPI.Entry loadedMetadata;
private FileMetadata loadedMetadata;
private DropboxFileStatus status;
private Exception error;

Expand All @@ -52,14 +52,14 @@ public DropboxFile(String remoteFile, File localFile, String originalRev) {
/**
* @return the loadedMetadata
*/
public DropboxAPI.Entry getLoadedMetadata() {
public FileMetadata getLoadedMetadata() {
return loadedMetadata;
}

/**
* @param loadedMetadata the loadedMetadata to set
*/
public void setLoadedMetadata(DropboxAPI.Entry loadedMetadata) {
public void setLoadedMetadata(FileMetadata loadedMetadata) {
this.loadedMetadata = loadedMetadata;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,13 @@

import android.util.Log;

import com.dropbox.client2.DropboxAPI;
import com.dropbox.client2.exception.DropboxException;
import com.dropbox.client2.exception.DropboxServerException;
import com.dropbox.core.DbxDownloader;
import com.dropbox.core.DbxException;
import com.dropbox.core.v2.DbxClientV2;
import com.dropbox.core.v2.files.DeletedMetadata;
import com.dropbox.core.v2.files.FileMetadata;
import com.dropbox.core.v2.files.GetMetadataErrorException;
import com.dropbox.core.v2.files.Metadata;
import com.todotxt.todotxttouch.util.Util;

import java.io.File;
Expand All @@ -41,16 +45,16 @@
public class DropboxFileDownloader {
final static String TAG = DropboxFileDownloader.class.getSimpleName();

private DropboxAPI<?> dropboxApi;
private DbxClientV2 dbxClient;
private DropboxFileStatus status;
private Collection<DropboxFile> files;

/**
* @param files
*/
public DropboxFileDownloader(DropboxAPI<?> dropboxApi,
public DropboxFileDownloader(DbxClientV2 client,
Collection<DropboxFile> files) {
this.dropboxApi = dropboxApi;
this.dbxClient = client;
this.files = files;
status = DropboxFileStatus.INITIALIZED;
}
Expand Down Expand Up @@ -92,36 +96,44 @@ public void pullFiles() {
private void loadMetadata(DropboxFile file) {
Log.d(TAG, "Loading metadata for " + file.getRemoteFile());

DropboxAPI.Entry metadata = null;
Metadata metadata = null;

try {
metadata = dropboxApi.metadata(file.getRemoteFile(), 0, null,
false, null);
} catch (DropboxServerException se) {
if (se.error == DropboxServerException._404_NOT_FOUND) {
metadata = dbxClient.files().getMetadata(file.getRemoteFile());
} catch (GetMetadataErrorException mde) {
if (mde.errorValue.isPath() && mde.errorValue.getPathValue().isNotFound()) {
Log.d(TAG, "metadata NOT found! Returning NOT_FOUND status.");

file.setStatus(DropboxFileStatus.NOT_FOUND);

return;
}

throw new RemoteException("Server Exception: " + se.error + " " + se.reason, se);
} catch (DropboxException e) {
throw new RemoteException("Server Exception: " + mde.errorValue + " " + mde.getUserMessage(), mde);
} catch (DbxException e) {
throw new RemoteException("Dropbox Exception: " + e.getMessage(), e);
}

Log.d(TAG, "Metadata retrieved. rev on Dropbox = " + metadata.rev);
Log.d(TAG, "local rev = " + file.getOriginalRev());
FileMetadata fileMetadata = null;
if(metadata instanceof FileMetadata) {
file.setLoadedMetadata((FileMetadata) metadata);
fileMetadata = (FileMetadata) metadata;
Log.d(TAG, "Metadata retrieved. rev on Dropbox = " + fileMetadata.getRev());
}

file.setLoadedMetadata(metadata);
DeletedMetadata deletedMetadata = null;
if(metadata instanceof DeletedMetadata){
deletedMetadata = (DeletedMetadata) metadata;
}

Log.d(TAG, "local rev = " + file.getOriginalRev());

if (metadata.rev.equals(file.getOriginalRev())) {
if (fileMetadata != null && fileMetadata.getRev().equals(file.getOriginalRev())) {
// don't bother downloading if the rev is the same
Log.d(TAG, "revs match. returning NOT_CHANGED status.");

file.setStatus(DropboxFileStatus.NOT_CHANGED);
} else if (metadata.isDeleted) {
} else if (deletedMetadata != null) {
Log.d(TAG, "File marked as deleted on Dropbox! Returning NOT_FOUND status.");
file.setStatus(DropboxFileStatus.NOT_FOUND);
} else {
Expand All @@ -134,7 +146,7 @@ private void loadMetadata(DropboxFile file) {
private void loadFile(DropboxFile file) {
Log.d(TAG,
"Downloading " + file.getRemoteFile() + " at rev = "
+ file.getLoadedMetadata().rev);
+ file.getLoadedMetadata().getRev());

File localFile = file.getLocalFile();

Expand All @@ -156,11 +168,12 @@ private void loadFile(DropboxFile file) {
}

try {
dropboxApi.getFile(file.getRemoteFile(), file.getLoadedMetadata().rev, outputStream,
null);
DbxDownloader downloader = dbxClient.files().download(file.getRemoteFile(),
file.getLoadedMetadata().getRev());
downloader.download(outputStream);
outputStream.flush();
outputStream.close();
} catch (DropboxException e) {
} catch (DbxException e) {
throw new RemoteException("Cannot get file from Dropbox", e);
} catch (IOException e) {
throw new RemoteException("Failed to find file", e);
Expand Down
Loading