Skip to content

Commit af4a043

Browse files
committed
* Improved API from Scala to Rust
* Bump v0.10.0
1 parent b06689f commit af4a043

17 files changed

+243
-115
lines changed

java/AndroidManifest.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
33
package="org.astonbitecode.rustkeylock"
44
android:versionCode="1"
5-
android:versionName="0.9.0" >
5+
android:versionName="0.10.0" >
66

77
<uses-sdk
88
android:minSdkVersion="16"

java/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44

55
<groupId>org.astonbitecode.rustkeylock</groupId>
66
<artifactId>rust-keylock-android</artifactId>
7-
<version>0.9.0</version>
7+
<version>0.10.0</version>
88
<packaging>apk</packaging>
99

1010
<name>rust-keylock-android</name>

java/src/main/java/org/astonbitecode/rustkeylock/api/InterfaceWithRust.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,13 @@ public void set_password(String password, int number) {
4848
call(m);
4949
}
5050

51-
public void go_to_menu(String menuName) {
52-
Map<String, Object> m = GuiResponse.GoToMenu(menuName);
51+
public void go_to_menu(Map<String, Object> menu) {
52+
Map<String, Object> m = GuiResponse.GoToMenu(menu);
5353
call(m);
5454
}
5555

56-
public void go_to_menu_plus_arg(String menuName, String argNum, String argStr) {
57-
Map<String, Object> m = GuiResponse.GoToMenuPlusArgs(menuName, argNum, argStr);
56+
public void go_to_menu(String menu) {
57+
Map<String, Object> m = GuiResponse.GoToMenu(menu);
5858
call(m);
5959
}
6060

java/src/main/java/org/astonbitecode/rustkeylock/api/stubs/GuiResponse.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -32,21 +32,19 @@ public static Map<String, Object> ChangePassword(String password, Integer number
3232
return map;
3333
}
3434

35-
public static Map<String, Object> GoToMenu(String menu) {
35+
public static Map<String, Object> GoToMenu(Map<String, Object> m) {
3636
Map<String, Object> inner = new HashMap<>();
37-
inner.put("menu", menu);
37+
inner.put("menu", m);
3838
Map<String, Object> map = new HashMap<>();
3939
map.put("GoToMenu", inner);
4040
return map;
4141
}
4242

43-
public static Map<String, Object> GoToMenuPlusArgs(String menu, String intArg, String stringArg) {
43+
public static Map<String, Object> GoToMenu(String m) {
4444
Map<String, Object> inner = new HashMap<>();
45-
inner.put("menu", menu);
46-
inner.put("intarg", intArg);
47-
inner.put("stringarg", stringArg);
45+
inner.put("menu", m);
4846
Map<String, Object> map = new HashMap<>();
49-
map.put("GoToMenuPlusArgs", inner);
47+
map.put("GoToMenu", inner);
5048
return map;
5149
}
5250

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,112 @@
1+
// Copyright 2019 astonbitecode
2+
// This file is part of rust-keylock password manager.
3+
//
4+
// rust-keylock is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// rust-keylock is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU General Public License
15+
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
16+
package org.astonbitecode.rustkeylock.api.stubs;
17+
18+
import org.astonbitecode.rustkeylock.utils.Defs;
19+
20+
import java.util.HashMap;
21+
import java.util.Map;
22+
23+
public class JavaMenu {
24+
25+
public static Map<String, Object> EntriesList(String filter) {
26+
Map<String, Object> inner = new HashMap<>();
27+
inner.put("filter", filter);
28+
Map<String, Object> map = new HashMap<>();
29+
map.put(Defs.MENU_ENTRIES_LIST, inner);
30+
return map;
31+
}
32+
33+
public static String Exit() {
34+
return Defs.MENU_EXIT;
35+
}
36+
37+
public static String ForceExit() {
38+
return Defs.MENU_FORCE_EXIT;
39+
}
40+
41+
public static String ChangePass() {
42+
return Defs.MENU_CHANGE_PASS;
43+
}
44+
45+
public static Map<String, Object> Save(Boolean b) {
46+
Map<String, Object> inner = new HashMap<>();
47+
inner.put("b", b);
48+
Map<String, Object> map = new HashMap<>();
49+
map.put(Defs.MENU_SAVE, inner);
50+
return map;
51+
}
52+
53+
public static Map<String, Object> TryPass(Boolean b) {
54+
Map<String, Object> inner = new HashMap<>();
55+
inner.put("b", b);
56+
Map<String, Object> map = new HashMap<>();
57+
map.put(Defs.MENU_TRY_PASS, inner);
58+
return map;
59+
}
60+
61+
public static String ExportEntries() {
62+
return Defs.MENU_EXPORT_ENTRIES;
63+
}
64+
65+
public static String ImportEntries() {
66+
return Defs.MENU_IMPORT_ENTRIES;
67+
}
68+
69+
public static String ShowConfiguration() {
70+
return Defs.MENU_SHOW_CONFIGURATION;
71+
}
72+
73+
public static String Main() {
74+
return Defs.MENU_MAIN;
75+
}
76+
77+
public static String NewEntry() {
78+
return Defs.MENU_NEW_ENTRY;
79+
}
80+
81+
public static Map<String, Object> ShowEntry(Integer idx) {
82+
Map<String, Object> inner = new HashMap<>();
83+
inner.put("idx", idx);
84+
Map<String, Object> map = new HashMap<>();
85+
map.put(Defs.MENU_SHOW_ENTRY, inner);
86+
return map;
87+
}
88+
89+
public static Map<String, Object> EditEntry(Integer idx) {
90+
Map<String, Object> inner = new HashMap<>();
91+
inner.put("idx", idx);
92+
Map<String, Object> map = new HashMap<>();
93+
map.put(Defs.MENU_EDIT_ENTRY, inner);
94+
return map;
95+
}
96+
97+
public static Map<String, Object> DeleteEntry(Integer idx) {
98+
Map<String, Object> inner = new HashMap<>();
99+
inner.put("idx", idx);
100+
Map<String, Object> map = new HashMap<>();
101+
map.put(Defs.MENU_DELETE_ENTRY, inner);
102+
return map;
103+
}
104+
105+
public static Map<String, Object> SetDbToken(String token) {
106+
Map<String, Object> inner = new HashMap<>();
107+
inner.put("token", token);
108+
Map<String, Object> map = new HashMap<>();
109+
map.put(Defs.MENU_SET_DB_TOKEN, inner);
110+
return map;
111+
}
112+
}

java/src/main/java/org/astonbitecode/rustkeylock/fragments/ChangePassword.java

+5-6
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,6 @@
1515
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
1616
package org.astonbitecode.rustkeylock.fragments;
1717

18-
import org.astonbitecode.rustkeylock.R;
19-
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
20-
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
21-
import org.astonbitecode.rustkeylock.utils.Defs;
22-
2318
import android.app.Fragment;
2419
import android.os.Bundle;
2520
import android.util.Log;
@@ -29,6 +24,10 @@
2924
import android.view.ViewGroup;
3025
import android.widget.Button;
3126
import android.widget.EditText;
27+
import org.astonbitecode.rustkeylock.R;
28+
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
29+
import org.astonbitecode.rustkeylock.api.stubs.JavaMenu;
30+
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
3231

3332
public class ChangePassword extends Fragment implements OnClickListener, BackButtonHandler {
3433
private static final long serialVersionUID = 8235249433565909373L;
@@ -86,7 +85,7 @@ public void onClick(View view) {
8685
@Override
8786
public void onBackButton() {
8887
Log.d(TAG, "Back button pressed");
89-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
88+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
9089
}
9190

9291
@Override

java/src/main/java/org/astonbitecode/rustkeylock/fragments/EditConfiguration.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,8 @@
2929
import com.dropbox.core.android.Auth;
3030
import org.astonbitecode.rustkeylock.R;
3131
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
32+
import org.astonbitecode.rustkeylock.api.stubs.JavaMenu;
3233
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
33-
import org.astonbitecode.rustkeylock.utils.Defs;
3434

3535
import java.util.ArrayList;
3636
import java.util.Arrays;
@@ -78,7 +78,7 @@ public void onClick(View view) {
7878
}
7979
} else if (view.getId() == R.id.editConfigurationCancelButton) {
8080
Log.d(TAG, "Clicked Cancel in configuration");
81-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
81+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
8282
} else if (view.getId() == R.id.editConfigurationGetTokenButton) {
8383
String appKey = getString(R.string.dbx_app_key);
8484
Log.d(TAG, "Clicked Get Dropbox token in configuration. App key: " + appKey);
@@ -95,7 +95,7 @@ public void onResume() {
9595
String retrieved_token_from_shared_preferences = Auth.getOAuth2Token();
9696
if (retrieved_token_from_shared_preferences != null) {
9797
token = retrieved_token_from_shared_preferences;
98-
InterfaceWithRust.INSTANCE.go_to_menu_plus_arg(Defs.MENU_SET_DB_TOKEN, Defs.EMPTY_ARG, token);
98+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.SetDbToken(token));
9999
}
100100
}
101101
}
@@ -131,7 +131,7 @@ private void prepareUiElements(View v) {
131131
@Override
132132
public void onBackButton() {
133133
Log.d(TAG, "Back button pressed");
134-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
134+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
135135
}
136136

137137
@Override

java/src/main/java/org/astonbitecode/rustkeylock/fragments/ExitMenu.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717

1818
import org.astonbitecode.rustkeylock.R;
1919
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
20+
import org.astonbitecode.rustkeylock.api.stubs.JavaMenu;
2021
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
2122
import org.astonbitecode.rustkeylock.utils.Defs;
2223

@@ -51,16 +52,16 @@ private void addButtonListeners(View rootView) {
5152
public void onClick(View view) {
5253
if (view.getId() == R.id.exitButtonYes) {
5354
Log.d(TAG, "The User selected to force Exit with unsaved data");
54-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_FORCE_EXIT);
55+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.ForceExit());
5556
} else {
5657
Log.e(TAG, "The User selected not to exit because of unsaved data");
57-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
58+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
5859
}
5960
}
6061

6162
@Override
6263
public void onBackButton() {
6364
Log.d(TAG, "Back button pressed");
64-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
65+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
6566
}
6667
}

java/src/main/java/org/astonbitecode/rustkeylock/fragments/ListEntries.java

+7-8
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
import org.astonbitecode.rustkeylock.adapters.EntriesAdapter;
3434
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
3535
import org.astonbitecode.rustkeylock.api.JavaEntry;
36+
import org.astonbitecode.rustkeylock.api.stubs.JavaMenu;
3637
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
37-
import org.astonbitecode.rustkeylock.utils.Defs;
3838

3939
import java.util.ArrayList;
4040
import java.util.List;
@@ -61,7 +61,7 @@ public ListEntries(List<JavaEntry> entries, String filter) {
6161
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
6262
restore(savedInstanceState);
6363
if (savedInstanceState != null) {
64-
InterfaceWithRust.INSTANCE.go_to_menu_plus_arg(Defs.MENU_ENTRIES_LIST, Defs.EMPTY_ARG, filter);
64+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.EntriesList(filter));
6565
}
6666
View rootView = inflater.inflate(R.layout.fragment_list_entries, container, false);
6767
Button nb = (Button) rootView.findViewById(R.id.addNewButton);
@@ -92,8 +92,7 @@ public void afterTextChanged(final Editable s) {
9292
timer.schedule(new TimerTask() {
9393
@Override
9494
public void run() {
95-
InterfaceWithRust.INSTANCE.go_to_menu_plus_arg(Defs.MENU_ENTRIES_LIST, Defs.EMPTY_ARG,
96-
s != null ? s.toString() : "");
95+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.EntriesList(s != null ? s.toString() : ""));
9796
}
9897
}, DELAY);
9998
}
@@ -122,24 +121,24 @@ public void onActivityCreated(Bundle savedInstanceState) {
122121
public void onListItemClick(ListView l, View v, int pos, long id) {
123122
Log.d(TAG, "Clicked entry with index " + pos + " in the list of entries");
124123
super.onListItemClick(l, v, pos, id);
125-
InterfaceWithRust.INSTANCE.go_to_menu_plus_arg(Defs.MENU_SHOW_ENTRY, pos + "", Defs.EMPTY_ARG);
124+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.ShowEntry(pos));
126125
}
127126

128127
@Override
129128
public void onClick(View view) {
130129
if (view.getId() == R.id.mainMenuButton) {
131130
Log.d(TAG, "Clicked go to the Main menu");
132-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
131+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
133132
} else if (view.getId() == R.id.addNewButton) {
134133
Log.d(TAG, "Clicked add new entry");
135-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_NEW_ENTRY);
134+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.NewEntry());
136135
}
137136
}
138137

139138
@Override
140139
public void onBackButton() {
141140
Log.d(TAG, "Back button pressed");
142-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_MAIN);
141+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Main());
143142
}
144143

145144
@Override

java/src/main/java/org/astonbitecode/rustkeylock/fragments/MainMenu.java

+13-14
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@
1515
// along with rust-keylock. If not, see <http://www.gnu.org/licenses/>.
1616
package org.astonbitecode.rustkeylock.fragments;
1717

18-
import org.astonbitecode.rustkeylock.MainActivity;
19-
import org.astonbitecode.rustkeylock.R;
20-
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
21-
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
22-
import org.astonbitecode.rustkeylock.utils.Defs;
23-
2418
import android.app.Fragment;
2519
import android.content.Context;
2620
import android.os.Bundle;
@@ -31,6 +25,11 @@
3125
import android.view.ViewGroup;
3226
import android.view.inputmethod.InputMethodManager;
3327
import android.widget.Button;
28+
import org.astonbitecode.rustkeylock.MainActivity;
29+
import org.astonbitecode.rustkeylock.R;
30+
import org.astonbitecode.rustkeylock.api.InterfaceWithRust;
31+
import org.astonbitecode.rustkeylock.api.stubs.JavaMenu;
32+
import org.astonbitecode.rustkeylock.handlers.back.BackButtonHandler;
3433

3534
public class MainMenu extends Fragment implements OnClickListener, BackButtonHandler {
3635
private static final long serialVersionUID = -4385132544016979748L;
@@ -70,25 +69,25 @@ private void addButtonListeners(View rootView) {
7069
public void onClick(View view) {
7170
if (view.getId() == R.id.listButton) {
7271
Log.d(TAG, "The User Selected to List Entries");
73-
InterfaceWithRust.INSTANCE.go_to_menu_plus_arg(Defs.MENU_ENTRIES_LIST, Defs.EMPTY_ARG, "");
72+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.EntriesList(""));
7473
} else if (view.getId() == R.id.saveButton) {
7574
Log.d(TAG, "The User Selected to Save Entries");
76-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_SAVE);
75+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Save(false));
7776
} else if (view.getId() == R.id.changePasswordButton) {
7877
Log.d(TAG, "The User Selected to Change the password");
79-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_CHANGE_PASS);
78+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.ChangePass());
8079
} else if (view.getId() == R.id.exitButton) {
8180
Log.d(TAG, "The User Selected to Exit rust-keylock");
82-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_EXIT);
81+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Exit());
8382
} else if (view.getId() == R.id.exportButton) {
8483
Log.d(TAG, "The User Selected to export entries");
85-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_EXPORT_ENTRIES);
84+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.ExportEntries());
8685
} else if (view.getId() == R.id.importButton) {
8786
Log.d(TAG, "The User Selected to import entries");
88-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_IMPORT_ENTRIES);
87+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.ImportEntries());
8988
} else if (view.getId() == R.id.mmEditConfigurationButton) {
9089
Log.d(TAG, "The User Selected to edit the configuration");
91-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_SHOW_CONFIGURATION);
90+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.ShowConfiguration());
9291
} else {
9392
Log.e(TAG, "The User selected a Menu that is not implemented yet in Rust");
9493
}
@@ -97,7 +96,7 @@ public void onClick(View view) {
9796
@Override
9897
public void onBackButton() {
9998
Log.d(TAG, "Back button pressed");
100-
InterfaceWithRust.INSTANCE.go_to_menu(Defs.MENU_EXIT);
99+
InterfaceWithRust.INSTANCE.go_to_menu(JavaMenu.Exit());
101100
}
102101

103102
private class UiThreadRunnable implements Runnable {

0 commit comments

Comments
 (0)