Merge branch 'branding' into bring-branding-to-master

# Conflicts:
#	.drone.yml
#	build.gradle
#	src/main/java/com/owncloud/android/services/SyncedFolderJobService.java
#	src/main/java/com/owncloud/android/services/observer/SyncedFolderObserver.java
#	src/main/java/com/owncloud/android/utils/RecursiveFileObserver.java
This commit is contained in:
Mario Danic 2017-03-05 21:09:36 +01:00
commit 0ffb67c506
966 changed files with 724 additions and 150 deletions

View File

@ -1,6 +1,6 @@
pipeline:
test:
image: nextcloudci/android:android-14
image: nextcloudci/android:android-15
commands:
- echo no | android create avd --force -n test -t $ANDROID_TARGET --abi $ANDROID_ABI -c 20M
- emulator -avd test -no-window &
@ -8,12 +8,15 @@ pipeline:
# build app and assemble APK, in debug mode
- ./gradlew assembleDebug
# run all the local unit tests of app module
- ./gradlew :testDebug
- ./gradlew :testGenericDebugUnitTest
- ./gradlew :testCustomDebugUnitTest
# run all the instrumented tests of app module - DISABLED until we get an stable setup for Espresso in Travis
# - ./gradlew connectedDebugAndroidTest --info
# install app, then assemble and install instrumented tests of app module
- ./gradlew :installDebug
- ./gradlew :installDebugAndroidTest
- ./gradlew :installGenericDebug
- ./gradlew :installCustomDebug
- ./gradlew :installGenericDebugAndroidTest
- ./gradlew :installCustomDebugAndroidTest
# run sample instrumented unit test
# TODO fails because test runner is not available
#- adb shell am instrument -w -e debug false -e class com.owncloud.android.datamodel.OCFileUnitTest com.owncloud.android.test/android.support.test.runner.AndroidJUnitRunner

1
.gitignore vendored
View File

@ -33,3 +33,4 @@ tests/proguard-project.txt
*.iml
build
/gradle.properties

View File

@ -28,7 +28,7 @@ For other software dependencies check the details in the section corresponding t
You will need [git][1] to access to the different versions of the Nextcloud's source code. The source code is hosted in Github and may be read by anybody without needing a Github account. You will need a Github account if you want to contribute to the development of the app with your own code.
Next steps will assume you have a Github account and that you will get the code from your own fork.
Next steps will assume you have a Github account and that you will get the code from your own fork.
* In a web browser, go to https://github.com/nextcloud/android, and click the 'Fork' button near the top right corner.
* Open a terminal and go on with the next steps in it.
@ -63,11 +63,20 @@ To set up the project in Android Studio follow the next steps:
* Run the 'clean' and 'build' tasks using the Gradle wrapper provided
- Windows: ```gradlew.bat clean build```
- Mac OS/Linux: ```./gradlew clean build```
The first time the Gradle wrapper is called, the correct Gradle version will be downloaded automatically. An Internet connection is needed for it works.
The generated APK file is saved in android/build/outputs/apk as android-debug.apk
### 4. App flavours
The app is currently equipped to be built with two flavours:
* generic - the regular build, released as a Nextcloud Android app on the Play store
* custom - a customized build, to be used by people who need features we can't or
won't include into the traditional build (like Firebase Analytics)
When building the *generic*, you will *not* get the dependencies imposed by the *custom*
build.
[0]: https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md
[1]: https://git-scm.com/

View File

@ -14,6 +14,7 @@ buildscript {
}
dependencies {
classpath 'com.android.tools.build:gradle:2.2.3'
classpath 'com.google.gms:google-services:3.0.0'
}
}
@ -40,54 +41,6 @@ repositories {
}
}
dependencies {
/// dependencies for app building
compile name: 'touch-image-view'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.nextcloud:android-library:1.0.13'
compile "com.android.support:support-v4:${supportLibraryVersion}"
compile "com.android.support:design:${supportLibraryVersion}"
compile 'com.jakewharton:disklrucache:2.0.2'
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.google.code.findbugs:annotations:2.0.1'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.github.evernote:android-job:v1.1.7'
/// dependencies for local unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
/// dependencies for instrumented tests
// JUnit4 Rules
androidTestCompile 'com.android.support.test:rules:0.5'
// Android JUnit Runner
androidTestCompile 'com.android.support.test:runner:0.5'
// Android Annotation Support
androidTestCompile "com.android.support:support-annotations:${supportLibraryVersion}"
// Espresso core
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
androidTestCompile "com.android.support:support-annotations:${supportLibraryVersion}"
}
tasks.withType(Test) {
/// increased logging for tests
testLogging {
events "passed", "skipped", "failed"
}
}
android {
lintOptions {
abortOnError true
@ -112,40 +65,33 @@ android {
testInstrumentationRunnerArgument "TEST_SERVER_URL", "\"$System.env.OCTEST_SERVER_BASE_URL\""
multiDexEnabled true
applicationId "com.nextcloud.client"
// adapt structure from Eclipse to Gradle/Android Studio expectations;
// see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
productFlavors {
generic {
applicationId 'com.nextcloud.client'
}
custom {
// structure is:
// domain tld
// domain name
// .client
applicationId 'com.custom.client'
}
}
configurations {
customCompile
}
}
// adapt structure from Eclipse to Gradle/Android Studio expectations;
// see http://tools.android.com/tech-docs/new-build-system/user-guide#TOC-Configuring-the-Structure
sourceSets {
main {
manifest.srcFile 'AndroidManifest.xml'
java.srcDirs = ['src']
resources.srcDirs = ['src']
aidl.srcDirs = ['src']
renderscript.srcDirs = ['src']
res.srcDirs = ['res']
assets.srcDirs = ['assets']
}
// move whole local unit tests structure as a whole from src/test/* to test/*
test.setRoot('test')
// move whole instrumented tests structure as a whole from src/androidTest/* to androidTest/*
androidTest.setRoot('androidTest')
// Move the build types to build-types/<type>
// For instance, build-types/debug/java, build-types/debug/AndroidManifest.xml, ...
// This moves them out of them default location under src/<type>/... which would
// conflict with src/ being used by the main source set.
// Adding new build types or product flavors should be accompanied
// by a similar customization.
debug.setRoot('build-types/debug')
release.setRoot('build-types/release')
}
dexOptions {
// Skip pre-dexing when running on Travis CI or when disabled via -Dpre-dex=false.
preDexLibraries = preDexEnabled && !travisBuild
@ -163,6 +109,7 @@ android {
packagingOptions {
exclude 'META-INF/LICENSE.txt'
}
task checkstyle(type: Checkstyle) {
configFile = file("${rootProject.projectDir}/checkstyle.xml")
configProperties.checkstyleSuppressionsPath = file("${project.rootDir}/config/quality/checkstyle/suppressions.xml").absolutePath
@ -215,3 +162,54 @@ android {
check.dependsOn 'checkstyle', 'findbugs', 'pmd', 'lint'
}
dependencies {
/// dependencies for app building
compile name: 'touch-image-view'
compile 'com.android.support:multidex:1.0.1'
compile 'com.github.nextcloud:android-library:1.0.11'
compile "com.android.support:support-v4:${supportLibraryVersion}"
compile "com.android.support:design:${supportLibraryVersion}"
compile 'com.jakewharton:disklrucache:2.0.2'
compile "com.android.support:appcompat-v7:${supportLibraryVersion}"
compile 'com.getbase:floatingactionbutton:1.10.1'
compile 'com.google.code.findbugs:annotations:2.0.1'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile 'com.google.android.gms:play-services:10.2.0'
compile 'com.github.evernote:android-job:v1.1.7'
customCompile 'com.google.firebase:firebase-core:10.2.0'
/// dependencies for local unit tests
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:1.10.19'
/// dependencies for instrumented tests
// JUnit4 Rules
androidTestCompile 'com.android.support.test:rules:0.5'
// Android JUnit Runner
androidTestCompile 'com.android.support.test:runner:0.5'
// Android Annotation Support
androidTestCompile "com.android.support:support-annotations:${supportLibraryVersion}"
// Espresso core
androidTestCompile 'com.android.support.test.espresso:espresso-core:2.2.2'
// UIAutomator - for cross-app UI tests, and to grant screen is turned on in Espresso tests
//androidTestCompile 'com.android.support.test.uiautomator:uiautomator-v18:2.1.2'
// fix conflict in dependencies; see http://g.co/androidstudio/app-test-app-conflict for details
//androidTestCompile "com.android.support:support-annotations:${supportLibraryVersion}"
}
tasks.withType(Test) {
/// increased logging for tests
testLogging {
events "passed", "skipped", "failed"
}
}
apply plugin: 'com.google.gms.google-services'

View File

@ -1,27 +0,0 @@
/**
* ownCloud Android client application
*
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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.
*
* 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.owncloud.android.ui.fragment;
import android.support.v4.app.Fragment;
public class AuthenticatorAccountDetailsFragment extends Fragment {
}

View File

@ -1,27 +0,0 @@
/**
* ownCloud Android client application
*
* Copyright (C) 2012 Bartek Przybylski
* Copyright (C) 2015 ownCloud Inc.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2,
* as published by the Free Software Foundation.
*
* 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.
*
* 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.owncloud.android.ui.fragment;
import android.support.v4.app.Fragment;
public class AuthenticatorGetStartedFragment extends Fragment {
}

View File

@ -0,0 +1,30 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
Nextcloud Android client application
Copyright (C) 2017 Mario Danic
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
at your option) any later version.
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 Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
-->
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools">
<application
android:name="com.owncloud.android.CustomApp"
tools:replace="android:name">
</application>
</manifest>

View File

@ -0,0 +1,35 @@
{
"project_info": {
"project_number": "",
"project_id": ""
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "",
"android_client_info": {
"package_name": "com.custom.client"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": ""
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
}
}
}
],
"configuration_version": "1"
}

View File

@ -0,0 +1,50 @@
/**
* Nextcloud Android client application
*
* @author Mario Danic
* Copyright (C) 2017 Mario Danic
* Copyright (C) 2017 Nextcloud GmbH
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Affero General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* at your option) any later version.
*
* 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 Affero General Public License for more details.
*
* You should have received a copy of the GNU Affero General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android;
import com.google.firebase.analytics.FirebaseAnalytics;
/**
* Custom App class for custom builds
*/
public class CustomApp extends MainApp {
private FirebaseAnalytics firebaseAnalytics;
@Override
public void onCreate() {
super.onCreate();
firebaseAnalytics = FirebaseAnalytics.getInstance(this);
}
private FirebaseAnalytics getFirebaseAnalyticsInstance() {
/*
In order for Firebase Analytics to work, you also need to
put a proper google-services.json in src/custom folder
If that file is flawed, nothing will be sent to Firebase
*/
return firebaseAnalytics;
}
}

View File

@ -46,6 +46,12 @@
android:paddingTop="@dimen/standard_half_padding"
android:visibility="gone">
<TextView
android:id="@+id/drawer_quota_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/drawer_quota"/>
<ProgressBar
android:id="@+id/drawer_quota_ProgressBar"
style="?android:attr/progressBarStyleHorizontal"
@ -56,11 +62,6 @@
android:text="@string/drawer_quota"
/>
<TextView
android:id="@+id/drawer_quota_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/drawer_quota"/>
</LinearLayout>
</android.support.design.widget.NavigationView>

View File

@ -0,0 +1,103 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<!-- Beta indicator -->
<bool name="is_beta">false</bool>
<!-- App name and other strings-->
<string name="app_name">Nextcloud</string>
<string name="account_type">nextcloud</string> <!-- better if was a domain name; but changing it now would require migrate accounts when the app is updated -->
<string name="authority">com.custom.client.provider</string> <!-- better if was the app package with ".provider" appended ; it identifies the provider -->
<string name="users_and_groups_search_authority">com.custom.client.provider.UsersAndGroupsSearch</string>
<string name="document_provider_authority">com.custom.provider.Documents</string>
<string name="file_provider_authority">com.custom.provider.Files</string>
<string name ="db_file">nextcloud.db</string>
<string name ="db_name">nextcloud</string>
<string name ="data_folder">nextcloud</string>
<string name ="log_name">nextcloud</string>
<string name ="default_display_name_for_root_folder">Nextcloud</string>
<string name ="user_agent">Mozilla/5.0 (Android) ownCloud-android/%1$s</string>
<!-- URLs and flags related -->
<string name="server_url"></string>
<bool name="show_server_url_input">true</bool>
<bool name="show_welcome_link">false</bool>
<string name="welcome_link_url">"https://nextcloud.com/providers"</string>
<string name="share_api_link"></string>
<!-- Flags to setup the authentication methods available in the app -->
<string name="auth_method_oauth2">off</string>
<string name="auth_method_saml_web_sso">off</string>
<!-- Flags to enable/disable some features -->
<string name = "send_files_to_other_apps">on</string>
<bool name = "share_via_link_feature">true</bool>
<bool name = "share_with_users_feature">true</bool>
<!-- Colors -->
<color name="login_text_color">@color/white</color>
<color name="login_text_hint_color">#7fC0E3</color>
<color name="login_background_color">#FFFFFF</color>
<color name="login_logo_background_color">#FFFFFF</color>
<color name="background_color">#FFFFFF</color>
<color name="actionbar_start_color">#0082c9</color>
<color name="actionbar_end_color">#0082c9</color>
<color name="primary_button_background_color">@color/owncloud_blue_accent</color>
<color name="primary_button_text_color">@color/white</color>
<color name="secondary_button_background_color">#D6D7D7</color>
<color name="secondary_button_text_color">@color/black</color>
<color name="drawer_header_color">@color/owncloud_blue_accent</color>
<!-- Button -->
<color name="button_text_color">#000000</color>
<!-- Multiselect backgrounds -->
<color name="action_mode_background">#757575</color>
<color name="action_mode_status_bar_background">#616161</color>
<color name="selected_item_background">#ECECEC</color>
<!-- Multiaccount support -->
<bool name="multiaccount_support">true</bool>
<!-- Drawer options -->
<bool name="recently_added_enabled">true</bool>
<bool name="recently_modified_enabled">true</bool>
<bool name="shared_enabled">true</bool>
<bool name="videos_enabled">true</bool>
<!-- Bottom toolbar -->
<bool name="bottom_toolbar_enabled">true</bool>
<!-- Help, imprint and feedback -->
<bool name="calendar_contacts_enabled">true</bool>
<bool name="help_enabled">true</bool>
<bool name="imprint_enabled">false</bool>
<bool name="recommend_enabled">true</bool>
<bool name="feedback_enabled">true</bool>
<bool name="logger_enabled">false</bool>
<string name="url_help">https://help.nextcloud.com/c/feature</string>
<string name="url_imprint"></string>
<string name="mail_recommend">"mailto:"</string>
<string name="mail_feedback">"mailto:android@nextcloud.com"</string>
<string name="url_app_download">"https://play.google.com/store/apps/details?id=com.nextcloud.client"</string>
<string name="url_server_install">https://nextcloud.com/install</string>
<!--Destination mail for sending log files -->
<string name="mail_logger"></string>
<!-- Participate links -->
<string name="fdroid_beta_link" translatable="false">https://f-droid.org/repository/browse/?fdid=com.nextcloud.android.beta</string>
<string name="beta_apk_link" translatable="false">https://github.com/nextcloud/android/raw/beta/apks/latest.apk</string>
<string name="play_store_register_beta" translatable="false">https://play.google.com/apps/testing/com.nextcloud.client</string>
<string name="fdroid_link" translatable="false">https://f-droid.org/repository/browse/?fdid=com.nextcloud.client</string>
<string name="irc_weblink" translatable="false">http://webchat.freenode.net?channels=nextcloud-mobile</string>
<string name="help_link" translatable="false">https://help.nextcloud.com/c/clients/android</string>
<string name="translation_link" translatable="false">https://www.transifex.com/nextcloud/nextcloud/android/</string>
<string name="contributing_link" translatable="false">https://github.com/nextcloud/android/blob/master/CONTRIBUTING.md</string>
<string name="report_issue_link" translatable="false">https://github.com/nextcloud/android/issues</string>
<!-- login data links -->
<string name="login_data_own_scheme" translatable="false">cloud</string>
</resources>

View File

@ -0,0 +1,35 @@
{
"project_info": {
"project_number": "",
"project_id": ""
},
"client": [
{
"client_info": {
"mobilesdk_app_id": "",
"android_client_info": {
"package_name": "com.nextcloud.client"
}
},
"oauth_client": [],
"api_key": [
{
"current_key": ""
}
],
"services": {
"analytics_service": {
"status": 1
},
"appinvite_service": {
"status": 1,
"other_platform_oauth_client": []
},
"ads_service": {
"status": 1
}
}
}
],
"configuration_version": "1"
}

View File

@ -140,7 +140,7 @@
<provider
android:name=".providers.UsersAndGroupsSearchProvider"
android:authorities="com.nextcloud.android.providers.UsersAndGroupsSearchProvider"
android:authorities="@string/users_and_groups_search_authority"
android:enabled="true"
android:exported="false"
android:label="@string/search_users_and_groups_hint" />

View File

@ -52,8 +52,6 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
/**
* Main Application of the project

View File

@ -72,7 +72,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
private static final int RESULTS_PER_PAGE = 50;
private static final int REQUESTED_PAGE = 1;
public static final String AUTHORITY = "com.nextcloud.android.providers.UsersAndGroupsSearchProvider";
public static String AUTHORITY;
public static final String ACTION_SHARE_WITH = AUTHORITY + ".action.SHARE_WITH";
public static final String CONTENT = "content";
@ -106,6 +106,7 @@ public class UsersAndGroupsSearchProvider extends ContentProvider {
@Override
public boolean onCreate() {
AUTHORITY = getContext().getResources().getString(R.string.users_and_groups_search_authority);
mUriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
mUriMatcher.addURI(AUTHORITY, SearchManager.SUGGEST_URI_PATH_QUERY + "/*", SEARCH);
return true;

View File

@ -0,0 +1,93 @@
/**
* Nextcloud Android client application
*
* @author Tobias Kaminsky
* Copyright (C) 2016 Tobias Kaminsky
* Copyright (C) 2016 Nextcloud
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* 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 AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.owncloud.android.services;
import android.accounts.Account;
import android.annotation.TargetApi;
import android.app.job.JobParameters;
import android.app.job.JobService;
import android.content.Context;
import android.content.Intent;
import android.os.Build;
import android.os.PersistableBundle;
import com.owncloud.android.MainApp;
import com.owncloud.android.authentication.AccountUtils;
import com.owncloud.android.files.services.FileUploader;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.operations.UploadFileOperation;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.MimeTypeUtil;
import java.io.File;
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
public class SyncedFolderJobService extends JobService {
private static final String TAG = "SyncedFolderJobService";
public static final String LOCAL_PATH = "filePath";
public static final String REMOTE_PATH = "remotePath";
public static final String ACCOUNT = "account";
public static final String UPLOAD_BEHAVIOUR = "uploadBehaviour";
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return START_REDELIVER_INTENT;
}
@Override
public boolean onStartJob(JobParameters params) {
Context context = MainApp.getAppContext();
PersistableBundle bundle = params.getExtras();
String filePath = bundle.getString(LOCAL_PATH);
String remotePath = bundle.getString(REMOTE_PATH);
Account account = AccountUtils.getOwnCloudAccountByName(context, bundle.getString(ACCOUNT));
Integer uploadBehaviour = bundle.getInt(UPLOAD_BEHAVIOUR);
Log_OC.d(TAG, "startJob: " + params.getJobId() + ", filePath: " + filePath);
File file = new File(filePath);
// File can be deleted between job generation and job execution. If file does not exist, just ignore it
if (file.exists()) {
String mimeType = MimeTypeUtil.getBestMimeTypeByFilename(file.getAbsolutePath());
FileUploader.UploadRequester requester = new FileUploader.UploadRequester();
requester.uploadNewFile(
context,
account,
filePath,
remotePath,
uploadBehaviour,
mimeType,
true, // create parent folder if not existent
UploadFileOperation.CREATED_AS_INSTANT_PICTURE
);
}
return false;
}
@Override
public boolean onStopJob(JobParameters params) {
return false;
}
}

View File

@ -0,0 +1,78 @@
package com.owncloud.android.services.observer;
import android.annotation.TargetApi;
import android.app.job.JobInfo;
import android.app.job.JobScheduler;
import android.content.ComponentName;
import android.content.Context;
import android.os.Build;
import android.os.FileObserver;
import android.os.PersistableBundle;
import android.util.Log;
import com.owncloud.android.MainApp;
import com.owncloud.android.datamodel.SyncedFolder;
import com.owncloud.android.lib.common.utils.Log_OC;
import com.owncloud.android.services.SyncedFolderJobService;
import com.owncloud.android.utils.FileStorageUtils;
import com.owncloud.android.utils.RecursiveFileObserver;
import java.io.File;
import java.util.Date;
class SyncedFolderObserver extends RecursiveFileObserver {
private Context context;
public static final String TAG = "SyncedFolderObserver";
private SyncedFolder syncedFolder;
public SyncedFolderObserver(SyncedFolder syncedFolder) {
super(syncedFolder.getLocalPath(), FileObserver.CREATE + FileObserver.MOVED_TO);
context = MainApp.getAppContext();
this.syncedFolder = syncedFolder;
Log_OC.d("SyncedFolderObserver", "Started watching: " + syncedFolder.getLocalPath());
}
@TargetApi(Build.VERSION_CODES.LOLLIPOP)
@Override
public void onEvent(int event, String path) {
Log.d(TAG, "Event: " + event + " Path: " + path);
File temp = new File(path);
// do not upload "null"-files, test if file exists and is a real file
if (!temp.getName().equalsIgnoreCase("null") && temp.isFile() && !temp.getName().endsWith(".tmp")) {
PersistableBundle bundle = new PersistableBundle();
// TODO extract
bundle.putString(SyncedFolderJobService.LOCAL_PATH, path);
bundle.putString(SyncedFolderJobService.REMOTE_PATH, FileStorageUtils.getInstantUploadFilePath(
syncedFolder.getRemotePath(), temp.getName(),
new Date().getTime(),
syncedFolder.getSubfolderByDate()));
bundle.putString(SyncedFolderJobService.ACCOUNT, syncedFolder.getAccount());
bundle.putInt(SyncedFolderJobService.UPLOAD_BEHAVIOUR, syncedFolder.getUploadAction());
JobScheduler js = (JobScheduler) context.getSystemService(Context.JOB_SCHEDULER_SERVICE);
Long date = new Date().getTime();
JobInfo job = new JobInfo.Builder(
date.intValue(),
new ComponentName(context, SyncedFolderJobService.class))
.setRequiresCharging(syncedFolder.getChargingOnly())
.setMinimumLatency(10000)
.setRequiredNetworkType(syncedFolder.getWifiOnly() ? JobInfo.NETWORK_TYPE_UNMETERED : JobInfo.NETWORK_TYPE_ANY)
.setExtras(bundle)
.setPersisted(true)
.build();
Integer result = js.schedule(job);
if (result <= 0) {
Log_OC.d(TAG, "Job failed to start: " + result);
}
}
}
}

Some files were not shown because too many files have changed in this diff Show More