Skip to content

Commit

Permalink
Merge pull request #307 from spacecowboy/dropbox_update
Browse files Browse the repository at this point in the history
Switch to Dropbox Core API
  • Loading branch information
spacecowboy committed Sep 6, 2015
2 parents 9b617d0 + 39c5d4f commit 56eda36
Show file tree
Hide file tree
Showing 24 changed files with 810 additions and 503 deletions.
25 changes: 7 additions & 18 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ repositories {

// Version number
def versionMajor = 5 // Major UI overhauls
def versionMinor = 6 // Some new functionality
def versionMinor = 7 // Some new functionality
def versionPatch = 0 // Bug fixes
def versionBuild = 0 // Bump for dogfood builds, public betas, etc.
def versionBuild = 1 // Bump for dogfood builds, public betas, etc.

// Version name from git
def getVersionName = { ->
Expand All @@ -64,6 +64,11 @@ android {
abortOnError false
}

packagingOptions {
exclude 'META-INF/LICENSE.txt'
exclude 'META-INF/NOTICE.txt'
}

defaultConfig {
applicationId "com.nononsenseapps.notepad"
minSdkVersion 14
Expand Down Expand Up @@ -129,20 +134,6 @@ apt {
}
}

// Dropbox
task nativeLibsToJar(type: Zip) {
destinationDir file("$buildDir/native-libs")
baseName 'native-libs'
extension 'jar'
from fileTree(dir: 'src/play/libs', include: '**/*.so')
into 'lib/'
}

// If non-free, depend on dropbox
tasks.withType(JavaCompile) {
compileTask -> if (compileTask.toString().contains("Play")) compileTask.dependsOn(nativeLibsToJar)
}

dependencies {
//compile fileTree(dir: 'libs', include: '*.jar')
compile 'com.android.support:support-v4:19.0.1'
Expand All @@ -164,9 +155,7 @@ dependencies {
// Dropbox and non-free stuff
playCompile fileTree(dir: 'src/play/libs', include: '*.jar')
playBetaCompile fileTree(dir: 'src/play/libs', include: '*.jar')
playCompile fileTree(dir: "$buildDir/native-libs", include: "*.jar")
playCompile 'com.google.android.gms:play-services:5.0.89'
playBetaCompile fileTree(dir: "$buildDir/native-libs", include: "*.jar")
playBetaCompile 'com.google.android.gms:play-services:5.0.89'
// Tests
androidTestCompile 'com.squareup.spoon:spoon-client:1.1.1'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,10 @@ public void testProps() {
assertNotNull(Config.getGtasksApiKey(context));
assertFalse(Config.getGtasksApiKey(context).isEmpty());

assertNotNull(Config.getKeyDropboxSyncPublic(context));
assertFalse(Config.getKeyDropboxSyncPublic(context).isEmpty());
assertNotNull(Config.getKeyDropboxAPI(context));
assertFalse(Config.getKeyDropboxAPI(context).isEmpty());

assertNotNull(Config.getKeyDropboxSyncSecret(context));
assertFalse(Config.getKeyDropboxSyncSecret(context).isEmpty());
assertNotNull(Config.getKeyDropboxAPISecret(context));
assertFalse(Config.getKeyDropboxAPISecret(context).isEmpty());
}
}
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
/*
* Copyright (c) 2014 Jonas Kalderstam.
* Copyright (c) 2015 Jonas Kalderstam.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* http://www.apache.org/licenses/LICENSE-2.0
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

package com.nononsenseapps.notepad.sync.orgsync;
Expand All @@ -22,11 +23,24 @@
* Dummy file, see play flavor.
*/
public class DropboxSyncHelper {
public static boolean hasSynced(Activity activity) {

public DropboxSyncHelper(Activity activity) {

}

public boolean isLinked() {
return false;
}

public static void doFirstSync(Activity activity) {
public void linkAccount() {

}

public void unlinkAccount() {

}

public boolean handleLinkResult() {
return false;
}
}
12 changes: 6 additions & 6 deletions app/src/main/java/com/nononsenseapps/build/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class Config {
public final static boolean LOGGING = true;

public static final String KEY_GTASKS_API_KEY = "gtasks_api_key";
public static final String KEY_DROPBOX_SYNC_PUBLIC = "dropbox_sync_public";
public static final String KEY_DROPBOX_SYNC_SECRET = "dropbox_sync_secret";
public static final String KEY_DROPBOX_API = "dropbox_api";
public static final String KEY_DROPBOX_API_SECRET = "dropbox_api_secret";

private static final String propFile = "secretkeys.properties";
private static Properties props;
Expand All @@ -59,11 +59,11 @@ public static String getGtasksApiKey(final Context context) {
"AIzaSyCAjRk2GfPARlIU3JsaEiExLMtj_rdN2i4");
}

public static String getKeyDropboxSyncPublic(final Context context) {
return getProperties(context).getProperty(KEY_DROPBOX_SYNC_PUBLIC);
public static String getKeyDropboxAPI(final Context context) {
return getProperties(context).getProperty(KEY_DROPBOX_API);
}

public static String getKeyDropboxSyncSecret(final Context context) {
return getProperties(context).getProperty(KEY_DROPBOX_SYNC_SECRET);
public static String getKeyDropboxAPISecret(final Context context) {
return getProperties(context).getProperty(KEY_DROPBOX_API_SECRET);
}
}
51 changes: 30 additions & 21 deletions app/src/main/java/com/nononsenseapps/notepad/prefs/SyncPrefs.java
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ public class SyncPrefs extends PreferenceFragment implements
public static final String KEY_DROPBOX_ENABLE = "pref_sync_dropbox_enabled";
public static final String KEY_DROPBOX_DIR = "pref_sync_dropbox_dir";
private static final int PICK_SD_DIR_CODE = 1;
private static final int DROPBOX_LINK_CODE = 3895;
private static final int PICK_DROPBOX_DIR_CODE = 2;


Expand All @@ -88,6 +87,7 @@ public class SyncPrefs extends PreferenceFragment implements
private Preference prefAccount;
private Preference prefSdDir;
private Preference prefDropboxDir;
private DropboxSyncHelper mDropboxHelper = null;

// private Preference prefSyncFreq;

Expand Down Expand Up @@ -200,9 +200,9 @@ public boolean onPreferenceClick(final Preference preference) {
// Dropbox, disable if no key present
findPreference(KEY_DROPBOX_ENABLE)
.setEnabled(BuildConfig.DROPBOX_ENABLED &&
Config.getKeyDropboxSyncSecret(getActivity()) !=
Config.getKeyDropboxAPI(getActivity()) !=
null &&
!Config.getKeyDropboxSyncSecret(getActivity())
!Config.getKeyDropboxAPISecret(getActivity())
.contains(" "));
prefDropboxDir = findPreference(KEY_DROPBOX_DIR);
prefDropboxDir.setEnabled(BuildConfig.DROPBOX_ENABLED);
Expand All @@ -213,7 +213,10 @@ public boolean onPreferenceClick(final Preference preference) {
public boolean onPreferenceClick(
final Preference preference) {
// See if initial sync is complete
if (DropboxSyncHelper.hasSynced(getActivity())) {
if (mDropboxHelper == null) {
mDropboxHelper = new DropboxSyncHelper(getActivity());
}
if (mDropboxHelper.isLinked()) {
// Start the filepicker
Intent i = new Intent(getActivity(),
DropboxFilePickerActivity.class);
Expand All @@ -232,13 +235,6 @@ public boolean onPreferenceClick(
startActivityForResult(i,
PICK_DROPBOX_DIR_CODE);

} else {
// Start first sync
DropboxSyncHelper.doFirstSync(getActivity());
// Notify the user to wait
Toast.makeText(getActivity(),
R.string.wait_for_dropbox,
Toast.LENGTH_SHORT).show();
}

return true;
Expand Down Expand Up @@ -292,11 +288,18 @@ public void onSharedPreferenceChanged(SharedPreferences prefs,
} else if (KEY_SD_DIR.equals(key)) {
setSdDirSummary(prefs);
} else if (KEY_DROPBOX_ENABLE.equals(key)) {
// TODO
if (mDropboxHelper == null) {
mDropboxHelper = new DropboxSyncHelper(getActivity());
}
if (prefs.getBoolean(key, false)) {
DropboxSynchronizer.linkAccount(this,
DROPBOX_LINK_CODE);
// authorize the user
mDropboxHelper.linkAccount();
// DropboxSynchronizer.linkAccount(this,
// DROPBOX_LINK_CODE);
} else {
DropboxSynchronizer.unlink(getActivity());
mDropboxHelper.unlinkAccount();
// DropboxSynchronizer.unlink(getActivity());
}
// Restart sync service
OrgSyncService.stop(getActivity());
Expand All @@ -315,17 +318,23 @@ public void onSharedPreferenceChanged(SharedPreferences prefs,
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == DROPBOX_LINK_CODE) {
if (resultCode == Activity.RESULT_OK) {
// Start first sync
DropboxSyncHelper.doFirstSync(getActivity());
public void onResume() {
super.onResume();

if (mDropboxHelper != null) {
if (mDropboxHelper.handleLinkResult()) {
// Success
} else {
// ... Link failed or was cancelled by the user.
// Link failed or was cancelled by the user.
PreferenceManager.getDefaultSharedPreferences(getActivity()).edit()
.putBoolean(KEY_DROPBOX_ENABLE, false).commit();
}
} else if (requestCode == PICK_DROPBOX_DIR_CODE) {
}
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == PICK_DROPBOX_DIR_CODE) {
if (resultCode == Activity.RESULT_OK) {
PreferenceManager.getDefaultSharedPreferences(getActivity
()).edit().putString(KEY_DROPBOX_DIR,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@ public void handleMessage(Message msg) {
}

} catch (IOException ignored) {
Log.e(TAG, ignored.getMessage());
} catch (ParseException ignored) {
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public OrgFile getNewFile(final String desiredName) throws IOException,
* @param orgFile
* The file to delete.
*/
public void deleteRemoteFile(final OrgFile orgFile);
public void deleteRemoteFile(final OrgFile orgFile) throws IOException;

/**
* Rename the file on the remote end.
Expand All @@ -88,21 +88,21 @@ public OrgFile getNewFile(final String desiredName) throws IOException,
* @param orgFile
* This contains the new name.
*/
public void renameRemoteFile(final String oldName, final OrgFile orgFile);
public void renameRemoteFile(final String oldName, final OrgFile orgFile) throws IOException;

/**
* Returns a BufferedReader to the remote file. Null if it doesn't exist.
*
* @param filename
* Name of the file, without path
*/
public BufferedReader getRemoteFile(final String filename);
public BufferedReader getRemoteFile(final String filename) throws IOException;

/**
*
* @return a set of all remote files.
*/
public HashSet<String> getRemoteFilenames();
public HashSet<String> getRemoteFilenames() throws IOException;

/**
* Do a full 2-way sync.
Expand Down
15 changes: 2 additions & 13 deletions app/src/play/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -98,30 +98,19 @@
android:label="@string/app_name"
android:theme="@style/FilePicker.Theme">
</activity>
<service
android:name="com.nononsenseapps.notepad.sync.orgsync.DropboxSyncHelper"
android:enabled="true"
android:exported="false" />

<!-- Dropbox -->
<activity android:name="com.dropbox.sync.android.DbxAuthActivity" />
<activity
android:name="com.dropbox.client2.android.AuthActivity"
android:launchMode="singleTask" >
android:launchMode="singleTask"
android:configChanges="orientation|keyboard" >
<intent-filter>
<data android:scheme="db-yt0azqlcrdl2u22" />

<action android:name="android.intent.action.VIEW" />

<category android:name="android.intent.category.BROWSABLE" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
</activity>
<service
android:name="com.dropbox.sync.android.DbxSyncService"
android:enabled="true"
android:exported="false"
android:label="Dropbox Sync" />
</application>

</manifest>
Loading

0 comments on commit 56eda36

Please sign in to comment.