Compare commits
No commits in common. "master" and "foregroundService" have entirely different histories.
master
...
foreground
@ -227,7 +227,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
public static final int REQUEST_ID_READ_EXTERNAL_STORAGE = 2001;
|
public static final int REQUEST_ID_READ_EXTERNAL_STORAGE = 2001;
|
||||||
|
|
||||||
private boolean checkAndRequestPermissions() {
|
private boolean checkAndRequestPermissions() {
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(
|
if (ContextCompat.checkSelfPermission(
|
||||||
this, Manifest.permission.READ_EXTERNAL_STORAGE) ==
|
this, Manifest.permission.READ_EXTERNAL_STORAGE) ==
|
||||||
|
@ -1,10 +1,8 @@
|
|||||||
package com.localtransfer;
|
package com.localtransfer;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.app.Activity;
|
import android.app.Activity;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
@ -12,8 +10,6 @@ import android.view.MenuItem;
|
|||||||
|
|
||||||
import androidx.appcompat.app.ActionBar;
|
import androidx.appcompat.app.ActionBar;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
@ -53,22 +49,14 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
SwitchPreference shared;
|
SwitchPreference shared;
|
||||||
shared = findPreference("use_shared_storage");
|
shared = findPreference("use_shared_storage");
|
||||||
if(shared.isChecked()) {
|
if(shared.isChecked())
|
||||||
if(checkAndRequestPermissions())
|
directory.setVisible(true);
|
||||||
directory.setVisible(true);
|
|
||||||
else
|
|
||||||
shared.setChecked(false);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
directory.setVisible(false);
|
directory.setVisible(false);
|
||||||
|
|
||||||
shared.setOnPreferenceClickListener(preference -> {
|
shared.setOnPreferenceClickListener(preference -> {
|
||||||
if(shared.isChecked()) {
|
if(shared.isChecked())
|
||||||
if(checkAndRequestPermissions())
|
directory.setVisible(true);
|
||||||
directory.setVisible(true);
|
|
||||||
else
|
|
||||||
shared.setChecked(false);
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
directory.setVisible(false);
|
directory.setVisible(false);
|
||||||
return false;
|
return false;
|
||||||
@ -83,35 +71,6 @@ public class SettingsActivity extends AppCompatActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean checkAndRequestPermissions() {
|
|
||||||
|
|
||||||
if (ContextCompat.checkSelfPermission(
|
|
||||||
getActivity(), Manifest.permission.READ_EXTERNAL_STORAGE) ==
|
|
||||||
PackageManager.PERMISSION_GRANTED) {
|
|
||||||
Log.d("READ_EXTERNAL_STORAGE", "already granted");
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
ActivityCompat.requestPermissions(getActivity(), new String[] {android.Manifest.permission.READ_EXTERNAL_STORAGE}, MainActivity.REQUEST_ID_READ_EXTERNAL_STORAGE);
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
@Override
|
|
||||||
public void onRequestPermissionsResult(int requestCode,
|
|
||||||
String permissions[],
|
|
||||||
int[] grantResults) {
|
|
||||||
switch (requestCode) {
|
|
||||||
case MainActivity.REQUEST_ID_READ_EXTERNAL_STORAGE:
|
|
||||||
if (grantResults.length > 0 &&
|
|
||||||
grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
Log.d("READ_EXTERNAL_STORAGE", "granted");
|
|
||||||
} else {
|
|
||||||
Log.d("READ_EXTERNAL_STORAGE", "No granted");
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||||
super.onActivityResult(requestCode, resultCode, data);
|
super.onActivityResult(requestCode, resultCode, data);
|
||||||
|
@ -28,8 +28,6 @@ public class UploadFile extends Transfer {
|
|||||||
|
|
||||||
public Uri uri;
|
public Uri uri;
|
||||||
|
|
||||||
public String type;
|
|
||||||
|
|
||||||
public UploadFile() {
|
public UploadFile() {
|
||||||
this.id = View.generateViewId();
|
this.id = View.generateViewId();
|
||||||
instances.add(this);
|
instances.add(this);
|
||||||
@ -46,19 +44,9 @@ public class UploadFile extends Transfer {
|
|||||||
Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
|
Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
|
||||||
file.type = activity.getContentResolver().getType(uri);
|
file.name = cursor.getString(cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME));
|
||||||
|
file.size = cursor.getLong(cursor.getColumnIndex(OpenableColumns.SIZE));
|
||||||
int col_name = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
file.sizeSI = Transfer.humanReadableByteCountBin(file.size);
|
||||||
if (col_name != -1)
|
|
||||||
file.name = cursor.getString(col_name);
|
|
||||||
if(file.name == null)
|
|
||||||
file.name = file.type.split("/")[0] + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + "." + file.type.split("/")[1];
|
|
||||||
|
|
||||||
int col_size = cursor.getColumnIndex(OpenableColumns.SIZE);
|
|
||||||
if (col_name != -1) {
|
|
||||||
file.size = cursor.getLong(col_size);
|
|
||||||
file.sizeSI = Transfer.humanReadableByteCountBin(file.size);
|
|
||||||
}
|
|
||||||
|
|
||||||
file.AddTransfer();
|
file.AddTransfer();
|
||||||
}
|
}
|
||||||
@ -128,7 +116,15 @@ public class UploadFile extends Transfer {
|
|||||||
Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
|
Cursor cursor = activity.getContentResolver().query(uri, null, null, null, null);
|
||||||
cursor.moveToFirst();
|
cursor.moveToFirst();
|
||||||
|
|
||||||
String fileNameUTF8 = new String(name.getBytes(), StandardCharsets.ISO_8859_1);
|
String type = activity.getContentResolver().getType(uri);
|
||||||
|
|
||||||
|
String fileName = null;
|
||||||
|
int col_name = cursor.getColumnIndex(OpenableColumns.DISPLAY_NAME);
|
||||||
|
if (col_name != -1)
|
||||||
|
fileName = cursor.getString(col_name);
|
||||||
|
if(fileName == null)
|
||||||
|
fileName = type.split("/")[0] + "_" + new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()) + "." + type.split("/")[1];
|
||||||
|
String fileNameUTF8 = new String(fileName.getBytes(), StandardCharsets.ISO_8859_1);
|
||||||
|
|
||||||
url = new URL(protocol, host, port, root + "/upload.php");
|
url = new URL(protocol, host, port, root + "/upload.php");
|
||||||
|
|
||||||
@ -156,7 +152,6 @@ public class UploadFile extends Transfer {
|
|||||||
InputStream in = activity.getContentResolver().openInputStream(uri);
|
InputStream in = activity.getContentResolver().openInputStream(uri);
|
||||||
|
|
||||||
size = in.available();
|
size = in.available();
|
||||||
sizeSI = Transfer.humanReadableByteCountBin(size);
|
|
||||||
|
|
||||||
while ((bufferLength = in.read(buffer)) > 0) {
|
while ((bufferLength = in.read(buffer)) > 0) {
|
||||||
request.write(buffer, 0, bufferLength);
|
request.write(buffer, 0, bufferLength);
|
||||||
@ -173,7 +168,7 @@ public class UploadFile extends Transfer {
|
|||||||
int responseCode = conn.getResponseCode();
|
int responseCode = conn.getResponseCode();
|
||||||
|
|
||||||
if (responseCode == HttpURLConnection.HTTP_OK) {
|
if (responseCode == HttpURLConnection.HTTP_OK) {
|
||||||
message = "File " + name + " successful upload";
|
message = "File " + fileName + " successful upload";
|
||||||
state = Transfer.STATE_SUCCESS;
|
state = Transfer.STATE_SUCCESS;
|
||||||
progressEnd();
|
progressEnd();
|
||||||
}
|
}
|
||||||
|
@ -300,7 +300,7 @@ public class DownloadFragment extends Fragment {
|
|||||||
|
|
||||||
DownloadFile dl = (DownloadFile) DownloadFile.getFileById(id);
|
DownloadFile dl = (DownloadFile) DownloadFile.getFileById(id);
|
||||||
|
|
||||||
if(dl.mime.equals("text/plain")) {
|
if(dl.type.equals("text/plain")) {
|
||||||
String text = null;
|
String text = null;
|
||||||
try {
|
try {
|
||||||
InputStream is = getActivity().getContentResolver().openInputStream(dl.uri);
|
InputStream is = getActivity().getContentResolver().openInputStream(dl.uri);
|
||||||
@ -321,7 +321,7 @@ public class DownloadFragment extends Fragment {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
Intent intent = new Intent(Intent.ACTION_SEND);
|
Intent intent = new Intent(Intent.ACTION_SEND);
|
||||||
intent.setType(dl.mime);
|
intent.setType(dl.type);
|
||||||
intent.putExtra(Intent.EXTRA_TEXT, text);
|
intent.putExtra(Intent.EXTRA_TEXT, text);
|
||||||
startActivity(Intent.createChooser(intent, getString(R.string.share_title)));
|
startActivity(Intent.createChooser(intent, getString(R.string.share_title)));
|
||||||
} catch (ActivityNotFoundException e) {
|
} catch (ActivityNotFoundException e) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user