Skip to content

Commit

Permalink
Added upload and download functionality
Browse files Browse the repository at this point in the history
Add folder traversal
Improved stability
  • Loading branch information
SG-O committed Aug 16, 2022
1 parent 81976f9 commit b6ccbc1
Show file tree
Hide file tree
Showing 44 changed files with 841 additions and 81 deletions.
7 changes: 5 additions & 2 deletions .idea/misc.xml

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

6 changes: 3 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
applicationId "de.sg_o.app.photonet"
minSdkVersion 24
targetSdkVersion 33
versionCode 1
versionName '0.1'
versionCode 2
versionName '0.2'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
multiDexEnabled false
Expand Down Expand Up @@ -79,7 +79,7 @@ android {
}

dependencies {
implementation 'de.sg-o.lib:photoNet:0.8'
implementation 'de.sg-o.lib:photoNet:0.9'
implementation "androidx.swiperefreshlayout:swiperefreshlayout:1.1.0"
implementation 'androidx.appcompat:appcompat:1.5.0'
implementation 'com.google.android.material:material:1.6.1'
Expand Down
11 changes: 11 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
android:maxSdkVersion="28" />
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
<uses-permission android:name="android.permission.WAKE_LOCK" />

<application
android:allowBackup="true"
Expand Down Expand Up @@ -63,6 +68,12 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<service android:name=".filetransfer.TransferService" />
<receiver
android:name = ".filetransfer.TransferNotificationActionReceiver"
android:enabled = "true"
android:exported = "true" >
</receiver>
</application>

</manifest>
38 changes: 37 additions & 1 deletion app/src/main/java/de/sg_o/app/photonet/DetailsActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@

package de.sg_o.app.photonet;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;

import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;
Expand All @@ -28,9 +31,16 @@

import com.google.android.material.tabs.TabLayout;

import de.sg_o.app.photonet.ui.main.SectionsPagerAdapter;
import java.io.FileNotFoundException;
import java.io.OutputStream;

import de.sg_o.app.photonet.filetransfer.TransferService;
import de.sg_o.app.photonet.filetransfer.TransferWorker;
import de.sg_o.app.photonet.menu.SectionsPagerAdapter;
import de.sg_o.lib.photoNet.netData.FileListItem;

public class DetailsActivity extends AppCompatActivity {
public static FileListItem toDownload = null;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -55,4 +65,30 @@ protected void onCreate(Bundle savedInstanceState) {
tabs.setupWithViewPager(viewPager);

}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent resultData) {
super.onActivityResult(requestCode, resultCode, resultData);
Uri uri;
if (requestCode == 1 && resultCode == Activity.RESULT_OK) {
if (resultData != null) {
uri = resultData.getData();
writeFileContent(uri);
}
}
}

private void writeFileContent(Uri uri)
{
if (toDownload == null) return;
FileListItem tmp = toDownload;
toDownload = null;
try {
ParcelFileDescriptor pfd = getContentResolver().openFileDescriptor(uri, "w");
OutputStream fileOutputStream = new ParcelFileDescriptor.AutoCloseOutputStream(pfd);
TransferWorker.addTransfer(tmp.getDownload(fileOutputStream, 2));
TransferService.startService(this);
} catch (FileNotFoundException ignore) {
}
}
}
2 changes: 2 additions & 0 deletions app/src/main/java/de/sg_o/app/photonet/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
import com.google.android.material.floatingactionbutton.FloatingActionButton;

import de.sg_o.app.photonet.menu.PrintersAdapter;
import de.sg_o.app.photonet.ui.main.DiscoveryDialogFragment;
import de.sg_o.app.photonet.ui.main.PrinterEditDialogFragment;
import de.sg_o.lib.photoNet.manager.Environment;
import de.sg_o.lib.photoNet.printer.Printer;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
/*
*
* Copyright (C) 2022 Joerg Bayer (SG-O)
*
* 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
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* 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.
*
*/

package de.sg_o.app.photonet.filetransfer;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

import androidx.core.content.ContextCompat;

public class TransferNotificationActionReceiver extends BroadcastReceiver {
public static final String PAUSE_ACTION = "pause";
public static final String RESUME_ACTION = "resume";
public static final String STOP_ACTION = "stop";
public static final String RETRY_ACTION = "retry";
public static final String IGNORE_ACTION = "ignore";

@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
Intent forward = new Intent(context, TransferService.class);
forward.setAction(action);
ContextCompat.startForegroundService(context, forward);
}
}
Loading

0 comments on commit b6ccbc1

Please sign in to comment.