This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.graphics.Rect | |
import android.util.TypedValue | |
import android.view.View | |
import androidx.recyclerview.widget.RecyclerView | |
class SpaceItemDecoration() : RecyclerView.ItemDecoration() { | |
enum class Orientation { | |
HORIZONTAL, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<resources> | |
... | |
<style name="ShapeAppearance.Button.CutCorners" parent="ShapeAppearance.MaterialComponents.SmallComponent"> | |
<item name="cornerFamily">cut</item> | |
<item name="cornerSize">8dp</item> | |
</style> | |
</resources> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="utf-8"?> | |
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" | |
xmlns:app="http://schemas.android.com/apk/res-auto" | |
xmlns:tools="http://schemas.android.com/tools" | |
android:layout_width="match_parent" | |
android:layout_height="match_parent"> | |
<com.google.android.material.button.MaterialButton | |
android:layout_width="wrap_content" | |
android:layout_height="wrap_content" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.content.Context | |
import android.util.AttributeSet | |
import android.view.MotionEvent | |
import android.view.View.OnTouchListener | |
import android.view.inputmethod.EditorInfo | |
import androidx.appcompat.widget.AppCompatEditText | |
import androidx.core.widget.doAfterTextChanged | |
class SearchEditText | |
@JvmOverloads constructor( |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import android.widget.TextView | |
import androidx.annotation.DrawableRes | |
import androidx.core.content.ContextCompat | |
private const val DRAWABLE_LEFT_INDEX = 0 | |
private const val DRAWABLE_TOP_INDEX = 1 | |
private const val DRAWABLE_RIGHT_INDEX = 2 | |
private const val DRAWABLE_BOTTOM_INDEX = 3 | |
fun TextView.setLeftDrawable(@DrawableRes drawableResId: Int) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class SearchEditText | |
@JvmOverloads constructor( | |
context: Context, | |
attributeSet: AttributeSet? = null, | |
defStyle: Int = androidx.appcompat.R.attr.editTextStyle | |
) : AppCompatEditText(context, attributeSet, defStyle) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setTextChangeListener() { | |
doAfterTextChanged { | |
if (it.isNullOrBlank()) { | |
setRightDrawable(0) | |
} else { | |
setRightDrawable(android.R.drawable.ic_menu_close_clear_cancel) | |
} | |
queryTextListener?.onQueryTextChange(it.toString()) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setOnEditorActionListener() { | |
setOnEditorActionListener { _, actionId, _ -> | |
if (actionId == EditorInfo.IME_ACTION_SEARCH) { | |
queryTextListener?.onQueryTextSubmit(text.toString()) | |
true | |
} else { | |
false | |
} | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private fun setDrawablesListener() { | |
setOnTouchListener(OnTouchListener { view, event -> | |
view.performClick() | |
if (event.action == MotionEvent.ACTION_UP) { | |
when { | |
rightDrawableClicked(event) -> { | |
setText("") | |
return@OnTouchListener true | |
} | |
leftDrawableClicked(event) -> { |
OlderNewer