Skip to content

Commit f5da24a

Browse files
added sqlite to room migration
1 parent 11927d4 commit f5da24a

196 files changed

Lines changed: 5506 additions & 0 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

AutocompleteExample/.gitignore

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
*.iml
2+
.gradle
3+
/local.properties
4+
/.idea/caches
5+
/.idea/libraries
6+
/.idea/modules.xml
7+
/.idea/workspace.xml
8+
/.idea/navEditor.xml
9+
/.idea/assetWizardSettings.xml
10+
.DS_Store
11+
/build
12+
/captures
13+
.externalNativeBuild
14+
.cxx
15+
local.properties

AutocompleteExample/app/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/build
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
plugins {
2+
id 'com.android.application'
3+
id 'kotlin-android'
4+
}
5+
6+
android {
7+
compileSdkVersion 30
8+
buildToolsVersion "30.0.3"
9+
10+
defaultConfig {
11+
applicationId "com.velmurugan.autocompleteexample"
12+
minSdkVersion 24
13+
targetSdkVersion 30
14+
versionCode 1
15+
versionName "1.0"
16+
17+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
18+
}
19+
20+
buildTypes {
21+
release {
22+
minifyEnabled false
23+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
24+
}
25+
}
26+
compileOptions {
27+
sourceCompatibility JavaVersion.VERSION_1_8
28+
targetCompatibility JavaVersion.VERSION_1_8
29+
}
30+
kotlinOptions {
31+
jvmTarget = '1.8'
32+
}
33+
34+
buildFeatures {
35+
viewBinding true
36+
}
37+
}
38+
39+
dependencies {
40+
41+
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
42+
implementation 'androidx.core:core-ktx:1.5.0'
43+
implementation 'androidx.appcompat:appcompat:1.3.0'
44+
implementation 'com.google.android.material:material:1.3.0'
45+
implementation 'androidx.constraintlayout:constraintlayout:2.0.4'
46+
testImplementation 'junit:junit:4.+'
47+
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
48+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
49+
//Retrofit
50+
implementation 'com.google.code.gson:gson:2.8.6'
51+
implementation 'com.squareup.retrofit2:retrofit:2.9.0'
52+
implementation 'com.squareup.retrofit2:converter-gson:2.9.0'
53+
54+
//Coroutine
55+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-android:1.4.1"
56+
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-core:1.4.2"
57+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.velmurugan.autocompleteexample
2+
3+
import androidx.test.platform.app.InstrumentationRegistry
4+
import androidx.test.ext.junit.runners.AndroidJUnit4
5+
import org.junit.Test
6+
import org.junit.runner.RunWith
7+
import org.junit.Assert.*
8+
9+
/**
10+
* Instrumented test, which will execute on an Android device.
11+
*
12+
* See [testing documentation](http://d.android.com/tools/testing).
13+
*/
14+
@RunWith(AndroidJUnit4::class)
15+
class ExampleInstrumentedTest {
16+
@Test
17+
fun useAppContext() {
18+
// Context of the app under test.
19+
val appContext = InstrumentationRegistry.getInstrumentation().targetContext
20+
assertEquals("com.velmurugan.autocompleteexample", appContext.packageName)
21+
}
22+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
package="com.velmurugan.autocompleteexample">
4+
5+
<uses-permission android:name="android.permission.INTERNET" />
6+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
7+
<application
8+
android:allowBackup="true"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:usesCleartextTraffic="true"
12+
13+
android:roundIcon="@mipmap/ic_launcher_round"
14+
android:supportsRtl="true"
15+
android:theme="@style/Theme.AutocompleteExample">
16+
<activity android:name=".MainActivity">
17+
<intent-filter>
18+
<action android:name="android.intent.action.MAIN" />
19+
20+
<category android:name="android.intent.category.LAUNCHER" />
21+
</intent-filter>
22+
</activity>
23+
</application>
24+
25+
</manifest>
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.velmurugan.autocompleteexample
2+
3+
class ApiService {}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package com.velmurugan.autocompleteexample
2+
3+
import android.content.Context
4+
import android.widget.ArrayAdapter
5+
import android.widget.Filter
6+
import android.widget.Filterable
7+
import java.util.ArrayList
8+
9+
class AutoSuggestAdapter(context: Context, resource: Int) : ArrayAdapter<String?>(context, resource), Filterable {
10+
private var mlistData = mutableListOf<String>()
11+
fun setData(list: List<String>?) {
12+
mlistData.clear()
13+
mlistData.addAll(list!!)
14+
}
15+
16+
override fun getCount(): Int {
17+
return mlistData.size
18+
}
19+
20+
override fun getItem(position: Int): String? {
21+
return mlistData[position]
22+
}
23+
/**
24+
* Used to Return the full object directly from adapter.
25+
*
26+
* @param position
27+
* @return
28+
*/
29+
fun getObject(position: Int): String {
30+
return mlistData[position]
31+
}
32+
33+
override fun getFilter(): Filter {
34+
return object : Filter() {
35+
override fun performFiltering(constraint: CharSequence?): FilterResults? {
36+
val filterResults = FilterResults()
37+
if (constraint != null) {
38+
filterResults.values = mlistData
39+
filterResults.count = mlistData.size
40+
}
41+
return filterResults
42+
}
43+
44+
override fun publishResults(constraint: CharSequence?, results: FilterResults?) {
45+
if (results != null && results.count > 0) {
46+
notifyDataSetChanged()
47+
} else {
48+
notifyDataSetInvalidated()
49+
}
50+
}
51+
}
52+
}
53+
54+
init {
55+
mlistData = ArrayList()
56+
}
57+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.velmurugan.autocompleteexample
2+
3+
import android.R
4+
import android.os.Bundle
5+
import android.text.Editable
6+
import android.text.TextWatcher
7+
import android.widget.AdapterView.OnItemClickListener
8+
import android.widget.Toast
9+
import androidx.appcompat.app.AppCompatActivity
10+
import com.velmurugan.autocompleteexample.databinding.ActivityMainBinding
11+
import kotlinx.coroutines.*
12+
13+
class MainActivity : AppCompatActivity() {
14+
lateinit var binding: ActivityMainBinding
15+
lateinit var autoSuggestAdapter: AutoSuggestAdapter
16+
17+
override fun onCreate(savedInstanceState: Bundle?) {
18+
super.onCreate(savedInstanceState)
19+
binding = ActivityMainBinding.inflate(layoutInflater)
20+
setContentView(binding.root)
21+
//Setting up the adapter for AutoSuggest
22+
//Setting up the adapter for AutoSuggest
23+
autoSuggestAdapter = AutoSuggestAdapter(this, R.layout.simple_dropdown_item_1line)
24+
binding.autoComplete.setThreshold(2)
25+
binding.autoComplete.setAdapter(autoSuggestAdapter)
26+
binding.autoComplete.onItemClickListener = OnItemClickListener { parent, view, position, id ->
27+
Toast.makeText(this, autoSuggestAdapter.getObject(position), Toast.LENGTH_SHORT).show()
28+
}
29+
binding.autoComplete.addTextChangedListener(object : TextWatcher {
30+
override fun beforeTextChanged(s: CharSequence, start: Int, count: Int, after: Int) {}
31+
override fun onTextChanged(s: CharSequence, start: Int, before: Int, count: Int) {
32+
33+
val count = binding.autoComplete.text.toString().length
34+
35+
if (count> 2) {
36+
doApiCall()
37+
}
38+
39+
40+
}
41+
42+
override fun afterTextChanged(s: Editable) {}
43+
})
44+
}
45+
46+
fun doApiCall() {
47+
val count = binding.autoComplete.text.toString().length
48+
CoroutineScope(Dispatchers.IO).launch {
49+
val apiCall = RetrofitService.getInstance().getAllMovies()
50+
if (apiCall.isSuccessful) {
51+
withContext(Dispatchers.Main) {
52+
val response = apiCall.body()
53+
updateAutoComplete(apiCall.body()?.subList(0,count))
54+
}
55+
}
56+
}
57+
}
58+
59+
private fun updateAutoComplete(body: List<Movie>?) {
60+
body?.let {
61+
val list = it.map { it.name }
62+
autoSuggestAdapter.setData(list);
63+
autoSuggestAdapter.notifyDataSetChanged();
64+
}
65+
}
66+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
package com.velmurugan.autocompleteexample
2+
3+
data class Movie(val name: String, val imageUrl: String, val category: String)

0 commit comments

Comments
 (0)