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..0e23f8e --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,19 @@ + + + + + + \ 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..5bd7a23 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,10 @@ + +# MDBSocials # 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. When pushing code to this repo, DO NOT push to master. Create a new branch and open a pull request. 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..088129b --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,43 @@ +apply plugin: 'com.android.application' + +android { + compileSdkVersion 25 + buildToolsVersion "25.0.2" + defaultConfig { + applicationId "io.github.sumukhshiv.mdbsocials" + 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.2.0' + compile 'com.android.support.constraint:constraint-layout:1.0.0-beta5' + compile 'com.google.firebase:firebase-auth:10.2.0' + compile 'com.android.support:design:25.2.0' + compile 'com.android.support:recyclerview-v7:25.2.0' + compile 'com.android.support:cardview-v7:25.2.0' + compile 'com.google.firebase:firebase-database:10.2.0' + compile 'com.google.firebase:firebase-storage:10.2.0' + compile 'com.android.support:cardview-v7:25.1.1' + 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..581c685 --- /dev/null +++ b/app/google-services.json @@ -0,0 +1,55 @@ +{ + "project_info": { + "project_number": "499588796344", + "firebase_url": "https://mdbsocials-e2598.firebaseio.com", + "project_id": "mdbsocials-e2598", + "storage_bucket": "mdbsocials-e2598.appspot.com" + }, + "client": [ + { + "client_info": { + "mobilesdk_app_id": "1:499588796344:android:3fcbbeeb8c1bfb78", + "android_client_info": { + "package_name": "io.github.sumukhshiv.mdbsocials" + } + }, + "oauth_client": [ + { + "client_id": "499588796344-d2vkc698olp0jq6g848evvubjss1k1bq.apps.googleusercontent.com", + "client_type": 1, + "android_info": { + "package_name": "io.github.sumukhshiv.mdbsocials", + "certificate_hash": "1B12EB78F4B2B55714B404F17036C3F98D92F442" + } + }, + { + "client_id": "499588796344-96odu7ltkjkfvjfa63pcc3evgu4r8iuh.apps.googleusercontent.com", + "client_type": 3 + } + ], + "api_key": [ + { + "current_key": "AIzaSyAd9oy9jHjxSiF17n6zDLtASKbABjYlwa4" + } + ], + "services": { + "analytics_service": { + "status": 1 + }, + "appinvite_service": { + "status": 2, + "other_platform_oauth_client": [ + { + "client_id": "499588796344-96odu7ltkjkfvjfa63pcc3evgu4r8iuh.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 100644 index 0000000..67d5f8d --- /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/sumukhshivakumar/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/io/github/sumukhshiv/mdbsocials/ExampleInstrumentedTest.java b/app/src/androidTest/java/io/github/sumukhshiv/mdbsocials/ExampleInstrumentedTest.java new file mode 100644 index 0000000..b7f8d72 --- /dev/null +++ b/app/src/androidTest/java/io/github/sumukhshiv/mdbsocials/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package io.github.sumukhshiv.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("io.github.sumukhshiv.mdbsocials", appContext.getPackageName()); + } +} diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9954990 --- /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/io/github/sumukhshiv/mdbsocials/DetailScreenActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/DetailScreenActivity.java new file mode 100644 index 0000000..4d71e56 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/DetailScreenActivity.java @@ -0,0 +1,229 @@ +package io.github.sumukhshiv.mdbsocials; + +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.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.ImageView; +import android.widget.TextView; +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.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 java.io.IOException; +import java.io.InputStream; +import java.net.HttpURLConnection; +import java.net.URL; +import java.util.ArrayList; + +public class DetailScreenActivity extends AppCompatActivity implements View.OnClickListener { + + private Social social; + TextView textViewEventNameDetail; + ImageView imageViewDetail; + TextView emailDetail; + Button buttonInterestedDetail; + TextView textViewDescription; + Button buttonAreYouInterested; + FirebaseAuth firebaseAuth; + FirebaseUser firebaseUser; + String urlString; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_detail_screen); + textViewEventNameDetail = (TextView) findViewById(R.id.textViewEventNameDetail); + imageViewDetail = (ImageView) findViewById(R.id.imageViewDetail); + emailDetail = (TextView) findViewById(R.id.textViewEmailDetail); + buttonInterestedDetail = (Button) findViewById(R.id.buttonInterstedDetail); + buttonAreYouInterested = (Button) findViewById(R.id.buttonAreYouInterested); + textViewDescription = (TextView) findViewById(R.id.textViewDescription); + buttonAreYouInterested.setOnClickListener(this); + buttonInterestedDetail.setOnClickListener(this); + + firebaseAuth = FirebaseAuth.getInstance(); + firebaseUser = firebaseAuth.getCurrentUser(); + urlString = ""; + + } + + @Override + protected void onResume() { + super.onResume(); + + //grabbing the social, which was just clicked on from UserArea + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + social = (Social) bundle.getSerializable("SOCIAL"); + + //Setting different aspects of the Detail Screen View + textViewEventNameDetail.setText(social.nameOfEvent); + emailDetail.setText(social.emailOfHost); + buttonInterestedDetail.setText(Integer.toString(social.numberIntersted)); + textViewDescription.setText(social.description); + class DownloadFilesTask extends AsyncTask { + protected Bitmap doInBackground(String... strings) { + //Adding image to imageView on the Detail Screen using AsyncTask (w/o Glide) + try { + urlString = strings[0]; + URL url = new URL(urlString); + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setDoInput(true); + connection.connect(); + InputStream input = connection.getInputStream(); + Bitmap myBitmap = BitmapFactory.decodeStream(input); + return myBitmap; + } catch (IOException e) { + return null; + } + } + + protected void onProgressUpdate(Void... progress) {} + + protected void onPostExecute(Bitmap result) { + imageViewDetail.setImageBitmap(result); + } + } + + FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-e2598.appspot.com").child(social.image).getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) { + (new DownloadFilesTask()).execute(uri.toString()); + Log.d("Adding to ImageView", uri.toString()); + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception exception) { + Log.d("Failed adding Image", exception.toString()); + } + }); + + } + + /** + * Helper Method used to add current user to the Interested Array List of Social + * Takes in no parameters and returns nothing + * Series of tasks to add the current user after checking various cases in Switch statement + */ + private void addInterested() { + //NOTE, also add self email to people interested arraylist + final String socialKey = social.image.substring(0, social.image.length() - 4); + final DatabaseReference ref = FirebaseDatabase.getInstance().getReference("/socials").child(socialKey); + + ref.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + int numberIntersted = dataSnapshot.child("numberIntersted").getValue(Integer.class); + numberIntersted++; + buttonInterestedDetail.setText(Integer.toString(numberIntersted)); + addInterestedToDatabase(numberIntersted, socialKey); + ArrayList a = social.peopleInterested; + if (a != null && !a.contains(firebaseUser.getUid())) { + a.add(firebaseUser.getUid()); + social.peopleInterested = a; + ref.child("peopleInterested").setValue(a); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + + } + + /** + * Helper method to actually write updated Arraylist of interested users to Firebase Database + * @param interested + * @param firekey + */ + public static void addInterestedToDatabase(int interested, String firekey) { + DatabaseReference ref = FirebaseDatabase.getInstance().getReference("socials"); + ref.child(firekey).child("numberIntersted").setValue(interested); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case (R.id.buttonAreYouInterested): + FirebaseDatabase database = FirebaseDatabase.getInstance(); + DatabaseReference myRef = database.getReference("/users").child(firebaseUser.getUid()); + + //SingleValueEventListener because we want to only retrieve the information once. + //Traditional ValueEventListener causes problems because it is triggered multiple times + myRef.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + Object user = dataSnapshot.child("email").getValue(); + + //Checking if user inputed all the various fields + //Used if/else if/else because only 3 cases + if (user == null) { + Toast.makeText(getApplicationContext(), "Please Update Profile!", + Toast.LENGTH_LONG).show(); + } else if (social.peopleInterested.contains(firebaseUser.getUid())) { + Toast.makeText(getApplicationContext(), "You're already Interested!", + Toast.LENGTH_LONG).show(); + } else { + //call on helper method to actually add user to arraylist in social + addInterested(); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + break; + + case (R.id.buttonInterstedDetail): + FirebaseDatabase database2 = FirebaseDatabase.getInstance(); + DatabaseReference myRef2 = database2.getReference("/users").child(firebaseUser.getUid()); + + myRef2.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + Object user = dataSnapshot.child("email").getValue(); + + if (user == null) { + Toast.makeText(getApplicationContext(), "Please Update Profile!", + Toast.LENGTH_LONG).show(); + } else { + //Pass social object to populate the recycler view using its arrayList of interested members + Intent intent = new Intent(getApplicationContext(), InterestedMembersActivity.class); + Bundle bundle = new Bundle(); + bundle.putSerializable("SOCIAL", social); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + startActivity(intent); + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + + } + }); + break; + } + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/FirebaseUtils.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/FirebaseUtils.java new file mode 100644 index 0000000..f9d0881 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/FirebaseUtils.java @@ -0,0 +1,80 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.Context; +import android.content.Intent; +import android.support.annotation.NonNull; +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; + +/** + * Created by sumukhshivakumar on 3/2/17. + */ + +public class FirebaseUtils { + + public static void login(final String email, String password, final ProgressDialog progressDialog, Activity activity) { + FirebaseAuth firebaseAuth = FirebaseAuth.getInstance(); + final Context context = activity.getApplicationContext(); + firebaseAuth.signInWithEmailAndPassword(email, password) + .addOnCompleteListener(activity, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + progressDialog.dismiss(); + if (task.isSuccessful()) { + Toast.makeText(context, "Login Successful!", Toast.LENGTH_SHORT).show(); + Intent loginToFeedIntent = new Intent(context, UserArea.class); + loginToFeedIntent.putExtra("email", email); + loginToFeedIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(loginToFeedIntent); + } else if (!task.isSuccessful()) { + Toast.makeText(context, "Email/Password combination is not correct. Please Try Again.", Toast.LENGTH_LONG).show(); + } + + } + }); + + } + + public static void signUp(final String email, final String password, final ProgressDialog progressDialog, Activity activity) { + final FirebaseAuth mAuth = FirebaseAuth.getInstance(); + final Context context = activity.getApplicationContext(); + mAuth.createUserWithEmailAndPassword(email, password) + .addOnCompleteListener(activity, new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (!task.isSuccessful()) { + + //Various checks to see whether user input is valid + if (!email.contains("@")) { + Toast.makeText(context, "Please enter a valid Email Address", Toast.LENGTH_SHORT).show(); + } + else if (mAuth.signInWithEmailAndPassword(email, password) != null) { + Toast.makeText(context, "An account with this email already exists.", + Toast.LENGTH_SHORT).show(); + } else { + Toast.makeText(context, "Authentication Failed.", + Toast.LENGTH_SHORT).show(); + } + progressDialog.dismiss(); + } else if (task.isSuccessful()) { + //case where registration was successful + progressDialog.dismiss(); + Toast.makeText(context, "Registered Successfully!", Toast.LENGTH_SHORT).show(); + //After registering go straight to Feed + Intent signupToFeedIntent = new Intent(context, UserArea.class); + signupToFeedIntent.putExtra("email", email); + signupToFeedIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(signupToFeedIntent); + } + + + } + }); + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/InterestedMembersActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/InterestedMembersActivity.java new file mode 100644 index 0000000..9d77a16 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/InterestedMembersActivity.java @@ -0,0 +1,43 @@ +package io.github.sumukhshiv.mdbsocials; + +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 java.util.ArrayList; + +public class InterestedMembersActivity extends AppCompatActivity { + + Social social; + InterestedProfilesAdapter toSetProfilesAdapter; + ArrayList profilesInterested; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_interested_members); + + //grab the social object to populate recyclerView + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + social = (Social) bundle.getSerializable("SOCIAL"); + + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewInterestedMembers); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + + //Grab social objects people interested arraylist for adapter + profilesInterested = social.peopleInterested; + toSetProfilesAdapter = new InterestedProfilesAdapter(getApplicationContext(), profilesInterested); + recyclerView.setAdapter(toSetProfilesAdapter); + } + + @Override + public void onResume() { + super.onResume(); + Intent intent = getIntent(); + Bundle bundle = intent.getExtras(); + social = (Social) bundle.getSerializable("SOCIAL"); + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/InterestedProfilesAdapter.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/InterestedProfilesAdapter.java new file mode 100644 index 0000000..d03cb9b --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/InterestedProfilesAdapter.java @@ -0,0 +1,73 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.content.Context; +import android.support.v7.widget.RecyclerView; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; +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; + +/** + * Created by sumukhshivakumar on 2/25/17. + */ + +public class InterestedProfilesAdapter extends RecyclerView.Adapter { + Context context; + ArrayList profiles; + + public InterestedProfilesAdapter(Context context, ArrayList profiles) { + this.context = context; + this.profiles = profiles; + } + + @Override + public InterestedProfilesAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_view2, parent, false); + return new CustomViewHolder(view); + } + + @Override + public void onBindViewHolder(final InterestedProfilesAdapter.CustomViewHolder holder, int position) { + final String profile = profiles.get(position); + /** + * Arraylist is a list of IDs so we retrieve each user and go into Database to find corresponding + * email address + */ + + FirebaseDatabase database = FirebaseDatabase.getInstance(); + DatabaseReference myRef = database.getReference("/users").child(profile); + myRef.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + String email = dataSnapshot.child("email").getValue().toString(); + holder.MemberName.setText(email); + } + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + } + + @Override + public int getItemCount() { + return profiles.size(); + } + + public class CustomViewHolder extends RecyclerView.ViewHolder { + + //Only using email of user so no need to grab the profile image of each user + TextView MemberName; + + public CustomViewHolder(View view) { + super(view); + MemberName = (TextView) view.findViewById(R.id.textViewInterestedMember); + + } + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/LogInActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/LogInActivity.java new file mode 100644 index 0000000..0f6cbfd --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/LogInActivity.java @@ -0,0 +1,81 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.app.ProgressDialog; +import android.content.Intent; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.TextUtils; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; + +public class LogInActivity extends AppCompatActivity implements View.OnClickListener{ + private EditText editTextEmailLogin; + private EditText editTextPasswordLogin; + private Button buttonSignIn; + private TextView textViewRegister; + private FirebaseAuth firebaseAuth; + public ProgressDialog progressDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_log_in); + + //Retrieve all views from XML + editTextEmailLogin = (EditText) findViewById(R.id.editTextEmail); + editTextPasswordLogin = (EditText) findViewById(R.id.editTextPassword); + buttonSignIn = (Button) findViewById(R.id.buttonSignin); + textViewRegister = (TextView) findViewById(R.id.textViewRegister); + progressDialog = new ProgressDialog(this); + firebaseAuth = firebaseAuth.getInstance(); + + //Adding the click listeners + buttonSignIn.setOnClickListener(this); + textViewRegister.setOnClickListener(this); + + } + + /** + * Modular function that Logs users into the app. Takes in no arguments and returns nothing. + * Series of actions completed to login user using FirebaseAuth call. + */ + public void userLogin() { + final String email = editTextEmailLogin.getText().toString().trim(); + String password = editTextPasswordLogin.getText().toString().trim(); + + if (TextUtils.isEmpty(email)) { + Toast.makeText(this, "Please enter a valid Email Address", Toast.LENGTH_SHORT).show(); + return; + } + + if (TextUtils.isEmpty(password)) { + Toast.makeText(this, "Please enter a Password", Toast.LENGTH_SHORT).show(); + return; + } + + + progressDialog.setMessage("Logging in User..."); + progressDialog.show(); + + FirebaseUtils.login(email, password, progressDialog, this); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.buttonSignin: + userLogin(); + break; + case R.id.textViewRegister: + Intent toHome = new Intent(LogInActivity.this, SignUpActivity.class); + startActivity(toHome); + } + } + +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/MainActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/MainActivity.java new file mode 100644 index 0000000..a6587c1 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/MainActivity.java @@ -0,0 +1,83 @@ +package io.github.sumukhshiv.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 com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +public class MainActivity extends AppCompatActivity implements View.OnClickListener{ + + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + Button buttonLogin; + Button buttonSignUp; + + @Override + protected void onCreate(Bundle savedInstanceState) { + + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_main); + buttonLogin = (Button) findViewById(R.id.buttonSignin); + buttonSignUp = (Button) findViewById(R.id.buttonRegister); + + buttonLogin.setOnClickListener(this); + buttonSignUp.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("Login Status", "onAuthStateChanged:signed_in:" + user.getUid()); + Intent intent = new Intent(getApplicationContext(),UserArea.class); + startActivity(intent); + + + } else { + // User is signed out + Log.d("Login Status", "onAuthStateChanged:signed_out"); + } + + } + }; + + } + + @Override + public void onStart() { + super.onStart(); + mAuth.addAuthStateListener(mAuthListener); + } + + @Override + public void onStop() { + super.onStop(); + if (mAuthListener != null) { + mAuth.removeAuthStateListener(mAuthListener); + } + } + + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.buttonSignin: + Intent loginIntent = new Intent(MainActivity.this, LogInActivity.class); + startActivity(loginIntent); + break; + + case R.id.buttonRegister: + Intent signUpIntent = new Intent(MainActivity.this, SignUpActivity.class); + startActivity(signUpIntent); + break; + + } + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/NewSocialActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/NewSocialActivity.java new file mode 100644 index 0000000..fb393c9 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/NewSocialActivity.java @@ -0,0 +1,210 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.provider.MediaStore; +import android.support.annotation.NonNull; +import android.support.v7.app.AlertDialog; +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.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 com.google.firebase.storage.UploadTask; +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; + +public class NewSocialActivity extends AppCompatActivity implements View.OnClickListener { + + public final static int REQUEST_CAMERA = 1; + public static final int GET_FROM_GALLERY = 3; + private FirebaseAuth firebaseAuth; + private FirebaseUser firebaseUser; + + Intent data; + private StorageReference mStorageRef; + + EditText editTextEventName; + EditText editTextDate; + EditText editTextDescription; + ImageView imageViewUploadPhoto; + Button buttonPost; + + private ProgressDialog progressDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_new_social); + + //defining all variables used + editTextEventName = (EditText) findViewById(R.id.editTextEventName); + Button buttonUploadPicture = (Button) findViewById(R.id.buttonUploadPicture); + editTextDate = (EditText) findViewById(R.id.editTextDate); + editTextDescription = (EditText) findViewById(R.id.editTextDescription); + imageViewUploadPhoto = (ImageView) findViewById(R.id.imageViewUploadPhoto); + buttonPost = (Button) findViewById(R.id.buttonPost); + progressDialog = new ProgressDialog(this); + + buttonUploadPicture.setOnClickListener(this); + buttonPost.setOnClickListener(this); + + firebaseAuth = FirebaseAuth.getInstance(); + firebaseUser = firebaseAuth.getCurrentUser(); + + + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + + //Detects request codes + //Retrieves image onActivityResult and sets it to the imageView + if((requestCode==GET_FROM_GALLERY || requestCode == REQUEST_CAMERA) && resultCode == Activity.RESULT_OK) { + Uri selectedImage = data.getData(); + Bitmap bitmap = null; + try { + bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage); + //BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap); + ((ImageView) findViewById(R.id.imageViewUploadPhoto)).setImageBitmap(bitmap); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + this.data = data; + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + //Adding a photo case + case (R.id.buttonUploadPicture): + AlertDialog alertDialog = new AlertDialog.Builder(NewSocialActivity.this).create(); + alertDialog.setTitle("Set a Photo"); + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Take a Photo", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Open Camera + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + if (takePictureIntent.resolveActivity(getPackageManager()) != null) { + startActivityForResult(takePictureIntent, REQUEST_CAMERA); + } + dialog.dismiss(); + } + }); + alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Upload from Gallery", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //launch gallery + startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), GET_FROM_GALLERY); + dialog.dismiss(); + } + }); + alertDialog.show(); + break; + + //Posting the Social Firebase and Newsfeed + case (R.id.buttonPost): + + FirebaseDatabase database = FirebaseDatabase.getInstance(); + final DatabaseReference myRef = database.getReference("/users").child(firebaseUser.getUid()); + + myRef.addListenerForSingleValueEvent(new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + Object user = dataSnapshot.child("email").getValue(); + + if (user == null) { + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Please Update Profile!", + Toast.LENGTH_LONG).show(); + } else { + FirebaseDatabase database = FirebaseDatabase.getInstance(); + final DatabaseReference myRef = database.getReference("/socials"); + + //Used if-else because only 3 options and not all check for same type data as required by switch statement + //Check all text is filled out + if (editTextEventName.getText().toString().isEmpty() || editTextDate.getText().toString().isEmpty() || + editTextDescription.getText().toString().isEmpty()) { + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Please fill out all fields", Toast.LENGTH_SHORT).show(); + } + //Check if image is not yet added + else if (data == null) { + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Please upload an image", Toast.LENGTH_SHORT).show(); + } + + //Else actually post the social with all the above fields + else { + progressDialog.setMessage("Uploading New Social..."); + progressDialog.show(); + + mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-e2598.appspot.com"); + final String imageKey = myRef.child("socials").push().getKey(); + StorageReference imageRef = mStorageRef.child(imageKey + ".png"); + + //Adding the photo to Storage + //Intentionally did not add to Utils class, too many dependencies, created more confusion + //than modularity + imageRef.putFile(data.getData()).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception exception) { + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Please upload an image", Toast.LENGTH_SHORT).show(); + } + }).addOnSuccessListener(new OnSuccessListener(){ + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + + //image was successfully added to Storage + ArrayList memberArrayList = new ArrayList(); + memberArrayList.add(firebaseUser.getUid()); + + //Create new Social Object to add to Database and save Social + Social socialToPost = new Social(editTextEventName.getText().toString(), editTextDate.getText().toString(), editTextDescription.getText().toString(), + imageKey + ".png", firebaseUser.getEmail(), 1, memberArrayList); + myRef.child(imageKey).setValue(socialToPost); + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Posted new Social!", Toast.LENGTH_SHORT).show(); + Intent intent = new Intent(getApplicationContext(), UserArea.class); + startActivity(intent); + } + }); + } + } + } + + @Override + public void onCancelled(DatabaseError databaseError) { + } + }); + break; + } + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/Profile.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/Profile.java new file mode 100644 index 0000000..a6919ef --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/Profile.java @@ -0,0 +1,22 @@ +package io.github.sumukhshiv.mdbsocials; + +import java.util.ArrayList; + +/** + * Created by sumukhshivakumar on 2/24/17. + */ + +public class Profile { + + String fullName; + String email; + String profileImage; + ArrayList socialsAttending; + + public Profile(String fullName, String email, String profileImage, ArrayList socialsAttending) { + this.fullName = fullName; + this.email = email; + this.profileImage = profileImage; + this.socialsAttending = socialsAttending; + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/ProfileActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/ProfileActivity.java new file mode 100644 index 0000000..17bcc05 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/ProfileActivity.java @@ -0,0 +1,164 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.app.Activity; +import android.app.ProgressDialog; +import android.content.DialogInterface; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.provider.MediaStore; +import android.support.annotation.NonNull; +import android.support.v7.app.AlertDialog; +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.storage.FirebaseStorage; +import com.google.firebase.storage.StorageReference; +import com.google.firebase.storage.UploadTask; + +import java.io.FileNotFoundException; +import java.io.IOException; +import java.util.ArrayList; + +public class ProfileActivity extends AppCompatActivity implements View.OnClickListener { + + public final static int REQUEST_CAMERA = 1; + public static final int GET_FROM_GALLERY = 3; + private Intent data; + private FirebaseDatabase database = FirebaseDatabase.getInstance(); + private DatabaseReference myRef = database.getReference("users"); + private StorageReference mStorageRef; + private FirebaseAuth firebaseAuth; + private FirebaseUser firebaseUser; + private EditText editTextUpdateName; + + private ProgressDialog progressDialog; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_profile); + + Button buttonSaveProfileUpdate = (Button) findViewById(R.id.buttonSaveProfileUpdate); + ImageView updateProfilePicture = (ImageView) findViewById(R.id.imageViewUpdateProfilePicture); + editTextUpdateName = (EditText) findViewById(R.id.editTextUpdateName); + + buttonSaveProfileUpdate.setOnClickListener(this); + updateProfilePicture.setOnClickListener(this); + + firebaseAuth = FirebaseAuth.getInstance(); + firebaseUser = firebaseAuth.getCurrentUser(); + + progressDialog = new ProgressDialog(this); + + } + + @Override + protected void onActivityResult(int requestCode, int resultCode, Intent data) { + super.onActivityResult(requestCode, resultCode, data); + + + //Detects request codes + if((requestCode==GET_FROM_GALLERY || requestCode == REQUEST_CAMERA) && resultCode == Activity.RESULT_OK) { + Uri selectedImage = data.getData(); + Bitmap bitmap = null; + try { + bitmap = MediaStore.Images.Media.getBitmap(this.getContentResolver(), selectedImage); + //BitmapDrawable bitmapDrawable = new BitmapDrawable(getResources(), bitmap); + ((ImageView) findViewById(R.id.imageViewUpdateProfilePicture)).setImageBitmap(bitmap); + } catch (FileNotFoundException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } catch (IOException e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + } + + this.data = data; + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + + //case to add a profile picture + case (R.id.imageViewUpdateProfilePicture): + AlertDialog alertDialog = new AlertDialog.Builder(ProfileActivity.this).create(); + alertDialog.setTitle("Set a Photo"); + alertDialog.setButton(AlertDialog.BUTTON_POSITIVE, "Take a Photo", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //Open Camera + Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); + if (takePictureIntent.resolveActivity(getPackageManager()) != null) { + startActivityForResult(takePictureIntent, REQUEST_CAMERA); + } + dialog.dismiss(); + } + }); + alertDialog.setButton(AlertDialog.BUTTON_NEGATIVE, "Upload from Gallery", + new DialogInterface.OnClickListener() { + public void onClick(DialogInterface dialog, int which) { + //launch gallery + startActivityForResult(new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.INTERNAL_CONTENT_URI), GET_FROM_GALLERY); + dialog.dismiss(); + } + }); + alertDialog.show(); + break; + + //case to save the profile to firebase + case (R.id.buttonSaveProfileUpdate): + //getting the reference to the storage + mStorageRef = FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-e2598.appspot.com"); + final String imageKey = myRef.child("users").push().getKey(); + StorageReference imageRef = mStorageRef.child(imageKey + ".png"); + + //Doing various checks for the different fields. + //Used if else because the checks are on different variables + if (editTextUpdateName.getText().toString().isEmpty()) { + Toast.makeText(getApplicationContext(), "Please enter your name", Toast.LENGTH_SHORT).show(); + } else if (data == null) { + Toast.makeText(getApplicationContext(), "Please upload an image", Toast.LENGTH_SHORT).show(); + } else { + progressDialog.setMessage("Updating your Profile..."); + progressDialog.show(); + //adding the image to storage + //Intentionally did not use Utils class, Too many dependencies and created more confusion than modularity + imageRef.putFile(data.getData()).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception exception) { + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Please upload an image", Toast.LENGTH_SHORT).show(); + } + }).addOnSuccessListener(new OnSuccessListener(){ + @Override + public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { + //creating a new Profile object to send data to Firebase Database + Profile updatedProfile = new Profile(editTextUpdateName.getText().toString(), firebaseUser.getEmail(), imageKey + ".png" , new ArrayList() ); + myRef.child(firebaseUser.getUid()).setValue(updatedProfile); + progressDialog.dismiss(); + Toast.makeText(getApplicationContext(), "Updated your Profile!", Toast.LENGTH_SHORT).show(); + + //Go straight to Social Feed + Intent intent = new Intent(getApplicationContext(), UserArea.class); + startActivity(intent); + } + }); + } + break; + } + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/SignUpActivity.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/SignUpActivity.java new file mode 100644 index 0000000..375a505 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/SignUpActivity.java @@ -0,0 +1,206 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.app.ProgressDialog; +import android.support.annotation.NonNull; +import android.support.v7.app.AppCompatActivity; +import android.os.Bundle; +import android.text.Editable; +import android.text.TextUtils; +import android.text.TextWatcher; +import android.util.Log; +import android.view.View; +import android.widget.Button; +import android.widget.EditText; +import android.widget.TextView; +import android.widget.Toast; + +import com.google.firebase.auth.FirebaseAuth; +import com.google.firebase.auth.FirebaseUser; + +import static android.graphics.Color.DKGRAY; +import static android.graphics.Color.GREEN; +import static android.graphics.Color.RED; +import static android.graphics.Color.YELLOW; + +public class SignUpActivity extends AppCompatActivity implements View.OnClickListener{ + + private Button buttonRegisterUser; + private EditText editTextEmail; + private EditText editTextPassword; + private TextView textViewPasswordStrengthIndiactor; + private TextView textViewPasswordGraphic; + private ProgressDialog progressDialog; + private FirebaseAuth mAuth; + private FirebaseAuth.AuthStateListener mAuthListener; + + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_sign_up); + + //assigning variables + mAuth = FirebaseAuth.getInstance(); + progressDialog = new ProgressDialog(this); + buttonRegisterUser = (Button) findViewById(R.id.buttonRegisterSignUp); + buttonRegisterUser.setOnClickListener(this); + + editTextEmail = (EditText) findViewById(R.id.editTextEmailSignUp); + editTextPassword = (EditText) findViewById(R.id.editTextPasswordSignup); + + textViewPasswordStrengthIndiactor = (TextView) findViewById(R.id.textViewPasswordStrengthIndicator); + textViewPasswordGraphic = (TextView) findViewById(R.id.textViewPasswordGraphic); + + mAuthListener = new FirebaseAuth.AuthStateListener() { + @Override + public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { + FirebaseUser user = firebaseAuth.getCurrentUser(); + if (user != null) { + // User is signed in + Log.d("AUTHinSignup", "onAuthStateChanged:signed_in:" + user.getUid()); + } else { + // User is signed out + Log.d("AUTHinSignUp", "onAuthStateChanged:signed_out"); + } + } + }; + + editTextPassword.addTextChangedListener(mTextEditorWatcher); + + } + + @Override + public void onStart() { + super.onStart(); + mAuth.addAuthStateListener(mAuthListener); + } + + + @Override + public void onStop() { + super.onStop(); + if (mAuthListener != null) { + mAuth.removeAuthStateListener(mAuthListener); + } + } + + private final TextWatcher mTextEditorWatcher = new TextWatcher() { + + public void beforeTextChanged(CharSequence s, int start, int count, int after) + { + + } + + public void onTextChanged(CharSequence s, int start, int before, int count) + { + + } + + /** + * Method to update the passwordStrengthGraphic in real time + * @param s + * Returns nothing, just modifies the length, color, and text of different textviews + */ + public void afterTextChanged(Editable s) + { + switch (s.length()) { + case 0: + textViewPasswordStrengthIndiactor.setTextColor(DKGRAY); + textViewPasswordGraphic.setBackgroundColor(DKGRAY); + textViewPasswordGraphic.setWidth(0); + textViewPasswordGraphic.setHeight(12); + break; + case (1): + textViewPasswordStrengthIndiactor.setText("Must be at least 6 digits"); + textViewPasswordStrengthIndiactor.setTextColor(DKGRAY); + textViewPasswordGraphic.setBackgroundColor(DKGRAY); + textViewPasswordGraphic.setWidth(50); + textViewPasswordGraphic.setHeight(12); + break; + case 6: + textViewPasswordStrengthIndiactor.setText("Easy"); + textViewPasswordGraphic.setBackgroundColor(RED); + textViewPasswordGraphic.setWidth(200); + textViewPasswordGraphic.setHeight(12); + break; + case 8: + textViewPasswordStrengthIndiactor.setText("Easy"); + textViewPasswordGraphic.setBackgroundColor(RED); + textViewPasswordGraphic.setWidth(300); + textViewPasswordGraphic.setHeight(12); + break; + + case 11: + textViewPasswordStrengthIndiactor.setText("Medium"); + textViewPasswordGraphic.setBackgroundColor(YELLOW); + textViewPasswordGraphic.setWidth(400); + textViewPasswordGraphic.setHeight(12); + break; + + case 13: + textViewPasswordStrengthIndiactor.setText("Medium"); + textViewPasswordGraphic.setBackgroundColor(YELLOW); + textViewPasswordGraphic.setWidth(500); + textViewPasswordGraphic.setHeight(12); + break; + case 15: + textViewPasswordStrengthIndiactor.setText("Strong"); + textViewPasswordGraphic.setBackgroundColor(GREEN); + textViewPasswordGraphic.setWidth(850); + textViewPasswordGraphic.setHeight(12); + break; + case 17: + textViewPasswordStrengthIndiactor.setText("Strong"); + textViewPasswordGraphic.setBackgroundColor(GREEN); + textViewPasswordGraphic.setWidth(950); + textViewPasswordGraphic.setHeight(12); + break; + case 20: + textViewPasswordStrengthIndiactor.setText("Password Max Length Reached"); + textViewPasswordGraphic.setBackgroundColor(DKGRAY); + + } + + } + }; + + /** + * Helper method used to register users into Firebase Authentication + * Uses the firebase createUserWithEmailAndPassword method + * Displays Progress Dialogue in between firebase actions + */ + private void registerUser() { + final String email = editTextEmail.getText().toString().trim(); + final String password = editTextPassword.getText().toString().trim(); + + //If cases to check that all fields are filled out + //Separated into 3 if cases to provide more informative tests + if (TextUtils.isEmpty(email)) { + Toast.makeText(this, "Please enter a valid Email Address", Toast.LENGTH_SHORT).show(); + return; + } + if (TextUtils.isEmpty(password)) { + Toast.makeText(this, "Please enter a Password", Toast.LENGTH_SHORT).show(); + return; + } + if (password.length() < 6) { + + Toast.makeText(this, "Password must be at least 6 characters", Toast.LENGTH_SHORT).show(); + return; + } + + progressDialog.setMessage("Registering User..."); + progressDialog.show(); + + FirebaseUtils.signUp(email, password, progressDialog, this); + } + + @Override + public void onClick(View view) { + switch (view.getId()) { + case R.id.buttonRegisterSignUp: + registerUser(); + break; + } + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/Social.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/Social.java new file mode 100644 index 0000000..939ab7b --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/Social.java @@ -0,0 +1,30 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.graphics.drawable.Drawable; + +import java.io.Serializable; +import java.util.ArrayList; + +/** + * Created by sumukhshivakumar on 2/24/17. + */ + +public class Social implements Serializable{ + String nameOfEvent; + String date; + String description; + String image; + String emailOfHost; + int numberIntersted; + ArrayList peopleInterested; + + public Social(String nameOfEvent, String date, String description, String image, String emailOfHost, int numberIntersted, ArrayList peopleInterested) { + this.nameOfEvent = nameOfEvent; + this.date = date; + this.description = description; + this.image = image; + this.emailOfHost = emailOfHost; + this.numberIntersted = numberIntersted; + this.peopleInterested = peopleInterested; + } +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/SocialsAdapter.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/SocialsAdapter.java new file mode 100644 index 0000000..3b42a1f --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/SocialsAdapter.java @@ -0,0 +1,135 @@ +package io.github.sumukhshiv.mdbsocials; + +import android.content.Context; +import android.content.Intent; +import android.graphics.Bitmap; +import android.net.Uri; +import android.os.AsyncTask; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v7.widget.CardView; +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.OnFailureListener; +import com.google.android.gms.tasks.OnSuccessListener; +import com.google.firebase.storage.FirebaseStorage; + +import java.util.ArrayList; + +/** + * Created by sumukhshivakumar on 2/24/17. + */ + +public class SocialsAdapter extends RecyclerView.Adapter { + + Context context; + ArrayList socials; + + public SocialsAdapter(Context context, ArrayList socials) { + this.context = context; + this.socials = socials; + } + + public void setSocialsList(ArrayList list) { + socials = list; + } + + @Override + public SocialsAdapter.CustomViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.row_view, parent, false); + return new CustomViewHolder(view); + } + + @Override + public void onBindViewHolder(final SocialsAdapter.CustomViewHolder holder, int position) { + //used to view the most recent socials at the top + final Social social = socials.get(socials.size() - position - 1); + + //Adds image from Storage into the imageView + //Uses AsyncTask and Firebase Download from URL + class DownloadFilesTask extends AsyncTask { + protected Bitmap doInBackground(String... strings) { + try {return Glide. + with(context). + load(strings[0]). + asBitmap(). + into(100, 100). // Width and height + get();} + catch (Exception e) {return null;} + } + + protected void onProgressUpdate(Void... progress) {} + + protected void onPostExecute(Bitmap result) { + holder.imageViewEventImage.setImageBitmap(result); + } + } + FirebaseStorage.getInstance().getReferenceFromUrl("gs://mdbsocials-e2598.appspot.com").child(social.image).getDownloadUrl().addOnSuccessListener(new OnSuccessListener() { + @Override + public void onSuccess(Uri uri) { + (new DownloadFilesTask()).execute(uri.toString()); + Log.d("AddingPhoto", uri.toString()); + } + }).addOnFailureListener(new OnFailureListener() { + @Override + public void onFailure(@NonNull Exception exception) { + Log.d("Failed to add image", exception.toString()); + } + }); + + + holder.textViewEventName.setText(social.nameOfEvent); + holder.textViewHostEmail.setText(social.emailOfHost); + holder.textViewNumberInterested.setText(Integer.toString(social.numberIntersted)); + + + //Click listener for each card. Kept as setOnCLickListener because used only once in the code + //Uses the social object specific to the one found in each instance of the bindViewHolder + holder.cardViewFeed.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View v) { + Intent intent = new Intent(context, DetailScreenActivity.class); + Bundle bundle = new Bundle(); + bundle.putSerializable("SOCIAL", social); + intent.putExtras(bundle); + intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); + context.startActivity(intent); + } + }); + + } + + @Override + public int getItemCount() { + return socials.size(); + } + + public class CustomViewHolder extends RecyclerView.ViewHolder { + + //Set up the variables + ImageView imageViewEventImage; + TextView textViewEventName; + TextView textViewHostEmail; + TextView textViewNumberInterested; + CardView cardViewFeed; + + public CustomViewHolder(View view) { + super(view); + + imageViewEventImage = (ImageView) view.findViewById(R.id.imageViewSocialImage); + textViewEventName = (TextView) view.findViewById(R.id.textViewEventName); + textViewHostEmail = (TextView) view.findViewById(R.id.textViewHostEmail); + textViewNumberInterested = (TextView) view.findViewById(R.id.textViewNumberInterested); + cardViewFeed = (CardView) view.findViewById(R.id.cardViewFeed); + + } + } + +} diff --git a/app/src/main/java/io/github/sumukhshiv/mdbsocials/UserArea.java b/app/src/main/java/io/github/sumukhshiv/mdbsocials/UserArea.java new file mode 100644 index 0000000..e965ec7 --- /dev/null +++ b/app/src/main/java/io/github/sumukhshiv/mdbsocials/UserArea.java @@ -0,0 +1,152 @@ +package io.github.sumukhshiv.mdbsocials; + +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.util.Log; +import android.util.SparseBooleanArray; +import android.view.View; +import android.widget.AdapterView; +import android.widget.ArrayAdapter; +import android.widget.ListView; +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.GenericTypeIndicator; +import com.google.firebase.database.ValueEventListener; + +import java.util.ArrayList; + +public class UserArea extends AppCompatActivity { + + FirebaseDatabase database = FirebaseDatabase.getInstance(); + DatabaseReference myRef = database.getReference("/socials"); + ArrayList arrayListSocials; + ValueEventListener mSocialsEventListener; + SocialsAdapter toSetSocialsAdapter; + + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_user_area); + + //Elements for the side navbar with the series of options. + final ListView mDrawerList; + final ArrayAdapter mAdapter; + String[] optionsArray = {"Update Profile", "Create New Social", "Logout"}; + final Intent grabIntent = getIntent(); + mDrawerList = (ListView) findViewById(R.id.navList); + mAdapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1, optionsArray); + mDrawerList.setAdapter(mAdapter); + + //Default toast to indicate swipe from the left reveals more options. + Toast.makeText(UserArea.this, "Swipe from the left for more options", Toast.LENGTH_SHORT).show(); + + /** + * Click listener for the items of the navbar. Did not implement for the class because this + * is not directly a view viewed by default on the screen. This works best according to + * StackOverFlow. + */ + mDrawerList.setOnItemClickListener(new AdapterView.OnItemClickListener() { + @Override + public void onItemClick(AdapterView adapterView, View view, int i, long l) { + SparseBooleanArray clickedItemPositions = mDrawerList.getCheckedItemPositions(); + mAdapter.notifyDataSetChanged(); + + for(int j = 0;j < clickedItemPositions.size(); j ++){ + boolean checked = clickedItemPositions.valueAt(j); + + if(checked) { + int key = clickedItemPositions.keyAt(j); + String item = (String) mDrawerList.getItemAtPosition(key); + + switch (item) { + case ("Update Profile"): + Intent updateProfileIntent = new Intent(getApplicationContext(), ProfileActivity.class); + updateProfileIntent.putExtra("email", grabIntent.getStringExtra("email")); + startActivity(updateProfileIntent); + break; + case ("Create New Social"): + Intent newSocialIntent = new Intent(getApplicationContext(), NewSocialActivity.class); + newSocialIntent.putExtra("email", grabIntent.getStringExtra("email")); + startActivity(newSocialIntent); + break; + case ("Logout"): + FirebaseAuth.getInstance().signOut(); + Intent logoutIntent = new Intent(getApplicationContext(), MainActivity.class); + startActivity(logoutIntent); + break; + + } + + } + } + } + }); + + + /** + * Grabbing RecyclerView + * Setting LayoutManager + * Creating a new Adapter + * Attaching it to the recyclerView + */ + + RecyclerView recyclerView = (RecyclerView) findViewById(R.id.recyclerViewFeed); + recyclerView.setLayoutManager(new LinearLayoutManager(getApplicationContext())); + arrayListSocials = new ArrayList<>(); + toSetSocialsAdapter = new SocialsAdapter(getApplicationContext(), arrayListSocials); + recyclerView.setAdapter(toSetSocialsAdapter); + + } + + @Override + public void onStart() { + super.onStart(); + Toast.makeText(UserArea.this, "Swipe from the left for more options", Toast.LENGTH_LONG).show(); + if (mSocialsEventListener == null) { + mSocialsEventListener = new ValueEventListener() { + @Override + public void onDataChange(DataSnapshot dataSnapshot) { + ArrayList temp = new ArrayList<>(); + for (DataSnapshot postSnapshot: dataSnapshot.getChildren()) { + + /** + * Create a new Social Object based on what is found within Firebase + * Uses the datasnapchat and integrates through all of database to create + * social object for each social + */ + + String name = postSnapshot.child("nameOfEvent").getValue(String.class); + String date = postSnapshot.child("date").getValue(String.class); + String description = postSnapshot.child("description").getValue(String.class); + String image = postSnapshot.child("image").getValue(String.class); + String emailOfHost = postSnapshot.child("emailOfHost").getValue(String.class); + int numberInterested = postSnapshot.child("numberIntersted").getValue(Integer.class); + GenericTypeIndicator> t = new GenericTypeIndicator>() {}; + ArrayList listOfUsersInSocial = postSnapshot.child("peopleInterested").getValue(t); + Social newSocial = new Social(name, date, description, image, emailOfHost, numberInterested, listOfUsersInSocial); + temp.add(newSocial); + Log.d("DEBUG", arrayListSocials.size() + ""); + } + toSetSocialsAdapter.setSocialsList(temp); + toSetSocialsAdapter.notifyDataSetChanged(); + } + + @Override + public void onCancelled(DatabaseError databaseError) { + // Getting Post failed, log a message + //Log.w(TAG, "loadPost:onCancelled", databaseError.toException()); + } + }; + myRef.addValueEventListener(mSocialsEventListener); + } + } + +} diff --git a/app/src/main/res/drawable-v21/ic_menu_camera.xml b/app/src/main/res/drawable-v21/ic_menu_camera.xml new file mode 100644 index 0000000..0d9ea10 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_camera.xml @@ -0,0 +1,12 @@ + + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_gallery.xml b/app/src/main/res/drawable-v21/ic_menu_gallery.xml new file mode 100644 index 0000000..f6872c4 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_gallery.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_manage.xml b/app/src/main/res/drawable-v21/ic_menu_manage.xml new file mode 100644 index 0000000..c1be60b --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_manage.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/drawable-v21/ic_menu_send.xml b/app/src/main/res/drawable-v21/ic_menu_send.xml new file mode 100644 index 0000000..00c668c --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_send.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_share.xml b/app/src/main/res/drawable-v21/ic_menu_share.xml new file mode 100644 index 0000000..a28fb9e --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_share.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable-v21/ic_menu_slideshow.xml b/app/src/main/res/drawable-v21/ic_menu_slideshow.xml new file mode 100644 index 0000000..209aa64 --- /dev/null +++ b/app/src/main/res/drawable-v21/ic_menu_slideshow.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/ic_person_black_24dp.xml b/app/src/main/res/drawable/ic_person_black_24dp.xml new file mode 100644 index 0000000..b2cb337 --- /dev/null +++ b/app/src/main/res/drawable/ic_person_black_24dp.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/drawable/mdb_logo.jpg b/app/src/main/res/drawable/mdb_logo.jpg new file mode 100644 index 0000000..20552e2 Binary files /dev/null and b/app/src/main/res/drawable/mdb_logo.jpg differ diff --git a/app/src/main/res/drawable/side_nav_bar.xml b/app/src/main/res/drawable/side_nav_bar.xml new file mode 100644 index 0000000..458b4b0 --- /dev/null +++ b/app/src/main/res/drawable/side_nav_bar.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_detail_screen.xml b/app/src/main/res/layout/activity_detail_screen.xml new file mode 100644 index 0000000..842a865 --- /dev/null +++ b/app/src/main/res/layout/activity_detail_screen.xml @@ -0,0 +1,96 @@ + + + + + + + + + +