diff --git a/FoodifyServer/.gitignore b/FoodifyServer/.gitignore new file mode 100644 index 0000000..aa724b7 --- /dev/null +++ b/FoodifyServer/.gitignore @@ -0,0 +1,15 @@ +*.iml +.gradle +/local.properties +/.idea/caches +/.idea/libraries +/.idea/modules.xml +/.idea/workspace.xml +/.idea/navEditor.xml +/.idea/assetWizardSettings.xml +.DS_Store +/build +/captures +.externalNativeBuild +.cxx +local.properties diff --git a/FoodifyServer/app/.gitignore b/FoodifyServer/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/FoodifyServer/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/FoodifyServer/app/build.gradle b/FoodifyServer/app/build.gradle new file mode 100644 index 0000000..79ea59b --- /dev/null +++ b/FoodifyServer/app/build.gradle @@ -0,0 +1,52 @@ +plugins { + id 'com.android.application' +} + +android { + compileSdk 32 + + defaultConfig { + applicationId "com.waterbase.foodifyServer" + minSdk 23 + targetSdk 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_1_8 + targetCompatibility JavaVersion.VERSION_1_8 + } + buildFeatures { + viewBinding true + } +} + +dependencies { + + implementation 'androidx.appcompat:appcompat:1.4.1' + implementation 'com.google.android.material:material:1.6.0' + implementation 'androidx.constraintlayout:constraintlayout:2.1.4' + implementation 'androidx.lifecycle:lifecycle-livedata-ktx:2.4.1' + implementation 'androidx.lifecycle:lifecycle-viewmodel-ktx:2.4.1' + implementation 'androidx.navigation:navigation-fragment:2.4.2' + implementation 'androidx.navigation:navigation-ui:2.4.2' + testImplementation 'junit:junit:4.13.2' + androidTestImplementation 'androidx.test.ext:junit:1.1.3' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.4.0' + + + //Add library + implementation 'com.google.firebase:firebase-core:10.2.0' + implementation 'com.google.firebase:firebase-database:10.2.0' +} + +apply plugin: 'com.google.gms.google-services' \ No newline at end of file diff --git a/FoodifyServer/app/proguard-rules.pro b/FoodifyServer/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/FoodifyServer/app/proguard-rules.pro @@ -0,0 +1,21 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-renamesourcefileattribute SourceFile \ No newline at end of file diff --git a/FoodifyServer/app/src/androidTest/java/com/waterbase/foodifyServer/ExampleInstrumentedTest.java b/FoodifyServer/app/src/androidTest/java/com/waterbase/foodifyServer/ExampleInstrumentedTest.java new file mode 100644 index 0000000..1804c68 --- /dev/null +++ b/FoodifyServer/app/src/androidTest/java/com/waterbase/foodifyServer/ExampleInstrumentedTest.java @@ -0,0 +1,26 @@ +package com.waterbase.foodifyServer; + +import android.content.Context; + +import androidx.test.platform.app.InstrumentationRegistry; +import androidx.test.ext.junit.runners.AndroidJUnit4; + +import org.junit.Test; +import org.junit.runner.RunWith; + +import static org.junit.Assert.*; + +/** + * Instrumented test, which will execute on an Android device. + * + * @see Testing documentation + */ +@RunWith(AndroidJUnit4.class) +public class ExampleInstrumentedTest { + @Test + public void useAppContext() { + // Context of the app under test. + Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext(); + assertEquals("com.waterbase.foodifyServer", appContext.getPackageName()); + } +} \ No newline at end of file diff --git a/FoodifyServer/app/src/main/AndroidManifest.xml b/FoodifyServer/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..9c5baa9 --- /dev/null +++ b/FoodifyServer/app/src/main/AndroidManifest.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/FoodifyServer/app/src/main/assets/fonts/NABILA.TTF b/FoodifyServer/app/src/main/assets/fonts/NABILA.TTF new file mode 100644 index 0000000..4f74aff Binary files /dev/null and b/FoodifyServer/app/src/main/assets/fonts/NABILA.TTF differ diff --git a/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Common/Common.java b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Common/Common.java new file mode 100644 index 0000000..04c0921 --- /dev/null +++ b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Common/Common.java @@ -0,0 +1,7 @@ +package com.waterbase.foodifyServer.Common; + +import com.waterbase.foodifyServer.Model.User; + +public class Common { + public static User currentUser; +} diff --git a/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Home.java b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Home.java new file mode 100644 index 0000000..a39dcae --- /dev/null +++ b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Home.java @@ -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; + } +} \ No newline at end of file diff --git a/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/MainActivity.java b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/MainActivity.java new file mode 100644 index 0000000..5af6fd9 --- /dev/null +++ b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/MainActivity.java @@ -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); + } + }); + } +} \ No newline at end of file diff --git a/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Model/User.java b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Model/User.java new file mode 100644 index 0000000..5c89da0 --- /dev/null +++ b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/Model/User.java @@ -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; + } +} diff --git a/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/SignIn.java b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/SignIn.java new file mode 100644 index 0000000..4d05c60 --- /dev/null +++ b/FoodifyServer/app/src/main/java/com/waterbase/foodifyServer/SignIn.java @@ -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) { + + } + }); + } +} \ No newline at end of file diff --git a/FoodifyServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml b/FoodifyServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml new file mode 100644 index 0000000..2b068d1 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable-v24/ic_launcher_foreground.xml @@ -0,0 +1,30 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/FoodifyServer/app/src/main/res/drawable/background.jpg b/FoodifyServer/app/src/main/res/drawable/background.jpg new file mode 100644 index 0000000..4657f61 Binary files /dev/null and b/FoodifyServer/app/src/main/res/drawable/background.jpg differ diff --git a/FoodifyServer/app/src/main/res/drawable/btn_bg_design.xml b/FoodifyServer/app/src/main/res/drawable/btn_bg_design.xml new file mode 100644 index 0000000..82b141c --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/btn_bg_design.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/FoodifyServer/app/src/main/res/drawable/foreground_design.xml b/FoodifyServer/app/src/main/res/drawable/foreground_design.xml new file mode 100644 index 0000000..bc60c66 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/foreground_design.xml @@ -0,0 +1,10 @@ + + + + + + \ No newline at end of file diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_access_time_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_access_time_24.xml new file mode 100644 index 0000000..bdf91f9 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_access_time_24.xml @@ -0,0 +1,6 @@ + + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_exit_to_app_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_exit_to_app_24.xml new file mode 100644 index 0000000..0d905fd --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_exit_to_app_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_local_phone_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_local_phone_24.xml new file mode 100644 index 0000000..67d862a --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_local_phone_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_playlist_add_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_playlist_add_24.xml new file mode 100644 index 0000000..6dc6a69 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_playlist_add_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_restaurant_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_restaurant_24.xml new file mode 100644 index 0000000..9ead2b7 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_restaurant_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_shopping_cart_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_shopping_cart_24.xml new file mode 100644 index 0000000..ba0b471 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_shopping_cart_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_baseline_vpn_key_24.xml b/FoodifyServer/app/src/main/res/drawable/ic_baseline_vpn_key_24.xml new file mode 100644 index 0000000..1bdb032 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_baseline_vpn_key_24.xml @@ -0,0 +1,5 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_launcher_background.xml b/FoodifyServer/app/src/main/res/drawable/ic_launcher_background.xml new file mode 100644 index 0000000..07d5da9 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_launcher_background.xml @@ -0,0 +1,170 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_menu_camera.xml b/FoodifyServer/app/src/main/res/drawable/ic_menu_camera.xml new file mode 100644 index 0000000..634fe92 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_menu_camera.xml @@ -0,0 +1,12 @@ + + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_menu_gallery.xml b/FoodifyServer/app/src/main/res/drawable/ic_menu_gallery.xml new file mode 100644 index 0000000..03c7709 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_menu_gallery.xml @@ -0,0 +1,9 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/ic_menu_slideshow.xml b/FoodifyServer/app/src/main/res/drawable/ic_menu_slideshow.xml new file mode 100644 index 0000000..5e9e163 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/ic_menu_slideshow.xml @@ -0,0 +1,9 @@ + + + diff --git a/FoodifyServer/app/src/main/res/drawable/side_nav_bar.xml b/FoodifyServer/app/src/main/res/drawable/side_nav_bar.xml new file mode 100644 index 0000000..6d81870 --- /dev/null +++ b/FoodifyServer/app/src/main/res/drawable/side_nav_bar.xml @@ -0,0 +1,9 @@ + + + \ No newline at end of file diff --git a/FoodifyServer/app/src/main/res/layout/activity_home.xml b/FoodifyServer/app/src/main/res/layout/activity_home.xml new file mode 100644 index 0000000..25be055 --- /dev/null +++ b/FoodifyServer/app/src/main/res/layout/activity_home.xml @@ -0,0 +1,31 @@ + + + + + + + + \ No newline at end of file diff --git a/FoodifyServer/app/src/main/res/layout/activity_main.xml b/FoodifyServer/app/src/main/res/layout/activity_main.xml new file mode 100644 index 0000000..6cf6488 --- /dev/null +++ b/FoodifyServer/app/src/main/res/layout/activity_main.xml @@ -0,0 +1,67 @@ + + + + + + + + + +