From ce97adc7ee3d622d0dddc26d84a0cbf4d6077042 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Thu, 25 Jul 2019 15:32:53 +0100 Subject: [PATCH 01/12] #1259 Crash Report: UnsatisfiedLinkError - integrate with changes to kiwix-lib --- .../java/org/kiwix/kiwixmobile/di/modules/JNIModule.java | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/JNIModule.java b/app/src/main/java/org/kiwix/kiwixmobile/di/modules/JNIModule.java index 14ce3f6aa..9e15c1092 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/di/modules/JNIModule.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/di/modules/JNIModule.java @@ -17,6 +17,7 @@ */ package org.kiwix.kiwixmobile.di.modules; +import android.content.Context; import dagger.Module; import dagger.Provides; import javax.inject.Singleton; @@ -29,7 +30,7 @@ import org.kiwix.kiwixlib.JNIKiwix; @Module public class JNIModule { @Provides @Singleton - public JNIKiwix providesJNIKiwix() { - return new JNIKiwix(); + public JNIKiwix providesJNIKiwix(Context context) { + return new JNIKiwix(context); } } From 43305738e584687f91f793e56b78d7a3f6f4b2cd Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Wed, 7 Aug 2019 13:19:42 +0100 Subject: [PATCH 02/12] #1259 update to latest library --- app/build.gradle | 8 +------- kiwixlib/build.gradle | 24 ------------------------ kiwixlib/libs/.gitkeep | 0 kiwixlib/src/main/AndroidManifest.xml | 7 ------- 4 files changed, 1 insertion(+), 38 deletions(-) delete mode 100644 kiwixlib/build.gradle delete mode 100644 kiwixlib/libs/.gitkeep delete mode 100644 kiwixlib/src/main/AndroidManifest.xml diff --git a/app/build.gradle b/app/build.gradle index 37539c74e..8c95b288c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,13 +48,7 @@ String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] dependencies { // use jdk8 java.time backport, as long app < Build.VERSION_CODES.O implementation("com.jakewharton.threetenabp:threetenabp:1.1.1") - // Get kiwixlib online if it is not populated locally - if (file("../kiwixlib/src/main").list().length == 1) { - implementation 'org.kiwix.kiwixlib:kiwixlib:1.0.12' - } else { - implementation project(":kiwixlib") - archs = file("../kiwixlib/src/main/jniLibs").list() - } + implementation 'org.kiwix.kiwixlib:kiwixlib:5.2.0' // Android Support implementation "androidx.appcompat:appcompat:$appCompatVersion" diff --git a/kiwixlib/build.gradle b/kiwixlib/build.gradle deleted file mode 100644 index d61c875eb..000000000 --- a/kiwixlib/build.gradle +++ /dev/null @@ -1,24 +0,0 @@ -apply plugin: 'com.android.library' - -android { - compileSdkVersion 28 - - defaultConfig { - minSdkVersion 15 - targetSdkVersion 28 - testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" - } - - buildTypes { - release { - minifyEnabled false - proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' - } - } -} - -dependencies { - implementation fileTree(dir: 'libs', include: ['*.jar']) - androidTestImplementation("androidx.test.espresso:espresso-core:$espressoVersion") - testImplementation "junit:junit:$jUnitVersion" -} diff --git a/kiwixlib/libs/.gitkeep b/kiwixlib/libs/.gitkeep deleted file mode 100644 index e69de29bb..000000000 diff --git a/kiwixlib/src/main/AndroidManifest.xml b/kiwixlib/src/main/AndroidManifest.xml deleted file mode 100644 index 77b50dc6a..000000000 --- a/kiwixlib/src/main/AndroidManifest.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - - - - From 0e895b192c09d53f07ba1305b53d91ab3241f9e3 Mon Sep 17 00:00:00 2001 From: mhutti1 Date: Sun, 11 Aug 2019 16:33:13 +0200 Subject: [PATCH 03/12] #1259 Allow a local kiwix-lib aar to be used --- app/build.gradle | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 8c95b288c..0090d25cd 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -48,7 +48,14 @@ String[] archs = ['arm64-v8a', 'armeabi-v7a', 'x86', 'x86_64'] dependencies { // use jdk8 java.time backport, as long app < Build.VERSION_CODES.O implementation("com.jakewharton.threetenabp:threetenabp:1.1.1") - implementation 'org.kiwix.kiwixlib:kiwixlib:5.2.0' + + // Get kiwixlib online if it is not populated locally + if (!file("./libs").exists()) { + implementation 'org.kiwix.kiwixlib:kiwixlib:5.2.0' + } else { + implementation 'com.getkeepsafe.relinker:relinker:1.3.1' + implementation fileTree(include: ['*.aar'], dir: 'libs') + } // Android Support implementation "androidx.appcompat:appcompat:$appCompatVersion" From cb2e89a89f20937648831226f1114f396fe2634c Mon Sep 17 00:00:00 2001 From: Isaac Hutt Date: Wed, 14 Aug 2019 13:59:12 +0200 Subject: [PATCH 04/12] Add details on building with kiwix-lib --- CONTRIBUTING.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index d388dc72f..b5af9d4e7 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -58,6 +58,8 @@ If you wish to rebase you should be following the [Golden Rule](https://www.atla The default build is `debug`, with this variant you can use a debugger while developing. To install the application click the `run` button in Android Studio with the `app` configuration selected while you have a device connected. All other build types but `release` can be ignored, the `release` build is what gets uploaded to the Google Play store and can be built locally with the dummy credentials/keystore provided. +By default we fetch kiwix-lib, the key component for interacting with ZIM files from maven, but if you wish to use your own locally compiled version for testing purposes, then you can create the directory `app/libs` and place your .aar file inside it to have it used instead. + ### Testing Unit tests are located in `app/src/test` and to run them locally you From 1076a15097c42a0a374f85a30c2ae94a73b13bf0 Mon Sep 17 00:00:00 2001 From: Aditya-Sood Date: Wed, 14 Aug 2019 19:40:51 +0530 Subject: [PATCH 05/12] Add check for urls without an extension Eg: Instead of a url like .../Main_Page.html, just .../Main_Page --- .../main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java index e463ce37d..7a189e277 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java @@ -202,10 +202,10 @@ public class AddNoteDialog extends DialogFragment int rightmostDot = path.lastIndexOf('.'); if (rightmostSlash > -1 && rightmostDot > -1) { - return (path.substring(rightmostSlash + 1, rightmostDot)); + return path.substring(rightmostSlash + 1, (rightmostDot > rightmostSlash) ? rightmostDot : path.length()); } - return ""; // If couldn't find the dot and/or slash + return ""; // If couldn't find a dot and/or slash in the url } // Override onBackPressed() to respond to user pressing 'Back' button on navigation bar From 2a07a5bc65cac0231648a695a7faa4950a2e5a46 Mon Sep 17 00:00:00 2001 From: Aditya-Sood Date: Fri, 16 Aug 2019 20:37:53 +0530 Subject: [PATCH 06/12] Add null check for article --- .../kiwix/kiwixmobile/main/AddNoteDialog.java | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java index 7a189e277..33121a4c1 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java @@ -106,12 +106,16 @@ public class AddNoteDialog extends DialogFragment ZIM_NOTES_DIRECTORY = NOTES_DIRECTORY + zimNoteDirectoryName + "/"; } else { - showToast(R.string.error_filenotfound, Toast.LENGTH_LONG); - closeKeyboard(); - getFragmentManager().beginTransaction().remove(AddNoteDialog.this).commit(); + onFailureToCreateAddNoteDialog(); } } + private void onFailureToCreateAddNoteDialog() { + showToast(R.string.error_filenotfound, Toast.LENGTH_LONG); + closeKeyboard(); + getFragmentManager().beginTransaction().remove(AddNoteDialog.this).commit(); + } + @Override public @NonNull View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { @@ -185,7 +189,13 @@ public class AddNoteDialog extends DialogFragment // Returns url of the form: "content://org.kiwix.kiwixmobile.zim.base/A/Main_Page.html" String articleUrl = ((MainActivity) getActivity()).getCurrentWebView().getUrl(); - String notefileName = getTextAfterLastSlashWithoutExtension(articleUrl); + String notefileName = ""; + if (articleUrl == null) { + onFailureToCreateAddNoteDialog(); + return "Not Available"; + } else { + notefileName = getTextAfterLastSlashWithoutExtension(articleUrl); + } return (!notefileName.isEmpty()) ? notefileName : articleTitle; } From 7edb8dc185cfbcecf38427404886c5b37b23d40b Mon Sep 17 00:00:00 2001 From: Aditya-Sood Date: Fri, 16 Aug 2019 21:33:19 +0530 Subject: [PATCH 07/12] Reformat code style --- .../kiwix/kiwixmobile/main/AddNoteDialog.java | 49 +++++++++---------- 1 file changed, 23 insertions(+), 26 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java index 33121a4c1..f03348e1b 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java @@ -20,7 +20,6 @@ import android.view.inputmethod.InputMethodManager; import android.widget.EditText; import android.widget.TextView; import android.widget.Toast; - import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.appcompat.widget.Toolbar; @@ -28,20 +27,17 @@ import androidx.core.content.ContextCompat; import androidx.core.content.FileProvider; import androidx.fragment.app.DialogFragment; import androidx.fragment.app.Fragment; - -import org.kiwix.kiwixmobile.BuildConfig; -import org.kiwix.kiwixmobile.R; -import org.kiwix.kiwixmobile.data.ZimContentProvider; -import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil; - +import butterknife.BindView; +import butterknife.ButterKnife; +import butterknife.Unbinder; import java.io.BufferedReader; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; - -import butterknife.BindView; -import butterknife.ButterKnife; -import butterknife.Unbinder; +import org.kiwix.kiwixmobile.BuildConfig; +import org.kiwix.kiwixmobile.R; +import org.kiwix.kiwixmobile.data.ZimContentProvider; +import org.kiwix.kiwixmobile.utils.SharedPreferenceUtil; import static org.kiwix.kiwixmobile.utils.Constants.NOTES_DIRECTORY; @@ -55,7 +51,7 @@ import static org.kiwix.kiwixmobile.utils.Constants.NOTES_DIRECTORY; */ public class AddNoteDialog extends DialogFragment - implements ConfirmationAlertDialogFragment.UserClickListener { + implements ConfirmationAlertDialogFragment.UserClickListener { public static final String TAG = "AddNoteDialog"; @@ -91,8 +87,8 @@ public class AddNoteDialog extends DialogFragment super.onCreate(savedInstanceState); setStyle(DialogFragment.STYLE_NORMAL, - sharedPreferenceUtil.nightMode() ? R.style.AddNoteDialogStyle_Night - : R.style.AddNoteDialogStyle); + sharedPreferenceUtil.nightMode() ? R.style.AddNoteDialogStyle_Night + : R.style.AddNoteDialogStyle); // Returns name of the form ".../Kiwix/granbluefantasy_en_all_all_nopic_2018-10.zim" zimFileName = ZimContentProvider.getZimFile(); @@ -118,7 +114,7 @@ public class AddNoteDialog extends DialogFragment @Override public @NonNull View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, - @Nullable Bundle savedInstanceState) { + @Nullable Bundle savedInstanceState) { super.onCreateView(inflater, container, savedInstanceState); View view = inflater.inflate(R.layout.dialog_add_note, container, false); unbinder = ButterKnife.bind(this, view); @@ -212,7 +208,8 @@ public class AddNoteDialog extends DialogFragment int rightmostDot = path.lastIndexOf('.'); if (rightmostSlash > -1 && rightmostDot > -1) { - return path.substring(rightmostSlash + 1, (rightmostDot > rightmostSlash) ? rightmostDot : path.length()); + return path.substring( + rightmostSlash + 1, (rightmostDot > rightmostSlash) ? rightmostDot : path.length()); } return ""; // If couldn't find a dot and/or slash in the url @@ -233,14 +230,14 @@ public class AddNoteDialog extends DialogFragment void exitAddNoteDialog() { if (noteEdited) { Fragment previousInstance = getActivity().getSupportFragmentManager() - .findFragmentByTag(ConfirmationAlertDialogFragment.TAG); + .findFragmentByTag(ConfirmationAlertDialogFragment.TAG); if (previousInstance == null) { // Custom AlertDialog for taking user confirmation before closing note dialog in case of unsaved changes DialogFragment newFragment = new ConfirmationAlertDialogFragment(sharedPreferenceUtil, TAG, - R.string.confirmation_alert_dialog_message); + R.string.confirmation_alert_dialog_message); newFragment.show(getActivity().getSupportFragmentManager(), - ConfirmationAlertDialogFragment.TAG); + ConfirmationAlertDialogFragment.TAG); } } else { // Closing unedited note dialog straightaway @@ -294,13 +291,13 @@ public class AddNoteDialog extends DialogFragment private void showKeyboard() { InputMethodManager inputMethodManager = - (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } void closeKeyboard() { InputMethodManager inputMethodManager = - (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } @@ -313,7 +310,7 @@ public class AddNoteDialog extends DialogFragment if (isExternalStorageWritable()) { if (ContextCompat.checkSelfPermission(getContext(), - Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { + Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { Log.d(TAG, "WRITE_EXTERNAL_STORAGE permission not granted"); showToast(R.string.note_save_unsuccessful, Toast.LENGTH_LONG); return; @@ -392,7 +389,7 @@ public class AddNoteDialog extends DialogFragment if (noteEdited) { saveNote( - addNoteEditText.getText().toString()); // Save edited note before sharing the text file + addNoteEditText.getText().toString()); // Save edited note before sharing the text file } File noteFile = new File(ZIM_NOTES_DIRECTORY + articleNotefileName + ".txt"); @@ -404,8 +401,8 @@ public class AddNoteDialog extends DialogFragment // From Nougat 7 (API 24) access to files is shared temporarily with other apps // Need to use FileProvider for the same noteFileUri = - FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", - noteFile); + FileProvider.getUriForFile(getContext(), BuildConfig.APPLICATION_ID + ".fileprovider", + noteFile); } else { noteFileUri = Uri.fromFile(noteFile); } @@ -419,7 +416,7 @@ public class AddNoteDialog extends DialogFragment noteFileShareIntent.putExtra(Intent.EXTRA_STREAM, noteFileUri); noteFileShareIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); Intent shareChooser = Intent.createChooser(noteFileShareIntent, - getString(R.string.note_share_app_chooser_title)); + getString(R.string.note_share_app_chooser_title)); if (noteFileShareIntent.resolveActivity(getActivity().getPackageManager()) != null) { startActivity(shareChooser); From 3d7e2232d98e7f953012cb7eba2fa6b5c8f4473a Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Tue, 20 Aug 2019 15:55:23 +0100 Subject: [PATCH 08/12] #1259 update to latest library, integrate with api changes --- app/build.gradle | 9 ++++++--- .../kiwixmobile/data/ZimContentProvider.java | 18 ++++++++---------- 2 files changed, 14 insertions(+), 13 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 0090d25cd..528a22088 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -50,8 +50,8 @@ dependencies { implementation("com.jakewharton.threetenabp:threetenabp:1.1.1") // Get kiwixlib online if it is not populated locally - if (!file("./libs").exists()) { - implementation 'org.kiwix.kiwixlib:kiwixlib:5.2.0' + if (!shouldUseLocalVersion()) { + implementation 'org.kiwix.kiwixlib:kiwixlib:6.0.0' } else { implementation 'com.getkeepsafe.relinker:relinker:1.3.1' implementation fileTree(include: ['*.aar'], dir: 'libs') @@ -125,7 +125,6 @@ dependencies { // Leak canary debugImplementation 'com.squareup.leakcanary:leakcanary-android:2.0-alpha-2' - implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlinVersion" implementation "android.arch.lifecycle:extensions:1.1.1" implementation "io.objectbox:objectbox-kotlin:$objectboxVersion" @@ -138,6 +137,10 @@ dependencies { testImplementation 'androidx.arch.core:core-testing:2.0.1' } +private boolean shouldUseLocalVersion() { + file("./libs").exists() +} + // Set custom app import directory def map = [:] def custom = new File("app/src") diff --git a/app/src/main/java/org/kiwix/kiwixmobile/data/ZimContentProvider.java b/app/src/main/java/org/kiwix/kiwixmobile/data/ZimContentProvider.java index 01e305b3f..a85b17395 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/data/ZimContentProvider.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/data/ZimContentProvider.java @@ -125,7 +125,7 @@ public class ZimContentProvider extends ContentProvider { * * Note that the value returned is NOT unique for each zim file. Versions of the same wiki * (complete, nopic, novid, etc) may return the same title. - * */ + */ public static String getZimFileTitle() { if (currentJNIReader == null || zimFileName == null) { return null; @@ -409,10 +409,8 @@ public class ZimContentProvider extends ContentProvider { String fileName = uri.toString(); fileName = fileName.substring(fileName.lastIndexOf('/') + 1, fileName.length()); File f = new File(FileUtils.getFileCacheDir(getContext()), fileName); - JNIKiwixString mime = new JNIKiwixString(); - JNIKiwixString title = new JNIKiwixString(); - JNIKiwixInt size = new JNIKiwixInt(); - byte[] data = currentJNIReader.getContent(filePath, title, mime, size); + byte[] data = currentJNIReader.getContent(new JNIKiwixString(filePath), new JNIKiwixString(), + new JNIKiwixString(), new JNIKiwixInt()); FileOutputStream out = new FileOutputStream(f); out.write(data, 0, data.length); out.flush(); @@ -473,10 +471,10 @@ public class ZimContentProvider extends ContentProvider { @Override public void run() { try { - JNIKiwixString mime = new JNIKiwixString(); - JNIKiwixString title = new JNIKiwixString(); - JNIKiwixInt size = new JNIKiwixInt(); - byte[] data = currentJNIReader.getContent(articleZimUrl, title, mime, size); + final JNIKiwixString mime = new JNIKiwixString(); + final JNIKiwixInt size = new JNIKiwixInt(); + final JNIKiwixString url = new JNIKiwixString(this.articleZimUrl); + byte[] data = currentJNIReader.getContent(url, new JNIKiwixString(), mime, size); if (mime.value != null && mime.value.equals("text/css") && MainActivity.nightMode) { out.write(("img, video { \n" + " -webkit-filter: invert(1); \n" + @@ -486,7 +484,7 @@ public class ZimContentProvider extends ContentProvider { out.write(data, 0, data.length); out.flush(); - Log.d(TAG_KIWIX, "reading " + articleZimUrl + Log.d(TAG_KIWIX, "reading " + url.value + "(mime: " + mime.value + ", size: " + size.value + ") finished."); } catch (IOException | NullPointerException e) { Log.e(TAG_KIWIX, "Exception reading article " + articleZimUrl + " from zim file", From 06fcfa55d5643c6baf0204422505fb087db95cb6 Mon Sep 17 00:00:00 2001 From: Aditya-Sood Date: Wed, 21 Aug 2019 18:56:33 +0530 Subject: [PATCH 09/12] Minor refactor --- app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java index f03348e1b..aed566fd2 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java @@ -109,7 +109,7 @@ public class AddNoteDialog extends DialogFragment private void onFailureToCreateAddNoteDialog() { showToast(R.string.error_filenotfound, Toast.LENGTH_LONG); closeKeyboard(); - getFragmentManager().beginTransaction().remove(AddNoteDialog.this).commit(); + getFragmentManager().beginTransaction().remove(this).commit(); } @Override From c462f9bcc82dfbc5bd9833c9624a4f2a2abf6349 Mon Sep 17 00:00:00 2001 From: Aditya-Sood Date: Thu, 22 Aug 2019 14:18:14 +0530 Subject: [PATCH 10/12] Minor refactor --- app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java | 1 - 1 file changed, 1 deletion(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java index aed566fd2..69cbff947 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java @@ -188,7 +188,6 @@ public class AddNoteDialog extends DialogFragment String notefileName = ""; if (articleUrl == null) { onFailureToCreateAddNoteDialog(); - return "Not Available"; } else { notefileName = getTextAfterLastSlashWithoutExtension(articleUrl); } From f39802cb5eaa3404e48c7bd2465cc8de8f003336 Mon Sep 17 00:00:00 2001 From: Aditya-Sood Date: Thu, 22 Aug 2019 16:06:16 +0530 Subject: [PATCH 11/12] Fix inspection errors --- .../kiwix/kiwixmobile/main/AddNoteDialog.java | 62 ++++++++----------- 1 file changed, 27 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java index 69cbff947..886ee5d35 100644 --- a/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java +++ b/app/src/main/java/org/kiwix/kiwixmobile/main/AddNoteDialog.java @@ -69,14 +69,12 @@ public class AddNoteDialog extends DialogFragment private String zimFileName; private String zimFileTitle; private String articleTitle; - // Corresponds to "ZimFileName" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt" - private String zimNoteDirectoryName; // Corresponds to "ArticleUrl" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt" private String articleNotefileName; private boolean noteFileExists = false; - boolean noteEdited = false; // Keeps track of state of the note (whether edited since last save) + private boolean noteEdited = false; // Keeps track of state of the note (whether edited since last save) - private String ZIM_NOTES_DIRECTORY; // Stores path to directory for the currently open zim's notes + private String zimNotesDirectory; // Stores path to directory for the currently open zim's notes public AddNoteDialog(@NonNull SharedPreferenceUtil sharedPreferenceUtil) { this.sharedPreferenceUtil = sharedPreferenceUtil; @@ -97,10 +95,11 @@ public class AddNoteDialog extends DialogFragment zimFileTitle = ZimContentProvider.getZimFileTitle(); articleTitle = ((MainActivity) getActivity()).getCurrentWebView().getTitle(); - zimNoteDirectoryName = getZimNoteDirectoryName(); + // Corresponds to "ZimFileName" of "{External Storage}/Kiwix/Notes/ZimFileName/ArticleUrl.txt" + String zimNoteDirectoryName = getZimNoteDirectoryName(); articleNotefileName = getArticleNotefileName(); - ZIM_NOTES_DIRECTORY = NOTES_DIRECTORY + zimNoteDirectoryName + "/"; + zimNotesDirectory = NOTES_DIRECTORY + zimNoteDirectoryName + "/"; } else { onFailureToCreateAddNoteDialog(); } @@ -121,29 +120,22 @@ public class AddNoteDialog extends DialogFragment toolbar.setTitle(R.string.note); toolbar.setNavigationIcon(R.drawable.ic_close_white_24dp); - toolbar.setNavigationOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View v) { - closeKeyboard(); - exitAddNoteDialog(); - } + toolbar.setNavigationOnClickListener(v -> { + closeKeyboard(); + exitAddNoteDialog(); }); - toolbar.setOnMenuItemClickListener(new Toolbar.OnMenuItemClickListener() { - @Override - public boolean onMenuItemClick(MenuItem item) { + toolbar.setOnMenuItemClickListener(item -> { + switch (item.getItemId()) { + case R.id.share_note: // Opens app-chooser for sharing the note text file + shareNote(); + break; - switch (item.getItemId()) { - case R.id.share_note: // Opens app-chooser for sharing the note text file - shareNote(); - break; - - case R.id.save_note: // Saves the note as a text file - saveNote(addNoteEditText.getText().toString()); - break; - } - return true; + case R.id.save_note: // Saves the note as a text file + saveNote(addNoteEditText.getText().toString()); + break; } + return true; }); toolbar.inflateMenu(R.menu.menu_add_note_dialog); @@ -226,7 +218,7 @@ public class AddNoteDialog extends DialogFragment }; } - void exitAddNoteDialog() { + private void exitAddNoteDialog() { if (noteEdited) { Fragment previousInstance = getActivity().getSupportFragmentManager() .findFragmentByTag(ConfirmationAlertDialogFragment.TAG); @@ -257,7 +249,7 @@ public class AddNoteDialog extends DialogFragment } } - void enableSaveNoteMenuItem() { + private void enableSaveNoteMenuItem() { if (toolbar.getMenu() != null) { MenuItem saveItem = toolbar.getMenu().findItem(R.id.save_note); saveItem.setEnabled(true); @@ -267,7 +259,7 @@ public class AddNoteDialog extends DialogFragment } } - void enableShareNoteMenuItem() { + private void enableShareNoteMenuItem() { if (toolbar.getMenu() != null) { MenuItem shareItem = toolbar.getMenu().findItem(R.id.share_note); shareItem.setEnabled(true); @@ -294,13 +286,13 @@ public class AddNoteDialog extends DialogFragment inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0); } - void closeKeyboard() { + private void closeKeyboard() { InputMethodManager inputMethodManager = (InputMethodManager) getContext().getSystemService(Context.INPUT_METHOD_SERVICE); inputMethodManager.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0); } - void saveNote(String noteText) { + private void saveNote(String noteText) { /* String content of the EditText, given by noteText, is saved into the text file given by: * "{External Storage}/Kiwix/Notes/ZimFileTitle/ArticleTitle.txt" @@ -315,7 +307,7 @@ public class AddNoteDialog extends DialogFragment return; } - File notesFolder = new File(ZIM_NOTES_DIRECTORY); + File notesFolder = new File(zimNotesDirectory); boolean folderExists = true; if (!notesFolder.exists()) { @@ -353,14 +345,14 @@ public class AddNoteDialog extends DialogFragment * is displayed in the EditText field (note content area) * */ - File noteFile = new File(ZIM_NOTES_DIRECTORY + articleNotefileName + ".txt"); + File noteFile = new File(zimNotesDirectory + articleNotefileName + ".txt"); if (noteFile.exists()) { noteFileExists = true; StringBuilder contents = new StringBuilder(); try (BufferedReader input = new BufferedReader(new java.io.FileReader(noteFile))) { - String line = null; + String line; while ((line = input.readLine()) != null) { contents.append(line); @@ -379,7 +371,7 @@ public class AddNoteDialog extends DialogFragment // No action in case the note file for the currently open article doesn't exist } - void shareNote() { + private void shareNote() { /* The note text file corresponding to the currently open article, given at: * "{External Storage}/Kiwix/Notes/ZimFileTitle/ArticleTitle.txt" @@ -391,7 +383,7 @@ public class AddNoteDialog extends DialogFragment addNoteEditText.getText().toString()); // Save edited note before sharing the text file } - File noteFile = new File(ZIM_NOTES_DIRECTORY + articleNotefileName + ".txt"); + File noteFile = new File(zimNotesDirectory + articleNotefileName + ".txt"); Uri noteFileUri = null; if (noteFile.exists()) { From 7430ec9c69b4f808ff837aae48b376be2638be17 Mon Sep 17 00:00:00 2001 From: Sean Mac Gillicuddy Date: Thu, 22 Aug 2019 16:22:26 +0100 Subject: [PATCH 12/12] #1259 update kiwixlib --- app/build.gradle | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/build.gradle b/app/build.gradle index 528a22088..b889fbd00 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -51,7 +51,7 @@ dependencies { // Get kiwixlib online if it is not populated locally if (!shouldUseLocalVersion()) { - implementation 'org.kiwix.kiwixlib:kiwixlib:6.0.0' + implementation 'org.kiwix.kiwixlib:kiwixlib:6.0.2' } else { implementation 'com.getkeepsafe.relinker:relinker:1.3.1' implementation fileTree(include: ['*.aar'], dir: 'libs')