Skip to content

Commit

Permalink
Fix crash on Android < 12
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanklee committed Dec 14, 2023
1 parent 41495b3 commit cc2650a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 4 deletions.
26 changes: 26 additions & 0 deletions app/src/main/java/com/klee/sapio/ui/view/SearchFragment.kt
Original file line number Diff line number Diff line change
@@ -1,18 +1,22 @@
package com.klee.sapio.ui.view

import android.content.Context
import android.graphics.PorterDuff
import android.os.Build
import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.view.inputmethod.InputMethodManager
import androidx.core.content.ContextCompat
import androidx.core.widget.addTextChangedListener
import androidx.fragment.app.Fragment
import androidx.fragment.app.viewModels
import androidx.lifecycle.lifecycleScope
import androidx.recyclerview.widget.LinearLayoutManager
import com.google.android.material.R
import com.klee.sapio.databinding.FragmentSearchBinding
import com.klee.sapio.domain.EvaluationRepository
import com.klee.sapio.ui.viewmodel.SearchViewModel
Expand All @@ -36,6 +40,7 @@ class SearchFragment : Fragment() {
container: ViewGroup?,
savedInstanceState: Bundle?
): View {

mBinding = FragmentSearchBinding.inflate(layoutInflater)
mBinding.recyclerView.layoutManager = LinearLayoutManager(context)
mBinding.recyclerView.visibility = View.INVISIBLE
Expand Down Expand Up @@ -64,9 +69,30 @@ class SearchFragment : Fragment() {
showResults(text.isNotEmpty())
}

setSearchIconsColor()

return mBinding.root
}

private fun setSearchIconsColor() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
mBinding.searchIcon.setColorFilter(
ContextCompat.getColor(
requireContext(),
R.color.material_dynamic_primary80
),
PorterDuff.Mode.SRC_IN
)
mBinding.searchIconBig.setColorFilter(
ContextCompat.getColor(
requireContext(),
R.color.material_dynamic_primary80
),
PorterDuff.Mode.SRC_IN
)
}
}

override fun onResume() {
super.onResume()
showKeyboard()
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/res/layout/fragment_search.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@
android:layout_marginLeft="20dp"
android:layout_marginTop="10dp"
android:src="@drawable/search"
app:tint="@color/teal_200"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/recyclerView"
app:tint="@color/material_dynamic_primary80" />
app:layout_constraintTop_toBottomOf="@+id/recyclerView"/>

<androidx.appcompat.widget.LinearLayoutCompat
android:layout_width="wrap_content"
Expand All @@ -59,11 +59,11 @@
android:layout_gravity="center"
android:layout_margin="20dp"
android:src="@drawable/search"
app:tint="@color/teal_200"
app:layout_constraintBottom_toTopOf="@+id/editTextSearch"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/recyclerView"
app:tint="@color/material_dynamic_primary80" />
app:layout_constraintTop_toTopOf="@+id/recyclerView"/>

<TextView
android:id="@+id/searchText"
Expand Down

0 comments on commit cc2650a

Please sign in to comment.