Last active
November 1, 2017 22:42
-
-
Save claraj/897d86a86423303f41cc3b48821691d3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.clara.moviereviewsfirebase; | |
import android.support.v7.app.AppCompatActivity; | |
import android.os.Bundle; | |
import android.util.Log; | |
import android.view.View; | |
import android.widget.Button; | |
import android.widget.EditText; | |
import android.widget.RatingBar; | |
import android.widget.TextView; | |
import android.widget.Toast; | |
import com.google.firebase.database.DataSnapshot; | |
import com.google.firebase.database.DatabaseError; | |
import com.google.firebase.database.DatabaseReference; | |
import com.google.firebase.database.FirebaseDatabase; | |
import com.google.firebase.database.GenericTypeIndicator; | |
import com.google.firebase.database.ValueEventListener; | |
import java.util.ArrayList; | |
import java.util.HashMap; | |
public class MainActivity extends AppCompatActivity { | |
EditText mMovieNameET, mMovieReviewTextET, mSearchMovieET; | |
RatingBar mMovieStars; | |
Button mSaveButton, mShowLatestReviewButton, mShowAllReviewsButton, mSearchMovieButton; | |
TextView mLatestMovieTV, mMovieSearchTV, mAllMoviesTV; | |
private static final String TAG = "Movie Review Activity"; | |
private static final String ALL_REVIEWS_KEY = "all_reviews"; | |
private DatabaseReference reviewsReference; | |
@Override | |
protected void onCreate(Bundle savedInstanceState) { | |
super.onCreate(savedInstanceState); | |
setContentView(R.layout.activity_main); | |
//References for components | |
mSaveButton = (Button) findViewById(R.id.save_review_button); | |
//mShowLatestReviewButton = (Button) findViewById(R.id.show_latest_review_button); | |
mSearchMovieButton = (Button) findViewById(R.id.search_movie_review_button); // not needed as UI updates automatically | |
//mShowAllReviewsButton = (Button) findViewById(R.id.show_all_reviews_button); // not needed as UI updates automatically | |
mMovieNameET = (EditText) findViewById(R.id.movie_name_et); | |
mMovieReviewTextET = (EditText) findViewById(R.id.movie_review_et); | |
mSearchMovieET = (EditText) findViewById(R.id.search_name_et); | |
mMovieStars = (RatingBar) findViewById(R.id.movie_stars_rb); | |
mLatestMovieTV = (TextView) findViewById(R.id.latest_movie_data_tv); | |
mMovieSearchTV = (TextView) findViewById(R.id.search_movie_result_tv); | |
mAllMoviesTV = (TextView) findViewById(R.id.all_movie_data_tv); | |
addListeners(); | |
FirebaseDatabase database = FirebaseDatabase.getInstance(); | |
DatabaseReference dbReference = database.getReference(); | |
reviewsReference = dbReference.child(ALL_REVIEWS_KEY); | |
fetchAllReviews(); | |
fetchLatestReview(); | |
} | |
private void saveReview() { | |
String name = mMovieNameET.getText().toString(); | |
String reviewText = mMovieReviewTextET.getText().toString(); | |
float stars = mMovieStars.getRating(); | |
// TODO | |
} | |
private void fetchLatestReview() { | |
// TODO | |
} | |
// Save data in a list to preserve order. | |
// Can use this approach if order is important | |
private void fetchAllReviews() { | |
// TODO | |
} | |
/* | |
// Fetch all reviews, marshalls data into a HashMap. | |
// Can use this approach if it doesn't matter what order the results of a list are in | |
private void fetchAllReviews() { | |
// TOD | |
} | |
*/ | |
private void searchReviews() { | |
// TODO | |
} | |
private void addListeners() { | |
//Register listeners for buttons | |
mSaveButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View view) { | |
saveReview(); | |
} | |
}); | |
mSearchMovieButton.setOnClickListener(new View.OnClickListener() { | |
@Override | |
public void onClick(View v) { | |
searchReviews(); | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment