diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java b/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java index 309e87ab8..e42bd15e9 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/ThreadDisplayFragment.java @@ -112,6 +112,7 @@ import com.ferg.awfulapp.webview.WebViewJsInterface; import com.ferg.awfulapp.widget.PageBar; import com.ferg.awfulapp.widget.PagePicker; +import com.ferg.awfulapp.widget.WebViewSearchBar; import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayout; import com.orangegangsters.github.swipyrefreshlayout.library.SwipyRefreshLayoutDirection; @@ -549,9 +550,7 @@ public boolean onOptionsItemSelected(MenuItem item) { copyThreadURL(null); break; case R.id.find: - if (mThreadView != null) { - this.mThreadView.showFindDialog(null, true); - } + ((WebViewSearchBar) item.getActionView()).setWebView(mThreadView); break; case R.id.keep_screen_on: this.toggleScreenOn(); diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/util/ViewExt.kt b/Awful.apk/src/main/java/com/ferg/awfulapp/util/ViewExt.kt index cabe1ec53..4b9f065b0 100644 --- a/Awful.apk/src/main/java/com/ferg/awfulapp/util/ViewExt.kt +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/util/ViewExt.kt @@ -3,6 +3,7 @@ package com.ferg.awfulapp.util import android.app.Activity import android.support.v4.app.Fragment import android.view.View +import android.view.ViewGroup fun View.isVisible() = (this.visibility == View.VISIBLE) @@ -28,4 +29,7 @@ fun Fragment.bind(resId: Int): Lazy = lazy(LazyThreadSafetyMode.NONE) { view!!.findViewById(resId) } fun Activity.bind(resId: Int): Lazy = - lazy(LazyThreadSafetyMode.NONE) { findViewById(resId) } \ No newline at end of file + lazy(LazyThreadSafetyMode.NONE) { findViewById(resId) } + +fun ViewGroup.bind(resId: Int): Lazy = + lazy(LazyThreadSafetyMode.NONE) { findViewById(resId) } \ No newline at end of file diff --git a/Awful.apk/src/main/java/com/ferg/awfulapp/widget/WebViewSearchBar.kt b/Awful.apk/src/main/java/com/ferg/awfulapp/widget/WebViewSearchBar.kt new file mode 100644 index 000000000..568dbd6a8 --- /dev/null +++ b/Awful.apk/src/main/java/com/ferg/awfulapp/widget/WebViewSearchBar.kt @@ -0,0 +1,94 @@ +package com.ferg.awfulapp.widget + +import android.content.Context +import android.support.v7.view.CollapsibleActionView +import android.text.Editable +import android.text.TextWatcher +import android.util.AttributeSet +import android.view.LayoutInflater +import android.view.inputmethod.InputMethodManager +import android.webkit.WebView +import android.widget.EditText +import android.widget.ImageButton +import android.widget.LinearLayout +import android.widget.TextView +import com.ferg.awfulapp.R +import com.ferg.awfulapp.util.bind +import kotlin.properties.Delegates + + +/** + * Created by baka kaba on 24/02/2020. + * + * A simple widget for searching a provided [webView]. + * + * Replaces the in-built find toolbar in the Webview class which is fully broken at this point. + * Set [webView] and text entered into the search bar will be forwarded to its search system. This + * implements [CollapsibleActionView] so it can be used as an expanding menu item that appears in + * the toolbar, and cleans up after itself once closed. + * + * Implemented as a LinearLayout because ConstraintLayout wasn't playing nice with the textbox filling + * the available area. + */ + +class WebViewSearchBar @JvmOverloads constructor( + context: Context, + attrs: AttributeSet? = null, + defStyleAttr: Int = 0 +) : LinearLayout(context, attrs, defStyleAttr), WebView.FindListener, CollapsibleActionView { + + private val nextButton: ImageButton by bind(R.id.web_view_search_next_result) + private val prevButton: ImageButton by bind(R.id.web_view_search_prev_result) + private val searchBox: EditText by bind(R.id.web_view_search_text) + private val resultCount: TextView by bind(R.id.webview_search_result_count) + + /** The webview this widget will attempt to search in */ + var webView by Delegates.observable(null) { _, _, new -> new?.setFindListener(this) } + + init { + LayoutInflater.from(context) + .inflate(R.layout.webview_search_bar, this, true) + searchBox.addTextChangedListener(object : TextWatcher { + override fun afterTextChanged(s: Editable?) { + onTextChanged() + } + + override fun beforeTextChanged(s: CharSequence?, start: Int, count: Int, after: Int) {} + + override fun onTextChanged(s: CharSequence?, start: Int, before: Int, count: Int) {} + + }) + nextButton.setOnClickListener { webView?.findNext(true) } + prevButton.setOnClickListener { webView?.findNext(false) } + } + + /** Called when the text in the search box changes */ + private fun onTextChanged() { + // don't pass null to #findAllAsync no matter what it claims, those NPEs are why I had to write this + webView?.findAllAsync(searchBox.text?.toString() ?: "") + } + + override fun onFindResultReceived(activeMatchOrdinal: Int, numberOfMatches: Int, isDoneCounting: Boolean) { + resultCount.text = when { + searchBox.text.isEmpty() -> "" + numberOfMatches == 0 -> "0/0" + else -> "${activeMatchOrdinal + 1}/$numberOfMatches" + } + } + + override fun onActionViewExpanded() { + searchBox.requestFocus() + // need to delay this call for... reasons? this makes the keyboard pop up reliably though + searchBox.postDelayed({ + val imm = context.getSystemService(Context.INPUT_METHOD_SERVICE) as InputMethodManager? + imm?.showSoftInput(searchBox, InputMethodManager.SHOW_IMPLICIT) + }, 100) + } + + override fun onActionViewCollapsed() { + // clean up because we're only getting hidden + searchBox.text.clear() + searchBox.clearFocus() + webView?.clearMatches() + } +} \ No newline at end of file diff --git a/Awful.apk/src/main/res/drawable/expander_group.xml b/Awful.apk/src/main/res/drawable/expander_group.xml deleted file mode 100644 index 0119f6c7f..000000000 --- a/Awful.apk/src/main/res/drawable/expander_group.xml +++ /dev/null @@ -1,7 +0,0 @@ - - - - diff --git a/Awful.apk/src/main/res/drawable/ic_expand_more.xml b/Awful.apk/src/main/res/drawable/ic_expand_more.xml index 97e34f216..af5eff9d3 100644 --- a/Awful.apk/src/main/res/drawable/ic_expand_more.xml +++ b/Awful.apk/src/main/res/drawable/ic_expand_more.xml @@ -1,9 +1,9 @@ + android:width="24dp" + android:height="24dp" + android:viewportWidth="24.0" + android:viewportHeight="24.0"> + android:pathData="M16.59,8.59L12,13.17 7.41,8.59 6,10l6,6 6,-6z" /> diff --git a/Awful.apk/src/main/res/layout/forum_index_item.xml b/Awful.apk/src/main/res/layout/forum_index_item.xml index ca6463a10..d4b9d9bb6 100644 --- a/Awful.apk/src/main/res/layout/forum_index_item.xml +++ b/Awful.apk/src/main/res/layout/forum_index_item.xml @@ -41,10 +41,13 @@ android:layout_height="20dp" android:layout_gravity="center" android:contentDescription="@string/show_and_hide_subforums" + android:scaleType="fitCenter" + android:scaleX="1.3" + android:scaleY="1.3" android:tint="?primaryPostFontColor" android:visibility="visible" app:srcCompat="@drawable/ic_expand_more" - tools:ignore="MissingPrefix"/> + tools:ignore="MissingPrefix" /> diff --git a/Awful.apk/src/main/res/layout/private_message_fragment.xml b/Awful.apk/src/main/res/layout/private_message_fragment.xml index 2198766cf..c682a7281 100644 --- a/Awful.apk/src/main/res/layout/private_message_fragment.xml +++ b/Awful.apk/src/main/res/layout/private_message_fragment.xml @@ -53,11 +53,12 @@ android:id="@+id/hide_message" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:layout_alignParentTop="true" android:layout_alignParentEnd="true" android:layout_alignParentRight="true" - android:layout_alignParentTop="true" + android:scaleType="center" app:srcCompat="@drawable/ic_expand_more" - tools:ignore="MissingPrefix"/> + tools:ignore="MissingPrefix" /> + + + + + + + + + + + + + \ No newline at end of file diff --git a/Awful.apk/src/main/res/menu/post_menu.xml b/Awful.apk/src/main/res/menu/post_menu.xml index d04b241e6..b4b5e5ee1 100644 --- a/Awful.apk/src/main/res/menu/post_menu.xml +++ b/Awful.apk/src/main/res/menu/post_menu.xml @@ -42,7 +42,8 @@ android:id="@+id/find" android:icon="@drawable/ic_find_in_page_dark" android:title="@string/find" - app:showAsAction="never" + app:showAsAction="never|collapseActionView" + app:actionViewClass="com.ferg.awfulapp.widget.WebViewSearchBar" /> Attach username to crash reports + Previous result + Next result + Search in page + +