Commit 7ef1238b authored by Peter Jankuliak's avatar Peter Jankuliak
Browse files

Move JNI related code out from MainActivity

parent 4bd63c9f
......@@ -27,6 +27,7 @@ void start_client_thread( string repo_root
g_client_thread = thread([=] {
if (g_client) return;
debug("Starting new ouinet client.");
g_client = make_unique<ouinet::Client>(g_ios);
// In case we're restarting.
......@@ -68,13 +69,14 @@ void start_client_thread( string repo_root
}
g_ios.run();
debug("Stopping ouinet client.");
g_client.reset();
});
}
extern "C"
JNIEXPORT void JNICALL
Java_ie_equalit_ouinet_MainActivity_startOuinetClient(
Java_ie_equalit_ouinet_Ouinet_startOuinetClient(
JNIEnv* env,
jobject /* this */,
jstring j_repo_root,
......@@ -90,7 +92,7 @@ Java_ie_equalit_ouinet_MainActivity_startOuinetClient(
extern "C"
JNIEXPORT void JNICALL
Java_ie_equalit_ouinet_MainActivity_stopOuinetClient(
Java_ie_equalit_ouinet_Ouinet_stopOuinetClient(
JNIEnv *env,
jobject /* this */,
jstring repo_root)
......@@ -102,7 +104,7 @@ Java_ie_equalit_ouinet_MainActivity_stopOuinetClient(
extern "C"
JNIEXPORT void JNICALL
Java_ie_equalit_ouinet_MainActivity_setOuinetInjectorEP(
Java_ie_equalit_ouinet_Ouinet_setOuinetInjectorEP(
JNIEnv* env,
jobject /* this */,
jstring j_injector_ep)
......@@ -117,7 +119,7 @@ Java_ie_equalit_ouinet_MainActivity_setOuinetInjectorEP(
extern "C"
JNIEXPORT void JNICALL
Java_ie_equalit_ouinet_MainActivity_setOuinetIPNS(
Java_ie_equalit_ouinet_Ouinet_setOuinetIPNS(
JNIEnv* env,
jobject /* this */,
jstring j_inps)
......
......@@ -24,6 +24,7 @@ import android.widget.Toast;
import ie.equalit.ouinet.OuiWebViewClient;
import ie.equalit.ouinet.Util;
import ie.equalit.ouinet.Ouinet;
interface OnInput {
public void call(String input);
......@@ -33,19 +34,7 @@ public class MainActivity extends AppCompatActivity {
private WebView _webView;
private OuiWebViewClient _webViewClient;
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("ipfs_bindings");
System.loadLibrary("client");
System.loadLibrary("native-lib");
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "8080");
}
private Ouinet _ouinet;
void go_home() {
String home = "http://www.bbc.com";
......@@ -89,13 +78,13 @@ public class MainActivity extends AppCompatActivity {
if (key.equalsIgnoreCase("ipns")) {
toast("Setting IPNS to: " + val);
writeIPNS(val);
setOuinetIPNS(val);
_ouinet.setOuinetIPNS(val);
}
else if (key.equalsIgnoreCase("injector")) {
toast("Setting injector to: " + val);
writeInjectorEP(val);
_webViewClient.forgetCredentials();
setOuinetInjectorEP(val);
_ouinet.setOuinetInjectorEP(val);
}
else {
toast("Unknown config key: " + key);
......@@ -119,17 +108,20 @@ public class MainActivity extends AppCompatActivity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
_ouinet = new Ouinet();
setContentView(R.layout.activity_main);
String ipns = readIPNS();
if (ipns.length() > 0) { setOuinetIPNS(ipns); }
if (ipns.length() > 0) { _ouinet.setOuinetIPNS(ipns); }
String injector_ep = readInjectorEP();
if (injector_ep.length() > 0) { setOuinetInjectorEP(injector_ep); }
if (injector_ep.length() > 0) { _ouinet.setOuinetInjectorEP(injector_ep); }
startOuinetClient( getFilesDir().getAbsolutePath()
, injector_ep
, ipns);
_ouinet.startOuinetClient( getFilesDir().getAbsolutePath()
, injector_ep
, ipns);
_webView = (WebView) findViewById(R.id.webview);
......@@ -183,7 +175,7 @@ public class MainActivity extends AppCompatActivity {
public void call(String input) {
writeInjectorEP(input);
_webViewClient.forgetCredentials();
setOuinetInjectorEP(input);
_ouinet.setOuinetInjectorEP(input);
}
});
}
......@@ -193,14 +185,14 @@ public class MainActivity extends AppCompatActivity {
@Override
public void call(String input) {
writeIPNS(input);
setOuinetIPNS(input);
_ouinet.setOuinetIPNS(input);
}
});
}
@Override
protected void onDestroy() {
stopOuinetClient();
_ouinet.stopOuinetClient();
super.onDestroy();
}
......@@ -249,13 +241,4 @@ public class MainActivity extends AppCompatActivity {
super.onBackPressed();
}
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native void startOuinetClient(String repo_root, String injector, String ipns);
public native void stopOuinetClient();
public native void setOuinetInjectorEP(String endpoint);
public native void setOuinetIPNS(String ipns);
}
package ie.equalit.ouinet;
public class Ouinet {
// Used to load the 'native-lib' library on application startup.
static {
System.loadLibrary("ipfs_bindings");
System.loadLibrary("client");
System.loadLibrary("native-lib");
System.setProperty("http.proxyHost", "127.0.0.1");
System.setProperty("http.proxyPort", "8080");
System.setProperty("https.proxyHost", "127.0.0.1");
System.setProperty("https.proxyPort", "8080");
}
/**
* A native method that is implemented by the 'native-lib' native library,
* which is packaged with this application.
*/
public native void startOuinetClient(String repo_root, String injector, String ipns);
public native void stopOuinetClient();
public native void setOuinetInjectorEP(String endpoint);
public native void setOuinetIPNS(String ipns);
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment