├── .gitignore ├── .idea ├── compiler.xml ├── copyright │ └── profiles_settings.xml ├── gradle.xml ├── misc.xml ├── modules.xml └── runConfigurations.xml ├── app ├── .gitignore ├── build.gradle ├── google-services.json ├── libs │ └── josephdalughut-skout-bd41074eead3.zip ├── proguard-rules.pro └── src │ ├── androidTest │ └── java │ │ └── com │ │ └── example │ │ └── ekene │ │ └── blogzone │ │ └── ExampleInstrumentedTest.java │ ├── main │ ├── AndroidManifest.xml │ ├── java │ │ └── com │ │ │ └── example │ │ │ └── ekene │ │ │ └── blogzone │ │ │ ├── Blogzone.java │ │ │ ├── LoginActivity.java │ │ │ ├── MainActivity.java │ │ │ ├── PostActivity.java │ │ │ ├── ProfileActivity.java │ │ │ ├── RegisterActivity.java │ │ │ └── SinglePostActivity.java │ └── res │ │ ├── drawable │ │ ├── action_button_style.xml │ │ ├── add_img.png │ │ ├── addicon.png │ │ ├── bg.jpg │ │ ├── bgg.jpg │ │ ├── buttonstyle.xml │ │ ├── edit_text_styles.xml │ │ ├── ic_add_black_24dp.xml │ │ ├── imag.jpg │ │ ├── layoutstyle.xml │ │ └── lowres.jpg │ │ ├── layout │ │ ├── activity_login.xml │ │ ├── activity_main.xml │ │ ├── activity_post.xml │ │ ├── activity_profile.xml │ │ ├── activity_register.xml │ │ ├── activity_single_post.xml │ │ ├── card_items.xml │ │ └── content_main.xml │ │ ├── menu │ │ └── menu_main.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 │ │ ├── dimens.xml │ │ ├── strings.xml │ │ └── styles.xml │ └── test │ └── java │ └── com │ └── example │ └── ekene │ └── blogzone │ └── 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 | 5 | 6 | 7 | 19 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 46 | -------------------------------------------------------------------------------- /.idea/modules.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /.idea/runConfigurations.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 11 | 12 | -------------------------------------------------------------------------------- /app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 26 5 | buildToolsVersion "26.0.0" 6 | defaultConfig { 7 | applicationId "com.example.ekene.blogzone" 8 | minSdkVersion 16 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(dir: 'libs', include: ['*.jar']) 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.+' 28 | compile 'com.android.support:design:26.+' 29 | compile 'com.firebaseui:firebase-ui-database:0.4.4' 30 | compile 'com.google.firebase:firebase-auth:10.0.1' 31 | compile 'com.google.firebase:firebase-core:10.0.1' 32 | compile 'com.google.firebase:firebase-storage:10.0.1' 33 | compile 'com.android.support:cardview-v7:26.0.0-alpha1' 34 | compile 'com.android.support:recyclerview-v7:26.0.0-alpha1' 35 | compile 'com.google.firebase:firebase-database:10.0.1' 36 | compile 'com.squareup.picasso:picasso:2.5.2' 37 | compile 'com.theartofdev.edmodo:android-image-cropper:2.5.+' 38 | compile 'com.android.support.constraint:constraint-layout:1.0.2' 39 | testCompile 'junit:junit:4.12' 40 | } 41 | apply plugin: 'com.google.gms.google-services' -------------------------------------------------------------------------------- /app/google-services.json: -------------------------------------------------------------------------------- 1 | { 2 | "project_info": { 3 | "project_number": "800594296385", 4 | "firebase_url": "https://myblog-97550.firebaseio.com", 5 | "project_id": "myblog-97550", 6 | "storage_bucket": "myblog-97550.appspot.com" 7 | }, 8 | "client": [ 9 | { 10 | "client_info": { 11 | "mobilesdk_app_id": "1:800594296385:android:13ecad4fa52ac53a", 12 | "android_client_info": { 13 | "package_name": "com.example.ekene.myblog" 14 | } 15 | }, 16 | "oauth_client": [ 17 | { 18 | "client_id": "800594296385-ae23anavb41s9l1tsr5k7ccbftvg635o.apps.googleusercontent.com", 19 | "client_type": 1, 20 | "android_info": { 21 | "package_name": "com.example.ekene.myblog", 22 | "certificate_hash": "89df3f7b512058ac1f255f51d70722c99d8f025d" 23 | } 24 | }, 25 | { 26 | "client_id": "800594296385-9fp3npea2jipmhf0i67riqoq82hiu2l4.apps.googleusercontent.com", 27 | "client_type": 3 28 | } 29 | ], 30 | "api_key": [ 31 | { 32 | "current_key": "AIzaSyBJem7nAJBfyIo-jMkCwBIdtjWWtEvGSoE" 33 | } 34 | ], 35 | "services": { 36 | "analytics_service": { 37 | "status": 1 38 | }, 39 | "appinvite_service": { 40 | "status": 2, 41 | "other_platform_oauth_client": [ 42 | { 43 | "client_id": "800594296385-9fp3npea2jipmhf0i67riqoq82hiu2l4.apps.googleusercontent.com", 44 | "client_type": 3 45 | } 46 | ] 47 | }, 48 | "ads_service": { 49 | "status": 2 50 | } 51 | } 52 | }, 53 | { 54 | "client_info": { 55 | "mobilesdk_app_id": "1:800594296385:android:583ee094a94d9c05", 56 | "android_client_info": { 57 | "package_name": "com.example.ekene.blogzone" 58 | } 59 | }, 60 | "oauth_client": [ 61 | { 62 | "client_id": "800594296385-r9aokq2l1dmr9tadhggpp08svr4lq4sm.apps.googleusercontent.com", 63 | "client_type": 1, 64 | "android_info": { 65 | "package_name": "com.example.ekene.blogzone", 66 | "certificate_hash": "89df3f7b512058ac1f255f51d70722c99d8f025d" 67 | } 68 | }, 69 | { 70 | "client_id": "800594296385-9fp3npea2jipmhf0i67riqoq82hiu2l4.apps.googleusercontent.com", 71 | "client_type": 3 72 | } 73 | ], 74 | "api_key": [ 75 | { 76 | "current_key": "AIzaSyBJem7nAJBfyIo-jMkCwBIdtjWWtEvGSoE" 77 | } 78 | ], 79 | "services": { 80 | "analytics_service": { 81 | "status": 1 82 | }, 83 | "appinvite_service": { 84 | "status": 2, 85 | "other_platform_oauth_client": [ 86 | { 87 | "client_id": "800594296385-9fp3npea2jipmhf0i67riqoq82hiu2l4.apps.googleusercontent.com", 88 | "client_type": 3 89 | } 90 | ] 91 | }, 92 | "ads_service": { 93 | "status": 2 94 | } 95 | } 96 | } 97 | ], 98 | "configuration_version": "1" 99 | } -------------------------------------------------------------------------------- /app/libs/josephdalughut-skout-bd41074eead3.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/libs/josephdalughut-skout-bd41074eead3.zip -------------------------------------------------------------------------------- /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:\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 | 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/example/ekene/blogzone/ExampleInstrumentedTest.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 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.ekene.blogzone", appContext.getPackageName()); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /app/src/main/AndroidManifest.xml: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 15 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 27 | 28 | 29 | 30 | 33 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/Blogzone.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 2 | 3 | /** 4 | * Created by EKENE on 11/4/2017. 5 | */ 6 | 7 | public class Blogzone { 8 | 9 | private String title, desc, imageUrl, username; 10 | 11 | public Blogzone(String title, String desc, String imageUrl, String username) { 12 | this.title = title; 13 | this.desc = desc; 14 | this.imageUrl=imageUrl; 15 | this.username = username; 16 | } 17 | 18 | public Blogzone() { 19 | } 20 | 21 | public void setImageUrl(String imageUrl) { 22 | this.imageUrl = imageUrl; 23 | } 24 | 25 | public String getUsername() { 26 | return username; 27 | } 28 | 29 | public void setUsername(String username) { 30 | this.username = username; 31 | } 32 | public void setTitle(String title) { 33 | this.title = title; 34 | } 35 | 36 | public void setDesc(String desc) { 37 | this.desc = desc; 38 | } 39 | 40 | public String getImageUrl() { 41 | return imageUrl; 42 | } 43 | 44 | public String getTitle() { 45 | return title; 46 | } 47 | 48 | public String getDesc() { 49 | return desc; 50 | } 51 | 52 | } 53 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/LoginActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 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.text.TextUtils; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.EditText; 11 | import android.widget.Toast; 12 | 13 | import com.google.android.gms.tasks.OnCompleteListener; 14 | import com.google.android.gms.tasks.Task; 15 | import com.google.firebase.auth.AuthResult; 16 | import com.google.firebase.auth.FirebaseAuth; 17 | import com.google.firebase.database.DataSnapshot; 18 | import com.google.firebase.database.DatabaseError; 19 | import com.google.firebase.database.DatabaseReference; 20 | import com.google.firebase.database.FirebaseDatabase; 21 | import com.google.firebase.database.ValueEventListener; 22 | 23 | public class LoginActivity extends AppCompatActivity { 24 | private EditText loginEmail, loginPass; 25 | private FirebaseAuth mAuth; 26 | private DatabaseReference mDatabase; 27 | private Button loginBtn; 28 | 29 | @Override 30 | protected void onCreate(Bundle savedInstanceState) { 31 | super.onCreate(savedInstanceState); 32 | setContentView(R.layout.activity_login); 33 | 34 | loginBtn = (Button)findViewById(R.id.loginBtn); 35 | loginEmail = (EditText)findViewById(R.id.login_email); 36 | loginPass = (EditText)findViewById(R.id.login_password); 37 | 38 | mAuth = FirebaseAuth.getInstance(); 39 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Users"); 40 | 41 | loginBtn.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View view) { 44 | Toast.makeText(LoginActivity.this, "PROCESSING....", Toast.LENGTH_LONG).show(); 45 | String email = loginEmail.getText().toString().trim(); 46 | String password = loginPass.getText().toString().trim(); 47 | 48 | if (!TextUtils.isEmpty(email)&& !TextUtils.isEmpty(password)){ 49 | 50 | mAuth.signInWithEmailAndPassword(email,password).addOnCompleteListener(new OnCompleteListener() { 51 | @Override 52 | public void onComplete(@NonNull Task task) { 53 | if (task.isSuccessful()){ 54 | checkUserExistence(); 55 | }else { 56 | Toast.makeText(LoginActivity.this, "Couldn't login, User not found", Toast.LENGTH_SHORT).show(); 57 | } 58 | } 59 | }); 60 | }else { 61 | 62 | Toast.makeText(LoginActivity.this, "Complete all fields", Toast.LENGTH_SHORT).show(); 63 | } 64 | } 65 | }); 66 | } 67 | 68 | public void checkUserExistence(){ 69 | 70 | final String user_id = mAuth.getCurrentUser().getUid(); 71 | mDatabase.addValueEventListener(new ValueEventListener() { 72 | @Override 73 | public void onDataChange(DataSnapshot dataSnapshot) { 74 | 75 | if (dataSnapshot.hasChild(user_id)){ 76 | startActivity(new Intent(LoginActivity.this, MainActivity.class)); 77 | }else { 78 | Toast.makeText(LoginActivity.this, "User not registered!", Toast.LENGTH_SHORT).show(); 79 | } 80 | } 81 | 82 | @Override 83 | public void onCancelled(DatabaseError databaseError) { 84 | 85 | } 86 | }); 87 | } 88 | } 89 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/MainActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 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.design.widget.Snackbar; 9 | import android.support.v7.app.AppCompatActivity; 10 | import android.support.v7.widget.LinearLayoutManager; 11 | import android.support.v7.widget.RecyclerView; 12 | import android.support.v7.widget.Toolbar; 13 | import android.view.View; 14 | import android.view.Menu; 15 | import android.view.MenuItem; 16 | import android.widget.Button; 17 | import android.widget.ImageButton; 18 | import android.widget.ImageView; 19 | import android.widget.TextView; 20 | import android.widget.Toast; 21 | 22 | import com.firebase.ui.database.FirebaseRecyclerAdapter; 23 | import com.google.firebase.auth.FirebaseAuth; 24 | import com.google.firebase.database.DatabaseReference; 25 | import com.google.firebase.database.FirebaseDatabase; 26 | import com.squareup.picasso.Picasso; 27 | public class MainActivity extends AppCompatActivity { 28 | private RecyclerView recyclerView; 29 | private DatabaseReference mDatabase; 30 | private FirebaseAuth mAuth; 31 | private FirebaseAuth.AuthStateListener mAuthListener; 32 | @Override 33 | protected void onCreate(Bundle savedInstanceState) { 34 | super.onCreate(savedInstanceState); 35 | setContentView(R.layout.activity_main); 36 | Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); 37 | setSupportActionBar(toolbar); 38 | //initialize recyclerview and FIrebase objects 39 | recyclerView = (RecyclerView)findViewById(R.id.recyclerview); 40 | recyclerView.setLayoutManager(new LinearLayoutManager(this)); 41 | recyclerView.setHasFixedSize(true); 42 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Blogzone"); 43 | mAuth = FirebaseAuth.getInstance(); 44 | mAuthListener = new FirebaseAuth.AuthStateListener() { 45 | @Override 46 | public void onAuthStateChanged(@NonNull FirebaseAuth firebaseAuth) { 47 | if (mAuth.getCurrentUser()==null){ 48 | Intent loginIntent = new Intent(MainActivity.this, RegisterActivity.class); 49 | loginIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TASK);startActivity(loginIntent); 50 | } 51 | } 52 | }; 53 | } 54 | @Override 55 | protected void onStart() { 56 | super.onStart(); 57 | mAuth.addAuthStateListener(mAuthListener); 58 | FirebaseRecyclerAdapter FBRA = new FirebaseRecyclerAdapter( 59 | Blogzone.class, 60 | R.layout.card_items, 61 | BlogzoneViewHolder.class, 62 | mDatabase 63 | ) { 64 | @Override 65 | protected void populateViewHolder(BlogzoneViewHolder viewHolder, Blogzone model, int position) { 66 | final String post_key = getRef(position).getKey().toString(); 67 | viewHolder.setTitle(model.getTitle()); 68 | viewHolder.setDesc(model.getDesc()); 69 | viewHolder.setImageUrl(getApplicationContext(), model.getImageUrl()); 70 | viewHolder.setUserName(model.getUsername()); 71 | viewHolder.mView.setOnClickListener(new View.OnClickListener() { 72 | @Override 73 | public void onClick(View view) { 74 | Intent singleActivity = new Intent(MainActivity.this, SinglePostActivity.class); 75 | singleActivity.putExtra("PostID", post_key); 76 | startActivity(singleActivity); 77 | } 78 | }); 79 | } 80 | }; 81 | recyclerView.setAdapter(FBRA); 82 | } 83 | public static class BlogzoneViewHolder extends RecyclerView.ViewHolder{ 84 | View mView; 85 | public BlogzoneViewHolder(View itemView) { 86 | super(itemView); 87 | mView = itemView; 88 | } 89 | public void setTitle(String title){ 90 | TextView post_title = mView.findViewById(R.id.post_title_txtview); 91 | post_title.setText(title); 92 | } 93 | public void setDesc(String desc){ 94 | TextView post_desc = mView.findViewById(R.id.post_desc_txtview); 95 | post_desc.setText(desc); 96 | } 97 | public void setImageUrl(Context ctx, String imageUrl){ 98 | ImageView post_image = mView.findViewById(R.id.post_image); 99 | Picasso.with(ctx).load(imageUrl).into(post_image); 100 | } 101 | public void setUserName(String userName){ 102 | TextView postUserName = mView.findViewById(R.id.post_user); 103 | postUserName.setText(userName); 104 | } 105 | } 106 | @Override 107 | public boolean onCreateOptionsMenu(Menu menu) { 108 | // Inflate the menu; this adds items to the action bar if it is present. 109 | getMenuInflater().inflate(R.menu.menu_main, menu); 110 | return true; 111 | } 112 | @Override 113 | public boolean onOptionsItemSelected(MenuItem item) { 114 | int id = item.getItemId(); 115 | if (id == R.id.action_settings) { 116 | return true; 117 | } 118 | else if (id == R.id.action_add) { 119 | startActivity(new Intent(MainActivity.this, PostActivity.class)); 120 | } else if (id == R.id.logout){ 121 | mAuth.signOut(); 122 | Intent logouIntent = new Intent(MainActivity.this, RegisterActivity.class); 123 | logouIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 124 | startActivity(logouIntent); 125 | } 126 | return super.onOptionsItemSelected(item); 127 | } 128 | } 129 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/PostActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 2 | 3 | import android.app.ProgressDialog; 4 | import android.content.Intent; 5 | import android.net.Uri; 6 | import android.support.annotation.NonNull; 7 | import android.support.v7.app.AppCompatActivity; 8 | import android.os.Bundle; 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.ImageView; 15 | import android.widget.ProgressBar; 16 | import android.widget.Toast; 17 | 18 | import com.google.android.gms.tasks.OnCompleteListener; 19 | import com.google.android.gms.tasks.OnSuccessListener; 20 | import com.google.android.gms.tasks.Task; 21 | import com.google.firebase.FirebaseApp; 22 | import com.google.firebase.auth.FirebaseAuth; 23 | import com.google.firebase.auth.FirebaseUser; 24 | import com.google.firebase.database.DataSnapshot; 25 | import com.google.firebase.database.DatabaseError; 26 | import com.google.firebase.database.DatabaseReference; 27 | import com.google.firebase.database.FirebaseDatabase; 28 | import com.google.firebase.database.ValueEventListener; 29 | import com.google.firebase.storage.FirebaseStorage; 30 | import com.google.firebase.storage.StorageReference; 31 | import com.google.firebase.storage.UploadTask; 32 | import com.squareup.picasso.Picasso; 33 | 34 | public class PostActivity extends AppCompatActivity { 35 | // imports 36 | private ImageButton imageBtn; 37 | private static final int GALLERY_REQUEST_CODE = 2; 38 | private Uri uri = null; 39 | private EditText textTitle; 40 | private EditText textDesc; 41 | private Button postBtn; 42 | private StorageReference storage; 43 | private FirebaseDatabase database; 44 | private DatabaseReference databaseRef; 45 | private FirebaseAuth mAuth; 46 | private DatabaseReference mDatabaseUsers; 47 | private FirebaseUser mCurrentUser; 48 | 49 | @Override 50 | protected void onCreate(Bundle savedInstanceState) { 51 | super.onCreate(savedInstanceState); 52 | setContentView(R.layout.activity_post); 53 | // initializing objects 54 | postBtn = (Button)findViewById(R.id.postBtn); 55 | textDesc = (EditText)findViewById(R.id.textDesc); 56 | textTitle = (EditText)findViewById(R.id.textTitle); 57 | storage = FirebaseStorage.getInstance().getReference(); 58 | databaseRef = database.getInstance().getReference().child("Blogzone"); 59 | mAuth = FirebaseAuth.getInstance(); 60 | mCurrentUser = mAuth.getCurrentUser(); 61 | mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users").child(mCurrentUser.getUid()); 62 | imageBtn = (ImageButton)findViewById(R.id.imageBtn); 63 | //picking image from gallery 64 | imageBtn.setOnClickListener(new View.OnClickListener() { 65 | @Override 66 | public void onClick(View view) { 67 | Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT); 68 | galleryIntent.setType("image/*"); 69 | startActivityForResult(galleryIntent, GALLERY_REQUEST_CODE); 70 | } 71 | }); 72 | // posting to Firebase 73 | postBtn.setOnClickListener(new View.OnClickListener() { 74 | @Override 75 | public void onClick(View view) { 76 | Toast.makeText(PostActivity.this, "POSTING...", Toast.LENGTH_LONG).show(); 77 | final String PostTitle = textTitle.getText().toString().trim(); 78 | final String PostDesc = textDesc.getText().toString().trim(); 79 | // do a check for empty fields 80 | if (!TextUtils.isEmpty(PostDesc) && !TextUtils.isEmpty(PostTitle)){ 81 | StorageReference filepath = storage.child("post_images").child(uri.getLastPathSegment()); 82 | filepath.putFile(uri).addOnSuccessListener(new OnSuccessListener() { 83 | @Override 84 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 85 | 86 | @SuppressWarnings("VisibleForTests") 87 | //getting the post image download url 88 | final Uri downloadUrl = taskSnapshot.getDownloadUrl(); 89 | Toast.makeText(getApplicationContext(), "Succesfully Uploaded", Toast.LENGTH_SHORT).show(); 90 | final DatabaseReference newPost = databaseRef.push(); 91 | //adding post contents to database reference 92 | mDatabaseUsers.addValueEventListener(new ValueEventListener() { 93 | @Override 94 | public void onDataChange(DataSnapshot dataSnapshot) { 95 | newPost.child("title").setValue(PostTitle); 96 | newPost.child("desc").setValue(PostDesc); 97 | newPost.child("imageUrl").setValue(downloadUrl.toString()); 98 | newPost.child("uid").setValue(mCurrentUser.getUid()); 99 | newPost.child("username").setValue(dataSnapshot.child("name").getValue()) 100 | .addOnCompleteListener(new OnCompleteListener() { 101 | @Override 102 | public void onComplete(@NonNull Task task) { 103 | 104 | if (task.isSuccessful()){ 105 | Intent intent = new Intent(PostActivity.this, MainActivity.class); 106 | startActivity(intent); 107 | } 108 | } 109 | }); 110 | } 111 | 112 | @Override 113 | public void onCancelled(DatabaseError databaseError) { 114 | 115 | } 116 | }); 117 | } 118 | }); 119 | 120 | } 121 | } 122 | }); 123 | 124 | } 125 | 126 | @Override 127 | // image from gallery result 128 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 129 | super.onActivityResult(requestCode, resultCode, data); 130 | 131 | if (requestCode == GALLERY_REQUEST_CODE && resultCode == RESULT_OK){ 132 | uri = data.getData(); 133 | imageBtn.setImageURI(uri); 134 | } 135 | } 136 | } 137 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/ProfileActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 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.text.TextUtils; 8 | import android.view.View; 9 | import android.widget.Button; 10 | import android.widget.EditText; 11 | import android.widget.ImageButton; 12 | import android.widget.Toast; 13 | 14 | import com.google.android.gms.tasks.OnSuccessListener; 15 | import com.google.firebase.auth.FirebaseAuth; 16 | import com.google.firebase.database.DatabaseReference; 17 | import com.google.firebase.database.FirebaseDatabase; 18 | import com.google.firebase.storage.FirebaseStorage; 19 | import com.google.firebase.storage.StorageReference; 20 | import com.google.firebase.storage.UploadTask; 21 | import com.theartofdev.edmodo.cropper.CropImage; 22 | import com.theartofdev.edmodo.cropper.CropImageView; 23 | //import com.theartofdev.edmodo.cropper.CropImage; 24 | //import com.theartofdev.edmodo.cropper.CropImageView; 25 | 26 | public class ProfileActivity extends AppCompatActivity { 27 | 28 | private EditText profUserName; 29 | private ImageButton imageButton; 30 | private final static int GALLERY_REQ = 1; 31 | private Button doneBtn; 32 | private Uri mImageUri = null; 33 | private FirebaseAuth mAuth; 34 | private DatabaseReference mDatabaseUsers; 35 | private StorageReference mStorageRef; 36 | 37 | @Override 38 | protected void onCreate(Bundle savedInstanceState) { 39 | super.onCreate(savedInstanceState); 40 | setContentView(R.layout.activity_profile); 41 | 42 | mAuth = FirebaseAuth.getInstance(); 43 | mDatabaseUsers = FirebaseDatabase.getInstance().getReference().child("Users"); 44 | mStorageRef = FirebaseStorage.getInstance().getReference().child("profile_images"); 45 | profUserName = (EditText)findViewById(R.id.profUserName); 46 | imageButton = (ImageButton)findViewById(R.id.imagebutton); 47 | doneBtn = (Button)findViewById(R.id.doneBtn); 48 | 49 | imageButton.setOnClickListener(new View.OnClickListener() { 50 | @Override 51 | public void onClick(View view) { 52 | 53 | 54 | Intent galleryIntent = new Intent(Intent.ACTION_GET_CONTENT); 55 | galleryIntent.setType("image/*"); 56 | startActivityForResult(galleryIntent, GALLERY_REQ); 57 | } 58 | }); 59 | 60 | doneBtn.setOnClickListener(new View.OnClickListener() { 61 | @Override 62 | public void onClick(View view) { 63 | final String name = profUserName.getText().toString().trim(); 64 | final String userID = mAuth.getCurrentUser().getUid(); 65 | if (!TextUtils.isEmpty(name) && mImageUri != null){ 66 | 67 | StorageReference filepath = mStorageRef.child(mImageUri.getLastPathSegment()); 68 | filepath.putFile(mImageUri).addOnSuccessListener(new OnSuccessListener() { 69 | @Override 70 | public void onSuccess(UploadTask.TaskSnapshot taskSnapshot) { 71 | @SuppressWarnings("VisibleForTests") 72 | String downloadUrl = taskSnapshot.getDownloadUrl().toString(); 73 | mDatabaseUsers.child(userID).child("name").setValue(name); 74 | mDatabaseUsers.child(userID).child("image").setValue(downloadUrl); 75 | 76 | Toast.makeText(ProfileActivity.this, "Successful", Toast.LENGTH_SHORT).show(); 77 | Intent i = new Intent(ProfileActivity.this, LoginActivity.class); 78 | startActivity(i); 79 | } 80 | }); 81 | 82 | } 83 | } 84 | }); 85 | 86 | } 87 | @Override 88 | protected void onActivityResult(int requestCode, int resultCode, Intent data) { 89 | super.onActivityResult(requestCode, resultCode, data); 90 | 91 | if (requestCode == GALLERY_REQ && resultCode == RESULT_OK){ 92 | 93 | Uri imageUri = data.getData(); 94 | CropImage.activity(imageUri) 95 | .setGuidelines(CropImageView.Guidelines.ON) 96 | .setAspectRatio(1,1) 97 | .start(this); 98 | } 99 | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE){ 100 | CropImage.ActivityResult result = CropImage.getActivityResult(data); 101 | if (resultCode == RESULT_OK){ 102 | mImageUri = result.getUri(); 103 | imageButton.setImageURI(mImageUri); 104 | }else { 105 | if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE){ 106 | Exception err = result.getError(); 107 | } 108 | } 109 | } 110 | } 111 | 112 | } 113 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/RegisterActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 2 | 3 | import android.content.Intent; 4 | import android.support.annotation.MainThread; 5 | import android.support.annotation.NonNull; 6 | import android.support.v7.app.AppCompatActivity; 7 | import android.os.Bundle; 8 | import android.text.TextUtils; 9 | import android.view.View; 10 | import android.widget.Button; 11 | import android.widget.EditText; 12 | import android.widget.TextView; 13 | import android.widget.Toast; 14 | 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 | private Button registerBtn; 24 | private EditText emailField, usernameField, passwordField; 25 | private FirebaseAuth mAuth; 26 | private DatabaseReference mDatabase; 27 | private TextView loginTxtView; 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_register); 32 | 33 | loginTxtView = (TextView)findViewById(R.id.loginTxtView); 34 | registerBtn = (Button)findViewById(R.id.registerBtn); 35 | emailField = (EditText)findViewById(R.id.emailField); 36 | usernameField = (EditText)findViewById(R.id.usernameField); 37 | passwordField = (EditText)findViewById(R.id.passwordField); 38 | mAuth = FirebaseAuth.getInstance(); 39 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Users"); 40 | loginTxtView.setOnClickListener(new View.OnClickListener() { 41 | @Override 42 | public void onClick(View view) { 43 | startActivity(new Intent(RegisterActivity.this, LoginActivity.class)); 44 | } 45 | }); 46 | registerBtn.setOnClickListener(new View.OnClickListener() { 47 | @Override 48 | public void onClick(View view) { 49 | Toast.makeText(RegisterActivity.this, "LOADING...", Toast.LENGTH_LONG).show(); 50 | final String username = usernameField.getText().toString().trim(); 51 | final String email = emailField.getText().toString().trim(); 52 | final String password = passwordField.getText().toString().trim(); 53 | if (!TextUtils.isEmpty(email) && !TextUtils.isEmpty(username)&&!TextUtils.isEmpty(password)){ 54 | mAuth.createUserWithEmailAndPassword(email, password).addOnCompleteListener(new OnCompleteListener() { 55 | @Override 56 | public void onComplete(@NonNull Task task) { 57 | String user_id = mAuth.getCurrentUser().getUid(); 58 | DatabaseReference current_user_db = mDatabase.child(user_id); 59 | current_user_db.child("Username").setValue(username); 60 | current_user_db.child("Image").setValue("Default"); 61 | Toast.makeText(RegisterActivity.this, "Registeration Succesful", Toast.LENGTH_SHORT).show(); 62 | Intent regIntent = new Intent(RegisterActivity.this, ProfileActivity.class); 63 | regIntent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP); 64 | startActivity(regIntent); 65 | } 66 | }); 67 | }else { 68 | 69 | Toast.makeText(RegisterActivity.this, "Complete all fields", Toast.LENGTH_SHORT).show(); 70 | } 71 | } 72 | }); 73 | } 74 | } 75 | -------------------------------------------------------------------------------- /app/src/main/java/com/example/ekene/blogzone/SinglePostActivity.java: -------------------------------------------------------------------------------- 1 | package com.example.ekene.blogzone; 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 | import android.widget.ImageView; 9 | import android.widget.TextView; 10 | 11 | import com.google.firebase.auth.FirebaseAuth; 12 | import com.google.firebase.database.DataSnapshot; 13 | import com.google.firebase.database.DatabaseError; 14 | import com.google.firebase.database.DatabaseReference; 15 | import com.google.firebase.database.FirebaseDatabase; 16 | import com.google.firebase.database.ValueEventListener; 17 | import com.squareup.picasso.Picasso; 18 | 19 | public class SinglePostActivity extends AppCompatActivity { 20 | 21 | private ImageView singelImage; 22 | private TextView singleTitle, singleDesc; 23 | String post_key = null; 24 | private DatabaseReference mDatabase; 25 | private Button deleteBtn; 26 | private FirebaseAuth mAuth; 27 | 28 | @Override 29 | protected void onCreate(Bundle savedInstanceState) { 30 | super.onCreate(savedInstanceState); 31 | setContentView(R.layout.activity_single_post); 32 | 33 | singelImage = (ImageView)findViewById(R.id.singleImageview); 34 | singleTitle = (TextView)findViewById(R.id.singleTitle); 35 | singleDesc = (TextView)findViewById(R.id.singleDesc); 36 | mDatabase = FirebaseDatabase.getInstance().getReference().child("Blogzone"); 37 | post_key = getIntent().getExtras().getString("PostID"); 38 | deleteBtn = (Button)findViewById(R.id.deleteBtn); 39 | mAuth = FirebaseAuth.getInstance(); 40 | deleteBtn.setVisibility(View.INVISIBLE); 41 | deleteBtn.setOnClickListener(new View.OnClickListener() { 42 | @Override 43 | public void onClick(View view) { 44 | 45 | mDatabase.child(post_key).removeValue(); 46 | 47 | Intent mainintent = new Intent(SinglePostActivity.this, MainActivity.class); 48 | startActivity(mainintent); 49 | } 50 | }); 51 | 52 | 53 | mDatabase.child(post_key).addValueEventListener(new ValueEventListener() { 54 | @Override 55 | public void onDataChange(DataSnapshot dataSnapshot) { 56 | String post_title = (String) dataSnapshot.child("title").getValue(); 57 | String post_desc = (String) dataSnapshot.child("desc").getValue(); 58 | String post_image = (String) dataSnapshot.child("imageUrl").getValue(); 59 | String post_uid = (String) dataSnapshot.child("uid").getValue(); 60 | 61 | singleTitle.setText(post_title); 62 | singleDesc.setText(post_desc); 63 | Picasso.with(SinglePostActivity.this).load(post_image).into(singelImage); 64 | if (mAuth.getCurrentUser().getUid().equals(post_uid)){ 65 | 66 | deleteBtn.setVisibility(View.VISIBLE); 67 | } 68 | } 69 | 70 | @Override 71 | public void onCancelled(DatabaseError databaseError) { 72 | 73 | } 74 | }); 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/action_button_style.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/add_img.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/src/main/res/drawable/add_img.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/addicon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/src/main/res/drawable/addicon.png -------------------------------------------------------------------------------- /app/src/main/res/drawable/bg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/src/main/res/drawable/bg.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/bgg.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/src/main/res/drawable/bgg.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/buttonstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | 10 | 11 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/edit_text_styles.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 7 | 8 | 9 | 10 | 11 | 12 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/ic_add_black_24dp.xml: -------------------------------------------------------------------------------- 1 | 6 | 9 | 10 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/imag.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/src/main/res/drawable/imag.jpg -------------------------------------------------------------------------------- /app/src/main/res/drawable/layoutstyle.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 6 | 7 | 8 | 9 | -------------------------------------------------------------------------------- /app/src/main/res/drawable/lowres.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/kenny-io/Blogzone/4ed435cde1fc22dd839178023b7f6f508cf741cb/app/src/main/res/drawable/lowres.jpg -------------------------------------------------------------------------------- /app/src/main/res/layout/activity_login.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 20 | 21 | 31 | 32 | 42 | 43 | 53 | 54 |