Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add automatic code formatting to pull requests #54

Merged
merged 2 commits into from
May 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
33 changes: 33 additions & 0 deletions .github/workflows/reformat.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
name: Re-format Code

on:
pull_request:
branches:
- main

jobs:
format:
runs-on: ubuntu-latest

steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.ref }}

- name: Install IntelliJ IDEA
run: |
wget -q -O idea.tar.gz https://download.jetbrains.com/idea/ideaIC-2024.1.1.tar.gz
tar -xzf idea.tar.gz

- name: Format code
run: |
./*/bin/format.sh -m *.java -r .

- name: Commit changes
run: |
git config user.name 'github-actions[bot]'
git config user.email "github-actions[bot]@users.noreply.github.com"
git commit -a -m "Auto-format code"
git push

32 changes: 32 additions & 0 deletions .idea/codeStyles/Project.xml

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

5 changes: 5 additions & 0 deletions .idea/codeStyles/codeStyleConfig.xml

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

Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import androidx.core.app.ActivityCompat;
import androidx.fragment.app.Fragment;


/**
* A simple {@link Fragment} subclass.
* Use the {@link FileChooserFragment #newInstance} factory method to
Expand All @@ -32,7 +31,8 @@ public class FileChooserFragment extends Fragment {
private EditText editTextPath;

@Override
public View onCreateView(final LayoutInflater inflater, final ViewGroup container, final Bundle savedInstanceState) {
public View onCreateView(final LayoutInflater inflater, final ViewGroup container,
final Bundle savedInstanceState) {

View rootView = inflater.inflate(R.layout.fragment_file_chooser, container, false);

Expand All @@ -56,15 +56,13 @@ private void askPermissionAndBrowseFile() {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.M) { // Level 23

// Check if we have Call permission
int permisson = ActivityCompat.checkSelfPermission(this.getContext(),
Manifest.permission.READ_EXTERNAL_STORAGE);
int permisson =
ActivityCompat.checkSelfPermission(this.getContext(), Manifest.permission.READ_EXTERNAL_STORAGE);

if (permisson != PackageManager.PERMISSION_GRANTED) {
// If don't have permission so prompt the user.
this.requestPermissions(
new String[]{Manifest.permission.READ_EXTERNAL_STORAGE},
MY_REQUEST_CODE_PERMISSION
);
this.requestPermissions(new String[] { Manifest.permission.READ_EXTERNAL_STORAGE },
MY_REQUEST_CODE_PERMISSION);
return;
}
}
Expand All @@ -83,8 +81,7 @@ private void doBrowseFile() {

// When you have the request results
@Override
public void onRequestPermissionsResult(int requestCode,
String[] permissions, int[] grantResults) {
public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {

super.onRequestPermissionsResult(requestCode, permissions, grantResults);
//
Expand All @@ -93,8 +90,7 @@ public void onRequestPermissionsResult(int requestCode,

// Note: If request is cancelled, the result arrays are empty.
// Permissions granted (CALL_PHONE).
if (grantResults.length > 0
&& grantResults[0] == PackageManager.PERMISSION_GRANTED) {
if (grantResults.length > 0 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {

Log.i(LOG_TAG, "Permission granted!");
Toast.makeText(this.getContext(), "Permission granted!", Toast.LENGTH_SHORT).show();
Expand All @@ -111,7 +107,6 @@ public void onRequestPermissionsResult(int requestCode,
}
}


@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
switch (requestCode) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,18 @@ class FileUploadObserver implements StreamObserver<FileUploadResponse> {

@Override
public void onNext(FileUploadResponse fileUploadResponse) {
Log.d("grpcDebug","File upload status :: " + fileUploadResponse.getStatus());
Log.d("grpcDebug", "File upload status :: " + fileUploadResponse.getStatus());
}

@Override
public void onError(Throwable throwable) {
Log.d("grpcDebug","ERROR :: " + throwable.toString());
Log.d("grpcDebug", "ERROR :: " + throwable.toString());
}

@Override
public void onCompleted() {
Date current = Calendar.getInstance().getTime();
Log.d("grpcDebug","Started file transfer ended at: "+ current.toString());
Log.d("grpcDebug", "Started file transfer ended at: " + current.toString());
}

}
40 changes: 17 additions & 23 deletions BundleClient/app/src/main/java/com/ddd/bundleclient/FileUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import android.provider.OpenableColumns;
import android.text.TextUtils;
import android.util.Log;

import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStream;
Expand Down Expand Up @@ -62,10 +63,12 @@ else if (isDownloadsDocument(uri)) {
final String id;
Cursor cursor = null;
try {
cursor = context.getContentResolver().query(uri, new String[]{MediaStore.MediaColumns.DISPLAY_NAME}, null, null, null);
cursor = context.getContentResolver()
.query(uri, new String[] { MediaStore.MediaColumns.DISPLAY_NAME }, null, null, null);
if (cursor != null && cursor.moveToFirst()) {
String fileName = cursor.getString(0);
String path = Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
String path =
Environment.getExternalStorageDirectory().toString() + "/Download/" + fileName;
if (!TextUtils.isEmpty(path)) {
return path;
}
Expand All @@ -80,13 +83,12 @@ else if (isDownloadsDocument(uri)) {
if (id.startsWith("raw:")) {
return id.replaceFirst("raw:", "");
}
String[] contentUriPrefixesToTry = new String[] {
"content://downloads/public_downloads",
"content://downloads/my_downloads"
};
String[] contentUriPrefixesToTry = new String[] { "content://downloads/public_downloads",
"content://downloads/my_downloads" };
for (String contentUriPrefix : contentUriPrefixesToTry) {
try {
final Uri contentUri = ContentUris.withAppendedId(Uri.parse(contentUriPrefix), Long.valueOf(id));
final Uri contentUri =
ContentUris.withAppendedId(Uri.parse(contentUriPrefix), Long.valueOf(id));

// final Uri contentUri = ContentUris.withAppendedId(
// Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
Expand All @@ -105,8 +107,8 @@ else if (isDownloadsDocument(uri)) {
return id.replaceFirst("raw:", "");
}
try {
contentUri = ContentUris.withAppendedId(
Uri.parse("content://downloads/public_downloads"), Long.valueOf(id));
contentUri = ContentUris.withAppendedId(Uri.parse("content://downloads/public_downloads"),
Long.valueOf(id));

} catch (NumberFormatException e) {
e.printStackTrace();
Expand All @@ -132,16 +134,14 @@ else if (isMediaDocument(uri)) {
contentUri = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
}
selection = "_id=?";
selectionArgs = new String[]{split[1]};
selectionArgs = new String[] { split[1] };

return getDataColumn(context, contentUri, selection,
selectionArgs);
return getDataColumn(context, contentUri, selection, selectionArgs);
} else if (isGoogleDriveUri(uri)) {
return getDriveFilePath(uri, context);
}
}


// MediaStore (and general)
else if ("content".equalsIgnoreCase(uri.getScheme())) {

Expand All @@ -152,7 +152,7 @@ else if ("content".equalsIgnoreCase(uri.getScheme())) {
if (isGoogleDriveUri(uri)) {
return getDriveFilePath(uri, context);
}
if( Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
if (Build.VERSION.SDK_INT == Build.VERSION_CODES.N) {
// return getFilePathFromURI(context,uri);
return getMediaFilePathForN(uri, context);
// return getRealPathFromURI(context,uri);
Expand All @@ -178,7 +178,6 @@ private static boolean fileExists(String filePath) {
return file.exists();
}


/**
* Get full file path from external storage
*
Expand Down Expand Up @@ -298,16 +297,13 @@ private static String getMediaFilePathForN(Uri uri, Context context) {
return file.getPath();
}


private static String getDataColumn(Context context, Uri uri,
String selection, String[] selectionArgs) {
private static String getDataColumn(Context context, Uri uri, String selection, String[] selectionArgs) {
Cursor cursor = null;
final String column = "_data";
final String[] projection = {column};
final String[] projection = { column };

try {
cursor = context.getContentResolver().query(uri, projection,
selection, selectionArgs, null);
cursor = context.getContentResolver().query(uri, projection, selection, selectionArgs, null);

if (cursor != null && cursor.moveToFirst()) {
final int index = cursor.getColumnIndexOrThrow(column);
Expand Down Expand Up @@ -353,7 +349,6 @@ private static boolean isGooglePhotosUri(Uri uri) {
return "com.google.android.apps.photos.content".equals(uri.getAuthority());
}


/**
* @param uri The Uri to check.
* @return Whether the Uri authority is Google Drive.
Expand All @@ -363,5 +358,4 @@ private static boolean isGoogleDriveUri(Uri uri) {
|| "com.google.android.apps.docs.storage.legacy".equals(uri.getAuthority());
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ class GrpcReceiveTask {
String currentTransportId;
private final Activity activity;


GrpcReceiveTask(Activity activity) {
this.activityReference = new WeakReference<Activity>(activity);
this.resultText = (TextView) activity.findViewById(R.id.grpc_response_text);
Expand Down Expand Up @@ -67,7 +66,8 @@ private void inBackground(String... params) throws Exception {
try {
BundleTransmission bundleTransmission;
bundleTransmission = new BundleTransmission(applicationContext.getApplicationInfo().dataDir);
bundleRequests = HelloworldActivity.clientWindow.getWindow(bundleTransmission.getBundleSecurity().getClientSecurity());
bundleRequests = HelloworldActivity.clientWindow.getWindow(
bundleTransmission.getBundleSecurity().getClientSecurity());
} catch (SecurityExceptions.BundleIDCryptographyException e) {
Log.d(HelloworldActivity.TAG, "{BR}: Failed to get Window: " + e);
e.printStackTrace();
Expand All @@ -84,9 +84,7 @@ private void inBackground(String... params) throws Exception {
}
for (String bundle : bundleRequests) {
String bundleName = bundle + ".bundle";
ReqFilePath request = ReqFilePath.newBuilder()
.setValue(bundleName)
.build();
ReqFilePath request = ReqFilePath.newBuilder().setValue(bundleName).build();
Log.d(HelloworldActivity.TAG, "Downloading file: " + bundleName);
StreamObserver<Bytes> downloadObserver = new StreamObserver<Bytes>() {
FileOutputStream fileOutputStream = null;
Expand All @@ -103,6 +101,7 @@ public void onNext(Bytes fileContent) {
onError(e);
}
}

@Override
public void onError(Throwable t) {
Log.d(HelloworldActivity.TAG, "Error downloading file: " + t.getMessage(), t);
Expand All @@ -114,6 +113,7 @@ public void onError(Throwable t) {
}
}
}

@Override
public void onCompleted() {
try {
Expand All @@ -130,6 +130,7 @@ public void onCompleted() {
}
postExecute("Complete");
}

public void shutdownExecutor() {
executor.shutdown();
}
Expand All @@ -153,12 +154,10 @@ protected void postExecute(String result) {
GrpcSendTask sendTask = new GrpcSendTask(activity);
sendTask.executeInBackground("192.168.49.1", "1778");


String FILE_PATH = applicationContext.getApplicationInfo().dataDir + "/Shared/received-bundles";
BundleTransmission bundleTransmission = new BundleTransmission(applicationContext.getApplicationInfo().dataDir);
bundleTransmission.processReceivedBundles(currentTransportId, FILE_PATH);


Activity activity = activityReference.get();
if (activity == null) {
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import io.grpc.stub.StreamObserver;

class GrpcSendTask {
// private final HelloworldActivity helloworldActivity;
// private final HelloworldActivity helloworldActivity;
private final WeakReference<Activity> activityReference;
private ManagedChannel channel;
private final ExecutorService executor = Executors.newSingleThreadExecutor();
Expand Down Expand Up @@ -64,10 +64,7 @@ private void inBackground(String... params) throws Exception {
BundleDTO toSend = bundleTransmission.generateBundleForTransmission();
System.out.println("[BDA] An outbound bundle generated with id: " + toSend.getBundleId());
FileUploadRequest metadata = FileUploadRequest.newBuilder()
.setMetadata(MetaData.newBuilder()
.setName(toSend.getBundleId())
.setType("bundle").build())
.build();
.setMetadata(MetaData.newBuilder().setName(toSend.getBundleId()).setType("bundle").build()).build();
streamObserver.onNext(metadata);

// upload file as chunk
Expand All @@ -81,8 +78,7 @@ private void inBackground(String... params) throws Exception {
int size = 0;
while ((size = inputStream.read(bytes)) != -1) {
FileUploadRequest uploadRequest = FileUploadRequest.newBuilder()
.setFile(File.newBuilder().setContent(ByteString.copyFrom(bytes, 0, size)).build())
.build();
.setFile(File.newBuilder().setContent(ByteString.copyFrom(bytes, 0, size)).build()).build();
streamObserver.onNext(uploadRequest);
}
inputStream.close();
Expand Down
Loading