Skip to content

Commit

Permalink
release 0.1.1 alpha work in progress
Browse files Browse the repository at this point in the history
  • Loading branch information
martinellison committed Mar 15, 2020
1 parent d655ba7 commit af471d6
Show file tree
Hide file tree
Showing 50 changed files with 1,657 additions and 632 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,4 @@ test
testfiles
testfiles/testrep2.git/
tools
Lowu/app/src/main/java/taiposwig
5 changes: 5 additions & 0 deletions Lowu/android/content/annotations.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
<root>
<item name='android.content.SharedPreferences'>
<annotation name='java.lang.Deprecated' />
</item>
</root>
135 changes: 105 additions & 30 deletions Lowu/app/src/main/java/hk/jennyemily/work/lowu/MainActivity.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/. */

package hk.jennyemily.work.lowu;

import android.app.Activity;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
Expand All @@ -29,8 +30,9 @@ public class MainActivity extends AppCompatActivity {
}

private taiposwig.SWIGTYPE_p_LowuData td;
String TAG = "fanling10";
private final static String TAG = "fanling10";
private WebView mWebView;
private static final int RESULT_SETTINGS = 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -41,39 +43,20 @@ protected void onCreate(Bundle savedInstanceState) {
toolbar.setTitle("Fanling10");
setSupportActionBar(toolbar);

Log.d(TAG, "making data...");
JSONObject json = new JSONObject();
try {
json.put("database_path", getApplicationContext().getDataDir() + "/search.db");
//json.put("database_path", getApplicationContext().getDataDir() + "/test2.db");
json.put("git_path", getApplicationContext().getDataDir() + "/test2.git");
//json.put("git_path", getApplicationContext().getDataDir() + "/store.git");
json.put("branch", "master");
json.put("have_url", true);
json.put("url", "[email protected]:martin/data1.git");
//json.put("url", "[email protected]:fanling/testrep2.git");
json.put("name", "martin");
json.put("email", "[email protected]");
json.put("unique_prefix", "x");
json.put("ssh_path", getApplicationContext().getDataDir() + "/id_rsa");
json.put("slurp_ssh", true);
} catch (JSONException e) {
e.printStackTrace();
}
setInitialPreferencesIfRequired();

td = taiposwig.taiposwig.make_data(json.toString());
Log.d(TAG, "making data...");
td = taiposwig.taiposwig.make_data(jsonOptions().toString());
Log.d(TAG, "data made.");

// mWebView = new WebView(this);
WebView mWebView = findViewById(R.id.webview);
WebView mWebView = findViewById(R.id.webview);
WebSettings webSettings = mWebView.getSettings();
webSettings.setJavaScriptEnabled(true);
mWebView.addJavascriptInterface(new WebAppInterface(this), "taipo");
//!!! add some code here to set platform-specific javascript (look at the PC version)
mWebView.setWebViewClient(new WebViewClient());

// setContentView(mWebView);
Log.d(TAG, "web view set");
Log.d(TAG, "web view set");
String ih = taiposwig.taiposwig.initial_html(td);
Log.d(TAG, "have initial html");
// Log.d(TAG, "initial html: "+ih);
Expand All @@ -84,19 +67,85 @@ protected void onCreate(Bundle savedInstanceState) {
Log.d(TAG, "on create done");
}

void setInitialPreferencesIfRequired() {
Log.d(TAG, "setting initial preferences...");
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext()));
if (sp.getString("unique_prefix", "") == "") {
SharedPreferences.Editor ed = sp.edit();
ed.putString("database_path", getApplicationContext().getDataDir() + "/search.db");
ed.putString("git_path", getApplicationContext().getDataDir() + "/test2.git");
ed.putString("git_branch", "master");
ed.putBoolean("git_has_url", true);
ed.putString("git_url", "[email protected]:martin/data1.git");
ed.putString("git_name", "martin");
ed.putString("git_email", "[email protected]");
ed.putString("unique_prefix", "x");
ed.putString("ssh_path", getApplicationContext().getDataDir() + "/id_rsa");
ed.putBoolean("slurp_ssh", true);
ed.apply();
Log.d(TAG, "set initial preferences.");
} else {
Log.d(TAG, "preferences already set");
}
}

JSONObject jsonOptions() {
Log.d(TAG, "setting options...");
JSONObject json = new JSONObject();
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext()));
try {
json.put("database_path", sp.getString("database_path", "??"));
json.put("git_path", sp.getString("git_path", "??"));
json.put("branch", sp.getString("git_branch", "??"));
json.put("have_url", sp.getBoolean("git_have_url", false));
json.put("url", sp.getString("git_url", "??"));
json.put("name", sp.getString("git_name", "??"));
json.put("email", sp.getString("git_email", "??"));
json.put("unique_prefix", sp.getString("unique_prefix", "??"));
json.put("ssh_path", sp.getString("ssh_path", "??"));
json.put("slurp_ssh", sp.getBoolean("slurp_ssh", true));
Log.d(TAG, "options set, prefix is " + sp.getString("unique_prefix", "??"));
} catch (JSONException e) {
e.printStackTrace();
}
return json;
}

@Override
protected void onPause() {
Log.d(TAG, "pausing...");
taiposwig.taiposwig.handle_event(td, CCycleEvent.Pause);
super.onPause();
}

@Override
protected void onResume() {
Log.d(TAG, "resuming...");
taiposwig.taiposwig.handle_event(td, CCycleEvent.Resume);
super.onResume();
}

@Override
protected void onStart() {
Log.d(TAG, "starting...");
super.onStart();
}

@Override
protected void onRestart() {
Log.d(TAG, "restarting...");
super.onRestart();
}

@Override
protected void onStop() {
Log.d(TAG, "stopping...");
taiposwig.taiposwig.handle_event(td, CCycleEvent.Stop);
super.onStop();
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
Expand All @@ -114,26 +163,52 @@ public boolean onOptionsItemSelected(MenuItem item) {
case R.id.menuSettings:
Log.d(TAG, "settings clicked");
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
startActivity(intent);
startActivityForResult(intent, RESULT_SETTINGS);
break;
default:
Log.d(TAG, "some menu option selected");
}
return super.onOptionsItemSelected(item);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

switch (requestCode) {
case RESULT_SETTINGS:
switch (resultCode) {
case PreferencesActivity.NOT_CHANGED_RESULT:
Log.d(TAG, "settings done, not changed result");
break;
case PreferencesActivity.CHANGED_RESULT:
Log.d(TAG, "settings done, changed result");
Intent i = new Intent(MainActivity.this, MainActivity.class);
i.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
i.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
MainActivity.this.startActivity(i);
break;
default:
Log.d(TAG, "settings done, unknown result " + resultCode);
break;
}
break;
default:
throw new IllegalStateException("Unexpected value: " + requestCode);
}
}

@Override
protected void onDestroy() {
taiposwig.taiposwig.handle_event(td, CCycleEvent.Stop);
Log.d(TAG, "on destroy, releasing rust data...");
taiposwig.taiposwig.handle_event(td, CCycleEvent.Destroy);
Log.d(TAG, "on destroy, releasing rust data (" + (isFinishing() ? "finishing" : "not finishing") + ")...");
taiposwig.taiposwig.delete_data(td);
super.onDestroy();
Log.d(TAG, "done.");
}

class WebAppInterface {
WebAppInterface(Activity a) {
// mActivity = a;
}

@JavascriptInterface
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,19 +4,27 @@

package hk.jennyemily.work.lowu;

import android.app.Activity;
import android.content.SharedPreferences;
import android.os.Bundle;

import com.google.android.material.floatingactionbutton.FloatingActionButton;
import com.google.android.material.snackbar.Snackbar;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.Toolbar;

import android.view.View;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.EditTextPreference;
import android.preference.Preference;
import android.preference.PreferenceActivity;
import android.preference.PreferenceManager;
import android.util.Log;

import static android.util.Log.d;

public class PreferencesActivity extends PreferenceActivity {
private final static String TAG = "fanling10:PreferencesActivity";
private static final String[] keys = {
"git_path",
"git_branch", "git_has_url", "git_url", "git_name", "git_email", "database_path",
"unique_prefix", "ssh_path", "slurp_ssh"
};
public final static int NOT_CHANGED_RESULT = RESULT_FIRST_USER;
public final static int CHANGED_RESULT = RESULT_FIRST_USER + 1;

@Override
protected void onCreate(Bundle savedInstanceState) {
Expand All @@ -35,6 +43,33 @@ public void onClick(View view) {
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);*/
addPreferencesFromResource(R.xml.prefs);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Log.d(TAG, "as edited: " + getPreferenceManager().getSharedPreferencesName());
Log.d(TAG, "default: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext()));
for (String key : keys) {
Preference pref = findPreference(key);
// Log.d(TAG, key + " is a " + pref.toString());
pref.setOnPreferenceChangeListener(sChangeListener);
if (pref instanceof EditTextPreference) {
pref.setSummary(sp.getString(pref.getKey(), "??"));
Log.d(TAG, pref.getKey() + ": " + sp.getString(pref.getKey(), "??"));
} else if (pref instanceof CheckBoxPreference) {
pref.setSummary(sp.getBoolean(pref.getKey(), false) ? "true" : "false");
}
}
Log.d(TAG, "unique prefix: " + sp.getString("unique_prefix", "??"));
setResult(NOT_CHANGED_RESULT);
}

private static Preference.OnPreferenceChangeListener sChangeListener = new Preference.OnPreferenceChangeListener() {
@Override
public boolean onPreferenceChange(Preference preference, Object newValue) {
String stringValue = newValue.toString();
d(TAG, "preference " + preference.getKey() + " changed to " + stringValue);
preference.setSummary(stringValue);
Activity activity = (Activity) preference.getContext();
activity.setResult(CHANGED_RESULT);
return true;
}
};
}
7 changes: 2 additions & 5 deletions Lowu/app/src/main/java/taiposwig/CCycleEvent.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
Expand All @@ -18,6 +14,7 @@ public final class CCycleEvent {
public final static CCycleEvent Resume = new CCycleEvent("Resume");
public final static CCycleEvent Stop = new CCycleEvent("Stop");
public final static CCycleEvent StopPC = new CCycleEvent("StopPC");
public final static CCycleEvent Destroy = new CCycleEvent("Destroy");

public final int swigValue() {
return swigValue;
Expand Down Expand Up @@ -53,7 +50,7 @@ private CCycleEvent(String swigName, CCycleEvent swigEnum) {
swigNext = this.swigValue+1;
}

private static CCycleEvent[] swigValues = { Start, Pause, Resume, Stop, StopPC };
private static CCycleEvent[] swigValues = { Start, Pause, Resume, Stop, StopPC, Destroy };
private static int swigNext = 0;
private final int swigValue;
private final String swigName;
Expand Down
4 changes: 0 additions & 4 deletions Lowu/app/src/main/java/taiposwig/CResponseItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
Expand Down
4 changes: 0 additions & 4 deletions Lowu/app/src/main/java/taiposwig/SWIGTYPE_p_LowuData.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
Expand Down
4 changes: 0 additions & 4 deletions Lowu/app/src/main/java/taiposwig/taiposwig.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
Expand Down
4 changes: 0 additions & 4 deletions Lowu/app/src/main/java/taiposwig/taiposwigJNI.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/* This Source Code Form is subject to the terms of the Mozilla Public
License, v. 2.0. If a copy of the MPL was not distributed with this
file, You can obtain one at https://mozilla.org/MPL/2.0/. */

/* ----------------------------------------------------------------------------
* This file was automatically generated by SWIG (http://www.swig.org).
* Version 4.0.1
Expand Down
Loading

0 comments on commit af471d6

Please sign in to comment.