Skip to content

Commit

Permalink
release 0.1.3
Browse files Browse the repository at this point in the history
  • Loading branch information
martinellison committed Jul 26, 2020
1 parent bcdb464 commit 20d4520
Show file tree
Hide file tree
Showing 35 changed files with 482 additions and 166 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"??"
**/??
**/"??"
**/#*#
**/*.rs.bk
**/.#*
Expand Down
2 changes: 2 additions & 0 deletions Lowu/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ dependencies {
implementation 'androidx.appcompat:appcompat:1.0.2'
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
implementation 'com.google.android.material:material:1.0.0'
implementation 'androidx.navigation:navigation-fragment:2.0.0'
implementation 'androidx.navigation:navigation-ui:2.0.0'
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
Expand Down
10 changes: 7 additions & 3 deletions Lowu/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="hk.jennyemily.work.lowu">

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.BLUETOOTH" />

<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".LoadSSHActivity"
android:label="@string/title_activity_load_ssh"
android:theme="@style/AppTheme.NoActionBar"></activity>
<activity
android:name=".PreferencesActivity"
android:label="@string/title_activity_preferences"
Expand All @@ -29,8 +36,5 @@
</intent-filter>
</activity>
</application>
<uses-permission android:name="android.permission.INTERNET" />

<uses-permission android:name="android.permission.BLUETOOTH" />

</manifest>
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package hk.jennyemily.work.lowu;

import android.content.Context;
import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;

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

public class LoadSSHActivity extends AppCompatActivity {
private final static String TAG = "fanling10-load-SSH";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_load_ssh);
final Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
final Button button = (Button) findViewById(R.id.buttonAddFiles);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
final String ssh_path = sp.getString("ssh_path", "??");
if (ssh_path != "??") {
final Context context = getApplicationContext();
uploadUsingEditText(R.id.editTextPrivateKey, ssh_path, context);
uploadUsingEditText(R.id.editTextPublicKey, ssh_path + ".pub", context);
}
}
});
}

private void uploadUsingEditText(int id, String filePath, Context context) {
final EditText editText = (EditText) findViewById(id);
final String key = editText.getText().toString();
writeToFile(filePath, key, context);
}

private void writeToFile(String filePath, String data, Context context) {
try {
Log.d(TAG, "Writing to " + filePath + "...");
File file = new File(getFilesDir(), filePath);
Log.d(TAG, "Writing to " + file.getAbsolutePath() +"...");
FileOutputStream fileOutputStream = new FileOutputStream(file);
OutputStreamWriter outputStreamWriter = new OutputStreamWriter(fileOutputStream);
Log.d(TAG, "Writing '" + data.substring(0, 20) + "'...");
outputStreamWriter.write(data);
outputStreamWriter.close();
Log.d(TAG, "Written to " + filePath + ".");
} catch (
IOException e) {
Log.e("Exception", "File write failed: " + e.toString());
}
}
}
42 changes: 25 additions & 17 deletions Lowu/app/src/main/java/hk/jennyemily/work/lowu/MainActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,17 +51,20 @@ protected void onCreate(Bundle savedInstanceState) {
setInitialPreferencesIfRequired();

Log.d(TAG, "making data...");
td = taiposwig.taiposwig.make_data(jsonOptions().toString());
final String optionsString = jsonOptions().toString();
Log.d(TAG, "options as JSON: " + optionsString);
td = taiposwig.taiposwig.make_data(optionsString);
Log.d(TAG, "data made.");

mWebView = findViewById(R.id.webview);
mWebView.setVerticalScrollBarEnabled(true);
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());
Log.d(TAG, "web view set");
// if (savedInstanceState != null) mWebView.restoreState(savedInstanceState);
// if (savedInstanceState != null) mWebView.restoreState(savedInstanceState);
if (appStatus.equals("initial")) {
String ih = taiposwig.taiposwig.initial_html(td);
Log.d(TAG, "have initial html, displaying...");
Expand All @@ -79,15 +82,16 @@ void setInitialPreferencesIfRequired() {
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext()));
if (sp.getString("unique_prefix", "") == "") {
SharedPreferences.Editor ed = sp.edit();
ed.putBoolean("correct", false);
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", "git@test.jennyemily.hk:martin/data1.git");
ed.putString("git_branch", "main");
ed.putBoolean("git_has_url", false);
ed.putString("git_url", "git@work.jennyemily.hk: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.putString("ssh_path", "id_rsa");
ed.putBoolean("slurp_ssh", true);
ed.putBoolean("auto_link", false);
ed.apply();
Expand All @@ -103,18 +107,20 @@ JSONObject jsonOptions() {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Log.d(TAG, "in main using: " + PreferenceManager.getDefaultSharedPreferencesName(getBaseContext()));
try {
json.put("correct", sp.getBoolean("correct", false));
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("have_url", sp.getBoolean("git_has_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("ssh_path", getApplicationContext().getFilesDir() + "/" + sp.getString("ssh_path", "??"));
json.put("slurp_ssh", sp.getBoolean("slurp_ssh", true));
json.put("auto_link", sp.getBoolean("auto_link", false));
Log.d(TAG, "options set, prefix is " + sp.getString("unique_prefix", "??"));
Log.d(TAG, "options set, prefix is " + sp.getString("unique_prefix", "??") + ", " + (
sp.getBoolean("git_have_url", false) ? "no url" : ("url is " + sp.getString("git_url", "??"))));
} catch (JSONException e) {
e.printStackTrace();
}
Expand All @@ -128,15 +134,15 @@ public void onRestoreInstanceState(Bundle savedState) {
String restoredState = savedState.getString(APP_STATUS);
if (restoredState != appStatus)
Log.e(TAG, "restored state is " + restoredState + " but current state is " + appStatus);
mWebView.restoreState(savedState);
mWebView.restoreState(savedState);
}

@Override
public void onSaveInstanceState(Bundle outState) {
Log.d(TAG, "saving instance state...");
outState.putString(APP_STATUS, appStatus);
if (mWebView == null) Log.e(TAG, "no web view, cannot save");
else mWebView.saveState(outState);
if (mWebView == null) Log.e(TAG, "no web view, cannot save");
else mWebView.saveState(outState);
super.onSaveInstanceState(outState);
}

Expand Down Expand Up @@ -182,15 +188,17 @@ public boolean onCreateOptionsMenu(Menu menu) {

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
switch (id) {
case R.id.menuSettings:
Log.d(TAG, "settings clicked");
Intent intent = new Intent(MainActivity.this, PreferencesActivity.class);
startActivityForResult(intent, RESULT_SETTINGS);
Intent intentPreferences = new Intent(MainActivity.this, PreferencesActivity.class);
startActivityForResult(intentPreferences, RESULT_SETTINGS);
break;
case R.id.menuLoadSSH:
Log.d(TAG, "load files clicked");
Intent intentLoadFiles = new Intent(MainActivity.this, LoadSSHActivity.class);
startActivity(intentLoadFiles);
break;
default:
Log.d(TAG, "some menu option selected");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,29 +19,15 @@
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", "auto_link"
"correct", "git_path", "git_branch", "git_has_url", "git_url", "git_name", "git_email",
"database_path", "unique_prefix", "ssh_path", "slurp_ssh", "auto_link"
};
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) {
super.onCreate(savedInstanceState);
/* setContentView(R.layout.activity_preferences);
Toolbar toolbar = findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
FloatingActionButton fab = findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
getSupportActionBar().setDisplayHomeAsUpEnabled(true);*/
addPreferencesFromResource(R.xml.prefs);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getBaseContext());
Log.d(TAG, "as edited: " + getPreferenceManager().getSharedPreferencesName());
Expand Down
25 changes: 25 additions & 0 deletions Lowu/app/src/main/res/layout/activity_load_ssh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?xml version="1.0" encoding="utf-8"?>
<androidx.coordinatorlayout.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".LoadSSHActivity">

<com.google.android.material.appbar.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/AppTheme.AppBarOverlay">

<androidx.appcompat.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
android:background="?attr/colorPrimary"
app:popupTheme="@style/AppTheme.PopupOverlay" />

</com.google.android.material.appbar.AppBarLayout>

<include layout="@layout/content_load_ssh" />

</androidx.coordinatorlayout.widget.CoordinatorLayout>
35 changes: 35 additions & 0 deletions Lowu/app/src/main/res/layout/content_load_ssh.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:context=".LoadSSHActivity"
tools:showIn="@layout/activity_load_ssh">

<EditText
android:id="@+id/editTextPrivateKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:hint="Enter the SSH private key here"
android:inputType="textMultiLine"
android:lines="5" />

<EditText
android:id="@+id/editTextPublicKey"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/editTextPrivateKey"
android:hint="Enter the SSH public key here"
android:inputType="textMultiLine"
android:lines="5" />

<Button
android:id="@+id/buttonAddFiles"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/editTextPublicKey"
android:text="Set keys" />
</RelativeLayout>
5 changes: 4 additions & 1 deletion Lowu/app/src/main/res/menu/menu_main.xml
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context="hk.jennyemily.work.lowu.MainActivity">

<item
android:id="@+id/menuSettings"
android:orderInCategory="100"
android:title="Settings" />
<item
android:id="@+id/menuLoadSSH"
android:orderInCategory="110"
android:title="Load SSH keys" />
</menu>
3 changes: 2 additions & 1 deletion Lowu/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<resources>
<string name="app_name">Lowu</string>
<string name="action_settings">Settings</string>
<string name="title_activity_preferences">PreferencesActivity</string>
<string name="title_activity_preferences">Preferences</string>
<string name="title_activity_load_ssh">Load SSH keys</string>
</resources>
5 changes: 5 additions & 0 deletions Lowu/app/src/main/res/xml/prefs.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
<?xml version="1.0" encoding="utf-8"?>
<PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
<CheckBoxPreference
android:defaultValue="false"
android:key="correct"
android:summary="Are these preferences correct?"
android:title="Correct?" />
<PreferenceCategory
android:summary="Git repository"
android:title="Git repository">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/* 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 org.junit.Test;

import static org.junit.Assert.*;

/**
* Example local unit test, which will execute on the development machine (host).
*
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
*/
public class ExampleUnitTest {
@Test
public void addition_isCorrect() {
assertEquals(4, 2 + 2);
}
}
2 changes: 1 addition & 1 deletion Lowu/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {

}
dependencies {
classpath 'com.android.tools.build:gradle:3.6.1'
classpath 'com.android.tools.build:gradle:3.6.2'

// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
Expand Down
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
** See [issues after cutover]{}

## Introduction

Fanling10 is is a version of fanling using rust.
Expand All @@ -20,7 +22,7 @@ Most of the code is written in Rust, and uses cross-platform
crates. In particular, Git (or, rather, git2) is used to synchronise
data across multiple installations, and sqlite is used to search a
library. This means that the same data can be synchronised across
multiple installations, even though they are on different platforms.
multiple installations, even though they are on different platforms.

### Different kinds of items

Expand Down
Loading

0 comments on commit 20d4520

Please sign in to comment.