Skip to content

Commit

Permalink
Convert firestore quickstart to Kotlin (#638)
Browse files Browse the repository at this point in the history
  • Loading branch information
samtstern authored Sep 7, 2018
1 parent b31782c commit e1e8816
Show file tree
Hide file tree
Showing 38 changed files with 1,498 additions and 173 deletions.
10 changes: 10 additions & 0 deletions firestore/app/build.gradle
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
apply plugin: 'com.android.application'
apply plugin: 'kotlin-android'
apply plugin: 'kotlin-android-extensions'
apply plugin: 'org.jetbrains.kotlin.android.extensions'

android {
testBuildType "release"
Expand Down Expand Up @@ -30,7 +33,14 @@ android {
}
}

androidExtensions {
experimental = true
}

dependencies {
implementation project(':internal')
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.2.50"

// Firestore
implementation 'com.google.firebase:firebase-core:16.0.3'
implementation 'com.google.firebase:firebase-firestore:17.1.0'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
import android.support.test.runner.AndroidJUnit4;
import android.support.test.uiautomator.UiDevice;
import android.support.test.uiautomator.UiObject;
import android.support.test.uiautomator.UiSelector;
import android.support.test.uiautomator.UiScrollable;
import android.support.test.uiautomator.UiSelector;
import android.test.suitebuilder.annotation.LargeTest;
import android.view.accessibility.AccessibilityWindowInfo;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.example.fireeats.java.MainActivity;

import org.junit.Assert;
import org.junit.Before;
import org.junit.Rule;
Expand Down Expand Up @@ -55,7 +58,7 @@
.clickAndWaitForNewWindow(TIMEOUT);

// Click add review
getById("fab_show_rating_dialog").click();
getById("fabShowRatingDialog").click();

//Write a review
getById("restaurant_form_text").setText("\uD83D\uDE0E\uD83D\uDE00");
Expand All @@ -65,11 +68,11 @@
getById("restaurant_form_button").clickAndWaitForNewWindow(TIMEOUT);

// Assert that the review exists
UiScrollable ratingsList = new UiScrollable(getIdSelector("recycler_ratings"));
UiScrollable ratingsList = new UiScrollable(getIdSelector("recyclerRatings"));
ratingsList.waitForExists(TIMEOUT);
ratingsList.scrollToBeginning(100);
Assert.assertTrue(
getById("recycler_ratings")
getById("recyclerRatings")
.getChild(new UiSelector().text("\uD83D\uDE0E\uD83D\uDE00"))
.waitForExists(TIMEOUT));
}
Expand Down
26 changes: 22 additions & 4 deletions firestore/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@
android:supportsRtl="true"
android:theme="@style/AppTheme"
android:name="android.support.multidex.MultiDexApplication">
<activity
android:name=".MainActivity"
android:theme="@style/AppTheme.Activity">

<activity android:name=".EntryChoiceActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.EntryChoice">

<intent-filter>
<action android:name="android.intent.action.MAIN" />

Expand All @@ -19,7 +21,23 @@
</activity>

<activity
android:name=".RestaurantDetailActivity"
android:name=".java.MainActivity"
android:theme="@style/AppTheme.Activity">

</activity>

<activity
android:name=".java.RestaurantDetailActivity"
android:theme="@style/AppTheme.Activity" />

<activity
android:name=".kotlin.MainActivity"
android:theme="@style/AppTheme.Activity">

</activity>

<activity
android:name=".kotlin.RestaurantDetailActivity"
android:theme="@style/AppTheme.Activity" />
</application>

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.google.firebase.example.fireeats

import android.content.Intent
import com.firebase.example.internal.BaseEntryChoiceActivity
import com.firebase.example.internal.Choice

class EntryChoiceActivity : BaseEntryChoiceActivity() {

override fun getChoices(): List<Choice> {
return listOf(
Choice(
"Java",
"Run the Cloud Firestore quickstart written in Java.",
Intent(this, com.google.firebase.example.fireeats.java.MainActivity::class.java)),
Choice(
"Kotlin",
"Run the Cloud Firestore quickstart written in Kotlin.",
Intent(this, com.google.firebase.example.fireeats.kotlin.MainActivity::class.java))
)
}

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.google.firebase.example.fireeats;
package com.google.firebase.example.fireeats.java;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -9,7 +9,8 @@
import android.view.ViewGroup;
import android.widget.Spinner;

import com.google.firebase.example.fireeats.model.Restaurant;
import com.google.firebase.example.fireeats.R;
import com.google.firebase.example.fireeats.java.model.Restaurant;
import com.google.firebase.firestore.Query;

import butterknife.BindView;
Expand All @@ -31,16 +32,16 @@ interface FilterListener {

private View mRootView;

@BindView(R.id.spinner_category)
@BindView(R.id.spinnerCategory)
Spinner mCategorySpinner;

@BindView(R.id.spinner_city)
@BindView(R.id.spinnerCity)
Spinner mCitySpinner;

@BindView(R.id.spinner_sort)
@BindView(R.id.spinnerSort)
Spinner mSortSpinner;

@BindView(R.id.spinner_price)
@BindView(R.id.spinnerPrice)
Spinner mPriceSpinner;

private FilterListener mFilterListener;
Expand Down Expand Up @@ -73,7 +74,7 @@ public void onResume() {
ViewGroup.LayoutParams.WRAP_CONTENT);
}

@OnClick(R.id.button_search)
@OnClick(R.id.buttonSearch)
public void onSearchClicked() {
if (mFilterListener != null) {
mFilterListener.onFilter(getFilters());
Expand All @@ -82,7 +83,7 @@ public void onSearchClicked() {
dismiss();
}

@OnClick(R.id.button_cancel)
@OnClick(R.id.buttonCancel)
public void onCancelClicked() {
dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.google.firebase.example.fireeats;
package com.google.firebase.example.fireeats.java;

import android.content.Context;
import android.text.TextUtils;

import com.google.firebase.example.fireeats.model.Restaurant;
import com.google.firebase.example.fireeats.util.RestaurantUtil;
import com.google.firebase.example.fireeats.R;
import com.google.firebase.example.fireeats.java.model.Restaurant;
import com.google.firebase.example.fireeats.java.util.RestaurantUtil;
import com.google.firebase.firestore.Query;

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.google.firebase.example.fireeats;
package com.google.firebase.example.fireeats.java;

import android.arch.lifecycle.ViewModelProviders;
import android.content.DialogInterface;
Expand Down Expand Up @@ -26,12 +26,13 @@
import com.google.android.gms.tasks.OnCompleteListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.example.fireeats.adapter.RestaurantAdapter;
import com.google.firebase.example.fireeats.model.Rating;
import com.google.firebase.example.fireeats.model.Restaurant;
import com.google.firebase.example.fireeats.util.RatingUtil;
import com.google.firebase.example.fireeats.util.RestaurantUtil;
import com.google.firebase.example.fireeats.viewmodel.MainActivityViewModel;
import com.google.firebase.example.fireeats.R;
import com.google.firebase.example.fireeats.java.adapter.RestaurantAdapter;
import com.google.firebase.example.fireeats.java.model.Rating;
import com.google.firebase.example.fireeats.java.model.Restaurant;
import com.google.firebase.example.fireeats.java.util.RatingUtil;
import com.google.firebase.example.fireeats.java.util.RestaurantUtil;
import com.google.firebase.example.fireeats.java.viewmodel.MainActivityViewModel;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.FirebaseFirestore;
Expand Down Expand Up @@ -59,16 +60,16 @@ public class MainActivity extends AppCompatActivity implements
@BindView(R.id.toolbar)
Toolbar mToolbar;

@BindView(R.id.text_current_search)
@BindView(R.id.textCurrentSearch)
TextView mCurrentSearchView;

@BindView(R.id.text_current_sort_by)
@BindView(R.id.textCurrentSortBy)
TextView mCurrentSortByView;

@BindView(R.id.recycler_restaurants)
@BindView(R.id.recyclerRestaurants)
RecyclerView mRestaurantsRecycler;

@BindView(R.id.view_empty)
@BindView(R.id.viewEmpty)
ViewGroup mEmptyView;

private FirebaseFirestore mFirestore;
Expand Down Expand Up @@ -197,13 +198,13 @@ protected void onActivityResult(int requestCode, int resultCode, Intent data) {
}
}

@OnClick(R.id.filter_bar)
@OnClick(R.id.filterBar)
public void onFilterClicked() {
// Show the dialog containing filter options
mFilterDialog.show(getSupportFragmentManager(), FilterDialogFragment.TAG);
}

@OnClick(R.id.button_clear_filter)
@OnClick(R.id.buttonClearFilter)
public void onClearFilterClicked() {
mFilterDialog.resetFilters();

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.google.firebase.example.fireeats;
package com.google.firebase.example.fireeats.java;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -10,7 +10,8 @@
import android.widget.EditText;

import com.google.firebase.auth.FirebaseAuth;
import com.google.firebase.example.fireeats.model.Rating;
import com.google.firebase.example.fireeats.R;
import com.google.firebase.example.fireeats.java.model.Rating;

import butterknife.BindView;
import butterknife.ButterKnife;
Expand All @@ -24,10 +25,10 @@ public class RatingDialogFragment extends DialogFragment {

public static final String TAG = "RatingDialog";

@BindView(R.id.restaurant_form_rating)
@BindView(R.id.restaurantFormRating)
MaterialRatingBar mRatingBar;

@BindView(R.id.restaurant_form_text)
@BindView(R.id.restaurantFormText)
EditText mRatingText;

interface RatingListener {
Expand Down Expand Up @@ -67,7 +68,7 @@ public void onResume() {

}

@OnClick(R.id.restaurant_form_button)
@OnClick(R.id.restaurantFormButton)
public void onSubmitClicked(View view) {
Rating rating = new Rating(
FirebaseAuth.getInstance().getCurrentUser(),
Expand All @@ -81,7 +82,7 @@ public void onSubmitClicked(View view) {
dismiss();
}

@OnClick(R.id.restaurant_form_cancel)
@OnClick(R.id.restaurantFormCancel)
public void onCancelClicked(View view) {
dismiss();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.google.firebase.example.fireeats;
package com.google.firebase.example.fireeats.java;

import android.content.Context;
import android.os.Bundle;
Expand All @@ -18,10 +18,11 @@
import com.google.android.gms.tasks.OnFailureListener;
import com.google.android.gms.tasks.OnSuccessListener;
import com.google.android.gms.tasks.Task;
import com.google.firebase.example.fireeats.adapter.RatingAdapter;
import com.google.firebase.example.fireeats.model.Rating;
import com.google.firebase.example.fireeats.model.Restaurant;
import com.google.firebase.example.fireeats.util.RestaurantUtil;
import com.google.firebase.example.fireeats.R;
import com.google.firebase.example.fireeats.java.adapter.RatingAdapter;
import com.google.firebase.example.fireeats.java.model.Rating;
import com.google.firebase.example.fireeats.java.model.Restaurant;
import com.google.firebase.example.fireeats.java.util.RestaurantUtil;
import com.google.firebase.firestore.DocumentReference;
import com.google.firebase.firestore.DocumentSnapshot;
import com.google.firebase.firestore.EventListener;
Expand All @@ -43,31 +44,31 @@ public class RestaurantDetailActivity extends AppCompatActivity

public static final String KEY_RESTAURANT_ID = "key_restaurant_id";

@BindView(R.id.restaurant_image)
@BindView(R.id.restaurantImage)
ImageView mImageView;

@BindView(R.id.restaurant_name)
@BindView(R.id.restaurantName)
TextView mNameView;

@BindView(R.id.restaurant_rating)
@BindView(R.id.restaurantRating)
MaterialRatingBar mRatingIndicator;

@BindView(R.id.restaurant_num_ratings)
@BindView(R.id.restaurantNumRatings)
TextView mNumRatingsView;

@BindView(R.id.restaurant_city)
@BindView(R.id.restaurantCity)
TextView mCityView;

@BindView(R.id.restaurant_category)
@BindView(R.id.restaurantCategory)
TextView mCategoryView;

@BindView(R.id.restaurant_price)
@BindView(R.id.restaurantPrice)
TextView mPriceView;

@BindView(R.id.view_empty_ratings)
@BindView(R.id.viewEmptyRatings)
ViewGroup mEmptyView;

@BindView(R.id.recycler_ratings)
@BindView(R.id.recyclerRatings)
RecyclerView mRatingsRecycler;

private RatingDialogFragment mRatingDialog;
Expand Down Expand Up @@ -174,12 +175,12 @@ private void onRestaurantLoaded(Restaurant restaurant) {
.into(mImageView);
}

@OnClick(R.id.restaurant_button_back)
@OnClick(R.id.restaurantButtonBack)
public void onBackArrowClicked(View view) {
onBackPressed();
}

@OnClick(R.id.fab_show_rating_dialog)
@OnClick(R.id.fabShowRatingDialog)
public void onAddRatingClicked(View view) {
mRatingDialog.show(getSupportFragmentManager(), RatingDialogFragment.TAG);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.google.firebase.example.fireeats.adapter;
package com.google.firebase.example.fireeats.java.adapter;

import android.support.v7.widget.RecyclerView;
import android.util.Log;
Expand Down
Loading

0 comments on commit e1e8816

Please sign in to comment.