Skip to content

Commit

Permalink
Improved simple word exports.
Browse files Browse the repository at this point in the history
Now featuring description saving inside simple exports as well as
savechapter knowledge, also minor style changes and bugfixes
  • Loading branch information
litoj committed Sep 15, 2021
1 parent 541a980 commit ef1a713
Show file tree
Hide file tree
Showing 25 changed files with 455 additions and 408 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 52
versionName '1.5.2'
versionCode 53
versionName '1.6.0'
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 @@ -241,8 +241,9 @@ public GeneralPath getDefaultSubjectsDir() {
}

@Override
public OutputStream outputInternal(GeneralPath file) throws IOException {
return CONTEXT.openFileOutput(file.getName(), Context.MODE_PRIVATE);
public OutputStream outputInternal(GeneralPath file, boolean append) throws IOException {
return CONTEXT.openFileOutput(file.getName(),
append ? Context.MODE_APPEND : Context.MODE_PRIVATE);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,10 +75,10 @@ public interface BackUpdater {
}

public ExplorerStuff(OnItemActionListener l, Content onItemClick, Runnable oss, Runnable onCheck,
ViewState vs, BackLog bl, Context c, HorizontalScrollView hsv,
RecyclerView rv, LinearLayout path, ScrollView infoScroll, TextView info,
SearchView searchView, View touchOutside, AppBarLayout searchCollapser,
BackUpdater bu) {
ViewState vs, BackLog bl, Context c, HorizontalScrollView hsv,
RecyclerView rv, LinearLayout path, ScrollView infoScroll, TextView info,
SearchView searchView, View touchOutside, AppBarLayout searchCollapser,
BackUpdater bu) {
this.itemListener = l;
this.bu = bu;
content = onItemClick;
Expand Down
5 changes: 2 additions & 3 deletions Android app/app/src/main/java/com/schlmgr/gui/UriPath.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ public UriPath(Uri uri) {
}

public UriPath(Uri uri, boolean internal) {
System.out.println(uri.toString());
this.uri = uri;
original = uri.toString();
if (uri.toString().startsWith("file://"))
Expand Down Expand Up @@ -75,8 +74,8 @@ public DocumentFile getDocumentFile() {
}

@Override
public OutputStream createOutputStream() throws IOException {
return CONTEXT.getContentResolver().openOutputStream(uri);
public OutputStream createOutputStream(boolean append) throws IOException {
return CONTEXT.getContentResolver().openOutputStream(uri, "wa");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,12 +87,13 @@ public class AboutFragment extends Fragment implements ControlListener {
public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_about, container, false);
activity.getSupportActionBar().setTitle(activity.getString(R.string.app_name) + " " + BuildConfig.VERSION_NAME);
activity.getSupportActionBar().setTitle(activity.getString(R.string.app_name) + " v" + BuildConfig.VERSION_NAME);
new Thread(() -> {
versions_release.setTgl(root);
versions_beta.setTgl(root);
RecyclerView rvRelease = (RecyclerView) versions_release.toToggle;
String[][] releases = {
{"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"},
{"1.4.3", "- fixed some library issues with missing values"},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@

import static IOSystem.Formatter.defaultReacts;
import static IOSystem.Formatter.getIOSystem;
import static com.schlmgr.gui.Controller.CONTEXT;
import static com.schlmgr.gui.Controller.activity;
import static com.schlmgr.gui.Controller.dp;
import static com.schlmgr.gui.CurrentData.backLog;
Expand Down Expand Up @@ -157,30 +158,6 @@ public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
}

new Thread(() -> {
delete.setOnClickListener(v -> {
if (((SearchAdapter) backLog.adapter).selected > 0)
new ContinuePopup(getString(R.string.continue_delete), () -> {
for (int i = VS.contentAdapter.list.size() - 1; i >= 0; i--) {
HierarchyItemModel him = VS.contentAdapter.list.get(i);
if (him.isSelected()) {
if (backLog.path.isEmpty()) him.bd.destroy(null);
else {
him.parent.removeChild((Container) (him instanceof SearchItemModel ?
((SearchItemModel) him).path.get(-2)
: backLog.path.get(-2)), him.bd);
him.bd.destroy(him.parent);
}
VS.contentAdapter.list.remove(i);
}
}
if (!backLog.path.isEmpty()) CurrentData.save(backLog.path);
root.post(() -> {
VS.contentAdapter.notifyDataSetChanged();
VS.contentAdapter.selected = -1;
selectOpts.setVisibility(View.GONE);
});
});
});
reference.setOnClickListener(v -> {
int search = 0;
EasyList<? extends BasicData> list = null;
Expand Down Expand Up @@ -305,6 +282,29 @@ public View onInclude(LayoutInflater li, CreatorPopup cp) {
}));
}
});
delete.setOnClickListener(v -> {
if (((SearchAdapter) backLog.adapter).selected > 0)
new ContinuePopup(getString(R.string.continue_delete), () -> root.post(() -> {
boolean left = false;
for (int i = VS.contentAdapter.list.size() - 1; i >= 0; i--) {
HierarchyItemModel him = VS.contentAdapter.list.get(i);
if (him.isSelected()) {
if (him.bd.destroy(him.parent)) {
VS.contentAdapter.list.remove(i);
VS.contentAdapter.notifyItemRemoved(i);
} else left = true;
}
}
if (!backLog.path.isEmpty()) CurrentData.save(backLog.path);
if (VS.contentAdapter instanceof HierarchyAdapter && !backLog.path.isEmpty())
es.setInfo(backLog.path.get(-1), (Container) backLog.path.get(-2));
if (!left) {
VS.contentAdapter.selected = -1;
es.rv.postDelayed(() -> VS.contentAdapter.notifyDataSetChanged(), 200);
selectOpts.setVisibility(View.GONE);
} else Toast.makeText(CONTEXT, R.string.popup_delete_fail, Toast.LENGTH_SHORT).show();
}));
});
if (backLog.adapter instanceof SearchAdapter && VS.contentAdapter.selected > -1) {
selectOpts.setVisibility(View.VISIBLE);
for (HierarchyItemModel him : (List<? extends HierarchyItemModel>) backLog.adapter.list)
Expand Down Expand Up @@ -356,12 +356,6 @@ private void move(boolean ref) {
if (him.isSelected()) VS.pasteData.src.add(him);
for (BasicData bd : backLog.path) VS.pasteData.srcPath.add((Container) bd);
paste.setOnClickListener(v -> {
/*if (backLog.path.size() == VS.pasteData.srcPath.size()) {
int i = 0;
boolean ok = false;
for (BasicData bd : backLog.path) if (ok = bd != VS.pasteData.srcPath.get(i++)) break;
if (!ok) return;
}*/
Container npp = (Container) backLog.path.get(-2);
Container np = (Container) backLog.path.get(-1);
boolean searchNow = VS.contentAdapter.search;
Expand Down Expand Up @@ -465,14 +459,14 @@ private void setVisibleOpts() {
*/
private void tglEnabled(TextView tv, boolean enabled) {
if (tv.isEnabled() == enabled) return;
if (tv == delete)
tv.setCompoundDrawables(null, enabled ? icDelete : icDelete_disabled, null, null);
else if (tv == reference)
if (tv == reference)
tv.setCompoundDrawables(null, enabled ? icReference : icReference_disabled, null, null);
else if (tv == cut)
tv.setCompoundDrawables(null, enabled ? icCut : icCut_disabled, null, null);
else if (tv == edit)
tv.setCompoundDrawables(null, enabled ? icEdit : icEdit_disabled, null, null);
else if (tv == delete)
tv.setCompoundDrawables(null, enabled ? icDelete : icDelete_disabled, null, null);
else if (tv == paste)
tv.setCompoundDrawables(null, enabled ? icPaste : icPaste_disabled, null, null);
tv.setTextColor(enabled ? 0xFFFFFFFF : 0x66FFFFFF);
Expand Down Expand Up @@ -543,6 +537,8 @@ this, convert(new ArrayList<>(MainChapter.ELEMENTS), null),
Controller.activity.getSupportActionBar().setTitle(bd.toString());
}
if (container) {
if (VS.contentAdapter.list != null)
for (HierarchyItemModel him : VS.contentAdapter.list) him.setSelected(false);
es.rv.setAdapter(backLog.adapter = VS.contentAdapter = new HierarchyAdapter(es.rv,
this, convert(((Container) bd).getChildren(parent), (Container) bd),
this::setVisibleOpts));
Expand Down Expand Up @@ -892,10 +888,18 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
case WORD_READ:
try {
List<BasicData> currentPath = (List<BasicData>) backLog.path.clone();
defaultReacts.get(SimpleReader.class + ":success").react(
SimpleReader.simpleLoad(new UriPath(data.getData()).load(),
(Container) backLog.path.get(-1),
(Container) backLog.path.get(-2), 0, -1, -1));
Container self = (Container) backLog.path.get(-1),
par = (Container) backLog.path.get(-2);
SimpleReader content = new SimpleReader(new UriPath(data.getData()).load(), self, par);
if (backLog.adapter instanceof HierarchyAdapter) {
HierarchyAdapter ha = (HierarchyAdapter) backLog.adapter;
int old = ha.list.size();
int pos = old;
for (BasicData bd : content.added)
ha.addItem(new HierarchyItemModel(bd, self, pos++));
es.rv.post(() -> es.setInfo(self, par));
}
defaultReacts.get(SimpleReader.class + ":success").react(content.result);
CurrentData.save(currentPath);
} catch (Exception e) {
if (e instanceof IllegalArgumentException) return;
Expand All @@ -904,17 +908,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
break;
case WORD_WRITE:
try (OutputStreamWriter osw = new OutputStreamWriter(
activity.getContentResolver().openOutputStream(data.getData()),
StandardCharsets.UTF_8)) {
osw.append(SimpleWriter.writeChapter(new StringBuilder(),
(Container) backLog.path.get(-2), (Container) backLog.path.get(-1)));
Formatter.defaultReacts.get(SimpleWriter.class + ":success")
.react(backLog.path.get(-1).getName());
} catch (Exception e) {
Formatter.defaultReacts.get(ContainerFile.class + ":save")
.react(e, data.getData(), backLog.path.get(-1));
}
new SimpleWriter(new UriPath(data.getData()), new Container[]{
(Container) backLog.path.get(-1), (Container) backLog.path.get(-2)});
break;
case IMAGE_PICK:
defaultReacts.get("NotifyNewImage")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import android.view.ViewGroup;
import android.widget.CompoundButton;
import android.widget.EditText;
import android.widget.NumberPicker;
import android.widget.TextView.BufferType;

import androidx.annotation.NonNull;
Expand All @@ -18,15 +19,17 @@
import com.schlmgr.gui.list.HierarchyItemModel;

import IOSystem.Formatter;
import IOSystem.SimpleWriter;
import testing.Test;

public class SettingsFragment extends Fragment implements ControlListener {

private NumberPicker wordSplit;
private EditText amount;
private EditText time;

public View onCreateView(@NonNull LayoutInflater inflater,
ViewGroup container, Bundle savedInstanceState) {
ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_settings, container, false);

CompoundButton parse = root.findViewById(R.id.setts_him_parse);
Expand All @@ -49,6 +52,12 @@ public View onCreateView(@NonNull LayoutInflater inflater,
desc.setChecked(HierarchyItemModel.show_desc);
desc.setOnClickListener(v -> HierarchyItemModel.setShowDesc(desc.isChecked()));

wordSplit = root.findViewById(R.id.setts_word_splitter);
wordSplit.setMinValue(0);
wordSplit.setMaxValue(3);
wordSplit.setDisplayedValues(new String[]{"';'", "'='", "' = '", "' → '"});
wordSplit.setValue(getWordSplit(SimpleWriter.getWordSplitter()));

amount = root.findViewById(R.id.setts_test_amount);
amount.setText("" + Test.getAmount(), BufferType.EDITABLE);
amount.setOnFocusChangeListener((v, hasFocus) -> {
Expand Down Expand Up @@ -80,10 +89,39 @@ public View onCreateView(@NonNull LayoutInflater inflater,
return root;
}

public static int getWordSplit(String wordSplitter) {
switch (wordSplitter) {
case "=":
return 1;
case " = ":
return 2;
case " → ":
return 3;
case ";":
default:
return 0;
}
}

public static String getWordSplit(int wordSplitter) {
switch (wordSplitter) {
case 1:
return "=";
case 2:
return " = ";
case 3:
return " → ";
case 0:
default:
return ";";
}
}

@Override
public void onDestroy() {
Test.setAmount(Integer.parseInt(amount.getText().toString()));
Test.setDefaultTime(Integer.parseInt(time.getText().toString()));
SimpleWriter.setWordSplitter(getWordSplit(wordSplit.getValue()));
super.onDestroy();
}

Expand Down
26 changes: 13 additions & 13 deletions Android app/app/src/main/res/layout/fragment_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:background="@color/colorPrimaryBg">
android:background="@color/colorPrimaryBg"
android:orientation="vertical">

<include
layout="@layout/explorer"
Expand All @@ -19,17 +19,6 @@
android:orientation="horizontal"
android:visibility="gone">

<TextView
android:id="@+id/select_delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/ic_delete_disabled"
android:enabled="false"
android:text="@string/delete"
android:textAlignment="center"
android:textColor="#6FFF" />

<TextView
android:id="@+id/select_reference"
android:layout_width="0dp"
Expand Down Expand Up @@ -63,6 +52,17 @@
android:text="@string/edit"
android:textAlignment="center"
android:textColor="#6FFF" />

<TextView
android:id="@+id/select_delete"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:drawableTop="@drawable/ic_delete_disabled"
android:enabled="false"
android:text="@string/delete"
android:textAlignment="center"
android:textColor="#6FFF" />
</LinearLayout>

<LinearLayout
Expand Down
27 changes: 27 additions & 0 deletions Android app/app/src/main/res/layout/fragment_settings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,33 @@
android:text="@string/setts_show_desc"
android:textSize="18sp" />

<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_marginTop="5dp"
android:background="#3888" />

<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">

<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:minLines="3"
android:padding="5dp"
android:text="@string/setts_word_splitter"
android:textSize="18sp" />

<NumberPicker
android:id="@+id/setts_word_splitter"
android:layout_width="50dp"
android:layout_height="match_parent"
android:descendantFocusability="blocksDescendants"
/>
</LinearLayout>

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
Expand Down
2 changes: 1 addition & 1 deletion Android app/app/src/main/res/layout/popup_creator.xml
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginVertical="5dp"
android:solidColor="#AAA" />
android:descendantFocusability="blocksDescendants" />
</LinearLayout>

<View
Expand Down
Loading

0 comments on commit ef1a713

Please sign in to comment.