diff --git a/.gitignore b/.gitignore new file mode 100755 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..8cdb7eb --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/modules.xml b/.idea/modules.xml new file mode 100644 index 0000000..e455c7c --- /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/app/.gitignore b/app/.gitignore new file mode 100755 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 100755 index 0000000..97d0298 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,46 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "com.example.datarsd1.mdbsocials_2" + minSdkVersion 15 + targetSdkVersion 25 + versionCode 1 + versionName "1.0" + testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" + } + 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:25.1.1' + compile 'com.google.firebase:firebase-auth:9.6.1' + compile 'com.google.firebase:firebase-database:9.6.1' + compile 'com.google.firebase:firebase-storage:9.6.1' + testCompile 'junit:junit:4.12' + compile 'com.android.support.constraint:constraint-layout:1.0.0-alpha8' + compile 'com.google.android.gms:play-services-auth:9.6.1' + compile 'com.google.android.gms:play-services-gcm:9.6.1' + compile 'com.android.support:recyclerview-v7:25.1.1' + compile 'com.android.support:cardview-v7:25.1.1' + compile 'com.android.support:support-v4:25.1.1' + compile 'com.github.bumptech.glide:glide:3.7.0' + compile 'com.android.support:palette-v7:25.1.1' + compile 'com.android.support:design:25.1.1' +} + + + + +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 100755 index 0000000..febf3e7 --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,55 @@ +{ + "project_info": { + "project_number": "958355265554", + "firebase_url": "https://mdbsocials-2.firebaseio.com", + "project_id": "mdbsocials-2", + "storage_bucket": "mdbsocials-2.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:958355265554:android:cfaa8e4aac594fa7", + "android_client_info": { + "package_name": "com.example.datarsd1.mdbsocials_2" + } + }, + "oauth_client": [ + { + "client_id": "958355265554-9rpqldndbvfnlm0jlrchfgcut9d87k14.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "com.example.datarsd1.mdbsocials_2", + "certificate_hash": "c0769d44fad38d3f70d2e1943ac41688c92dd43b" + } + }, + { + "client_id": "958355265554-rnc9pfabbfs69l3ohn6m7430ieh0meh4.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyA4hwDtXVryud26rBOs-kmJtCNhVeuU2v0" + } + ], + "services": { + "analytics_service": { + "status": 1 + }, + "appinvite_service": { + "status": 2, + "other_platform_oauth_client": [ + { + "client_id": "958355265554-rnc9pfabbfs69l3ohn6m7430ieh0meh4.apps.googleusercontent.com", + "client_type": 3 + } + ] + }, + "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 100755 index 0000000..4c601d5 --- /dev/null +++ b/app/proguard-rules.pro @@ -0,0 +1,17 @@ +# Add project specific ProGuard rules here. +# By default, the flags in this file are appended to flags specified +# in /Users/datarsd1/Library/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 *; +#} diff --git a/app/src/androidTest/java/com/example/datarsd1/mdbsocials_2/ExampleInstrumentedTest.java b/app/src/androidTest/java/com/example/datarsd1/mdbsocials_2/ExampleInstrumentedTest.java new file mode 100755 index 0000000..4a1df12 --- /dev/null +++ b/app/src/androidTest/java/com/example/datarsd1/mdbsocials_2/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.example.datarsd1.mdbsocials_2; + +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.datarsd1.mdbsocials_2", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100755 index 0000000..43b7dc5 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,27 @@ + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/AddSocial.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/AddSocial.java new file mode 100755 index 0000000..f45cd24 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/AddSocial.java @@ -0,0 +1,124 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.ContentValues; +import android.content.DialogInterface; +import android.content.Intent; +import android.net.Uri; +import android.provider.MediaStore; +import android.support.v7.app.AlertDialog; +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.ImageView; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +public class AddSocial extends AppCompatActivity implements View.OnClickListener{ + + private EditText newTitleText, newDateText, newDescText; + private FirebaseAuth mAuth; + private String firebasePathLocation; + private DatabaseReference mDatabase; + private ImageView preview; + + private Button addEventButton, uploadImageButton; + + private Uri eventimageuri; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_add_social); + + newTitleText = (EditText)findViewById(R.id.newEventTitle); + newDateText = (EditText)findViewById(R.id.newEventDate); + newDescText = (EditText)findViewById(R.id.newEventDesc); + + mDatabase = FirebaseDatabase.getInstance().getReference(); + final String id = mDatabase.child("Socials").push().getKey(); + mAuth = FirebaseAuth.getInstance(); + + preview = (ImageView)findViewById(R.id.eventImagePreview); + + addEventButton = (Button)findViewById(R.id.newEventCreate); + uploadImageButton = (Button)findViewById(R.id.newEventImage); + addEventButton.setOnClickListener(this); + uploadImageButton.setOnClickListener(this); + } + + public void onClick(View v) + { + switch(v.getId()) + { + case R.id.newEventCreate: + Log.d("new evt clicked", "button onclick working"); + if (eventimageuri==null|| newTitleText.getText()==null || newDateText.getText()==null || newDescText.getText()==null || + newTitleText.getText().toString().length()==0 || newDateText.getText().toString().length()==0 || newDescText.getText().toString().length()==0) + { + Toast.makeText(getApplicationContext(),"Please Enter All Fields Properly",Toast.LENGTH_LONG).show(); + }else + { + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference(); + final String key = ref.child("Socials").push().getKey(); + StorageReference storageRef = FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-2.appspot.com"); + StorageReference riversRef = storageRef.child("eventPics/" + key + ".jpg"); + + String name = newTitleText.getText().toString(); + String date = newDateText.getText().toString(); + String desc = newDescText.getText().toString(); + String host = mAuth.getCurrentUser().getEmail(); + + FirebaseUtils.writeEventToDB(mDatabase, riversRef, eventimageuri, key, name, date, desc, host, mAuth); + startActivity(new Intent(getApplicationContext(),UserFeedActivity.class)); + } + break; + case R.id.newEventImage: + AlertDialog alertDialog = new AlertDialog.Builder(AddSocial.this).create(); + alertDialog.setTitle("Image Upload Options"); + alertDialog.setButton(AlertDialog.BUTTON_NEUTRAL, "Take a Photo", new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int which) + { + dialog.dismiss(); + Intent takePictureIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); + + ContentValues values = new ContentValues(); + values.put(MediaStore.Images.Media.TITLE, "Image"); + Uri tempuri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values); + takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, tempuri); + startActivityForResult(takePictureIntent, 0); + } + }); + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Upload from Gallery", new DialogInterface.OnClickListener() + { + public void onClick(DialogInterface dialog, int which) { + dialog.dismiss(); + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + startActivityForResult(intent, 1); } + }); + alertDialog.show(); + Button glitchy = alertDialog.getButton(AlertDialog.BUTTON_NEUTRAL); + glitchy.setEnabled(false); + break; + } + } + + protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) + { + super.onActivityResult(requestCode, resultCode, imageReturnedIntent); + if (resultCode == RESULT_OK && requestCode == 1) { + eventimageuri = imageReturnedIntent.getData(); + preview.setImageURI(eventimageuri); + } + } +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/DownloadImageTask.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/DownloadImageTask.java new file mode 100755 index 0000000..09e86aa --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/DownloadImageTask.java @@ -0,0 +1,87 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.os.AsyncTask; +import android.util.Log; +import android.widget.ImageView; + +import com.bumptech.glide.Glide; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.concurrent.ExecutionException; + +import static android.R.attr.bitmap; + +/** + * Created by Adhiraj Datar on 3/2/2017. + */ + +public class DownloadImageTask extends AsyncTask { + private ImageView container; + private ProgressDialog mDialog; + private Context context; + private Activity act; + private Bitmap bitmap; + + public DownloadImageTask(Activity act, Context context, ImageView mActivity) { + super(); + this.container = mActivity; + this.act = act; + this.context = context; + mDialog = new ProgressDialog(act); + bitmap = null; + } + + protected void onPreExecute() { + container.setImageBitmap(null); + mDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); + mDialog.setCancelable(true); + mDialog.setMessage("Loading..."); + mDialog.setProgress(0); + mDialog.show(); + } + + protected Bitmap doInBackground(String... urls) { + for (String s: urls) + { + try{ + bitmap = Glide.with(context) + .load(s) + .asBitmap() + .into(100,100) + .get(); + } catch (final ExecutionException e) { + Log.e("h", e.getMessage()); + } catch (final InterruptedException e) { + Log.e("a", e.getMessage()); + } catch (final NullPointerException e) { + // + } + if (isCancelled()) break; + } + return bitmap; + } + protected void onProgressUpdate(Integer... progress) { + mDialog.show(); + mDialog.setProgress(progress[0]); + } + + protected void onPostExecute(Bitmap result) { + if (result != null) { + container.setImageBitmap(result); + } + else { + + } + + mDialog.dismiss(); + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/EventDetailsActivity.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/EventDetailsActivity.java new file mode 100755 index 0000000..9795177 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/EventDetailsActivity.java @@ -0,0 +1,199 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.Intent; +import android.net.Uri; +import android.support.design.widget.FloatingActionButton; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.Menu; +import android.view.MenuItem; +import android.view.View; +import android.widget.Button; +import android.widget.CheckBox; +import android.widget.ImageView; +import android.widget.TextView; +import android.widget.Toast; + +import com.bumptech.glide.Glide; +import com.google.android.gms.tasks.OnSuccessListener; +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 com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.sql.Array; +import java.util.ArrayList; + +public class EventDetailsActivity extends AppCompatActivity implements View.OnClickListener{ + + TextView name, host, date, desc; + ImageView wallpaper, hostimg; + FirebaseAuth mAuth; + DatabaseReference mDatabaseRef; + StorageReference mStorageRef; + Button interestButton; + FloatingActionButton eventadd; + + ArrayList interestedNames, interestedEmails, interestedIds; + + String user; + + int initialNumInterested; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_event_details); + + user = FirebaseAuth.getInstance().getCurrentUser().getUid(); + + mAuth = FirebaseAuth.getInstance(); + mDatabaseRef = FirebaseDatabase.getInstance().getReference(); + mStorageRef = FirebaseStorage.getInstance().getReference(); + + interestedNames = new ArrayList<>(); + interestedEmails = new ArrayList<>(); + interestedIds = new ArrayList<>(); + + wallpaper = (ImageView)findViewById(R.id.profilewallpaper); + hostimg = (ImageView)findViewById(R.id.profileimage); + + name = (TextView)findViewById(R.id.eventNameDisplay); + name.setText(getIntent().getExtras().getString("title")); + + host = (TextView)findViewById(R.id.eventHostDisplay); + host.setText("By: " + getIntent().getExtras().getString("host")); + + date = (TextView)findViewById(R.id.eventDateDisplay); + date.setText("Date: " + getIntent().getExtras().getString("date")); + + desc = (TextView)findViewById(R.id.eventDescDisplay); + desc.setText(getIntent().getExtras().getString("desc")); + + initialNumInterested = getIntent().getExtras().getInt("numInterested"); + + StorageReference evtImgRef = mStorageRef.child(getIntent().getExtras().getString("firebasePath")); + evtImgRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) + { + new DownloadImageTask(EventDetailsActivity.this, getApplicationContext(), wallpaper).execute(uri.toString()); + } + }); + + final StorageReference hostImgRef = mStorageRef.child("profiles/"+getIntent().getExtras().getString("hostuid")+".jpg"); + hostImgRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) + { + new DownloadImageTask(EventDetailsActivity.this, getApplicationContext(), hostimg).execute(uri.toString()); + } + }); + + interestButton = (Button)findViewById(R.id.eventInterestedButton); + interestButton.setText("Interested: "+getIntent().getExtras().getInt("numInterested")); + interestButton.setOnClickListener(this); + + eventadd = (FloatingActionButton) findViewById(R.id.addInterestButton); + eventadd.setOnClickListener(this); + + + } + + public void onClick(View v) + { + switch(v.getId()) + { + case R.id.eventInterestedButton: + Intent intent = new Intent(getApplicationContext(), InterestedActivity.class); + if (initialNumInterested == 0) + { + Toast.makeText(getApplicationContext(),"Nobody is interested in this",Toast.LENGTH_LONG).show(); + + }else { + intent.putExtra("key", getIntent().getExtras().getString("id")); + startActivity(intent); + } + break; + case R.id.addInterestButton: + addInterest(); + eventadd.setEnabled(false); + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/Socials/"+getIntent().getExtras().getString("id")); + break; + } + } + + public void addInterest() + { + final String email = FirebaseAuth.getInstance().getCurrentUser().getEmail(); + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/Socials/"+getIntent().getExtras().getString("id")); + ref.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + ref.child("interested").child("" + dataSnapshot.child("numInterested").getValue(Integer.class)).setValue(email); + ref.child("interestedUIDs").child("" + dataSnapshot.child("numInterested").getValue(Integer.class)).setValue(mAuth.getCurrentUser().getUid()); + interestButton.setText("Interested: "+((int)(dataSnapshot.child("numInterested").getValue(Integer.class) + 1))); + ref.child("numInterested").setValue((int)(dataSnapshot.child("numInterested").getValue(Integer.class) + 1)); + + initialNumInterested+=1; + } + @Override + public void onCancelled(DatabaseError databaseError) {} + }); + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.logoutMenuButton: + UserUtils fb = new UserUtils(mAuth); + fb.signOut(); + startActivity(new Intent(this, MainActivity.class)); + break; + } + return super.onOptionsItemSelected(item); + } + + @Override + protected void onStart() { + super.onStart(); + toggleInterestButton(); + } + + protected void onResume() + { + super.onResume(); + toggleInterestButton(); + } + + public void toggleInterestButton() + { + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/Socials/"+getIntent().getExtras().getString("id")); + ref.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + ArrayList interestedPeopleIDs = (ArrayList) dataSnapshot.child("interestedUIDs").getValue(); + if (interestedPeopleIDs != null && interestedPeopleIDs.contains(mAuth.getCurrentUser().getUid())) + { + eventadd.setEnabled(false); + } + } + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + } + +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/FirebaseUtils.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/FirebaseUtils.java new file mode 100755 index 0000000..7afe4ee --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/FirebaseUtils.java @@ -0,0 +1,75 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.Intent; +import android.graphics.Bitmap; +import android.graphics.BitmapFactory; +import android.net.Uri; + +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.database.DatabaseReference; +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.URL; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Map; + +/** + * Created by Adhiraj Datar on 3/2/2017. + */ + +public class FirebaseUtils +{ + + public static void writeUserToDB(FirebaseAuth mAuth, DatabaseReference mDatabase, Uri profileImage, String name, String email, String password) + { + String key = mAuth.getCurrentUser().getUid(); + Map post = new HashMap<>(); + + String profilePicLocation = "profiles/" + key + ".jpg"; + StorageReference storageRef = FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-2.appspot.com").child(profilePicLocation); + storageRef.putFile(profileImage); + + post.put("uid", key); + post.put("name", name); + post.put("email", email); + post.put("password",password); + + mDatabase.child("Users").push().setValue(post); + } + + public static void writeEventToDB(final DatabaseReference mDatabase, StorageReference riversRef, final Uri eventimageuri, final String key, final String name, final String date, final String desc, final String host, final FirebaseAuth mAuth) + { + riversRef.putFile(eventimageuri).addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + ArrayList interested = new ArrayList(); + Integer numInterested = 0; + Map post = new HashMap(); + post.put("name", name); + post.put("host", host); + post.put("date", date); + post.put("desc", desc); + post.put("hostuid",mAuth.getCurrentUser().getUid()); + post.put("interestedList", interested); + post.put("firebasepath", "eventPics/"+key+".jpg"); + post.put("id",key); + post.put("numInterested", numInterested); + if (name.length()==0 || host==null || host.length()==0 || date.length()==0 || desc.length()==0 || key==null || key.length()==0) + { + + }else + { + mDatabase.child("Socials").child(key).setValue(post); + } + } + }); + } + +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/InterestedActivity.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/InterestedActivity.java new file mode 100755 index 0000000..5b053ea --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/InterestedActivity.java @@ -0,0 +1,115 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.Intent; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; +import android.view.Menu; +import android.view.MenuItem; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.database.ChildEventListener; +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 java.util.ArrayList; + +public class InterestedActivity extends AppCompatActivity { + FirebaseAuth mAuth; + RecyclerView interestedPeopleRVDisplay; + InterestedAdapter interestedPeopleRVAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) + { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_interested); + + mAuth = FirebaseAuth.getInstance(); + + interestedPeopleRVDisplay = (RecyclerView) findViewById(R.id.usersinterestedrecycler); + interestedPeopleRVDisplay.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + + Intent intent = getIntent(); + interestedPeopleRVAdapter = new InterestedAdapter(InterestedActivity.this, getApplicationContext(), new ArrayList()); + + interestedPeopleRVDisplay.setAdapter(interestedPeopleRVAdapter); + final String firebasekey = intent.getStringExtra("key"); + + final ArrayList interestedPeople = new ArrayList<>(); + final ArrayList interestedUIDs = new ArrayList<>(); + + DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/Socials"); + + ref.addChildEventListener(new ChildEventListener() { + + @Override + public void onChildAdded(DataSnapshot dataSnapshot, String s) { + if (dataSnapshot.getKey().equals(firebasekey)) { + ArrayList x = (ArrayList) dataSnapshot.child("interested").getValue(); + ArrayList uids = (ArrayList) dataSnapshot.child("interestedUIDs").getValue(); + + for (int i = 0; i < x.size(); i++) + { + interestedPeople.add(x.get(i)); + interestedUIDs.add(uids.get(i)); + } + + ArrayList interestedMDBros = new ArrayList<>(); + + + for (int i = 0; i < interestedPeople.size(); i++) { + interestedMDBros.add(new User("profiles/"+interestedUIDs.get(i)+".jpg",interestedPeople.get(i))); + } + + interestedPeopleRVAdapter.updateList(interestedMDBros); + interestedPeopleRVAdapter.notifyDataSetChanged(); + } + } + + @Override + public void onChildChanged(DataSnapshot dataSnapshot, String s) { + + } + + @Override + public void onChildRemoved(DataSnapshot dataSnapshot) { + + } + + @Override + public void onChildMoved(DataSnapshot dataSnapshot, String s) { + + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.logoutMenuButton: + UserUtils fb = new UserUtils(mAuth); + fb.signOut(); + startActivity(new Intent(this, MainActivity.class)); + break; + } + return super.onOptionsItemSelected(item); + } + +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/InterestedAdapter.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/InterestedAdapter.java new file mode 100755 index 0000000..61cc0a1 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/InterestedAdapter.java @@ -0,0 +1,82 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.app.Activity; +import android.content.Context; +import android.net.Uri; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageView; +import android.widget.TextView; + +import com.bumptech.glide.Glide; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.util.ArrayList; + +/** + * Created by Adhiraj Datar on 3/2/2017. + */ + +public class InterestedAdapter extends RecyclerView.Adapter +{ + Context context; + public static ArrayList mdbros; + Activity activity; + + public InterestedAdapter(Activity activity, Context context, ArrayList interestedpeople) + { + this.context = context; + this.activity = activity; + this.mdbros = interestedpeople; + } + + public InterestedAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) + { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_view_user, parent, false); + return new CustomViewHolder(view); + } + + public void onBindViewHolder(final InterestedAdapter.CustomViewHolder holder, int position) + { + User curr = mdbros.get(position); + holder.interestedPersonEmail.setText(curr.email); + + StorageReference mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-2.appspot.com"); + StorageReference interestedImageRef = mStorageRef.child(curr.img); + interestedImageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) + { + new DownloadImageTask(activity, context, holder.interestedPersonImage).execute(uri.toString()); + } + }); + } + + public int getItemCount() + { + return mdbros.size(); + } + + public void updateList(ArrayList i) + { + mdbros = i; + } + + public class CustomViewHolder extends RecyclerView.ViewHolder + { + TextView interestedPersonEmail; + ImageView interestedPersonImage; + + public CustomViewHolder(View view) { + super(view); + + interestedPersonEmail = (TextView) view.findViewById(R.id.userProfileEmail); + interestedPersonImage = (ImageView) view.findViewById(R.id.userProfileImage); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/MainActivity.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/MainActivity.java new file mode 100755 index 0000000..eaca25e --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/MainActivity.java @@ -0,0 +1,104 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.Intent; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +/** + * Main Activity of MDBSocials app + * inflates main activity layout, sets listeners and enables Authorization features + * Main Sign in Page/ Sign up page. Not seen if user is already logged in + * sends intents to: UserFeedActivity and SignupActivity + */ + +public class MainActivity extends AppCompatActivity implements View.OnClickListener{ + + Button loginButton, signUpButton; + EditText usernameInput, passwordInput; + + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + + @Override + /** + * onCreate method for main activity of MDBSocials app + * inflates main activity layout, sets listeners and enables Authorization features + * sends intents to: UserFeedActivity and SignupActivity + */ + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + + usernameInput = (EditText)findViewById(R.id.emailInput); + passwordInput = (EditText)findViewById(R.id.passwordInput); + loginButton = (Button)findViewById(R.id.loginButton); + signUpButton = (Button)findViewById(R.id.signUpButton); + + loginButton.setOnClickListener(this); + signUpButton.setOnClickListener(this); + + mAuth = FirebaseAuth.getInstance(); + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = firebaseAuth.getCurrentUser(); + if (user != null) { + startActivity(new Intent(MainActivity.this, UserFeedActivity.class)); + }else + { + + } + } + }; + } + + /** + * onClick method for main activity of MDBSocials app + * handles click events for sign up and sign in buttons + * sends intents to: SingupActivity and UserFeedActivity + */ + public void onClick(View v) + { + switch (v.getId()) { + case R.id.loginButton: + signIn(); + break; + case R.id.signUpButton: + startActivity(new Intent(MainActivity.this, SignupActivity.class)); + break; + } + } + + /** + * signIn method for main activity of MDBSocials app + * calls on UserUtils helper class to handle user authorization + * sends intents to: UserFeedActivity and SignupActivity + */ + public void signIn() + { + UserUtils authManager = new UserUtils(mAuth); + authManager.signIn(this, usernameInput.getText().toString(), passwordInput.getText().toString()); + } + + @Override + public void onStart() { + super.onStart(); + mAuth.addAuthStateListener(mAuthListener); + } + + @Override + public void onStop() { + super.onStop(); + if (mAuthListener != null) { + mAuth.removeAuthStateListener(mAuthListener); + } + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/SignupActivity.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/SignupActivity.java new file mode 100755 index 0000000..e76a734 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/SignupActivity.java @@ -0,0 +1,130 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.Intent; +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.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; +import com.google.firebase.database.DatabaseReference; +import com.google.firebase.database.FirebaseDatabase; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.util.HashMap; +import java.util.Map; + +/** + * Signup Activity of MDBSocials app + * inflates signup activity layout, sets listeners and enables Authorization features + * Main Sign up page. Not seen if user is already logged in + * sends intents to: UserFeedActivity + */ + +public class SignupActivity extends AppCompatActivity implements View.OnClickListener { + + private Button addProfilePicButton, addUserButton; + private EditText usernameInput, passwordInput, nameInput; + + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + + private Uri profileImage; + private String profilePicLocation; + private DatabaseReference mDatabase; + + final int GET_PROFILE_IMAGE = 1; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_signup); + + addProfilePicButton = (Button)findViewById(R.id.addProfilePhotoButton); + addUserButton = (Button)findViewById(R.id.signUpButton); + + usernameInput = (EditText) findViewById(R.id.signUpEmailInput); + passwordInput = (EditText) findViewById(R.id.signUpPasswordInput); + nameInput = (EditText) findViewById(R.id.signUpNameInput); + + mAuth = FirebaseAuth.getInstance(); + mDatabase = FirebaseDatabase.getInstance().getReference(); + + addProfilePicButton.setOnClickListener(this); + addUserButton.setOnClickListener(this); + + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = firebaseAuth.getCurrentUser(); + if (user != null) { + startActivity(new Intent(SignupActivity.this, UserFeedActivity.class)); + }else + { + + } + } + }; + } + + public void onClick(View v) + { + switch (v.getId()) + { + case R.id.addProfilePhotoButton: + Intent intent = new Intent(Intent.ACTION_GET_CONTENT); + intent.setType("image/*"); + startActivityForResult(intent, GET_PROFILE_IMAGE); + break; + case R.id.signUpButton: + signUp(); + break; + } + } + + public void signUp() + { + final String userName, userPassword, userEmail; + userName = nameInput.getText().toString(); + userEmail = usernameInput.getText().toString(); + userPassword = passwordInput.getText().toString(); + + UserUtils signUpUtil = new UserUtils(mAuth); + signUpUtil.signUp(getApplicationContext(), mDatabase, profileImage, userPassword, userEmail, userName); + } + + protected void onActivityResult(int requestCode, int resultCode, Intent imageReturnedIntent) + { + super.onActivityResult(requestCode, resultCode, imageReturnedIntent); + if (resultCode == RESULT_OK && requestCode==1) + { + profileImage = imageReturnedIntent.getData(); + ((ImageView)findViewById(R.id.profilePicPreview)).setImageURI(profileImage); + } + } + + @Override + public void onStart() { + super.onStart(); + mAuth.addAuthStateListener(mAuthListener); + } + + @Override + public void onStop() { + super.onStop(); + if (mAuthListener != null) { + mAuth.removeAuthStateListener(mAuthListener); + } + } + +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/Social.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/Social.java new file mode 100755 index 0000000..0c07692 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/Social.java @@ -0,0 +1,28 @@ +package com.example.datarsd1.mdbsocials_2; + +import java.util.ArrayList; + +/** + * Created by Adhiraj Datar on 3/2/2017. + */ + +public class Social { + + String title, host, description, date, firebaseLocation, id, hostuid; + ArrayList interested, interestedUIDs; + Integer numInterested; + + public Social(String t, String h, String desc, String d, String fbl, String id, Integer numInterested, String hostuid, ArrayList interested, ArrayList interestedUIDs) { + this.title = t; + this.host = h; + this.description = desc; + this.date = d; + this.firebaseLocation = fbl; + this.id = id; + this.interested = interested; + this.interestedUIDs = interestedUIDs; + this.numInterested = numInterested; + this.hostuid = hostuid; + } + +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/User.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/User.java new file mode 100755 index 0000000..94202e8 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/User.java @@ -0,0 +1,19 @@ +package com.example.datarsd1.mdbsocials_2; + +/** + * Created by Adhiraj Datar on 3/2/2017. + */ +public class User +{ + + String img; + String email; + + public User(String img, String email) + { + this.img = img; + this.email = email; + } + +} + diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserFeedActivity.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserFeedActivity.java new file mode 100755 index 0000000..ca66ff6 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserFeedActivity.java @@ -0,0 +1,113 @@ +package com.example.datarsd1.mdbsocials_2; + +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.view.Menu; +import android.view.MenuItem; +import android.view.View; + +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.HashMap; + +public class UserFeedActivity extends AppCompatActivity implements View.OnClickListener{ + + private FirebaseAuth mAuth; + UserFeedAdapter adapter; + RecyclerView eventsListView; + DatabaseReference mDatabase; + FloatingActionButton fab; + + ArrayList socials = new ArrayList(); + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_user_feed); + + mAuth = FirebaseAuth.getInstance(); + mDatabase = FirebaseDatabase.getInstance().getReference(); + + eventsListView = (RecyclerView) findViewById(R.id.eventsFeedRecyclerView); + eventsListView.setLayoutManager(new LinearLayoutManager(this)); + + adapter = new UserFeedAdapter(UserFeedActivity.this, getApplicationContext(), socials); + eventsListView.setAdapter(adapter); + + fab = (FloatingActionButton)findViewById(R.id.addEventButton); + fab.setOnClickListener(this); + + mDatabase.child("Socials").addValueEventListener(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + socials = new ArrayList(); + for (DataSnapshot d: dataSnapshot.getChildren()) + { + HashMap evt = (HashMap) d.getValue(); + String id = (String) evt.get("id"); + String firebasePathLocation = (String) evt.get("firebasepath"); + String name = (String) evt.get("name"); + String host = (String) evt.get("host"); + String date = (String) evt.get("date"); + String desc = (String) evt.get("desc"); + String hostuid = (String) evt.get("hostuid"); + Integer numInterested = ((Long)evt.get("numInterested")).intValue(); + ArrayList interested = (ArrayList) evt.get("interestedList"); + ArrayList interestedUIDs = (ArrayList) evt.get("interestedUIDs"); + if(interested == null) + { + interested = new ArrayList(); + }else if(interestedUIDs == null) + { + interestedUIDs = new ArrayList(); + } + Social social = new Social(name, host, desc, date, firebasePathLocation, id, numInterested, hostuid, interested, interestedUIDs); + socials.add(social); + } + adapter.setSocialsList(socials); + adapter.notifyDataSetChanged(); + } + @Override + public void onCancelled(DatabaseError databaseError) { } + }); + } + + public void onClick(View v) + { + switch(v.getId()) + { + case R.id.addEventButton: + Intent intent = new Intent(getApplicationContext(),AddSocial.class); + startActivity(intent); + break; + } + } + + @Override + public boolean onCreateOptionsMenu(Menu menu) { + getMenuInflater().inflate(R.menu.main_menu, menu); + return super.onCreateOptionsMenu(menu); + } + + @Override + public boolean onOptionsItemSelected(MenuItem item) { + switch (item.getItemId()) { + case R.id.logoutMenuButton: + UserUtils fb = new UserUtils(mAuth); + fb.signOut(); + startActivity(new Intent(this, MainActivity.class)); + break; + } + return super.onOptionsItemSelected(item); + } +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserFeedAdapter.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserFeedAdapter.java new file mode 100755 index 0000000..27ee160 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserFeedAdapter.java @@ -0,0 +1,150 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.app.Activity; +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +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.TextView; + +import com.bumptech.glide.Glide; +import com.google.android.gms.tasks.OnSuccessListener; +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 com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.util.ArrayList; +import java.util.HashMap; + +import static android.content.Intent.FLAG_ACTIVITY_NEW_TASK; + + +public class UserFeedAdapter extends RecyclerView.Adapter +{ + + private Context context; + private Activity activity; + private DatabaseReference mDatabase = FirebaseDatabase.getInstance().getReference();; + + private ArrayList socialList = new ArrayList<>(); + + public UserFeedAdapter(Activity activity, Context context, ArrayList socials) { + this.context = context; + this.activity = activity; + this.socialList = socials; + } + + public void setSocialsList(ArrayList schedule) + { + socialList = schedule; + } + + @Override + public int getItemCount() { + return socialList.size(); + } + + @Override + public CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_event_view, parent, false); + return new CustomViewHolder(view); + } + + @Override + public void onBindViewHolder(final CustomViewHolder holder, int position) + { + Social s = socialList.get(getItemCount()-position-1); + holder.hostNameView.setText(s.host); + holder.eventNameView.setText(s.title); + + if(s.interested == null) + { + s.interested = new ArrayList<>(); + } + + holder.numInterestedView.setText("Interested: "+s.numInterested); + + StorageReference storageRef = FirebaseStorage.getInstance().getReference().child(socialList.get(position).firebaseLocation); + storageRef.getDownloadUrl().addOnSuccessListener(new OnSuccessListener() + { + @Override + public void onSuccess(Uri uri) + { + new DownloadImageTask(activity, context, holder.eventImageView).execute(uri.toString()); + } + + }); + } + + class CustomViewHolder extends RecyclerView.ViewHolder + { + TextView eventNameView, hostNameView, numInterestedView; + ImageView eventImageView; + ArrayList interestedNames, interestedEmails; + + public CustomViewHolder(View v) + { + super(v); + this.eventNameView = (TextView) v.findViewById(R.id.eventTitle); + this.eventImageView = (ImageView) v.findViewById(R.id.eventImage); + this.hostNameView = (TextView) v.findViewById(R.id.eventHost); + this.numInterestedView = (TextView) v.findViewById(R.id.eventInterested); + + interestedNames = new ArrayList(); + interestedEmails = new ArrayList(); + + v.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + final Social s = socialList.get(getAdapterPosition()); + Intent intent = new Intent(context, EventDetailsActivity.class); + + ValueEventListener postListener = new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + ArrayList interested = s.interested; + for (DataSnapshot d: dataSnapshot.getChildren()) { + HashMap evt = (HashMap) d.getValue(); + if (interested.contains(evt.get("uid"))) { + interestedNames.add((String) evt.get("name")); + interestedNames.add((String) evt.get("email")); + } + } + } + @Override + public void onCancelled(DatabaseError databaseError) { + Log.e("Error", "Something went wrong"); + } + }; + mDatabase.child("Users").addValueEventListener(postListener); + + intent.putExtra("title", s.title); + intent.putExtra("host", s.host); + intent.putExtra("desc", s.description); + intent.putExtra("date", s.date); + intent.putExtra("interestedList", s.interested.size()); + intent.putExtra("firebasePath", s.firebaseLocation); + intent.putExtra("id",s.id); + intent.putExtra("hostuid",s.hostuid); + intent.putExtra("numInterested", s.numInterested); + intent.putExtra("interestedUIDs", s.interestedUIDs); + intent.putStringArrayListExtra("interestedName", interestedNames); + intent.putStringArrayListExtra("interestedEmail", interestedEmails); + intent.addFlags(FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); + } + } + + +} diff --git a/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserUtils.java b/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserUtils.java new file mode 100755 index 0000000..e17ef74 --- /dev/null +++ b/app/src/main/java/com/example/datarsd1/mdbsocials_2/UserUtils.java @@ -0,0 +1,82 @@ +package com.example.datarsd1.mdbsocials_2; + +import android.content.Context; +import android.content.Intent; +import android.net.Uri; +import android.support.annotation.NonNull; +import android.util.Log; +import android.widget.CheckBox; +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.database.DatabaseReference; +import com.google.firebase.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by datarsd1 on 3/1/17. + */ + +public class UserUtils +{ + + private FirebaseAuth mAuth; + + public UserUtils(FirebaseAuth mAuth) + { + this.mAuth = mAuth; + } + + public void signIn(final Context context, String userEmail, String userPassword) + { + if (userPassword == null || userEmail == null || userEmail.length() == 0 || userPassword.length() == 0) + { + Toast.makeText(context, "You didn't Enter Anything", Toast.LENGTH_SHORT).show(); + }else + { + mAuth.signInWithEmailAndPassword(userEmail, userPassword).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (!task.isSuccessful()) { + Toast.makeText(context, "Sign in Failed.", Toast.LENGTH_SHORT).show(); + } + } + }); + } + } + + public void signUp(final Context context, final DatabaseReference mDatabase, final Uri profileImage, final String userPassword, final String userEmail, final String userName) + { + if (profileImage == null || userPassword == null || userEmail == null || userEmail.length() == 0 || userPassword.length() == 0 || userName.length()==0) + { + Toast.makeText(context, "You didn't Enter Anything", Toast.LENGTH_SHORT).show(); + }else + { + mAuth.createUserWithEmailAndPassword(userEmail, userPassword).addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (task.isSuccessful()) + { + FirebaseUtils.writeUserToDB(mAuth, mDatabase, profileImage, userName, userEmail, userPassword); + }else + { + Toast.makeText(context, "Sign Up Failed. Make sure you entered a valid email and a STRONG password (uppercase, symbols, 10+ chars)", + Toast.LENGTH_LONG).show(); + } + } + }); + } + } + + public void signOut() + { + mAuth.signOut(); + } + +} diff --git a/app/src/main/res/drawable/buttonshape.xml b/app/src/main/res/drawable/buttonshape.xml new file mode 100755 index 0000000..94c4e2d --- /dev/null +++ b/app/src/main/res/drawable/buttonshape.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/cardviewshape.xml b/app/src/main/res/drawable/cardviewshape.xml new file mode 100755 index 0000000..4755870 --- /dev/null +++ b/app/src/main/res/drawable/cardviewshape.xml @@ -0,0 +1,15 @@ + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/circle.xml b/app/src/main/res/drawable/circle.xml new file mode 100755 index 0000000..25a070e --- /dev/null +++ b/app/src/main/res/drawable/circle.xml @@ -0,0 +1,14 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/logout.png b/app/src/main/res/drawable/logout.png new file mode 100755 index 0000000..6d07c2f Binary files /dev/null and b/app/src/main/res/drawable/logout.png differ diff --git a/app/src/main/res/drawable/mdblogo.png b/app/src/main/res/drawable/mdblogo.png new file mode 100755 index 0000000..566ae01 Binary files /dev/null and b/app/src/main/res/drawable/mdblogo.png differ diff --git a/app/src/main/res/drawable/passwordtext.xml b/app/src/main/res/drawable/passwordtext.xml new file mode 100755 index 0000000..09a755b --- /dev/null +++ b/app/src/main/res/drawable/passwordtext.xml @@ -0,0 +1,19 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/plusicon.png b/app/src/main/res/drawable/plusicon.png new file mode 100755 index 0000000..bd171be Binary files /dev/null and b/app/src/main/res/drawable/plusicon.png differ diff --git a/app/src/main/res/drawable/titletextfield.xml b/app/src/main/res/drawable/titletextfield.xml new file mode 100755 index 0000000..e73b6dc --- /dev/null +++ b/app/src/main/res/drawable/titletextfield.xml @@ -0,0 +1,17 @@ + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/usernametext.xml b/app/src/main/res/drawable/usernametext.xml new file mode 100755 index 0000000..49f9969 --- /dev/null +++ b/app/src/main/res/drawable/usernametext.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/wallpaper.jpg b/app/src/main/res/drawable/wallpaper.jpg new file mode 100755 index 0000000..703d3d7 Binary files /dev/null and b/app/src/main/res/drawable/wallpaper.jpg differ diff --git a/app/src/main/res/drawable/wallpaper2.png b/app/src/main/res/drawable/wallpaper2.png new file mode 100755 index 0000000..a02719a Binary files /dev/null and b/app/src/main/res/drawable/wallpaper2.png differ diff --git a/app/src/main/res/layout/activity_add_social.xml b/app/src/main/res/layout/activity_add_social.xml new file mode 100755 index 0000000..f8a6b96 --- /dev/null +++ b/app/src/main/res/layout/activity_add_social.xml @@ -0,0 +1,80 @@ + + + + + + + + + + +