├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml ├── runConfigurations.xml └── vcs.xml ├── LICENSE ├── README.md ├── Screenshots ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png └── 6.png ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── vaibhav │ │ └── simpleblogapp │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── vaibhav │ │ │ └── simpleblogapp │ │ │ ├── FCMthings │ │ │ ├── MyfirebaseInstanceServices.java │ │ │ └── SharedPrefManager.java │ │ │ ├── Global.java │ │ │ ├── Models │ │ │ ├── Blog.java │ │ │ ├── ChatMessage.java │ │ │ └── SimpleBlog.java │ │ │ ├── ProfileExists.java │ │ │ └── ShowActivity │ │ │ ├── ChatActivity.java │ │ │ ├── LoginActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── PostActivity.java │ │ │ ├── ProfileActivity.java │ │ │ ├── RegisterActivity.java │ │ │ └── SetupActivity.java │ └── res │ │ ├── drawable │ │ ├── ic_broken_image.xml │ │ ├── ic_facebook.xml │ │ ├── ic_google.xml │ │ ├── ic_no_heart_gray.xml │ │ ├── ic_upload_pic.xml │ │ ├── ic_user_white.xml │ │ ├── ic_yes_heart_colored.xml │ │ ├── input_outline.xml │ │ ├── input_outline2.xml │ │ ├── input_outline3.xml │ │ └── send.xml │ │ ├── layout │ │ ├── activity_chat.xml │ │ ├── activity_login.xml │ │ ├── activity_main.xml │ │ ├── activity_post.xml │ │ ├── activity_profile.xml │ │ ├── activity_profile_exists.xml │ │ ├── activity_register.xml │ │ ├── activity_setup.xml │ │ ├── blog_row.xml │ │ └── message_row.xml │ │ ├── menu │ │ └── main_menu.xml │ │ ├── mipmap-hdpi │ │ ├── ic_add_white_24dp.png │ │ ├── ic_launcher.png │ │ └── ic_person_black_24dp.png │ │ ├── mipmap-mdpi │ │ ├── ic_add_white_24dp.png │ │ ├── ic_launcher.png │ │ └── ic_person_black_24dp.png │ │ ├── mipmap-xhdpi │ │ ├── ic_add_white_24dp.png │ │ ├── ic_launcher.png │ │ └── ic_person_black_24dp.png │ │ ├── mipmap-xxhdpi │ │ ├── ic_add_white_24dp.png │ │ ├── ic_launcher.png │ │ └── ic_person_black_24dp.png │ │ ├── mipmap-xxxhdpi │ │ ├── ic_add_white_24dp.png │ │ ├── ic_launcher.png │ │ └── ic_person_black_24dp.png │ │ ├── values-w820dp │ │ └── dimens.xml │ │ └── values │ │ ├── colors.xml │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── vaibhav │ └── simpleblogapp │ └── 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 | -------------------------------------------------------------------------------- /.idea/vcs.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 VAIBHAV MINIYAR 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 | # Simple-Blog-App 2 | 3 | #### Project for Google Firebase-Hackathon-Pune-India 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | -------------------------------------------------------------------------------- /Screenshots/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-minion/Simple-Blog-App/4b29c1aa486f14de663c6d03e6aa8e3a8883923e/Screenshots/1.png -------------------------------------------------------------------------------- /Screenshots/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-minion/Simple-Blog-App/4b29c1aa486f14de663c6d03e6aa8e3a8883923e/Screenshots/2.png -------------------------------------------------------------------------------- /Screenshots/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-minion/Simple-Blog-App/4b29c1aa486f14de663c6d03e6aa8e3a8883923e/Screenshots/3.png -------------------------------------------------------------------------------- /Screenshots/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-minion/Simple-Blog-App/4b29c1aa486f14de663c6d03e6aa8e3a8883923e/Screenshots/4.png -------------------------------------------------------------------------------- /Screenshots/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-minion/Simple-Blog-App/4b29c1aa486f14de663c6d03e6aa8e3a8883923e/Screenshots/5.png -------------------------------------------------------------------------------- /Screenshots/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/im-minion/Simple-Blog-App/4b29c1aa486f14de663c6d03e6aa8e3a8883923e/Screenshots/6.png -------------------------------------------------------------------------------- /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 | packagingOptions { 7 | exclude 'META-INF/DEPENDENCIES.txt' 8 | exclude 'META-INF/LICENSE.txt' 9 | exclude 'META-INF/NOTICE.txt' 10 | exclude 'META-INF/NOTICE' 11 | exclude 'META-INF/LICENSE' 12 | exclude 'META-INF/DEPENDENCIES' 13 | exclude 'META-INF/notice.txt' 14 | exclude 'META-INF/license.txt' 15 | exclude 'META-INF/dependencies.txt' 16 | exclude 'META-INF/LGPL2.1' 17 | } 18 | defaultConfig { 19 | applicationId "com.example.vaibhav.simpleblogapp" 20 | minSdkVersion 16 21 | targetSdkVersion 25 22 | multiDexEnabled true 23 | versionCode 1 24 | versionName "1.0" 25 | testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner" 26 | } 27 | buildTypes { 28 | release { 29 | minifyEnabled true 30 | shrinkResources true 31 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 32 | } 33 | } 34 | } 35 | 36 | dependencies { 37 | compile fileTree(dir: 'libs', include: ['*.jar']) 38 | androidTestCompile('com.android.support.test.espresso:espresso-core:2.2.2', { 39 | exclude group: 'com.android.support', module: 'support-annotations' 40 | }) 41 | 42 | // Include all the Twitter APIs 43 | // (Optional) Monetize using mopub 44 | 45 | //noinspection GradleCompatible 46 | compile 'com.android.support:appcompat-v7:26.1.0' 47 | compile 'com.android.support:recyclerview-v7:26.1.0' 48 | compile 'com.android.support:cardview-v7:26.1.0' 49 | compile 'de.hdodenhof:circleimageview:2.1.0' 50 | compile 'com.theartofdev.edmodo:android-image-cropper:2.3.+' 51 | compile 'com.android.support.test.espresso:espresso-core:2.2.2' 52 | compile 'com.android.support:design:26.1.0' 53 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 54 | compile 'com.android.support:multidex:1.0.0' 55 | 56 | compile 'com.squareup.picasso:picasso:2.5.2' 57 | implementation 'com.squareup.okhttp3:okhttp:3.9.1' 58 | compile 'com.jakewharton.picasso:picasso2-okhttp3-downloader:1.1.0' 59 | 60 | compile 'com.twitter.sdk.android:twitter:3.0.0' 61 | compile 'com.twitter.sdk.android:tweet-ui:3.0.0' 62 | compile 'com.twitter.sdk.android:tweet-composer:3.0.0' 63 | compile 'com.facebook.android:facebook-android-sdk:[4,5)' 64 | 65 | compile 'com.google.firebase:firebase-core:10.0.1' 66 | compile 'com.google.android.gms:play-services-auth:10.0.1' 67 | compile 'com.google.firebase:firebase-auth:10.0.1' 68 | compile 'com.google.firebase:firebase-database:10.0.1' 69 | compile 'com.google.firebase:firebase-storage:10.0.1' 70 | compile 'com.google.firebase:firebase-messaging:10.0.1' 71 | compile 'com.firebaseui:firebase-ui-database:0.4.0' 72 | compile 'com.google.firebase:firebase-ads:10.0.1' 73 | testCompile 'junit:junit:4.12' 74 | } 75 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "768693657101", 4 | "firebase_url": "https://simpleblogapp-da4a5.firebaseio.com", 5 | "project_id": "simpleblogapp-da4a5", 6 | "storage_bucket": "simpleblogapp-da4a5.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:768693657101:android:dd9aaf7e887d0de0", 12 | "android_client_info": { 13 | "package_name": "com.example.vaibhav.simpleblogapp" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "768693657101-1fr984hncd2bd208mm2hp436qs9hrmt9.apps.googleusercontent.com", 19 | "client_type": 1, 20 | "android_info": { 21 | "package_name": "com.example.vaibhav.simpleblogapp", 22 | "certificate_hash": "7b0a8d5f29fcfd508a04c4c8c2b02ee331e4feff" 23 | } 24 | }, 25 | { 26 | "client_id": "768693657101-9k9abk486eud1das9f828e4p7l59mohc.apps.googleusercontent.com", 27 | "client_type": 1, 28 | "android_info": { 29 | "package_name": "com.example.vaibhav.simpleblogapp", 30 | "certificate_hash": "22f472af043be36d6912d2d8e2ceaf2b7382ce0a" 31 | } 32 | }, 33 | { 34 | "client_id": "768693657101-jmo5scebk7tkfisounqnou97scvgceot.apps.googleusercontent.com", 35 | "client_type": 1, 36 | "android_info": { 37 | "package_name": "com.example.vaibhav.simpleblogapp", 38 | "certificate_hash": "f1754f1da51e576c0f5118878413261a5f6dab84" 39 | } 40 | }, 41 | { 42 | "client_id": "768693657101-outj3k296vkfudi7tfsdqhe10ki53tue.apps.googleusercontent.com", 43 | "client_type": 3 44 | } 45 | ], 46 | "api_key": [ 47 | { 48 | "current_key": "AIzaSyBcrb_F_wQ2Zqnh_6wTRJ0d48IawLZ2UJg" 49 | } 50 | ], 51 | "services": { 52 | "analytics_service": { 53 | "status": 1 54 | }, 55 | "appinvite_service": { 56 | "status": 2, 57 | "other_platform_oauth_client": [ 58 | { 59 | "client_id": "768693657101-outj3k296vkfudi7tfsdqhe10ki53tue.apps.googleusercontent.com", 60 | "client_type": 3 61 | } 62 | ] 63 | }, 64 | "ads_service": { 65 | "status": 2 66 | } 67 | } 68 | } 69 | ], 70 | "configuration_version": "1" 71 | } -------------------------------------------------------------------------------- /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 /home/vaibhav/Android/Sdk/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 | -------------------------------------------------------------------------------- /app/src/androidTest/java/com/example/vaibhav/simpleblogapp/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp; 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.example.vaibhav.simpleblogapp", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 16 | 19 | 20 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/FCMthings/MyfirebaseInstanceServices.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.FCMthings; 2 | 3 | import android.content.Intent; 4 | import android.util.Log; 5 | 6 | import com.example.vaibhav.simpleblogapp.FCMthings.SharedPrefManager; 7 | import com.google.firebase.iid.FirebaseInstanceId; 8 | import com.google.firebase.iid.FirebaseInstanceIdService; 9 | 10 | /** 11 | * Created by vaibhav on 23/6/17. 12 | */ 13 | 14 | public class MyfirebaseInstanceServices extends FirebaseInstanceIdService { 15 | 16 | public static final String TOKEN_BROADCAST = "myfctokenBroadcast"; 17 | 18 | @Override 19 | public void onTokenRefresh() { 20 | // Get updated InstanceID token. 21 | String refreshedToken = FirebaseInstanceId.getInstance().getToken(); 22 | Log.d("FirabaseTOKEN", " " + refreshedToken); 23 | 24 | storeToken(refreshedToken); 25 | getApplicationContext().sendBroadcast(new Intent(TOKEN_BROADCAST)); 26 | } 27 | 28 | private void storeToken(String token) { 29 | SharedPrefManager.getInstance(getApplicationContext()).storeToken(token); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/FCMthings/SharedPrefManager.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.FCMthings; 2 | 3 | import android.content.Context; 4 | import android.content.SharedPreferences; 5 | 6 | /** 7 | * Created by vaibhav on 23/6/17. 8 | */ 9 | 10 | public class SharedPrefManager { 11 | 12 | private static final String SHARED_PREF_NAME = "FCMdemoSharedPref"; 13 | private static final String KEY_ACCESS_TOKEN = "token"; 14 | 15 | private Context mCtx; 16 | private static SharedPrefManager mInstance; 17 | 18 | private SharedPrefManager(Context context) { 19 | mCtx = context; 20 | } 21 | 22 | public static synchronized SharedPrefManager getInstance(Context context) { 23 | if (mInstance == null) { 24 | mInstance = new SharedPrefManager(context); 25 | } 26 | return mInstance; 27 | } 28 | 29 | public boolean storeToken(String token) { 30 | SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); 31 | SharedPreferences.Editor editor = sharedPreferences.edit(); 32 | editor.putString(KEY_ACCESS_TOKEN, token); 33 | editor.apply(); 34 | return true; 35 | } 36 | 37 | public String getToken() { 38 | SharedPreferences sharedPreferences = mCtx.getSharedPreferences(SHARED_PREF_NAME, Context.MODE_PRIVATE); 39 | return sharedPreferences.getString(KEY_ACCESS_TOKEN, null); 40 | } 41 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/Global.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp; 2 | 3 | /** 4 | * Created by vaibhav on 12/24/17. 5 | */ 6 | 7 | import android.app.Application; 8 | 9 | import com.jakewharton.picasso.OkHttp3Downloader; 10 | import com.squareup.picasso.Picasso; 11 | 12 | public class Global extends Application { 13 | @Override 14 | public void onCreate() { 15 | super.onCreate(); 16 | 17 | Picasso.Builder builder = new Picasso.Builder(this); 18 | builder.downloader(new OkHttp3Downloader(this,Integer.MAX_VALUE)); 19 | Picasso built = builder.build(); 20 | built.setIndicatorsEnabled(true); 21 | built.setLoggingEnabled(true); 22 | Picasso.setSingletonInstance(built); 23 | 24 | } 25 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/Models/Blog.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.Models; 2 | 3 | /** 4 | * Created by vaibhav on 7/1/17. 5 | */ 6 | 7 | public class Blog { 8 | private String Title; 9 | private String DESCRIPTION; 10 | private String IMAGE; 11 | private String username; 12 | 13 | public Blog(String title, String DESCRIPTION, String IMAGE, String username) { 14 | this.Title = title; 15 | this.DESCRIPTION = DESCRIPTION; 16 | this.IMAGE = IMAGE; 17 | this.username = username; 18 | } 19 | 20 | public Blog() { 21 | 22 | } 23 | 24 | public String getTitle() { 25 | return Title; 26 | } 27 | 28 | public void setTitle(String title) { 29 | Title = title; 30 | } 31 | 32 | public String getDESCRIPTION() { 33 | return DESCRIPTION; 34 | } 35 | 36 | public void setDESCRIPTION(String DESCRIPTION) { 37 | this.DESCRIPTION = DESCRIPTION; 38 | } 39 | 40 | public String getIMAGE() { 41 | return IMAGE; 42 | } 43 | 44 | public void setIMAGE(String IMAGE) { 45 | this.IMAGE = IMAGE; 46 | } 47 | 48 | public String getUsername() { 49 | return username; 50 | } 51 | 52 | public void setUsername(String username) { 53 | this.username = username; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/Models/ChatMessage.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.Models; 2 | 3 | import java.util.Date; 4 | 5 | public class ChatMessage { 6 | 7 | private String messageText; 8 | private String messageUser; 9 | private String profileUrl; 10 | private long messageTime; 11 | 12 | public ChatMessage() { 13 | 14 | } 15 | 16 | public ChatMessage(String messageText, String messageUser, String profileUrl) { 17 | this.messageText = messageText; 18 | this.profileUrl = profileUrl; 19 | this.messageUser = messageUser; 20 | // Initialize to current time 21 | messageTime = new Date().getTime(); 22 | } 23 | 24 | public String getProfileUrl() { 25 | return profileUrl; 26 | } 27 | 28 | public void setProfileUrl(String profileUrl) { 29 | this.profileUrl = profileUrl; 30 | } 31 | 32 | public String getMessageText() { 33 | return messageText; 34 | } 35 | 36 | public void setMessageText(String messageText) { 37 | this.messageText = messageText; 38 | } 39 | 40 | public String getMessageUser() { 41 | return messageUser; 42 | } 43 | 44 | public void setMessageUser(String messageUser) { 45 | this.messageUser = messageUser; 46 | } 47 | 48 | public long getMessageTime() { 49 | return messageTime; 50 | } 51 | 52 | public void setMessageTime(long messageTime) { 53 | this.messageTime = messageTime; 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/Models/SimpleBlog.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.Models; 2 | 3 | import android.app.Application; 4 | 5 | import com.google.firebase.FirebaseApp; 6 | import com.google.firebase.database.FirebaseDatabase; 7 | import com.squareup.picasso.OkHttpDownloader; 8 | import com.squareup.picasso.Picasso; 9 | 10 | /** 11 | * Created by vaibhav on 8/1/17. 12 | */ 13 | 14 | public class SimpleBlog extends Application { 15 | 16 | @Override 17 | public void onCreate() { 18 | super.onCreate(); 19 | 20 | if (!FirebaseApp.getApps(this).isEmpty()) { 21 | FirebaseDatabase.getInstance().setPersistenceEnabled(true);//offlinecapability 22 | } 23 | Picasso.Builder builder = new Picasso.Builder(this); 24 | builder.downloader(new OkHttpDownloader(this, Integer.MAX_VALUE)); 25 | Picasso built = builder.build(); 26 | built.setIndicatorsEnabled(false); 27 | built.setLoggingEnabled(true); 28 | Picasso.setSingletonInstance(built); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ProfileExists.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp; 2 | 3 | import android.content.Intent; 4 | import android.support.v7.app.AppCompatActivity; 5 | import android.os.Bundle; 6 | import android.widget.ImageView; 7 | import android.widget.TextView; 8 | 9 | import com.example.vaibhav.simpleblogapp.ShowActivity.MainActivity; 10 | import com.google.firebase.auth.FirebaseAuth; 11 | import com.squareup.picasso.Picasso; 12 | 13 | public class ProfileExists extends AppCompatActivity { 14 | 15 | @Override 16 | protected void onCreate(Bundle savedInstanceState) { 17 | super.onCreate(savedInstanceState); 18 | setContentView(R.layout.activity_profile_exists); 19 | TextView tv = (TextView) findViewById(R.id.textView); 20 | ImageView iv = (ImageView) findViewById(R.id.imageView); 21 | String uname = FirebaseAuth.getInstance().getCurrentUser().getDisplayName(); 22 | tv.setText("Logged in as " + uname); 23 | if (FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl() == null) { 24 | Picasso.with(ProfileExists.this).load("http://www.gpp-kavkaz.ru/images/no_avatar.jpg?crc=238954602").into(iv); 25 | } else { 26 | Picasso.with(ProfileExists.this).load(FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl()).into(iv); 27 | } 28 | } 29 | 30 | @Override 31 | public void onBackPressed() { 32 | super.onBackPressed(); 33 | startActivity(new Intent(ProfileExists.this, MainActivity.class)); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/ChatActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.content.SharedPreferences; 6 | import android.os.Build; 7 | import android.os.Bundle; 8 | import android.preference.PreferenceManager; 9 | import android.support.annotation.RequiresApi; 10 | import android.support.design.widget.FloatingActionButton; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.support.v7.widget.LinearLayoutManager; 13 | import android.support.v7.widget.RecyclerView; 14 | import android.text.format.DateFormat; 15 | import android.util.Log; 16 | import android.view.View; 17 | import android.widget.EditText; 18 | import android.widget.ListView; 19 | import android.widget.TextView; 20 | import android.widget.Toast; 21 | 22 | import com.example.vaibhav.simpleblogapp.Models.ChatMessage; 23 | import com.example.vaibhav.simpleblogapp.R; 24 | 25 | import com.firebase.ui.database.FirebaseListAdapter; 26 | import com.firebase.ui.database.FirebaseRecyclerAdapter; 27 | import com.google.firebase.auth.FirebaseAuth; 28 | import com.google.firebase.database.DataSnapshot; 29 | import com.google.firebase.database.DatabaseError; 30 | import com.google.firebase.database.DatabaseReference; 31 | import com.google.firebase.database.FirebaseDatabase; 32 | import com.google.firebase.database.ValueEventListener; 33 | import com.squareup.picasso.Picasso; 34 | 35 | import java.util.Arrays; 36 | import java.util.Objects; 37 | 38 | import de.hdodenhof.circleimageview.CircleImageView; 39 | 40 | public class ChatActivity extends AppCompatActivity { 41 | 42 | EditText input; 43 | RecyclerView chatRecView; 44 | DatabaseReference dbChatRef; 45 | 46 | @Override 47 | protected void onCreate(Bundle savedInstanceState) { 48 | super.onCreate(savedInstanceState); 49 | setContentView(R.layout.activity_chat); 50 | SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getApplicationContext()); 51 | FloatingActionButton fab = findViewById(R.id.fab); 52 | 53 | chatRecView = findViewById(R.id.list_of_messages); 54 | dbChatRef = FirebaseDatabase.getInstance().getReference("/chat"); 55 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 56 | layoutManager.setStackFromEnd(false); 57 | chatRecView.setHasFixedSize(true); 58 | chatRecView.setLayoutManager(layoutManager); 59 | 60 | if (FirebaseAuth.getInstance().getCurrentUser() == null) { 61 | startActivity(new Intent(ChatActivity.this, LoginActivity.class)); 62 | } 63 | fab.setOnClickListener(new View.OnClickListener() { 64 | @Override 65 | public void onClick(View v) { 66 | fabClick(); 67 | } 68 | }); 69 | } 70 | 71 | private void fabClick() { 72 | if (FirebaseAuth.getInstance().getCurrentUser() == null) { 73 | Toast.makeText(getApplicationContext(), "Not logged in!", Toast.LENGTH_SHORT).show(); 74 | onStart(); 75 | } else { 76 | input = findViewById(R.id.input); 77 | // Read the input field and push a new instance 78 | // of ChatMessage to the Firebase database 79 | String message = input.getText().toString(); 80 | if (message.isEmpty()) { 81 | input.setError("You can't post an empty Message. !!"); 82 | } else { 83 | if (FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl() == null) { 84 | FirebaseDatabase.getInstance() 85 | .getReference() 86 | .child("chat") 87 | .push() 88 | .setValue(new ChatMessage( 89 | input.getText().toString(), 90 | FirebaseAuth.getInstance() 91 | .getCurrentUser() 92 | .getEmail(), 93 | "null") 94 | ); 95 | Log.d("abcdabcd", String.valueOf(FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl())); 96 | // Clear the input 97 | } else { 98 | FirebaseDatabase.getInstance() 99 | .getReference() 100 | .child("chat") 101 | .push() 102 | .setValue(new ChatMessage(input.getText().toString(), 103 | FirebaseAuth.getInstance() 104 | .getCurrentUser() 105 | .getEmail(), 106 | FirebaseAuth.getInstance().getCurrentUser().getPhotoUrl().toString()) 107 | ); 108 | } 109 | } 110 | input.setText(""); 111 | } 112 | } 113 | 114 | @Override 115 | public void onStart() { 116 | super.onStart(); 117 | final FirebaseRecyclerAdapter firebaseRecyclerAdapter = 118 | new FirebaseRecyclerAdapter( 119 | ChatMessage.class, 120 | R.layout.message_row, 121 | ChatViewHolder.class, 122 | dbChatRef) { 123 | @Override 124 | protected void populateViewHolder(ChatViewHolder viewHolder, ChatMessage model, int position) { 125 | final String chatKey = getRef(position).getKey(); 126 | 127 | viewHolder.setMessageText(model.getMessageText()); 128 | viewHolder.setMessageTime(model.getMessageTime()); 129 | viewHolder.setUserName(model.getMessageUser()); 130 | viewHolder.setUserProfileImage(model.getProfileUrl(), getApplicationContext()); 131 | } 132 | }; 133 | chatRecView.setAdapter(firebaseRecyclerAdapter); 134 | } 135 | 136 | public static class ChatViewHolder extends RecyclerView.ViewHolder { 137 | TextView userName; 138 | TextView messageTime; 139 | TextView messageText; 140 | CircleImageView userProfileImage; 141 | 142 | public ChatViewHolder(View itemView) { 143 | super(itemView); 144 | userName = itemView.findViewById(R.id.message_user); 145 | messageTime = itemView.findViewById(R.id.message_time); 146 | messageText = itemView.findViewById(R.id.message_text); 147 | userProfileImage = itemView.findViewById(R.id.profile_image); 148 | } 149 | 150 | public void setUserName(String usr) { 151 | userName.setText(usr); 152 | } 153 | 154 | public void setMessageTime(long time) { 155 | messageTime.setText(DateFormat.format("dd-MM-yyyy (HH:mm:ss)", 156 | time)); 157 | } 158 | 159 | public void setMessageText(String message) { 160 | messageText.setText(message); 161 | } 162 | 163 | public void setUserProfileImage(String profile_url, Context mctx) { 164 | if (profile_url == "null"){ 165 | userProfileImage.setImageResource(R.drawable.ic_user_white); 166 | }else{ 167 | Picasso.with(mctx) 168 | .load(profile_url) 169 | .into(userProfileImage); 170 | } 171 | 172 | } 173 | } 174 | 175 | @Override 176 | public boolean onSupportNavigateUp() { 177 | return super.onSupportNavigateUp(); 178 | } 179 | 180 | } 181 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.text.TextUtils; 9 | import android.util.Log; 10 | import android.view.View; 11 | import android.widget.Button; 12 | import android.widget.EditText; 13 | import android.widget.ImageView; 14 | import android.widget.Toast; 15 | 16 | import com.example.vaibhav.simpleblogapp.R; 17 | import com.facebook.AccessToken; 18 | import com.facebook.CallbackManager; 19 | import com.facebook.FacebookCallback; 20 | import com.facebook.FacebookException; 21 | import com.facebook.login.LoginManager; 22 | import com.facebook.login.LoginResult; 23 | import com.facebook.login.widget.LoginButton; 24 | import com.google.android.gms.auth.api.Auth; 25 | import com.google.android.gms.auth.api.signin.GoogleSignInAccount; 26 | import com.google.android.gms.auth.api.signin.GoogleSignInOptions; 27 | import com.google.android.gms.auth.api.signin.GoogleSignInResult; 28 | import com.google.android.gms.common.ConnectionResult; 29 | import com.google.android.gms.common.SignInButton; 30 | import com.google.android.gms.common.api.GoogleApiClient; 31 | import com.google.android.gms.tasks.OnCompleteListener; 32 | import com.google.android.gms.tasks.Task; 33 | import com.google.firebase.auth.AuthCredential; 34 | import com.google.firebase.auth.AuthResult; 35 | import com.google.firebase.auth.FacebookAuthProvider; 36 | import com.google.firebase.auth.FirebaseAuth; 37 | import com.google.firebase.auth.FirebaseUser; 38 | import com.google.firebase.auth.GoogleAuthProvider; 39 | import com.google.firebase.auth.TwitterAuthProvider; 40 | import com.google.firebase.database.DataSnapshot; 41 | import com.google.firebase.database.DatabaseError; 42 | import com.google.firebase.database.DatabaseReference; 43 | import com.google.firebase.database.FirebaseDatabase; 44 | import com.google.firebase.database.ValueEventListener; 45 | 46 | import com.facebook.FacebookSdk; 47 | import com.facebook.appevents.AppEventsLogger; 48 | import com.twitter.sdk.android.core.Callback; 49 | import com.twitter.sdk.android.core.DefaultLogger; 50 | import com.twitter.sdk.android.core.Result; 51 | import com.twitter.sdk.android.core.Twitter; 52 | import com.twitter.sdk.android.core.TwitterAuthConfig; 53 | import com.twitter.sdk.android.core.TwitterConfig; 54 | import com.twitter.sdk.android.core.TwitterException; 55 | import com.twitter.sdk.android.core.TwitterSession; 56 | import com.twitter.sdk.android.core.identity.TwitterLoginButton; 57 | 58 | import java.util.Arrays; 59 | 60 | public class LoginActivity extends AppCompatActivity implements View.OnClickListener, GoogleApiClient.OnConnectionFailedListener { 61 | 62 | private EditText mLoginEmailField; 63 | private EditText mLoginPasswordField; 64 | private Button mNewAccount; 65 | private Button mLoginButton; 66 | private ProgressDialog mProgressbar; 67 | private DatabaseReference mDatabaseUsers; 68 | //private SignInButton signInButton; 69 | private TwitterLoginButton twitterLoginButton; 70 | 71 | private static final String TAG = "GoogleActivity"; 72 | private static final int RC_SIGN_IN = 9001; 73 | 74 | // [START declare_auth] 75 | private FirebaseAuth mAuth; 76 | // [END declare_auth] 77 | 78 | private String number; 79 | 80 | private GoogleApiClient mGoogleApiClient; 81 | 82 | 83 | private ImageView fbImage; 84 | CallbackManager callbackManager; 85 | 86 | private ImageView googleImg; 87 | 88 | @Override 89 | protected void onCreate(Bundle savedInstanceState) { 90 | super.onCreate(savedInstanceState); 91 | setContentView(R.layout.activity_login); 92 | FacebookSdk.sdkInitialize(getApplicationContext()); 93 | AppEventsLogger.activateApp(this); 94 | 95 | bindViews(); 96 | 97 | onClicks(); 98 | 99 | } 100 | 101 | private void bindViews() { 102 | mAuth = FirebaseAuth.getInstance(); 103 | 104 | mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users"); 105 | mDatabaseUsers.keepSynced(true); 106 | 107 | mProgressbar = new ProgressDialog(this); 108 | 109 | mLoginEmailField = findViewById(R.id.loginemailfield); 110 | mLoginPasswordField = findViewById(R.id.loginpasswordfield); 111 | mLoginButton = findViewById(R.id.loginbtn); 112 | mNewAccount = findViewById(R.id.newaccount); 113 | 114 | fbImage = findViewById(R.id.fbimage); 115 | //signInButton = findViewById(R.id.google_sign_in_button); 116 | twitterLoginButton = findViewById(R.id.t_login_button); 117 | 118 | googleImg = findViewById(R.id.google_sign_in); 119 | 120 | } 121 | 122 | private void onClicks() { 123 | mNewAccount.setOnClickListener(new View.OnClickListener() { 124 | @Override 125 | public void onClick(View v) { 126 | startActivity(new Intent(LoginActivity.this, RegisterActivity.class)); 127 | } 128 | }); 129 | 130 | mLoginButton.setOnClickListener(new View.OnClickListener() { 131 | @Override 132 | public void onClick(View v) { 133 | checkLogin(); 134 | } 135 | }); 136 | 137 | //signInButton.setOnClickListener(this); 138 | 139 | 140 | twitterLoginButton.setOnClickListener(this); 141 | 142 | twitter(); 143 | 144 | fbInit(); 145 | 146 | googleInit(); 147 | 148 | googleImg.setOnClickListener(new View.OnClickListener() { 149 | @Override 150 | public void onClick(View v) { 151 | signUpGoogle(); 152 | } 153 | }); 154 | } 155 | 156 | private void googleInit() { 157 | GoogleSignInOptions gso = new GoogleSignInOptions.Builder(GoogleSignInOptions.DEFAULT_SIGN_IN) 158 | .requestIdToken(getString(R.string.default_web_client_id)) 159 | .requestEmail() 160 | .build(); 161 | mGoogleApiClient = new GoogleApiClient.Builder(this) 162 | .enableAutoManage(this /* FragmentActivity */, this /* OnConnectionFailedListener */) 163 | .addApi(Auth.GOOGLE_SIGN_IN_API, gso) 164 | .build(); 165 | } 166 | 167 | private void signUpGoogle() { 168 | try { 169 | Auth.GoogleSignInApi.signOut(mGoogleApiClient); 170 | Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 171 | startActivityForResult(signInIntent, RC_SIGN_IN); 172 | } catch (Exception e) { 173 | } 174 | } 175 | 176 | private void fbInit() { 177 | 178 | FacebookSdk.sdkInitialize(getApplicationContext()); 179 | callbackManager = CallbackManager.Factory.create(); 180 | LoginManager.getInstance().registerCallback(callbackManager, new FacebookCallback() { 181 | @Override 182 | public void onSuccess(LoginResult loginResult) { 183 | Log.d("facebook:token", AccessToken.getCurrentAccessToken().getToken()); 184 | AccessToken.getCurrentAccessToken().getToken(); 185 | signInWithFacebook(loginResult.getAccessToken()); 186 | } 187 | 188 | @Override 189 | public void onCancel() { 190 | Log.d(TAG, "facebook:onCancel"); 191 | } 192 | 193 | @Override 194 | public void onError(FacebookException error) { 195 | Log.d(TAG, "facebook:onError", error); 196 | } 197 | }); 198 | fbImage.setOnClickListener(new View.OnClickListener() { 199 | @Override 200 | public void onClick(View v) { 201 | LoginManager.getInstance().logInWithReadPermissions(LoginActivity.this, Arrays.asList("email", "user_location", "user_birthday", "public_profile", "user_friends")); 202 | } 203 | }); 204 | } 205 | 206 | private void signInWithFacebook(AccessToken token) { 207 | Log.d(TAG, "signInWithFacebook:" + token.getToken()); 208 | AuthCredential credential = FacebookAuthProvider.getCredential(token.getToken()); 209 | final String tokenString = token.getToken(); 210 | mAuth.signInWithCredential(credential) 211 | .addOnCompleteListener(this, new OnCompleteListener() { 212 | @Override 213 | public void onComplete(@NonNull Task task) { 214 | Log.d(TAG, "signInWithCredential:onComplete:" + task.isSuccessful()); 215 | // 216 | // startActivity(new Intent(SignUp09.this, Dashboard.class)); 217 | // If sign in fails, display a message to the user. If sign in succeeds 218 | // the auth state listener will be notified and logic to handle the 219 | // signed in user can be handled in the listener. 220 | if (!task.isSuccessful()) { 221 | Log.w(TAG, "signInWithCredential", task.getException()); 222 | Toast.makeText(LoginActivity.this, "Sorry for inconvenience,Please try again..", 223 | Toast.LENGTH_SHORT).show(); 224 | } else { 225 | //signInFacebook(tokenString); 226 | Toast.makeText(LoginActivity.this, "Welcome..!", Toast.LENGTH_SHORT).show(); 227 | checkUserExist(); 228 | } 229 | } 230 | 231 | 232 | }); 233 | } 234 | 235 | private void twitter() { 236 | TwitterConfig config = new TwitterConfig.Builder(this) 237 | .logger(new DefaultLogger(Log.DEBUG)) 238 | .twitterAuthConfig(new TwitterAuthConfig(getResources().getString(R.string.com_twitter_sdk_android_CONSUMER_KEY), getResources().getString(R.string.com_twitter_sdk_android_CONSUMER_SECRET))) 239 | .debug(true) 240 | .build(); 241 | Twitter.initialize(config); 242 | twitterLoginButton.setCallback(new Callback() { 243 | @Override 244 | public void success(Result result) { 245 | Log.d(TAG, "twitterLogin:success" + result); 246 | handleTwitterSession(result.data); 247 | } 248 | 249 | @Override 250 | public void failure(TwitterException exception) { 251 | Log.w(TAG, "twitterLogin:failure", exception); 252 | 253 | } 254 | }); 255 | } 256 | 257 | private void handleTwitterSession(TwitterSession session) { 258 | Log.d(TAG, "handleTwitterSession:" + session); 259 | mProgressbar.setMessage("Checking LOGIN....."); 260 | mProgressbar.show(); 261 | AuthCredential credential = TwitterAuthProvider.getCredential( 262 | session.getAuthToken().token, 263 | session.getAuthToken().secret); 264 | 265 | mAuth.signInWithCredential(credential) 266 | .addOnCompleteListener(this, new OnCompleteListener() { 267 | @Override 268 | public void onComplete(@NonNull Task task) { 269 | if (task.isSuccessful()) { 270 | // Sign in success, update UI with the signed-in user's information 271 | Log.d(TAG, "signInWithCredential:success"); 272 | Toast.makeText(LoginActivity.this, "Welcome", Toast.LENGTH_LONG).show(); 273 | checkUserExist(); 274 | mProgressbar.dismiss(); 275 | //***** updateUI(user); 276 | } else { 277 | // If sign in fails, display a message to the user. 278 | Log.w(TAG, "signInWithCredential:failure", task.getException()); 279 | 280 | Toast.makeText(LoginActivity.this, "Failed276" + task.getException().getMessage(), 281 | Toast.LENGTH_SHORT).show(); 282 | mProgressbar.dismiss(); 283 | //**** updateUI(null); 284 | } 285 | } 286 | }); 287 | } 288 | 289 | private void signIn() { 290 | Intent signInIntent = Auth.GoogleSignInApi.getSignInIntent(mGoogleApiClient); 291 | startActivityForResult(signInIntent, RC_SIGN_IN); 292 | } 293 | 294 | 295 | private void firebaseAuthWithGoogle(GoogleSignInAccount acct) { 296 | Log.d(TAG, "firebaseAuthWithGoogle:" + acct.getId()); 297 | mProgressbar.setMessage("Checking LOGIN....."); 298 | mProgressbar.show(); 299 | AuthCredential credential = GoogleAuthProvider.getCredential(acct.getIdToken(), null); 300 | mAuth.signInWithCredential(credential) 301 | .addOnCompleteListener(this, new OnCompleteListener() { 302 | @Override 303 | public void onComplete(@NonNull Task task) { 304 | if (task.isSuccessful()) { 305 | // Sign in success, update UI with the signed-in user's information 306 | Log.d(TAG, "signInWithCredential:success"); 307 | FirebaseUser user = mAuth.getCurrentUser(); 308 | mAuth = FirebaseAuth.getInstance(); 309 | Toast.makeText(LoginActivity.this, "Welcome..!", Toast.LENGTH_SHORT).show(); 310 | checkUserExist(); 311 | mProgressbar.dismiss(); 312 | //***updateUI(user); 313 | } else { 314 | // If sign in fails, display a message to the user. 315 | Log.w(TAG, "signInWithCredential:failure", task.getException()); 316 | Toast.makeText(LoginActivity.this, "Authentication failed." + task.getException().getMessage(), 317 | Toast.LENGTH_SHORT).show(); 318 | mProgressbar.dismiss(); 319 | //****updateUI(null); 320 | } 321 | } 322 | }); 323 | } 324 | 325 | @Override 326 | public void onActivityResult(int requestCode, int resultCode, Intent data) { 327 | super.onActivityResult(requestCode, resultCode, data); 328 | 329 | // Result returned from launching the Intent from GoogleSignInApi.getSignInIntent(...); 330 | if (requestCode == RC_SIGN_IN) { 331 | GoogleSignInResult result = Auth.GoogleSignInApi.getSignInResultFromIntent(data); 332 | if (result.isSuccess()) { 333 | // Google Sign In was successful, authenticate with Firebase 334 | GoogleSignInAccount account = result.getSignInAccount(); 335 | firebaseAuthWithGoogle(account); 336 | } else { 337 | // Google Sign In failed, update UI appropriately 338 | } 339 | } 340 | callbackManager.onActivityResult(requestCode, resultCode, data); 341 | twitterLoginButton.onActivityResult(requestCode, resultCode, data); 342 | } 343 | 344 | 345 | private void checkLogin() { 346 | String email = mLoginEmailField.getText().toString().trim(); 347 | String password = mLoginPasswordField.getText().toString().trim(); 348 | if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) { 349 | Toast.makeText(getApplicationContext(), "uname:" + email + " passwd:" + password, Toast.LENGTH_LONG).show(); 350 | 351 | mProgressbar.setMessage("Checking LOGIN....."); 352 | mProgressbar.show(); 353 | 354 | mAuth.signInWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { 355 | @Override 356 | public void onComplete(@NonNull Task task) { 357 | if (task.isSuccessful()) { 358 | mProgressbar.dismiss(); 359 | checkUserExist(); 360 | } else { 361 | mProgressbar.dismiss(); 362 | Toast.makeText(LoginActivity.this, "TASK FAILED", Toast.LENGTH_LONG).show(); 363 | Log.w("LoginThing---", "signInWithEmail:failed", task.getException()); 364 | } 365 | } 366 | }); 367 | } 368 | } 369 | 370 | private void checkUserExist() { 371 | mProgressbar.setMessage("loading.."); 372 | mProgressbar.show(); 373 | final String user_id = mAuth.getCurrentUser().getUid(); 374 | mDatabaseUsers.addValueEventListener(new ValueEventListener() { 375 | @Override 376 | public void onDataChange(DataSnapshot dataSnapshot) { 377 | if (dataSnapshot.hasChild(user_id)) { 378 | Intent mainIntent = new Intent(LoginActivity.this, MainActivity.class); 379 | mainIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); 380 | startActivity(mainIntent); 381 | mProgressbar.dismiss(); 382 | } else { 383 | Intent setupIntent = new Intent(LoginActivity.this, SetupActivity.class); 384 | setupIntent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK); 385 | startActivity(setupIntent); 386 | mProgressbar.dismiss(); 387 | } 388 | } 389 | 390 | @Override 391 | public void onCancelled(DatabaseError databaseError) { 392 | } 393 | }); 394 | } 395 | 396 | @Override 397 | public void onClick(View v) { 398 | 399 | } 400 | 401 | @Override 402 | public void onConnectionFailed(@NonNull ConnectionResult connectionResult) { 403 | } 404 | // private void facebook() { 405 | // mCallbackManager = CallbackManager.Factory.create(); 406 | // loginButton.setReadPermissions("email", "public_profile"); 407 | // loginButton.registerCallback(mCallbackManager, new FacebookCallback() { 408 | // 409 | // @Override 410 | // public void onSuccess(LoginResult loginResult) { 411 | // Log.d(TAG, "facebook:onSuccess:" + loginResult); 412 | // handleFacebookAccessToken(loginResult.getAccessToken()); 413 | // } 414 | // 415 | // @Override 416 | // public void onCancel() { 417 | // Log.d(TAG, "facebook:onCancel"); 418 | // } 419 | // 420 | // @Override 421 | // public void onError(FacebookException error) { 422 | // Log.d(TAG, "facebook:onError", error); 423 | // } 424 | // }); 425 | // } 426 | } 427 | //hash key 428 | //8XVPHaUeV2wPURiHhBMmGl9tq4Q= 429 | //2jmj7l5rSw0yVb/vlWAYkK/YBwk= 430 | //fb--1455972557797661 431 | //fb--d36f1ea27ff477805f7d382e88b1ed84 -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.content.Context; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.design.widget.FloatingActionButton; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.support.v7.widget.LinearLayoutManager; 10 | import android.support.v7.widget.RecyclerView; 11 | import android.util.Log; 12 | import android.view.Menu; 13 | import android.view.MenuItem; 14 | import android.view.View; 15 | import android.widget.ImageButton; 16 | import android.widget.ImageView; 17 | import android.widget.TextView; 18 | import android.widget.Toast; 19 | 20 | import com.example.vaibhav.simpleblogapp.Models.Blog; 21 | import com.example.vaibhav.simpleblogapp.R; 22 | import com.firebase.ui.database.FirebaseRecyclerAdapter; 23 | import com.google.android.gms.ads.AdRequest; 24 | import com.google.android.gms.ads.AdView; 25 | import com.google.firebase.auth.FirebaseAuth; 26 | import com.google.firebase.auth.FirebaseUser; 27 | import com.google.firebase.database.DataSnapshot; 28 | import com.google.firebase.database.DatabaseError; 29 | import com.google.firebase.database.DatabaseReference; 30 | import com.google.firebase.database.FirebaseDatabase; 31 | import com.google.firebase.database.ValueEventListener; 32 | import com.squareup.picasso.Callback; 33 | import com.squareup.picasso.NetworkPolicy; 34 | import com.squareup.picasso.Picasso; 35 | 36 | public class MainActivity extends AppCompatActivity { 37 | private RecyclerView mBlogList; 38 | private DatabaseReference mDatabase; 39 | private FirebaseAuth mAuth; 40 | private DatabaseReference mDatabaseUsers; 41 | private DatabaseReference mDBRefSetup; 42 | private DatabaseReference mDatabaseLike; 43 | private FirebaseAuth.AuthStateListener mAuthListener; 44 | private FloatingActionButton floatingActionButton; 45 | private boolean mProcessLike = false; 46 | 47 | @Override 48 | protected void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.activity_main); 51 | AdView adView = findViewById(R.id.adView); 52 | AdRequest adRequest = new AdRequest.Builder().build(); 53 | adView.loadAd(adRequest); 54 | firebaseInit(); 55 | 56 | blogList(); 57 | //comment 58 | //2323232 59 | floatingActionButton.setOnClickListener(new View.OnClickListener() { 60 | @Override 61 | public void onClick(View v) { 62 | startActivity(new Intent(MainActivity.this, ChatActivity.class)); 63 | } 64 | }); 65 | checkUserExist(); 66 | } 67 | 68 | @Override 69 | public void onStop() { 70 | super.onStop(); 71 | if (mAuthListener != null) { 72 | mAuth.removeAuthStateListener(mAuthListener); 73 | } 74 | } 75 | 76 | @Override 77 | protected void onStart() { 78 | super.onStart(); 79 | mAuth.addAuthStateListener(mAuthListener);//important thing!!!for sign out!!! 80 | FirebaseRecyclerAdapter firebaseRecyclerAdapter = new FirebaseRecyclerAdapter( 81 | Blog.class, 82 | R.layout.blog_row, 83 | BloViewHolder.class, 84 | mDatabase) { 85 | @Override 86 | protected void populateViewHolder(final BloViewHolder viewHolder, final Blog model, final int position) { 87 | final String post_key = getRef(position).getKey(); 88 | 89 | viewHolder.setTitle(model.getTitle()); 90 | viewHolder.setDesc(model.getDESCRIPTION()); 91 | viewHolder.setUsername(model.getUsername()); 92 | viewHolder.setImage(getApplicationContext(), model.getIMAGE()); 93 | viewHolder.mView.setOnClickListener(new View.OnClickListener() { 94 | @Override 95 | public void onClick(View v) { 96 | Toast.makeText(getApplicationContext(), "You just cliked on blog " + viewHolder.post_title.getText(), Toast.LENGTH_LONG).show(); 97 | } 98 | }); 99 | viewHolder.setLikeBtn(post_key); 100 | viewHolder.mLikebtn.setOnClickListener(new View.OnClickListener() { 101 | @Override 102 | public void onClick(View view) { 103 | 104 | mProcessLike = true; 105 | 106 | mDatabaseLike.addValueEventListener(new ValueEventListener() { 107 | @Override 108 | public void onDataChange(DataSnapshot dataSnapshot) { 109 | if (mProcessLike) { 110 | 111 | if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())) { 112 | 113 | mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).removeValue(); 114 | 115 | mProcessLike = false; 116 | 117 | } else { 118 | 119 | mDatabaseLike.child(post_key).child(mAuth.getCurrentUser().getUid()).setValue("RandomValue"); 120 | 121 | mProcessLike = false; 122 | 123 | } 124 | } 125 | 126 | } 127 | 128 | @Override 129 | public void onCancelled(DatabaseError databaseError) { 130 | 131 | } 132 | }); 133 | 134 | } 135 | }); 136 | } 137 | }; 138 | mBlogList.setAdapter(firebaseRecyclerAdapter); 139 | } 140 | 141 | private void firebaseInit() { 142 | 143 | mAuth = FirebaseAuth.getInstance(); 144 | mAuthListener = new FirebaseAuth.AuthStateListener() { 145 | 146 | @Override 147 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 148 | if (FirebaseAuth.getInstance().getCurrentUser() == null) { 149 | Intent loginIntent = new Intent(MainActivity.this, LoginActivity.class); 150 | loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_NEW_TASK); 151 | startActivity(loginIntent); 152 | }//if there is no curreent user then only move to liginActivity 153 | } 154 | }; 155 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog"); 156 | mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users"); 157 | mDBRefSetup = FirebaseDatabase.getInstance().getReference().child("Users"); 158 | mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Likes"); 159 | mDatabaseLike.keepSynced(true); 160 | mDatabaseUsers.keepSynced(true); 161 | mDatabase.keepSynced(true); 162 | } 163 | 164 | private void blogList() { 165 | mBlogList = findViewById(R.id.blog_list); 166 | LinearLayoutManager layoutManager = new LinearLayoutManager(this); 167 | layoutManager.setReverseLayout(true); 168 | layoutManager.setStackFromEnd(true); 169 | mBlogList.setHasFixedSize(true); 170 | mBlogList.setLayoutManager(layoutManager); 171 | floatingActionButton = findViewById(R.id.fab); 172 | } 173 | 174 | private void checkUserExist() { 175 | 176 | FirebaseUser user = FirebaseAuth.getInstance().getCurrentUser(); 177 | if (user != null) { 178 | final String user_id = user.getUid(); 179 | mDatabaseUsers.addValueEventListener(new ValueEventListener() { 180 | @Override 181 | public void onDataChange(DataSnapshot dataSnapshot) { 182 | if (!dataSnapshot.hasChild(user_id)) { 183 | Intent setupIntent = new Intent(MainActivity.this, SetupActivity.class); 184 | setupIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 185 | startActivity(setupIntent); 186 | } else { 187 | onStart(); 188 | } 189 | } 190 | 191 | @Override 192 | public void onCancelled(DatabaseError databaseError) { 193 | } 194 | }); 195 | } 196 | } 197 | 198 | public static class BloViewHolder extends RecyclerView.ViewHolder { 199 | View mView; 200 | TextView post_title; 201 | ImageButton mLikebtn; 202 | FirebaseAuth mAuth; 203 | DatabaseReference mDatabaseLike; 204 | 205 | public BloViewHolder(View itemView) { 206 | super(itemView); 207 | mView = itemView; 208 | mLikebtn = (ImageButton) mView.findViewById(R.id.post_like); 209 | 210 | mDatabaseLike = FirebaseDatabase.getInstance().getReference().child("Likes"); 211 | mDatabaseLike.keepSynced(true); 212 | mAuth = FirebaseAuth.getInstance(); 213 | post_title = mView.findViewById(R.id.post_title); 214 | // post_title.setOnClickListener(new View.OnClickListener() { 215 | // @Override 216 | // public void onClick(View v) { 217 | // Log.d("MAinactivity", "someText"); 218 | // } 219 | // }); 220 | } 221 | 222 | public void setLikeBtn(final String post_key) { 223 | mDatabaseLike.addValueEventListener(new ValueEventListener() { 224 | @Override 225 | public void onDataChange(DataSnapshot dataSnapshot) { 226 | 227 | if (dataSnapshot.child(post_key).hasChild(mAuth.getCurrentUser().getUid())) { 228 | mLikebtn.setImageResource(R.drawable.ic_yes_heart_colored); 229 | } else { 230 | mLikebtn.setImageResource(R.drawable.ic_no_heart_gray); 231 | } 232 | } 233 | 234 | @Override 235 | public void onCancelled(DatabaseError databaseError) { 236 | 237 | } 238 | }); 239 | } 240 | 241 | public void setTitle(String title) { 242 | post_title.setText(title); 243 | } 244 | 245 | public void setDesc(String DESCRIPTION) { 246 | TextView post_description = mView.findViewById(R.id.post_text); 247 | post_description.setText(DESCRIPTION); 248 | } 249 | 250 | public void setUsername(String username) { 251 | TextView post_username = mView.findViewById(R.id.post_username); 252 | post_username.setText(username); 253 | } 254 | 255 | public void setImage(final Context ctx, final String IMAGE) { 256 | final ImageView post_image = mView.findViewById(R.id.post_image); 257 | Picasso.with(ctx) 258 | .load(IMAGE) 259 | .networkPolicy(NetworkPolicy.OFFLINE) 260 | .into(post_image, new Callback() { 261 | @Override 262 | public void onSuccess() { 263 | } 264 | 265 | @Override 266 | public void onError() { 267 | //if error occured try again by getting the image from online 268 | Picasso.with(ctx) 269 | .load(IMAGE) 270 | .error(R.drawable.ic_broken_image) 271 | .into(post_image, new Callback() { 272 | @Override 273 | public void onSuccess() { 274 | } 275 | 276 | @Override 277 | public void onError() { 278 | Toast.makeText(ctx, "failed to load image !", Toast.LENGTH_SHORT).show(); 279 | } 280 | }); 281 | } 282 | }); 283 | } 284 | } 285 | 286 | @Override 287 | public void onBackPressed() { 288 | super.onBackPressed(); 289 | } 290 | 291 | @Override 292 | public boolean onCreateOptionsMenu(Menu menu) { 293 | getMenuInflater().inflate(R.menu.main_menu, menu); 294 | return super.onCreateOptionsMenu(menu); 295 | } 296 | 297 | @Override 298 | public boolean onOptionsItemSelected(MenuItem item) { 299 | 300 | switch (item.getItemId()) { 301 | case R.id.action_add: 302 | startActivity(new Intent(MainActivity.this, PostActivity.class)); 303 | break; 304 | case R.id.action_logout: 305 | logout(); 306 | break; 307 | case R.id.action_settings: 308 | mDBRefSetup.addValueEventListener(new ValueEventListener() { 309 | @Override 310 | public void onDataChange(DataSnapshot dataSnapshot) { 311 | if (dataSnapshot.hasChild(FirebaseAuth.getInstance().getCurrentUser().getUid())) { 312 | // User is Present in DB 313 | startActivity(new Intent(MainActivity.this, ProfileActivity.class)); 314 | } else { 315 | startActivity(new Intent(MainActivity.this, SetupActivity.class)); 316 | } 317 | } 318 | 319 | @Override 320 | public void onCancelled(DatabaseError databaseError) { 321 | 322 | } 323 | }); 324 | break; 325 | } 326 | return super.onOptionsItemSelected(item); 327 | } 328 | 329 | private void logout() { 330 | mAuth.signOut(); 331 | 332 | } 333 | } -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/PostActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.os.Bundle; 7 | import android.support.annotation.NonNull; 8 | import android.support.v7.app.AppCompatActivity; 9 | import android.text.TextUtils; 10 | import android.view.View; 11 | import android.widget.Button; 12 | import android.widget.EditText; 13 | import android.widget.ImageButton; 14 | import android.widget.Toast; 15 | 16 | import com.example.vaibhav.simpleblogapp.R; 17 | import com.google.android.gms.tasks.OnCompleteListener; 18 | import com.google.android.gms.tasks.OnFailureListener; 19 | import com.google.android.gms.tasks.OnSuccessListener; 20 | import com.google.android.gms.tasks.Task; 21 | import com.google.firebase.auth.FirebaseAuth; 22 | import com.google.firebase.auth.FirebaseUser; 23 | import com.google.firebase.database.DataSnapshot; 24 | import com.google.firebase.database.DatabaseError; 25 | import com.google.firebase.database.DatabaseReference; 26 | import com.google.firebase.database.FirebaseDatabase; 27 | import com.google.firebase.database.ValueEventListener; 28 | import com.google.firebase.storage.FirebaseStorage; 29 | import com.google.firebase.storage.StorageReference; 30 | import com.google.firebase.storage.UploadTask; 31 | 32 | public class PostActivity extends AppCompatActivity { 33 | 34 | private Button mSubmitBtn; 35 | private static final int GALLERY_REQUEST = 999; 36 | private ImageButton mSelectImage; 37 | private EditText mPostTitle; 38 | private EditText mPostDesc; 39 | private Uri mImageUri; 40 | private StorageReference mStorageRef; 41 | private DatabaseReference mDatabase; 42 | private ProgressDialog mprogressbar; 43 | private FirebaseUser mCurrentUser; 44 | private DatabaseReference mDatabaseUSer; 45 | 46 | 47 | @Override 48 | protected void onCreate(Bundle savedInstanceState) { 49 | super.onCreate(savedInstanceState); 50 | setContentView(R.layout.activity_post); 51 | 52 | bindViews(); 53 | 54 | FirebaseAuth mAuth = FirebaseAuth.getInstance(); 55 | mCurrentUser = mAuth.getCurrentUser(); 56 | mDatabaseUSer = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid()); 57 | 58 | clickEvents(); 59 | 60 | } 61 | 62 | private void bindViews() { 63 | mprogressbar = new ProgressDialog(this); 64 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Blog"); 65 | mStorageRef = FirebaseStorage.getInstance().getReference(); 66 | mPostTitle = (EditText) findViewById(R.id.editText1); 67 | mPostDesc = (EditText) findViewById(R.id.editText2); 68 | mSubmitBtn = (Button) findViewById(R.id.btn); 69 | mSelectImage = (ImageButton) findViewById(R.id.imageButton2); 70 | } 71 | 72 | private void clickEvents() { 73 | mSelectImage.setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View v) { 76 | Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT); 77 | galleryIntent.setType("image/*"); 78 | 79 | startActivityForResult(galleryIntent, GALLERY_REQUEST); 80 | } 81 | }); 82 | 83 | mSubmitBtn.setOnClickListener(new View.OnClickListener() { 84 | @Override 85 | public void onClick(View v) { 86 | startPosting(); 87 | } 88 | }); 89 | 90 | } 91 | 92 | private void startPosting() { 93 | 94 | mprogressbar.setMessage("Posting..."); 95 | 96 | final String title_val = mPostTitle.getText().toString().trim(); 97 | final String desc_val = mPostDesc.getText().toString().trim(); 98 | 99 | if (!TextUtils.isEmpty(title_val) && !TextUtils.isEmpty(desc_val) && mImageUri != null) { 100 | //can post 101 | // mImageUri= Uri.fromFile(new File(mImageUri.getLastPathSegment())); 102 | mprogressbar.show(); 103 | StorageReference filepath = mStorageRef.child("Blog_Images").child(mImageUri.getLastPathSegment()); 104 | filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener() { 105 | @Override 106 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 107 | 108 | final Uri downloadUrl = taskSnapshot.getDownloadUrl(); 109 | final DatabaseReference newPost = mDatabase.push();//cret uniquid 110 | mDatabaseUSer.addValueEventListener(new ValueEventListener() { 111 | @Override 112 | public void onDataChange(DataSnapshot dataSnapshot) { 113 | 114 | newPost.child("Title").setValue(title_val); 115 | newPost.child("DESCRIPTION").setValue(desc_val); 116 | newPost.child("IMAGE").setValue(downloadUrl.toString()); 117 | newPost.child("uid").setValue(mCurrentUser.getUid()); 118 | newPost.child("username").setValue(dataSnapshot.child("name").getValue()).addOnCompleteListener(new OnCompleteListener() { 119 | @Override 120 | public void onComplete(@NonNull Task task) { 121 | if (task.isSuccessful()) { 122 | startActivity(new Intent(PostActivity.this, MainActivity.class)); 123 | 124 | } 125 | } 126 | }); 127 | } 128 | 129 | @Override 130 | public void onCancelled(DatabaseError databaseError) { 131 | 132 | } 133 | }); 134 | 135 | mprogressbar.dismiss(); 136 | Toast.makeText(PostActivity.this, "Posted Successfully!!!!!", 137 | Toast.LENGTH_SHORT).show(); 138 | 139 | 140 | } 141 | }).addOnFailureListener(new OnFailureListener() { 142 | @Override 143 | public void onFailure(@NonNull Exception e) { 144 | Toast.makeText(PostActivity.this, "Unabel to post Please TRY AGAIN!!!!", 145 | Toast.LENGTH_LONG).show(); 146 | } 147 | }); 148 | } 149 | } 150 | 151 | @Override 152 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 153 | super.onActivityResult(requestCode, resultCode, data); 154 | if (requestCode == GALLERY_REQUEST && resultCode == RESULT_OK) { 155 | mImageUri = data.getData(); 156 | mSelectImage.setImageURI(mImageUri); 157 | } 158 | 159 | } 160 | } 161 | 162 | //LD_PRELOAD='/usr/lib/x86_64-linux-gnu/libstdc++.so.6' ~/Android/Sdk/tools/emulator -netdelay none -netspeed full -avd Nexus_5_API_25 163 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/ProfileActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.content.Intent; 4 | import android.net.Uri; 5 | import android.support.v7.app.AppCompatActivity; 6 | import android.os.Bundle; 7 | import android.util.Log; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.TextView; 11 | 12 | import com.example.vaibhav.simpleblogapp.R; 13 | import com.facebook.AccessToken; 14 | import com.facebook.login.LoginManager; 15 | import com.google.firebase.auth.FirebaseAuth; 16 | import com.google.firebase.database.DataSnapshot; 17 | import com.google.firebase.database.DatabaseError; 18 | import com.google.firebase.database.DatabaseReference; 19 | import com.google.firebase.database.FirebaseDatabase; 20 | import com.google.firebase.database.ValueEventListener; 21 | import com.google.firebase.storage.FirebaseStorage; 22 | import com.google.firebase.storage.StorageReference; 23 | import com.squareup.picasso.Picasso; 24 | 25 | import de.hdodenhof.circleimageview.CircleImageView; 26 | 27 | public class ProfileActivity extends AppCompatActivity { 28 | CircleImageView circleImageViewProfile; 29 | TextView textViewProfile; 30 | String uimage; 31 | String uname; 32 | Button buttonProfile; 33 | private TextView edit; 34 | 35 | @Override 36 | protected void onCreate(Bundle savedInstanceState) { 37 | super.onCreate(savedInstanceState); 38 | setContentView(R.layout.activity_profile); 39 | bindViews(); 40 | DatabaseReference mDatabseUsers = FirebaseDatabase.getInstance().getReference().child("Users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()); 41 | mDatabseUsers.addValueEventListener(new ValueEventListener() { 42 | @Override 43 | public void onDataChange(DataSnapshot dataSnapshot) { 44 | if (dataSnapshot.hasChild("name")) { 45 | uname = String.valueOf(dataSnapshot.child("name").getValue()); 46 | String temp = getString(R.string.log_in_as) + uname; 47 | textViewProfile.setText(temp); 48 | } 49 | if (dataSnapshot.hasChild("image")) { 50 | uimage = String.valueOf(dataSnapshot.child("image").getValue()); 51 | Log.d("fgfgfgfg", " " + uimage); 52 | Picasso.with(getApplicationContext()).load(uimage).into(circleImageViewProfile); 53 | } 54 | } 55 | 56 | @Override 57 | public void onCancelled(DatabaseError databaseError) { 58 | } 59 | }); 60 | 61 | buttonProfile.setOnClickListener(new View.OnClickListener() { 62 | @Override 63 | public void onClick(View v) { 64 | FirebaseAuth.getInstance().signOut(); 65 | Intent logOut = new Intent(ProfileActivity.this, LoginActivity.class); 66 | logOut.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK); 67 | startActivity(logOut); 68 | } 69 | }); 70 | edit.setOnClickListener(new View.OnClickListener() { 71 | @Override 72 | public void onClick(View v) { 73 | startActivity(new Intent(ProfileActivity.this, SetupActivity.class)); 74 | } 75 | }); 76 | } 77 | 78 | private void bindViews() { 79 | circleImageViewProfile = (CircleImageView) findViewById(R.id.ProfilecircleImageView); 80 | textViewProfile = (TextView) findViewById(R.id.profileTextView); 81 | buttonProfile = (Button) findViewById(R.id.profileLogOut); 82 | edit = (TextView) findViewById(R.id.editProfile); 83 | } 84 | } 85 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/RegisterActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Intent; 5 | import android.os.Bundle; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.text.TextUtils; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | import android.widget.Toast; 13 | 14 | import com.example.vaibhav.simpleblogapp.R; 15 | import com.google.android.gms.tasks.OnCompleteListener; 16 | import com.google.android.gms.tasks.Task; 17 | import com.google.firebase.auth.AuthResult; 18 | import com.google.firebase.auth.FirebaseAuth; 19 | import com.google.firebase.database.DatabaseReference; 20 | import com.google.firebase.database.FirebaseDatabase; 21 | 22 | public class RegisterActivity extends AppCompatActivity { 23 | 24 | private EditText mNameField; 25 | private EditText mEmailField; 26 | private EditText mPasswordField; 27 | private Button mRegBtn; 28 | 29 | private ProgressDialog mProgress; 30 | 31 | private FirebaseAuth mAuth; 32 | private DatabaseReference mDatabase; 33 | 34 | @Override 35 | protected void onCreate(Bundle savedInstanceState) { 36 | super.onCreate(savedInstanceState); 37 | setContentView(R.layout.activity_register); 38 | 39 | init(); 40 | 41 | mRegBtn.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View v) { 44 | startRegister(); 45 | } 46 | }); 47 | } 48 | 49 | private void init() { 50 | mAuth = FirebaseAuth.getInstance(); 51 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Users"); 52 | mNameField = findViewById(R.id.name); 53 | mEmailField = findViewById(R.id.email); 54 | mPasswordField = findViewById(R.id.password); 55 | mProgress = new ProgressDialog(this); 56 | mRegBtn = findViewById(R.id.btn); 57 | } 58 | 59 | private void startRegister() { 60 | final String name = mNameField.getText().toString().trim(); 61 | String email = mEmailField.getText().toString().trim(); 62 | String password = mPasswordField.getText().toString().trim(); 63 | 64 | if (!TextUtils.isEmpty(name) && !TextUtils.isEmpty(email) && !TextUtils.isEmpty(password)) { 65 | 66 | mProgress.setMessage("Sigining UP......"); 67 | mProgress.show(); 68 | mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { 69 | @Override 70 | public void onComplete(@NonNull Task task) { 71 | 72 | if (task.isSuccessful()) { 73 | 74 | String user_id = mAuth.getCurrentUser().getUid(); 75 | DatabaseReference current_user_db = mDatabase.child(user_id); 76 | 77 | current_user_db.child("name").setValue(name); 78 | current_user_db.child("image").setValue("default"); 79 | 80 | mProgress.dismiss(); 81 | Intent mainIntent = new Intent(RegisterActivity.this, SetupActivity.class); 82 | mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 83 | startActivity(mainIntent); 84 | 85 | } else { 86 | Toast.makeText(RegisterActivity.this, "Failed!!", Toast.LENGTH_LONG).show(); 87 | mProgress.dismiss(); 88 | } 89 | 90 | } 91 | }); 92 | 93 | } 94 | 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/vaibhav/simpleblogapp/ShowActivity/SetupActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.vaibhav.simpleblogapp.ShowActivity; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.BroadcastReceiver; 5 | import android.content.Context; 6 | import android.content.Intent; 7 | import android.content.IntentFilter; 8 | import android.net.Uri; 9 | import android.os.Bundle; 10 | import android.support.annotation.NonNull; 11 | import android.support.v7.app.AppCompatActivity; 12 | import android.text.TextUtils; 13 | import android.util.Log; 14 | import android.view.View; 15 | import android.widget.Button; 16 | import android.widget.EditText; 17 | import android.widget.ImageButton; 18 | import android.widget.Toast; 19 | 20 | import com.example.vaibhav.simpleblogapp.FCMthings.SharedPrefManager; 21 | import com.example.vaibhav.simpleblogapp.FCMthings.MyfirebaseInstanceServices; 22 | import com.example.vaibhav.simpleblogapp.R; 23 | import com.facebook.AccessToken; 24 | import com.facebook.login.LoginManager; 25 | import com.google.android.gms.tasks.OnFailureListener; 26 | import com.google.android.gms.tasks.OnSuccessListener; 27 | import com.google.firebase.auth.FirebaseAuth; 28 | import com.google.firebase.database.DatabaseReference; 29 | import com.google.firebase.database.FirebaseDatabase; 30 | import com.google.firebase.storage.FirebaseStorage; 31 | import com.google.firebase.storage.StorageReference; 32 | import com.google.firebase.storage.UploadTask; 33 | import com.theartofdev.edmodo.cropper.CropImage; 34 | import com.theartofdev.edmodo.cropper.CropImageView; 35 | 36 | public class SetupActivity extends AppCompatActivity { 37 | 38 | private ImageButton mSetupImage; 39 | private EditText mNameField; 40 | private Button mFinishBtn; 41 | private Uri mImageUri = null; 42 | private DatabaseReference mDatabseUsers; 43 | private FirebaseAuth mAuth; 44 | private StorageReference mStorageRef; 45 | private static final int GALLARY_REQUEST = 1; 46 | private ProgressDialog mProgress; 47 | private BroadcastReceiver broadcastReceiver; 48 | private String tokenString = null; 49 | 50 | public SetupActivity() { 51 | 52 | } 53 | 54 | @Override 55 | protected void onCreate(Bundle savedInstanceState) { 56 | super.onCreate(savedInstanceState); 57 | setContentView(R.layout.activity_setup); 58 | registerReceiver(broadcastReceiver, new IntentFilter(MyfirebaseInstanceServices.TOKEN_BROADCAST)); 59 | broadcastReceiver = new BroadcastReceiver() { 60 | @Override 61 | public void onReceive(Context context, Intent intent) { 62 | tokenString = SharedPrefManager.getInstance(SetupActivity.this).getToken(); 63 | } 64 | }; 65 | tokenString = SharedPrefManager.getInstance(SetupActivity.this).getToken(); 66 | // Log.d("received", " " + tokenString); 67 | bindViews(); 68 | onClickMethods(); 69 | 70 | } 71 | 72 | @Override 73 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 74 | super.onActivityResult(requestCode, resultCode, data); 75 | 76 | if (requestCode == GALLARY_REQUEST && resultCode == RESULT_OK) { 77 | Uri imageUri = data.getData(); 78 | CropImage.activity(imageUri) 79 | .setGuidelines(CropImageView.Guidelines.ON) 80 | .setAspectRatio(1, 1) 81 | .start(this); 82 | 83 | } 84 | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) { 85 | CropImage.ActivityResult result = CropImage.getActivityResult(data); 86 | if (resultCode == RESULT_OK) { 87 | mImageUri = result.getUri(); 88 | mSetupImage.setImageURI(mImageUri); 89 | } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) { 90 | Exception error = result.getError(); 91 | Log.d("setupError", error + ""); 92 | } 93 | } 94 | } 95 | 96 | private void bindViews() { 97 | mAuth = FirebaseAuth.getInstance(); 98 | mStorageRef = FirebaseStorage.getInstance().getReference().child("ProfileImages"); 99 | mDatabseUsers = FirebaseDatabase.getInstance().getReference().child("Users"); 100 | mSetupImage = (ImageButton) findViewById(R.id.setupImagebtn); 101 | mNameField = (EditText) findViewById(R.id.setupName); 102 | mFinishBtn = (Button) findViewById(R.id.finishbtn); 103 | mProgress = new ProgressDialog(this); 104 | } 105 | 106 | private void onClickMethods() { 107 | 108 | mSetupImage.setOnClickListener(new View.OnClickListener() { 109 | @Override 110 | public void onClick(View v) { 111 | Intent galleryIntent = new Intent(); 112 | galleryIntent.setAction(Intent.ACTION_GET_CONTENT); 113 | galleryIntent.setType("image/*"); 114 | startActivityForResult(galleryIntent, GALLARY_REQUEST); 115 | } 116 | }); 117 | mFinishBtn.setOnClickListener(new View.OnClickListener() { 118 | @Override 119 | public void onClick(View v) { 120 | startSetupAccount(); 121 | } 122 | }); 123 | } 124 | 125 | private void startSetupAccount() { 126 | final String name = mNameField.getText().toString().trim(); 127 | final String user_id = mAuth.getCurrentUser().getUid(); 128 | if (!TextUtils.isEmpty(name) && mImageUri != null) { 129 | mProgress.setMessage("Saving Profile....."); 130 | mProgress.show(); 131 | StorageReference filepath = mStorageRef.child(mImageUri.getLastPathSegment()); 132 | 133 | filepath.putFile(mImageUri) 134 | .addOnSuccessListener(new OnSuccessListener() { 135 | @Override 136 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 137 | String downloadUri = taskSnapshot.getDownloadUrl().toString(); 138 | mDatabseUsers.child(user_id).child("name").setValue(name); 139 | mDatabseUsers.child(user_id).child("image").setValue(downloadUri); 140 | mDatabseUsers.child(user_id).child("token").setValue(tokenString); 141 | Intent mainIntent = new Intent(SetupActivity.this, MainActivity.class); 142 | mainIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 143 | mProgress.dismiss(); 144 | Toast.makeText(SetupActivity.this, "Profile Saved Successfully :)", Toast.LENGTH_LONG).show(); 145 | startActivity(mainIntent); 146 | } 147 | }) 148 | .addOnFailureListener(new OnFailureListener() { 149 | @Override 150 | public void onFailure(@NonNull Exception exception) { 151 | Toast.makeText(SetupActivity.this, "FAILED!!", Toast.LENGTH_LONG).show(); 152 | mProgress.dismiss(); 153 | } 154 | }); 155 | } 156 | } 157 | 158 | } 159 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_broken_image.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_facebook.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_google.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 15 | 18 | 19 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_no_heart_gray.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_upload_pic.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_user_white.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_yes_heart_colored.xml: -------------------------------------------------------------------------------- 1 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/input_outline.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/input_outline2.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/input_outline3.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 7 | 8 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/send.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 12 | 13 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_chat.xml: -------------------------------------------------------------------------------- 1 | 2 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 32 | 33 | 34 | 35 | 45 | 46 | 56 | 57 | 66 | 67 | -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 25 | 26 | 42 | 43 |