Skip to content

Commit

Permalink
Fixed QPyNotebook issue
Browse files Browse the repository at this point in the history
  • Loading branch information
riverfor committed Feb 6, 2020
1 parent b5e05b2 commit 7be0476
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 125 deletions.
7 changes: 2 additions & 5 deletions qpysdk/src/main/java/org/qpython/qpysdk/QPySDK.java
Original file line number Diff line number Diff line change
Expand Up @@ -276,7 +276,7 @@ public void extractRes(final String resource, File target, boolean force) {
Log.d(TAG, "NO EXTRACT");

}
if (resource.startsWith("private")) {
if (resource.startsWith("private") || resource.startsWith("notebook")) {
chmodX();
}
}
Expand Down Expand Up @@ -338,12 +338,9 @@ public void extractRes2(final String resource, File target) {
}
}

if (resource.startsWith("private"))

{
if (resource.startsWith("private") || resource.startsWith("notebook")) {
chmodX();
}

}

private void chmodX () {
Expand Down
Binary file modified qpython/src/main/assets/notebook3.mp3
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -365,6 +365,9 @@ private void initQPy(boolean py3) {
qpysdk.extractRes(py3?"private31":"private1", HomeMainActivity.this.getFilesDir());
qpysdk.extractRes(py3?"private32":"private2", HomeMainActivity.this.getFilesDir());
qpysdk.extractRes(py3?"private33":"private3", HomeMainActivity.this.getFilesDir());
if (py3) {
qpysdk.extractRes("notebook3", HomeMainActivity.this.getFilesDir());
}
File externalStorage = new File(Environment.getExternalStorageDirectory(), "qpython");
FileHelper.createDirIfNExists(externalStorage + "/cache");
FileHelper.createDirIfNExists(externalStorage + "/log");
Expand Down
130 changes: 11 additions & 119 deletions qpython/src/main/java/org/qpython/qpy/main/fragment/SettingFragment.java
Original file line number Diff line number Diff line change
Expand Up @@ -254,54 +254,6 @@ private void initListener() {
return false;
});

// notebook_res.setOnPreferenceClickListener(preference -> {
// Log.d(TAG, "notebook_res.setOnPreferenceClickListener");
//
// installNotebook();
// return false;
//
// });

// if (isQPycRelease(false)) {
// update_qpy3.setSummary(getString(R.string.choose_py3_inter));
// } else {
// update_qpy3.setSummary(getString(R.string.install_py3_first));
//
// }
// if (isQPycRelease(true)) {
// update_qpy2compatible.setSummary(getString(R.string.choose_py2compatible_inter));
// } else {
// update_qpy2compatible.setSummary(getString(R.string.install_py2compatible_first));
// }

// update_qpy2compatible.setOnPreferenceClickListener(preference -> {
//
// new AlertDialog.Builder(getActivity(), R.style.MyDialog)
// .setTitle(R.string.notice)
// .setMessage(R.string.install_py2compatible_hint)
// .setPositiveButton(R.string.download_it, (dialog1, which)->getQPYC(true))
// .setNegativeButton(R.string.cancel, (dialog1, which) -> dialog1.dismiss())
// .create()
// .show();
//
//
//
// return false;
// });

// update_qpy3.setOnPreferenceClickListener(preference -> {
// Log.d(TAG, "update_qpy3.setOnPreferenceClickListener");
// new AlertDialog.Builder(getActivity(), R.style.MyDialog)
// .setTitle(R.string.notice)
// .setMessage(R.string.install_py3_hint)
// .setPositiveButton(R.string.download_it, (dialog1, which)->getQPYC(false))
// .setNegativeButton(R.string.cancel, (dialog1, which) -> dialog1.dismiss())
// .create()
// .show();
//
// return false;
//
// });
if (!NAction.isQPy3(getActivity())) {
notebook_run.setSummary(getString(R.string.notebook_py3_support));
notebook_run.setEnabled(false);
Expand All @@ -310,29 +262,13 @@ private void initListener() {
notebook_run.setChecked(NotebookUtil.isNBSrvSet(getActivity()));

notebook_run.setOnPreferenceChangeListener((preference, newValue) -> {

if (NotebookUtil.isNotebookLibInstall(getActivity())){

if ((boolean)newValue) {
NotebookUtil.startNotebookService2(getActivity());

} else {
NotebookUtil.killNBSrv(getActivity());
}
notebook_page.setSummary(NotebookUtil.isNotebookLibInstall(getActivity())?R.string.notebook_installed : R.string.notebook_not_started);

if ((boolean)newValue) {
NotebookUtil.startNotebookService2(getActivity());

} else {

new AlertDialog.Builder(getActivity(), R.style.MyDialog)
.setTitle(R.string.notice)
.setMessage(R.string.install_notebook_first)
.setPositiveButton(R.string.ok, (dialog1, which) -> releaseNotebook(preference))
.create()
.show();
notebook_run.setChecked(false);
return false;
NotebookUtil.killNBSrv(getActivity());
}
notebook_page.setSummary(NotebookUtil.isNotebookEnable(getActivity())?R.string.notebook_installed : R.string.notebook_not_started);

return true;
});
Expand All @@ -346,41 +282,10 @@ private void initListener() {
return false;
});

// py2compatible.setOnPreferenceClickListener(preference -> {
// Log.d(TAG, "py2.setOnPreferenceClickListener");
// NotebookUtil.killNBSrv(getActivity());
//
// if (!isQPycRelease(true)) {
// new AlertDialog.Builder(getActivity(), R.style.MyDialog)
// .setTitle(R.string.notice)
// .setMessage(R.string.install_py2compatible_first)
// .setPositiveButton(R.string.ok, (dialog1, which) -> dialog1.dismiss())
// .create()
// .show();
//
// } else {
// NotebookUtil.killNBSrv(getActivity());
//
// releasePython2Compatable(preference);
// }
// return false;
// });

py3.setOnPreferenceClickListener(preference -> {
// if (!isQPycRelease(false)) {
//
// new AlertDialog.Builder(getActivity(), R.style.MyDialog)
// .setTitle(R.string.notice)
// .setMessage(R.string.install_py3_first)
// .setPositiveButton(R.string.ok, (dialog1, which) -> dialog1.dismiss())
// .create()
// .show();
//
// } else {
NotebookUtil.killNBSrv(getActivity());

releasePython3(preference);
// }
NotebookUtil.killNBSrv(getActivity());
releasePython3(preference);

return false;
});

Expand Down Expand Up @@ -751,9 +656,11 @@ private void releasePython3(Preference preference) {
qpysdk.extractRes("private31", getActivity().getFilesDir(), true);
qpysdk.extractRes("private32", getActivity().getFilesDir(), true);
qpysdk.extractRes("private33", getActivity().getFilesDir(),true);
qpysdk.extractRes("notebook3", getActivity().getFilesDir(), true);

File externalStorage = new File(Environment.getExternalStorageDirectory(), "qpython");

qpysdk.extractRes("public", new File(externalStorage + "/lib"));
qpysdk.extractRes("publi3c", new File(externalStorage + "/lib"));

subscriber.onNext(true);
subscriber.onCompleted();
Expand Down Expand Up @@ -1020,19 +927,6 @@ public void complete(String name, File installer) {
} catch (Exception e) {

}
// try {
// if (ispy2compatible) {
// update_qpy2compatible.setSummary(getString(R.string.choose_py2compatible_inter));
//
// } else {
// update_qpy3.setSummary(getString(R.string.choose_py3_inter));
// }
//
// Toast.makeText(App.getContext(), R.string.file_downloaded, Toast.LENGTH_SHORT).show();
// } catch (Exception e) {
//
// }

}

@Override
Expand Down Expand Up @@ -1066,9 +960,7 @@ private boolean isQPycRelease(boolean ispy2compatible) {
}
return isRelease;
}




private void removeQPyc2Core() {
Log.d(TAG, "removeQPyc2Core");
String files = getActivity().getFilesDir().getAbsolutePath();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,8 @@ public static boolean isNotebookEnable(Context context) {
*/
public static boolean isNotebookInstall(Context context) {
if (NAction.isQPy3(context)) {
return new File(RELEASE_PATH, context.getString(R.string.notebook3libs_file_name)).exists();
return true;
//return new File(RELEASE_PATH, context.getString(R.string.notebook3libs_file_name)).exists();

} else {
return new File(RELEASE_PATH, context.getString(R.string.notebook2libs_file_name)).exists();
Expand Down

0 comments on commit 7be0476

Please sign in to comment.