diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..603b140 --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.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 diff --git a/.idea/codeStyles/Project.xml b/.idea/codeStyles/Project.xml new file mode 100644 index 0000000..88ea3aa --- /dev/null +++ b/.idea/codeStyles/Project.xml @@ -0,0 +1,122 @@ + + + + + + + + + +
+ + + + xmlns:android + + ^$ + + + +
+
+ + + + xmlns:.* + + ^$ + + + BY_NAME + +
+
+ + + + .*:id + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + .*:name + + http://schemas.android.com/apk/res/android + + + +
+
+ + + + name + + ^$ + + + +
+
+ + + + style + + ^$ + + + +
+
+ + + + .* + + ^$ + + + BY_NAME + +
+
+ + + + .* + + http://schemas.android.com/apk/res/android + + + ANDROID_ATTRIBUTE_ORDER + +
+
+ + + + .* + + .* + + + BY_NAME + +
+
+
+
+ + +
+
\ No newline at end of file diff --git a/.idea/codeStyles/codeStyleConfig.xml b/.idea/codeStyles/codeStyleConfig.xml new file mode 100644 index 0000000..79ee123 --- /dev/null +++ b/.idea/codeStyles/codeStyleConfig.xml @@ -0,0 +1,5 @@ + + + + \ No newline at end of file diff --git a/.idea/dictionaries/uttam.xml b/.idea/dictionaries/uttam.xml new file mode 100644 index 0000000..a19ebdb --- /dev/null +++ b/.idea/dictionaries/uttam.xml @@ -0,0 +1,12 @@ + + + + detailsf + dosen + foodrunner + kartikey + relativelayout + sharma + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ac6b0ae --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,21 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml new file mode 100644 index 0000000..a5f05cd --- /dev/null +++ b/.idea/jarRepositories.xml @@ -0,0 +1,25 @@ + + + + + + + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..37a7509 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,9 @@ + + + + + + + + \ No newline at end of file diff --git a/.idea/runConfigurations.xml b/.idea/runConfigurations.xml new file mode 100644 index 0000000..7f68460 --- /dev/null +++ b/.idea/runConfigurations.xml @@ -0,0 +1,12 @@ + + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/.gitignore b/app/.gitignore new file mode 100644 index 0000000..42afabf --- /dev/null +++ b/app/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle new file mode 100644 index 0000000..8106220 --- /dev/null +++ b/app/build.gradle @@ -0,0 +1,47 @@ +apply plugin: 'com.android.application' +apply plugin: 'kotlin-android' +apply plugin: 'kotlin-android-extensions' +apply plugin: 'kotlin-kapt' + +android { + compileSdkVersion 30 + buildToolsVersion "30.0.0" + + defaultConfig { + applicationId "com.kartikey.foodrunner" + minSdkVersion 18 + targetSdkVersion 30 + versionCode 1 + versionName "1.0" + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } +} + +dependencies { + implementation fileTree(dir: "libs", include: ["*.jar"]) + + def room_version = "2.2.5" + implementation "androidx.room:room-runtime:$room_version" + kapt "androidx.room:room-compiler:$room_version" + + implementation "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" + implementation 'androidx.core:core-ktx:1.3.0' + implementation 'androidx.appcompat:appcompat:1.1.0' + implementation 'androidx.constraintlayout:constraintlayout:1.1.3' + implementation 'com.squareup.picasso:picasso:2.71828' + implementation 'com.android.support:design:28.0.0' + implementation 'com.android.volley:volley:1.1.1' + implementation 'androidx.legacy:legacy-support-v4:1.0.0' + testImplementation 'junit:junit:4.12' + androidTestImplementation 'androidx.test.ext:junit:1.1.1' + androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0' + +} \ No newline at end of file diff --git a/app/proguard-rules.pro b/app/proguard-rules.pro new file mode 100644 index 0000000..481bb43 --- /dev/null +++ b/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/app/src/androidTest/java/com/kartikey/foodrunner/ExampleInstrumentedTest.kt b/app/src/androidTest/java/com/kartikey/foodrunner/ExampleInstrumentedTest.kt new file mode 100644 index 0000000..5e6e1c8 --- /dev/null +++ b/app/src/androidTest/java/com/kartikey/foodrunner/ExampleInstrumentedTest.kt @@ -0,0 +1,24 @@ +package com.kartikey.foodrunner + +import androidx.test.platform.app.InstrumentationRegistry +import androidx.test.ext.junit.runners.AndroidJUnit4 + +import org.junit.Test +import org.junit.runner.RunWith + +import org.junit.Assert.* + +/** + * Instrumented test, which will execute on an Android device. + * + * See [testing documentation](http://d.android.com/tools/testing). + */ +@RunWith(AndroidJUnit4::class) +class ExampleInstrumentedTest { + @Test + fun useAppContext() { + // Context of the app under test. + val appContext = InstrumentationRegistry.getInstrumentation().targetContext + assertEquals("com.kartikey.foodrunner", appContext.packageName) + } +} \ No newline at end of file diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml new file mode 100644 index 0000000..8706f05 --- /dev/null +++ b/app/src/main/AndroidManifest.xml @@ -0,0 +1,51 @@ + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/ic_app_logo-playstore.png b/app/src/main/ic_app_logo-playstore.png new file mode 100644 index 0000000..49a0300 Binary files /dev/null and b/app/src/main/ic_app_logo-playstore.png differ diff --git a/app/src/main/java/com/kartikey/foodrunner/activity/CartActivity.kt b/app/src/main/java/com/kartikey/foodrunner/activity/CartActivity.kt new file mode 100644 index 0000000..aab58f3 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/activity/CartActivity.kt @@ -0,0 +1,364 @@ +package com.kartikey.foodrunner.activity + + +import android.app.NotificationChannel +import android.app.NotificationManager +import android.content.Context +import android.content.Intent +import android.os.Build +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.provider.Settings +import android.view.MenuItem +import android.view.View +import android.widget.* +import androidx.core.app.NotificationCompat +import androidx.core.app.NotificationManagerCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.adapter.CartAdapter +import com.kartikey.foodrunner.model.CartItems +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONArray +import org.json.JSONException +import org.json.JSONObject + + +class CartActivity : AppCompatActivity() { + + lateinit var toolbar: androidx.appcompat.widget.Toolbar + lateinit var txtOrderingFrom: TextView + lateinit var btnPlaceOrder: Button + lateinit var recyclerView: RecyclerView + lateinit var layoutManager: RecyclerView.LayoutManager + lateinit var menuAdapter: CartAdapter + lateinit var restaurantId: String + lateinit var restaurantName: String + lateinit var linearLayout: LinearLayout + lateinit var progressLayout: RelativeLayout + lateinit var selectedItemsId: ArrayList + + var totalCost = 0 + var cartListItems = arrayListOf() + + override fun onCreate(savedInstanceState: Bundle?) { + + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_cart) + + btnPlaceOrder = findViewById(R.id.btnPlaceOrder) + txtOrderingFrom = findViewById(R.id.txtOrderingFrom) + linearLayout = findViewById(R.id.linearLayout) + toolbar = findViewById(R.id.toolBar) + progressLayout = findViewById(R.id.activityCartProgressLayout) + + restaurantId = intent.getStringExtra("restaurantId").toString() + restaurantName = intent.getStringExtra("restaurantName").toString() + selectedItemsId = intent.getStringArrayListExtra("selectedItemsId") as ArrayList + + //set the restaurant name + txtOrderingFrom.text = restaurantName + + btnPlaceOrder.setOnClickListener { + + val sharedPreferences = this.getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + if (ConnectionManager().checkConnectivity(this)) { + progressLayout.visibility = View.VISIBLE + + try { + + val foodJsonArray = JSONArray() + + for (foodItem in selectedItemsId) { + val singleItemObject = JSONObject() + singleItemObject.put("food_item_id", foodItem) + foodJsonArray.put(singleItemObject) + + } + + val sendOrder = JSONObject() + + sendOrder.put("user_id", sharedPreferences.getString("user_id", "0")) + sendOrder.put("restaurant_id", restaurantId.toString()) + sendOrder.put("total_cost", totalCost) + sendOrder.put("food", foodJsonArray) + + val queue = Volley.newRequestQueue(this) + val url = "http://13.235.250.119/v2/place_order/fetch_result/" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.POST, + url, + sendOrder, + Response.Listener + { + + val jsonObjectData = it.getJSONObject("data") + val success = jsonObjectData.getBoolean("success") + + if (success) { + Toast.makeText( + this, + "Order Placed", + Toast.LENGTH_SHORT + ).show() + //send a notification to the user regarding his order + createNotification() + + val intent = Intent(this, OrderPlacedActivity::class.java) + startActivity(intent) + finishAffinity() + + } else { + val responseMessageServer = + jsonObjectData.getString("errorMessage") + Toast.makeText( + this, + responseMessageServer.toString(), + Toast.LENGTH_SHORT + ).show() + + } + progressLayout.visibility = View.GONE + }, + Response.ErrorListener + { + Toast.makeText( + this, + "Some Error occurred!!!", + Toast.LENGTH_SHORT + ).show() + + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + this, + "Some unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + + } + + } else { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity() + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + } + //setting the toolbar + setToolBar() + + layoutManager = LinearLayoutManager(this) + recyclerView = findViewById(R.id.recyclerViewCart) + + } + + fun fetchData() { + if (ConnectionManager().checkConnectivity(this)) { + progressLayout.visibility = View.VISIBLE + try { + + val queue = Volley.newRequestQueue(this) + val url = "http://13.235.250.119/v2/restaurants/fetch_result/${restaurantId}" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.GET, + url, + null, + Response.Listener + { + + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + + val data = responseJsonObjectData.getJSONArray("data") + //old listener of jsonObjectRequest are still listening therefore clear is used + cartListItems.clear() + totalCost = 0 + + for (i in 0 until data.length()) { + val cartItemJsonObject = data.getJSONObject(i) + + if (selectedItemsId.contains(cartItemJsonObject.getString("id"))) { + val menuObject = CartItems( + cartItemJsonObject.getString("id"), + cartItemJsonObject.getString("name"), + cartItemJsonObject.getString("cost_for_one"), + cartItemJsonObject.getString("restaurant_id") + ) + + this.totalCost += cartItemJsonObject.getString("cost_for_one") + .toString().toInt() + cartListItems.add(menuObject) + + } + menuAdapter = CartAdapter( + this, + cartListItems + ) + + recyclerView.adapter = menuAdapter + recyclerView.layoutManager = layoutManager + } + + //set the total on the button + btnPlaceOrder.text = "Place Order (Total Cost: Rs. $totalCost)" + } + progressLayout.visibility = View.GONE + }, + Response.ErrorListener + { + + Toast.makeText( + this, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + progressLayout.visibility = View.GONE + + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + this, + "Some Unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + + } else { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity() + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + + } + + fun setToolBar() { + setSupportActionBar(toolbar) + supportActionBar?.title = "My Cart" + supportActionBar?.setHomeButtonEnabled(true) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_white_back_arrow) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + when (id) { + android.R.id.home -> { + super.onBackPressed() + } + } + return super.onOptionsItemSelected(item) + } + + + override fun onResume() { + if (ConnectionManager().checkConnectivity(this)) { + fetchData() + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity() + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + } + + //Learnt about it online and decided to implement it + fun createNotification() { + val notificationId = 1; + val channelId = "personal_notification" + val notificationBuilder = NotificationCompat.Builder(this, channelId) + notificationBuilder.setSmallIcon(R.drawable.food_runner_logo) + notificationBuilder.setContentTitle("Order Placed") + notificationBuilder.setContentText("Your order has been placed successfully!") + notificationBuilder.setStyle( + NotificationCompat.BigTextStyle() + .bigText("Ordered from ${restaurantName} and amounting to Rs.${totalCost} .Thank you for ordering from FoodRunner. Stay Safe!") + ) + notificationBuilder.priority = NotificationCompat.PRIORITY_DEFAULT + val notificationManagerCompat = NotificationManagerCompat.from(this) + notificationManagerCompat.notify(notificationId, notificationBuilder.build()) + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) //if the version is less than oreo + { + val name = "Order Placed" + val description = "Your order has been placed!" + val importance = NotificationManager.IMPORTANCE_DEFAULT + + val notificationChannel = NotificationChannel(channelId, name, importance) + notificationChannel.description = description + val notificationManager = + (getSystemService(Context.NOTIFICATION_SERVICE)) as NotificationManager + notificationManager.createNotificationChannel(notificationChannel) + + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/activity/DashboardActivity.kt b/app/src/main/java/com/kartikey/foodrunner/activity/DashboardActivity.kt new file mode 100644 index 0000000..a496961 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/activity/DashboardActivity.kt @@ -0,0 +1,251 @@ +package com.kartikey.foodrunner.activity + +import android.content.Context +import android.content.Intent +import android.content.SharedPreferences +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.os.Handler +import android.view.MenuItem +import android.view.WindowManager +import android.widget.FrameLayout +import android.widget.TextView +import android.widget.Toast +import androidx.appcompat.app.ActionBarDrawerToggle +import androidx.coordinatorlayout.widget.CoordinatorLayout +import androidx.core.app.ActivityCompat +import androidx.core.view.GravityCompat +import androidx.drawerlayout.widget.DrawerLayout +import com.google.android.material.navigation.NavigationView +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.fragment.* + + +class DashboardActivity : AppCompatActivity() { + + lateinit var coordinatorLayout: CoordinatorLayout + lateinit var toolbar: androidx.appcompat.widget.Toolbar + lateinit var frameLayout: FrameLayout + lateinit var navigationView: NavigationView + lateinit var drawerLayout: DrawerLayout + lateinit var txtCurrentUser: TextView + lateinit var txtMobileNumber: TextView + lateinit var sharedPreferences: SharedPreferences + + var previousMenuItemSelected: MenuItem? = null + + override fun onCreate(savedInstanceState: Bundle?) { + + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_dashboard) + sharedPreferences = getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + coordinatorLayout = findViewById(R.id.coordinatorLayout) + toolbar = findViewById(R.id.toolBar) + frameLayout = findViewById(R.id.frameLayout) + navigationView = findViewById(R.id.navigationView) + drawerLayout = findViewById(R.id.drawerLayout) + val headerView = navigationView.getHeaderView(0) + txtCurrentUser = headerView.findViewById(R.id.txtCurrentUser) + txtMobileNumber = headerView.findViewById(R.id.txtMobileNumber) + + //Used to set the default dashboard to checked when the + //app opens or the back btn is pressed to go to the previous fragment + navigationView.menu.getItem(0).setCheckable(true) + navigationView.menu.getItem(0).setChecked(true) + + //set tool bar + setToolBar() + + //default user details + txtCurrentUser.text = sharedPreferences.getString("name", "Kartikey Sharma") + txtMobileNumber.text = "+91-" + sharedPreferences.getString("mobile_number", "9876543210") + + val actionBarDrawerToggle = ActionBarDrawerToggle( + this@DashboardActivity, + drawerLayout, + R.string.open_drawer,//hamburger icon to open + R.string.close_drawer + )//once opened it changes to back arrow + + drawerLayout.addDrawerListener(actionBarDrawerToggle) + actionBarDrawerToggle.syncState() + //to sync with the state of the navigation toggle with the state of the navigation drawer + + navigationView.setNavigationItemSelectedListener { + + if (previousMenuItemSelected != null && previousMenuItemSelected!!.itemId != R.id.logout) { + previousMenuItemSelected?.isChecked = true + } + + //the current fragment will be previous fragment when a user clicks a new fragment + previousMenuItemSelected = it + it.isCheckable = true + it.isChecked = true + + //The closing of navigation drawer is delayed to make the transition smoother + //Delayed by 0.2s + val pendingRunnable = Runnable { drawerLayout.closeDrawer(GravityCompat.START) } + Handler().postDelayed( + pendingRunnable, + 100 + ) + + when (it.itemId) { + + R.id.home -> { + openDashboard() + drawerLayout.closeDrawers() + } + R.id.profile -> { + + supportFragmentManager.beginTransaction() + .replace( + R.id.frameLayout, + ProfileFragment(this) + ) + .commit() + + supportActionBar?.title = "My Profile" + drawerLayout.closeDrawers() + Toast.makeText( + this@DashboardActivity, + "My Profile", + Toast.LENGTH_SHORT + ) + .show() + + } + R.id.favouriteRestaurants -> { + + supportFragmentManager.beginTransaction() + .replace( + R.id.frameLayout, + FavouriteRestaurantFragment(this) + ) + .commit() + + supportActionBar?.title = "Favourite Restaurants" + drawerLayout.closeDrawers() + + } + R.id.orderHistory -> { + + supportFragmentManager.beginTransaction().replace( + R.id.frameLayout, OrderHistoryFragment() + ).commit() + supportActionBar?.title = "My Previous Orders" + drawerLayout.closeDrawers() + + Toast.makeText( + this@DashboardActivity, + "Order History", + Toast.LENGTH_SHORT + ).show() + + } + R.id.faqs -> { + + supportFragmentManager.beginTransaction() + .replace( + R.id.frameLayout, + FaqsFragment() + ) + .commit() + + supportActionBar?.title = "Frequently Asked Questions" + drawerLayout.closeDrawers() + + Toast.makeText( + this@DashboardActivity, + " FAQs ", + Toast.LENGTH_SHORT + ) + .show() + } + R.id.logout -> { + drawerLayout.closeDrawers() + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("Confirmation") + alterDialog.setMessage("Are you sure you want to log out?") + alterDialog.setPositiveButton("Yes") + { _, _ -> + sharedPreferences.edit().putBoolean("user_logged_in", false).apply() + val intent = + Intent(this@DashboardActivity, LoginRegisterActivity::class.java) + startActivity(intent) + ActivityCompat.finishAffinity(this) + //app login user credentials are erased and it takes the user to the login screen + } + + alterDialog.setNegativeButton("No") + { _, _ -> + openDashboard() + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + } + + return@setNavigationItemSelectedListener true + } + openDashboard() + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + + val id = item.itemId + if (id == android.R.id.home) { + drawerLayout.openDrawer(GravityCompat.START) + } + return super.onOptionsItemSelected(item) + } + + override fun onBackPressed() { + + val currentFragment = supportFragmentManager.findFragmentById(R.id.frameLayout) + + when (currentFragment) { + !is DashboardFragment -> { + navigationView.menu.getItem(0).setChecked(true) + openDashboard() + } + else -> { + super.onBackPressed() + } + } + } + + fun setToolBar() { + setSupportActionBar(toolbar) + supportActionBar?.title = "All Restaurants" + supportActionBar?.setHomeButtonEnabled(true) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_menu) + } + + fun openDashboard() { + val transaction = supportFragmentManager.beginTransaction() + transaction.replace( + R.id.frameLayout, + DashboardFragment(this) + ) + transaction.commit() + + supportActionBar?.title = "All Restaurants" + navigationView.setCheckedItem(R.id.home) + } + + //to disable auto pop of soft keyboard on the search + override fun onResume() { + window.setSoftInputMode( + WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN + ); + super.onResume() + } +} diff --git a/app/src/main/java/com/kartikey/foodrunner/activity/LoginRegisterActivity.kt b/app/src/main/java/com/kartikey/foodrunner/activity/LoginRegisterActivity.kt new file mode 100644 index 0000000..c2856aa --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/activity/LoginRegisterActivity.kt @@ -0,0 +1,65 @@ +package com.kartikey.foodrunner.activity + +import android.content.Context +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.view.MenuItem +import com.kartikey.foodrunner.fragment.LoginFragment +import com.kartikey.foodrunner.R + +class LoginRegisterActivity : AppCompatActivity() { + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_login_register) + + val sharedPreferences = getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + if (sharedPreferences.getBoolean("user_logged_in", false)) { + val intent = Intent(this@LoginRegisterActivity, DashboardActivity::class.java) + startActivity(intent) + finish(); + } else { + openLoginFragment() + } + } + + fun openLoginFragment() { + + val transaction = supportFragmentManager.beginTransaction() + transaction.replace( + R.id.frameLayout, + LoginFragment(this) + ) + transaction.commit() + supportActionBar?.title = "DashboardActivity" + + } + + override fun onBackPressed() { + val currentFragment = supportFragmentManager.findFragmentById(R.id.frameLayout) + when (currentFragment) { + !is LoginFragment -> { + openLoginFragment() + } + else -> { + super.onBackPressed() + } + } + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + when (id) { + android.R.id.home -> { + openLoginFragment() + } + } + return super.onOptionsItemSelected(item) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/activity/OrderPlacedActivity.kt b/app/src/main/java/com/kartikey/foodrunner/activity/OrderPlacedActivity.kt new file mode 100644 index 0000000..fdc3778 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/activity/OrderPlacedActivity.kt @@ -0,0 +1,41 @@ +package com.kartikey.foodrunner.activity + + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.widget.Button +import android.widget.RelativeLayout +import android.widget.Toast +import com.kartikey.foodrunner.R + +class OrderPlacedActivity : AppCompatActivity() { + + lateinit var btnOkay: Button + lateinit var orderPlacedSuccessfully: RelativeLayout + + override fun onCreate(savedInstanceState: Bundle?) { + + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_order_placed) + orderPlacedSuccessfully = findViewById(R.id.orderPlacedSuccessfully) + btnOkay = findViewById(R.id.btnOkay) + + btnOkay.setOnClickListener { + val intent = Intent(this, DashboardActivity::class.java) + startActivity(intent) + finishAffinity() + } + } + + override fun onBackPressed() { + Toast.makeText( + this@OrderPlacedActivity, + "Press OK for Main Menu", + Toast.LENGTH_SHORT + ) + .show() + //force user to press okay button to take him to dashboard screen + //user can't use back button + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/activity/RestaurantMenuActivity.kt b/app/src/main/java/com/kartikey/foodrunner/activity/RestaurantMenuActivity.kt new file mode 100644 index 0000000..7790bb9 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/activity/RestaurantMenuActivity.kt @@ -0,0 +1,238 @@ +package com.kartikey.foodrunner.activity + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.provider.Settings +import android.view.MenuItem +import android.view.View +import android.widget.Button +import android.widget.RelativeLayout +import android.widget.Toast +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.adapter.RestaurantMenuAdapter +import com.kartikey.foodrunner.model.RestaurantMenu +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException +import kotlin.collections.HashMap + +class RestaurantMenuActivity : AppCompatActivity() { + + lateinit var toolbar: androidx.appcompat.widget.Toolbar + lateinit var recyclerView: RecyclerView + lateinit var layoutManager: RecyclerView.LayoutManager + lateinit var menuAdapter: RestaurantMenuAdapter + lateinit var restaurantId: String + lateinit var restaurantName: String + lateinit var proceedToCartLayout: RelativeLayout + lateinit var btnProceedToCart: Button + lateinit var restaurantMenuProgressDialog: RelativeLayout + + var restaurantMenuList = arrayListOf() + + + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_restaurant_menu) + + proceedToCartLayout = findViewById(R.id.rlProceedToCart) + btnProceedToCart = findViewById(R.id.btnProceedToCart) + restaurantMenuProgressDialog = + findViewById(R.id.restaurantMenuProgressDialog) + + toolbar = findViewById(R.id.toolBar) + + restaurantId = intent.getStringExtra("restaurantId").toString() + restaurantName = intent.getStringExtra("restaurantName").toString() + + setToolBar() + layoutManager = LinearLayoutManager(this) + recyclerView = findViewById(R.id.recyclerViewRestaurantMenu) + + } + + fun fetchData() { + if (ConnectionManager().checkConnectivity(this)) { + restaurantMenuProgressDialog.visibility = View.VISIBLE + try { + + val queue = Volley.newRequestQueue(this) + val url = "http://13.235.250.119/v2/restaurants/fetch_result/${restaurantId}" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.GET, + url, + null, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + restaurantMenuList.clear() + + val data = responseJsonObjectData.getJSONArray("data") + + for (i in 0 until data.length()) { + val bookJsonObject = data.getJSONObject(i) + val menuObject = RestaurantMenu( + bookJsonObject.getString("id"), + bookJsonObject.getString("name"), + bookJsonObject.getString("cost_for_one") + + ) + restaurantMenuList.add(menuObject) + + menuAdapter = RestaurantMenuAdapter( + this, + restaurantId, + restaurantName, + proceedToCartLayout,//pass the relative layout which has the button to enable it later + btnProceedToCart, + restaurantMenuList + ) + + recyclerView.adapter = menuAdapter + recyclerView.layoutManager = layoutManager + } + } + restaurantMenuProgressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + Toast.makeText( + this, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + + restaurantMenuProgressDialog.visibility = View.GONE + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + this, + "Some Unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + + } else { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity() + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + + } + + fun setToolBar() { + setSupportActionBar(toolbar) + supportActionBar?.title = restaurantName + supportActionBar?.setHomeButtonEnabled(true) + supportActionBar?.setDisplayHomeAsUpEnabled(true) + supportActionBar?.setHomeAsUpIndicator(R.drawable.ic_white_back_arrow) + } + + override fun onBackPressed() { + + if (menuAdapter.getSelectedItemCount() > 0) { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("Alert!") + alterDialog.setMessage("Going back will remove everything from cart") + alterDialog.setPositiveButton("Okay") + { _, _ -> + super.onBackPressed() + } + alterDialog.setNegativeButton("No") + { _, _ -> + //do nothing + } + alterDialog.show() + } else { + super.onBackPressed() + } + + } + + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + when (id) { + android.R.id.home -> { + if (menuAdapter.getSelectedItemCount() > 0) { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("Alert!") + alterDialog.setMessage("Going back will remove everything from cart") + alterDialog.setPositiveButton("Okay") + { _, _ -> + super.onBackPressed() + } + alterDialog.setNegativeButton("No") + { _, _ -> + + } + alterDialog.show() + } else { + super.onBackPressed() + } + } + } + return super.onOptionsItemSelected(item) + } + + override fun onResume() { + + if (ConnectionManager().checkConnectivity(this)) { + if (restaurantMenuList.isEmpty()) + fetchData() + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(this) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + //chose to make an intent to ACTION_SETTINGS instead of WIRELESS_ACTION_SETTINGS as it + //is more convenient for someone who wants to choose between opening mobile data or WIFI + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity() + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/activity/SplashActivity.kt b/app/src/main/java/com/kartikey/foodrunner/activity/SplashActivity.kt new file mode 100644 index 0000000..1e9e4d1 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/activity/SplashActivity.kt @@ -0,0 +1,23 @@ +package com.kartikey.foodrunner.activity + +import android.content.Intent +import androidx.appcompat.app.AppCompatActivity +import android.os.Bundle +import android.os.Handler +import com.kartikey.foodrunner.R + +class SplashActivity : AppCompatActivity() { + override fun onCreate(savedInstanceState: Bundle?) { + super.onCreate(savedInstanceState) + setContentView(R.layout.activity_splash) + + //Used handler to delay the intent by 1 seconds + Handler().postDelayed( + { + val intent = Intent(this@SplashActivity, LoginRegisterActivity::class.java) + finish() + startActivity(intent) + }, 1000 + ) + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/adapter/CartAdapter.kt b/app/src/main/java/com/kartikey/foodrunner/adapter/CartAdapter.kt new file mode 100644 index 0000000..b00ee6e --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/adapter/CartAdapter.kt @@ -0,0 +1,37 @@ +package com.kartikey.foodrunner.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.model.CartItems + + +class CartAdapter(val context: Context, val cartItems: ArrayList) : + RecyclerView.Adapter() { + + class ViewHolderCart(view: View) : RecyclerView.ViewHolder(view) { + val txtOrderItem: TextView = view.findViewById(R.id.txtCartItemName) + val txtOrderItemPrice: TextView = view.findViewById(R.id.txtCartPrice) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderCart { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.cart_recycler_view_single_row, parent, false) + return ViewHolderCart(view) + } + + override fun getItemCount(): Int { + return cartItems.size + } + + override fun onBindViewHolder(holder: ViewHolderCart, position: Int) { + val cartItemObject = cartItems[position] + holder.txtOrderItem.text = cartItemObject.itemName + holder.txtOrderItemPrice.text = "Rs. ${cartItemObject.itemPrice}" + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/adapter/DashboardFragmentAdapter.kt b/app/src/main/java/com/kartikey/foodrunner/adapter/DashboardFragmentAdapter.kt new file mode 100644 index 0000000..4f20a9e --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/adapter/DashboardFragmentAdapter.kt @@ -0,0 +1,154 @@ +package com.kartikey.foodrunner.adapter + + +import android.content.Context +import android.content.Intent +import android.os.AsyncTask +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.* +import androidx.recyclerview.widget.RecyclerView +import androidx.room.Room +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.activity.RestaurantMenuActivity +import com.kartikey.foodrunner.database.RestaurantDatabase +import com.kartikey.foodrunner.database.RestaurantEntity +import com.kartikey.foodrunner.model.Restaurant +import com.squareup.picasso.Picasso + + +class DashboardFragmentAdapter(val context: Context, var itemList: ArrayList) : + RecyclerView.Adapter() { + + class ViewHolderDashboard(view: View) : RecyclerView.ViewHolder(view) { + val imgRestaurant: ImageView = view.findViewById(R.id.imgRestaurant) + val txtRestaurantName: TextView = view.findViewById(R.id.txtRestaurantName) + val txtPricePerPerson: TextView = view.findViewById(R.id.txtPricePerPerson) + val txtRating: TextView = view.findViewById(R.id.txtRating) + val llContent: LinearLayout = view.findViewById(R.id.llContent) + val txtFavourite: TextView = view.findViewById(R.id.txtFavourite) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderDashboard { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.dashboard_recycler_view_single_row, parent, false) + return ViewHolderDashboard(view) + } + + override fun getItemCount(): Int { + return itemList.size + } + + override fun onBindViewHolder(holder: ViewHolderDashboard, position: Int) { + val restaurant = itemList[position] + val restaurantEntity = RestaurantEntity( + restaurant.restaurantId, + restaurant.restaurantName + ) + + holder.txtFavourite.setOnClickListener { + if (!DBAsynTask(context, restaurantEntity, 1).execute().get()) { + val result = DBAsynTask(context, restaurantEntity, 2).execute().get() + + if (result) { + holder.txtFavourite.setTag("liked")//new value + holder.txtFavourite.background = + context.resources.getDrawable(R.drawable.ic_fav_fill) + } else { + Toast.makeText( + context, + "Some error occurred!", + Toast.LENGTH_SHORT + ) + .show() + } + + } else { + val result = DBAsynTask(context, restaurantEntity, 3).execute().get() + + if (result) { + holder.txtFavourite.setTag("unliked") + holder.txtFavourite.background = + context.resources.getDrawable(R.drawable.ic_fav_outline) + } else { + Toast.makeText( + context, + "Some error occurred!", + Toast.LENGTH_SHORT + ) + .show() + } + } + } + + holder.llContent.setOnClickListener { + + val intent = Intent(context, RestaurantMenuActivity::class.java) + intent.putExtra("restaurantId", holder.txtRestaurantName.getTag().toString()) + intent.putExtra("restaurantName", holder.txtRestaurantName.text.toString()) + context.startActivity(intent) + + } + + holder.txtRestaurantName.setTag(restaurant.restaurantId + "") + holder.txtRestaurantName.text = restaurant.restaurantName + holder.txtPricePerPerson.text = restaurant.costForOne + "/Person " + holder.txtRating.text = restaurant.restaurantRating + Picasso.get().load(restaurant.restaurantImage).error(R.drawable.ic_default_image_restaurant) + .into(holder.imgRestaurant) + + val checkFav = DBAsynTask(context, restaurantEntity, 1).execute() + val isFav = checkFav.get() + + if (isFav) { + holder.txtFavourite.setTag("liked") + holder.txtFavourite.background = context.resources.getDrawable(R.drawable.ic_fav_fill) + } else { + holder.txtFavourite.setTag("unliked") + holder.txtFavourite.background = + context.resources.getDrawable(R.drawable.ic_fav_outline) + } + + } + + fun filterList(filteredList: ArrayList) { + itemList = filteredList + notifyDataSetChanged() + } + + class DBAsynTask(val context: Context, val restaurantEntity: RestaurantEntity, val mode: Int) : + AsyncTask() { + val db = + Room.databaseBuilder(context, RestaurantDatabase::class.java, "restaurant-db").build() + + override fun doInBackground(vararg p0: Void?): Boolean { + /* + * Mode 1->check if restaurant is in favourites + * Mode 2->Save the restaurant into DB as favourites + * Mode 3-> Remove the favourite restaurant + */ + when (mode) { + 1 -> { + val restaurant: RestaurantEntity? = db.restaurantDao() + .getRestaurantById(restaurantEntity.restaurantId) + db.close() + return restaurant != null + } + 2 -> { + db.restaurantDao().insertRestaurant(restaurantEntity) + db.close() + return true + } + 3 -> { + db.restaurantDao().deleteRestaurant(restaurantEntity) + db.close() + return true + } + else -> { + return false + } + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/adapter/OrderHistoryAdapter.kt b/app/src/main/java/com/kartikey/foodrunner/adapter/OrderHistoryAdapter.kt new file mode 100644 index 0000000..45117bf --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/adapter/OrderHistoryAdapter.kt @@ -0,0 +1,140 @@ +package com.kartikey.foodrunner.adapter + +import android.content.Context +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import android.widget.Toast +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.model.CartItems +import com.kartikey.foodrunner.model.OrderHistoryRestaurant +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException + + +class OrderHistoryAdapter( + val context: Context, + val orderedRestaurantList: ArrayList +) : RecyclerView.Adapter() { + + class ViewHolderOrderHistoryRestaurant(view: View) : RecyclerView.ViewHolder(view) { + val txtRestaurantName: TextView = view.findViewById(R.id.txtRestaurantName) + val txtDate: TextView = view.findViewById(R.id.txtDate) + val recyclerViewItemsOrdered: RecyclerView = + view.findViewById(R.id.recyclerViewItemsOrdered) + } + + override fun onCreateViewHolder( + parent: ViewGroup, + viewType: Int + ): ViewHolderOrderHistoryRestaurant { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.order_history_recycler_single_row, parent, false) + + return ViewHolderOrderHistoryRestaurant(view) + } + + override fun getItemCount(): Int { + return orderedRestaurantList.size + } + + override fun onBindViewHolder(holder: ViewHolderOrderHistoryRestaurant, position: Int) { + val restaurantObject = orderedRestaurantList[position] + holder.txtRestaurantName.text = restaurantObject.restaurantName + var formatDate = restaurantObject.orderPlacedAt + formatDate = formatDate.replace("-", "/") //01-01-20 to 01/01/20 + formatDate = formatDate.substring(0, 6) + "20" + formatDate.substring( + 6, + 8 + ) //01/01/20 to 01/01/2020 + holder.txtDate.text = formatDate + + val layoutManager = LinearLayoutManager(context) + var orderedItemAdapter: CartAdapter + + if (ConnectionManager().checkConnectivity(context)) { + try { + val orderItemsPerRestaurant = ArrayList() + val sharedPreferences = context.getSharedPreferences( + context.getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + val userId = sharedPreferences.getString("user_id", "0") + + val queue = Volley.newRequestQueue(context) + val url = "http://13.235.250.119/v2/orders/fetch_result/${userId}" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.GET, + url, + null, + Response.Listener + { + + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + val data = responseJsonObjectData.getJSONArray("data") + val fetchedRestaurantJSONObject = data.getJSONObject(position) + orderItemsPerRestaurant.clear() + + val foodOrderedJsonArray = + fetchedRestaurantJSONObject.getJSONArray("food_items") + + for (j in 0 until foodOrderedJsonArray.length()) { + val eachFoodItem = foodOrderedJsonArray.getJSONObject(j) + val itemObject = CartItems( + eachFoodItem.getString("food_item_id"), + eachFoodItem.getString("name"), + eachFoodItem.getString("cost"), + "000" + ) + orderItemsPerRestaurant.add(itemObject) + } + + orderedItemAdapter = CartAdapter( + context, + orderItemsPerRestaurant + ) + + holder.recyclerViewItemsOrdered.adapter = orderedItemAdapter + holder.recyclerViewItemsOrdered.layoutManager = layoutManager + } + }, + Response.ErrorListener + { + Toast.makeText( + context, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + }) { + + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + context, + "Some Unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + } + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/adapter/RestaurantMenuAdapter.kt b/app/src/main/java/com/kartikey/foodrunner/adapter/RestaurantMenuAdapter.kt new file mode 100644 index 0000000..9d216e2 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/adapter/RestaurantMenuAdapter.kt @@ -0,0 +1,107 @@ +package com.kartikey.foodrunner.adapter + +import android.content.Context +import android.content.Intent +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.RelativeLayout +import android.widget.TextView +import androidx.recyclerview.widget.RecyclerView +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.activity.CartActivity +import com.kartikey.foodrunner.model.RestaurantMenu + +class RestaurantMenuAdapter + ( + val context: Context, + val restaurantId: String, + val restaurantName: String, + val proceedToCartPassed: RelativeLayout, + val btnProceedToCart: Button, + val restaurantMenu: ArrayList +) : RecyclerView.Adapter() { + + var itemSelectedCount: Int = 0 + lateinit var proceedToCart: RelativeLayout + + var itemsSelectedId = arrayListOf() + + class ViewHolderRestaurantMenu(view: View) : RecyclerView.ViewHolder(view) { + val txtSerialNumber: TextView = view.findViewById(R.id.txtSerialName) + val txtItemName: TextView = view.findViewById(R.id.txtItemName) + val txtItemPrice: TextView = view.findViewById(R.id.txtItemPrice) + val btnAddToCart: Button = view.findViewById(R.id.btnAddToCart) + } + + override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ViewHolderRestaurantMenu { + val view = LayoutInflater.from(parent.context) + .inflate(R.layout.restuarant_menu_recycler_view_single_row, parent, false) + + return ViewHolderRestaurantMenu(view) + } + + override fun getItemCount(): Int { + return restaurantMenu.size + } + + fun getSelectedItemCount(): Int { + return itemSelectedCount + } + + override fun onBindViewHolder(holder: ViewHolderRestaurantMenu, position: Int) { + val restaurantMenuItem = restaurantMenu[position] + proceedToCart = proceedToCartPassed//button view passed from the RestaurantMenuActivity + + btnProceedToCart.setOnClickListener(View.OnClickListener + { + val intent = Intent(context, CartActivity::class.java) + intent.putExtra( + "restaurantId", + restaurantId.toString() + ) + + intent.putExtra("restaurantName", restaurantName) + intent.putExtra( + "selectedItemsId", + itemsSelectedId + ) + context.startActivity(intent) + + }) + + holder.btnAddToCart.setOnClickListener(View.OnClickListener + { + if (holder.btnAddToCart.text.toString().equals("Remove")) { + itemSelectedCount-- //item unselected + + itemsSelectedId.remove(holder.btnAddToCart.getTag().toString()) + holder.btnAddToCart.text = context.getString(R.string.add) + holder.btnAddToCart.setBackgroundResource(R.drawable.rounded_view_for_menu_red) + + } else { + + itemSelectedCount++ //item selected + itemsSelectedId.add(holder.btnAddToCart.getTag().toString()) + + holder.btnAddToCart.text = context.getString(R.string.remove) + holder.btnAddToCart.setBackgroundResource(R.drawable.rounded_view_for_menu_chosen) + } + + if (itemSelectedCount > 0) { + proceedToCart.visibility = View.VISIBLE + } else { + proceedToCart.visibility = View.GONE + } + + }) + + holder.btnAddToCart.setTag(restaurantMenuItem.id + "") //save the item id in textViewName Tag ,will be used to add to cart + holder.txtSerialNumber.text = (position + 1).toString() //position starts from 0 + holder.txtItemName.text = restaurantMenuItem.name + holder.txtItemPrice.text = """Rs.${restaurantMenuItem.cost_for_one}""" + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/database/RestaurantDao.kt b/app/src/main/java/com/kartikey/foodrunner/database/RestaurantDao.kt new file mode 100644 index 0000000..55b20ea --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/database/RestaurantDao.kt @@ -0,0 +1,22 @@ +package com.kartikey.foodrunner.database + +import androidx.room.Dao +import androidx.room.Delete +import androidx.room.Insert +import androidx.room.Query + +@Dao +interface RestaurantDao { + @Insert + fun insertRestaurant(restaurantEntity: RestaurantEntity) + + @Delete + fun deleteRestaurant(restaurantEntity: RestaurantEntity) + + @Query("SELECT * FROM restaurants") + fun getAllRestaurants(): List + + @Query("SELECT * FROM restaurants WHERE restaurant_id = :restaurantId") + fun getRestaurantById(restaurantId: String): RestaurantEntity + +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/database/RestaurantDatabase.kt b/app/src/main/java/com/kartikey/foodrunner/database/RestaurantDatabase.kt new file mode 100644 index 0000000..ea74f2b --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/database/RestaurantDatabase.kt @@ -0,0 +1,10 @@ +package com.kartikey.foodrunner.database + +import androidx.room.Database +import androidx.room.RoomDatabase + +@Database(entities = [RestaurantEntity::class], version = 1) +abstract class RestaurantDatabase : RoomDatabase() { + abstract fun restaurantDao(): RestaurantDao + +} diff --git a/app/src/main/java/com/kartikey/foodrunner/database/RestaurantEntity.kt b/app/src/main/java/com/kartikey/foodrunner/database/RestaurantEntity.kt new file mode 100644 index 0000000..e92b08e --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/database/RestaurantEntity.kt @@ -0,0 +1,12 @@ +package com.kartikey.foodrunner.database + +import androidx.room.ColumnInfo +import androidx.room.Entity +import androidx.room.PrimaryKey + +@Entity(tableName = "restaurants") +data class RestaurantEntity + ( + @ColumnInfo(name = "restaurant_id") @PrimaryKey var restaurantId: String, + @ColumnInfo(name = "restaurant_name") var restaurantName: String +) \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/DashboardFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/DashboardFragment.kt new file mode 100644 index 0000000..6101db3 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/DashboardFragment.kt @@ -0,0 +1,264 @@ +package com.kartikey.foodrunner.fragment + + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import android.text.Editable +import android.text.TextWatcher +import android.view.* +import android.widget.EditText +import android.widget.RelativeLayout +import androidx.fragment.app.Fragment +import android.widget.Toast +import androidx.core.app.ActivityCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.adapter.DashboardFragmentAdapter +import com.kartikey.foodrunner.model.Restaurant +import com.kartikey.foodrunner.utils.ConnectionManager +import kotlinx.android.synthetic.main.sort_radio_button.view.* +import org.json.JSONException +import java.util.* +import kotlin.Comparator +import kotlin.collections.HashMap + + +class DashboardFragment(val contextParam: Context) : Fragment() { + + lateinit var recyclerView: RecyclerView + lateinit var layoutManager: RecyclerView.LayoutManager + lateinit var dashboardAdapter: DashboardFragmentAdapter + lateinit var etSearch: EditText + lateinit var radioButtonView: View + lateinit var progressDialog: RelativeLayout + lateinit var rlNoRestaurantFound: RelativeLayout + + var restaurantInfoList = arrayListOf() + var ratingComparator = Comparator + { rest1, rest2 -> + + if (rest1.restaurantRating.compareTo(rest2.restaurantRating, true) == 0) { + rest1.restaurantName.compareTo(rest2.restaurantName, true) + } else { + rest1.restaurantRating.compareTo(rest2.restaurantRating, true) + } + + } + + var costComparator = Comparator + { rest1, rest2 -> + rest1.costForOne.compareTo(rest2.costForOne, true) + } + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + + setHasOptionsMenu(true) + val view = inflater.inflate(R.layout.fragment_dashboard, container, false) + + layoutManager = LinearLayoutManager(activity) + recyclerView = view.findViewById(R.id.recyclerViewDashboard) + etSearch = view.findViewById(R.id.etSearch) + progressDialog = view.findViewById(R.id.dashboardProgressDialog) + rlNoRestaurantFound = view.findViewById(R.id.noRestaurantFound) + + rlNoRestaurantFound.visibility = View.INVISIBLE + + fun filterFun(strTyped: String) { + rlNoRestaurantFound.visibility = View.INVISIBLE + val filteredList = arrayListOf() + for (item in restaurantInfoList) { + if (item.restaurantName.toLowerCase(Locale.ROOT) + .contains(strTyped.toLowerCase(Locale.ROOT)) + ) { + filteredList.add(item) + } + } + if (filteredList.size == 0) { + rlNoRestaurantFound.visibility = View.VISIBLE + } + dashboardAdapter.filterList(filteredList) + } + + etSearch.addTextChangedListener(object : TextWatcher { + //as the user types the search filter is applied + override fun afterTextChanged(strTyped: Editable?) { + filterFun(strTyped.toString()) + } + + override fun beforeTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} + override fun onTextChanged(p0: CharSequence?, p1: Int, p2: Int, p3: Int) {} + } + ) + return view + + } + + fun fetchData() { + if (ConnectionManager().checkConnectivity(activity as Context)) { + progressDialog.visibility = View.VISIBLE + try { + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/restaurants/fetch_result/" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.GET, + url, + null, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + val data = responseJsonObjectData.getJSONArray("data") + + for (i in 0 until data.length()) { + val restaurantJsonObject = data.getJSONObject(i) + val restaurantObject = Restaurant( + restaurantJsonObject.getString("id"), + restaurantJsonObject.getString("name"), + restaurantJsonObject.getString("rating"), + restaurantJsonObject.getString("cost_for_one"), + restaurantJsonObject.getString("image_url") + ) + restaurantInfoList.add(restaurantObject) + + dashboardAdapter = DashboardFragmentAdapter( + activity as Context, + restaurantInfoList + ) + recyclerView.adapter = dashboardAdapter + recyclerView.layoutManager = layoutManager + } + } + progressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + progressDialog.visibility = View.GONE + Toast.makeText( + activity as Context, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + activity as Context, + "Some Unexpected error occurred!", + Toast.LENGTH_SHORT + ) + .show() + } + } else { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + + } + + override fun onCreateOptionsMenu(menu: Menu, inflater: MenuInflater) { + inflater.inflate(R.menu.menu_dashboard, menu) + } + + override fun onOptionsItemSelected(item: MenuItem): Boolean { + val id = item.itemId + + when (id) { + + R.id.sort -> { + radioButtonView = View.inflate( + contextParam, + R.layout.sort_radio_button, + null + ) //radiobutton view for sorting display + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("Sort By?") + alterDialog.setView(radioButtonView) + alterDialog.setPositiveButton("OK") + { _, _ -> + if (radioButtonView.radioHighToLow.isChecked) { + Collections.sort(restaurantInfoList, costComparator) + restaurantInfoList.reverse() + dashboardAdapter.notifyDataSetChanged() //update the adapter of changes + } + if (radioButtonView.radioLowToHigh.isChecked) { + Collections.sort(restaurantInfoList, costComparator) + dashboardAdapter.notifyDataSetChanged() //updates the adapter of changes + } + if (radioButtonView.radioRating.isChecked) { + Collections.sort(restaurantInfoList, ratingComparator) + restaurantInfoList.reverse() + dashboardAdapter.notifyDataSetChanged() + } + } + alterDialog.setNegativeButton("CANCEL") + { _, _ -> + //do nothing + } + alterDialog.create() + alterDialog.show() + } + } + return super.onOptionsItemSelected(item) + } + + + override fun onResume() { + if (ConnectionManager().checkConnectivity(activity as Context)) { + if (restaurantInfoList.isEmpty()) + fetchData() + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + } +} diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/FaqsFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/FaqsFragment.kt new file mode 100644 index 0000000..bd5c8db --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/FaqsFragment.kt @@ -0,0 +1,18 @@ +package com.kartikey.foodrunner.fragment + +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import com.kartikey.foodrunner.R + +class FaqsFragment : Fragment() { + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + return inflater.inflate(R.layout.fragment_faqs, container, false) + } + +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/FavouriteRestaurantFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/FavouriteRestaurantFragment.kt new file mode 100644 index 0000000..03e4614 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/FavouriteRestaurantFragment.kt @@ -0,0 +1,207 @@ +package com.kartikey.foodrunner.fragment + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.AsyncTask +import android.os.Bundle +import android.provider.Settings +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.RelativeLayout +import android.widget.Toast +import androidx.core.app.ActivityCompat +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import androidx.room.Room +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.adapter.DashboardFragmentAdapter +import com.kartikey.foodrunner.database.RestaurantDatabase +import com.kartikey.foodrunner.database.RestaurantEntity +import com.kartikey.foodrunner.model.Restaurant +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException + + +class FavouriteRestaurantFragment(val contextParam: Context) : Fragment() { + + lateinit var recyclerView: RecyclerView + lateinit var layoutManager: RecyclerView.LayoutManager + lateinit var favouriteAdapter: DashboardFragmentAdapter + lateinit var progressDialog: RelativeLayout + lateinit var noFavouritesLayout: RelativeLayout + + var restaurantInfoList = arrayListOf() + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = inflater.inflate(R.layout.fragment_favourite_restaurant, container, false) + + layoutManager = LinearLayoutManager(activity) + recyclerView = view.findViewById(R.id.recyclerViewFavouriteRestaurant) + progressDialog = view.findViewById(R.id.favouriteRestaurantProgressDialog) + noFavouritesLayout = view.findViewById(R.id.noFavouriteRestaurantsLayout) + + return view + } + + fun fetchData() { + if (ConnectionManager().checkConnectivity(activity as Context)) { + + progressDialog.visibility = View.VISIBLE + noFavouritesLayout.visibility = View.INVISIBLE + try { + + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/restaurants/fetch_result/" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.GET, + url, + null, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + + restaurantInfoList.clear() + val data = responseJsonObjectData.getJSONArray("data") + + for (i in 0 until data.length()) { + val restaurantJsonObject = data.getJSONObject(i) + val restaurantEntity = RestaurantEntity( + restaurantJsonObject.getString("id"), + restaurantJsonObject.getString("name") + ) + + if (DBAsynTask(contextParam, restaurantEntity, 1).execute().get()) { + val restaurantObject = Restaurant( + restaurantJsonObject.getString("id"), + restaurantJsonObject.getString("name"), + restaurantJsonObject.getString("rating"), + restaurantJsonObject.getString("cost_for_one"), + restaurantJsonObject.getString("image_url") + ) + + restaurantInfoList.add(restaurantObject) + favouriteAdapter = DashboardFragmentAdapter( + activity as Context, + restaurantInfoList + ) + + recyclerView.adapter = favouriteAdapter + recyclerView.layoutManager = layoutManager + } + } + //Edge case. No items found + if (restaurantInfoList.size == 0) { + noFavouritesLayout.visibility = View.VISIBLE + } + } + progressDialog.visibility = View.GONE + }, + Response.ErrorListener { + Toast.makeText( + activity as Context, + "mSome Error occurred!", + Toast.LENGTH_SHORT + ).show() + progressDialog.visibility = View.GONE + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + activity as Context, + "Some Unexpected error occurred!", + Toast.LENGTH_SHORT + ) + .show() + } + } else { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + + } + + class DBAsynTask(val context: Context, val restaurantEntity: RestaurantEntity, val mode: Int) : + AsyncTask() { + val db = + Room.databaseBuilder(context, RestaurantDatabase::class.java, "restaurant-db").build() + + override fun doInBackground(vararg p0: Void?): Boolean { + /* + * Mode 1-> check if restaurant is in favourites + * Mode 2-> Save the restaurant into DB as favourites + * Mode 3-> Remove the favourite restaurant + */ + when (mode) { + 1 -> { + val restaurant: RestaurantEntity? = db.restaurantDao() + .getRestaurantById(restaurantEntity.restaurantId) + db.close() + return restaurant != null + } + else -> + return false + + } + } + } + + override fun onResume() { + if (ConnectionManager().checkConnectivity(activity as Context)) { + fetchData() + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/ForgotPasswordFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/ForgotPasswordFragment.kt new file mode 100644 index 0000000..146b228 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/ForgotPasswordFragment.kt @@ -0,0 +1,191 @@ +package com.kartikey.foodrunner.fragment + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.EditText +import android.widget.RelativeLayout +import android.widget.Toast +import androidx.core.app.ActivityCompat + +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException +import org.json.JSONObject + + +class ForgotPasswordFragment(val contextParam: Context, val mobile_number: String) : Fragment() { + + lateinit var etOTP: EditText + lateinit var etNewPassword: EditText + lateinit var etConfirmForgotPassword: EditText + lateinit var forgotPasswordProgressDialog: RelativeLayout + lateinit var btnSubmit: Button + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = inflater.inflate(R.layout.fragment_forgot_password, container, false) + + etOTP = view.findViewById(R.id.etOTP) + etNewPassword = view.findViewById(R.id.etNewPassword) + etConfirmForgotPassword = view.findViewById(R.id.etConfirmForgotPassword) + btnSubmit = view.findViewById(R.id.btnSubmit) + forgotPasswordProgressDialog = view.findViewById(R.id.forgotPasswordProgressDialog) + + btnSubmit.setOnClickListener(View.OnClickListener + { + if (etOTP.text.isBlank()) { + etOTP.setError("OTP missing") + } else { + if (etNewPassword.text.isBlank()) { + etNewPassword.setError("Password Missing") + } else { + if (etConfirmForgotPassword.text.isBlank()) { + etConfirmForgotPassword.setError("Confirm Password Missing") + } else { + if ((etNewPassword.text.toString() + .toInt() == etConfirmForgotPassword.text.toString().toInt()) + ) { + if (ConnectionManager().checkConnectivity(activity as Context)) { + forgotPasswordProgressDialog.visibility = View.VISIBLE + + try { + val loginUser = JSONObject() + + loginUser.put("mobile_number", mobile_number) + loginUser.put("password", etNewPassword.text.toString()) + loginUser.put("otp", etOTP.text.toString()) + + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/reset_password/fetch_result" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.POST, + url, + loginUser, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = + responseJsonObjectData.getBoolean("success") + + if (success) { + val serverMessage = + responseJsonObjectData.getString("successMessage") + + Toast.makeText( + contextParam, + serverMessage, + Toast.LENGTH_SHORT + ).show() + + passwordChanged() + } else { + val responseMessageServer = + responseJsonObjectData.getString("errorMessage") + Toast.makeText( + contextParam, + responseMessageServer.toString(), + Toast.LENGTH_SHORT + ).show() + } + forgotPasswordProgressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + forgotPasswordProgressDialog.visibility = View.GONE + Toast.makeText( + contextParam, + "mSome Error occurred!!!", + Toast.LENGTH_SHORT + ).show() + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + } catch (e: JSONException) { + Toast.makeText( + contextParam, + "Some unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + } else { + val alterDialog = + androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.create() + alterDialog.show() + } + } else { + etConfirmForgotPassword.setError("Passwords don't match") + } + } + } + } + + }) + + return view + } + + fun passwordChanged() { + val transaction = fragmentManager?.beginTransaction() + transaction?.replace( + R.id.frameLayout, + LoginFragment(contextParam) + ) + transaction?.commit() + } + + override fun onResume() { + + if (!ConnectionManager().checkConnectivity(activity as Context)) { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/ForgotPasswordInputFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/ForgotPasswordInputFragment.kt new file mode 100644 index 0000000..fe21765 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/ForgotPasswordInputFragment.kt @@ -0,0 +1,201 @@ +package com.kartikey.foodrunner.fragment + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.EditText +import android.widget.RelativeLayout +import android.widget.Toast +import androidx.core.app.ActivityCompat + +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException +import org.json.JSONObject + + +class ForgotPasswordInputFragment(val contextParam: Context) : Fragment() { + + lateinit var etMobileNumber: EditText + lateinit var etEmail: EditText + lateinit var btnNext: Button + lateinit var progressDialog: RelativeLayout + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = inflater.inflate(R.layout.fragment_forgot_password_input, container, false) + + etMobileNumber = view.findViewById(R.id.etMobileNumber) + etEmail = view.findViewById(R.id.etEmail) + btnNext = view.findViewById(R.id.btnNext) + progressDialog = view.findViewById(R.id.forgotPasswordInputProgressDialog) + + btnNext.setOnClickListener(View.OnClickListener + { + + if (etMobileNumber.text.isBlank()) { + etMobileNumber.setError("Mobile Number Missing") + } else { + if (etEmail.text.isBlank()) { + etEmail.setError("Email Missing") + } else { + + if (ConnectionManager().checkConnectivity(activity as Context)) { + try { + val loginUser = JSONObject() + + loginUser.put("mobile_number", etMobileNumber.text) + loginUser.put("email", etEmail.text) + + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/forgot_password/fetch_result/" + + progressDialog.visibility = View.VISIBLE + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.POST, + url, + loginUser, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + val firstTry = + responseJsonObjectData.getBoolean("first_try") + + if (firstTry) { + Toast.makeText( + contextParam, + "OTP sent", + Toast.LENGTH_SHORT + ).show() + + callChangePasswordFragment() + + } else { + Toast.makeText( + contextParam, + "OTP sent already", + Toast.LENGTH_SHORT + ).show() + + callChangePasswordFragment() + } + + } else { + val responseMessageServer = + responseJsonObjectData.getString("errorMessage") + Toast.makeText( + contextParam, + responseMessageServer.toString(), + Toast.LENGTH_SHORT + ).show() + + } + progressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + println(it) + Toast.makeText( + context, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + + + progressDialog.visibility = View.GONE + + }) { + + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + contextParam, + "Some unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + } else { + val alterDialog = + androidx.appcompat.app.AlertDialog.Builder(activity as Context) + + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.create() + alterDialog.show() + } + } + } + }) + + return view + } + + fun callChangePasswordFragment() { + val transaction = fragmentManager?.beginTransaction() + + transaction?.replace( + R.id.frameLayout, + ForgotPasswordFragment(contextParam, etMobileNumber.text.toString()) + ) + transaction?.commit() + } + + + override fun onResume() { + if (!ConnectionManager().checkConnectivity(activity as Context)) { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + + } + + super.onResume() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/LoginFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/LoginFragment.kt new file mode 100644 index 0000000..02d0bee --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/LoginFragment.kt @@ -0,0 +1,238 @@ +package com.kartikey.foodrunner.fragment + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.graphics.Paint +import android.os.Bundle +import android.provider.Settings +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.* +import androidx.core.app.ActivityCompat +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.activity.DashboardActivity +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException +import org.json.JSONObject + + +class LoginFragment(val contextParam: Context) : Fragment() { + lateinit var txtSignUp: TextView + lateinit var etMobileNumber: EditText + lateinit var etPassword: EditText + lateinit var txtForgotPassword: TextView + lateinit var btnLogin: Button + lateinit var loginProgressDialog: RelativeLayout + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + val view = inflater.inflate(R.layout.fragment_login, container, false) + + etMobileNumber = view.findViewById(R.id.etMobileNumber) + etPassword = view.findViewById(R.id.etPassword) + txtForgotPassword = view.findViewById(R.id.txtForgotPassword) + txtSignUp = view.findViewById(R.id.txtSignUp) + btnLogin = view.findViewById(R.id.btnLogin) + loginProgressDialog = view.findViewById(R.id.loginProgressDialog) + + loginProgressDialog.visibility = View.GONE + + //under line text + txtForgotPassword.paintFlags = Paint.UNDERLINE_TEXT_FLAG + txtSignUp.paintFlags = Paint.UNDERLINE_TEXT_FLAG + + txtForgotPassword.setOnClickListener { + openForgotPasswordInputFragment() + } + + txtSignUp.setOnClickListener { + openRegisterFragment() + } + + btnLogin.setOnClickListener { + + btnLogin.visibility = View.GONE + + if (etMobileNumber.text.isBlank()) { + etMobileNumber.setError("Mobile Number Missing") + btnLogin.visibility = View.VISIBLE + } else { + if (etPassword.text.isBlank()) { + btnLogin.visibility = View.VISIBLE + etPassword.setError("Missing Password") + } else { + loginUserFun() + } + } + } + return view + } + + fun openForgotPasswordInputFragment() { + val transaction = fragmentManager?.beginTransaction() + transaction?.replace( + R.id.frameLayout, + ForgotPasswordInputFragment(contextParam) + ) + transaction?.commit()//apply changes + } + + + fun openRegisterFragment() { + val transaction = fragmentManager?.beginTransaction() + transaction?.replace( + R.id.frameLayout, + RegisterFragment(contextParam) + ) + transaction?.commit() + } + + + fun loginUserFun() { + val sharedPreferencess = contextParam.getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + if (ConnectionManager().checkConnectivity(activity as Context)) { + loginProgressDialog.visibility = View.VISIBLE + try { + val loginUser = JSONObject() + loginUser.put("mobile_number", etMobileNumber.text) + loginUser.put("password", etPassword.text) + + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/login/fetch_result/" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.POST, + url, + loginUser, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + + if (success) { + val data = responseJsonObjectData.getJSONObject("data") + sharedPreferencess.edit().putBoolean("user_logged_in", true).apply() + sharedPreferencess.edit() + .putString("user_id", data.getString("user_id")).apply() + sharedPreferencess.edit().putString("name", data.getString("name")) + .apply() + sharedPreferencess.edit().putString("email", data.getString("email")) + .apply() + sharedPreferencess.edit() + .putString("mobile_number", data.getString("mobile_number")).apply() + sharedPreferencess.edit() + .putString("address", data.getString("address")).apply() + + Toast.makeText( + contextParam, + "Welcome " + data.getString("name"), + Toast.LENGTH_LONG + ).show() + + userSuccessfullyLoggedIn() + + } else { + btnLogin.visibility = View.VISIBLE + + val responseMessageServer = + responseJsonObjectData.getString("errorMessage") + Toast.makeText( + contextParam, + responseMessageServer.toString(), + Toast.LENGTH_SHORT + ).show() + } + loginProgressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + println(it) + btnLogin.visibility = View.VISIBLE + loginProgressDialog.visibility = View.GONE + + Toast.makeText( + contextParam, + "Some Error occurred!!!", + Toast.LENGTH_SHORT + ).show() + + + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + btnLogin.visibility = View.VISIBLE + Toast.makeText( + contextParam, + "Some unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + } else { + btnLogin.visibility = View.VISIBLE + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.create() + alterDialog.show() + } + } + + fun userSuccessfullyLoggedIn() { + val intent = Intent(activity as Context, DashboardActivity::class.java) + startActivity(intent) + activity?.finish(); + } + + override fun onResume() { + if (!ConnectionManager().checkConnectivity(activity as Context)) { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/OrderHistoryFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/OrderHistoryFragment.kt new file mode 100644 index 0000000..7c79e42 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/OrderHistoryFragment.kt @@ -0,0 +1,186 @@ +package com.kartikey.foodrunner.fragment + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.LinearLayout +import android.widget.RelativeLayout +import android.widget.Toast +import androidx.core.app.ActivityCompat.finishAffinity +import androidx.recyclerview.widget.LinearLayoutManager +import androidx.recyclerview.widget.RecyclerView +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.adapter.OrderHistoryAdapter +import com.kartikey.foodrunner.model.OrderHistoryRestaurant +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException + + +class OrderHistoryFragment : Fragment() { + + lateinit var layoutManager: RecyclerView.LayoutManager + lateinit var menuAdapter: OrderHistoryAdapter + lateinit var recyclerViewAllOrders: RecyclerView + lateinit var orderHistoryProgressDialog: RelativeLayout + lateinit var orderHistoryNoOrders: RelativeLayout + lateinit var orderHistoryDefaultOrders: LinearLayout + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + // Inflate the layout for this fragment + val view = inflater.inflate(R.layout.fragment_order_history, container, false) + + recyclerViewAllOrders = view.findViewById(R.id.recyclerViewAllOrders) + orderHistoryProgressDialog = view.findViewById(R.id.orderHistoryProgressLayout) + orderHistoryNoOrders = view.findViewById(R.id.orderHistoryNoOrders) + orderHistoryDefaultOrders = view.findViewById(R.id.linearLayoutOrder) + + return view + } + + fun setItemsForEachRestaurant() { + layoutManager = LinearLayoutManager(activity) + + val orderedRestaurantList = ArrayList() + val sharedPreferences = activity?.getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + val userId = sharedPreferences?.getString("user_id", "000") + + if (ConnectionManager().checkConnectivity(activity as Context)) { + orderHistoryProgressDialog.visibility = View.VISIBLE + + try { + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/orders/fetch_result/${userId}" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.GET, + url, + null, + Response.Listener + { + + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + val data = responseJsonObjectData.getJSONArray("data") + + //Edge Case. No orders present + if (data.length() == 0) { + orderHistoryNoOrders.visibility = View.VISIBLE + orderHistoryDefaultOrders.visibility = View.INVISIBLE + } else { + orderHistoryNoOrders.visibility = View.GONE + + for (i in 0 until data.length()) { + val restaurantItemJsonObject = data.getJSONObject(i) + + val eachRestaurantObject = OrderHistoryRestaurant( + restaurantItemJsonObject.getString("order_id"), + restaurantItemJsonObject.getString("restaurant_name"), + restaurantItemJsonObject.getString("total_cost"), + restaurantItemJsonObject.getString("order_placed_at") + .substring(0, 10) + ) + + orderedRestaurantList.add(eachRestaurantObject) + menuAdapter = OrderHistoryAdapter( + activity as Context, + orderedRestaurantList + ) + recyclerViewAllOrders.adapter = menuAdapter + recyclerViewAllOrders.layoutManager = layoutManager + + } + } + } + orderHistoryProgressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + orderHistoryProgressDialog.visibility = View.GONE + + Toast.makeText( + activity, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + context, + "Some Unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + } + + override fun onResume() { + if (ConnectionManager().checkConnectivity(activity as Context)) { + setItemsForEachRestaurant() + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + + } + + +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/ProfileFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/ProfileFragment.kt new file mode 100644 index 0000000..7b8c8bf --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/ProfileFragment.kt @@ -0,0 +1,43 @@ +package com.kartikey.foodrunner.fragment + +import android.content.Context +import android.os.Bundle +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.TextView +import com.kartikey.foodrunner.R + +class ProfileFragment(val contextParam: Context) : Fragment() { + + lateinit var txtName: TextView + lateinit var txtEmail: TextView + lateinit var txtMobileNumber: TextView + lateinit var txtAddress: TextView + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + + val view = inflater.inflate(R.layout.fragment_profile, container, false) + + txtName = view.findViewById(R.id.txtName) + txtEmail = view.findViewById(R.id.txtEmail) + txtMobileNumber = view.findViewById(R.id.txtMobileNumber) + txtAddress = view.findViewById(R.id.txtAddress) + + val sharedPreferences = contextParam.getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + txtName.text = sharedPreferences.getString("name", "") + txtEmail.text = sharedPreferences.getString("email", "") + txtMobileNumber.text = "+91-" + sharedPreferences.getString("mobile_number", "") + txtAddress.text = sharedPreferences.getString("address", "") + + return view + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/fragment/RegisterFragment.kt b/app/src/main/java/com/kartikey/foodrunner/fragment/RegisterFragment.kt new file mode 100644 index 0000000..ffb04a7 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/fragment/RegisterFragment.kt @@ -0,0 +1,249 @@ +package com.kartikey.foodrunner.fragment + +import android.app.Activity +import android.content.Context +import android.content.Intent +import android.os.Bundle +import android.provider.Settings +import androidx.fragment.app.Fragment +import android.view.LayoutInflater +import android.view.View +import android.view.ViewGroup +import android.widget.Button +import android.widget.EditText +import android.widget.RelativeLayout +import android.widget.Toast +import androidx.appcompat.app.AppCompatActivity +import androidx.appcompat.widget.Toolbar +import androidx.core.app.ActivityCompat +import com.android.volley.Request +import com.android.volley.Response +import com.android.volley.toolbox.JsonObjectRequest +import com.android.volley.toolbox.Volley +import com.kartikey.foodrunner.R +import com.kartikey.foodrunner.activity.DashboardActivity +import com.kartikey.foodrunner.utils.ConnectionManager +import org.json.JSONException +import org.json.JSONObject + + +class RegisterFragment(val contextParam: Context) : Fragment() { + + lateinit var etName: EditText + lateinit var etEmail: EditText + lateinit var etMobileNumber: EditText + lateinit var etDeliveryAddress: EditText + lateinit var etPassword: EditText + lateinit var etConfirmPassword: EditText + lateinit var btnRegister: Button + lateinit var registerProgressDialog: RelativeLayout + + override fun onCreateView( + inflater: LayoutInflater, container: ViewGroup?, + savedInstanceState: Bundle? + ): View? { + + val view = inflater.inflate(R.layout.fragment_register, container, false) + + etName = view.findViewById(R.id.etName) + etEmail = view.findViewById(R.id.etEmail) + etMobileNumber = view.findViewById(R.id.etMobileNumber) + etDeliveryAddress = view.findViewById(R.id.etDeliveryAddress) + etPassword = view.findViewById(R.id.etPassword) + etConfirmPassword = view.findViewById(R.id.etConfirmPassword) + btnRegister = view.findViewById(R.id.btnSubmit) + registerProgressDialog = view.findViewById(R.id.registerProgressdialog) + + btnRegister.setOnClickListener { + registerUserFun() + } + return view + } + + fun userSuccessfullyRegistered() { + openDashBoard() + } + + fun openDashBoard() { + val intent = Intent(activity as Context, DashboardActivity::class.java) + startActivity(intent) + activity?.finish(); + } + + fun registerUserFun() { + val sharedPreferences = contextParam.getSharedPreferences( + getString(R.string.shared_preferences), + Context.MODE_PRIVATE + ) + + sharedPreferences.edit().putBoolean("user_logged_in", false).apply() + + if (ConnectionManager().checkConnectivity(activity as Context)) { + if (checkForErrors()) { + registerProgressDialog.visibility = View.VISIBLE + try { + val registerUser = JSONObject() + registerUser.put("name", etName.text) + registerUser.put("mobile_number", etMobileNumber.text) + registerUser.put("password", etPassword.text) + registerUser.put("address", etDeliveryAddress.text) + registerUser.put("email", etEmail.text) + + val queue = Volley.newRequestQueue(activity as Context) + val url = "http://13.235.250.119/v2/register/fetch_result" + + val jsonObjectRequest = object : JsonObjectRequest( + Request.Method.POST, + url, + registerUser, + Response.Listener + { + val responseJsonObjectData = it.getJSONObject("data") + val success = responseJsonObjectData.getBoolean("success") + + if (success) { + + val data = responseJsonObjectData.getJSONObject("data") + sharedPreferences.edit() + .putBoolean("user_logged_in", true).apply() + sharedPreferences.edit() + .putString("user_id", data.getString("user_id")).apply() + sharedPreferences.edit().putString("name", data.getString("name")) + .apply() + sharedPreferences.edit().putString("email", data.getString("email")) + .apply() + sharedPreferences.edit() + .putString("mobile_number", data.getString("mobile_number")) + .apply() + sharedPreferences.edit() + .putString("address", data.getString("address")).apply() + + Toast.makeText( + contextParam, + "Registered successfully", + Toast.LENGTH_SHORT + ).show() + + userSuccessfullyRegistered() + + } else { + val responseMessageServer = + responseJsonObjectData.getString("errorMessage") + Toast.makeText( + contextParam, + responseMessageServer.toString(), + Toast.LENGTH_SHORT + ).show() + } + registerProgressDialog.visibility = View.GONE + }, + Response.ErrorListener + { + registerProgressDialog.visibility = View.GONE + Toast.makeText( + contextParam, + "Some Error occurred!", + Toast.LENGTH_SHORT + ).show() + + }) { + override fun getHeaders(): MutableMap { + val headers = HashMap() + headers["Content-type"] = "application/json" + headers["token"] = "13714ab03e5a4d" + return headers + } + } + queue.add(jsonObjectRequest) + + } catch (e: JSONException) { + Toast.makeText( + contextParam, + "Some unexpected error occurred!", + Toast.LENGTH_SHORT + ).show() + } + } + } else { + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.create() + alterDialog.show() + } + } + + fun checkForErrors(): Boolean { + //errorPassCount determines if there are any errors or not + var errorPassCount = 0 + if (etName.text.isBlank()) { + etName.error = "Field Missing!" + } else { + errorPassCount++ + } + if (etMobileNumber.text.isBlank()) { + etMobileNumber.error = "Field Missing!" + } else { + errorPassCount++ + } + if (etEmail.text.isBlank()) { + etEmail.error = "Field Missing!" + } else { + errorPassCount++ + } + if (etDeliveryAddress.text.isBlank()) { + etDeliveryAddress.setError("Field Missing!") + } else { + errorPassCount++ + } + if (etConfirmPassword.text.isBlank()) { + etConfirmPassword.setError("Field Missing!") + } else { + errorPassCount++ + } + if (etPassword.text.isBlank()) { + etPassword.setError("Field Missing!") + } else { + errorPassCount++ + } + if (etPassword.text.isNotBlank() && etConfirmPassword.text.isNotBlank()) { + if (etPassword.text.toString().toInt() == etConfirmPassword.text.toString().toInt()) { + errorPassCount++ + } else { + etConfirmPassword.setError("Confirmed Password doesn't match") + } + } + return errorPassCount == 7 + } + + override fun onResume() { + if (!ConnectionManager().checkConnectivity(activity as Context)) { + + val alterDialog = androidx.appcompat.app.AlertDialog.Builder(activity as Context) + alterDialog.setTitle("No Internet") + alterDialog.setMessage("Internet Connection can't be established!") + alterDialog.setPositiveButton("Open Settings") + { _, _ -> + val settingsIntent = Intent(Settings.ACTION_SETTINGS) + startActivity(settingsIntent) + } + alterDialog.setNegativeButton("Exit") + { _, _ -> + ActivityCompat.finishAffinity(activity as Activity) + } + alterDialog.setCancelable(false) + alterDialog.create() + alterDialog.show() + } + super.onResume() + } +} \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/model/CartItems.kt b/app/src/main/java/com/kartikey/foodrunner/model/CartItems.kt new file mode 100644 index 0000000..70dd71f --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/model/CartItems.kt @@ -0,0 +1,9 @@ +package com.kartikey.foodrunner.model + +data class CartItems + ( + var itemId: String, + var itemName: String, + var itemPrice: String, + var restaurantId: String +) \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/model/OrderHistoryRestaurant.kt b/app/src/main/java/com/kartikey/foodrunner/model/OrderHistoryRestaurant.kt new file mode 100644 index 0000000..a145a80 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/model/OrderHistoryRestaurant.kt @@ -0,0 +1,9 @@ +package com.kartikey.foodrunner.model + +data class OrderHistoryRestaurant + ( + var orderId: String, + var restaurantName: String, + var totalCost: String, + var orderPlacedAt: String +) \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/model/Restaurant.kt b/app/src/main/java/com/kartikey/foodrunner/model/Restaurant.kt new file mode 100644 index 0000000..6adaa29 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/model/Restaurant.kt @@ -0,0 +1,10 @@ +package com.kartikey.foodrunner.model + +data class Restaurant + ( + var restaurantId: String, + var restaurantName: String, + var restaurantRating: String, + var costForOne: String, + var restaurantImage: String +) \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/model/RestaurantMenu.kt b/app/src/main/java/com/kartikey/foodrunner/model/RestaurantMenu.kt new file mode 100644 index 0000000..30e336a --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/model/RestaurantMenu.kt @@ -0,0 +1,8 @@ +package com.kartikey.foodrunner.model + +data class RestaurantMenu + ( + var id: String, + var name: String, + var cost_for_one: String +) \ No newline at end of file diff --git a/app/src/main/java/com/kartikey/foodrunner/utils/ConnectionManager.kt b/app/src/main/java/com/kartikey/foodrunner/utils/ConnectionManager.kt new file mode 100644 index 0000000..6a034f2 --- /dev/null +++ b/app/src/main/java/com/kartikey/foodrunner/utils/ConnectionManager.kt @@ -0,0 +1,21 @@ +package com.kartikey.foodrunner.utils + +import android.content.Context +import android.net.ConnectivityManager +import android.net.NetworkInfo + +class ConnectionManager { + + fun checkConnectivity(context: Context): Boolean { + + val connectivityManager = + context.getSystemService(Context.CONNECTIVITY_SERVICE) as ConnectivityManager + val activeNetwork: NetworkInfo? = connectivityManager.activeNetworkInfo + + if (activeNetwork?.isConnected !== null) { + return activeNetwork.isConnected + } else { + return false + } + } +} \ No newline at end of file diff --git a/app/src/main/res/drawable-anydpi/ic_default_image_restaurant.xml b/app/src/main/res/drawable-anydpi/ic_default_image_restaurant.xml new file mode 100644 index 0000000..6aaa315 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_default_image_restaurant.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_fav_fill.xml b/app/src/main/res/drawable-anydpi/ic_fav_fill.xml new file mode 100644 index 0000000..c3ab836 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_fav_fill.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_fav_outline.xml b/app/src/main/res/drawable-anydpi/ic_fav_outline.xml new file mode 100644 index 0000000..d2f6b39 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_fav_outline.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_cart.xml b/app/src/main/res/drawable-anydpi/ic_icon_cart.xml new file mode 100644 index 0000000..056088a --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_cart.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_email.xml b/app/src/main/res/drawable-anydpi/ic_icon_email.xml new file mode 100644 index 0000000..8e64dcc --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_email.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_favourite.xml b/app/src/main/res/drawable-anydpi/ic_icon_favourite.xml new file mode 100644 index 0000000..2cecffe --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_favourite.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_home.xml b/app/src/main/res/drawable-anydpi/ic_icon_home.xml new file mode 100644 index 0000000..a5c6a23 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_home.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_location.xml b/app/src/main/res/drawable-anydpi/ic_icon_location.xml new file mode 100644 index 0000000..7a45625 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_location.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_logout.xml b/app/src/main/res/drawable-anydpi/ic_icon_logout.xml new file mode 100644 index 0000000..c0ce723 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_logout.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_mobile.xml b/app/src/main/res/drawable-anydpi/ic_icon_mobile.xml new file mode 100644 index 0000000..7887370 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_mobile.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_order_history.xml b/app/src/main/res/drawable-anydpi/ic_icon_order_history.xml new file mode 100644 index 0000000..3702ba5 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_order_history.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_password.xml b/app/src/main/res/drawable-anydpi/ic_icon_password.xml new file mode 100644 index 0000000..01e838a --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_password.xml @@ -0,0 +1,11 @@ + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_person.xml b/app/src/main/res/drawable-anydpi/ic_icon_person.xml new file mode 100644 index 0000000..b7c595e --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_person.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_icon_person_filled.xml b/app/src/main/res/drawable-anydpi/ic_icon_person_filled.xml new file mode 100644 index 0000000..38b9c74 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_icon_person_filled.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_menu.xml b/app/src/main/res/drawable-anydpi/ic_menu.xml new file mode 100644 index 0000000..6783379 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_menu.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_search.xml b/app/src/main/res/drawable-anydpi/ic_search.xml new file mode 100644 index 0000000..22f20e5 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_search.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-anydpi/ic_white_back_arrow.xml b/app/src/main/res/drawable-anydpi/ic_white_back_arrow.xml new file mode 100644 index 0000000..3a26503 --- /dev/null +++ b/app/src/main/res/drawable-anydpi/ic_white_back_arrow.xml @@ -0,0 +1,17 @@ + + + + + diff --git a/app/src/main/res/drawable-hdpi/ic_default_image_restaurant.png b/app/src/main/res/drawable-hdpi/ic_default_image_restaurant.png new file mode 100644 index 0000000..3fffd75 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_default_image_restaurant.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_fav_fill.png b/app/src/main/res/drawable-hdpi/ic_fav_fill.png new file mode 100644 index 0000000..1242901 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_fav_fill.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_fav_outline.png b/app/src/main/res/drawable-hdpi/ic_fav_outline.png new file mode 100644 index 0000000..019260d Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_fav_outline.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_cart.png b/app/src/main/res/drawable-hdpi/ic_icon_cart.png new file mode 100644 index 0000000..0b96f28 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_cart.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_email.png b/app/src/main/res/drawable-hdpi/ic_icon_email.png new file mode 100644 index 0000000..1e4f1ce Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_email.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_faqs.png b/app/src/main/res/drawable-hdpi/ic_icon_faqs.png new file mode 100644 index 0000000..18bdeac Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_faqs.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_favourite.png b/app/src/main/res/drawable-hdpi/ic_icon_favourite.png new file mode 100644 index 0000000..89f0276 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_favourite.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_home.png b/app/src/main/res/drawable-hdpi/ic_icon_home.png new file mode 100644 index 0000000..67d102b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_home.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_location.png b/app/src/main/res/drawable-hdpi/ic_icon_location.png new file mode 100644 index 0000000..8adcffa Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_location.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_logout.png b/app/src/main/res/drawable-hdpi/ic_icon_logout.png new file mode 100644 index 0000000..1e38ca2 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_logout.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_mobile.png b/app/src/main/res/drawable-hdpi/ic_icon_mobile.png new file mode 100644 index 0000000..5399f10 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_mobile.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_order_history.png b/app/src/main/res/drawable-hdpi/ic_icon_order_history.png new file mode 100644 index 0000000..59186c5 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_order_history.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_password.png b/app/src/main/res/drawable-hdpi/ic_icon_password.png new file mode 100644 index 0000000..13254d1 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_password.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_person.png b/app/src/main/res/drawable-hdpi/ic_icon_person.png new file mode 100644 index 0000000..5f6efcd Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_person.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_icon_person_filled.png b/app/src/main/res/drawable-hdpi/ic_icon_person_filled.png new file mode 100644 index 0000000..dd5139b Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_icon_person_filled.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_menu.png b/app/src/main/res/drawable-hdpi/ic_menu.png new file mode 100644 index 0000000..d771ec2 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_menu.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_rating_star.png b/app/src/main/res/drawable-hdpi/ic_rating_star.png new file mode 100644 index 0000000..5c230f0 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_rating_star.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_search.png b/app/src/main/res/drawable-hdpi/ic_search.png new file mode 100644 index 0000000..9b8cdd3 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_search.png differ diff --git a/app/src/main/res/drawable-hdpi/ic_white_back_arrow.png b/app/src/main/res/drawable-hdpi/ic_white_back_arrow.png new file mode 100644 index 0000000..5153c62 Binary files /dev/null and b/app/src/main/res/drawable-hdpi/ic_white_back_arrow.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_default_image_restaurant.png b/app/src/main/res/drawable-mdpi/ic_default_image_restaurant.png new file mode 100644 index 0000000..23f94b2 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_default_image_restaurant.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_fav_fill.png b/app/src/main/res/drawable-mdpi/ic_fav_fill.png new file mode 100644 index 0000000..a757fca Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_fav_fill.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_fav_outline.png b/app/src/main/res/drawable-mdpi/ic_fav_outline.png new file mode 100644 index 0000000..0f6be64 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_fav_outline.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_cart.png b/app/src/main/res/drawable-mdpi/ic_icon_cart.png new file mode 100644 index 0000000..ea6f0a3 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_cart.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_email.png b/app/src/main/res/drawable-mdpi/ic_icon_email.png new file mode 100644 index 0000000..c4dfc54 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_email.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_faqs.png b/app/src/main/res/drawable-mdpi/ic_icon_faqs.png new file mode 100644 index 0000000..6f4528e Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_faqs.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_favourite.png b/app/src/main/res/drawable-mdpi/ic_icon_favourite.png new file mode 100644 index 0000000..af746be Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_favourite.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_home.png b/app/src/main/res/drawable-mdpi/ic_icon_home.png new file mode 100644 index 0000000..f34a246 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_home.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_location.png b/app/src/main/res/drawable-mdpi/ic_icon_location.png new file mode 100644 index 0000000..5671687 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_location.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_logout.png b/app/src/main/res/drawable-mdpi/ic_icon_logout.png new file mode 100644 index 0000000..0692435 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_logout.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_mobile.png b/app/src/main/res/drawable-mdpi/ic_icon_mobile.png new file mode 100644 index 0000000..3d646c1 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_mobile.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_order_history.png b/app/src/main/res/drawable-mdpi/ic_icon_order_history.png new file mode 100644 index 0000000..8636b17 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_order_history.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_password.png b/app/src/main/res/drawable-mdpi/ic_icon_password.png new file mode 100644 index 0000000..0fdc058 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_password.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_person.png b/app/src/main/res/drawable-mdpi/ic_icon_person.png new file mode 100644 index 0000000..01d2a3f Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_person.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_icon_person_filled.png b/app/src/main/res/drawable-mdpi/ic_icon_person_filled.png new file mode 100644 index 0000000..d6d2b33 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_icon_person_filled.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_menu.png b/app/src/main/res/drawable-mdpi/ic_menu.png new file mode 100644 index 0000000..8b415a6 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_menu.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_rating_star.png b/app/src/main/res/drawable-mdpi/ic_rating_star.png new file mode 100644 index 0000000..f1f2b4d Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_rating_star.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_search.png b/app/src/main/res/drawable-mdpi/ic_search.png new file mode 100644 index 0000000..3176c09 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_search.png differ diff --git a/app/src/main/res/drawable-mdpi/ic_white_back_arrow.png b/app/src/main/res/drawable-mdpi/ic_white_back_arrow.png new file mode 100644 index 0000000..f41cfe8 Binary files /dev/null and b/app/src/main/res/drawable-mdpi/ic_white_back_arrow.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_default_image_restaurant.png b/app/src/main/res/drawable-xhdpi/ic_default_image_restaurant.png new file mode 100644 index 0000000..7f6e317 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_default_image_restaurant.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_fav_fill.png b/app/src/main/res/drawable-xhdpi/ic_fav_fill.png new file mode 100644 index 0000000..e3d1b6d Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_fav_fill.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_fav_outline.png b/app/src/main/res/drawable-xhdpi/ic_fav_outline.png new file mode 100644 index 0000000..4e49a94 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_fav_outline.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_cart.png b/app/src/main/res/drawable-xhdpi/ic_icon_cart.png new file mode 100644 index 0000000..976908b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_cart.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_email.png b/app/src/main/res/drawable-xhdpi/ic_icon_email.png new file mode 100644 index 0000000..e47ce93 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_email.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_faqs.png b/app/src/main/res/drawable-xhdpi/ic_icon_faqs.png new file mode 100644 index 0000000..c52b502 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_faqs.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_favourite.png b/app/src/main/res/drawable-xhdpi/ic_icon_favourite.png new file mode 100644 index 0000000..db1c87b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_favourite.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_home.png b/app/src/main/res/drawable-xhdpi/ic_icon_home.png new file mode 100644 index 0000000..f3a7433 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_home.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_location.png b/app/src/main/res/drawable-xhdpi/ic_icon_location.png new file mode 100644 index 0000000..cffe52e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_location.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_logout.png b/app/src/main/res/drawable-xhdpi/ic_icon_logout.png new file mode 100644 index 0000000..236fe5e Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_logout.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_mobile.png b/app/src/main/res/drawable-xhdpi/ic_icon_mobile.png new file mode 100644 index 0000000..cec9169 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_mobile.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_order_history.png b/app/src/main/res/drawable-xhdpi/ic_icon_order_history.png new file mode 100644 index 0000000..b0861ae Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_order_history.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_password.png b/app/src/main/res/drawable-xhdpi/ic_icon_password.png new file mode 100644 index 0000000..ec56aaf Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_password.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_person.png b/app/src/main/res/drawable-xhdpi/ic_icon_person.png new file mode 100644 index 0000000..beec856 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_person.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_icon_person_filled.png b/app/src/main/res/drawable-xhdpi/ic_icon_person_filled.png new file mode 100644 index 0000000..6f4c23c Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_icon_person_filled.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_menu.png b/app/src/main/res/drawable-xhdpi/ic_menu.png new file mode 100644 index 0000000..ab98cad Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_menu.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_rating_star.png b/app/src/main/res/drawable-xhdpi/ic_rating_star.png new file mode 100644 index 0000000..ad0f2b3 Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_rating_star.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_search.png b/app/src/main/res/drawable-xhdpi/ic_search.png new file mode 100644 index 0000000..be56c4b Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_search.png differ diff --git a/app/src/main/res/drawable-xhdpi/ic_white_back_arrow.png b/app/src/main/res/drawable-xhdpi/ic_white_back_arrow.png new file mode 100644 index 0000000..fe88ecf Binary files /dev/null and b/app/src/main/res/drawable-xhdpi/ic_white_back_arrow.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_default_image_restaurant.png b/app/src/main/res/drawable-xxhdpi/ic_default_image_restaurant.png new file mode 100644 index 0000000..e036ee6 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_default_image_restaurant.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_fav_fill.png b/app/src/main/res/drawable-xxhdpi/ic_fav_fill.png new file mode 100644 index 0000000..478e0d1 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_fav_fill.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_fav_outline.png b/app/src/main/res/drawable-xxhdpi/ic_fav_outline.png new file mode 100644 index 0000000..d458fd3 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_fav_outline.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_cart.png b/app/src/main/res/drawable-xxhdpi/ic_icon_cart.png new file mode 100644 index 0000000..f4595ca Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_cart.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_email.png b/app/src/main/res/drawable-xxhdpi/ic_icon_email.png new file mode 100644 index 0000000..731ca7a Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_email.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_faqs.png b/app/src/main/res/drawable-xxhdpi/ic_icon_faqs.png new file mode 100644 index 0000000..91238ff Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_faqs.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_favourite.png b/app/src/main/res/drawable-xxhdpi/ic_icon_favourite.png new file mode 100644 index 0000000..ac54017 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_favourite.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_home.png b/app/src/main/res/drawable-xxhdpi/ic_icon_home.png new file mode 100644 index 0000000..43cdd90 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_home.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_location.png b/app/src/main/res/drawable-xxhdpi/ic_icon_location.png new file mode 100644 index 0000000..b303e1d Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_location.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_logout.png b/app/src/main/res/drawable-xxhdpi/ic_icon_logout.png new file mode 100644 index 0000000..f1fdcd4 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_logout.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_mobile.png b/app/src/main/res/drawable-xxhdpi/ic_icon_mobile.png new file mode 100644 index 0000000..50f022b Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_mobile.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_order_history.png b/app/src/main/res/drawable-xxhdpi/ic_icon_order_history.png new file mode 100644 index 0000000..e322e4b Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_order_history.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_password.png b/app/src/main/res/drawable-xxhdpi/ic_icon_password.png new file mode 100644 index 0000000..7d0bf4f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_password.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_person.png b/app/src/main/res/drawable-xxhdpi/ic_icon_person.png new file mode 100644 index 0000000..08ff56a Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_person.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_icon_person_filled.png b/app/src/main/res/drawable-xxhdpi/ic_icon_person_filled.png new file mode 100644 index 0000000..d2a73a1 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_icon_person_filled.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_menu.png b/app/src/main/res/drawable-xxhdpi/ic_menu.png new file mode 100644 index 0000000..65091d3 Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_menu.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_rating_star.png b/app/src/main/res/drawable-xxhdpi/ic_rating_star.png new file mode 100644 index 0000000..209671f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_rating_star.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_search.png b/app/src/main/res/drawable-xxhdpi/ic_search.png new file mode 100644 index 0000000..bcc211f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_search.png differ diff --git a/app/src/main/res/drawable-xxhdpi/ic_white_back_arrow.png b/app/src/main/res/drawable-xxhdpi/ic_white_back_arrow.png new file mode 100644 index 0000000..6c73d0f Binary files /dev/null and b/app/src/main/res/drawable-xxhdpi/ic_white_back_arrow.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_icon_faqs.png b/app/src/main/res/drawable-xxxhdpi/ic_icon_faqs.png new file mode 100644 index 0000000..2c252bd Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_icon_faqs.png differ diff --git a/app/src/main/res/drawable-xxxhdpi/ic_rating_star.png b/app/src/main/res/drawable-xxxhdpi/ic_rating_star.png new file mode 100644 index 0000000..09bb02f Binary files /dev/null and b/app/src/main/res/drawable-xxxhdpi/ic_rating_star.png differ diff --git a/app/src/main/res/drawable/action_filter.png b/app/src/main/res/drawable/action_filter.png new file mode 100644 index 0000000..1548d68 Binary files /dev/null and b/app/src/main/res/drawable/action_filter.png differ diff --git a/app/src/main/res/drawable/food_runner_logo.png b/app/src/main/res/drawable/food_runner_logo.png new file mode 100644 index 0000000..3b5e3e0 Binary files /dev/null and b/app/src/main/res/drawable/food_runner_logo.png differ diff --git a/app/src/main/res/drawable/ic_rupee_indian.png b/app/src/main/res/drawable/ic_rupee_indian.png new file mode 100644 index 0000000..6b0a808 Binary files /dev/null and b/app/src/main/res/drawable/ic_rupee_indian.png differ diff --git a/app/src/main/res/drawable/ic_tick_red.png b/app/src/main/res/drawable/ic_tick_red.png new file mode 100644 index 0000000..f1d1521 Binary files /dev/null and b/app/src/main/res/drawable/ic_tick_red.png differ diff --git a/app/src/main/res/drawable/profile_new.png b/app/src/main/res/drawable/profile_new.png new file mode 100644 index 0000000..477ec63 Binary files /dev/null and b/app/src/main/res/drawable/profile_new.png differ diff --git a/app/src/main/res/drawable/profile_pic_new_white.png b/app/src/main/res/drawable/profile_pic_new_white.png new file mode 100644 index 0000000..2152611 Binary files /dev/null and b/app/src/main/res/drawable/profile_pic_new_white.png differ diff --git a/app/src/main/res/drawable/rounded_border_for_view.xml b/app/src/main/res/drawable/rounded_border_for_view.xml new file mode 100644 index 0000000..c9f0c3e --- /dev/null +++ b/app/src/main/res/drawable/rounded_border_for_view.xml @@ -0,0 +1,7 @@ + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_corner_search.xml b/app/src/main/res/drawable/rounded_corner_search.xml new file mode 100644 index 0000000..3c30051 --- /dev/null +++ b/app/src/main/res/drawable/rounded_corner_search.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_view_for_menu_chosen.xml b/app/src/main/res/drawable/rounded_view_for_menu_chosen.xml new file mode 100644 index 0000000..fe5c71f --- /dev/null +++ b/app/src/main/res/drawable/rounded_view_for_menu_chosen.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/drawable/rounded_view_for_menu_red.xml b/app/src/main/res/drawable/rounded_view_for_menu_red.xml new file mode 100644 index 0000000..4deb429 --- /dev/null +++ b/app/src/main/res/drawable/rounded_view_for_menu_red.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/activity_cart.xml b/app/src/main/res/layout/activity_cart.xml new file mode 100644 index 0000000..e40b77b --- /dev/null +++ b/app/src/main/res/layout/activity_cart.xml @@ -0,0 +1,126 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +