mirror of
https://github.com/Nezumi-2711/PRM392.git
synced 2026-09-23 04:09:54 +00:00
Upload Foodify-Server
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package com.waterbase.foodifyServer.Common;
|
||||
|
||||
import com.waterbase.foodifyServer.Model.User;
|
||||
|
||||
public class Common {
|
||||
public static User currentUser;
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.waterbase.foodifyServer;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.Menu;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||
import androidx.appcompat.widget.Toolbar;
|
||||
import androidx.core.view.GravityCompat;
|
||||
import androidx.navigation.NavController;
|
||||
import androidx.navigation.Navigation;
|
||||
import androidx.navigation.ui.AppBarConfiguration;
|
||||
import androidx.navigation.ui.NavigationUI;
|
||||
import androidx.drawerlayout.widget.DrawerLayout;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import com.waterbase.foodifyServer.Common.Common;
|
||||
import com.waterbase.foodifyServer.databinding.ActivityHomeBinding;
|
||||
|
||||
public class Home extends AppCompatActivity implements NavigationView.OnNavigationItemSelectedListener{
|
||||
|
||||
TextView txtFullName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_home);
|
||||
|
||||
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
|
||||
toolbar.setTitle("Menu Management");
|
||||
setSupportActionBar(toolbar);
|
||||
|
||||
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.app_name, R.string.app_name);
|
||||
drawer.setDrawerListener(toggle);
|
||||
toggle.syncState();
|
||||
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
|
||||
navigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
//Set Name for user
|
||||
View headerView = navigationView.getHeaderView(0);
|
||||
txtFullName = (TextView) headerView.findViewById(R.id.txtFullName);
|
||||
txtFullName.setText(Common.currentUser.getName());
|
||||
|
||||
}
|
||||
|
||||
@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 onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
int id = item.getItemId();
|
||||
|
||||
|
||||
DrawerLayout drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
|
||||
drawerLayout.closeDrawer(GravityCompat.START);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,38 @@
|
||||
package com.waterbase.foodifyServer;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.TextView;
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
Button btnSignIn;
|
||||
TextView txtSlogan, txtAppName;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_main);
|
||||
|
||||
btnSignIn = (Button) findViewById(R.id.btnSignIn);
|
||||
txtSlogan = (TextView) findViewById(R.id.txtSlogan);
|
||||
txtAppName = (TextView) findViewById(R.id.txtAppName);
|
||||
|
||||
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/NABILA.TTF");
|
||||
txtSlogan.setTypeface(face);
|
||||
txtAppName.setTypeface(face);
|
||||
|
||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
Intent signIn = new Intent(MainActivity.this, SignIn.class);
|
||||
startActivity(signIn);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.waterbase.foodifyServer.Model;
|
||||
|
||||
public class User {
|
||||
private String Name, Password, Phone, IsStaff;
|
||||
|
||||
public User(String name, String password) {
|
||||
Name = name;
|
||||
Password = password;
|
||||
}
|
||||
|
||||
public User() {
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return Name;
|
||||
}
|
||||
|
||||
public void setName(String name) {
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return Password;
|
||||
}
|
||||
|
||||
public void setPassword(String password) {
|
||||
Password = password;
|
||||
}
|
||||
|
||||
public String getPhone() {
|
||||
return Phone;
|
||||
}
|
||||
|
||||
public void setPhone(String phone) {
|
||||
Phone = phone;
|
||||
}
|
||||
|
||||
public String getIsStaff() {
|
||||
return IsStaff;
|
||||
}
|
||||
|
||||
public void setIsStaff(String isStaff) {
|
||||
IsStaff = isStaff;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
package com.waterbase.foodifyServer;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.firebase.database.DataSnapshot;
|
||||
import com.google.firebase.database.DatabaseError;
|
||||
import com.google.firebase.database.DatabaseReference;
|
||||
import com.google.firebase.database.FirebaseDatabase;
|
||||
import com.google.firebase.database.ValueEventListener;
|
||||
import com.waterbase.foodifyServer.Common.Common;
|
||||
import com.waterbase.foodifyServer.Model.User;
|
||||
|
||||
public class SignIn extends AppCompatActivity {
|
||||
|
||||
EditText edtPhone, edtPassword;
|
||||
Button btnSignIn;
|
||||
|
||||
TextView txtAppName;
|
||||
|
||||
FirebaseDatabase db;
|
||||
DatabaseReference users;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_sign_in);
|
||||
|
||||
edtPassword = (EditText) findViewById(R.id.edtPassword);
|
||||
edtPhone = (EditText) findViewById(R.id.edtPhone);
|
||||
btnSignIn = (Button) findViewById(R.id.btnSignIn);
|
||||
txtAppName = (TextView) findViewById(R.id.txtAppName);
|
||||
|
||||
Typeface face = Typeface.createFromAsset(getAssets(), "fonts/NABILA.TTF");
|
||||
txtAppName.setTypeface(face);
|
||||
|
||||
//Init Firebase
|
||||
db = FirebaseDatabase.getInstance();
|
||||
users = db.getReference("User");
|
||||
|
||||
btnSignIn.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
signInUser(edtPhone.getText().toString(), edtPassword.getText().toString());
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
private void signInUser(String phone, String password) {
|
||||
final ProgressDialog mDialog = new ProgressDialog(SignIn.this);
|
||||
mDialog.setMessage("Vui lòng chờ...");
|
||||
mDialog.show();
|
||||
|
||||
final String localPhone = phone;
|
||||
final String localPassword = password;
|
||||
users.addValueEventListener(new ValueEventListener() {
|
||||
@Override
|
||||
public void onDataChange(DataSnapshot dataSnapshot) {
|
||||
if (dataSnapshot.child(localPhone).exists()) {
|
||||
mDialog.dismiss();
|
||||
User user = dataSnapshot.child(localPhone).getValue(User.class);
|
||||
user.setPhone(localPhone);
|
||||
if (Boolean.parseBoolean(user.getIsStaff())) //If isStaff = true
|
||||
{
|
||||
if (user.getPassword().equals(localPassword)) {
|
||||
//Login ok
|
||||
Intent login = new Intent(SignIn.this, Home.class);
|
||||
Common.currentUser = user;
|
||||
startActivity(login);
|
||||
finish();
|
||||
} else
|
||||
Toast.makeText(SignIn.this, "Wrong password!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else
|
||||
Toast.makeText(SignIn.this, "Please login with Staff account!", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
else {
|
||||
mDialog.dismiss();
|
||||
Toast.makeText(SignIn.this, "User not exist in Database", Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancelled(DatabaseError databaseError) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user