├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── LICENSE ├── README.md ├── app ├── .gitignore ├── build.gradle ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── simcoder │ │ └── tinder │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── simcoder │ │ │ └── tinder │ │ │ ├── Cards │ │ │ ├── arrayAdapter.java │ │ │ └── cards.java │ │ │ ├── Chat │ │ │ ├── ChatActivity.java │ │ │ ├── ChatAdapter.java │ │ │ ├── ChatObject.java │ │ │ └── ChatViewHolders.java │ │ │ ├── ChooseLoginRegistrationActivity.java │ │ │ ├── LoginActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── Matches │ │ │ ├── MatchesActivity.java │ │ │ ├── MatchesAdapter.java │ │ │ ├── MatchesObject.java │ │ │ └── MatchesViewHolders.java │ │ │ ├── RegistrationActivity.java │ │ │ └── SettingsActivity.java │ └── res │ │ ├── layout │ │ ├── activity_chat.xml │ │ ├── activity_choose_login_registration.xml │ │ ├── activity_login.xml │ │ ├── activity_main.xml │ │ ├── activity_matches.xml │ │ ├── activity_registration.xml │ │ ├── activity_settings.xml │ │ ├── item.xml │ │ ├── item_chat.xml │ │ └── item_matches.xml │ │ ├── mipmap-hdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-mdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_launcher.png │ │ └── ic_launcher_round.png │ │ └── values │ │ ├── colors.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── simcoder │ └── tinder │ └── ExampleUnitTest.java ├── build.gradle ├── gradle.properties ├── gradle └── wrapper │ ├── gradle-wrapper.jar │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat └── settings.gradle /.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | .externalNativeBuild 10 | -------------------------------------------------------------------------------- /.idea/compiler.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /.idea/copyright/profiles_settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | -------------------------------------------------------------------------------- /.idea/gradle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 17 | 18 | -------------------------------------------------------------------------------- /.idea/misc.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 16 | 26 | 27 | 28 | 29 | 30 | 31 | 33 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 SimCoder 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Tinder_android_app_clone 2 | 3 | ▷ Create an android app like tinder 4 | 5 | ▷ Full Video Tutorial Playlist here: https://www.youtube.com/playlist?list=PLxabZQCAe5fio9dm1Vd0peIY6HLfo5MCf 6 | 7 | ▷ Tools Used In this Project: 8 | - Android Studio; 9 | - Firebase: 10 | *Realtime database 11 | *Authentication 12 | - SwipeCards; 13 | 14 | ▷ In this project we've done:
15 | 1 - SwipeCards Implementation;
16 | 17 | ▷ If you have any question please ask, I'll try to answer to every question and even look at your code if that is necessary. 18 | 19 | 20 | PS: If ou're going to download the full project please use your on firebase API, the one in the project will NOT be mantained and the app may not work. 21 | 22 | 23 | # Implementation Guide 24 | 25 | **1 - Project**
26 | 1 - Open the Project in your android studio;
27 | 2 - !!!!IMPORTANT!!!! Change the Package Name. You can check how to do that here (https://stackoverflow.com/questions/16804093/android-studio-rename-package)
28 | 29 | 30 | **2 - Firebase Panel**
31 | 1 - Create Firebase Project (https://console.firebase.google.com/);
32 | 2 - import the file google-service.json into your project as the instructions say;
33 | 3 - Go to Firebase -> Registration and activate Login/Registrtion with email
34 | 4 - Go to Firebase -> storage and activate it;
35 | 36 | 37 | **!!!DONE!!!** 38 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion '26.0.2' 6 | defaultConfig { 7 | applicationId "com.simcoder.tinder" 8 | minSdkVersion 15 9 | targetSdkVersion 26 10 | versionCode 1 11 | versionName "1.0" 12 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(include: ['*.jar'], dir: 'libs') 24 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 25 | exclude group: 'com.android.support', module: 'support-annotations' 26 | }) 27 | compile 'com.android.support:appcompat-v7:26.0.0-alpha1' 28 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 29 | compile 'com.android.support:design:26.1.0' 30 | compile 'com.android.support:cardview-v7:26.1.0' 31 | compile 'com.android.support:support-annotations:x.x.x' 32 | compile 'com.google.firebase:firebase-core:11.0.4' 33 | compile 'com.google.firebase:firebase-database:11.0.4' 34 | compile 'com.google.firebase:firebase-auth:11.0.4' 35 | compile 'com.google.firebase:firebase-storage:11.0.4' 36 | compile 'com.github.bumptech.glide:glide:3.7.0' 37 | compile 'com.lorentzos.swipecards:library:1.0.9' 38 | testCompile 'junit:junit:4.12' 39 | } 40 | 41 | 42 | 43 | apply plugin: 'com.google.gms.google-services' 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | -------------------------------------------------------------------------------- /app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in C:\Users\manel\AppData\Local\Android\sdk1/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | 19 | # Uncomment this to preserve the line number information for 20 | # debugging stack traces. 21 | #-keepattributes SourceFile,LineNumberTable 22 | 23 | # If you keep the line number information, uncomment this to 24 | # hide the original source file name. 25 | #-renamesourcefileattribute SourceFile 26 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/simcoder/tinder/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder; 2 | 3 | import android.content.Context; 4 | import android.support.test.InstrumentationRegistry; 5 | import android.support.test.runner.AndroidJUnit4; 6 | 7 | import org.junit.Test; 8 | import org.junit.runner.RunWith; 9 | 10 | import static org.junit.Assert.*; 11 | 12 | /** 13 | * Instrumentation test, which will execute on an Android device. 14 | * 15 | * @see Testing documentation 16 | */ 17 | @RunWith(AndroidJUnit4.class) 18 | public class ExampleInstrumentedTest { 19 | @Test 20 | public void useAppContext() throws Exception { 21 | // Context of the app under test. 22 | Context appContext = InstrumentationRegistry.getTargetContext(); 23 | 24 | assertEquals("com.simcoder.tinder", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Cards/arrayAdapter.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Cards; 2 | 3 | import android.content.Context; 4 | import android.view.LayoutInflater; 5 | import android.view.View; 6 | import android.view.ViewGroup; 7 | import android.widget.ArrayAdapter; 8 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.bumptech.glide.Glide; 12 | import com.simcoder.tinder.R; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by manel on 9/5/2017. 18 | */ 19 | 20 | public class arrayAdapter extends ArrayAdapter{ 21 | 22 | Context context; 23 | 24 | public arrayAdapter(Context context, int resourceId, List items){ 25 | super(context, resourceId, items); 26 | } 27 | public View getView(int position, View convertView, ViewGroup parent){ 28 | cards card_item = getItem(position); 29 | 30 | if (convertView == null){ 31 | convertView = LayoutInflater.from(getContext()).inflate(R.layout.item, parent, false); 32 | } 33 | 34 | TextView name = (TextView) convertView.findViewById(R.id.name); 35 | ImageView image = (ImageView) convertView.findViewById(R.id.image); 36 | 37 | name.setText(card_item.getName()); 38 | switch(card_item.getProfileImageUrl()){ 39 | case "default": 40 | Glide.with(convertView.getContext()).load(R.mipmap.ic_launcher).into(image); 41 | break; 42 | default: 43 | Glide.clear(image); 44 | Glide.with(convertView.getContext()).load(card_item.getProfileImageUrl()).into(image); 45 | break; 46 | } 47 | 48 | 49 | return convertView; 50 | 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Cards/cards.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Cards; 2 | 3 | /** 4 | * Created by manel on 9/5/2017. 5 | */ 6 | 7 | public class cards { 8 | private String userId; 9 | private String name; 10 | private String profileImageUrl; 11 | public cards (String userId, String name, String profileImageUrl){ 12 | this.userId = userId; 13 | this.name = name; 14 | this.profileImageUrl = profileImageUrl; 15 | } 16 | 17 | public String getUserId(){ 18 | return userId; 19 | } 20 | public void setUserID(String userID){ 21 | this.userId = userId; 22 | } 23 | 24 | public String getName(){ 25 | return name; 26 | } 27 | public void setName(String name){ 28 | this.name = name; 29 | } 30 | 31 | public String getProfileImageUrl(){ 32 | return profileImageUrl; 33 | } 34 | public void setProfileImageUrl(String profileImageUrl){ 35 | this.profileImageUrl = profileImageUrl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Chat/ChatActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Chat; 2 | 3 | import android.support.v7.app.AppCompatActivity; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.LinearLayoutManager; 6 | import android.support.v7.widget.RecyclerView; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.EditText; 10 | 11 | import com.google.firebase.auth.FirebaseAuth; 12 | import com.google.firebase.database.ChildEventListener; 13 | import com.google.firebase.database.DataSnapshot; 14 | import com.google.firebase.database.DatabaseError; 15 | import com.google.firebase.database.DatabaseReference; 16 | import com.google.firebase.database.FirebaseDatabase; 17 | import com.google.firebase.database.ValueEventListener; 18 | import com.simcoder.tinder.Matches.MatchesActivity; 19 | import com.simcoder.tinder.Matches.MatchesAdapter; 20 | import com.simcoder.tinder.Matches.MatchesObject; 21 | import com.simcoder.tinder.R; 22 | 23 | import java.util.ArrayList; 24 | import java.util.HashMap; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | public class ChatActivity extends AppCompatActivity { 29 | private RecyclerView mRecyclerView; 30 | private RecyclerView.Adapter mChatAdapter; 31 | private RecyclerView.LayoutManager mChatLayoutManager; 32 | 33 | private EditText mSendEditText; 34 | 35 | private Button mSendButton; 36 | 37 | private String currentUserID, matchId, chatId; 38 | 39 | DatabaseReference mDatabaseUser, mDatabaseChat; 40 | @Override 41 | protected void onCreate(Bundle savedInstanceState) { 42 | super.onCreate(savedInstanceState); 43 | setContentView(R.layout.activity_chat); 44 | 45 | matchId = getIntent().getExtras().getString("matchId"); 46 | 47 | currentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid(); 48 | 49 | mDatabaseUser = FirebaseDatabase.getInstance().getReference().child("Users").child(currentUserID).child("connections").child("matches").child(matchId).child("ChatId"); 50 | mDatabaseChat = FirebaseDatabase.getInstance().getReference().child("Chat"); 51 | 52 | getChatId(); 53 | 54 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); 55 | mRecyclerView.setNestedScrollingEnabled(false); 56 | mRecyclerView.setHasFixedSize(false); 57 | mChatLayoutManager = new LinearLayoutManager(ChatActivity.this); 58 | mRecyclerView.setLayoutManager(mChatLayoutManager); 59 | mChatAdapter = new ChatAdapter(getDataSetChat(), ChatActivity.this); 60 | mRecyclerView.setAdapter(mChatAdapter); 61 | 62 | mSendEditText = findViewById(R.id.message); 63 | mSendButton = findViewById(R.id.send); 64 | 65 | mSendButton.setOnClickListener(new View.OnClickListener() { 66 | @Override 67 | public void onClick(View view) { 68 | sendMessage(); 69 | } 70 | }); 71 | } 72 | 73 | private void sendMessage() { 74 | String sendMessageText = mSendEditText.getText().toString(); 75 | 76 | if(!sendMessageText.isEmpty()){ 77 | DatabaseReference newMessageDb = mDatabaseChat.push(); 78 | 79 | Map newMessage = new HashMap(); 80 | newMessage.put("createdByUser", currentUserID); 81 | newMessage.put("text", sendMessageText); 82 | 83 | newMessageDb.setValue(newMessage); 84 | } 85 | mSendEditText.setText(null); 86 | } 87 | 88 | private void getChatId(){ 89 | mDatabaseUser.addListenerForSingleValueEvent(new ValueEventListener() { 90 | @Override 91 | public void onDataChange(DataSnapshot dataSnapshot) { 92 | if (dataSnapshot.exists()){ 93 | chatId = dataSnapshot.getValue().toString(); 94 | mDatabaseChat = mDatabaseChat.child(chatId); 95 | getChatMessages(); 96 | } 97 | } 98 | 99 | @Override 100 | public void onCancelled(DatabaseError databaseError) { 101 | 102 | } 103 | }); 104 | } 105 | 106 | private void getChatMessages() { 107 | mDatabaseChat.addChildEventListener(new ChildEventListener() { 108 | @Override 109 | public void onChildAdded(DataSnapshot dataSnapshot, String s) { 110 | if(dataSnapshot.exists()){ 111 | String message = null; 112 | String createdByUser = null; 113 | 114 | if(dataSnapshot.child("text").getValue()!=null){ 115 | message = dataSnapshot.child("text").getValue().toString(); 116 | } 117 | if(dataSnapshot.child("createdByUser").getValue()!=null){ 118 | createdByUser = dataSnapshot.child("createdByUser").getValue().toString(); 119 | } 120 | 121 | if(message!=null && createdByUser!=null){ 122 | Boolean currentUserBoolean = false; 123 | if(createdByUser.equals(currentUserID)){ 124 | currentUserBoolean = true; 125 | } 126 | ChatObject newMessage = new ChatObject(message, currentUserBoolean); 127 | resultsChat.add(newMessage); 128 | mChatAdapter.notifyDataSetChanged(); 129 | } 130 | } 131 | 132 | } 133 | @Override 134 | public void onChildChanged(DataSnapshot dataSnapshot, String s) { 135 | } 136 | @Override 137 | public void onChildRemoved(DataSnapshot dataSnapshot) { 138 | } 139 | @Override 140 | public void onChildMoved(DataSnapshot dataSnapshot, String s) { 141 | } 142 | @Override 143 | public void onCancelled(DatabaseError databaseError) { 144 | } 145 | }); 146 | } 147 | 148 | 149 | private ArrayList resultsChat = new ArrayList(); 150 | private List getDataSetChat() { 151 | return resultsChat; 152 | } 153 | } 154 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Chat/ChatAdapter.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Chat; 2 | 3 | import android.content.Context; 4 | import android.graphics.Color; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.Gravity; 7 | import android.view.LayoutInflater; 8 | import android.view.View; 9 | import android.view.ViewGroup; 10 | 11 | import com.bumptech.glide.Glide; 12 | import com.simcoder.tinder.R; 13 | 14 | import java.util.List; 15 | 16 | /** 17 | * Created by manel on 10/31/2017. 18 | */ 19 | 20 | public class ChatAdapter extends RecyclerView.Adapter{ 21 | private List chatList; 22 | private Context context; 23 | 24 | 25 | public ChatAdapter(List matchesList, Context context){ 26 | this.chatList = matchesList; 27 | this.context = context; 28 | } 29 | 30 | @Override 31 | public ChatViewHolders onCreateViewHolder(ViewGroup parent, int viewType) { 32 | 33 | View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_chat, null, false); 34 | RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 35 | layoutView.setLayoutParams(lp); 36 | ChatViewHolders rcv = new ChatViewHolders(layoutView); 37 | 38 | return rcv; 39 | } 40 | 41 | @Override 42 | public void onBindViewHolder(ChatViewHolders holder, int position) { 43 | holder.mMessage.setText(chatList.get(position).getMessage()); 44 | if(chatList.get(position).getCurrentUser()){ 45 | holder.mMessage.setGravity(Gravity.END); 46 | holder.mMessage.setTextColor(Color.parseColor("#404040")); 47 | holder.mContainer.setBackgroundColor(Color.parseColor("#F4F4F4")); 48 | }else{ 49 | holder.mMessage.setGravity(Gravity.START); 50 | holder.mMessage.setTextColor(Color.parseColor("#FFFFFF")); 51 | holder.mContainer.setBackgroundColor(Color.parseColor("#2DB4C8")); 52 | } 53 | 54 | } 55 | 56 | @Override 57 | public int getItemCount() { 58 | return this.chatList.size(); 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Chat/ChatObject.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Chat; 2 | 3 | /** 4 | * Created by manel on 10/31/2017. 5 | */ 6 | 7 | public class ChatObject { 8 | private String message; 9 | private Boolean currentUser; 10 | public ChatObject(String message, Boolean currentUser){ 11 | this.message = message; 12 | this.currentUser = currentUser; 13 | } 14 | 15 | public String getMessage(){ 16 | return message; 17 | } 18 | public void setMessage(String userID){ 19 | this.message = message; 20 | } 21 | 22 | public Boolean getCurrentUser(){ 23 | return currentUser; 24 | } 25 | public void setCurrentUser(Boolean currentUser){ 26 | this.currentUser = currentUser; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Chat/ChatViewHolders.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Chat; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.widget.ImageView; 8 | import android.widget.LinearLayout; 9 | import android.widget.TextView; 10 | 11 | import com.simcoder.tinder.R; 12 | 13 | /** 14 | * Created by manel on 10/31/2017. 15 | */ 16 | 17 | public class ChatViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener{ 18 | public TextView mMessage; 19 | public LinearLayout mContainer; 20 | public ChatViewHolders(View itemView) { 21 | super(itemView); 22 | itemView.setOnClickListener(this); 23 | 24 | mMessage = itemView.findViewById(R.id.message); 25 | mContainer = itemView.findViewById(R.id.container); 26 | } 27 | 28 | @Override 29 | public void onClick(View view) { 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/ChooseLoginRegistrationActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.view.View; 7 | import android.widget.Button; 8 | 9 | public class ChooseLoginRegistrationActivity extends AppCompatActivity { 10 | 11 | private Button mLogin, mRegister; 12 | @Override 13 | protected void onCreate(Bundle savedInstanceState) { 14 | super.onCreate(savedInstanceState); 15 | setContentView(R.layout.activity_choose_login_registration); 16 | 17 | mLogin = (Button) findViewById(R.id.login); 18 | mRegister = (Button) findViewById(R.id.register); 19 | 20 | mLogin.setOnClickListener(new View.OnClickListener() { 21 | @Override 22 | public void onClick(View view) { 23 | Intent intent = new Intent(ChooseLoginRegistrationActivity.this, LoginActivity.class); 24 | startActivity(intent); 25 | finish(); 26 | return; 27 | } 28 | }); 29 | 30 | mRegister.setOnClickListener(new View.OnClickListener() { 31 | @Override 32 | public void onClick(View view) { 33 | Intent intent = new Intent(ChooseLoginRegistrationActivity.this, RegistrationActivity.class); 34 | startActivity(intent); 35 | finish(); 36 | return; 37 | } 38 | }); 39 | } 40 | } 41 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder; 2 | 3 | import android.content.Intent; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.EditText; 10 | import android.widget.Toast; 11 | 12 | import com.google.android.gms.tasks.OnCompleteListener; 13 | import com.google.android.gms.tasks.Task; 14 | import com.google.firebase.auth.AuthResult; 15 | import com.google.firebase.auth.FirebaseAuth; 16 | import com.google.firebase.auth.FirebaseUser; 17 | 18 | public class LoginActivity extends AppCompatActivity { 19 | 20 | private Button mLogin; 21 | private EditText mEmail, mPassword; 22 | 23 | private FirebaseAuth mAuth; 24 | private FirebaseAuth.AuthStateListener firebaseAuthStateListener; 25 | @Override 26 | protected void onCreate(Bundle savedInstanceState) { 27 | super.onCreate(savedInstanceState); 28 | setContentView(R.layout.activity_login); 29 | 30 | mAuth = FirebaseAuth.getInstance(); 31 | firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() { 32 | @Override 33 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 34 | final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 35 | if (user !=null){ 36 | Intent intent = new Intent(LoginActivity.this, MainActivity.class); 37 | startActivity(intent); 38 | finish(); 39 | return; 40 | } 41 | } 42 | }; 43 | 44 | 45 | mLogin = (Button) findViewById(R.id.login); 46 | 47 | mEmail = (EditText) findViewById(R.id.email); 48 | mPassword = (EditText) findViewById(R.id.password); 49 | 50 | mLogin.setOnClickListener(new View.OnClickListener() { 51 | @Override 52 | public void onClick(View view) { 53 | final String email = mEmail.getText().toString(); 54 | final String password = mPassword.getText().toString(); 55 | mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(LoginActivity.this, new OnCompleteListener() { 56 | @Override 57 | public void onComplete(@NonNull Task task) { 58 | if(!task.isSuccessful()){ 59 | Toast.makeText(LoginActivity.this, "sign in error", Toast.LENGTH_SHORT).show(); 60 | } 61 | } 62 | }); 63 | } 64 | }); 65 | } 66 | 67 | @Override 68 | protected void onStart() { 69 | super.onStart(); 70 | mAuth.addAuthStateListener(firebaseAuthStateListener); 71 | } 72 | 73 | @Override 74 | protected void onStop() { 75 | super.onStop(); 76 | mAuth.removeAuthStateListener(firebaseAuthStateListener); 77 | } 78 | } -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.util.Log; 7 | import android.view.View; 8 | import android.widget.ListView; 9 | import android.widget.Toast; 10 | 11 | import com.google.firebase.auth.FirebaseAuth; 12 | import com.google.firebase.auth.FirebaseUser; 13 | import com.google.firebase.database.ChildEventListener; 14 | import com.google.firebase.database.DataSnapshot; 15 | import com.google.firebase.database.DatabaseError; 16 | import com.google.firebase.database.DatabaseReference; 17 | import com.google.firebase.database.FirebaseDatabase; 18 | import com.google.firebase.database.ValueEventListener; 19 | import com.lorentzos.flingswipe.SwipeFlingAdapterView; 20 | import com.simcoder.tinder.Cards.arrayAdapter; 21 | import com.simcoder.tinder.Cards.cards; 22 | import com.simcoder.tinder.Matches.MatchesActivity; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | 27 | public class MainActivity extends AppCompatActivity { 28 | private cards cards_data[]; 29 | private com.simcoder.tinder.Cards.arrayAdapter arrayAdapter; 30 | private int i; 31 | 32 | private FirebaseAuth mAuth; 33 | 34 | private String currentUId; 35 | 36 | private DatabaseReference usersDb; 37 | 38 | 39 | ListView listView; 40 | List rowItems; 41 | 42 | @Override 43 | protected void onCreate(Bundle savedInstanceState) { 44 | super.onCreate(savedInstanceState); 45 | setContentView(R.layout.activity_main); 46 | 47 | 48 | usersDb = FirebaseDatabase.getInstance().getReference().child("Users"); 49 | 50 | mAuth = FirebaseAuth.getInstance(); 51 | currentUId = mAuth.getCurrentUser().getUid(); 52 | 53 | checkUserSex(); 54 | 55 | rowItems = new ArrayList(); 56 | 57 | arrayAdapter = new arrayAdapter(this, R.layout.item, rowItems ); 58 | 59 | SwipeFlingAdapterView flingContainer = (SwipeFlingAdapterView) findViewById(R.id.frame); 60 | 61 | flingContainer.setAdapter(arrayAdapter); 62 | flingContainer.setFlingListener(new SwipeFlingAdapterView.onFlingListener() { 63 | @Override 64 | public void removeFirstObjectInAdapter() { 65 | Log.d("LIST", "removed object!"); 66 | rowItems.remove(0); 67 | arrayAdapter.notifyDataSetChanged(); 68 | } 69 | 70 | @Override 71 | public void onLeftCardExit(Object dataObject) { 72 | 73 | cards obj = (cards) dataObject; 74 | String userId = obj.getUserId(); 75 | usersDb.child(userId).child("connections").child("nope").child(currentUId).setValue(true); 76 | Toast.makeText(MainActivity.this, "Left", Toast.LENGTH_SHORT).show(); 77 | } 78 | 79 | @Override 80 | public void onRightCardExit(Object dataObject) { 81 | cards obj = (cards) dataObject; 82 | String userId = obj.getUserId(); 83 | usersDb.child(userId).child("connections").child("yeps").child(currentUId).setValue(true); 84 | isConnectionMatch(userId); 85 | Toast.makeText(MainActivity.this, "Right", Toast.LENGTH_SHORT).show(); 86 | } 87 | 88 | @Override 89 | public void onAdapterAboutToEmpty(int itemsInAdapter) { 90 | } 91 | 92 | @Override 93 | public void onScroll(float scrollProgressPercent) { 94 | } 95 | }); 96 | 97 | 98 | // Optionally add an OnItemClickListener 99 | flingContainer.setOnItemClickListener(new SwipeFlingAdapterView.OnItemClickListener() { 100 | @Override 101 | public void onItemClicked(int itemPosition, Object dataObject) { 102 | Toast.makeText(MainActivity.this, "Item Clicked", Toast.LENGTH_SHORT).show(); 103 | } 104 | }); 105 | 106 | } 107 | 108 | private void isConnectionMatch(String userId) { 109 | DatabaseReference currentUserConnectionsDb = usersDb.child(currentUId).child("connections").child("yeps").child(userId); 110 | currentUserConnectionsDb.addListenerForSingleValueEvent(new ValueEventListener() { 111 | @Override 112 | public void onDataChange(DataSnapshot dataSnapshot) { 113 | if (dataSnapshot.exists()){ 114 | Toast.makeText(MainActivity.this, "new Connection", Toast.LENGTH_LONG).show(); 115 | 116 | String key = FirebaseDatabase.getInstance().getReference().child("Chat").push().getKey(); 117 | 118 | usersDb.child(dataSnapshot.getKey()).child("connections").child("matches").child(currentUId).child("ChatId").setValue(key); 119 | usersDb.child(currentUId).child("connections").child("matches").child(dataSnapshot.getKey()).child("ChatId").setValue(key); 120 | } 121 | } 122 | 123 | @Override 124 | public void onCancelled(DatabaseError databaseError) { 125 | } 126 | }); 127 | } 128 | 129 | private String userSex; 130 | private String oppositeUserSex; 131 | public void checkUserSex(){ 132 | final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 133 | DatabaseReference userDb = usersDb.child(user.getUid()); 134 | userDb.addListenerForSingleValueEvent(new ValueEventListener() { 135 | @Override 136 | public void onDataChange(DataSnapshot dataSnapshot) { 137 | if (dataSnapshot.exists()){ 138 | if (dataSnapshot.child("sex").getValue() != null){ 139 | userSex = dataSnapshot.child("sex").getValue().toString(); 140 | switch (userSex){ 141 | case "Male": 142 | oppositeUserSex = "Female"; 143 | break; 144 | case "Female": 145 | oppositeUserSex = "Male"; 146 | break; 147 | } 148 | getOppositeSexUsers(); 149 | } 150 | } 151 | } 152 | @Override 153 | public void onCancelled(DatabaseError databaseError) { 154 | 155 | } 156 | }); 157 | } 158 | 159 | public void getOppositeSexUsers(){ 160 | usersDb.addChildEventListener(new ChildEventListener() { 161 | @Override 162 | public void onChildAdded(DataSnapshot dataSnapshot, String s) { 163 | if (dataSnapshot.child("sex").getValue() != null) { 164 | if (dataSnapshot.exists() && !dataSnapshot.child("connections").child("nope").hasChild(currentUId) && !dataSnapshot.child("connections").child("yeps").hasChild(currentUId) && dataSnapshot.child("sex").getValue().toString().equals(oppositeUserSex)) { 165 | String profileImageUrl = "default"; 166 | if (!dataSnapshot.child("profileImageUrl").getValue().equals("default")) { 167 | profileImageUrl = dataSnapshot.child("profileImageUrl").getValue().toString(); 168 | } 169 | cards item = new cards(dataSnapshot.getKey(), dataSnapshot.child("name").getValue().toString(), profileImageUrl); 170 | rowItems.add(item); 171 | arrayAdapter.notifyDataSetChanged(); 172 | } 173 | } 174 | } 175 | @Override 176 | public void onChildChanged(DataSnapshot dataSnapshot, String s) { 177 | } 178 | @Override 179 | public void onChildRemoved(DataSnapshot dataSnapshot) { 180 | } 181 | 182 | @Override 183 | public void onChildMoved(DataSnapshot dataSnapshot, String s) { 184 | } 185 | @Override 186 | public void onCancelled(DatabaseError databaseError) { 187 | } 188 | }); 189 | } 190 | 191 | 192 | public void logoutUser(View view) { 193 | mAuth.signOut(); 194 | Intent intent = new Intent(MainActivity.this, ChooseLoginRegistrationActivity.class); 195 | startActivity(intent); 196 | finish(); 197 | return; 198 | } 199 | 200 | public void goToSettings(View view) { 201 | Intent intent = new Intent(MainActivity.this, SettingsActivity.class); 202 | startActivity(intent); 203 | return; 204 | } 205 | 206 | public void goToMatches(View view) { 207 | Intent intent = new Intent(MainActivity.this, MatchesActivity.class); 208 | startActivity(intent); 209 | return; 210 | } 211 | } -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Matches/MatchesActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Matches; 2 | 3 | 4 | import android.os.Bundle; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.support.v7.widget.LinearLayoutManager; 7 | import android.support.v7.widget.RecyclerView; 8 | 9 | import com.google.firebase.auth.FirebaseAuth; 10 | import com.google.firebase.database.DataSnapshot; 11 | import com.google.firebase.database.DatabaseError; 12 | import com.google.firebase.database.DatabaseReference; 13 | import com.google.firebase.database.FirebaseDatabase; 14 | import com.google.firebase.database.ValueEventListener; 15 | import com.simcoder.tinder.R; 16 | 17 | import java.util.ArrayList; 18 | import java.util.List; 19 | 20 | public class MatchesActivity extends AppCompatActivity { 21 | private RecyclerView mRecyclerView; 22 | private RecyclerView.Adapter mMatchesAdapter; 23 | private RecyclerView.LayoutManager mMatchesLayoutManager; 24 | 25 | private String cusrrentUserID; 26 | 27 | @Override 28 | protected void onCreate(Bundle savedInstanceState) { 29 | super.onCreate(savedInstanceState); 30 | setContentView(R.layout.activity_matches); 31 | 32 | cusrrentUserID = FirebaseAuth.getInstance().getCurrentUser().getUid(); 33 | 34 | mRecyclerView = (RecyclerView) findViewById(R.id.recyclerView); 35 | mRecyclerView.setNestedScrollingEnabled(false); 36 | mRecyclerView.setHasFixedSize(true); 37 | mMatchesLayoutManager = new LinearLayoutManager(MatchesActivity.this); 38 | mRecyclerView.setLayoutManager(mMatchesLayoutManager); 39 | mMatchesAdapter = new MatchesAdapter(getDataSetMatches(), MatchesActivity.this); 40 | mRecyclerView.setAdapter(mMatchesAdapter); 41 | 42 | getUserMatchId(); 43 | 44 | 45 | 46 | 47 | 48 | } 49 | 50 | private void getUserMatchId() { 51 | 52 | DatabaseReference matchDb = FirebaseDatabase.getInstance().getReference().child("Users").child(cusrrentUserID).child("connections").child("matches"); 53 | matchDb.addListenerForSingleValueEvent(new ValueEventListener() { 54 | @Override 55 | public void onDataChange(DataSnapshot dataSnapshot) { 56 | if (dataSnapshot.exists()){ 57 | for(DataSnapshot match : dataSnapshot.getChildren()){ 58 | FetchMatchInformation(match.getKey()); 59 | } 60 | } 61 | } 62 | 63 | @Override 64 | public void onCancelled(DatabaseError databaseError) { 65 | 66 | } 67 | }); 68 | } 69 | 70 | private void FetchMatchInformation(String key) { 71 | DatabaseReference userDb = FirebaseDatabase.getInstance().getReference().child("Users").child(key); 72 | userDb.addListenerForSingleValueEvent(new ValueEventListener() { 73 | @Override 74 | public void onDataChange(DataSnapshot dataSnapshot) { 75 | if (dataSnapshot.exists()){ 76 | String userId = dataSnapshot.getKey(); 77 | String name = ""; 78 | String profileImageUrl = ""; 79 | if(dataSnapshot.child("name").getValue()!=null){ 80 | name = dataSnapshot.child("name").getValue().toString(); 81 | } 82 | if(dataSnapshot.child("profileImageUrl").getValue()!=null){ 83 | profileImageUrl = dataSnapshot.child("profileImageUrl").getValue().toString(); 84 | } 85 | 86 | 87 | MatchesObject obj = new MatchesObject(userId, name, profileImageUrl); 88 | resultsMatches.add(obj); 89 | mMatchesAdapter.notifyDataSetChanged(); 90 | } 91 | } 92 | 93 | @Override 94 | public void onCancelled(DatabaseError databaseError) { 95 | 96 | } 97 | }); 98 | 99 | } 100 | 101 | private ArrayList resultsMatches = new ArrayList(); 102 | private List getDataSetMatches() { 103 | return resultsMatches; 104 | } 105 | 106 | } 107 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Matches/MatchesAdapter.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Matches; 2 | 3 | import android.content.Context; 4 | import android.support.v7.widget.RecyclerView; 5 | import android.view.LayoutInflater; 6 | import android.view.View; 7 | import android.view.ViewGroup; 8 | 9 | import com.bumptech.glide.Glide; 10 | import com.simcoder.tinder.R; 11 | 12 | import java.util.List; 13 | 14 | /** 15 | * Created by manel on 10/31/2017. 16 | */ 17 | 18 | public class MatchesAdapter extends RecyclerView.Adapter{ 19 | private List matchesList; 20 | private Context context; 21 | 22 | 23 | public MatchesAdapter(List matchesList, Context context){ 24 | this.matchesList = matchesList; 25 | this.context = context; 26 | } 27 | 28 | @Override 29 | public MatchesViewHolders onCreateViewHolder(ViewGroup parent, int viewType) { 30 | 31 | View layoutView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_matches, null, false); 32 | RecyclerView.LayoutParams lp = new RecyclerView.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT); 33 | layoutView.setLayoutParams(lp); 34 | MatchesViewHolders rcv = new MatchesViewHolders(layoutView); 35 | 36 | return rcv; 37 | } 38 | 39 | @Override 40 | public void onBindViewHolder(MatchesViewHolders holder, int position) { 41 | holder.mMatchId.setText(matchesList.get(position).getUserId()); 42 | holder.mMatchName.setText(matchesList.get(position).getName()); 43 | if(!matchesList.get(position).getProfileImageUrl().equals("default")){ 44 | Glide.with(context).load(matchesList.get(position).getProfileImageUrl()).into(holder.mMatchImage); 45 | } 46 | } 47 | 48 | @Override 49 | public int getItemCount() { 50 | return this.matchesList.size(); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Matches/MatchesObject.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Matches; 2 | 3 | /** 4 | * Created by manel on 10/31/2017. 5 | */ 6 | 7 | public class MatchesObject { 8 | private String userId; 9 | private String name; 10 | private String profileImageUrl; 11 | public MatchesObject (String userId, String name, String profileImageUrl){ 12 | this.userId = userId; 13 | this.name = name; 14 | this.profileImageUrl = profileImageUrl; 15 | } 16 | 17 | public String getUserId(){ 18 | return userId; 19 | } 20 | public void setUserID(String userID){ 21 | this.userId = userId; 22 | } 23 | 24 | public String getName(){ 25 | return name; 26 | } 27 | public void setName(String name){ 28 | this.name = name; 29 | } 30 | 31 | public String getProfileImageUrl(){ 32 | return profileImageUrl; 33 | } 34 | public void setProfileImageUrl(String profileImageUrl){ 35 | this.profileImageUrl = profileImageUrl; 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/Matches/MatchesViewHolders.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder.Matches; 2 | 3 | import android.content.Intent; 4 | import android.os.Bundle; 5 | import android.support.v7.widget.RecyclerView; 6 | import android.view.View; 7 | import android.widget.ImageView; 8 | import android.widget.TextView; 9 | 10 | import com.simcoder.tinder.Chat.ChatActivity; 11 | import com.simcoder.tinder.R; 12 | 13 | /** 14 | * Created by manel on 10/31/2017. 15 | */ 16 | 17 | public class MatchesViewHolders extends RecyclerView.ViewHolder implements View.OnClickListener{ 18 | public TextView mMatchId, mMatchName; 19 | public ImageView mMatchImage; 20 | public MatchesViewHolders(View itemView) { 21 | super(itemView); 22 | itemView.setOnClickListener(this); 23 | 24 | mMatchId = (TextView) itemView.findViewById(R.id.Matchid); 25 | mMatchName = (TextView) itemView.findViewById(R.id.MatchName); 26 | 27 | mMatchImage = (ImageView) itemView.findViewById(R.id.MatchImage); 28 | } 29 | 30 | @Override 31 | public void onClick(View view) { 32 | Intent intent = new Intent(view.getContext(), ChatActivity.class); 33 | Bundle b = new Bundle(); 34 | b.putString("matchId", mMatchId.getText().toString()); 35 | intent.putExtras(b); 36 | view.getContext().startActivity(intent); 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/RegistrationActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder; 2 | 3 | import android.content.Intent; 4 | import android.support.annotation.NonNull; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.view.View; 8 | import android.widget.Button; 9 | import android.widget.EditText; 10 | import android.widget.RadioButton; 11 | import android.widget.RadioGroup; 12 | import android.widget.Toast; 13 | 14 | import com.google.android.gms.tasks.OnCompleteListener; 15 | import com.google.android.gms.tasks.Task; 16 | import com.google.firebase.auth.AuthResult; 17 | import com.google.firebase.auth.FirebaseAuth; 18 | import com.google.firebase.auth.FirebaseUser; 19 | import com.google.firebase.database.DatabaseReference; 20 | import com.google.firebase.database.FirebaseDatabase; 21 | 22 | import java.util.HashMap; 23 | import java.util.Map; 24 | 25 | public class RegistrationActivity extends AppCompatActivity { 26 | 27 | private Button mRegister; 28 | private EditText mEmail, mPassword, mName; 29 | 30 | private RadioGroup mRadioGroup; 31 | 32 | private FirebaseAuth mAuth; 33 | private FirebaseAuth.AuthStateListener firebaseAuthStateListener; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_registration); 39 | 40 | mAuth = FirebaseAuth.getInstance(); 41 | firebaseAuthStateListener = new FirebaseAuth.AuthStateListener() { 42 | @Override 43 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 44 | final FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 45 | if (user !=null){ 46 | Intent intent = new Intent(RegistrationActivity.this, MainActivity.class); 47 | startActivity(intent); 48 | finish(); 49 | return; 50 | } 51 | } 52 | }; 53 | 54 | 55 | mRegister = (Button) findViewById(R.id.register); 56 | 57 | mEmail = (EditText) findViewById(R.id.email); 58 | mPassword = (EditText) findViewById(R.id.password); 59 | mName = (EditText) findViewById(R.id.name); 60 | 61 | mRadioGroup = (RadioGroup) findViewById(R.id.radioGroup); 62 | 63 | mRegister.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View view) { 66 | int selectId = mRadioGroup.getCheckedRadioButtonId(); 67 | 68 | final RadioButton radioButton = (RadioButton) findViewById(selectId); 69 | 70 | if(radioButton.getText() == null){ 71 | return; 72 | } 73 | 74 | final String email = mEmail.getText().toString(); 75 | final String password = mPassword.getText().toString(); 76 | final String name = mName.getText().toString(); 77 | mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(RegistrationActivity.this, new OnCompleteListener() { 78 | @Override 79 | public void onComplete(@NonNull Task task) { 80 | if(!task.isSuccessful()){ 81 | Toast.makeText(RegistrationActivity.this, "sign up error", Toast.LENGTH_SHORT).show(); 82 | }else{ 83 | String userId = mAuth.getCurrentUser().getUid(); 84 | DatabaseReference currentUserDb = FirebaseDatabase.getInstance().getReference().child("Users").child(userId); 85 | Map userInfo = new HashMap<>(); 86 | userInfo.put("name", name); 87 | userInfo.put("sex", radioButton.getText().toString()); 88 | userInfo.put("profileImageUrl", "default"); 89 | currentUserDb.updateChildren(userInfo); 90 | } 91 | } 92 | }); 93 | } 94 | }); 95 | } 96 | 97 | @Override 98 | protected void onStart() { 99 | super.onStart(); 100 | mAuth.addAuthStateListener(firebaseAuthStateListener); 101 | } 102 | 103 | @Override 104 | protected void onStop() { 105 | super.onStop(); 106 | mAuth.removeAuthStateListener(firebaseAuthStateListener); 107 | } 108 | } 109 | -------------------------------------------------------------------------------- /app/src/main/java/com/simcoder/tinder/SettingsActivity.java: -------------------------------------------------------------------------------- 1 | package com.simcoder.tinder; 2 | 3 | import android.app.Activity; 4 | import android.content.Intent; 5 | import android.graphics.Bitmap; 6 | import android.net.Uri; 7 | import android.provider.MediaStore; 8 | import android.support.annotation.NonNull; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.os.Bundle; 11 | import android.view.View; 12 | import android.widget.Button; 13 | import android.widget.EditText; 14 | import android.widget.ImageView; 15 | 16 | import com.bumptech.glide.Glide; 17 | import com.google.android.gms.tasks.OnFailureListener; 18 | import com.google.android.gms.tasks.OnSuccessListener; 19 | import com.google.firebase.auth.FirebaseAuth; 20 | import com.google.firebase.auth.FirebaseUser; 21 | import com.google.firebase.database.ChildEventListener; 22 | import com.google.firebase.database.DataSnapshot; 23 | import com.google.firebase.database.DatabaseError; 24 | import com.google.firebase.database.DatabaseReference; 25 | import com.google.firebase.database.FirebaseDatabase; 26 | import com.google.firebase.database.ValueEventListener; 27 | import com.google.firebase.storage.FirebaseStorage; 28 | import com.google.firebase.storage.StorageReference; 29 | import com.google.firebase.storage.UploadTask; 30 | 31 | import java.io.ByteArrayOutputStream; 32 | import java.io.IOException; 33 | import java.util.HashMap; 34 | import java.util.Map; 35 | 36 | public class SettingsActivity extends AppCompatActivity { 37 | 38 | private EditText mNameField, mPhoneField; 39 | 40 | private Button mBack, mConfirm; 41 | 42 | private ImageView mProfileImage; 43 | 44 | private FirebaseAuth mAuth; 45 | private DatabaseReference mUserDatabase; 46 | 47 | private String userId, name, phone, profileImageUrl, userSex; 48 | 49 | private Uri resultUri; 50 | 51 | @Override 52 | protected void onCreate(Bundle savedInstanceState) { 53 | super.onCreate(savedInstanceState); 54 | setContentView(R.layout.activity_settings); 55 | 56 | mNameField = (EditText) findViewById(R.id.name); 57 | mPhoneField = (EditText) findViewById(R.id.phone); 58 | 59 | mProfileImage = (ImageView) findViewById(R.id.profileImage); 60 | 61 | mBack = (Button) findViewById(R.id.back); 62 | mConfirm = (Button) findViewById(R.id.confirm); 63 | 64 | mAuth = FirebaseAuth.getInstance(); 65 | userId = mAuth.getCurrentUser().getUid(); 66 | 67 | mUserDatabase = FirebaseDatabase.getInstance().getReference().child("Users").child(userId); 68 | 69 | getUserInfo(); 70 | 71 | mProfileImage.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View view) { 74 | Intent intent = new Intent(Intent.ACTION_PICK); 75 | intent.setType("image/*"); 76 | startActivityForResult(intent, 1); 77 | } 78 | }); 79 | mConfirm.setOnClickListener(new View.OnClickListener() { 80 | @Override 81 | public void onClick(View view) { 82 | saveUserInformation(); 83 | } 84 | }); 85 | mBack.setOnClickListener(new View.OnClickListener() { 86 | @Override 87 | public void onClick(View view) { 88 | finish(); 89 | return; 90 | } 91 | }); 92 | } 93 | 94 | 95 | private void getUserInfo() { 96 | mUserDatabase.addListenerForSingleValueEvent(new ValueEventListener() { 97 | @Override 98 | public void onDataChange(DataSnapshot dataSnapshot) { 99 | if(dataSnapshot.exists() && dataSnapshot.getChildrenCount()>0){ 100 | Map map = (Map) dataSnapshot.getValue(); 101 | if(map.get("name")!=null){ 102 | name = map.get("name").toString(); 103 | mNameField.setText(name); 104 | } 105 | if(map.get("phone")!=null){ 106 | phone = map.get("phone").toString(); 107 | mPhoneField.setText(phone); 108 | } 109 | if(map.get("sex")!=null){ 110 | userSex = map.get("sex").toString(); 111 | } 112 | Glide.clear(mProfileImage); 113 | if(map.get("profileImageUrl")!=null){ 114 | profileImageUrl = map.get("profileImageUrl").toString(); 115 | switch(profileImageUrl){ 116 | case "default": 117 | Glide.with(getApplication()).load(R.mipmap.ic_launcher).into(mProfileImage); 118 | break; 119 | default: 120 | Glide.with(getApplication()).load(profileImageUrl).into(mProfileImage); 121 | break; 122 | } 123 | } 124 | } 125 | } 126 | 127 | @Override 128 | public void onCancelled(DatabaseError databaseError) { 129 | 130 | } 131 | }); 132 | 133 | } 134 | 135 | private void saveUserInformation() { 136 | name = mNameField.getText().toString(); 137 | phone = mPhoneField.getText().toString(); 138 | 139 | Map userInfo = new HashMap(); 140 | userInfo.put("name", name); 141 | userInfo.put("phone", phone); 142 | mUserDatabase.updateChildren(userInfo); 143 | if(resultUri != null){ 144 | StorageReference filepath = FirebaseStorage.getInstance().getReference().child("profileImages").child(userId); 145 | Bitmap bitmap = null; 146 | 147 | try { 148 | bitmap = MediaStore.Images.Media.getBitmap(getApplication().getContentResolver(), resultUri); 149 | } catch (IOException e) { 150 | e.printStackTrace(); 151 | } 152 | 153 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 154 | bitmap.compress(Bitmap.CompressFormat.JPEG, 20, baos); 155 | byte[] data = baos.toByteArray(); 156 | UploadTask uploadTask = filepath.putBytes(data); 157 | uploadTask.addOnFailureListener(new OnFailureListener() { 158 | @Override 159 | public void onFailure(@NonNull Exception e) { 160 | finish(); 161 | } 162 | }); 163 | uploadTask.addOnSuccessListener(new OnSuccessListener() { 164 | @Override 165 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 166 | Uri downloadUrl = taskSnapshot.getDownloadUrl(); 167 | 168 | Map userInfo = new HashMap(); 169 | userInfo.put("profileImageUrl", downloadUrl.toString()); 170 | mUserDatabase.updateChildren(userInfo); 171 | 172 | finish(); 173 | return; 174 | } 175 | }); 176 | }else{ 177 | finish(); 178 | } 179 | } 180 | 181 | @Override 182 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 183 | super.onActivityResult(requestCode, resultCode, data); 184 | if(requestCode == 1 && resultCode == Activity.RESULT_OK){ 185 | final Uri imageUri = data.getData(); 186 | resultUri = imageUri; 187 | mProfileImage.setImageURI(resultUri); 188 | } 189 | } 190 | } 191 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_chat.xml: -------------------------------------------------------------------------------- 1 | 2 | 9 | 13 | 18 | 19 | 20 | 26 | 33 |