Skip to content

Commit

Permalink
Activate google-java-format & CI (fluttercommunity#20)
Browse files Browse the repository at this point in the history
* Initial Cirrus CI configuration.

* Format MainActivity

* Correct .cirrus.yml formatting.

* Cleanup .gitignore.

* remove IDE files

* Simplify CI script - only format & analyze for the moment.

* Let the format.sh script output the expected format.

* Use the google-java-format plugin to reformat all Java files.

* Fix import formatting

* More helpful formatter script.
  • Loading branch information
ened authored and onikiri2007 committed Oct 9, 2019
1 parent fbf8393 commit ca004cf
Show file tree
Hide file tree
Showing 16 changed files with 165 additions and 233 deletions.
9 changes: 9 additions & 0 deletions .ci/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM cirrusci/flutter:stable

RUN yes | sdkmanager \
"platforms;android-27" \
"build-tools;27.0.3" \
"extras;google;m2repository" \
"extras;android;m2repository"

RUN yes | sdkmanager --licenses
24 changes: 24 additions & 0 deletions .cirrus.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
task:
container:
dockerfile: .ci/Dockerfile
cpu: 8
memory: 16G
# upgrade_script:
# - flutter channel master
# - flutter upgrade
# - git fetch origin master
# activate_script: pub global activate flutter_plugin_tools
matrix:
- name: test+format
# install_script:
# - wget -O - https://apt.llvm.org/llvm-snapshot.gpg.key | sudo apt-key add -
# - sudo apt-add-repository "deb http://apt.llvm.org/xenial/ llvm-toolchain-xenial-7 main"
# - sudo apt-get update
# - sudo apt-get install -y --allow-unauthenticated clang-format-7
format_script: script/format.sh
- name: analyze
script:
- pub global activate tuneup
- flutter packages get
- pub global run tuneup check

42 changes: 36 additions & 6 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,13 +1,43 @@
.DS_Store
.dart_tool/
.atom/
.idea/
.vscode/

.packages
.pub/
.dart_tool/
pubspec.lock
flutter_export_environment.sh

build/

node_modules/
examples/all_plugins/pubspec.yaml

pubspec.lock
Podfile
Podfile.lock
.firebaserc
Pods/
.symlinks/
**/Flutter/App.framework/
**/Flutter/Flutter.framework/
**/Flutter/Generated.xcconfig
**/Flutter/flutter_assets/
ServiceDefinitions.json
xcuserdata/
*.xcworkspace
**/DerivedData/

local.properties
keystore.properties
.gradle/
gradlew
gradlew.bat
gradle-wrapper.jar
*.iml

GeneratedPluginRegistrant.h
GeneratedPluginRegistrant.m
GeneratedPluginRegistrant.java
build/
.flutter-plugins

.project
.classpath
.settings
19 changes: 0 additions & 19 deletions .idea/libraries/Dart_SDK.xml

This file was deleted.

9 changes: 0 additions & 9 deletions .idea/libraries/Flutter_for_Android.xml

This file was deleted.

10 changes: 0 additions & 10 deletions .idea/modules.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/runConfigurations/example_lib_main_dart.xml

This file was deleted.

45 changes: 0 additions & 45 deletions .idea/workspace.xml

This file was deleted.

13 changes: 0 additions & 13 deletions .vscode/launch.json

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
import android.app.Activity;
import android.app.Application;
import android.os.Bundle;
import android.util.Log;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.lifecycle.Observer;
Expand All @@ -18,13 +16,11 @@
import androidx.work.WorkRequest;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;

import io.flutter.plugin.common.MethodCall;
import io.flutter.plugin.common.MethodChannel;
import io.flutter.plugin.common.MethodChannel.MethodCallHandler;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry.Registrar;

import java.lang.ref.WeakReference;
import java.lang.reflect.Type;
import java.util.ArrayList;
Expand Down Expand Up @@ -91,8 +87,7 @@ public void onChanged(UploadProgress uploadProgress) {
}
}

@Nullable
private UploadProgressObserver uploadProgressObserver;
@Nullable private UploadProgressObserver uploadProgressObserver;

static class UploadCompletedObserver implements Observer<List<WorkInfo>> {
private final WeakReference<FlutterUploaderPlugin> plugin;
Expand All @@ -119,28 +114,24 @@ public void onChanged(List<WorkInfo> workInfoList) {
switch (info.getState()) {
case FAILED:
int failedStatus =
outputData.getInt(UploadWorker.EXTRA_STATUS, UploadStatus.FAILED);
int statusCode =
outputData.getInt(UploadWorker.EXTRA_STATUS_CODE, 500);
outputData.getInt(UploadWorker.EXTRA_STATUS, UploadStatus.FAILED);
int statusCode = outputData.getInt(UploadWorker.EXTRA_STATUS_CODE, 500);
String code = outputData.getString(UploadWorker.EXTRA_ERROR_CODE);
String errorMessage =
outputData.getString(UploadWorker.EXTRA_ERROR_MESSAGE);
String[] details =
outputData.getStringArray(UploadWorker.EXTRA_ERROR_DETAILS);
String errorMessage = outputData.getString(UploadWorker.EXTRA_ERROR_MESSAGE);
String[] details = outputData.getStringArray(UploadWorker.EXTRA_ERROR_DETAILS);
plugin.sendFailed(id, failedStatus, statusCode, code, errorMessage, details);
break;
case CANCELLED:
plugin.sendFailed(
id,
UploadStatus.CANCELED,
500,
"flutter_upload_cancelled",
"upload has been cancelled",
null);
id,
UploadStatus.CANCELED,
500,
"flutter_upload_cancelled",
"upload has been cancelled",
null);
break;
case SUCCEEDED:
int status =
outputData.getInt(UploadWorker.EXTRA_STATUS, UploadStatus.COMPLETE);
int status = outputData.getInt(UploadWorker.EXTRA_STATUS, UploadStatus.COMPLETE);
Map<String, String> headers = null;
Type type = new TypeToken<Map<String, String>>() {}.getType();
String headerJson = info.getOutputData().getString(UploadWorker.EXTRA_HEADERS);
Expand All @@ -158,8 +149,7 @@ public void onChanged(List<WorkInfo> workInfoList) {
}
}

@Nullable
private UploadCompletedObserver uploadCompletedObserver;
@Nullable private UploadCompletedObserver uploadCompletedObserver;

@Override
public void onMethodCall(MethodCall call, @NonNull Result result) {
Expand All @@ -186,8 +176,7 @@ public void onActivityCreated(Activity activity, Bundle savedInstanceState) {}
public void onActivityStarted(Activity activity) {
if (activity == register.activity()) {
uploadProgressObserver = new UploadProgressObserver(this);
UploadProgressReporter.getInstance()
.observeForever(uploadProgressObserver);
UploadProgressReporter.getInstance().observeForever(uploadProgressObserver);

uploadCompletedObserver = new UploadCompletedObserver(this);
WorkManager.getInstance(register.context())
Expand All @@ -210,8 +199,10 @@ public void onActivityStopped(Activity activity) {
uploadProgressObserver = null;
}

if(uploadCompletedObserver != null) {
WorkManager.getInstance(register.context()).getWorkInfosByTagLiveData(TAG).removeObserver(uploadCompletedObserver);
if (uploadCompletedObserver != null) {
WorkManager.getInstance(register.context())
.getWorkInfosByTagLiveData(TAG)
.removeObserver(uploadCompletedObserver);
uploadCompletedObserver = null;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,25 @@

public class UploadProgress {

private String _taskId;
private int _status;
private int _progress;


public UploadProgress(String taskId, int status, int progress) {
this._taskId = taskId;
this._status = status;
this._progress = progress;
}

public int getProgress() {
return _progress;
}

public int getStatus() {
return _status;
}

public String getTaskId() {
return _taskId;
}


private String _taskId;
private int _status;
private int _progress;

public UploadProgress(String taskId, int status, int progress) {
this._taskId = taskId;
this._status = status;
this._progress = progress;
}

public int getProgress() {
return _progress;
}

public int getStatus() {
return _status;
}

public String getTaskId() {
return _taskId;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,17 @@
import androidx.lifecycle.LiveData;

public class UploadProgressReporter extends LiveData<UploadProgress> {
private static UploadProgressReporter _instance;
private static UploadProgressReporter _instance;


@MainThread
public static UploadProgressReporter getInstance() {
if (_instance == null) {
_instance = new UploadProgressReporter();
}
return _instance;

}

void notifyProgress(UploadProgress progress) {
postValue(progress);
@MainThread
public static UploadProgressReporter getInstance() {
if (_instance == null) {
_instance = new UploadProgressReporter();
}
return _instance;
}

void notifyProgress(UploadProgress progress) {
postValue(progress);
}
}
Loading

0 comments on commit ca004cf

Please sign in to comment.