Skip to content

Commit 9d31a01

Browse files
committed
v1.8.1 - fixed crash on external dir use
1 parent f08189c commit 9d31a01

File tree

13 files changed

+67
-104
lines changed

13 files changed

+67
-104
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 32
10-
versionCode 59
11-
versionName '1.8.0'
10+
versionCode 60
11+
versionName '1.8.1'
1212
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1313
signingConfig signingConfigs.debug
1414
}

Android app/app/src/main/java/com/schlmgr/gui/activity/MainActivity.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ public void onCreate(Bundle savedInstanceState) {
6565
v -> c.currentControl.onClick(v));
6666
// Passing each menu ID as a set of Ids because each
6767
// menu should be considered as top level destinations.
68-
mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.menu_objects, R.id.test,
69-
R.id.menu_choose_dir, R.id.menu_options, R.id.menu_about)
68+
mAppBarConfiguration = new AppBarConfiguration.Builder(R.id.menu_objects,
69+
R.id.test, R.id.menu_options, R.id.menu_about)
7070
.setDrawerLayout(findViewById(R.id.drawer_layout)).build();
7171
navController = Navigation.findNavController(this, R.id.content_main);
7272
NavigationUI.setupActionBarWithNavController(this, navController, mAppBarConfiguration);

Android app/app/src/main/java/com/schlmgr/gui/activity/SelectDirActivity.java

-41
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,6 @@ public class SelectDirActivity extends PopupCareActivity
6464
public void onCreate(Bundle savedInstanceState) {
6565
super.onCreate(savedInstanceState);
6666
context = getApplicationContext();
67-
if (VERSION.SDK_INT >= 30) {
68-
Intent i = new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE);
69-
startActivityForResult(Intent.createChooser(i,
70-
activity.getString(R.string.action_chooser_dir)), GET_DIR);
71-
return;
72-
}
7367
setContentView(R.layout.activity_select_dir);
7468
((TextView) findViewById(R.id.bar)).setText(importing ? R.string.select_dir_import : R.string.select_dir_src);
7569
findViewById(R.id.bar_more).setOnClickListener(v -> {
@@ -286,39 +280,4 @@ public boolean onMenuItemClick(MenuItem item) {
286280
return true;
287281
}
288282

289-
@Override
290-
public void onActivityResult(int requestCode, int resultCode, Intent data) {
291-
if (resultCode == Activity.RESULT_OK) {
292-
new Thread(() -> {
293-
if (requestCode == GET_DIR) {
294-
Uri path = data.getData();
295-
CONTEXT.getContentResolver().takePersistableUriPermission(path, Intent
296-
.FLAG_GRANT_READ_URI_PERMISSION | Intent
297-
.FLAG_GRANT_WRITE_URI_PERMISSION);
298-
UriPath file = new UriPath(path, true);
299-
if (importing) {
300-
if (file.getChild("main.json") != null && file.getChild("setts.dat") != null)
301-
CurrentData.ImportedMchs.importMch(file);
302-
CurrentData.createMchs();
303-
if (backLog.path.isEmpty()) MainFragment.VS.mfInstance.setContent(null, null, 0);
304-
} else {
305-
if (Formatter.changeDir(file)) {
306-
MainFragment.VS = new MainFragment.ViewState();
307-
backLog.clear();
308-
CurrentData.createMchs();
309-
runOnUiThread(() -> Toast.makeText(
310-
context, getString(R.string.choose_dir), Toast.LENGTH_SHORT).show());
311-
} else runOnUiThread(() -> Toast.makeText(context, "Error", Toast.LENGTH_SHORT).show());
312-
}
313-
}
314-
super.onActivityResult(requestCode, resultCode, data);
315-
}, "DirAct onActivityResult").start();
316-
}
317-
super.
318-
319-
onBackPressed();
320-
321-
}
322-
323-
private static final int GET_DIR = 7;
324283
}

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

-34
This file was deleted.

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

+44-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import android.content.Intent;
1414
import android.content.res.Resources;
1515
import android.graphics.drawable.Drawable;
16+
import android.net.Uri;
17+
import android.os.Build;
1618
import android.os.Build.VERSION;
1719
import android.os.Bundle;
1820
import android.view.LayoutInflater;
@@ -850,7 +852,22 @@ public View onInclude(LayoutInflater li, CreatorPopup cp) {
850852
break;
851853
case R.id.more_import_mch:
852854
SelectDirActivity.importing = true;
853-
startActivity(new Intent(getContext(), SelectDirActivity.class));
855+
if (VERSION.SDK_INT >= 30) {
856+
startActivityForResult(Intent.createChooser(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE),
857+
activity.getString(R.string.action_chooser_dir)), GET_DIR);
858+
} else {
859+
startActivity(new Intent(getContext(), SelectDirActivity.class));
860+
}
861+
break;
862+
case R.id.more_change_dir:
863+
SelectDirActivity.importing = false;
864+
if (Build.VERSION.SDK_INT >= 30) {
865+
startActivityForResult(Intent.createChooser(new Intent(Intent.ACTION_OPEN_DOCUMENT_TREE),
866+
activity.getString(R.string.action_chooser_dir)), GET_DIR);
867+
} else {
868+
SelectDirActivity.importing = false;
869+
startActivity(new Intent(getContext(), SelectDirActivity.class));
870+
}
854871
break;
855872
case R.id.more_sf_revaluate:
856873
List<Container> currentPath = (List<Container>) backLog.path.clone();
@@ -954,6 +971,31 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
954971
defaultReacts.get("uncaught").react(Thread.currentThread(), e);
955972
}
956973
break;
974+
case GET_DIR:
975+
Uri path = data.getData();
976+
CONTEXT.getContentResolver().takePersistableUriPermission(path, Intent
977+
.FLAG_GRANT_READ_URI_PERMISSION | Intent
978+
.FLAG_GRANT_WRITE_URI_PERMISSION);
979+
UriPath file = new UriPath(path, true);
980+
if (SelectDirActivity.importing) {
981+
if (file.getChild("main.json") != null && file.getChild("setts.dat") != null)
982+
CurrentData.ImportedMchs.importMch(file);
983+
CurrentData.createMchs();
984+
if (backLog.path.isEmpty())
985+
activity.runOnUiThread(() -> MainFragment.VS.mfInstance.setContent(null, null, 0));
986+
} else {
987+
if (Formatter.changeDir(file)) {
988+
VS.pasteData = null;
989+
backLog.clear();
990+
CurrentData.createMchs();
991+
activity.runOnUiThread(() -> {
992+
MainFragment.VS.mfInstance.setContent(null, null, 0);
993+
Toast.makeText(
994+
CONTEXT, getString(R.string.choose_dir), Toast.LENGTH_SHORT).show();
995+
});
996+
} else activity.runOnUiThread(
997+
() -> Toast.makeText(CONTEXT, "Error", Toast.LENGTH_SHORT).show());
998+
}
957999
}
9581000
super.onActivityResult(requestCode, resultCode, data);
9591001
}, "MFrag onActivityResult").start();
@@ -974,6 +1016,7 @@ public void onResume() {
9741016
public static final int STORAGE_PERMISSION = 3;
9751017
public static final int IMAGE_PICK = 4;
9761018
public static final int SCH_READ = 5;
1019+
public static final int GET_DIR = 7;
9771020

9781021
public static class ViewState extends ExplorerStuff.ViewState {
9791022
private int menuRes;

Android app/app/src/main/res/layout/fragment_about.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -788,7 +788,7 @@
788788
android:layout_marginEnd="8dp"
789789
android:text="
790790
This program was developed to help people with school subjects, especially with foreign languages and biology.
791-
\n\nFor any further help contact me at [email protected]"
791+
\n\nFor any further help contact me at [email protected]"
792792
android:textSize="13sp" />
793793
</LinearLayout>
794794
</ScrollView>

Android app/app/src/main/res/menu/drawer.xml

-4
Original file line numberDiff line numberDiff line change
@@ -10,10 +10,6 @@
1010
android:id="@+id/test"
1111
android:icon="@drawable/ic_test"
1212
android:title="Test" />
13-
<item
14-
android:id="@+id/menu_choose_dir"
15-
android:icon="@drawable/ic_subjdir"
16-
android:title="@string/menu_choose_dir" />
1713
<item
1814
android:id="@+id/menu_options"
1915
android:icon="@drawable/ic_menu_settings"

Android app/app/src/main/res/menu/more_main.xml

+3
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
<item
77
android:id="@+id/more_import_mch"
88
android:title="@string/import_mch" />
9+
<item
10+
android:id="@+id/more_change_dir"
11+
android:title="@string/menu_choose_dir" />
912
<item
1013
android:id="@+id/more_sort"
1114
android:title="@string/sort">

Android app/app/src/main/res/navigation/mobile_navigation.xml

-5
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,6 @@
1717
android:label="Test"
1818
tools:layout="@layout/fragment_test" />
1919

20-
<fragment
21-
android:id="@+id/menu_choose_dir"
22-
android:name="com.schlmgr.gui.fragments.ChooseDirFragment"
23-
android:label="@string/menu_choose_dir"/>
24-
2520
<fragment
2621
android:id="@+id/menu_options"
2722
android:name="com.schlmgr.gui.fragments.SettingsFragment"

Android app/app/src/main/res/values-cs-rCZ/strings.xml

+5-5
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,18 @@
9898
\nPoznámky k položkám pište ve tvaru \'\\[poznámky k položce\\]\'.
9999
\nSlovíčka a jejich překlady oddělte pomocí \';\', \'=\', nebo \'→\'.
100100
\nPro zápis více slovíček se stejným překladem (a naopak) oddělte slovíčka zpětným lomítkem \\.
101-
\nKapitoly začínají řádkem ve tvaru \'název kapitoly \\[případné poznámky\\] {\', kapitolu ukončíte pomocí \'}\' na samostatném řádku. Přímo před otevřenou závorku můžete přidat \'§\' pro uložení kapitoly do vlastního souboru.
101+
\nKapitoly začínají řádkem ve tvaru \'název kapitoly [případné poznámky] {\', kapitolu ukončíte pomocí \'}\' na samostatném řádku. Přímo před otevřenou závorku můžete přidat \'§\' pro uložení kapitoly do vlastního souboru.
102102
\nKaždou položku pište na nový řádek, odsazení a mezery mezi jednotlivými položkami jsou libovolné.
103103
\nMožný příkladný formát:
104104
\n\nkapitola v souboru §{
105105
\n\tslovíčko 1;překlad 1
106106
\n\tslovíčko 2=překlad 2
107-
\n\tnázev podkapitoly \\[poznámky k podkapitole\\] {
108-
\n\t\tslovíčko 3 \\[poznámky\\] = překlad 3
107+
\n\tnázev podkapitoly [poznámky k podkapitole] {
108+
\n\t\tslovíčko 3 [poznámky] = překlad 3
109109
\n\t\tslovíčko 4\\slovíčko 5;překlad 4
110-
\n\t\tslovíčko 6 \\[poznámka\\] \\ slovíčko 7 → překlad 5
110+
\n\t\tslovíčko 6 [poznámka] \\ slovíčko 7 → překlad 5
111111
\n\t}
112-
\n\tslovíčko 7;překlad 1 \\[poznámka překladu\\]\\překlad 6
112+
\n\tslovíčko 7;překlad 1 [poznámka překladu]\\překlad 6
113113
\n}</string>
114114
<string name="help_search">Vyhledávání</string>
115115
<string name="help_search_how">Vyhledávání je umožňěno ve všech kapitolách a předmětech.

Android app/app/src/main/res/values/strings.xml

+6-6
Original file line numberDiff line numberDiff line change
@@ -93,21 +93,21 @@
9393
<string name="help_extra_words_export_how">Export words by opening a chapter which content you want to export and select \'Export words\' option in the more options menu. Than just select the file you want to add the current word content in. The exported words can be imported again without loss.</string>
9494
<string name="help_extra_words_import">Words importing</string>
9595
<string name="help_extra_words_import_how">You can import words from a file, it can be also structured in a simpler hierarchy. The file can contain chapters and words.
96-
\nDescription to individual items can be written directly behind the item in format like \'\\[description\\]\'.
96+
\nDescription to individual items can be written directly behind the item in format like \'[description]\'.
9797
\nWords and translates can be separated using \';\', \'=\', or \'→\'.
9898
\nWords with same translate are separated by a backward slash \'\\\'.
99-
\nChapters begin on a separate line in the following format \'chapter name \\[optional description\\] {\', end them with a single \'}\' on a separate line. For saving the chapter into an etra file, use \'§\' directly before \'{\'.
99+
\nChapters begin on a separate line in the following format \'chapter name [optional description] {\', end them with a single \'}\' on a separate line. For saving the chapter into an etra file, use \'§\' directly before \'{\'.
100100
\nEvery item should be written on a new line, spacing and indentation between them is ignored - meant only for better readability.
101101
\nPossible format example:
102102
\n\nchapter-in-file 1 §{
103103
\n\tword 1;translate 1
104104
\n\tword 2=translate 2
105-
\n\tsubchapter name \\[subchapter description\\] {
106-
\n\t\tword 3 \\[description\\] = translate 3
105+
\n\tsubchapter name [subchapter description] {
106+
\n\t\tword 3 [description] = translate 3
107107
\n\t\tword 4\\word 5;translate 4
108-
\n\t\tword 6 \\[description\\] \\ word 7 → translate 5
108+
\n\t\tword 6 [description] \\ word 7 → translate 5
109109
\n\t}
110-
\n\tword 7;translate 1 \\[description\\]\\translate 6
110+
\n\tword 7;translate 1 [description]\\translate 6
111111
\n}</string>
112112
<string name="help_search">Searching</string>
113113
<string name="help_search_how">Searching is enabled in all chapters and subjects.

Library/src/IOSystem/SimpleReader.java

+4-3
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,13 @@
1717
* Used sytnax:
1818
* <ul>
1919
* <li>chapter:
20-
* <p> name of the chapter
21-
* <p> {
22-
* <p> content of that chapter (including another chapters)
20+
* <p> name of the chapter {
21+
* <p> content of that chapter (including other chapters)
2322
* <p> }
2423
* <li>word:
2524
* <p> name\another name\more synonyms;translate\a synonym\...
25+
* <li> item description:
26+
* <p> ... [description, can contain more lines]
2627
* </ul>
2728
*
2829
* @author Josef Litoš

SchoolManager.apk

-260 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)