-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
35 changed files
with
640 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
app/src/main/java/id/eightstudio/www/orderfoods/Common/Common.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
172
app/src/main/java/id/eightstudio/www/orderfoods/Home.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
app/src/main/java/id/eightstudio/www/orderfoods/Interface/ItemClickListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
35 changes: 35 additions & 0 deletions
35
app/src/main/java/id/eightstudio/www/orderfoods/Model/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...a/id/eightstudio/www/orderfoods/User.java → ...ightstudio/www/orderfoods/Model/User.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.