Skip to content

Commit

Permalink
Part 2
Browse files Browse the repository at this point in the history
  • Loading branch information
Danboru committed Nov 30, 2017
1 parent 35659f5 commit b130544
Show file tree
Hide file tree
Showing 35 changed files with 640 additions and 26 deletions.
6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 18 additions & 6 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,25 @@ android {
}

dependencies {
implementation fileTree(dir: 'libs', include: ['*.jar'])
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
testImplementation 'junit:junit:4.12'

androidTestImplementation 'com.android.support.test:runner:1.0.1'
androidTestImplementation 'com.android.support.test.espresso:espresso-core:3.0.1'
compile 'com.google.firebase:firebase-database:11.6.2'
compile 'com.google.firebase:firebase-core:11.6.2'
implementation fileTree(include: ['*.jar'], dir: 'libs')
annotationProcessor 'com.jakewharton:butterknife-compiler:8.8.1'
testImplementation 'junit:junit:4.12'
implementation 'com.android.support:appcompat-v7:26.1.0'
implementation 'com.android.support.constraint:constraint-layout:1.0.2'
implementation 'com.android.support:support-v4:26.1.0'
implementation 'com.android.support:design:26.1.0'
implementation 'com.android.support:recyclerview-v7:26.1.0'
implementation 'com.android.support:cardview-v7:26.1.0'
compile 'com.google.firebase:firebase-database:11.6.0'
compile 'com.jakewharton:butterknife:8.8.1'
compile 'com.firebaseui:firebase-ui-database:2.1.0'
compile 'com.squareup.picasso:picasso:2.5.2'
compile 'com.cepheuen.elegant-number-button:lib:1.0.2'
compile 'com.amulyakhare:com.amulyakhare.textdrawable:1.0.1'
compile 'com.readystatesoftware.sqliteasset:sqliteassethelper:+'

}
apply plugin: 'com.google.gms.google-services'
6 changes: 5 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
</intent-filter>
</activity>
<activity android:name=".Signin" />
<activity android:name=".Signup"></activity>
<activity android:name=".Signup" />
<activity
android:name=".Home"
android:label="@string/title_activity_home"
android:theme="@style/AppTheme.NoActionBar"></activity>
</application>

</manifest>
11 changes: 11 additions & 0 deletions app/src/main/java/id/eightstudio/www/orderfoods/Common/Common.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package id.eightstudio.www.orderfoods.Common;

import id.eightstudio.www.orderfoods.Model.User;

/**
* Created by danbo on 30/11/17.
*/

public class Common {
public static User currentUser;
}
172 changes: 172 additions & 0 deletions app/src/main/java/id/eightstudio/www/orderfoods/Home.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,172 @@
package id.eightstudio.www.orderfoods;

import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.support.design.widget.NavigationView;
import android.support.v4.view.GravityCompat;
import android.support.v4.widget.DrawerLayout;
import android.support.v7.app.ActionBarDrawerToggle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;

import com.firebase.ui.database.FirebaseIndexRecyclerAdapter;
import com.firebase.ui.database.FirebaseRecyclerAdapter;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.squareup.picasso.Picasso;

import id.eightstudio.www.orderfoods.Common.Common;
import id.eightstudio.www.orderfoods.Interface.ItemClickListener;
import id.eightstudio.www.orderfoods.Model.Category;
import id.eightstudio.www.orderfoods.ViewHolder.MenuViewHolder;

public class Home extends AppCompatActivity
implements NavigationView.OnNavigationItemSelectedListener {

FirebaseDatabase database;
DatabaseReference category;

TextView txtFullName;

RecyclerView recycler_menu;
RecyclerView.LayoutManager layoutManager;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);

Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
toolbar.setTitle("Menu");
setSupportActionBar(toolbar);

//Init Firebase
database = FirebaseDatabase.getInstance();
category = database.getReference("Category");

//Floating Action Bar
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});

//Drawer Layout
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.addDrawerListener(toggle);
toggle.syncState();

//NavigationView
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);

//Set FullName
View headerView = navigationView.getHeaderView(0);
txtFullName = headerView.findViewById(R.id.txtFullName);
txtFullName.setText(Common.currentUser.getName());

//Load Menu Firebase
recycler_menu = findViewById(R.id.recycler_menu);
recycler_menu.setHasFixedSize(true);
layoutManager = new LinearLayoutManager(this);
recycler_menu.setLayoutManager(layoutManager);

loadMenu();

}

private void loadMenu() {

FirebaseRecyclerAdapter<Category, MenuViewHolder> adapter = new FirebaseRecyclerAdapter<Category, MenuViewHolder>(
Category.class,
R.layout.menu_item,
MenuViewHolder.class,
category
) {
@Override
protected void populateViewHolder(MenuViewHolder viewHolder, Category model, int position) {
viewHolder.txtMenuName.setText(model.getName());
Picasso.with(Home.this).load(model.getImage()).into(viewHolder.imageView);
final Category clickItem = model;
viewHolder.setOnClickListener(new ItemClickListener() {
@Override
public void onClick(View view, int position, boolean isLonggerPress) {
Toast.makeText(Home.this, "" + clickItem.getName() , Toast.LENGTH_SHORT).show();
}
});

}
};

//Set RecyclerView Adapter
recycler_menu.setAdapter(adapter);

}

@Override
public void onBackPressed() {
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
if (drawer.isDrawerOpen(GravityCompat.START)) {
drawer.closeDrawer(GravityCompat.START);
} else {
super.onBackPressed();
}
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.home, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();

//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}

return super.onOptionsItemSelected(item);
}

@SuppressWarnings("StatementWithEmptyBody")
@Override
public boolean onNavigationItemSelected(MenuItem item) {

// Handle navigation view item clicks here.
int id = item.getItemId();

if (id == R.id.nav_menu) {

} else if (id == R.id.nav_cart) {

} else if (id == R.id.nav_orders) {

} else if (id == R.id.nav_log_out) {

}

DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
drawer.closeDrawer(GravityCompat.START);
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package id.eightstudio.www.orderfoods.Interface;

import android.view.View;

/**
* Created by danbo on 30/11/17.
*/

public interface ItemClickListener {
void onClick(View view, int position, boolean isLonggerPress);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package id.eightstudio.www.orderfoods.Model;

/**
* Created by danbo on 30/11/17.
*/

public class Category {

private String Name;
private String Image;

public Category() {
}

public Category(String name, String image) {
Name = name;
Image = image;
}

public String getName() {
return Name;
}

public void setName(String name) {
Name = name;
}

public String getImage() {
return Image;
}

public void setImage(String image) {
Image = image;
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package id.eightstudio.www.orderfoods;
package id.eightstudio.www.orderfoods.Model;

/**
* Created by danbo on 30/11/17.
Expand Down
24 changes: 14 additions & 10 deletions app/src/main/java/id/eightstudio/www/orderfoods/Signin.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
package id.eightstudio.www.orderfoods;

import android.app.ProgressDialog;
import android.content.Intent;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ProgressBar;
import android.widget.Toast;

import com.google.firebase.database.DataSnapshot;
Expand All @@ -15,6 +15,9 @@
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import id.eightstudio.www.orderfoods.Common.Common;
import id.eightstudio.www.orderfoods.Model.User;

public class Signin extends AppCompatActivity {

EditText edtPhone, edtPassword;
Expand Down Expand Up @@ -42,19 +45,20 @@ public void onClick(View v) {
progressBar.setMessage("Tunggu Sebentar");
progressBar.show();

final String phone, pass;
phone = edtPhone.getText().toString();
pass = edtPassword.getText().toString();

table_user.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {

if (dataSnapshot.child(phone).exists()) {
if (dataSnapshot.child(edtPhone.getText().toString()).exists()) {
progressBar.dismiss();
User user = dataSnapshot.child(phone).getValue(User.class);
if (user.getPassword().equals(pass)) {
Toast.makeText(Signin.this, "Berhasil", Toast.LENGTH_SHORT).show();
User user = dataSnapshot.child(edtPhone.getText().toString()).getValue(User.class);
if (user.getPassword().equals(edtPassword.getText().toString())) {

Intent intent = new Intent(Signin.this, Home.class);
Common.currentUser = user;
startActivity(intent);
finish();

} else {
Toast.makeText(Signin.this, "Gagal", Toast.LENGTH_SHORT).show();
}
Expand All @@ -66,7 +70,7 @@ public void onDataChange(DataSnapshot dataSnapshot) {

@Override
public void onCancelled(DatabaseError databaseError) {

Toast.makeText(Signin.this, "Server Bermasalah", Toast.LENGTH_SHORT).show();
}
});

Expand Down
12 changes: 5 additions & 7 deletions app/src/main/java/id/eightstudio/www/orderfoods/Signup.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;

import id.eightstudio.www.orderfoods.Model.User;

public class Signup extends AppCompatActivity {

EditText edtPhone, edtName, edtPassword;
Expand Down Expand Up @@ -44,23 +46,19 @@ public void onClick(View v) {
progressDialog.setMessage("Tunggu Sebentar");
progressDialog.show();

final String phone, name, password;
phone = edtPhone.getText().toString();
name = edtName.getText().toString();
password = edtPassword.getText().toString();

table_user.addValueEventListener(new ValueEventListener() {

@Override
public void onDataChange(DataSnapshot dataSnapshot) {

if (dataSnapshot.child(phone).exists()) {
if (dataSnapshot.child(edtPassword.getText().toString()).exists()) {
progressDialog.dismiss();
Toast.makeText(Signup.this, "Phone sudah terdaftar", Toast.LENGTH_SHORT).show();
} else {
progressDialog.dismiss();
User user = new User(name, password);
table_user.child(phone).setValue(user);
User user = new User(edtName.getText().toString(), edtPassword.getText().toString());
table_user.child(edtPhone.getText().toString()).setValue(user);
Toast.makeText(Signup.this, "Berhasil Registrasi", Toast.LENGTH_SHORT).show();
}
}
Expand Down
Loading

0 comments on commit b130544

Please sign in to comment.