From 234c569cbfae7165c9f6a722d508c73e85adb5d2 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 11:16:45 +0530 Subject: [PATCH 01/12] Covert CompatFindActionModeCallback.java to Kotlin --- core/detekt_baseline.xml | 3 + .../main/CompatFindActionModeCallback.java | 226 ------------------ .../core/main/CompatFindActionModeCallback.kt | 213 +++++++++++++++++ 3 files changed, 216 insertions(+), 226 deletions(-) delete mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.java create mode 100644 core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt diff --git a/core/detekt_baseline.xml b/core/detekt_baseline.xml index 0e9fb11a2..d802b685a 100644 --- a/core/detekt_baseline.xml +++ b/core/detekt_baseline.xml @@ -12,6 +12,7 @@ LongParameterList:Repository.kt$Repository$( @param:IO private val io: Scheduler, @param:MainThread private val mainThread: Scheduler, private val bookDao: NewBookDao, private val bookmarksDao: NewBookmarksDao, private val historyDao: HistoryDao, private val languageDao: NewLanguagesDao, private val recentSearchDao: NewRecentSearchDao, private val zimReaderContainer: ZimReaderContainer ) MagicNumber:ArticleCount.kt$ArticleCount$1000.0 MagicNumber:ArticleCount.kt$ArticleCount$3 + MagicNumber:CompatFindActionModeCallback.kt$CompatFindActionModeCallback$100 MagicNumber:DownloadItem.kt$DownloadItem$1000L MagicNumber:DownloaderModule.kt$DownloaderModule$5 MagicNumber:FetchDownloadNotificationManager.kt$FetchDownloadNotificationManager$100 @@ -25,6 +26,7 @@ MagicNumber:Seconds.kt$Seconds$24 MagicNumber:Seconds.kt$Seconds$60 MagicNumber:Seconds.kt$Seconds$60.0 + NestedBlockDepth:CompatFindActionModeCallback.kt$CompatFindActionModeCallback$findAll NestedBlockDepth:FileUtils.kt$FileUtils$deleteZimFile NestedBlockDepth:ImageUtils.kt$ImageUtils$getBitmapFromView NestedBlockDepth:JNIInitialiser.kt$JNIInitialiser$loadICUData @@ -47,6 +49,7 @@ ReturnCount:FileUtils.kt$FileUtils$@Synchronized private fun deleteZimFileParts(path: String): Boolean ReturnCount:ImageUtils.kt$ImageUtils$private fun getBitmapFromView(width: Int, height: Int, viewToDrawFrom: View): Bitmap? ReturnCount:OnSwipeTouchListener.kt$OnSwipeTouchListener.GestureListener$override fun onFling( e1: MotionEvent, e2: MotionEvent, velocityX: Float, velocityY: Float ): Boolean + TooGenericExceptionCaught:CompatFindActionModeCallback.kt$CompatFindActionModeCallback$exception: Exception TooGenericExceptionCaught:JNIInitialiser.kt$JNIInitialiser$e: Exception TooGenericExceptionCaught:OnSwipeTouchListener.kt$OnSwipeTouchListener.GestureListener$exception: Exception TooGenericExceptionThrown:AdapterDelegateManager.kt$AdapterDelegateManager$throw RuntimeException("No delegate registered for $item") diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.java b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.java deleted file mode 100644 index a2432a8a8..000000000 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * Kiwix Android - * Copyright (c) 2019 Kiwix - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program. If not, see . - * - */ - -package org.kiwix.kiwixmobile.core.main; - -import android.annotation.SuppressLint; -import android.content.Context; -import android.text.Editable; -import android.text.Selection; -import android.text.Spannable; -import android.text.TextWatcher; -import android.view.LayoutInflater; -import android.view.Menu; -import android.view.MenuItem; -import android.view.View; -import android.view.inputmethod.InputMethodManager; -import android.webkit.WebView; -import android.widget.EditText; -import android.widget.TextView; -import androidx.appcompat.view.ActionMode; -import java.lang.reflect.Method; -import org.kiwix.kiwixmobile.core.R; - -public class CompatFindActionModeCallback - implements ActionMode.Callback, TextWatcher, View.OnClickListener { - - public boolean isActive; - - private View customView; - - private EditText editText; - - private TextView findResultsTextView; - - private WebView webView; - - private InputMethodManager input; - - private ActionMode actionMode; - - @SuppressLint("InflateParams") CompatFindActionModeCallback(Context context) { - customView = LayoutInflater.from(context).inflate(R.layout.webview_search, null); - editText = customView.findViewById(R.id.edit); - editText.setOnClickListener(this); - findResultsTextView = customView.findViewById(R.id.find_results); - input = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE); - isActive = false; - setText(""); - } - - public void setActive() { - isActive = true; - } - - public void finish() { - actionMode.finish(); - webView.clearMatches(); - } - - // Place text in the text field so it can be searched for. Need to press - // the find next or find previous button to find all of the matches. - public void setText(String text) { - editText.setText(text); - Spannable span = editText.getText(); - int length = span.length(); - - // Ideally, we would like to set the selection to the whole field, - // but this brings up the Text selection CAB, which dismisses this - // one. - Selection.setSelection(span, length, length); - - // Necessary each time we set the text, so that this will watch - // changes to it. - span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE); - } - - // Set the WebView to search. Must be non null, and set before calling startActionMode. - public void setWebView(WebView webView) { - if (null == webView) { - throw new AssertionError( - "WebView supplied to CompatFindActionModeCallback cannot be null"); - } - this.webView = webView; - findResultsTextView.setVisibility(View.VISIBLE); - this.webView.setFindListener((activeMatchOrdinal, numberOfMatches, isDoneCounting) -> { - String result; - if (editText.getText().toString().isEmpty()) { - result = ""; - } else if (numberOfMatches == 0) { - result = "0/0"; - } else { - result = (activeMatchOrdinal + 1) + "/" + numberOfMatches; - } - findResultsTextView.setText(result); - }); - } - - // Move the highlight to the next match. - // If true, find the next match further down in the document. - // If false, find the previous match, up in the document. - private void findNext(boolean next) { - - if (webView == null) { - throw new AssertionError("No WebView for CompatFindActionModeCallback::findNext"); - } - - webView.findNext(next); - } - - // Highlight all the instances of the string from mEditText in mWebView. - public void findAll() { - if (webView == null) { - throw new AssertionError("No WebView for CompatFindActionModeCallback::findAll"); - } - CharSequence find = editText.getText(); - if (find == null || find.length() == 0) { - webView.clearMatches(); - webView.findAllAsync(""); - } else { - webView.findAllAsync(find.toString()); - - // Enable word highlighting with reflection - try { - for (Method ms : WebView.class.getDeclaredMethods()) { - if (ms.getName().equals("setFindIsUp")) { - ms.setAccessible(true); - ms.invoke(webView, true); - break; - } - } - } catch (Exception ignored) { - - } - } - } - - // Show on screen keyboard - public void showSoftInput() { - //wait for any hidden show/hide processes to finish - editText.postDelayed(() -> { - - editText.requestFocus(); - //show the keyboard - input.showSoftInput(editText, 0); - }, 100); - } - - @Override - public void onClick(View v) { - findNext(true); - } - - @Override - public boolean onCreateActionMode(ActionMode mode, Menu menu) { - mode.setCustomView(customView); - mode.getMenuInflater().inflate(R.menu.menu_webview, menu); - actionMode = mode; - Editable edit = editText.getText(); - Selection.setSelection(edit, edit.length()); - editText.requestFocus(); - return true; - } - - @Override - public void onDestroyActionMode(ActionMode mode) { - actionMode = null; - isActive = false; - webView.clearMatches(); - input.hideSoftInputFromWindow(webView.getWindowToken(), 0); - } - - @Override - public boolean onPrepareActionMode(ActionMode mode, Menu menu) { - return false; - } - - @Override - public boolean onActionItemClicked(ActionMode mode, MenuItem item) { - if (webView == null) { - throw new AssertionError( - "No WebView for CompatFindActionModeCallback::onActionItemClicked"); - } - - input.hideSoftInputFromWindow(webView.getWindowToken(), 0); - - int itemId = item.getItemId(); - if (itemId == R.id.find_prev) { - findNext(false); - } else if (itemId == R.id.find_next) { - findNext(true); - } else { - return false; - } - return true; - } - - @Override - public void beforeTextChanged(CharSequence s, int start, int count, int after) { - // Does nothing. Needed to implement a TextWatcher. - } - - @Override - public void onTextChanged(CharSequence s, int start, int before, int count) { - findAll(); - } - - @Override - public void afterTextChanged(Editable s) { - // Does nothing. Needed to implement a TextWatcher. - } -} diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt new file mode 100644 index 000000000..3d9bf55e8 --- /dev/null +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -0,0 +1,213 @@ +/* + * Kiwix Android + * Copyright (c) 2019 Kiwix + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ +package org.kiwix.kiwixmobile.core.main + +import android.annotation.SuppressLint +import android.content.Context +import android.text.Editable +import android.text.Selection +import android.text.Spannable +import android.text.TextWatcher +import android.util.Log +import android.view.LayoutInflater +import android.view.Menu +import android.view.MenuItem +import android.view.View +import android.view.inputmethod.InputMethodManager +import android.webkit.WebView +import android.widget.EditText +import android.widget.TextView +import androidx.appcompat.view.ActionMode +import org.kiwix.kiwixmobile.core.R + +class CompatFindActionModeCallback internal constructor(context: Context) : + ActionMode.Callback, TextWatcher, View.OnClickListener { + private val tag = "CompatFindActionMode" + @JvmField var isActive: Boolean + + @SuppressLint("InflateParams") + private val customView: View = LayoutInflater.from(context).inflate(R.layout.webview_search, null) + private val editText: EditText + private val findResultsTextView: TextView + private var webView: WebView? = null + private val input: InputMethodManager + private var actionMode: ActionMode? = null + + init { + editText = customView.findViewById(R.id.edit) + editText.setOnClickListener(this) + findResultsTextView = customView.findViewById(R.id.find_results) + input = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager + isActive = false + setText("") + } + + fun setActive() { + isActive = true + } + + fun finish() { + actionMode?.finish() + webView?.clearMatches() + } + + // Place text in the text field so it can be searched for. Need to press + // the find next or find previous button to find all of the matches. + fun setText(text: String?) { + editText.setText(text) + val span: Spannable = editText.text + val length = span.length + + // Ideally, we would like to set the selection to the whole field, + // but this brings up the Text selection CAB, which dismisses this + // one. + Selection.setSelection(span, length, length) + + // Necessary each time we set the text, so that this will watch + // changes to it. + span.setSpan(this, 0, length, Spannable.SPAN_INCLUSIVE_INCLUSIVE) + } + + // Set the WebView to search. Must be non null, and set before calling startActionMode. + fun setWebView(webView: WebView?) { + if (null == webView) { + throw AssertionError( + "WebView supplied to CompatFindActionModeCallback cannot be null" + ) + } + this.webView = webView + findResultsTextView.visibility = View.VISIBLE + this.webView?.setFindListener { activeMatchOrdinal: Int, numberOfMatches: Int, _: Boolean -> + val result: String = when { + editText.text.toString().isEmpty() -> { + "" + } + numberOfMatches == 0 -> { + "0/0" + } + else -> { + (activeMatchOrdinal + 1).toString() + "/" + numberOfMatches + } + } + findResultsTextView.text = result + } + } + + // Move the highlight to the next match. + // If true, find the next match further down in the document. + // If false, find the previous match, up in the document. + private fun findNext(next: Boolean) { + if (webView == null) { + throw AssertionError("No WebView for CompatFindActionModeCallback::findNext") + } + webView?.findNext(next) + } + + // Highlight all the instances of the string from mEditText in mWebView. + fun findAll() { + if (webView == null) { + throw AssertionError("No WebView for CompatFindActionModeCallback::findAll") + } + val find: CharSequence? = editText.text + if (find == null || find.isEmpty()) { + webView?.clearMatches() + webView?.findAllAsync("") + } else { + webView?.findAllAsync("$find") + + // Enable word highlighting with reflection + try { + for (ms in WebView::class.java.declaredMethods) { + if (ms.name == "setFindIsUp") { + ms.isAccessible = true + ms.invoke(webView, true) + break + } + } + } catch (exception: Exception) { + Log.e(tag, "Exception in findAll", exception) + } + } + } + + // Show on screen keyboard + fun showSoftInput() { + // wait for any hidden show/hide processes to finish + editText.postDelayed({ + editText.requestFocus() + // show the keyboard + input.showSoftInput(editText, 0) + }, 100) + } + + override fun onClick(v: View) { + findNext(true) + } + + override fun onCreateActionMode(mode: ActionMode, menu: Menu): Boolean { + mode.customView = customView + mode.menuInflater.inflate(R.menu.menu_webview, menu) + actionMode = mode + val edit = editText.text + Selection.setSelection(edit, edit.length) + editText.requestFocus() + return true + } + + override fun onDestroyActionMode(mode: ActionMode) { + actionMode = null + isActive = false + webView?.clearMatches() + input.hideSoftInputFromWindow(webView?.windowToken, 0) + } + + override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean = false + + override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { + if (webView == null) { + throw AssertionError( + "No WebView for CompatFindActionModeCallback::onActionItemClicked" + ) + } + input.hideSoftInputFromWindow(webView?.windowToken, 0) + when (item.itemId) { + R.id.find_prev -> { + findNext(false) + } + R.id.find_next -> { + findNext(true) + } + else -> { + return false + } + } + return true + } + + override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) { + // Does nothing. Needed to implement a TextWatcher. + } + + override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) { + findAll() + } + + override fun afterTextChanged(s: Editable) { + // Does nothing. Needed to implement a TextWatcher. + } +} From 8fa8f40c83889fb3e626f643850a419577476948 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 14:22:23 +0530 Subject: [PATCH 02/12] Move field initialization outside the init block --- .../core/main/CompatFindActionModeCallback.kt | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index 3d9bf55e8..f4a5a4772 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -38,22 +38,19 @@ import org.kiwix.kiwixmobile.core.R class CompatFindActionModeCallback internal constructor(context: Context) : ActionMode.Callback, TextWatcher, View.OnClickListener { private val tag = "CompatFindActionMode" - @JvmField var isActive: Boolean + @JvmField var isActive: Boolean = false @SuppressLint("InflateParams") private val customView: View = LayoutInflater.from(context).inflate(R.layout.webview_search, null) - private val editText: EditText - private val findResultsTextView: TextView + private val editText: EditText = customView.findViewById(R.id.edit) + private val findResultsTextView: TextView = customView.findViewById(R.id.find_results) private var webView: WebView? = null - private val input: InputMethodManager + private val input: InputMethodManager = + context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager private var actionMode: ActionMode? = null init { - editText = customView.findViewById(R.id.edit) editText.setOnClickListener(this) - findResultsTextView = customView.findViewById(R.id.find_results) - input = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager - isActive = false setText("") } From 7770d6a6ae1871111d82472f46598bebed3b5b28 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 15:15:32 +0530 Subject: [PATCH 03/12] Use requireNotNull to raise exception Rename find to textToFind and clean up code --- .../core/main/CompatFindActionModeCallback.kt | 36 ++++++++----------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index f4a5a4772..42d101418 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -82,12 +82,9 @@ class CompatFindActionModeCallback internal constructor(context: Context) : // Set the WebView to search. Must be non null, and set before calling startActionMode. fun setWebView(webView: WebView?) { - if (null == webView) { - throw AssertionError( - "WebView supplied to CompatFindActionModeCallback cannot be null" - ) + this.webView = requireNotNull(webView) { + "WebView supplied to CompatFindActionModeCallback cannot be null" } - this.webView = webView findResultsTextView.visibility = View.VISIBLE this.webView?.setFindListener { activeMatchOrdinal: Int, numberOfMatches: Int, _: Boolean -> val result: String = when { @@ -109,23 +106,19 @@ class CompatFindActionModeCallback internal constructor(context: Context) : // If true, find the next match further down in the document. // If false, find the previous match, up in the document. private fun findNext(next: Boolean) { - if (webView == null) { - throw AssertionError("No WebView for CompatFindActionModeCallback::findNext") - } - webView?.findNext(next) + requireNotNull(webView) { + "No WebView for CompatFindActionModeCallback::findNext" + }.findNext(next) } // Highlight all the instances of the string from mEditText in mWebView. fun findAll() { - if (webView == null) { - throw AssertionError("No WebView for CompatFindActionModeCallback::findAll") + requireNotNull(webView) { + "No WebView for CompatFindActionModeCallback::findAll" } - val find: CharSequence? = editText.text - if (find == null || find.isEmpty()) { - webView?.clearMatches() - webView?.findAllAsync("") - } else { - webView?.findAllAsync("$find") + val textToFind: CharSequence? = editText.text + if (textToFind?.isNotEmpty() == true) { + webView?.findAllAsync("$textToFind") // Enable word highlighting with reflection try { @@ -139,6 +132,9 @@ class CompatFindActionModeCallback internal constructor(context: Context) : } catch (exception: Exception) { Log.e(tag, "Exception in findAll", exception) } + } else { + webView?.clearMatches() + webView?.findAllAsync("") } } @@ -176,10 +172,8 @@ class CompatFindActionModeCallback internal constructor(context: Context) : override fun onPrepareActionMode(mode: ActionMode, menu: Menu): Boolean = false override fun onActionItemClicked(mode: ActionMode, item: MenuItem): Boolean { - if (webView == null) { - throw AssertionError( - "No WebView for CompatFindActionModeCallback::onActionItemClicked" - ) + requireNotNull(webView) { + "No WebView for CompatFindActionModeCallback::onActionItemClicked" } input.hideSoftInputFromWindow(webView?.windowToken, 0) when (item.itemId) { From 6618309f882af5dd9bb0863b2eab2e0db76bb6a4 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 15:43:16 +0530 Subject: [PATCH 04/12] Replace for loop with firstOrNull --- .../core/main/CompatFindActionModeCallback.kt | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index 42d101418..08ae05daa 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -122,13 +122,12 @@ class CompatFindActionModeCallback internal constructor(context: Context) : // Enable word highlighting with reflection try { - for (ms in WebView::class.java.declaredMethods) { - if (ms.name == "setFindIsUp") { - ms.isAccessible = true - ms.invoke(webView, true) - break + WebView::class.java.declaredMethods + .firstOrNull { it.name == "setFindIsUp" } + ?.apply { + isAccessible = true + invoke(webView, true) } - } } catch (exception: Exception) { Log.e(tag, "Exception in findAll", exception) } From bc6f59196e986bbc29f6da7d82d06c6c967b65d4 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 15:52:01 +0530 Subject: [PATCH 05/12] Inline val result --- .../kiwixmobile/core/main/CompatFindActionModeCallback.kt | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index 08ae05daa..e26cb25cd 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -87,7 +87,7 @@ class CompatFindActionModeCallback internal constructor(context: Context) : } findResultsTextView.visibility = View.VISIBLE this.webView?.setFindListener { activeMatchOrdinal: Int, numberOfMatches: Int, _: Boolean -> - val result: String = when { + findResultsTextView.text = when { editText.text.toString().isEmpty() -> { "" } @@ -98,7 +98,6 @@ class CompatFindActionModeCallback internal constructor(context: Context) : (activeMatchOrdinal + 1).toString() + "/" + numberOfMatches } } - findResultsTextView.text = result } } From a02fb0f4dddd8a32a7a0da305b21a3e024f423c7 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 16:21:03 +0530 Subject: [PATCH 06/12] Remove braces from when clause --- .../core/main/CompatFindActionModeCallback.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index e26cb25cd..008799e78 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -88,15 +88,9 @@ class CompatFindActionModeCallback internal constructor(context: Context) : findResultsTextView.visibility = View.VISIBLE this.webView?.setFindListener { activeMatchOrdinal: Int, numberOfMatches: Int, _: Boolean -> findResultsTextView.text = when { - editText.text.toString().isEmpty() -> { - "" - } - numberOfMatches == 0 -> { - "0/0" - } - else -> { - (activeMatchOrdinal + 1).toString() + "/" + numberOfMatches - } + editText.text.toString().isEmpty() -> "" + numberOfMatches == 0 -> "0/0" + else -> "${(activeMatchOrdinal + 1)}/$numberOfMatches" } } } From 9f00d4e1521f39b88b9d4c9ffc85cc22e37f2707 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 16:45:42 +0530 Subject: [PATCH 07/12] Replace apply with let --- .../kiwixmobile/core/main/CompatFindActionModeCallback.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index 008799e78..b454f56d9 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -117,9 +117,9 @@ class CompatFindActionModeCallback internal constructor(context: Context) : try { WebView::class.java.declaredMethods .firstOrNull { it.name == "setFindIsUp" } - ?.apply { - isAccessible = true - invoke(webView, true) + ?.let { method -> + method.isAccessible = true + method.invoke(webView, true) } } catch (exception: Exception) { Log.e(tag, "Exception in findAll", exception) From 709614d7768fe1b3ec4026f7539912a60dc064b0 Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 16:49:32 +0530 Subject: [PATCH 08/12] Remove unnecessary parentheses --- .../kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index b454f56d9..c2b9dbc35 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -90,7 +90,7 @@ class CompatFindActionModeCallback internal constructor(context: Context) : findResultsTextView.text = when { editText.text.toString().isEmpty() -> "" numberOfMatches == 0 -> "0/0" - else -> "${(activeMatchOrdinal + 1)}/$numberOfMatches" + else -> "${activeMatchOrdinal + 1}/$numberOfMatches" } } } From f5a734f97c2b6d1bc815ac76f10433f59ebbc62b Mon Sep 17 00:00:00 2001 From: Abdul Wadood Date: Thu, 22 Oct 2020 17:08:35 +0530 Subject: [PATCH 09/12] Remove unnecessary parentheses from when --- .../core/main/CompatFindActionModeCallback.kt | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt index c2b9dbc35..6a0713911 100644 --- a/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt +++ b/core/src/main/java/org/kiwix/kiwixmobile/core/main/CompatFindActionModeCallback.kt @@ -169,15 +169,9 @@ class CompatFindActionModeCallback internal constructor(context: Context) : } input.hideSoftInputFromWindow(webView?.windowToken, 0) when (item.itemId) { - R.id.find_prev -> { - findNext(false) - } - R.id.find_next -> { - findNext(true) - } - else -> { - return false - } + R.id.find_prev -> findNext(false) + R.id.find_next -> findNext(true) + else -> return false } return true } From 3613e3da83e27deb675c2e2d61857a066a7f6b51 Mon Sep 17 00:00:00 2001 From: "translatewiki.net" Date: Thu, 29 Oct 2020 13:19:57 +0100 Subject: [PATCH 10/12] Localisation updates from https://translatewiki.net. --- app/src/main/res/values-diq/strings.xml | 3 +++ core/src/main/res/values-diq/strings.xml | 15 ++++++++++++++- core/src/main/res/values-iw/strings.xml | 1 + core/src/main/res/values-ku/strings.xml | 2 +- core/src/main/res/values-sv/strings.xml | 7 +++++++ core/src/main/res/values-zgh/strings.xml | 6 +++--- 6 files changed, 29 insertions(+), 5 deletions(-) diff --git a/app/src/main/res/values-diq/strings.xml b/app/src/main/res/values-diq/strings.xml index f71130e0b..6f4f53459 100644 --- a/app/src/main/res/values-diq/strings.xml +++ b/app/src/main/res/values-diq/strings.xml @@ -1,9 +1,12 @@ Sistemê dosyay şıma 4GB ra cori rê peşti nêdana Sistemê dosyaya şıma heta 4GB vıraştışi hesneyê Dosya nêabiye. Kerem kerê ena dosyay Kıtabgahê Taba Cihazi de cı geyre + Doaya bar kerê + Dosya bıgêrê diff --git a/core/src/main/res/values-diq/strings.xml b/core/src/main/res/values-diq/strings.xml index 4404851b6..b8888d37e 100644 --- a/core/src/main/res/values-diq/strings.xml +++ b/core/src/main/res/values-diq/strings.xml @@ -30,6 +30,7 @@ Kanalê xızmeti Hotspot Serkewtışê hotspoti nêbiyo Ravêrê eyaranê Wi-Fi + Gırebiyayış biyo red Hotspoto gureyneyino Veror kıtaba weçinê Server nêserniyayo. Kerem ke hotspot ake @@ -38,10 +39,11 @@ Server hewl vındarnayo Hotspot abiya Cêr de lokal detayê hotspoti deyaye.\nSSID: %1$s\nRavêrdış: %2$s + Server de depo kerde dosyayan weçinê Server gureyneyino Telimatê meymandariya kıtaban Gırey Wi-fi tesbit biya - Serva gureynayışê vêri WIFI hotspoti menuel akerê + Seba ena xısusiyeti gureynayışi rê gani veri hotspotê WIFI peydeatana akerê ya zi esas cihaz u gırote cihazi eyni torra Wi-Fi gırebiyayışê cı kontrol kerê. RAVÊR Şİ Heqa Hotspot/server eleqeyın rocaney . Kiwix Hotspot @@ -197,6 +199,7 @@ Gıreyin nêbiya %s ya wa dosya transfer vo? Transferê dosya biyo temam + Zey pêyan cıgeyre Cihazê Şıma: NEZDI CİHAZİ TRANSFERÊ DOSYAYAN @@ -218,11 +221,21 @@ Veror pêro wa bıesterneyo? Weçinaye veror wa bıesteriyo? İşareti pêro wa bıesteriyo? + Weçineyaye nışani wa bıesteriyê? Akerde Racınaye Otomatik + Rapora teşhisi bırışê + Detayê Sistemê Dosya + Rapora Teşhisi %d%% Nazdiyiya metini Taba newiye de ake Wanayoğ + Akerde kıtab çıniyo + Kıtabxaney akerê + Tab peyser ard + Antergey akerê + Antergey bıqefelne + Zerrek seni rocane beno? diff --git a/core/src/main/res/values-iw/strings.xml b/core/src/main/res/values-iw/strings.xml index 7629af7f1..eb7392998 100644 --- a/core/src/main/res/values-iw/strings.xml +++ b/core/src/main/res/values-iw/strings.xml @@ -228,6 +228,7 @@ שגיאה חמורה! נא לנסות לכבות ולהדליק מחדש את ה־P2P בווייפיי החיבור נכשל נדרשת הרשאת גישה באנדרואיד כדי לאפשר ליישום לזהות מכשירים עמיתים + נדרש אישור לגשת למיקום על ידי Android כדי לאפשרים ליישומון לאחסן קובצי Zim לא ניתן לאתר מגשירים עמיתים ללא הרשאות מיקום לא ניתן לגשת לקובצי zim ללא הרשאות אחסון נא להפעיל מיקום כדי לאפשר זיהוי עמיתים diff --git a/core/src/main/res/values-ku/strings.xml b/core/src/main/res/values-ku/strings.xml index dd22d0abb..f36f7737d 100644 --- a/core/src/main/res/values-ku/strings.xml +++ b/core/src/main/res/values-ku/strings.xml @@ -245,7 +245,7 @@ Rewş Hemû notan ji hemû gotaran bibe Temamiya notan paqij bike - Mezinahiya nivîsê bi bilindkirinên 25\% biguherîne. + Mezinahiya nivîsê bi bilindkirinên 25% biguherîne. Wêne Vîdeo Tenê Nivîs diff --git a/core/src/main/res/values-sv/strings.xml b/core/src/main/res/values-sv/strings.xml index 5c61f3e14..9b2e4212c 100644 --- a/core/src/main/res/values-sv/strings.xml +++ b/core/src/main/res/values-sv/strings.xml @@ -263,5 +263,12 @@ %d%% Text-zoomning Öppna i ny flik + Läsare + Inga öppnade böcker + Öppna bibliotek Fliken återställdes + Öppna sidomeny + Stäng sidomeny + Hur uppdaterar man innehåll? + För att uppdatera innehåll (en zim-fil) behöver du ladda ned den fullständig senaste versionen samma innehåll. Du kan göra det via nedladdningsavsnittet. diff --git a/core/src/main/res/values-zgh/strings.xml b/core/src/main/res/values-zgh/strings.xml index 4d1dba0b0..e650393c9 100644 --- a/core/src/main/res/values-zgh/strings.xml +++ b/core/src/main/res/values-zgh/strings.xml @@ -16,7 +16,7 @@ ⴷⴷⵓ ⵖⵔ ⵜⵉⵙⵖⴰⵍ ⵏ ⵓⵡⵉⴼⵉ ⵙⴽⵏ ⵓⵎⵍⴰⵏ - ⵜⴰⵡⵉⵍⴰ + ⵜⴰⵍⵇⵇⵎⵜ ⴰⵖⵓⵍ ⵙ ⵓⴼⵍⵍⴰ ⵜⵓⵜⵍⴰⵢⵜ ⵙⵜⵉ ⵜⵓⵜⵍⴰⵢⵜ @@ -46,7 +46,7 @@ ⵙⴱⴷⴷ ⵙⴱⴱⴷ ⴰⴳⵏⵙⴰⵏ - ⴱⵕⵕⴰ + ⴰⴱⵕⵕⴰⵏⵉ ⵢⴰⵀ ⵓⵀⵓ ⵙⴱⴷⴷ ⴰⴳⴰⵎ? @@ -57,7 +57,7 @@ ⴰⵥⵍⵎⴰⴹ ⴰⵙⵙⴰ ⴰⵙⵙⵏⵏⴰⴹ - ⴰⴷ ⵙⵍ ⵓⵔ ⵜⵙⵇⵙⴰⴷ + ⵓⵙⴰⵔ ⵜⵙⵇⵙⴰⴷ ⵜⵓⵜⵍⴰⵜⵉⵏ ⵉⵜⵜⵓⵙⵜⵢⵏ: ⵜⵓⵜⵍⴰⵢⵉⵏ ⵢⴰⴹⵏⵉⵏ: ⴰⵙⴽⵙⵍ ⴰⵎⴰⵢⵏⵓ From 6e7e1c8776d80abb24707cc7c8d531b062060609 Mon Sep 17 00:00:00 2001 From: dhruvrauthan Date: Sun, 1 Nov 2020 22:10:48 +0530 Subject: [PATCH 11/12] Fixed typo in DESIGN.md --- DESIGN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/DESIGN.md b/DESIGN.md index 0990f5950..c2ec13fed 100644 --- a/DESIGN.md +++ b/DESIGN.md @@ -39,7 +39,7 @@ Text should contrast well, use the correct weight and size to present content as Views using the same style often use different text style. Therefore text styles, and view styles are seperated and can be used simultaneously. To keep an android application consistent in style, thirteen text style attributes should be defined. These style attributes can be generated ([Material Design type scale generator](https://material.io/design/typography/the-type-system.html#type-scale)), or defined by editing `core/../values/type.xml`. -All text should have a text style to simplifiy appearance changes. To set a text style, simply set the `textAppearance` property using one of the thirteen text style attributes from `core/../values/type.xml`. Text can also be grouped if they are related and uses the same text style. This grouping can be done by creating a style that inherits, or sets a specific text appearance. E.x. `