Skip to content

Commit

Permalink
Improvements 1.0.3 (#1)
Browse files Browse the repository at this point in the history
* Added ability to change hint and text color
* removed useless background color, use "android:background"
* added default select states for buttons
* fixed counter shows the previous count
  • Loading branch information
Y-E-P authored Apr 12, 2023
1 parent 6987c19 commit 902801a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 26 deletions.
10 changes: 6 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ and:

```gradle
dependencies {
implementation 'com.github.Y-E-P:BrowserFiP:1.0.2'
implementation 'com.github.Y-E-P:BrowserFiP:1.0.3'
}
```

Expand All @@ -38,11 +38,12 @@ After successfully installing dependencies add FiPSearchView in your xml:
app:fip_next_icon="@drawable/ic_your_icon"
app:fip_previous_icon="@drawable/ic_your_icon"
app:fip_close_icon="@drawable/ic_your_icon"
app:fip_background_color="@color/your_color"
app:fip_divider_color="@color/your_color"
app:fip_divider_visible="true"
app:fip_counter_empty_color="@color/your_color"
app:fip_counter_matched_color="@color/your_color"
app:fip_hint_color="@color/your_hint_color"
app:fip_text_color="@color/your_text_color"
/>
```
All attributes are optional.
Expand All @@ -61,14 +62,15 @@ fip.setupSearchComponent(yorWebView)
```kotlin
fip?.setupView {
hint = //your hint
backgroundColor = //your background color
nextArrowIcon = //your next arrow icon
previousArrowIcon = //your previous arrow icon
closeArrowIcon = //your close arrow icon
dividerVisibility = //your divider visibility state true or false
dividerColor = //your divider color
counterEmptyColor = //your couter color
counterMatchedColor = //your counter matched color
counterMatchedColor = //your counter matched color
textColor = // your text color
hintColor = // your hint color
}
```
### Release resources after using FiPSearch(for example in onDestroy(Activity) or onDestroyView(Fragment))
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

<com.yupo.browserfiplib.FiPSearchView
android:id="@+id/fip"
android:background="@color/white"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize" />

Expand Down
4 changes: 2 additions & 2 deletions browserfiplib/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@ plugins {
id 'org.jetbrains.kotlin.android'
id 'maven-publish'
}
def libVersionName = "1.0.2"
def libVersionName = "1.0.3"
android {
namespace 'com.yupo.browserfiplib'
compileSdk project.compileSdkVersion.toInteger()

defaultConfig {
minSdk project.minSdkVersion.toInteger()
targetSdk project.targetSdkVersion.toInteger()
versionCode 3
versionCode 4
versionName libVersionName

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
Expand Down
52 changes: 37 additions & 15 deletions browserfiplib/src/main/java/com/yupo/browserfiplib/FiPSearchView.kt
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@ import android.widget.EditText
import android.widget.ImageButton
import android.widget.LinearLayout
import android.widget.TextView
import androidx.annotation.ColorInt
import androidx.annotation.ColorRes
import androidx.annotation.DrawableRes
import androidx.annotation.StyleableRes
import androidx.appcompat.widget.SearchView
import androidx.core.content.ContextCompat
import androidx.core.view.isVisible

class FiPSearchView @JvmOverloads constructor(
context: Context, attrs: AttributeSet? = null
Expand All @@ -35,14 +37,15 @@ class FiPSearchView @JvmOverloads constructor(

data class Settings(
var hint: String,
var backgroundColor: Int,
var nextArrowIcon: Drawable,
var previousArrowIcon: Drawable,
var closeArrowIcon: Drawable,
var dividerVisibility: Boolean,
var dividerColor: Int,
var counterEmptyColor: Int,
var counterMatchedColor: Int
var counterMatchedColor: Int,
var textColor: Int,
var hintColor: Int
)


Expand All @@ -59,10 +62,6 @@ class FiPSearchView @JvmOverloads constructor(
settings = Settings(
hint = typedArray.getString(R.styleable.FiPSearchView_fip_hint)
?: context.getString(R.string.fip_hint_text),
backgroundColor = typedArray.getColor(
R.styleable.FiPSearchView_fip_background_color,
getColor(R.color.fip_white)
),
nextArrowIcon = typedArray.getDrawableOrDefault(
R.styleable.FiPSearchView_fip_next_icon,
R.drawable.arrow_down_24
Expand All @@ -89,14 +88,21 @@ class FiPSearchView @JvmOverloads constructor(
counterMatchedColor = typedArray.getColor(
R.styleable.FiPSearchView_fip_counter_matched_color,
getColor(R.color.fip_matched_counter_color)
),
hintColor = typedArray.getColor(
R.styleable.FiPSearchView_fip_hint_color,
getColor(R.color.fip_hint_color)
),
textColor = typedArray.getColor(
R.styleable.FiPSearchView_fip_hint_color,
getColor(R.color.fip_black)
)
)
typedArray.recycle()
}

private fun initView() {
searchView.queryHint = settings.hint
setBackgroundColor(settings.backgroundColor)
buttonNext.setOnClickListener {
onNavigationClicked(ClickEvent.NEXT)
webView?.findNext(true) ?: errorMessage()
Expand All @@ -115,7 +121,8 @@ class FiPSearchView @JvmOverloads constructor(
buttonNext.setImageDrawable(settings.nextArrowIcon)
buttonPrevious.setImageDrawable(settings.previousArrowIcon)
buttonClose.setImageDrawable(settings.closeArrowIcon)
searchView.changeColors(R.color.fip_black)
searchView.changeHintColor(settings.hintColor)
searchView.changeTextColor(settings.textColor)
divider.visibility = if (settings.dividerVisibility) View.VISIBLE else View.INVISIBLE
divider.setBackgroundColor(settings.dividerColor)
}
Expand All @@ -137,6 +144,10 @@ class FiPSearchView @JvmOverloads constructor(
}

override fun onQueryTextChange(newText: String?): Boolean {
if (newText.isNullOrEmpty()) {
countTextView.isVisible = false
clearCounter()
}
handleTextChanges(newText)
return false
}
Expand All @@ -145,10 +156,8 @@ class FiPSearchView @JvmOverloads constructor(

private fun handleTextChanges(newText: String?) {
if (newText.isNullOrEmpty()) {
countTextView.visibility = GONE
webView?.clearMatches()
} else {
countTextView.visibility = VISIBLE
webView?.findAllAsync(newText)
}
}
Expand All @@ -165,7 +174,12 @@ class FiPSearchView @JvmOverloads constructor(
) {
enableButtons(numberOfMatches != 0)
val matchesNumber = if (numberOfMatches != 0) activeMatchOrdinal + 1 else activeMatchOrdinal
updateMatchesCounter(matchesNumber, numberOfMatches)
if (isDoneCounting) {
updateMatchesCounter(matchesNumber, numberOfMatches)
} else {
clearCounter()
}
countTextView.isVisible = isDoneCounting
}

override fun onActionViewExpanded() {
Expand All @@ -182,6 +196,10 @@ class FiPSearchView @JvmOverloads constructor(
String.format(context.getString(R.string.fip_counter), counter, matchesCount)
}

private fun clearCounter() {
countTextView.text = String.format(context.getString(R.string.fip_counter), 0, 0)
}

/**
* Method performs cleaning callbacks and WebView, call
* @see setupSearchComponent to setup widget again
Expand All @@ -201,10 +219,14 @@ class FiPSearchView @JvmOverloads constructor(
NEXT, PREVIOUS, CLOSE
}

private fun SearchView.changeColors(@ColorRes color: Int) {
val editText = this.findViewById<EditText>(androidx.appcompat.R.id.search_src_text)
editText.setTextColor(getColor(color))
editText.setHintTextColor(getColor(color))
private fun SearchView.changeTextColor(@ColorInt color: Int) {
this.findViewById<EditText>(androidx.appcompat.R.id.search_src_text)
.setTextColor(color)
}

private fun SearchView.changeHintColor(@ColorInt color: Int) {
this.findViewById<EditText>(androidx.appcompat.R.id.search_src_text)
.setHintTextColor(color)
}

private fun getDrawable(@DrawableRes resId: Int) = ContextCompat.getDrawable(context, resId)
Expand Down
2 changes: 2 additions & 0 deletions browserfiplib/src/main/res/color/color_arrow_button_state.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/fip_inactive_color" android:state_enabled="false" />
<item android:color="@color/fip_active_selected" android:state_selected="true" />
<item android:color="@color/fip_active_selected" android:state_pressed="true" />
<item android:color="@color/fip_active_color" />
</selector>
8 changes: 4 additions & 4 deletions browserfiplib/src/main/res/layout/fip_search_view.xml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
android:id="@+id/button_previous"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?actionBarItemBackground"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/fip_description_previous"
app:tint="@color/color_arrow_button_state"
tools:srcCompat="@drawable/arrow_down_24" />
Expand All @@ -51,7 +51,7 @@
android:id="@+id/button_next"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?actionBarItemBackground"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/fip_description_next"
app:tint="@color/color_arrow_button_state"
tools:srcCompat="@drawable/arrow_up_24" />
Expand All @@ -60,9 +60,9 @@
android:id="@+id/button_close"
android:layout_width="48dp"
android:layout_height="match_parent"
android:background="?actionBarItemBackground"
android:background="?attr/selectableItemBackground"
android:contentDescription="@string/fip_description_close"
app:tint="@color/fip_black"
app:tint="@color/color_arrow_button_state"
tools:srcCompat="@drawable/ic_close" />


Expand Down
3 changes: 2 additions & 1 deletion browserfiplib/src/main/res/values/attr.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
<attr name="fip_next_icon" format="reference" />
<attr name="fip_previous_icon" format="reference" />
<attr name="fip_close_icon" format="reference" />
<attr name="fip_background_color" format="color" />
<attr name="fip_divider_color" format="color" />
<attr name="fip_divider_visible" format="boolean" />
<attr name="fip_counter_empty_color" format="color" />
<attr name="fip_counter_matched_color" format="color" />
<attr name="fip_hint_color" format="color" />
<attr name="fip_text_color" format="color" />
</declare-styleable>
</resources>
2 changes: 2 additions & 0 deletions browserfiplib/src/main/res/values/colors.xml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<?xml version="1.0" encoding="utf-8"?>
<resources>
<color name="fip_black">#FF000000</color>
<color name="fip_hint_color">#BDBDBD</color>
<color name="fip_active_color">#FF000000</color>
<color name="fip_active_selected">#63000000</color>
<color name="fip_inactive_color">#BDBDBD</color>
<color name="fip_background_color">#FFFFFFFF</color>
<color name="fip_divider">#BDBDBD</color>
Expand Down

0 comments on commit 902801a

Please sign in to comment.