Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Updated Project to Gradle 7.5.1 and more... #42

Open
wants to merge 15 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 14 additions & 19 deletions app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
}

android {
compileSdkVersion rootProject.compileSdkVersion
compileSdkVersion 32
defaultConfig {
applicationId 'com.ferfalk.simplesearchviewexample'
minSdkVersion rootProject.minSdkVersion
targetSdkVersion rootProject.compileSdkVersion
minSdkVersion 21
targetSdkVersion 32
versionCode 1
versionName '1.0'

testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
}
buildFeatures {
viewBinding = true
}
// buildFeatures {viewBinding = true}
buildTypes {
release {
minifyEnabled true
Expand All @@ -26,25 +26,20 @@ android {
sourceCompatibility JavaVersion.VERSION_1_8
}
kotlinOptions {
jvmTarget = JavaVersion.VERSION_1_8.toString()
jvmTarget = '1.8'
}
}

dependencies {
implementation fileTree(include: ['*.jar'], dir: 'libs')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
implementation "androidx.core:core-ktx:1.3.1"
implementation "androidx.core:core-ktx:1.8.0"

implementation 'androidx.appcompat:appcompat:1.2.0'
implementation 'androidx.constraintlayout:constraintlayout:2.0.1'
implementation 'com.google.android.material:material:1.2.1'
implementation 'androidx.appcompat:appcompat:1.5.1'
implementation 'com.google.android.material:material:1.6.1'

implementation project(':simplesearchview')

testImplementation 'junit:junit:4.13'
androidTestImplementation 'androidx.test:runner:1.3.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
}
repositories {
mavenCentral()
androidTestImplementation 'androidx.test:runner:1.4.0'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
5 changes: 4 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,10 @@
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name="com.ferfalk.simplesearchviewexample.MainActivity">
<activity
android:name="com.ferfalk.simplesearchviewexample.MainActivity"
android:exported="true"
>
<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,33 +9,36 @@ import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import androidx.fragment.app.Fragment
import androidx.fragment.app.FragmentManager
import androidx.fragment.app.FragmentPagerAdapter
import androidx.fragment.app.FragmentActivity
import androidx.viewpager2.adapter.FragmentStateAdapter
import androidx.viewpager2.widget.ViewPager2
import com.ferfalk.simplesearchview.SimpleSearchView
import com.ferfalk.simplesearchview.utils.DimensUtils.convertDpToPx
import com.ferfalk.simplesearchviewexample.databinding.ActivityMainBinding
import com.google.android.material.tabs.TabLayout
import com.google.android.material.tabs.TabLayout.TabLayoutOnPageChangeListener
import com.google.android.material.tabs.TabLayoutMediator

class MainActivity : AppCompatActivity() {

private lateinit var binding: ActivityMainBinding
private val TAG = MainActivity::class.java.simpleName

private val container by lazy { findViewById<ViewPager2>(R.id.container) }
private val toolbar by lazy { findViewById<Toolbar>(R.id.toolbar) }
private val searchView by lazy { findViewById<SimpleSearchView>(R.id.searchView) }
private val tabLayout by lazy { findViewById<TabLayout>(R.id.tabLayout) }
private val tabTitles = arrayOf("Tab 1", "Tab 2", "Tab 3")

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

setContentView(R.layout.activity_main)
init()
}

private fun init() = with(binding) {
private fun init() {
setSupportActionBar(toolbar)
container.adapter = SectionsPagerAdapter(supportFragmentManager)
container.addOnPageChangeListener(TabLayoutOnPageChangeListener(tabLayout))
tabLayout.addOnTabSelectedListener(TabLayout.ViewPagerOnTabSelectedListener(container))
container.adapter = SectionsPagerAdapter(this)
TabLayoutMediator(tabLayout, container) { tab, pos -> tab.text = tabTitles[pos]}.attach()
}

override fun onCreateOptionsMenu(menu: Menu): Boolean {
Expand All @@ -45,40 +48,42 @@ class MainActivity : AppCompatActivity() {
return true
}

private fun setupSearchView(menu: Menu) = with(binding) {
private fun setupSearchView(menu: Menu) {
val item = menu.findItem(R.id.action_search)
searchView.setMenuItem(item)
searchView.setTabLayout(tabLayout)
searchView.setOnQueryTextListener(object : SimpleSearchView.OnQueryTextListener{
override fun onQueryTextChange(newText: String): Boolean {
Log.e(TAG, getString(R.string.changed, newText))
return false
}

override fun onQueryTextSubmit(query: String): Boolean {
Log.e(TAG, getString(R.string.submitted, query))
return false
}

override fun onQueryTextCleared(): Boolean {
Log.e(TAG, getString(R.string.cleared))
return false
}
})
searchView.apply {
setMenuItem(item)
setTabLayout(this@MainActivity.tabLayout)
setOnQueryTextListener(object : SimpleSearchView.OnQueryTextListener{
override fun onQueryTextChange(newText: String): Boolean {
Log.e(TAG, getString(R.string.changed, newText))
return false
}

override fun onQueryTextSubmit(query: String): Boolean {
Log.e(TAG, getString(R.string.submitted, query))
return false
}

override fun onQueryTextCleared(): Boolean {
Log.e(TAG, getString(R.string.cleared))
return false
}
})
}

// Adding padding to the animation because of the hidden menu item
val revealCenter = searchView.revealAnimationCenter
revealCenter!!.x -= convertDpToPx(EXTRA_REVEAL_CENTER_PADDING, this@MainActivity)
}

override fun onBackPressed() = with(binding) {
override fun onBackPressed() {
if (searchView.onBackPressed()) {
return
}
super.onBackPressed()
}

override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) = with(binding) {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (searchView.onActivityResult(requestCode, resultCode, data!!)) {
return
}
Expand All @@ -89,7 +94,7 @@ class MainActivity : AppCompatActivity() {
override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
val rootView = inflater.inflate(R.layout.fragment_main, container, false)
val textView = rootView.findViewById<TextView>(R.id.section_label)
textView.text = getString(R.string.section_format, arguments!!.getInt(ARG_SECTION_NUMBER))
textView.text = getString(R.string.section_format, requireArguments().getInt(ARG_SECTION_NUMBER))
return rootView
}

Expand All @@ -105,14 +110,11 @@ class MainActivity : AppCompatActivity() {
}
}

class SectionsPagerAdapter internal constructor(fm: FragmentManager) : FragmentPagerAdapter(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT) {
override fun getItem(position: Int): Fragment {
return PlaceholderFragment.newInstance(position + 1)
}
class SectionsPagerAdapter internal constructor(fm: FragmentActivity) : FragmentStateAdapter(fm) {

override fun getCount(): Int {
return 3
}
override fun getItemCount() = 3

override fun createFragment(position: Int) = PlaceholderFragment.newInstance(position + 1)
}

companion object {
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@

</com.google.android.material.appbar.AppBarLayout>

<androidx.viewpager.widget.ViewPager
<androidx.viewpager2.widget.ViewPager2
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="match_parent"
Expand Down
20 changes: 10 additions & 10 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<resources>
<string name="app_name">SimpleSearchView Example</string>
<string name="app_subtitle">SimpleSearchView</string>
<string name="tab_text_1">Tab 1</string>
<string name="tab_text_2">Tab 2</string>
<string name="tab_text_3">Tab 3</string>
<string name="section_format">Hello World from section: %1$d</string>
<string name="example">Example</string>
<string name="changed">changed: %1$s</string>
<string name="submitted">submitted: %1$s</string>
<string name="cleared">cleared</string>
<string name="app_name" translatable="false">SimpleSearchView Example</string>
<string name="app_subtitle" translatable="false">SimpleSearchView</string>
<string name="tab_text_1" translatable="false">Tab 1</string>
<string name="tab_text_2" translatable="false">Tab 2</string>
<string name="tab_text_3" translatable="false">Tab 3</string>
<string name="section_format" translatable="false">Hello World from section: %1$d</string>
<string name="example" translatable="false">Example</string>
<string name="changed" translatable="false">changed: %1$s</string>
<string name="submitted" translatable="false">submitted: %1$s</string>
<string name="cleared" translatable="false">cleared</string>
</resources>
29 changes: 4 additions & 25 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,31 +1,10 @@
// Top-level build file where you can add configuration options common to all sub-projects/modules.

buildscript {
ext.kotlin_version = '1.4.0'

repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:4.0.1'
classpath 'com.github.dcendents:android-maven-gradle-plugin:2.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
jcenter()
}
plugins {
id 'com.android.application' version '7.2.0' apply false
id 'com.android.library' version '7.2.0' apply false
id 'org.jetbrains.kotlin.android' version '1.6.21' apply false
}

task clean(type: Delete) {
delete rootProject.buildDir
}

ext {
compileSdkVersion = 30
minSdkVersion = 16
}
8 changes: 7 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,13 @@
# The setting is particularly useful for tweaking memory settings.
android.enableJetifier=true
android.useAndroidX=true
org.gradle.jvmargs=-Xmx1536m
org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=2048m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8
org.gradle.parallel=true
org.gradle.daemon=true
org.gradle.configureondemand=true
org.gradle.caching=true
org.gradle.unsafe.configuration-cache=true
org.gragle.warning.mode=none
# When configured, Gradle will run in incubating parallel mode.
# This option should only be used with decoupled projects. More details, visit
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
Expand Down
6 changes: 3 additions & 3 deletions gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Sat Sep 05 18:50:01 CEST 2020
#Sun Oct 23 12:22:34 GMT+01:00 2022
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.1.1-all.zip
zipStoreBase=GRADLE_USER_HOME
15 changes: 15 additions & 0 deletions settings.gradle
Original file line number Diff line number Diff line change
@@ -1 +1,16 @@
pluginManagement {
repositories {
gradlePluginPortal()
google()
mavenCentral()
}
}
dependencyResolutionManagement {
repositoriesMode.set(RepositoriesMode.FAIL_ON_PROJECT_REPOS)
repositories {
google()
mavenCentral()
}
}
rootProject.name = "SimpleSearchView"
include ':app', ':simplesearchview'
Loading