Skip to content

Commit

Permalink
4.0.0-alpha01 (#461)
Browse files Browse the repository at this point in the history
* #450 upgraded gradle plugin to 3.4.2, gradle wrapper to 5.4.1 and replaced dcendents maven plugin with new gradle-maven-plugin from sky-uk. Added kotlin support in the modules and bumped versions for new development cycles. Added script for local snapshot release. Updated RecyclerAdapter.

* update travis configuration

* update travis configuration

* #450 ported OkHttp module to Kotlin and upgraded to OkHttp 4.0.1

* #450 OkHttp BodyWriter is now cloaseable. Relying on Kotlin "use" to safely handle it. Refactored createBody method.

* #450 migrated HurlStack and generic http facade to Kotlin

* #450 try to make travis happy again

* #450 Refactored http package to network. Migrated ServerResponse to Kotlin and moved to network package. Setup kotlin in demo app and added global broadcast receiver.

* #450 migrated logger to Kotlin

* #450 better name for request body writer delegate method

* #450 migrated Scheme Handlers to Kotlin. It's now possible to register custom scheme handlers. Improved exception messages. Started migration of parcelable data classes to Kotlin.

* #450 moved all the configurable parameters in UploadServiceConfig. Enhanced debug log messages by printing upload service configuration, android version and processor cores

* #450 migrated UploadFile and Placeholders to Kotlin. Refactored scheme handlers names. Dropped ContentType class in favor of a String extension.

* #450 do not parcelize utility property bodyString

* #450 migrated BroadcastData in Kotlin

* #450 migrated UploadInfo to Kotlin.

* #450 Moved SchemeHandlers to UploadServiceConfig. Set default logger delegate debug log to info because some devices (e.g. Huawei ALE-L21 with Android API 22) does not display Log.d in LogCat and some vendor specific settings are needed. It's better to not deal with those.

* #450 Migrated UploadNotificationAction to Kotlin

* #450 fix cancelling uploads on Android API 26+

* #450 migrated UploadTaskParameters to Kotlin and refactored where needed

* #450 updated gradle plugin

* #450 updated Kotlin to 1.3.50. Used require to make code more readable.

* #450 migrated binary upload task to kotlin. Added http URL validator extension for strings

* #450 moved notification handling in separate listener. Removed automatic notification channel creation on Android 8+. This reduces UploadTask competences, complexity and code.

* #450 renamed package notifier to tasklistener

* #450 moved broadcast operations out of UploadTask. This further simplifies UploadTask logic and competences.

* #450 file deletion is now a competence of the scheme handler. This also solves a potential bug in FTP upload module and allows file deletion via content resolver (if supported). UploadInfo now contains full UploadFile information instead of the string path.

* #450 remove static constants in UploadTask in favor of a ServerResponse factory method

* #450 upload task now receives the notification ID as an init parameter

* #450 moved throttling logic in separate function

* #450 converted UploadTask in Kotlin

* #450 default number of retries for each request is now configurable in Retry Policy global configuration. Dropped Upload Delegate implementation.

* #450 Removed example empty UploadReceiver. BroadcastReceivers are now called RequestObservers. Log level can now be tuned based on BuildConfig.DEBUG value. Removed OkHttp call timeout. Not suitable for uploads which can run an indefinite amount of time. Started implementation of new kind of broadcast receivers. Added utility inline fun to safely perform the same action on all of the task's observers.

* #450 create new uploadInfo for each observer

* #450 http uploads now uses UTF-8 by default. removed concept of Intent from UploadTasks. Additional params are now passed directly in UploadTaskParameters. Converted UploadService to Kotlin

* #450 refactor starting upload. Reduced code in UploadService.

* #450 better log messages when instantiating new task fails

* #450 task observers are now passed as parameters in the init method. This in turn allowed to make the task independent from the upload service.

* #450 code shrinking

* #450 simplified notifying progress by sending only the bytes transferred and let the base class handle the rest

* #450 inject http stack in upload tasks. Done some renaming of http stack data types and methods to make the code more fluent to read

* #450 calculate sleep deadline only once

* #450 make HttpRequest implement the Closeable interface

* #450 use better equals

* #450 using lambda functions in logger to save performance evaluating messages which are not going to be logged. Started conversion of HttpUploadTask to Kotlin.

* #450 http stack requests auto-close on success and on error

* #450 converted MultipartUploadTask to Kotlin

* #450 code reorder

* #450 remove unnecessary annotation in Kotlin

* #450 progress listener is now passed to the BodyWriter which manages it internally. Simplified multipart upload task. Simplified notification handler.

* #450 Changed the task events lifecycle to be more Rx and LiveData-like

* #450 implemented tagging each HTTP connection with the uploadID to have better logging

* #450 refactored successfully uploaded files logic. Moved wake lock logic in extensions

* #450 removed author comments as they can be read from github, as well as some old docs

* #450 refactor sending broadcast

* #40 ported UploadNotificationConfig and UploadNotificationStatusConfig in Kotlin. Made necessary refactorings.

* #450 migrated all the request builders to Kotlin

* #450 made UploadServiceConfig, UploadServiceLogger and UploadService static methods java friendly. Migrated HttpUploadTaskParameters to Kotlin. Added extensions for multipart upload files.

* #450 migrated FTPUploadTaskParameters and UnixPermissions to Kotlin. Added Unit Tests for UnixPermissions.

* #450 moved content provider file selector in files picker activity. Moved Apache Commons FTP Code in FTPClientWrapper. Ported FTPUploadTask to Kotlin. Newer macOS doesn't have FTP server anymore, so setup a simple script to use vsftpd inside docker.
  • Loading branch information
gotev authored Sep 29, 2019
1 parent 0cb6193 commit 7b1624b
Show file tree
Hide file tree
Showing 139 changed files with 4,357 additions and 6,254 deletions.
15 changes: 0 additions & 15 deletions .idea/gradle.xml

This file was deleted.

12 changes: 0 additions & 12 deletions .idea/runConfigurations.xml

This file was deleted.

5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ android:
- tools
- platform-tools
- build-tools-28.0.3
- build-tools-29.0.2
- android-28
- android-29
- extra-google-m2repository
- extra-android-m2repository

env:
global:
- API=29 # Android API default
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ buildscript {

dependencies {
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "com.github.ben-manes:gradle-versions-plugin:$gradle_versions_plugin_version"
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven_gradle_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_plugin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
12 changes: 9 additions & 3 deletions examples/app/.idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion examples/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ buildscript {

dependencies {
classpath "com.android.tools.build:gradle:$gradle_version"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"

//classpath dependencies to import library project
classpath "com.github.ben-manes:gradle-versions-plugin:$gradle_versions_plugin_version"
classpath "com.github.dcendents:android-maven-gradle-plugin:$maven_gradle_version"
classpath "com.jfrog.bintray.gradle:gradle-bintray-plugin:$bintray_plugin_version"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
6 changes: 5 additions & 1 deletion examples/app/demoapp/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'

android {
compileSdkVersion target_sdk
Expand Down Expand Up @@ -52,6 +54,8 @@ dependencies {
implementation "androidx.appcompat:appcompat:$androidx_appcompat_version"
implementation 'com.google.android.material:material:1.0.0'

implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

// Debugging
implementation "com.facebook.stetho:stetho:${stethoVersion}"
implementation "com.facebook.stetho:stetho-okhttp3:${stethoVersion}"
Expand All @@ -62,7 +66,7 @@ dependencies {
annotationProcessor "com.jakewharton:butterknife-compiler:${butterKnifeVersion}"

implementation 'com.nononsenseapps:filepicker:4.0.0-beta1'
implementation 'net.gotev:recycleradapter:2.4.0'
implementation 'net.gotev:recycleradapter:2.8.1'

/*implementation "net.gotev:uploadservice:${libraryVersion}"
implementation "net.gotev:uploadservice-okhttp:${libraryVersion}"
Expand Down
11 changes: 2 additions & 9 deletions examples/app/demoapp/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="net.gotev.uploadservicedemo">

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<application
android:name=".App"
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
android:theme="@style/AppTheme"
android:usesCleartextTraffic="true">
<provider
android:name="androidx.core.content.FileProvider"
android:authorities="${applicationId}.provider"
Expand All @@ -21,12 +20,6 @@
android:resource="@xml/nnf_provider_paths" />
</provider>

<receiver android:name=".events.UploadReceiver" android:exported="false">
<intent-filter>
<action android:name="net.gotev.uploadservicedemo.uploadservice.broadcast.status" />
</intent-filter>
</receiver>

<receiver android:name=".events.NotificationActionsReceiver" android:exported="false">
<intent-filter>
<action android:name="net.gotev.uploadservicedemo.notification.action" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
package net.gotev.uploadservicedemo;

import android.app.Application;
import android.app.NotificationChannel;
import android.app.NotificationManager;
import android.content.Context;
import android.os.Build;
import android.os.StrictMode;
import android.util.Log;

import com.facebook.stetho.Stetho;
import com.facebook.stetho.okhttp3.StethoInterceptor;

import net.gotev.uploadservice.Logger;
import net.gotev.uploadservice.UploadService;
import net.gotev.uploadservice.UploadServiceConfig;
import net.gotev.uploadservice.data.RetryPolicyConfig;
import net.gotev.uploadservice.logger.UploadServiceLogger;
import net.gotev.uploadservice.okhttp.OkHttpStack;

import java.io.IOException;
Expand All @@ -27,6 +32,8 @@
*/
public class App extends Application {

public static String CHANNEL = "UploadServiceDemoChannel";

@Override
public void onCreate() {
super.onCreate();
Expand All @@ -43,17 +50,30 @@ public void onCreate() {

// Set your application namespace to avoid conflicts with other apps
// using this library
UploadService.NAMESPACE = BuildConfig.APPLICATION_ID;

// Set upload service debug log messages level
Logger.setLogLevel(Logger.LogLevel.DEBUG);
UploadServiceConfig.setNamespace(BuildConfig.APPLICATION_ID);

// Set up the Http Stack to use. If you omit this or comment it, HurlStack will be
// used by default
UploadService.HTTP_STACK = new OkHttpStack(getOkHttpClient());
UploadServiceConfig.setHttpStack(new OkHttpStack(getOkHttpClient()));

// setup backoff multiplier
UploadService.BACKOFF_MULTIPLIER = 2;
UploadServiceConfig.setRetryPolicy(new RetryPolicyConfig(1, 10, 2, 3));

// Set upload service debug log messages level
UploadServiceLogger.setDevelopmentMode(BuildConfig.DEBUG);

createNotificationChannel();

GlobalBroadcastReceiver receiver = new GlobalBroadcastReceiver();
receiver.register(this);
}

private void createNotificationChannel() {
if (Build.VERSION.SDK_INT >= 26) {
NotificationManager notificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
NotificationChannel channel = new NotificationChannel(CHANNEL, "Upload Service Demo", NotificationManager.IMPORTANCE_LOW);
notificationManager.createNotificationChannel(channel);
}
}

private OkHttpClient getOkHttpClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@
import android.content.Intent;
import android.graphics.Color;
import android.net.Uri;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import androidx.annotation.LayoutRes;
import androidx.annotation.StringRes;
import androidx.appcompat.app.AppCompatActivity;
import android.view.View;
import android.view.inputmethod.InputMethodManager;

import net.gotev.uploadservice.UploadNotificationAction;
import net.gotev.uploadservice.UploadNotificationConfig;
import net.gotev.uploadservice.data.UploadNotificationConfig;
import net.gotev.uploadservice.data.UploadNotificationAction;
import net.gotev.uploadservicedemo.events.NotificationActions;

import butterknife.ButterKnife;
Expand Down Expand Up @@ -42,35 +43,35 @@ protected void onPause() {
}

protected UploadNotificationConfig getNotificationConfig(final String uploadId, @StringRes int title) {
UploadNotificationConfig config = new UploadNotificationConfig();
UploadNotificationConfig config = new UploadNotificationConfig(App.CHANNEL);

PendingIntent clickIntent = PendingIntent.getActivity(
this, 1, new Intent(this, MainActivity.class), PendingIntent.FLAG_UPDATE_CURRENT);

config.setTitleForAllStatuses(getString(title))
.setRingToneEnabled(true)
.setClickIntentForAllStatuses(clickIntent)
.setClearOnActionForAllStatuses(true);
.setClearOnActionForAllStatuses(true)
.setRingToneEnabled(true);

config.getProgress().message = getString(R.string.uploading);
config.getProgress().iconResourceID = R.drawable.ic_upload;
config.getProgress().iconColorResourceID = Color.BLUE;
config.getProgress().actions.add(new UploadNotificationAction(
config.getProgress().setMessage(getString(R.string.uploading));
config.getProgress().setIconResourceID(R.drawable.ic_upload);
config.getProgress().setIconColorResourceID(Color.BLUE);
config.getProgress().getActions().add(new UploadNotificationAction(
R.drawable.ic_cancelled,
getString(R.string.cancel_upload),
NotificationActions.getCancelUploadAction(this, 1, uploadId)));

config.getCompleted().message = getString(R.string.upload_success);
config.getCompleted().iconResourceID = R.drawable.ic_upload_success;
config.getCompleted().iconColorResourceID = Color.GREEN;
config.getCompleted().setMessage(getString(R.string.upload_success));
config.getCompleted().setIconResourceID(R.drawable.ic_upload_success);
config.getCompleted().setIconColorResourceID(Color.GREEN);

config.getError().message = getString(R.string.upload_error);
config.getError().iconResourceID = R.drawable.ic_upload_error;
config.getError().iconColorResourceID = Color.RED;
config.getError().setMessage(getString(R.string.upload_error));
config.getError().setIconResourceID(R.drawable.ic_upload_error);
config.getError().setIconColorResourceID(Color.RED);

config.getCancelled().message = getString(R.string.upload_cancelled);
config.getCancelled().iconResourceID = R.drawable.ic_cancelled;
config.getCancelled().iconColorResourceID = Color.YELLOW;
config.getCancelled().setMessage(getString(R.string.upload_cancelled));
config.getCancelled().setIconResourceID(R.drawable.ic_cancelled);
config.getCancelled().setIconColorResourceID(Color.YELLOW);

return config;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,13 @@

import android.content.Intent;
import android.os.Bundle;
import androidx.annotation.Nullable;
import android.view.View;
import android.widget.Toast;

import androidx.annotation.Nullable;

import net.gotev.recycleradapter.AdapterItem;
import net.gotev.uploadservice.BinaryUploadRequest;
import net.gotev.uploadservice.protocols.binary.BinaryUploadRequest;
import net.gotev.uploadservicedemo.adapteritems.EmptyItem;
import net.gotev.uploadservicedemo.adapteritems.UploadItem;
import net.gotev.uploadservicedemo.utils.UploadItemUtils;
Expand Down Expand Up @@ -41,7 +42,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void onAddFile() {
fileParameterName = "file";
openFilePicker(false);
//openFilePicker(false);
performFileSearch();
}

@Override
Expand All @@ -50,7 +52,8 @@ public void onDone(String httpMethod, String serverUrl, UploadItemUtils uploadIt
try {
final String uploadId = UUID.randomUUID().toString();

final BinaryUploadRequest request = new BinaryUploadRequest(this, uploadId, serverUrl)
final BinaryUploadRequest request = new BinaryUploadRequest(this, serverUrl)
.setUploadID(uploadId)
.setMethod(httpMethod)
.setNotificationConfig(getNotificationConfig(uploadId, R.string.binary_upload))
//.setCustomUserAgent(getUserAgent())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,13 @@
import android.widget.EditText;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.core.app.NavUtils;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import net.gotev.recycleradapter.RecyclerAdapter;
import net.gotev.uploadservice.ftp.FTPUploadRequest;
import net.gotev.uploadservice.ftp.UnixPermissions;
import net.gotev.uploadservicedemo.adapteritems.EmptyItem;
import net.gotev.uploadservicedemo.adapteritems.UploadItem;
import net.gotev.uploadservicedemo.dialogs.AddFileParameterNameDialog;
Expand All @@ -21,10 +25,6 @@
import java.util.List;
import java.util.UUID;

import androidx.annotation.Nullable;
import androidx.core.app.NavUtils;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import butterknife.BindView;
import butterknife.OnClick;

Expand Down Expand Up @@ -83,7 +83,8 @@ protected void onCreate(@Nullable Bundle savedInstanceState) {
@Override
public void onValue(String value) {
remotePath = value;
openFilePicker(false);
//openFilePicker(false);
performFileSearch();
}
});
}
Expand Down Expand Up @@ -154,11 +155,12 @@ public void onDone() {
try {
final String uploadId = UUID.randomUUID().toString();

final FTPUploadRequest request = new FTPUploadRequest(this, uploadId, serverUrl.getText().toString(), ftpPort)
final FTPUploadRequest request = new FTPUploadRequest(this, serverUrl.getText().toString(), ftpPort)
.setUploadID(uploadId)
.setMaxRetries(UploadActivity.MAX_RETRIES)
.setNotificationConfig(getNotificationConfig(uploadId, R.string.ftp_upload))
.setUsernameAndPassword(ftpUsername.getText().toString(), ftpPassword.getText().toString())
.setCreatedDirectoriesPermissions(new UnixPermissions("777"))
//.setCreatedDirectoriesPermissions(new UnixPermissions("777"))
.setSocketTimeout(5000)
.setConnectTimeout(5000);

Expand Down
Loading

0 comments on commit 7b1624b

Please sign in to comment.