Skip to content

Commit

Permalink
Adding Room + Coroutines + RecyclerView implementation + Pinned items
Browse files Browse the repository at this point in the history
Fixes #120
Fixes #11 (FINALLY)
Fixes #99
Fixes #114
Fixes #15
  • Loading branch information
Mauker1 committed Aug 25, 2020
1 parent 7955900 commit ca7cfa4
Show file tree
Hide file tree
Showing 19 changed files with 424 additions and 630 deletions.
14 changes: 0 additions & 14 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>

<!--
Authorities is the package name, while name is the file of the provider
Add content provider so android's content resolver can see it.
The authority matches package, name represents the file the provider is in.
The syncable flag lets android now we're going to synchronize our content provider with the server.
Changing the exported tag to false means that only our app can see the content.
-->
<provider
android:name="br.com.mauker.materialsearchview.db.HistoryProvider"
android:authorities="br.com.mauker.materialsearchview.searchhistorydatabase"
android:exported="false"
android:protectionLevel="signature"
android:syncable="true"/>
</application>

</manifest>
8 changes: 0 additions & 8 deletions app/src/main/java/br/com/mauker/MsvAuthority.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import androidx.appcompat.app.AppCompatActivity
import androidx.appcompat.widget.Toolbar
import br.com.mauker.materialsearchview.MaterialSearchView
import br.com.mauker.materialsearchview.MaterialSearchView.SearchViewListener
import br.com.mauker.materialsearchview.db.model.History

class MainActivity : AppCompatActivity() {
private lateinit var searchView: MaterialSearchView
Expand Down Expand Up @@ -51,10 +52,21 @@ class MainActivity : AppCompatActivity() {
// Do something once the view is closed.
}
})
searchView.setOnItemClickListener { _, _, position, _ -> // Do something when the suggestion list is clicked.
val suggestion = searchView.getSuggestionAtPosition(position)
searchView.setQuery(suggestion, false)

val context: Context = this

val clickListener = object: MaterialSearchView.OnHistoryItemClickListener {
override fun onClick(history: History) {
searchView.setQuery(history.query, false)
}

override fun onLongClick(history: History) {
Toast.makeText(context, "Long clicked! Item: $history", Toast.LENGTH_SHORT).show()
}
}

searchView.setOnItemClickListener(clickListener)

searchView.setOnClearClickListener {
Toast.makeText(this, "Clear clicked!", Toast.LENGTH_LONG).show()
}
Expand All @@ -63,11 +75,6 @@ class MainActivity : AppCompatActivity() {
btClearAll.setOnClickListener { clearAll() }

searchView.adjustTintAlpha(0.8f)
val context: Context = this
searchView.setOnItemLongClickListener { _, _, i, _ ->
Toast.makeText(context, "Long clicked position: $i", Toast.LENGTH_SHORT).show()
true
}
// This will override the default audio action.
searchView.setOnVoiceClickedListener { Toast.makeText(context, "Voice clicked!", Toast.LENGTH_SHORT).show() }
}
Expand Down Expand Up @@ -120,9 +127,14 @@ class MainActivity : AppCompatActivity() {
searchView.clearSuggestions()
}

override fun onStop() {
super.onStop()
searchView.onViewStopped()
}

override fun onResume() {
super.onResume()
searchView.activityResumed()
// searchView.onViewResumed()
val arr = resources.getStringArray(R.array.suggestions)
searchView.addSuggestions(arr)
}
Expand Down
1 change: 1 addition & 0 deletions library/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ android {
dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation "androidx.appcompat:appcompat:$appCompatVersion"
implementation "androidx.constraintlayout:constraintlayout:$constraintLayoutVersion"
implementation "com.google.android.material:material:$materialDesignVersion"
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"

Expand Down

0 comments on commit ca7cfa4

Please sign in to comment.