File open Bug Fix & Add Page System's Split By Line Mode

This commit is contained in:
Zerglrisk 2016-06-21 09:56:29 +09:00
parent 9b7de55f55
commit 3db0519ec6
8 changed files with 79 additions and 4 deletions

View File

@ -181,7 +181,7 @@ public class SelectFileActivity extends ActionBarActivity implements SearchView.
private void finishWithResult(File file) {
if (file != null) {
Uri uri = Uri.fromFile(file);
Toast.makeText(this, uri.toString(), Toast.LENGTH_SHORT).show();
//Toast.makeText(this, uri.toString(), Toast.LENGTH_SHORT).show();
setResult(RESULT_OK, new Intent().setData(uri));
finish();
} else {
@ -242,6 +242,11 @@ public class SelectFileActivity extends ActionBarActivity implements SearchView.
}
} else if (selectedFile.isDirectory()) {
//Toast.makeText(this, "its folder", Toast.LENGTH_SHORT).show();
if (mfabOkMode) {
prevposition = 0;
mfabOkMode = false;
mFab.setDrawable(getResources().getDrawable(R.drawable.ic_fab_add));
}
new UpdateList().execute(selectedFile.getAbsolutePath());
}
} else if (folderOpenMode) {

View File

@ -147,6 +147,10 @@ public final class PreferenceHelper {
return getPrefs(context).getBoolean("page_system_active", true);
}
public static boolean getSplitByLine(Context context){
return getPrefs(context).getBoolean("split_by_line", true);
}
public static boolean hasDonated(Context context) {
return getPrefs(context).getBoolean("has_donated", false);
}
@ -224,6 +228,10 @@ public final class PreferenceHelper {
getEditor(context).putBoolean("page_system_active", value).commit();
}
public static void setSplitByLine(Context context, boolean value){
getEditor(context).putBoolean("split_by_line",value).commit();
}
public static void setSendErrorReport(Context context, boolean value) {
getEditor(context).putBoolean("send_error_reports", value).commit();
}

View File

@ -54,6 +54,7 @@ public class SettingsFragment extends Fragment implements NumberPickerDialog.INu
private boolean sAutoSave;
private boolean sIgnoreBackButton;
private boolean sSplitText;
private boolean sSplitByLine;
private boolean sErrorReports;
@Override
@ -71,6 +72,7 @@ public class SettingsFragment extends Fragment implements NumberPickerDialog.INu
sAutoSave = PreferenceHelper.getAutoSave(context);
sIgnoreBackButton = PreferenceHelper.getIgnoreBackButton(context);
sSplitText = PreferenceHelper.getSplitText(context);
sSplitByLine = PreferenceHelper.getSplitByLine(context);
sErrorReports = PreferenceHelper.getSendErrorReports(context);
}
@ -80,7 +82,7 @@ public class SettingsFragment extends Fragment implements NumberPickerDialog.INu
// Our custom layout
final View rootView = inflater.inflate(R.layout.fragment_settings, container, false);
final SwitchCompat swLineNumbers, swSyntax, swWrapContent, swMonospace, swReadOnly;
final SwitchCompat swSuggestions, swAccessoryView, swStorageAccessFramework, swAutoSave, swIgnoreBackButton, swSplitText, swErrorReports;
final SwitchCompat swSuggestions, swAccessoryView, swStorageAccessFramework, swAutoSave, swIgnoreBackButton, swSplitText, swSplitByLine, swErrorReports;
swLineNumbers = (SwitchCompat) rootView.findViewById(R.id.switch_line_numbers);
swSyntax = (SwitchCompat) rootView.findViewById(R.id.switch_syntax);
@ -94,6 +96,8 @@ public class SettingsFragment extends Fragment implements NumberPickerDialog.INu
swAutoSave = (SwitchCompat) rootView.findViewById(R.id.switch_auto_save);
swIgnoreBackButton = (SwitchCompat) rootView.findViewById(R.id.switch_ignore_backbutton);
swSplitText = (SwitchCompat) rootView.findViewById(R.id.switch_page_system);
swSplitByLine = (SwitchCompat) rootView.findViewById(R.id.split_by_line);
swErrorReports = (SwitchCompat) rootView.findViewById(R.id.switch_send_error_reports);
swLineNumbers.setChecked(sLineNumbers);
@ -108,6 +112,7 @@ public class SettingsFragment extends Fragment implements NumberPickerDialog.INu
swAutoSave.setChecked(sAutoSave);
swIgnoreBackButton.setChecked(sIgnoreBackButton);
swSplitText.setChecked(sSplitText);
swSplitByLine.setChecked(sSplitByLine);
swErrorReports.setChecked(sErrorReports);
TextView fontSizeView, encodingView, extraOptionsView, themeView, goPro;
@ -259,6 +264,14 @@ public class SettingsFragment extends Fragment implements NumberPickerDialog.INu
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
PreferenceHelper.setSplitText(getActivity(), isChecked);
swSplitByLine.setEnabled(isChecked);
}
});
swSplitByLine.setOnCheckedChangeListener(new CompoundButton.OnCheckedChangeListener() {
@Override
public void onCheckedChanged(CompoundButton buttonView, boolean isChecked) {
PreferenceHelper.setSplitByLine(getActivity(), isChecked);
}
});

View File

@ -37,6 +37,8 @@ public class PageSystem {
final int charForPage = 20000;
final int firstPageChars = 50000;
final int lineForPage = 250;
this.pageSystemInterface = pageSystemInterface;
pages = new LinkedList<>();
@ -46,8 +48,9 @@ public class PageSystem {
int nextIndexOfReturn;
final int textLength = text.length();
boolean pageSystemEnabled = PreferenceHelper.getSplitText(context);
boolean splitByLineEnablec = PreferenceHelper.getSplitByLine(context);
if (pageSystemEnabled) {
if (pageSystemEnabled && !splitByLineEnablec) {
while (i < textLength) {
// first page is longer
to = i + (i == 0 ? firstPageChars : charForPage);
@ -57,14 +60,38 @@ public class PageSystem {
pages.add(text.substring(i, to));
i = to + 1;
}
if (i == 0)
pages.add("");
} else if(pageSystemEnabled && splitByLineEnablec){
int linecount = 0;
to = 0;
while (i < textLength) {
// first page is longer
nextIndexOfReturn = text.indexOf("\n", to);
if (nextIndexOfReturn > to) {
to = nextIndexOfReturn;
linecount++;
}
if (to > text.length()) {
to = text.length();
pages.add(text.substring(i, to));
i = to;
}
if (linecount >= lineForPage) {
pages.add(text.substring(i, to));
i = to;
linecount = 0;
}
to++;
}
if (i == 0)
pages.add("");
} else {
pages.add(text);
}
startingLines = new int[pages.size()];
setStartingLines();
}

View File

@ -275,6 +275,20 @@
android:paddingRight="16dp"
android:textColor="@color/navigation_drawer_button_text_color_inverted"/>
<android.support.v7.widget.SwitchCompat
android:gravity="center_vertical"
android:layout_width="match_parent"
android:layout_height="56dp"
android:text="@string/split_by_line"
android:textSize="12sp"
android:id="@id/split_by_line"
android:layout_gravity="center_horizontal"
android:paddingEnd="16dp"
android:paddingStart="16dp"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:textColor="@color/navigation_drawer_button_text_color_inverted"/>
<android.support.v7.widget.SwitchCompat
android:gravity="center_vertical"
android:layout_width="match_parent"

View File

@ -83,6 +83,7 @@
<item type="id" name="drawer_button_extra_options"/>
<item type="id" name="switch_ignore_backbutton"/>
<item type="id" name="switch_page_system"/>
<item type="id" name="split_by_line"/>
<item type="id" name="switch_send_error_reports"/>
<item type="id" name="switch_accessory_view"/>
<item type="id" name="switch_storage_access_framework"/>

View File

@ -84,4 +84,6 @@
<string name="file_cannot_be_renamed">The file cannot be renamed</string>
<string name="use_storage_access_framework">Use the "Storage Access Framework"</string>
<string name="split_by_line">Split By Line</string>
</resources>

View File

@ -61,6 +61,11 @@
android:title="@string/split_text_if_too_long"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="split_by_line"
android:title="@string/split_by_line"
android:defaultValue="true"/>
<CheckBoxPreference
android:key="send_error_reports"
android:title="@string/send_error_reports"