Skip to content
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
55 changes: 27 additions & 28 deletions AppSearchSample/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@

plugins {
id 'com.android.application'
id 'kotlin-android'
id 'kotlin-kapt'
id 'org.jetbrains.kotlin.android'
}

apply plugin: 'kotlin-kapt'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we are using two different ways to apply plugins in this project (the plugins block and the apply plugin directive)?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How come we are using two different ways to apply plugins in this project (the plugins block and the apply plugin directive)?


android {
namespace 'com.android.example.appsearchsample'
compileSdkVersion 31
buildToolsVersion "30.0.3"
namespace "com.android.example.appsearchsample"
compileSdk 33

defaultConfig {
applicationId "com.android.example.appsearchsample"
minSdkVersion 14
targetSdkVersion 31
minSdk 33
targetSdk 33
versionCode 1
versionName "1.0"
multiDexEnabled = true

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -41,35 +42,33 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
sourceCompatibility JavaVersion.VERSION_17

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This (and minsdk) seems like it will significantly restrict what phones this sample will run on. Since this is a sample we intend for other people, can we make it run more broadly?

targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '1.8'
jvmTarget = '17'
}
buildFeatures {
viewBinding true
}
}

dependencies {
def appsearch_version = "1.0.0-alpha03"
kapt 'androidx.appsearch:appsearch-compiler:1.1.0-alpha03'

// AppSearch dependencies
implementation "androidx.appsearch:appsearch:$appsearch_version"
implementation "androidx.appsearch:appsearch-local-storage:$appsearch_version"
implementation "androidx.appsearch:appsearch-platform-storage:$appsearch_version"
kapt "androidx.appsearch:appsearch-compiler:$appsearch_version"
//api 'androidx.annotation:annotation:1.6.0'

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not quite clear what this new comment is intended to communicate -- could you clarify?

implementation 'androidx.appsearch:appsearch:1.1.0-alpha03'
implementation 'androidx.appsearch:appsearch-local-storage:1.1.0-alpha03'
implementation 'androidx.appsearch:appsearch-platform-storage:1.1.0-alpha03'

implementation 'androidx.activity:activity-ktx:1.3.1'
implementation 'androidx.appcompat:appcompat:1.3.1'
implementation 'androidx.core:core-ktx:1.8.0'
implementation 'androidx.appcompat:appcompat:1.6.1'
implementation 'com.google.android.material:material:1.5.0'
implementation 'androidx.concurrent:concurrent-futures-ktx:1.1.0'
implementation 'androidx.constraintlayout:constraintlayout:2.1.1'
implementation 'androidx.core:core-ktx:1.6.0'
implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-runtime-ktx:2.3.1'
implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.3.1'
implementation 'androidx.multidex:multidex:2.0.1'
implementation 'com.google.android.material:material:1.4.0'
implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version"
}
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
implementation 'androidx.navigation:navigation-fragment-ktx:2.5.2'
implementation 'androidx.navigation:navigation-ui-ktx:2.5.2'
testImplementation 'junit:junit:4.13.2'
androidTestImplementation 'androidx.test.ext:junit:1.1.3'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0'
}
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,14 @@ class MainActivity : AppCompatActivity() {
val addNoteDialogView = dialog as AlertDialog
val noteEditText =
addNoteDialogView.findViewById(R.id.add_note_text) as EditText?
val noteEditTitle =
addNoteDialogView.findViewById(R.id.add_note_title) as EditText?
val noteText = noteEditText?.text.toString()
val noteTitle = noteEditTitle?.text.toString()
progressSpinner.visibility = View.VISIBLE
noNotesMessage.visibility = View.GONE
notesList.visibility = View.GONE
noteViewModel.addNote(noteText)
noteViewModel.addNote(noteText, noteTitle)
}
.setNegativeButton(R.string.add_note_dialog_cancel) { dialog, _ ->
dialog.cancel()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ class NoteListItemAdapter(private val onDelete: (SearchResult?) -> Unit) :
view: View,
) : RecyclerView.ViewHolder(view) {
val noteTextView: TextView = view.findViewById(R.id.note_text)
val noteTitleView: TextView = view.findViewById(R.id.note_title)
val noteDeleteButtonView: Button = view.findViewById(R.id.note_delete_button)

fun bind(searchResult: SearchResult, onDelete: (SearchResult?) -> Unit) {
Expand All @@ -69,6 +70,7 @@ class NoteListItemAdapter(private val onDelete: (SearchResult?) -> Unit) :
}

noteTextView.text = stringBuilder
noteTitleView.text = note.title

noteDeleteButtonView.setOnClickListener { onDelete(searchResult) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,11 @@ data class Note(
@Document.StringProperty(
indexingType = AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES
)
val text: String
val text: String,

/** Field for a note title that that user inputs */
@Document.StringProperty(
indexingType = AppSearchSchema.StringPropertyConfig.INDEXING_TYPE_PREFIXES
)
val title: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,13 @@ class NoteViewModel(application: Application) : AndroidViewModel(application) {
*
* @param text text to create [Note] document for.
*/
fun addNote(text: String) {
fun addNote(text: String, title: String) {
val id = UUID.randomUUID().toString()
val note = Note(id = id, text = text)
val note = Note(id = id, text = text, title = title)
viewModelScope.launch {
val result = noteAppSearchManager.addNote(note)
if (!result.isSuccess) {
_errorMessageLiveData.postValue("Failed to add note with id: $id and text: $text")
_errorMessageLiveData.postValue("Failed to add note with id: $id, text: $text, and title: $title")
}

queryNotes()
Expand Down
11 changes: 11 additions & 0 deletions AppSearchSample/app/src/main/res/layout/add_note_dialog.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,21 @@
android:layout_height="match_parent"
android:padding="6dp">

<EditText
android:id="@+id/add_note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:gravity="top"
android:maxLength="40"
android:inputType="text"
android:hint="@string/add_note_title_hint" />

<EditText
android:id="@+id/add_note_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/add_note_title"
android:gravity="top"
android:maxLength="256"
android:inputType="textMultiLine"
Expand Down
38 changes: 29 additions & 9 deletions AppSearchSample/app/src/main/res/layout/item_note.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,19 +24,38 @@
android:layout_height="wrap_content"
android:minHeight="64dp">

<TextView
android:id="@+id/note_text"
<LinearLayout
android:id="@+id/title_container"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_marginTop="6dp"
android:layout_height="wrap_content"
android:layout_marginStart="6dp"
android:layout_marginLeft="6dp"
android:layout_marginTop="6dp"
android:layout_marginEnd="6dp"
android:layout_marginRight="6dp"
android:layout_marginBottom="6dp"
android:textColor="?android:attr/textColorPrimary"
app:layout_constraintEnd_toStartOf="@+id/note_delete_button"
android:orientation="vertical"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toStartOf="@+id/note_delete_button"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
app:layout_constraintBottom_toBottomOf="parent">

<TextView
android:id="@+id/note_title"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Medium"
android:textColor="?android:attr/textColorPrimary" />

<TextView
android:id="@+id/note_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="4dp"
android:textAppearance="@style/TextAppearance.AppCompat.Small"
android:textColor="?android:attr/textColorPrimary" />

</LinearLayout>

<com.google.android.material.button.MaterialButton
android:id="@+id/note_delete_button"
Expand All @@ -51,8 +70,9 @@
app:icon="@drawable/ic_baseline_delete_24"
app:iconGravity="textStart"
app:iconPadding="0dp"
app:layout_constraintBaseline_toBaselineOf="@+id/note_text"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toEndOf="@+id/note_text" />
app:layout_constraintStart_toEndOf="@+id/title_container"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>
1 change: 1 addition & 0 deletions AppSearchSample/app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<string name="no_notes_message">No notes found! Start by adding a note.</string>
<string name="search_bar_title">Search Notes</string>
<string name="search_bar_hint">Enter search text</string>
<string name="add_note_title_hint">Enter note title</string>
<string name="add_note_hint">Enter note text</string>
<string name="add_note_button_text">Add Note</string>
<string name="add_note_dialog_title">Add a new note</string>
Expand Down
27 changes: 5 additions & 22 deletions AppSearchSample/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,25 +15,8 @@
*/

// Top-level build file where you can add configuration options common to all sub-projects/modules.
buildscript {
ext.kotlin_version = "1.5.10"
repositories {
google()
mavenCentral()
}
dependencies {
classpath "com.android.tools.build:gradle:4.2.1"
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}

allprojects {
repositories {
google()
mavenCentral()
}
}

task clean (type: Delete) {
delete rootProject.buildDir
}
plugins {
id 'com.android.application' version '8.0.2' apply false
id 'com.android.library' version '8.0.2' apply false
id 'org.jetbrains.kotlin.android' version '1.8.20' apply false
}
6 changes: 5 additions & 1 deletion AppSearchSample/gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,12 @@ org.gradle.jvmargs=-Xmx2048m -Dfile.encoding=UTF-8
# http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
# org.gradle.parallel=true
# AndroidX package structure to make it clearer which packages are bundled with the
# Android operating system, and which are packaged with your app"s APK
# Android operating system, and which are packaged with your app's APK
# https://developer.android.com/topic/libraries/support-library/androidx-rn
android.useAndroidX=true
# Kotlin code style for this project: "official" or "obsolete":
kotlin.code.style=official
# Enables namespacing of each library's R class so that its R class includes only the
# resources declared in the library itself and none from the library's dependencies,
# thereby reducing the size of the R class for that library
android.nonTransitiveRClass=true
Binary file modified AppSearchSample/gradle/wrapper/gradle-wrapper.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions AppSearchSample/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#Tue Jun 29 07:46:11 PDT 2021
#Tue Jun 27 13:07:45 PDT 2023
distributionBase=GRADLE_USER_HOME
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionPath=wrapper/dists
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.0-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
37 changes: 17 additions & 20 deletions AppSearchSample/gradlew

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

Loading