Skip to content

Commit

Permalink
Code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
a-pavlov committed Feb 12, 2022
1 parent 318c18c commit c313a0c
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 152 deletions.
89 changes: 2 additions & 87 deletions android/jdonkey/src/main/java/org/dkf/jmule/AndroidPaths.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,112 +33,27 @@
/**
* @author gubatron
* @author aldenml
* JED2K stores all files to one place without sub dirs
*/
public final class AndroidPaths {

/**
* base storage path
*/
private static final String STORAGE_PATH = "Mule_on_Android";

/**
* downloaded files path
*/
private static final String DOWNLOADS_PATH = "";

/**
* metadata path for fast resume data saving
*/
private static final String METADATA_PATH = ".metadata";

private static final String TEMP_PATH = "temp";

private static final boolean USE_EXTERNAL_STORAGE_DIR_ON_OR_AFTER_ANDROID_10 = true;

private final Context context;
//private final Application app;

public AndroidPaths(Context app) {
this.context = app;
}

// public File data(Context ctx) {
//return new File(storage(), DOWNLOADS_PATH);
// return storage(ctx);
//}

public File data() {
//return new File(storage(), DOWNLOADS_PATH);
return storage();
}

//public File metadata(Context ctx) {
// return new File(storage(ctx), METADATA_PATH);
//}

//public File temp() {
// return new File(context.getExternalFilesDir(null), TEMP_PATH);
//}

private static final Logger LOG = LoggerFactory.getLogger(AndroidPaths.class);
/*
private static File storage(Context ctx) {
if (SystemUtils.hasAndroid10OrNewer()) {
File externalDir = ctx.getExternalFilesDir(null);
return new File(USE_EXTERNAL_STORAGE_DIR_ON_OR_AFTER_ANDROID_10 ?
externalDir : ctx.getFilesDir(),
STORAGE_PATH);
}
*/
/* For Older versions of Android where we used to have access to write to external storage
* <externalStoragePath>/FrostWire/
*/
/* String path = ConfigurationManager.instance().getString(Constants.PREF_KEY_STORAGE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath());
if (path.toLowerCase().endsWith("/" + STORAGE_PATH.toLowerCase())) {
return new File(path);
} else {
return new File(path, STORAGE_PATH);
}
*/
//String path = ConfigurationManager.instance().getString(Constants.PREF_KEY_STORAGE_PATH);
/*if (path.toLowerCase().endsWith("/" + STORAGE_PATH.toLowerCase())) {
return new File(path);
} else {
return new File(path, STORAGE_PATH);
}
*/
//return new File(path);
//}

private File storage() {
if (SystemUtils.hasAndroid10OrNewer()) {
File externalDir = context.getExternalFilesDir(null);
LOG.info("storage: external path {}", externalDir);
return USE_EXTERNAL_STORAGE_DIR_ON_OR_AFTER_ANDROID_10 ? externalDir : context.getFilesDir();

}

/* For Older versions of Android where we used to have access to write to external storage
* <externalStoragePath>/FrostWire/
* <externalStoragePath>
*/
String path = ConfigurationManager.instance().getStoragePath();
//ConfigurationManager.instance().getString(Constants.PREF_KEY_STORAGE_PATH, Environment.getExternalStorageDirectory().getAbsolutePath());
LOG.info("storage: internal path {}", path);
return new File(ConfigurationManager.instance().getStoragePath());
/*
if (path.toLowerCase().endsWith("/" + STORAGE_PATH.toLowerCase())) {
return new File(path);
} else {
return new File(path);
}*/

//String path = ConfigurationManager.instance().getString(Constants.PREF_KEY_STORAGE_PATH);
/*if (path.toLowerCase().endsWith("/" + STORAGE_PATH.toLowerCase())) {
return new File(path);
} else {
return new File(path, STORAGE_PATH);
}
*/
//return new File(path);
}
}
29 changes: 0 additions & 29 deletions android/jdonkey/src/main/java/org/dkf/jmule/Platforms.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

package org.dkf.jmule;

import android.content.Context;

import java.io.File;

/**
Expand Down Expand Up @@ -65,34 +63,7 @@ public static AndroidSettings appSettings() {
return get().appSettings();
}

/**
* Shortcut to current platform file system data method.
*
* @return
*/
//public static File data(Context ctx) {
// return get().systemPaths().data(ctx);
//}

public static File data() {
return get().systemPaths().data();
}

/**
* Shortcut to current platform file system torrents method.
*
* @return
*/
//public static File metadata(Context ctx) {
// return get().systemPaths().metadata(ctx);
//}

/**
* Shortcut to current platform file system temp method.
*
* @return
*/
//public static File temp() {
// return get().systemPaths().temp();
//}
}
Original file line number Diff line number Diff line change
Expand Up @@ -824,35 +824,6 @@ public void onClick(DialogInterface dialogInterface, int i) {
}
}

// TODO: refactor and move this method for a common place when needed
/*private static String saveViewContent(Context context, Uri uri, String name) {
InputStream inStream = null;
OutputStream outStream = null;
if (!Platforms.temp().exists()) {
Platforms.temp().mkdirs();
}
File target = new File(Platforms.temp(), name);
try {
inStream = context.getContentResolver().openInputStream(uri);
outStream = new FileOutputStream(target);
byte[] buffer = new byte[16384]; // MAGIC_NUMBER
int bytesRead;
while ((bytesRead = inStream.read(buffer)) != -1) {
outStream.write(buffer, 0, bytesRead);
}
} catch (Exception e) {
log.error("Error when copying file from " + uri + " to temp/" + name, e);
return null;
} finally {
IOUtils.closeQuietly(inStream);
IOUtils.closeQuietly(outStream);
}
return "file://" + target.getAbsolutePath();
}*/

public Fragment getFragmentByNavMenuId(int id) {
if (id == R.id.menu_main_search) {
return search;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -388,13 +388,7 @@ public void startActivity(Intent intent) {
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == StoragePicker.SELECT_FOLDER_REQUEST_CODE) {
StoragePreference.onDocumentTreeActivityResult(this, requestCode, resultCode, data);
}/* else if (requestCode == BuyActivity.PURCHASE_SUCCESSFUL_RESULT_CODE &&
data != null &&
data.hasExtra(BuyActivity.EXTRA_KEY_PURCHASE_TIMESTAMP)) {
// We (onActivityResult) are invoked before onResume()
removeAdsPurchaseTime = data.getLongExtra(BuyActivity.EXTRA_KEY_PURCHASE_TIMESTAMP, 0);
LOG.info("onActivityResult: User just purchased something. removeAdsPurchaseTime="+removeAdsPurchaseTime);
}*/
}
else {
super.onActivityResult(requestCode, resultCode, data);
}
Expand Down

0 comments on commit c313a0c

Please sign in to comment.