Skip to content

Commit f586b0d

Browse files
committed
Minor Fixes
1 parent ef1a713 commit f586b0d

File tree

9 files changed

+171
-103
lines changed

9 files changed

+171
-103
lines changed

Android app/app/build.gradle

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ android {
77
applicationId "com.schlmgr"
88
minSdkVersion 19
99
targetSdkVersion 30
10-
versionCode 53
11-
versionName '1.6.0'
10+
versionCode 54
11+
versionName '1.6.1'
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
signingConfig signingConfigs.debug
1414
}

Android app/app/libs/SMLib.jar

422 Bytes
Binary file not shown.

Android app/app/libs/SMLib.zip

-102 Bytes
Binary file not shown.

Android app/app/src/main/java/com/schlmgr/gui/fragments/AboutFragment.java

+1
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@ public View onCreateView(@NonNull LayoutInflater inflater,
9393
versions_beta.setTgl(root);
9494
RecyclerView rvRelease = (RecyclerView) versions_release.toToggle;
9595
String[][] releases = {
96+
{"1.6.1", "- reworked and improved word name resolving features, now more robust"},
9697
{"1.6.0", "- reworked and improved simple word exports, now more robust"},
9798
{"1.5.2", "- altered filesystem usage to handle Android 10+ Storage access framework"},
9899
{"1.5.0", "- working system for moving and referencing objects with recursion protection"},

Android app/app/src/main/java/com/schlmgr/gui/fragments/MainFragment.java

+17-6
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
208208
cp.np.setMaxValue(cp.np.getMaxValue() - 1);
209209
} else cp.npLayout.setVisibility(View.GONE);
210210
cp.ok.setOnClickListener(x -> {
211+
int position = him.position;
211212
String name = cp.et_name.getText().toString();
212213
if (name.isEmpty()) return;
213214
try {
@@ -224,16 +225,20 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
224225
if (!isMch) {
225226
if (sch != isSch)
226227
him.bd = ((SemiElementContainer) him.bd).convert();
227-
int position = cp.np.getValue();
228-
if (position != him.position)
229-
him.parent.putChild(him.parent.removeChild(him.bd),
228+
position = cp.np.getValue();
229+
if (position != him.position) him.parent.putChild(him.parent.removeChild(him.bd),
230230
him.bd, position - 1);
231231
CurrentData.save(backLog.path);
232232
} else ((MainChapter) him.bd).save();
233233
VS.contentAdapter.selected = -1;
234234
setSelectOpts(false);
235235
him.toShow = him.bd.toString();
236-
backLog.adapter.notifyDataSetChanged();
236+
if (position == him.position) backLog.adapter.notifyItemChanged(position - 1);
237+
else {
238+
backLog.adapter.list.add(position - 1, backLog.adapter.list.remove(him.position - 1));
239+
backLog.adapter.notifyItemMoved(him.position - 1, position - 1);
240+
him.position = position;
241+
}
237242
cp.dismiss();
238243
} catch (IllegalArgumentException iae) {
239244
if (!iae.getMessage().contains("Name can't")) throw iae;
@@ -246,6 +251,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
246251
} else if (him.bd instanceof TwoSided) {
247252
boolean pic = him.bd instanceof Picture;
248253
activity.runOnUiThread(() -> new CreatorPopup(getString(R.string.edit), new Includer() {
254+
int position = him.position;
249255
AbstractPopupRecyclerAdapter content;
250256

251257
@Override
@@ -259,7 +265,7 @@ public View onInclude(LayoutInflater li, CreatorPopup cp) {
259265
cp.np.setMaxValue(cp.np.getMaxValue() - 1);
260266
cp.ok.setOnClickListener(v -> {
261267
onClick.run();
262-
int position = cp.np.getValue();
268+
position = cp.np.getValue();
263269
if (position != him.position) {
264270
him.parent.putChild(him.parent.removeChild(him.bd),
265271
him.bd, position - 1);
@@ -274,7 +280,12 @@ public View onInclude(LayoutInflater li, CreatorPopup cp) {
274280
him.flipped = !him.flipped;
275281
him.flip();
276282
}
277-
backLog.adapter.notifyDataSetChanged();
283+
if (position == him.position) backLog.adapter.notifyItemChanged(position - 1);
284+
else {
285+
backLog.adapter.list.add(position - 1, backLog.adapter.list.remove(him.position - 1));
286+
backLog.adapter.notifyItemMoved(him.position - 1, position - 1);
287+
him.position = position;
288+
}
278289
cp.dismiss();
279290
});
280291
return ll;

Library/nbproject/private/private.xml

+1
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
55
<group>
66
<file>file:/home/kepis/Documents/SchoolManager/Library/src/IOSystem/SimpleWriter.java</file>
7+
<file>file:/home/kepis/Documents/SchoolManager/Library/src/testing/NameReader.java</file>
78
</group>
89
</open-files>
910
</project-private>

Library/nbproject/project.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ jlink.additionalmodules=
7373
jlink.additionalparam=
7474
jlink.launcher=true
7575
jlink.launcher.name=Library
76-
main.class=
76+
main.class=testing.NameReader
7777
manifest.file=manifest.mf
7878
meta.inf.dir=${src.dir}/META-INF
7979
mkdist.disabled=false

Library/src/testing/NameReader.java

+149-94
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package testing;
22

3+
import java.util.ArrayList;
34
import java.util.LinkedList;
45

5-
import objects.MainChapter;
6+
import java.util.List;
67
import objects.templates.BasicData;
78

89
/**
@@ -12,34 +13,30 @@
1213
*/
1314
public class NameReader {
1415

15-
/**
16-
* Used for any text reading to keep track of the current position of reading.
17-
*/
18-
public static class Source {
19-
2016
/**
21-
* Source to be read, from position {@link #index index}.
17+
* Source to be read, from position {@link #i i}.
2218
*/
23-
public final String str;
19+
private final String str;
20+
private final int length;
2421
/**
2522
* Where the given {@link #str source} should be read from.
2623
*/
27-
public int index;
24+
private int i = 0;
25+
26+
public final String[] result;
2827

29-
public MainChapter i;
30-
31-
public Source(String s, int index, MainChapter identifier) {
28+
public NameReader(String s) {
3229
this.str = s;
33-
this.index = index;
34-
i = identifier;
30+
length = str.length();
31+
List<StringBuilder> parts = new ArrayList<>(3);
32+
getParts(parts);
33+
result = new String[parts.size()];
34+
int i = 0;
35+
for (StringBuilder sb : parts) result[i++] = sb.toString();
3536
}
36-
}
3737

3838
/**
3939
* Reads the {@link BasicData#getName() name} and gives back all name possibilities.
40-
* Keep in mind, names with more variants will in most cases make a space after
41-
* ',' or '.' or '!' or '?'. To eliminate this, write '\\' before these
42-
* chars in these cases. Doesn't work for cases like {@code "\\.)more"}
4340
* <p>
4441
* Examples, for names:
4542
* <blockquote><pre>
@@ -54,90 +51,148 @@ public Source(String s, int index, MainChapter identifier) {
5451
* @return all variants of the {@link BasicData#getName() name}
5552
*/
5653
public static String[] readName(Object o) {
57-
return getParts(new Source(o.toString(), 0, null), true);
54+
String text = o.toString();
55+
return text.contains("/") ? new NameReader(text).result : new String[]{text};
5856
}
5957

6058
public static void main(String[] args) {
61-
for(String str : readName("b/(a) c"))System.out.println(str);
59+
// for(String str : readName("(/(1a/2(1b/2b B)a/3(1b/2(1c/2(1 D)c/3c C)b)a ))A")) System.out.println(str);
60+
// for(String str : readName("0 1a\\/1b 2a/2b.")) System.out.println(str);
6261
}
63-
private static String[] getParts(Source src, boolean first) {
64-
if (first && !src.str.contains("/")) return new String[]{src.str};
65-
boolean slash = false, bracket = false, itpcn = false;
66-
int start = src.index, index = start;
67-
String[] ret = {""};
68-
LinkedList<String> slashStrs = new LinkedList<>();
69-
cycle:
70-
for (; index < src.str.length(); index++) {
71-
switch (src.str.charAt(index)) {
72-
case '\\':
73-
index++;
74-
break;
75-
case '.':
76-
case '!':
77-
case '?':
78-
case ',':
79-
itpcn = true;//interpunction found
80-
case ' ':
81-
if (itpcn && !slash && index + 1 < src.str.length()) {
82-
itpcn = false;
83-
break;
62+
63+
private void getParts(List<StringBuilder> ret) {
64+
List<StringBuilder> parts = null;
65+
List<StringBuilder> recursiveParts = null;
66+
StringBuilder sb = new StringBuilder(8);
67+
int lastSplitter = i - 1;
68+
char now;
69+
renderer:
70+
for (; i < length; i++) switch (now = str.charAt(i)) {
71+
case '/':
72+
if (recursiveParts == null) {
73+
if (sb.length() > 0 || lastSplitter == i - 1) {
74+
if (parts == null) parts = new ArrayList<>(3);
75+
parts.add(sb);
76+
sb = new StringBuilder(8);
8477
}
85-
if (slash) {
86-
if (!bracket) slashStrs.add(substr(src.str, start, index));
87-
if (itpcn) for (int i = slashStrs.size() - 1; i >= 0; i--)
88-
slashStrs.set(i, slashStrs.get(i) + src.str.charAt(index));
89-
ret = compile(ret, slashStrs.toArray(new String[slashStrs.size()]));
90-
slash = false;
91-
slashStrs.clear();
92-
} else ret = compile(ret, substr(src.str, start, index + (itpcn ? 1 : 0)));
93-
if (itpcn) {
94-
itpcn = false;
95-
if (index + 1 >= src.str.length()) {
96-
src.index = src.str.length() - 1;
97-
return ret;
78+
} else {
79+
if (parts == null) {
80+
if (sb.length() > 0) for (StringBuilder part : recursiveParts) part.append(sb);
81+
parts = recursiveParts;
82+
} else for (StringBuilder part : recursiveParts) parts.add(part.append(sb));
83+
sb.setLength(0);
84+
recursiveParts = null;
85+
}
86+
lastSplitter = i;
87+
break;
88+
case '.':
89+
case '!':
90+
case '?':
91+
case ',':
92+
case ' ':
93+
if (parts == null) {
94+
sb.append(now);
95+
if (recursiveParts == null) {
96+
if (ret.isEmpty()) ret.add(sb);
97+
else for (StringBuilder part : ret) if (sb.length() > 0) part.append(sb);
98+
sb = new StringBuilder(8);
99+
} else {
100+
if (ret.isEmpty()) for (StringBuilder part : recursiveParts)
101+
ret.add(part.length() > 0 ? part.append(sb) : part);
102+
else {
103+
int size = ret.size();
104+
StringBuilder retPart;
105+
for (int j = 0; j < size; j++) {
106+
retPart = ret.remove(0);
107+
for (StringBuilder part : recursiveParts)
108+
ret.add(part.length() > 0 ? new StringBuilder(retPart).append(part).append(now)
109+
: new StringBuilder(retPart).append(part));
110+
}
98111
}
112+
sb.setLength(0);
113+
recursiveParts = null;
99114
}
100-
start = index + 1;
101-
bracket = false;
102-
break;
103-
case '(':
104-
src.index = index + 1;
105-
slashStrs.addAll(java.util.Arrays.asList(getParts(src, false)));
106-
start = 1 + (index = src.index);
107-
bracket = true;
108-
break;
109-
case ')':
110-
bracket = false;
111-
break cycle;
112-
case '/':
113-
if (!bracket) slashStrs.add(substr(src.str, start, index));
114-
else bracket = false;
115-
start = index + 1;
116-
slash = true;
117-
}
115+
} else {
116+
if (sb.length() > 0) {
117+
if (recursiveParts == null) parts.add(sb);
118+
else {
119+
for (StringBuilder part : recursiveParts) parts.add(part.append(sb));
120+
recursiveParts = null;
121+
}
122+
sb = new StringBuilder(8);
123+
} else if (recursiveParts != null) {
124+
for (StringBuilder part : recursiveParts) parts.add(part);
125+
recursiveParts = null;
126+
}
127+
if (ret.isEmpty()) for (StringBuilder part : parts)
128+
ret.add(part.length() > 0 ? part.append(now) : part);
129+
else {
130+
int size = ret.size();
131+
StringBuilder retPart;
132+
for (int j = 0; j < size; j++) {
133+
retPart = ret.remove(0);
134+
for (StringBuilder part : parts) ret.add(part.length() > 0 ? new StringBuilder(retPart)
135+
.append(part).append(now) : new StringBuilder(retPart).append(part));
136+
}
137+
}
138+
parts = null;
139+
}
140+
lastSplitter = i;
141+
break;
142+
case ')':
143+
break renderer;
144+
case '(':
145+
i++;
146+
recursiveParts = new ArrayList<>(2);
147+
if (sb.length() > 0) recursiveParts.add(sb);
148+
sb = new StringBuilder(8);
149+
getParts(recursiveParts);
150+
if (recursiveParts.size() == 1) {
151+
if (sb.length() > 0) sb.append(recursiveParts.get(0));
152+
else sb = recursiveParts.get(0);
153+
recursiveParts = null;
154+
}
155+
break;
156+
case '\\':
157+
now = str.charAt(++i);
158+
default:
159+
sb.append(now);
118160
}
119-
if (slash) {
120-
if (start < (src.index = index)) slashStrs.add(substr(src.str, start, index));
121-
return compile(ret, slashStrs.toArray(new String[slashStrs.size()]));
122-
} else if (bracket) ret =
123-
compile(ret, slashStrs.toArray(new String[slashStrs.size()]));
124-
return compile(ret, substr(src.str, start, src.index = index));
125-
}
126-
127-
private static String[] compile(String[] src1, String... src2) {
128-
if (src1.length == 0 || src2.length == 0) return src1.length == 0 ? src2 : src1;
129-
String[] ret = new String[src1.length * src2.length];
130-
for (int i = src2.length - 1; i != -1; i--) {
131-
int ch = src2[i].isEmpty() ? -1 : src2[i].charAt(0);
132-
for (int j = src1.length - 1; j != -1; j--)
133-
ret[j + i * src1.length] = src1[j].isEmpty() ? src2[i] : (src1[j]
134-
+ (ch != ',' && ch != '.' && ch != '?' && ch != '!'
135-
&& ch != '\'' && ch != -1 ? ' ' + src2[i] : src2[i]));
161+
if (parts == null) {
162+
if (recursiveParts == null) {
163+
if (sb.length() > 0) {
164+
if (ret.isEmpty()) ret.add(sb);
165+
else for (StringBuilder part : ret) part.append(sb);
166+
}
167+
} else {
168+
if (ret.isEmpty()) for (StringBuilder part : recursiveParts) ret.add(part.append(sb));
169+
else {
170+
int size = ret.size();
171+
for (int j = 0; j < size; j++) {
172+
StringBuilder retPart = ret.remove(j);
173+
for (StringBuilder part : recursiveParts) {
174+
ret.add(new StringBuilder(retPart).append(part).append(sb));
175+
}
176+
}
177+
}
178+
}
179+
} else {
180+
if (sb.length() > 0) {
181+
if (recursiveParts == null) parts.add(sb);
182+
else for (StringBuilder part : recursiveParts) parts.add(part.append(sb));
183+
} else if (recursiveParts != null) {
184+
for (StringBuilder part : recursiveParts) parts.add(part);
185+
}
186+
if (ret.isEmpty()) for (StringBuilder part : parts) ret.add(part);
187+
else {
188+
int size = ret.size();
189+
for (int j = 0; j < size; j++) {
190+
StringBuilder retPart = ret.remove(j);
191+
for (StringBuilder part : parts) {
192+
ret.add(new StringBuilder(retPart).append(part));
193+
}
194+
}
195+
}
136196
}
137-
return ret;
138-
}
139-
140-
private static String substr(String str, int begin, int end) {
141-
return str.substring(begin, end).replace("\\", "");
142197
}
143198
}

SchoolManager.apk

474 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)