Skip to content

Commit

Permalink
Update Gradle, Dependencies and Kotlin version. Binding has been repl…
Browse files Browse the repository at this point in the history
…aced by findViewById
  • Loading branch information
johncodeos committed Jun 14, 2022
1 parent 26f556e commit dfb6437
Show file tree
Hide file tree
Showing 12 changed files with 73 additions and 83 deletions.
2 changes: 1 addition & 1 deletion .idea/compiler.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 2 additions & 5 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,11 @@ android {
kotlinOptions {
jvmTarget = '1.8'
}
buildFeatures {
viewBinding true
}
}

dependencies {
implementation 'androidx.appcompat:appcompat:1.4.1'
implementation 'androidx.core:core-ktx:1.7.0'
implementation 'androidx.appcompat:appcompat:1.4.2'
implementation 'androidx.core:core-ktx:1.8.0'

implementation 'androidx.recyclerview:recyclerview:1.2.1'

Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,18 @@
package com.example.searchrecyclerviewexample

import android.os.Bundle
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.example.searchrecyclerviewexample.databinding.ActivityDetailsBinding

class DetailsActivity : AppCompatActivity() {

private lateinit var binding: ActivityDetailsBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDetailsBinding.inflate(layoutInflater)
val view = binding.root
setContentView(view)
setContentView(R.layout.activity_details)

binding.detailCountryText.text = intent.extras!!.getString("passselectedcountry")!!
val detailCountryText = findViewById<TextView>(R.id.detail_country_text_view)
detailCountryText.text = intent.extras!!.getString("passselectedcountry")!!

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,38 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.SearchView
import androidx.recyclerview.widget.LinearLayoutManager
import androidx.recyclerview.widget.RecyclerView
import com.example.searchrecyclerviewexample.databinding.ActivityMainBinding
import java.util.*
import kotlin.collections.ArrayList


class MainActivity : AppCompatActivity() {

lateinit var adapter: RecyclerViewAdapter
lateinit var countryrv: RecyclerView
private lateinit var countryRv: RecyclerView

private lateinit var binding: ActivityMainBinding

override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityMainBinding.inflate(layoutInflater)
setContentView(binding.root)
setContentView(R.layout.activity_main)

val searchIcon = binding.countrySearch.findViewById<ImageView>(androidx.appcompat.R.id.search_mag_icon)
val countrySearch = findViewById<SearchView>(R.id.country_search)
val searchIcon =
countrySearch.findViewById<ImageView>(androidx.appcompat.R.id.search_mag_icon)
searchIcon.setColorFilter(Color.WHITE)


val cancelIcon = binding.countrySearch.findViewById<ImageView>(androidx.appcompat.R.id.search_close_btn)
val cancelIcon =
countrySearch.findViewById<ImageView>(androidx.appcompat.R.id.search_close_btn)
cancelIcon.setColorFilter(Color.WHITE)

val textView = binding.countrySearch.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
val textView = countrySearch.findViewById<TextView>(androidx.appcompat.R.id.search_src_text)
textView.setTextColor(Color.WHITE)
// If you want to change the color of the cursor, change the 'colorAccent' in colors.xml


countryrv = findViewById(R.id.country_rv)
countryrv.layoutManager = LinearLayoutManager(countryrv.context)
countryrv.setHasFixedSize(true)
countryRv = findViewById(R.id.country_rv)
countryRv.layoutManager = LinearLayoutManager(countryRv.context)
countryRv.setHasFixedSize(true)

binding.countrySearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
countrySearch.setOnQueryTextListener(object : SearchView.OnQueryTextListener {
override fun onQueryTextSubmit(query: String?): Boolean {
return false
}
Expand Down Expand Up @@ -71,7 +69,7 @@ class MainActivity : AppCompatActivity() {
countryListWithEmojis.add("$countryName $flag")
}
adapter = RecyclerViewAdapter(countryListWithEmojis)
countryrv.adapter = adapter
countryRv.adapter = adapter
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,33 @@ import android.content.Intent
import android.graphics.Color
import android.util.Log
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.Filter
import android.widget.Filterable
import android.widget.RelativeLayout
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.searchrecyclerviewexample.databinding.RecyclerviewRowBinding
import java.util.*
import kotlin.collections.ArrayList


class RecyclerViewAdapter(private var countryList: ArrayList<String>) :
RecyclerView.Adapter<RecyclerView.ViewHolder>(), Filterable {
RecyclerView.Adapter<RecyclerViewAdapter.CountryViewHolder>(), Filterable {

var countryFilterList = ArrayList<String>()

lateinit var mContext: Context
private lateinit var mContext: Context

class CountryHolder(var viewBinding: RecyclerviewRowBinding) :
RecyclerView.ViewHolder(viewBinding.root)
inner class CountryViewHolder(view: View) : RecyclerView.ViewHolder(view)

init {
countryFilterList = countryList
}

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): RecyclerView.ViewHolder {
val binding =
RecyclerviewRowBinding.inflate(LayoutInflater.from(parent.context), parent, false)
val sch = CountryHolder(binding)
override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): CountryViewHolder {
val v =
LayoutInflater.from(parent.context).inflate(R.layout.recyclerview_row, parent, false)
val sch = CountryViewHolder(v)
mContext = parent.context
return sch
}
Expand All @@ -40,12 +40,15 @@ class RecyclerViewAdapter(private var countryList: ArrayList<String>) :
return countryFilterList.size
}

override fun onBindViewHolder(holder: RecyclerView.ViewHolder, position: Int) {
val countryHolder = holder as CountryHolder
countryHolder.viewBinding.selectCountryContainer.setBackgroundColor(Color.TRANSPARENT)
override fun onBindViewHolder(holder: CountryViewHolder, position: Int) {
val selectCountryContainer =
holder.itemView.findViewById<RelativeLayout>(R.id.select_country_container)
selectCountryContainer.setBackgroundColor(Color.TRANSPARENT)

countryHolder.viewBinding.selectCountryText.setTextColor(Color.WHITE)
countryHolder.viewBinding.selectCountryText.text = countryFilterList[position]
val selectCountryTextView =
holder.itemView.findViewById<TextView>(R.id.select_country_text_view)
selectCountryTextView.setTextColor(Color.WHITE)
selectCountryTextView.text = countryFilterList[position]

holder.itemView.setOnClickListener {
val intent = Intent(mContext, DetailsActivity::class.java)
Expand Down
17 changes: 7 additions & 10 deletions app/src/main/res/layout/activity_details.xml
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
tools:context=".DetailsActivity">

<TextView
android:id="@+id/detail_country_text"
android:id="@+id/detail_country_text_view"
android:layout_width="match_parent"
android:layout_marginStart="20dp"
android:layout_marginRight="20dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="United States 🇺🇸"
android:layout_marginStart="20dp"
android:layout_marginEnd="20dp"
android:gravity="center"
android:textSize="22sp"
android:text="United States 🇺🇸"
android:textColor="@android:color/white"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginEnd="20dp" />
android:textSize="22sp" />

</RelativeLayout>
42 changes: 21 additions & 21 deletions app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
@@ -1,28 +1,28 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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:id="@+id/country_content_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:orientation="vertical"
tools:context=".MainActivity">

<androidx.appcompat.widget.SearchView
android:id="@+id/country_search"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/country_content_id"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:textCursorDrawable="@null"
app:iconifiedByDefault="false"
app:queryBackground="@null" />
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark"
android:orientation="vertical"
tools:context=".MainActivity">

<androidx.appcompat.widget.SearchView
android:id="@+id/country_search"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/colorPrimary"
android:textCursorDrawable="@null"
app:iconifiedByDefault="false"
app:queryBackground="@null" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/country_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark" />

<androidx.recyclerview.widget.RecyclerView
android:id="@+id/country_rv"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/colorPrimaryDark" />

</LinearLayout>
6 changes: 2 additions & 4 deletions app/src/main/res/layout/recyclerview_row.xml
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:id="@+id/select_country_container"
android:layout_width="match_parent"
android:layout_height="57dp"
android:background="@color/colorPrimaryDark"
android:orientation="vertical">

<TextView
android:id="@+id/select_country_text"
android:id="@+id/select_country_text_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="16dp"
android:layout_centerInParent="true"
android:layout_marginLeft="16dp"
android:layout_marginStart="16dp"
android:layout_marginTop="8dp"
android:layout_marginBottom="8dp"
android:text="United States 🇺🇸"
Expand Down
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.
plugins {
id 'com.android.application' version '7.1.0' apply false
id 'com.android.library' version '7.1.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.10' apply false
id 'com.android.application' version '7.2.1' apply false
id 'com.android.library' version '7.2.1' apply false
id 'org.jetbrains.kotlin.android' version '1.7.0' apply false
}

task clean(type: Delete) {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Feb 01 16:38:26 EET 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.2-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.3.3-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME

0 comments on commit dfb6437

Please sign in to comment.