diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..39fb081 --- /dev/null +++ b/.gitignore @@ -0,0 +1,9 @@ +*.iml +.gradle +/local.properties +/.idea/workspace.xml +/.idea/libraries +.DS_Store +/build +/captures +.externalNativeBuild diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..96cc43e --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/copyright/profiles_settings.xml b/.idea/copyright/profiles_settings.xml new file mode 100644 index 0000000..e7bedf3 --- /dev/null +++ b/.idea/copyright/profiles_settings.xml @@ -0,0 +1,3 @@ + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..7ac24c7 --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,18 @@ + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..5d19981 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..f5e9010 --- /dev/null +++ b/.idea/modules.xml @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/README.md b/README.md index fe059e5..7238033 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,3 @@ -# sp17proj4android - Repository for Spring 2017 MDB Android Training Program Mini-Project 4 Submissions Finalized mini-projects should be stored in personal portfolios, but this repository will be used for providing feedback on code quality using the GitHub code review features. diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..796b96d --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..80f42d6 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,44 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 26 + buildToolsVersion "26.0.1" + defaultConfig { + applicationId "com.example.joey.mdbsocials" + minSdkVersion 15 + targetSdkVersion 26 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + vectorDrawables.useSupportLibrary = true + + } + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + compile fileTree(dir: 'libs', include: ['*.jar']) + androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { + exclude group: 'com.android.support', module: 'support-annotations' + }) + compile 'com.android.support:appcompat-v7:26.0.0-alpha1' + compile 'com.android.support.constraint:constraint-layout:1.0.2' + compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' + compile 'com.android.support:cardview-v7:26.0.0-alpha1' + compile 'com.github.bumptech.glide:glide:3.8.0' + compile 'com.google.firebase:firebase-core:10.0.1' + compile 'com.google.firebase:firebase-auth:10.0.1' + compile 'com.google.firebase:firebase-database:10.0.1' + compile 'com.google.firebase:firebase-storage:10.0.1' + compile 'com.android.support:design:26.0.0-alpha1' + compile 'com.firebaseui:firebase-ui-storage:0.6.0' + + testCompile 'junit:junit:4.12' +} + +apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/app/google-services.json b/app/google-services.json new file mode 100644 index 0000000..5c798bf --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,42 @@ +{ + "project_info": { + "project_number": "406430029370", + "firebase_url": "https://mdbsocials-1b45c.firebaseio.com", + "project_id": "mdbsocials-1b45c", + "storage_bucket": "mdbsocials-1b45c.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:406430029370:android:479d592c2c2c236d", + "android_client_info": { + "package_name": "com.example.joey.mdbsocials" + } + }, + "oauth_client": [ + { + "client_id": "406430029370-0ltu61tdn3mt4p8ddnabgetq3ma80m63.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyA7qHngMUfLUE3EGZDsbUIEvobSVuvi0Xc" + } + ], + "services": { + "analytics_service": { + "status": 1 + }, + "appinvite_service": { + "status": 1, + "other_platform_oauth_client": [] + }, + "ads_service": { + "status": 2 + } + } + } + ], + "configuration_version": "1" +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..c1dea9d --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,25 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /home/joey/Android/Sdk/tools/proguard/proguard-android.txt +# You can edit the include path and order by changing the proguardFiles +# directive in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# Add any project specific keep options here: + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile diff --git a/app/src/androidTest/java/com/example/joey/mdbsocials/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/joey/mdbsocials/ExampleInstrumentedTest.java new file mode 100644 index 0000000..49fe7cc --- /dev/null +++ b/app/src/androidTest/java/com/example/joey/mdbsocials/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.joey.mdbsocials; + +import android.content.Context; +import android.support.test.InstrumentationRegistry; +import android.support.test.runner.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumentation test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() throws Exception { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getTargetContext(); + + assertEquals("com.example.joey.mdbsocials", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..ffc3702 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/joey/mdbsocials/CreateSocial.java b/app/src/main/java/com/example/joey/mdbsocials/CreateSocial.java new file mode 100644 index 0000000..5ad9e10 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/CreateSocial.java @@ -0,0 +1,79 @@ +package com.example.joey.mdbsocials; + +import android.content.Intent; +import android.icu.text.SimpleDateFormat; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.Toast; + +import com.google.android.gms.tasks.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.database.ServerValue; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; +import com.google.firebase.storage.UploadTask; + +public class CreateSocial extends AppCompatActivity implements View.OnClickListener{ + + private Uri file; + private EditText socialName; + private EditText socialDate; + private EditText socialDescription; + private ImageView previewImage; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_create_social); + + socialName = (EditText) findViewById(R.id.socialName); + socialDate = (EditText) findViewById(R.id.profileDate); + socialDescription = (EditText) findViewById(R.id.socalDescription); + previewImage = (ImageView) findViewById(R.id.imagePreview); + + findViewById(R.id.addImage).setOnClickListener(this); + findViewById(R.id.createSocial).setOnClickListener(this); + + } + + @Override + public void onClick(View view) { + switch (view.getId()){ + case R.id.createSocial: + String name = socialName.getText().toString(); + String date = socialDate.getText().toString(); + String description = socialDescription.getText().toString(); + FirebaseUtils.pushNewSocial(this, name, description, date, file); + + break; + case R.id.addImage: + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + startActivityForResult(intent, 1); + break; + } + } + + @Override + public void onActivityResult(int requestCode, int resultCode, Intent data){ + super.onActivityResult(requestCode, resultCode, data); + + if(resultCode == RESULT_OK && requestCode == 1){ + file = data.getData(); + previewImage.setImageURI(file); + + + } + } + +} diff --git a/app/src/main/java/com/example/joey/mdbsocials/EventProfile.java b/app/src/main/java/com/example/joey/mdbsocials/EventProfile.java new file mode 100644 index 0000000..4d88f9b --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/EventProfile.java @@ -0,0 +1,90 @@ +package com.example.joey.mdbsocials; + +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.firebase.ui.storage.images.FirebaseImageLoader; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +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.MutableData; +import com.google.firebase.database.Transaction; +import com.google.firebase.database.ValueEventListener; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.util.ArrayList; + +public class EventProfile extends AppCompatActivity { + + private int interested; + private Button interestedButton; + private ArrayList people; + private FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_event_profile); + + final String id = getIntent().getStringExtra("id"); + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/socials/" + id); + interested = getIntent().getIntExtra("interested", 0); + people = new ArrayList<>(); + interestedButton = (Button) findViewById(R.id.profileInterestButton); + + ((TextView) findViewById(R.id.profileTitle)).setText(getIntent().getStringExtra("name")); + ((TextView) findViewById(R.id.profileDescription)).setText(getIntent().getStringExtra("description")); + ((TextView) findViewById(R.id.profileDate)).setText(getIntent().getStringExtra("date")); + ((TextView) findViewById(R.id.profileInterested)).setText(""+interested); + + FirebaseUtils.loadImageFromFirebase(id, (ImageView) findViewById(R.id.profileImage), (ProgressBar) findViewById(R.id.progressBarProfile)); + + //use transaction to update the number + + //TODO: Could not determine how to get this listener in FirebaseUtils.class because the onclicklistener can ONLY be set after valueEventListener executed + ref.child("people").addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + for (DataSnapshot person : dataSnapshot.getChildren()){ + people.add(person.getValue(String.class)); + } + if(people.contains(user.getEmail())){ + interestedButton.setText("Already Interested!"); + } + interestedButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + if(!people.contains(user.getEmail())){ + FirebaseUtils.addInterestedTransaction(id); + interested++; + ((TextView) findViewById(R.id.profileInterested)).setText(""+interested); + + } + } + }); + } + + @Override + public void onCancelled(DatabaseError databaseError) { + Toast.makeText(EventProfile.this,"Oh no! Database error!", Toast.LENGTH_SHORT).show(); + } + }); + + + } + + + +} diff --git a/app/src/main/java/com/example/joey/mdbsocials/FeedActivity.java b/app/src/main/java/com/example/joey/mdbsocials/FeedActivity.java new file mode 100644 index 0000000..8affa05 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/FeedActivity.java @@ -0,0 +1,64 @@ +package com.example.joey.mdbsocials; + +import android.content.Intent; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.View; +import android.widget.ListAdapter; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; +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.ValueEventListener; + +import java.util.ArrayList; +import java.util.Collections; + +public class FeedActivity extends AppCompatActivity implements View.OnClickListener{ + + ArrayList socials = new ArrayList<>(); + final SocialAdapter adapter = new SocialAdapter(FeedActivity.this, socials); + private DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/socials"); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_feed); + + RecyclerView activityList = (RecyclerView) findViewById(R.id.activityList); + activityList.setLayoutManager(new LinearLayoutManager(this)); + + activityList.setAdapter(adapter); + + FirebaseUtils.initFeed(FeedActivity.this, adapter); + + findViewById(R.id.newSocialFAB).setOnClickListener(this); + + } + + @Override + public void onClick(View view) { + switch (view.getId()){ + case R.id.newSocialFAB: + Intent intent = new Intent(getApplicationContext(), CreateSocial.class); + startActivity(intent); + break; + } + + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + Intent intent = new Intent(FeedActivity.this, LoginActivity.class); + FirebaseAuth.getInstance().signOut(); + startActivity(intent); + } +} \ No newline at end of file diff --git a/app/src/main/java/com/example/joey/mdbsocials/FirebaseUtils.java b/app/src/main/java/com/example/joey/mdbsocials/FirebaseUtils.java new file mode 100644 index 0000000..334dcd3 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/FirebaseUtils.java @@ -0,0 +1,288 @@ +package com.example.joey.mdbsocials; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; +import android.os.AsyncTask; +import android.support.annotation.NonNull; +import android.util.Log; +import android.view.View; +import android.widget.EditText; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.Toast; + +import com.google.android.gms.tasks.OnCompleteListener; +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.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; +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.MutableData; +import com.google.firebase.database.Transaction; +import com.google.firebase.database.ValueEventListener; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; +import com.google.firebase.storage.UploadTask; + +import java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Collections; + +/** + * Created by joey on 10/6/17. + */ + +public class FirebaseUtils { + + + /** + * Creates a new user in firebase + * @param context the context of the signup activity - used to display toasts + * @param email the email the user wishes to create account with as string + * @param pass1 password string + * @param pass2 check to see if two passwords match + */ + public static void attemptSignup(final Context context, String email, String pass1, String pass2) { + if (email.equals("")) { + Toast.makeText(context, "Enter Valid email!", Toast.LENGTH_SHORT).show(); + } else if (pass1.equals("") || pass2.equals("")) { + Toast.makeText(context, "Complete both password banks!", Toast.LENGTH_SHORT).show(); + } else if (!pass1.equals(pass2)) { + Toast.makeText(context, "Passwords do not match!", Toast.LENGTH_SHORT).show(); + } else { + FirebaseAuth.getInstance().createUserWithEmailAndPassword(email, pass1).addOnCompleteListener((Activity) context, + new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (!task.isSuccessful()) { + Toast.makeText(context, "Signup failed!", Toast.LENGTH_SHORT).show(); + } else { + Intent intent = new Intent(context, FeedActivity.class); + context.startActivity(intent); + } + } + }); + } + + } + + /** + *Attempts a login based on user input in fields + * @param context the context of Login Activity + * @param email a string that is the email the user submits + * @param password a string that is the password the user submits. + */ + public static void attemptLogin(final Context context, String email, String password) { + + if (!email.equals("") && !password.equals("")) { + FirebaseAuth.getInstance().signInWithEmailAndPassword(email, password).addOnCompleteListener((Activity) context, + new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + Log.d("FIREBASE", "signInWithEmail:onComplete:"+task.isSuccessful()); + + if(!task.isSuccessful()){ + Log.w("FIREBASE", "signInWithEmail:failed", task.getException()); + Toast.makeText(context, "Login failed!", Toast.LENGTH_SHORT).show(); + }else { + Intent intent = new Intent(context, FeedActivity.class); + context.startActivity(intent); + Toast.makeText(context, "Login SUCCESS!", Toast.LENGTH_SHORT).show(); + } + + } + }); + + } + } + + /** + * Attempts to create a new social based on entered fields. + * @param context context of CreateSocial Activity to push toasts / start activiites + * @param name name of new social + * @param description description of social + * @param date date of social + * @param file image file associated with social + */ + public static void pushNewSocial(final CreateSocial context, final String name, final String description, final String date, final Uri file){ + //check to see if image exists + if(file == null){ + Toast.makeText(context, "no image selected!", Toast.LENGTH_SHORT).show(); + return; + } + if(name.equals("") || description.equals("") ||date.equals("")){ + Toast.makeText(context, "Must fill in fields", Toast.LENGTH_SHORT).show(); + return; + } + //get Firebase information + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/socials"); + StorageReference storageReference = FirebaseStorage.getInstance().getReference(); + final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); + + + //First generate a key for the image + final String key = ref.push().getKey(); + StorageReference imageRef = storageReference.child(key + ".png"); + + imageRef.putFile(file).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception e) { + Toast.makeText(context, "no image selected!", Toast.LENGTH_SHORT).show(); + } + }).addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + Social social = new Social(key, user.getEmail(), name, description, date); + + ref.child(key).setValue(social); + + Intent returnIntent = new Intent(context, FeedActivity.class); + context.startActivity(returnIntent); + + } + }); + } + + /** + * Creates the firebase listener for social objects and adds them to the feed Recycler view. + * @param context context of the feed activity + * @param adapter the adapter of the recycler view + */ + public static void initFeed(final FeedActivity context, final SocialAdapter adapter){ + final ArrayList socials = adapter.getSocials(); + DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/socials"); + ref.orderByChild("timestamp").addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + ArrayList newSocials = new ArrayList<>(); + for (DataSnapshot socialObject : dataSnapshot.getChildren()){ + Social social = socialObject.getValue(Social.class); + newSocials.add(social); + } + //CODE DOES ORDER BY TIMESTAMP, but in descending order, reverse to chagne to ascending. + Collections.reverse(newSocials); + socials.clear(); + socials.addAll(newSocials); + adapter.notifyDataSetChanged(); + } + + @Override + public void onCancelled(DatabaseError databaseError) { + Toast.makeText(context,"Oh no! Database error!", Toast.LENGTH_SHORT).show(); + } + }); + + } + + /** + * Class used for asycronous image downloading. + */ + private static class DownloadImagesTask extends AsyncTask { + + private ImageView imageView; + private ProgressBar progressBar; + + public DownloadImagesTask(ImageView imageView, ProgressBar progressBar){ + this.imageView = imageView; + this.progressBar = progressBar; + } + + @Override + protected Bitmap doInBackground(Uri... uris) { + if(uris.length == 1){ + return downloadImage(uris[0].toString()); + } + return null; + } + + @Override + protected void onPreExecute() { + imageView.setVisibility(View.INVISIBLE); + progressBar.setVisibility(View.VISIBLE); + } + + @Override + protected void onPostExecute(Bitmap result) { + imageView.setImageBitmap(result); + imageView.setVisibility(View.VISIBLE); + progressBar.setVisibility(View.GONE); + } + + + private Bitmap downloadImage(String src) { + try { + URL url = new URL(src); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + Bitmap myBitmap = BitmapFactory.decodeStream(input); + return myBitmap; + } catch (MalformedURLException e) { + Log.d("Exceptions", e.getMessage()); + } catch (IOException e) { + Log.d("Exceptions", e.getMessage()); + } + return null; + } + } + + /** + * Instantiates a new Download image task to pull an image from firebase for a given social + * @param id the id of the social + * @param imageView view where image is placed + * @param progressBar progress bar that image replaces. + */ + public static void loadImageFromFirebase(final String id, final ImageView imageView, final ProgressBar progressBar){ + StorageReference storageReference = FirebaseStorage.getInstance().getReference().child(id+".png"); + storageReference.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) { + new DownloadImagesTask(imageView, progressBar).execute(uri); + } + }); + + } + + /** + * Uses firebase transaction to update interested field + * @param id id of the social. + */ + public static void addInterestedTransaction(String id){ + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/socials/" + id); + String key = ref.child("people").push().getKey(); + ref.child("people").child(key).setValue(FirebaseAuth.getInstance().getCurrentUser().getEmail()); + ref.child("interested").runTransaction(new Transaction.Handler() { + @Override + public Transaction.Result doTransaction(MutableData mutableData) { + int interested = mutableData.getValue(Integer.class); + interested++; + mutableData.setValue(interested); + return Transaction.success(mutableData); + } + + @Override + public void onComplete(DatabaseError databaseError, boolean b, + DataSnapshot dataSnapshot) { + Log.d("FIREBASE", "Successful incrementation of interested count"); + + } + }); + + } + + +} diff --git a/app/src/main/java/com/example/joey/mdbsocials/LoginActivity.java b/app/src/main/java/com/example/joey/mdbsocials/LoginActivity.java new file mode 100644 index 0000000..786d381 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/LoginActivity.java @@ -0,0 +1,82 @@ +package com.example.joey.mdbsocials; + + +import android.content.Intent; +import android.support.annotation.NonNull; +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.Toast; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +public class LoginActivity extends AppCompatActivity implements View.OnClickListener { + + private static FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_login); + + findViewById(R.id.loginButton).setOnClickListener(this); + findViewById(R.id.signUpButton).setOnClickListener(this); + + + mAuth = FirebaseAuth.getInstance(); + + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = firebaseAuth.getCurrentUser(); + if(user != null) { + //user is signed in + Log.d("FIREBASE", "onAuthStateChanged:signed_in" + user.getUid()); + }else{ + //user is signed out + Log.d("FIREABASE", "onAuthStateChanged:signed_out"); + } + } + }; + + mAuth.addAuthStateListener(mAuthListener); + + } + + @Override + public void onClick(View view) { + Log.d("THIS", "SHIT WAS CALLED"); + switch(view.getId()){ + case R.id.loginButton: + String email = ((EditText) findViewById(R.id.emailText)).getText().toString(); + String password = ((EditText) findViewById(R.id.passwordText)).getText().toString(); + FirebaseUtils.attemptLogin(this, email, password); + break; + case R.id.signUpButton: + Intent intent = new Intent(LoginActivity.this, SignUpActivity.class); + startActivity(intent); + break; + default: + break; + } + } + + + + @Override + protected void onResume() { + super.onResume(); + mAuth.signOut(); + ((EditText) findViewById(R.id.emailText)).setText(""); + ((EditText) findViewById(R.id.passwordText)).setText(""); + + } +} diff --git a/app/src/main/java/com/example/joey/mdbsocials/SignUpActivity.java b/app/src/main/java/com/example/joey/mdbsocials/SignUpActivity.java new file mode 100644 index 0000000..e1b55a7 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/SignUpActivity.java @@ -0,0 +1,58 @@ +package com.example.joey.mdbsocials; + +import android.content.Intent; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.Toast; + +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.auth.AuthResult; +import com.google.firebase.auth.FirebaseAuth; + +public class SignUpActivity extends AppCompatActivity implements View.OnClickListener { + + private FirebaseAuth mAuth; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sign_up); + + findViewById(R.id.createAccountButton).setOnClickListener(this); + + mAuth = FirebaseAuth.getInstance(); + } + + @Override + public void onClick(View view) { + switch (view.getId()){ + case R.id.createAccountButton: + String email = ((EditText) findViewById(R.id.signUpEmailText)).getText().toString(); + String pass1 = ((EditText) findViewById(R.id.signUpPasswordText)).getText().toString(); + String pass2 = ((EditText) findViewById(R.id.confirmPasswordText)).getText().toString(); + FirebaseUtils.attemptSignup(this, email, pass1, pass2); + break; + } + } + + @Override + protected void onResume() { + super.onResume(); + mAuth.signOut(); + ((EditText) findViewById(R.id.signUpEmailText)).setText(""); + ((EditText) findViewById(R.id.signUpPasswordText)).setText(""); + ((EditText) findViewById(R.id.confirmPasswordText)).setText(""); + } + + @Override + public void onBackPressed() { + super.onBackPressed(); + Intent intent = new Intent(SignUpActivity.this, LoginActivity.class); + startActivity(intent); + } +} diff --git a/app/src/main/java/com/example/joey/mdbsocials/Social.java b/app/src/main/java/com/example/joey/mdbsocials/Social.java new file mode 100644 index 0000000..71c0eb0 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/Social.java @@ -0,0 +1,85 @@ +package com.example.joey.mdbsocials; + +/** + * Created by joey on 9/28/17. + */ + +public class Social { + String id; + String name; + String owner; + String date; + String description; + int interested = 0; + + public Social(){} + + + + public Social(String id, String owner, String name, String date, String description, int interested) { + this.id = id; + this.owner = owner; + this.name = name; + this.date = date; + this.description = description; + this.interested = interested; + } + + public Social(String id, String owner, String name, String date, String description) { + this.id = id; + this.owner = owner; + this.name = name; + this.date = date; + this.description = description; + this.interested = 0; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public int getInterested() { + return interested; + } + + public void setInterested(int interested) { + this.interested = interested; + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/joey/mdbsocials/SocialAdapter.java b/app/src/main/java/com/example/joey/mdbsocials/SocialAdapter.java new file mode 100644 index 0000000..b18c731 --- /dev/null +++ b/app/src/main/java/com/example/joey/mdbsocials/SocialAdapter.java @@ -0,0 +1,93 @@ +package com.example.joey.mdbsocials; + +import android.content.Context; +import android.content.Intent; +import android.support.v7.widget.RecyclerView; +import android.util.Log; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.ProgressBar; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.firebase.ui.storage.images.FirebaseImageLoader; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.util.ArrayList; + +/** + * Created by joey on 9/27/17. + */ + +public class SocialAdapter extends RecyclerView.Adapter { + private Context context; + private ArrayList socials; + + public ArrayList getSocials(){ + return socials; + } + + public SocialAdapter(Context context, ArrayList socials){ + this.context = context; + this.socials = socials; + } + + @Override + public SocialViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(parent.getContext()).inflate(R.layout.social_row, parent, false); + return new SocialViewHolder(v); + } + + @Override + public void onBindViewHolder(SocialViewHolder holder, int position) { + Social social = socials.get(position); + holder.emailText.setText(social.owner); + holder.interestedCount.setText("" + social.interested); + holder.eventName.setText(social.name); + + FirebaseUtils.loadImageFromFirebase(social.id, holder.eventImage, holder.progressBar); + } + + @Override + public int getItemCount(){ + return socials.size(); + } + + class SocialViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener { + TextView eventName; + ImageView eventImage; + TextView interestedCount; + TextView emailText; + ProgressBar progressBar; + + public SocialViewHolder(View v){ + super(v); + eventName = v.findViewById(R.id.eventName); + eventImage = v.findViewById(R.id.eventImage); + interestedCount = v.findViewById(R.id.eventInterested); + emailText = v.findViewById(R.id.eventEmail); + progressBar = v.findViewById(R.id.progressBar); + itemView.setOnClickListener(this); + } + + @Override + public void onClick(View view) { + // implement code to open the detail screen for the current view + Social s = socials.get(getAdapterPosition()); + Intent intent = new Intent(context, EventProfile.class); + intent.putExtra("id", s.id); + intent.putExtra("name", s.name); + intent.putExtra("date", s.date); + intent.putExtra("description", s.description); + intent.putExtra("interested", s.interested); + + context.startActivity(intent); + + + } + } + +} diff --git a/app/src/main/res/drawable/ic_add_black_24dp.xml b/app/src/main/res/drawable/ic_add_black_24dp.xml new file mode 100644 index 0000000..0258249 --- /dev/null +++ b/app/src/main/res/drawable/ic_add_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/mdblogo.png b/app/src/main/res/drawable/mdblogo.png new file mode 100644 index 0000000..5295423 Binary files /dev/null and b/app/src/main/res/drawable/mdblogo.png differ diff --git a/app/src/main/res/layout/activity_create_social.xml b/app/src/main/res/layout/activity_create_social.xml new file mode 100644 index 0000000..e0cb2ca --- /dev/null +++ b/app/src/main/res/layout/activity_create_social.xml @@ -0,0 +1,140 @@ + + + + + + + + + + + + + + + + + +