Skip to content

Commit

Permalink
Minor Fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
litoj committed Oct 8, 2021
1 parent ef1a713 commit f586b0d
Show file tree
Hide file tree
Showing 9 changed files with 171 additions and 103 deletions.
4 changes: 2 additions & 2 deletions Android app/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.schlmgr"
minSdkVersion 19
targetSdkVersion 30
versionCode 53
versionName '1.6.0'
versionCode 54
versionName '1.6.1'
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
signingConfig signingConfigs.debug
}
Expand Down
Binary file modified Android app/app/libs/SMLib.jar
Binary file not shown.
Binary file modified Android app/app/libs/SMLib.zip
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ public View onCreateView(@NonNull LayoutInflater inflater,
versions_beta.setTgl(root);
RecyclerView rvRelease = (RecyclerView) versions_release.toToggle;
String[][] releases = {
{"1.6.1", "- reworked and improved word name resolving features, now more robust"},
{"1.6.0", "- reworked and improved simple word exports, now more robust"},
{"1.5.2", "- altered filesystem usage to handle Android 10+ Storage access framework"},
{"1.5.0", "- working system for moving and referencing objects with recursion protection"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
cp.np.setMaxValue(cp.np.getMaxValue() - 1);
} else cp.npLayout.setVisibility(View.GONE);
cp.ok.setOnClickListener(x -> {
int position = him.position;
String name = cp.et_name.getText().toString();
if (name.isEmpty()) return;
try {
Expand All @@ -224,16 +225,20 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
if (!isMch) {
if (sch != isSch)
him.bd = ((SemiElementContainer) him.bd).convert();
int position = cp.np.getValue();
if (position != him.position)
him.parent.putChild(him.parent.removeChild(him.bd),
position = cp.np.getValue();
if (position != him.position) him.parent.putChild(him.parent.removeChild(him.bd),
him.bd, position - 1);
CurrentData.save(backLog.path);
} else ((MainChapter) him.bd).save();
VS.contentAdapter.selected = -1;
setSelectOpts(false);
him.toShow = him.bd.toString();
backLog.adapter.notifyDataSetChanged();
if (position == him.position) backLog.adapter.notifyItemChanged(position - 1);
else {
backLog.adapter.list.add(position - 1, backLog.adapter.list.remove(him.position - 1));
backLog.adapter.notifyItemMoved(him.position - 1, position - 1);
him.position = position;
}
cp.dismiss();
} catch (IllegalArgumentException iae) {
if (!iae.getMessage().contains("Name can't")) throw iae;
Expand All @@ -246,6 +251,7 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
} else if (him.bd instanceof TwoSided) {
boolean pic = him.bd instanceof Picture;
activity.runOnUiThread(() -> new CreatorPopup(getString(R.string.edit), new Includer() {
int position = him.position;
AbstractPopupRecyclerAdapter content;

@Override
Expand All @@ -259,7 +265,7 @@ public View onInclude(LayoutInflater li, CreatorPopup cp) {
cp.np.setMaxValue(cp.np.getMaxValue() - 1);
cp.ok.setOnClickListener(v -> {
onClick.run();
int position = cp.np.getValue();
position = cp.np.getValue();
if (position != him.position) {
him.parent.putChild(him.parent.removeChild(him.bd),
him.bd, position - 1);
Expand All @@ -274,7 +280,12 @@ public View onInclude(LayoutInflater li, CreatorPopup cp) {
him.flipped = !him.flipped;
him.flip();
}
backLog.adapter.notifyDataSetChanged();
if (position == him.position) backLog.adapter.notifyItemChanged(position - 1);
else {
backLog.adapter.list.add(position - 1, backLog.adapter.list.remove(him.position - 1));
backLog.adapter.notifyItemMoved(him.position - 1, position - 1);
him.position = position;
}
cp.dismiss();
});
return ll;
Expand Down
1 change: 1 addition & 0 deletions Library/nbproject/private/private.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<open-files xmlns="http://www.netbeans.org/ns/projectui-open-files/2">
<group>
<file>file:/home/kepis/Documents/SchoolManager/Library/src/IOSystem/SimpleWriter.java</file>
<file>file:/home/kepis/Documents/SchoolManager/Library/src/testing/NameReader.java</file>
</group>
</open-files>
</project-private>
2 changes: 1 addition & 1 deletion Library/nbproject/project.properties
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ jlink.additionalmodules=
jlink.additionalparam=
jlink.launcher=true
jlink.launcher.name=Library
main.class=
main.class=testing.NameReader
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
Expand Down
243 changes: 149 additions & 94 deletions Library/src/testing/NameReader.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package testing;

import java.util.ArrayList;
import java.util.LinkedList;

import objects.MainChapter;
import java.util.List;
import objects.templates.BasicData;

/**
Expand All @@ -12,34 +13,30 @@
*/
public class NameReader {

/**
* Used for any text reading to keep track of the current position of reading.
*/
public static class Source {

/**
* Source to be read, from position {@link #index index}.
* Source to be read, from position {@link #i i}.
*/
public final String str;
private final String str;
private final int length;
/**
* Where the given {@link #str source} should be read from.
*/
public int index;
private int i = 0;

public final String[] result;

public MainChapter i;

public Source(String s, int index, MainChapter identifier) {
public NameReader(String s) {
this.str = s;
this.index = index;
i = identifier;
length = str.length();
List<StringBuilder> parts = new ArrayList<>(3);
getParts(parts);
result = new String[parts.size()];
int i = 0;
for (StringBuilder sb : parts) result[i++] = sb.toString();
}
}

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

public static void main(String[] args) {
for(String str : readName("b/(a) c"))System.out.println(str);
// 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);
// for(String str : readName("0 1a\\/1b 2a/2b.")) System.out.println(str);
}
private static String[] getParts(Source src, boolean first) {
if (first && !src.str.contains("/")) return new String[]{src.str};
boolean slash = false, bracket = false, itpcn = false;
int start = src.index, index = start;
String[] ret = {""};
LinkedList<String> slashStrs = new LinkedList<>();
cycle:
for (; index < src.str.length(); index++) {
switch (src.str.charAt(index)) {
case '\\':
index++;
break;
case '.':
case '!':
case '?':
case ',':
itpcn = true;//interpunction found
case ' ':
if (itpcn && !slash && index + 1 < src.str.length()) {
itpcn = false;
break;

private void getParts(List<StringBuilder> ret) {
List<StringBuilder> parts = null;
List<StringBuilder> recursiveParts = null;
StringBuilder sb = new StringBuilder(8);
int lastSplitter = i - 1;
char now;
renderer:
for (; i < length; i++) switch (now = str.charAt(i)) {
case '/':
if (recursiveParts == null) {
if (sb.length() > 0 || lastSplitter == i - 1) {
if (parts == null) parts = new ArrayList<>(3);
parts.add(sb);
sb = new StringBuilder(8);
}
if (slash) {
if (!bracket) slashStrs.add(substr(src.str, start, index));
if (itpcn) for (int i = slashStrs.size() - 1; i >= 0; i--)
slashStrs.set(i, slashStrs.get(i) + src.str.charAt(index));
ret = compile(ret, slashStrs.toArray(new String[slashStrs.size()]));
slash = false;
slashStrs.clear();
} else ret = compile(ret, substr(src.str, start, index + (itpcn ? 1 : 0)));
if (itpcn) {
itpcn = false;
if (index + 1 >= src.str.length()) {
src.index = src.str.length() - 1;
return ret;
} else {
if (parts == null) {
if (sb.length() > 0) for (StringBuilder part : recursiveParts) part.append(sb);
parts = recursiveParts;
} else for (StringBuilder part : recursiveParts) parts.add(part.append(sb));
sb.setLength(0);
recursiveParts = null;
}
lastSplitter = i;
break;
case '.':
case '!':
case '?':
case ',':
case ' ':
if (parts == null) {
sb.append(now);
if (recursiveParts == null) {
if (ret.isEmpty()) ret.add(sb);
else for (StringBuilder part : ret) if (sb.length() > 0) part.append(sb);
sb = new StringBuilder(8);
} else {
if (ret.isEmpty()) for (StringBuilder part : recursiveParts)
ret.add(part.length() > 0 ? part.append(sb) : part);
else {
int size = ret.size();
StringBuilder retPart;
for (int j = 0; j < size; j++) {
retPart = ret.remove(0);
for (StringBuilder part : recursiveParts)
ret.add(part.length() > 0 ? new StringBuilder(retPart).append(part).append(now)
: new StringBuilder(retPart).append(part));
}
}
sb.setLength(0);
recursiveParts = null;
}
start = index + 1;
bracket = false;
break;
case '(':
src.index = index + 1;
slashStrs.addAll(java.util.Arrays.asList(getParts(src, false)));
start = 1 + (index = src.index);
bracket = true;
break;
case ')':
bracket = false;
break cycle;
case '/':
if (!bracket) slashStrs.add(substr(src.str, start, index));
else bracket = false;
start = index + 1;
slash = true;
}
} else {
if (sb.length() > 0) {
if (recursiveParts == null) parts.add(sb);
else {
for (StringBuilder part : recursiveParts) parts.add(part.append(sb));
recursiveParts = null;
}
sb = new StringBuilder(8);
} else if (recursiveParts != null) {
for (StringBuilder part : recursiveParts) parts.add(part);
recursiveParts = null;
}
if (ret.isEmpty()) for (StringBuilder part : parts)
ret.add(part.length() > 0 ? part.append(now) : part);
else {
int size = ret.size();
StringBuilder retPart;
for (int j = 0; j < size; j++) {
retPart = ret.remove(0);
for (StringBuilder part : parts) ret.add(part.length() > 0 ? new StringBuilder(retPart)
.append(part).append(now) : new StringBuilder(retPart).append(part));
}
}
parts = null;
}
lastSplitter = i;
break;
case ')':
break renderer;
case '(':
i++;
recursiveParts = new ArrayList<>(2);
if (sb.length() > 0) recursiveParts.add(sb);
sb = new StringBuilder(8);
getParts(recursiveParts);
if (recursiveParts.size() == 1) {
if (sb.length() > 0) sb.append(recursiveParts.get(0));
else sb = recursiveParts.get(0);
recursiveParts = null;
}
break;
case '\\':
now = str.charAt(++i);
default:
sb.append(now);
}
if (slash) {
if (start < (src.index = index)) slashStrs.add(substr(src.str, start, index));
return compile(ret, slashStrs.toArray(new String[slashStrs.size()]));
} else if (bracket) ret =
compile(ret, slashStrs.toArray(new String[slashStrs.size()]));
return compile(ret, substr(src.str, start, src.index = index));
}

private static String[] compile(String[] src1, String... src2) {
if (src1.length == 0 || src2.length == 0) return src1.length == 0 ? src2 : src1;
String[] ret = new String[src1.length * src2.length];
for (int i = src2.length - 1; i != -1; i--) {
int ch = src2[i].isEmpty() ? -1 : src2[i].charAt(0);
for (int j = src1.length - 1; j != -1; j--)
ret[j + i * src1.length] = src1[j].isEmpty() ? src2[i] : (src1[j]
+ (ch != ',' && ch != '.' && ch != '?' && ch != '!'
&& ch != '\'' && ch != -1 ? ' ' + src2[i] : src2[i]));
if (parts == null) {
if (recursiveParts == null) {
if (sb.length() > 0) {
if (ret.isEmpty()) ret.add(sb);
else for (StringBuilder part : ret) part.append(sb);
}
} else {
if (ret.isEmpty()) for (StringBuilder part : recursiveParts) ret.add(part.append(sb));
else {
int size = ret.size();
for (int j = 0; j < size; j++) {
StringBuilder retPart = ret.remove(j);
for (StringBuilder part : recursiveParts) {
ret.add(new StringBuilder(retPart).append(part).append(sb));
}
}
}
}
} else {
if (sb.length() > 0) {
if (recursiveParts == null) parts.add(sb);
else for (StringBuilder part : recursiveParts) parts.add(part.append(sb));
} else if (recursiveParts != null) {
for (StringBuilder part : recursiveParts) parts.add(part);
}
if (ret.isEmpty()) for (StringBuilder part : parts) ret.add(part);
else {
int size = ret.size();
for (int j = 0; j < size; j++) {
StringBuilder retPart = ret.remove(j);
for (StringBuilder part : parts) {
ret.add(new StringBuilder(retPart).append(part));
}
}
}
}
return ret;
}

private static String substr(String str, int begin, int end) {
return str.substring(begin, end).replace("\\", "");
}
}
Binary file modified SchoolManager.apk
Binary file not shown.

0 comments on commit f586b0d

Please sign in to comment.