Added an extended class Application to get the Context from anywhere in the application, the DHT configuration (data storage folder) has been changed.

This commit is contained in:
ChronosX88 2019-02-26 15:37:27 +04:00
parent 724c3c8da7
commit ab63f87d7c
No known key found for this signature in database
GPG Key ID: 8F92E090A87804AA
3 changed files with 27 additions and 3 deletions

View File

@ -5,7 +5,7 @@
<configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" /> <configuration PROFILE_NAME="Debug" CONFIG_NAME="Debug" />
</configurations> </configurations>
</component> </component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" project-jdk-name="1.8" project-jdk-type="JavaSDK"> <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" /> <output url="file://$PROJECT_DIR$/build/classes" />
</component> </component>
<component name="ProjectType"> <component name="ProjectType">

View File

@ -0,0 +1,22 @@
package io.github.chronosx88.influence;
import android.app.Application;
import android.content.Context;
/**
* Extended Application class which designed for getting Context from anywhere in the application.
*/
public class ExtendedApplication extends Application {
private static Application instance;
@Override
public void onCreate() {
super.onCreate();
instance = this;
}
public static Context getContext() {
return instance.getApplicationContext();
}
}

View File

@ -2,6 +2,8 @@ package io.github.chronosx88.influence.kademlia;
import java.io.File; import java.io.File;
import io.github.chronosx88.influence.ExtendedApplication;
/** /**
* A set of Kademlia configuration parameters. Default values are * A set of Kademlia configuration parameters. Default values are
* supplied and can be changed by the application as necessary. * supplied and can be changed by the application as necessary.
@ -17,7 +19,7 @@ public class DefaultConfiguration implements KadConfiguration
private final static int K = 5; private final static int K = 5;
private final static int RCSIZE = 3; private final static int RCSIZE = 3;
private final static int STALE = 1; private final static int STALE = 1;
private final static String LOCAL_FOLDER = "com/github/joshuakissoon/kademlia"; private final static String LOCAL_FOLDER = "DHT_Data";
private final static boolean IS_TESTING = true; private final static boolean IS_TESTING = true;
@ -75,7 +77,7 @@ public class DefaultConfiguration implements KadConfiguration
public String getNodeDataFolder(String ownerId) public String getNodeDataFolder(String ownerId)
{ {
/* Setup the main storage folder if it doesn't exist */ /* Setup the main storage folder if it doesn't exist */
String path = System.getProperty("user.home") + File.separator + DefaultConfiguration.LOCAL_FOLDER; String path = ExtendedApplication.getContext().getFilesDir() + File.separator + DefaultConfiguration.LOCAL_FOLDER;
File folder = new File(path); File folder = new File(path);
if (!folder.isDirectory()) if (!folder.isDirectory())
{ {