<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:id="@+id/drawer_layout"
android:layout_width="match_parent"
android:keepScreenOn="true"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:background="@color/white"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/bg_border_layout"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<ImageView
android:id="@+id/img_opening_drawlayout"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/ic_menu_icon"
/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="horizontal"
android:layout_weight="88">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="2"
android:gravity="center"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:orientation="horizontal"
android:layout_weight="2">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:orientation="vertical"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
<de.hdodenhof.circleimageview.CircleImageView
android:layout_width="match_parent"
android:layout_weight="2"
android:layout_height="0dp"
android:src="@drawable/ic_menu_icon"
android:id="@+id/restuarnt_img" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="@dimen/text_size_medium_small"
android:layout_height="match_parent"></LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:orientation="horizontal"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/masterName"
android:gravity="center"
android:textStyle="normal"
android:fontFamily="@font/source_sans_pro_bold"
android:textSize="@dimen/text_size_large"
android:text="FruFresh "/>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_large"
android:text="Master "/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="match_parent"></LinearLayout>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:src="@drawable/ic_fri_logo"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="3"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@color/silver"
android:layout_weight="1">
<com.google.android.material.tabs.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF"
app:tabGravity="fill"
app:tabIndicatorColor="#D20638"
app:tabIndicatorFullWidth="true"
app:tabMaxWidth="0dp"
app:tabMode="fixed"
app:tabSelectedTextColor="#D20638"
android:layout_marginBottom=".5dp"
app:tabTextColor="@color/black" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="8">
<androidx.viewpager.widget.ViewPager
android:background="#FFFFFF"
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/left_menu"
android:layout_width="@dimen/right_drawer_width"
android:orientation="vertical"
android:layout_gravity="left"
android:background="@color/white"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="@drawable/bg_border_layout"
android:layout_weight="1">
<TextView
android:id="@+id/masterdrawlayoutName"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center"
android:textColor="#717171"
android:text="FruFresh "
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/dashboard_layout"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="DASHBOARD"
android:textColor="#717171"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/orderHistory_layout"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="ORDER HISTORY"
android:textColor="#717171"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/Reports_layout"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="REPORTS"
android:gravity="center"
android:textColor="#717171"
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:id="@+id/booking_inventry"
android:clickable="true"
android:focusable="true"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="INVENTORY"
android:textColor="#717171"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:visibility="invisible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="REPORTS"
android:gravity="center"
android:textColor="#717171"
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="25"
android:layout_height="match_parent"></LinearLayout>
<ImageView
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="match_parent"
android:scaleType="centerInside"
android:src="@drawable/ic_supoort" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="match_parent"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="30"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="SUPPORT"
android:textColor="#717171"
android:gravity="center"
android:textSize="@dimen/text_size_medium_small"
android:textStyle="normal" />
<LinearLayout
android:layout_width="0dp"
android:layout_weight="35"
android:layout_height="match_parent"></LinearLayout>
</LinearLayout>
<LinearLayout
android:id="@+id/logout_layout"
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="LOGOUT"
android:textColor="#717171"
android:gravity="center"
android:textSize="@dimen/text_size_medium_small"
android:textStyle="normal" />
</LinearLayout>
<LinearLayout
android:clickable="true"
android:focusable="true"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
<TextView
android:id="@+id/App_virsion"
android:visibility="visible"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="App Virsion"
android:gravity="center"
android:textColor="#717171"
android:textSize="@dimen/text_size_medium"
android:textStyle="normal" />
</LinearLayout>
</LinearLayout>
</androidx.drawerlayout.widget.DrawerLayout>
Sourse code:
import android.app.Dialog; import android.content.BroadcastReceiver; import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Typeface; import android.graphics.drawable.ColorDrawable; import android.location.Address; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.util.Log; import android.view.KeyEvent; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.view.WindowManager; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.TextView; import android.widget.Toast; import androidx.annotation.NonNull; import androidx.appcompat.app.AppCompatActivity; import androidx.cardview.widget.CardView; import androidx.core.content.res.ResourcesCompat; import androidx.drawerlayout.widget.DrawerLayout; import androidx.fragment.app.Fragment; import androidx.fragment.app.FragmentManager; import androidx.fragment.app.FragmentPagerAdapter; import androidx.viewpager.widget.ViewPager; import com.dfoe.frimaster.DataBaseServices.MasterDB; import com.dfoe.frimaster.FragmentForDashBorad.DeliveryFragment; import com.dfoe.frimaster.FragmentForDashBorad.DineInFragment; import com.dfoe.frimaster.FragmentForDashBorad.TakeAwayFragment; import com.dfoe.frimaster.RetrofitServices.RetrofitInterfaceTask; import com.dfoe.frimaster.SocketCommunication.SocketIoClass; import com.google.android.material.tabs.TabLayout; import com.google.gson.JsonObject; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import java.util.ArrayList; import java.util.List; import de.hdodenhof.circleimageview.CircleImageView; import okhttp3.MediaType; import okhttp3.RequestBody; import retrofit2.Call; import retrofit2.Response; import retrofit2.Retrofit; import retrofit2.converter.gson.GsonConverterFactory; public class DashBoard extends AppCompatActivity implements View.OnClickListener, ShowListenerResponse { private TabLayout tabLayout; private ViewPager viewPager; public static Context mActivity; public static MasterDB db; ViewPagerAdapter adapter; public static int screenWidth, screenHeight; public static DashBoardTaskHandler dashBoardTaskHandler; public static SocketIoClass socketIoClass; public static int restaurant_id = 0, user_id = 0, order_no = 0, order_status = 0; private DrawerLayout mDrawerLayout; LinearLayout left_menu, dashboard_layout, orderHistory_layout, Reports_layout, logout_layout, booking_inventry; public static String currency = ""; public static String RestaurantName = ""; public String RestaurantImage = ""; ImageView img_opening_drawlayout; TextView masterName, masterdrawlayoutName, App_virsion; CircleImageView restuarnt_img; JSONArray OrderDeatilsArray; JSONArray restaurant_orders; JSONArray messages; JSONArray payments; private Basesalertdialog alertdialogs; public JSONObject responseJsonObject = new JSONObject(); JSONArray TakeAwayDeatilss = new JSONArray(); @Override protected void onCreate(Bundle savedInstanceState) { requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title getSupportActionBar().hide(); // hide the title bar setContentView(R.layout.activity_dashoard_layout); super.onCreate(savedInstanceState); viewPager = (ViewPager) findViewById(R.id.viewpager); viewPager.setOffscreenPageLimit(0); setupViewPager(viewPager); mActivity = DashBoard.this; dashBoardTaskHandler = new DashBoardTaskHandler(); db = MasterDB.getInstance(DashBoard.this); OrderDeatilsArray = new JSONArray(); restaurant_orders = new JSONArray(); messages = new JSONArray(); payments = new JSONArray(); restaurant_id = db.RestaurantID(); TakeAwayDeatilss = new JSONArray(); TakeAwayDeatilss = db.getOrderDetailsFromPayments(); user_id = db.MasterUserID(); OrderDeatilsArray = db.getOrderDeatilsForOrderNo(order_no); screenWidth = getWindowManager().getDefaultDisplay().getWidth(); screenHeight = getWindowManager().getDefaultDisplay().getHeight() + getStatusBarHeight(); tabLayout = (TabLayout) findViewById(R.id.tabs); mDrawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout); left_menu = (LinearLayout) findViewById(R.id.left_menu); img_opening_drawlayout = (ImageView) findViewById(R.id.img_opening_drawlayout); img_opening_drawlayout.setOnClickListener(this); currency = db.getCurrencyDeatils(); RestaurantName = db.getRestaurantDeatils(); masterName = (TextView) findViewById(R.id.masterName); App_virsion = (TextView) findViewById(R.id.App_virsion); masterName.setText(RestaurantName + " "); masterdrawlayoutName = (TextView) findViewById(R.id.masterdrawlayoutName); masterdrawlayoutName.setText(RestaurantName + " "); dashboard_layout = (LinearLayout) findViewById(R.id.dashboard_layout); orderHistory_layout = (LinearLayout) findViewById(R.id.orderHistory_layout); Reports_layout = (LinearLayout) findViewById(R.id.Reports_layout); logout_layout = (LinearLayout) findViewById(R.id.logout_layout); booking_inventry = (LinearLayout) findViewById(R.id.booking_inventry); logout_layout.setOnClickListener(this); dashboard_layout.setOnClickListener(this); orderHistory_layout.setOnClickListener(this); Reports_layout.setOnClickListener(this); booking_inventry.setOnClickListener(this); restuarnt_img = (CircleImageView) findViewById(R.id.restuarnt_img); RestaurantImage = db.getRestaurantImage(); App_virsion.setText("V:" + AppUtils.getVersionName(getApplicationContext())); alertdialogs = new Basesalertdialog(DashBoard.this); get_pending_order_master(0); IntentFilter filter = new IntentFilter(); filter.addAction("android.net.conn.CONNECTIVITY_CHANGE"); registerReceiver(mBroadcastReceiver, filter); Picasso.with(DashBoard.this).load(RestaurantImage).error(R.drawable.ic_fri_logo).into(restuarnt_img, new Callback() { @Override public void onSuccess() { } @Override public void onError() { } }); // viewPager.addOnPageChangeListener(new ViewPager.OnPageChangeListener() {// @Override// public void onPageScrolled(int position, float positionOffset, int positionOffsetPixels) {// int tabspostion = position;// }//// @Override// public void onPageSelected(int position) {//// }//// @Override// public void onPageScrollStateChanged(int state) {//// int pos = viewPager.getCurrentItem();//////// tabLayout.getTabAt(pos).select();//// viewPager.setCurrentItem(pos);//// if(state == 0) {//////////////// Fragment activeFragment = adapter.getItem(pos);//////// }// }// }); tabLayout.setupWithViewPager(viewPager); // tabLayout.setOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {// @Override// public void onTabSelected(TabLayout.Tab tab) {//// //THIS!!// if (viewPager != null) {// tabLayout.getTabAt(tab.getPosition()).select();//// viewPager.setCurrentItem(tab.getPosition());//// }// }//// @Override// public void onTabUnselected(TabLayout.Tab tab) {//// }//// @Override// public void onTabReselected(TabLayout.Tab tab) {//// }// }); setCustomFont(); // tabLayout.getTabAt(2).getOrCreateBadge().setNumber(12); socketIoClass = new SocketIoClass(); } public void get_pending_order_master(final int DownlaodingApi) { Retrofit retrofit = new Retrofit.Builder() .baseUrl(CommonParams.bseURL) .addConverterFactory(GsonConverterFactory.create()) .build(); RetrofitInterfaceTask retrofitService = retrofit.create(RetrofitInterfaceTask.class); Call<JsonObject> call = null; JSONObject postJsopnData = new JSONObject(); JSONArray TakeAwayDeatilss = new JSONArray(); TakeAwayDeatilss.put(0); // postJsopnData = new JSONObject(); try { postJsopnData.put("restaurant_id", DashBoard.restaurant_id); postJsopnData.put("order_status", TakeAwayDeatilss); } catch (JSONException e) { e.printStackTrace(); } RequestBody body = RequestBody.create(MediaType.parse("application/json"), postJsopnData.toString()); call = retrofitService.getmasterpending(body); if (call != null) { call.enqueue(new retrofit2.Callback<JsonObject>() { @Override public void onResponse(Call<JsonObject> call, Response<JsonObject> response) { if (response.isSuccessful()) { if (response.body().get("status").toString().equals("true")) { try { Log.e("PendingOrders", response.body().getAsJsonArray("payments").toString()); upDateNewOrderDetailsToDB(new JSONObject(response.body().getAsJsonObject().toString())); } catch (JSONException e) { e.printStackTrace(); } // try {// restaurant_orders = new JSONArray(response.body().getAsJsonArray("restaurant_orders").toString());// } catch (JSONException e) {// e.printStackTrace();// }// try {// responseJsonObject.put("restaurant_orders", restaurant_orders);// if (dashBoardTaskHandler != null) {// dashBoardTaskHandler.sendEmptyMessage(DashBoardTaskHandler.Insert_Data_In_Database);// }// } catch (JSONException e) {// e.printStackTrace();// }// try {// messages = new JSONArray(response.body().getAsJsonArray("messages").toString());// } catch (JSONException e) {// e.printStackTrace();// }// try {// responseJsonObject.put("messages", messages);// if (dashBoardTaskHandler != null) {// dashBoardTaskHandler.sendEmptyMessage(DashBoardTaskHandler.Insert_Data_In_Messages);// }// } catch (JSONException e) {// e.printStackTrace();// }// try {// payments = new JSONArray(response.body().getAsJsonArray("payments").toString());// } catch (JSONException e) {// e.printStackTrace();// }// try {// responseJsonObject.put("payments", payments);// if (dashBoardTaskHandler != null) {// dashBoardTaskHandler.sendEmptyMessage(DashBoardTaskHandler.Insert_Data_In_Database1);// }// } catch (JSONException e) {// e.printStackTrace();// }// if (TakeAwayFragment.TakeAwayHandler != null) {// TakeAwayFragment.TakeAwayHandler.sendEmptyMessage(TakeAwayFragment.TakeAwayHandler.Upate_UI_TAKEWAY_CONFIRM);// } } } else { String message = response.message(); if (message.equals("Not Found")) Toast.makeText(DashBoard.this, "Server is down. Try it later", Toast.LENGTH_LONG).show(); else Toast.makeText(DashBoard.this, "Server is down. Try it later", Toast.LENGTH_LONG).show(); } } public void onFailure(Call<JsonObject> call, Throwable t) { /* if (alertdialogs.isNetworkAvailable(DashBoard.this)) { alertdialogs.serverconnectionerrorshow(getApplicationContext(), 1); } else { alertdialogs.internetconnectionerrorshow(DashBoard.this, 1);*/ try { if (t.getCause().getMessage().contains("Network is unreachable")) Toast.makeText(DashBoard.this, "Internet not available, Please check connection", Toast.LENGTH_LONG).show(); else if (t.getCause().getMessage().contains("Network is unreachable") || t.getCause().getMessage().contains("Connection refused")) Toast.makeText(DashBoard.this, "Server is down. Try it later", Toast.LENGTH_LONG).show(); } catch (Exception e) { e.printStackTrace(); } } }); } } public void setCustomFont() { ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0); int tabsCount = vg.getChildCount(); for (int j = 0; j < tabsCount; j++) { ViewGroup vgTab = (ViewGroup) vg.getChildAt(j); int tabChildsCount = vgTab.getChildCount(); for (int i = 0; i < tabChildsCount; i++) { View tabViewChild = vgTab.getChildAt(i); if (tabViewChild instanceof TextView) { try { final Typeface typeface = ResourcesCompat.getFont(DashBoard.this, R.font.source_sans_pro_regular); ((TextView) tabViewChild).setTypeface(typeface); } catch (Exception ex) { String emx = ex.getMessage().toString(); } //Put your font in assests folder //assign name of the font here (Must be case sensitive) } } } } @Override protected void onDestroy() { DashBoard.socketIoClass.client.disconnect(); DashBoard.currency = ""; DashBoard.user_id = 0; DashBoard.screenHeight = 0; DashBoard.screenWidth = 0; DashBoard.mActivity = null; DashBoard.dashBoardTaskHandler = null; DashBoard.db = null; DashBoard.restaurant_id = 0; DashBoard.RestaurantName = ""; unregisterReceiver(mBroadcastReceiver); super.onDestroy(); } public int getStatusBarHeight() { int result = 0; int resourceId = getResources().getIdentifier("status_bar_height", "dimen", "android"); if (resourceId > 0) { result = getResources().getDimensionPixelSize(resourceId); } return result; } private void setupViewPager(ViewPager viewPager) { adapter = new ViewPagerAdapter(getSupportFragmentManager()); adapter.addFragment(new DineInFragment(), "Dine-in"); adapter.addFragment(new TakeAwayFragment(), "Take-away"); adapter.addFragment(new DeliveryFragment(), "Delivery"); viewPager.setAdapter(adapter); } @Override public void onClick(View view) { switch (view.getId()) { case R.id.img_opening_drawlayout: this.mDrawerLayout.openDrawer(this.left_menu); break; case R.id.dashboard_layout: if (this.mDrawerLayout.isDrawerOpen(this.left_menu)) { this.mDrawerLayout.closeDrawer(this.left_menu); } break; case R.id.orderHistory_layout: if (this.mDrawerLayout.isDrawerOpen(this.left_menu)) { this.mDrawerLayout.closeDrawer(this.left_menu); } Intent j = new Intent(DashBoard.this, OrderHistoryActivity.class); startActivity(j); break; case R.id.booking_inventry: if (this.mDrawerLayout.isDrawerOpen(this.left_menu)) { this.mDrawerLayout.closeDrawer(this.left_menu); } Intent jk = new Intent(DashBoard.this, Inventry_bottom_main.class); startActivity(jk); break; case R.id.Reports_layout: if (this.mDrawerLayout.isDrawerOpen(this.left_menu)) { this.mDrawerLayout.closeDrawer(this.left_menu); } Intent j1 = new Intent(DashBoard.this, ItemReportsActivity.class); startActivity(j1); break; case R.id.logout_layout: if (this.mDrawerLayout.isDrawerOpen(this.left_menu)) { this.mDrawerLayout.closeDrawer(this.left_menu); } showLogoutDialog(); break; } } public void showLogoutDialog() { final Dialog OrderQuantityDialog = new Dialog(DashBoard.this, android.R.style.Theme_Black_NoTitleBar); getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); OrderQuantityDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT)); OrderQuantityDialog.setContentView(R.layout.dialog_signout_layout); CardView cancel_button = (CardView) OrderQuantityDialog.findViewById(R.id.cancel_button); CardView confirm_button = (CardView) OrderQuantityDialog.findViewById(R.id.confirm_button); confirm_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { db.deleteAllTable(); DashBoard.socketIoClass.client.disconnect(); OrderQuantityDialog.dismiss(); Intent j = new Intent(DashBoard.this, MainActivity.class); startActivity(j); finish(); } }); cancel_button.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { OrderQuantityDialog.dismiss(); } }); OrderQuantityDialog.setCancelable(false); OrderQuantityDialog.show(); } @Override public void callback(String value) { } class ViewPagerAdapter extends FragmentPagerAdapter { private final List<Fragment> mFragmentList = new ArrayList<>(); private final List<String> mFragmentTitleList = new ArrayList<>(); public ViewPagerAdapter(FragmentManager manager) { super(manager); } @Override public Fragment getItem(int position) { return mFragmentList.get(position); } @Override public int getCount() { return mFragmentList.size(); } public void addFragment(Fragment fragment, String title) { mFragmentList.add(fragment); mFragmentTitleList.add(title); } @Override public CharSequence getPageTitle(int position) { return mFragmentTitleList.get(position); } } @Override public boolean onKeyDown(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { if (this.mDrawerLayout.isDrawerOpen(this.left_menu)) { this.mDrawerLayout.closeDrawer(this.left_menu); } else { this.mDrawerLayout.openDrawer(this.left_menu); } return true; } else { return super.onKeyDown(keyCode, event); } } public class DashBoardTaskHandler extends Handler { public static final int ChangeActivity = 1; public static final int ShowToastMessage = 2; public static final int Download_Order = 3; public static final int ORDER_RECEIVED_FROM_NOTIFICATION = 7; public static final int GET_PENDING_ORDERS = 8; @Override public void handleMessage(@NonNull Message msg) { switch (msg.what) { case ChangeActivity: String message = ((String) msg.obj).trim(); String[] messageSplit = message.split("@@"); Intent j = new Intent(DashBoard.this, SeatViewLayout.class); j.putExtra("table_id", messageSplit[1]); j.putExtra("seat_id", 0); startActivity(j); break; case ShowToastMessage: Toast.makeText(DashBoard.this, "Order status Updated", Toast.LENGTH_LONG).show(); break; case Download_Order: get_pending_order_master(Download_Order); break; case ORDER_RECEIVED_FROM_NOTIFICATION: //TODO check if order already exists JSONObject notificationObj = (JSONObject) msg.obj; try { if (notificationObj.getString("type").equalsIgnoreCase("restaurant_orders")) { Message msg1 = new Message(); msg1.obj = notificationObj; msg1.what = TakeAwayFragment.TakeAwayHandler.TAKE_AWAY_ORDER_RECEIVED_FROM_NOTIFICATION; TakeAwayFragment.TakeAwayHandler.sendMessageDelayed(msg1, 500); } break; } catch (JSONException e) { e.printStackTrace(); } case GET_PENDING_ORDERS: // JSONObject details = (JSONObject) msg.obj; get_pending_order_master(0); break; } } } public void upDateNewOrderDetailsToDB(JSONObject mJSONObject) { try { Log.e("", mJSONObject.getJSONArray("payments").toString()); if (mJSONObject.has("restaurant_orders")) { db.insertRestaurantOrder(mJSONObject.getJSONArray("restaurant_orders")); } } catch (Exception e) { } try { if (mJSONObject.has("payments")) { Log.e("", mJSONObject.getJSONArray("payments").toString()); db.insertRestaurantPayment(mJSONObject.getJSONArray("payments")); } } catch (Exception e) { } try { if (mJSONObject.has("messages")) { Log.e("", mJSONObject.getJSONObject("messages").toString()); db.insertRestorentMessages(mJSONObject.getJSONObject("messages")); } } catch (Exception e) { } try { Log.e("", mJSONObject.getJSONArray("payments").toString()); } catch (JSONException e) { e.printStackTrace(); } if (TakeAwayFragment.TakeAwayHandler != null) { TakeAwayFragment.TakeAwayHandler.sendEmptyMessage(TakeAwayFragment.TakeAwayHandler.Upate_UI_TAKEWAY_CONFIRM); } } public void insertMasterDataInDatabase() { try { if (responseJsonObject.has("restaurant_orders")) { db.insertRestaurantOrder(responseJsonObject.getJSONArray("restaurant_orders")); } else if (responseJsonObject.has("messages")) { db.insertRestorentMessages(responseJsonObject.getJSONObject("messages")); } else if (responseJsonObject.has("payments")) { db.insertRestaurantPayment(responseJsonObject.getJSONArray("payments")); } } catch (JSONException e) { e.printStackTrace(); } } public void insertMasterDataInDatabase1() { try { if (responseJsonObject.has("payments")) { db.insertRestaurantPayment(responseJsonObject.getJSONArray("payments")); } else if (responseJsonObject.has("messages")) { db.insertRestorentMessages(responseJsonObject.getJSONObject("messages")); } if (TakeAwayFragment.TakeAwayHandler != null) { TakeAwayFragment.TakeAwayHandler.sendEmptyMessage(TakeAwayFragment.TakeAwayHandler.Upate_UI); } } catch (Exception ex) { } } public void insertMasterDataInDatabasMessage() { try { if (responseJsonObject.has("messages")) { db.insertRestorentMessagesOff(responseJsonObject.getJSONArray("messages")); } else if (responseJsonObject.has("payments")) { db.insertRestaurantPayment(responseJsonObject.getJSONArray("payments")); } } catch (JSONException e) { e.printStackTrace(); } } BroadcastReceiver mBroadcastReceiver = new BroadcastReceiver() { @Override public void onReceive(Context context, Intent intent) { ConnectivityManager cm = (ConnectivityManager) context.getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo netInfo = cm.getActiveNetworkInfo(); //should check null because in airplane mode it will be null boolean isInterNetConnected = netInfo != null && netInfo.isConnected(); if (isInterNetConnected) { get_pending_order_master(0); } } }; }
Dine Fragement:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="match_parent"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="90"
android:layout_height="match_parent">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="Total: "
android:id="@+id/total_seat_txt"
android:layout_gravity="center|left"
android:gravity="center|left"
android:textSize="@dimen/text_size_medium"
android:textColor="#717171" />
<LinearLayout
android:layout_width="@dimen/text_size_medium"
android:layout_height="match_parent"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="Vacant: "
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textColor="#717171" />
<TextView
android:id="@+id/txt_vacant"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text=""
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textColor="#30A400" />
<LinearLayout
android:layout_width="@dimen/text_size_medium"
android:layout_height="match_parent"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text="Occupied: "
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textColor="#717171" />
<TextView
android:id="@+id/txt_occupied"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:text=""
android:layout_gravity="center"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:textColor="#D20638" />
<LinearLayout
android:layout_width="@dimen/text_size_medium"
android:layout_height="match_parent"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:layout_height="match_parent">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="match_parent"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="8.5">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"></LinearLayout>
<GridView
android:id="@+id/tables_list"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="90"
android:layout_gravity="center"
android:gravity="center"
android:layout_marginBottom="@dimen/text_size_medium_small"
android:layout_marginTop="@dimen/text_size_medium_small"
android:verticalSpacing="@dimen/text_size_medium_small"
android:listSelector="@android:color/transparent"
android:numColumns="1"
android:visibility="visible"></GridView>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="5"></LinearLayout>
</LinearLayout>
</LinearLayout>
</LinearLayout>
List Layout:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_width="match_parent"
android:clickable="false"
android:layout_height="wrap_content">
<androidx.cardview.widget.CardView
android:id="@+id/tableview"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:clipChildren="false"
app:cardBackgroundColor="@color/white"
android:background="@color/black"
android:layout_margin="5dp"
app:cardPreventCornerOverlap="true"
android:elevation="@dimen/text_size_medium"
app:cardUseCompatPadding="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="false"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:clickable="false"
android:layout_height="match_parent"
android:layout_weight="0.25"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:clickable="false"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="9.5">
<LinearLayout
android:layout_width="match_parent"
android:clickable="false"
android:layout_height="@dimen/text_size_small"></LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="false"
android:id="@+id/txt_table_name"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_medium"
android:text=" "/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/text_size_small"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_A_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:textColor="@color/white"
android:id="@+id/txt_seat_A"
android:textSize="@dimen/text_size_large"
android:text="A"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_B_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:textColor="@color/white"
android:id="@+id/txt_seat_B"
android:textSize="@dimen/text_size_large"
android:text="B"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_C_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:id="@+id/txt_seat_C"
android:textSize="@dimen/text_size_large"
android:textColor="@color/white"
android:text="C"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_D_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:id="@+id/txt_seat_D"
android:textColor="@color/white"
android:textSize="@dimen/text_size_large"
android:text="D"/></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_E_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:id="@+id/txt_seat_E"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_large"
android:text="E"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_F_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/txt_seat_F"
android:textColor="@color/white"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_large"
android:text="F"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_G_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:id="@+id/txt_seat_G"
android:textColor="@color/white"
android:textSize="@dimen/text_size_large"
android:text="G"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_H_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/txt_seat_H"
android:fontFamily="@font/source_sans_pro_regular"
android:textColor="@color/white"
android:textSize="@dimen/text_size_large"
android:text="H"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_I_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:textColor="@color/white"
android:id="@+id/txt_seat_I"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_large"
android:text="I"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:id="@+id/seat_J_layout"
android:orientation="horizontal"
android:background="@drawable/ic_vacant_status"
>
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:id="@+id/txt_seat_J"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_large"
android:textColor="@color/white"
android:text="J"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:background="@color/white"
></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/text_size_small"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"></LinearLayout>
</LinearLayout>
</androidx.cardview.widget.CardView>
</LinearLayout>
Sourse Code:
import android.app.AlertDialog; import android.content.Context; import android.content.DialogInterface; import android.graphics.Color; import android.net.ConnectivityManager; import android.net.NetworkInfo; import android.os.Bundle; import android.os.Handler; import android.os.Message; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.AdapterView; import android.widget.BaseAdapter; import android.widget.GridView; import android.widget.LinearLayout; import android.widget.TextView; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.fragment.app.Fragment; import com.dfoe.frimaster.Basesalertdialog; import com.dfoe.frimaster.DashBoard; import com.dfoe.frimaster.MainActivity; import com.dfoe.frimaster.R; import com.dfoe.frimaster.ShowListenerResponse; import org.json.JSONArray; import org.json.JSONObject; import java.util.ArrayList; public class DineInFragment extends Fragment implements ShowListenerResponse { GridView tables_list; ArrayList<Integer> table_ids = new ArrayList<>(); TableGridViewAdapter tableGridViewAdapter; TextView total_seat_txt,txt_vacant,txt_occupied; public static DineHandler dineHandler; private Basesalertdialog alertdialogs; public DineInFragment() { // Required empty public constructor } @Override public void onCreate(@Nullable Bundle savedInstanceState) { super.onCreate(savedInstanceState); } @Nullable @Override public View onCreateView(@NonNull LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) { View v = inflater.inflate(R.layout.fragment_dine_in_layout, null); tables_list = (GridView)v.findViewById(R.id.tables_list); table_ids = DashBoard.db.RestaurantTableDeatils(); tableGridViewAdapter = new TableGridViewAdapter(); total_seat_txt = (TextView)v.findViewById(R.id.total_seat_txt); txt_vacant = (TextView)v.findViewById(R.id.txt_vacant); txt_occupied = (TextView)v.findViewById(R.id.txt_occupied); dineHandler = new DineHandler(); JSONObject getSeatsStatus = DashBoard.db.getSeatsStatus(0); alertdialogs = new Basesalertdialog(this); ConnectivityManager cm = (ConnectivityManager) getContext().getSystemService(Context.CONNECTIVITY_SERVICE); NetworkInfo activeNetwork = cm.getActiveNetworkInfo(); boolean isConnected = activeNetwork != null && activeNetwork.isConnectedOrConnecting(); if (!isConnected) { //finish(); new AlertDialog.Builder(getContext()) .setTitle("Not Connected to Internet") .setIcon(android.R.drawable.ic_dialog_alert) .setCancelable(false) .setMessage("Please Connect to Internet") .setPositiveButton("Close", new DialogInterface.OnClickListener() { public void onClick(DialogInterface arg0, int arg1) { // finishAffinity(); } }).create().show(); } if(getSeatsStatus != null) { try { if(getSeatsStatus.has("total_seats")) { total_seat_txt.setText("Total: "+getSeatsStatus.getString("total_seats")); } if(getSeatsStatus.has("total_vacant_seat")) { txt_vacant.setText(""+getSeatsStatus.getString("total_vacant_seat")); } if(getSeatsStatus.has("total_occupied_seat")) { txt_occupied.setText(""+getSeatsStatus.getString("total_occupied_seat")); } } catch (Exception ex) { } } tables_list.setAdapter(tableGridViewAdapter); tables_list.setOnItemClickListener(new AdapterView.OnItemClickListener() { @Override public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) { if(DashBoard.dashBoardTaskHandler != null) { String message = "postion@@"+table_ids.get(i); Message toastMsg = DashBoard.dashBoardTaskHandler.obtainMessage( DashBoard.DashBoardTaskHandler.ChangeActivity, message); DashBoard.dashBoardTaskHandler.sendMessage(toastMsg); } //Toast.makeText(getActivity().getBaseContext(),"Postion : " + table_ids.get(i),Toast.LENGTH_LONG).show(); } }); return v; } @Override public void callback(String value) { } /* @Override public void onResume() { dineHandler = new DineHandler(); super.onResume(); } @Override public void onDestroy() { dineHandler = null; super.onDestroy(); } */ private class TableGridViewAdapter extends BaseAdapter { public TableGridViewAdapter() { } @Override public long getItemId(int arg0) { return 0; } @Override public Object getItem(int position) { return table_ids.get(position); } @Override public int getCount() { return table_ids.size(); } @Override public View getView(int position, View convertView, ViewGroup parent) { ViewHolderGridView holder = null; LayoutInflater inflater = (LayoutInflater) DashBoard.mActivity .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.listview_item_table_view_layout, null); holder = new ViewHolderGridView(); // holder.tableview = (LinearLayout) convertView.findViewById(R.id.tableview); holder.txt_table_name = (TextView) convertView.findViewById(R.id.txt_table_name); int width = (int) (DashBoard.screenWidth * 0.9); // width = (int) (width * 0.30); //int height = (int) (width * 0.75); // holder.tableview.setLayoutParams(params); width = (int)((width)/20); width = (int)((width)* 1.5); LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(width,width); // holder.txt_table_name.setText(table_ids.get(position).toString()); JSONObject tabledeatils = DashBoard.db.RestaurantTableDeatils(table_ids.get(position)); holder.seat_A_layout = (LinearLayout)convertView.findViewById(R.id.seat_A_layout); holder.seat_B_layout = (LinearLayout)convertView.findViewById(R.id.seat_B_layout); holder.seat_D_layout = (LinearLayout)convertView.findViewById(R.id.seat_D_layout); holder.seat_E_layout = (LinearLayout)convertView.findViewById(R.id.seat_E_layout); holder.seat_F_layout = (LinearLayout)convertView.findViewById(R.id.seat_F_layout); holder.seat_G_layout = (LinearLayout)convertView.findViewById(R.id.seat_G_layout); holder.seat_H_layout = (LinearLayout)convertView.findViewById(R.id.seat_H_layout); holder.seat_I_layout = (LinearLayout)convertView.findViewById(R.id.seat_I_layout); holder.seat_J_layout = (LinearLayout)convertView.findViewById(R.id.seat_J_layout); holder.seat_C_layout = (LinearLayout)convertView.findViewById(R.id.seat_C_layout); holder.seat_A_layout.setLayoutParams(params); holder.seat_B_layout.setLayoutParams(params); holder.seat_C_layout.setLayoutParams(params); holder.seat_D_layout.setLayoutParams(params); holder.seat_E_layout.setLayoutParams(params); holder.seat_F_layout.setLayoutParams(params); holder.seat_G_layout.setLayoutParams(params); holder.seat_H_layout.setLayoutParams(params); holder.seat_I_layout.setLayoutParams(params); holder.seat_J_layout.setLayoutParams(params); holder.txt_seat_A = (TextView) convertView.findViewById(R.id.txt_seat_A); holder.txt_seat_B = (TextView)convertView.findViewById(R.id.txt_seat_B); holder.txt_seat_C = (TextView)convertView.findViewById(R.id.txt_seat_C); holder.txt_seat_D = (TextView)convertView.findViewById(R.id.txt_seat_D); holder.txt_seat_E = (TextView)convertView.findViewById(R.id.txt_seat_E); holder.txt_seat_F = (TextView)convertView.findViewById(R.id.txt_seat_F); holder.txt_seat_G = (TextView)convertView.findViewById(R.id.txt_seat_G); holder.txt_seat_H = (TextView)convertView.findViewById(R.id.txt_seat_H); holder.txt_seat_I = (TextView)convertView.findViewById(R.id.txt_seat_I); holder.txt_seat_J = (TextView)convertView.findViewById(R.id.txt_seat_J); if(tabledeatils != null) { if(tabledeatils.has("table_name")) { try { holder.txt_table_name.setText(tabledeatils.getString("table_name")); } catch (Exception ex) { } } if(tabledeatils.has("numberOfSeats")) { try { int noOfSeats = tabledeatils.getInt("numberOfSeats"); if(noOfSeats == 2) { holder.seat_C_layout.setVisibility(View.INVISIBLE); holder.seat_H_layout.setVisibility(View.INVISIBLE); holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_D_layout.setVisibility(View.INVISIBLE); holder.seat_E_layout.setVisibility(View.INVISIBLE); holder.seat_F_layout.setVisibility(View.INVISIBLE); holder.seat_G_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 3) { holder.seat_H_layout.setVisibility(View.INVISIBLE); holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_D_layout.setVisibility(View.INVISIBLE); holder.seat_E_layout.setVisibility(View.INVISIBLE); holder.seat_F_layout.setVisibility(View.INVISIBLE); holder.seat_G_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 4) { holder.seat_H_layout.setVisibility(View.INVISIBLE); holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_E_layout.setVisibility(View.INVISIBLE); holder.seat_F_layout.setVisibility(View.INVISIBLE); holder.seat_G_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 5) { holder.seat_H_layout.setVisibility(View.INVISIBLE); holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_F_layout.setVisibility(View.INVISIBLE); holder.seat_G_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==4) { holder.txt_seat_E.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 6) { holder.seat_H_layout.setVisibility(View.INVISIBLE); holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_G_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==4) { holder.txt_seat_E.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==5) { holder.txt_seat_F.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 7) { holder.seat_H_layout.setVisibility(View.INVISIBLE); holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==4) { holder.txt_seat_E.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==5) { holder.txt_seat_F.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==6) { holder.txt_seat_G.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 8) { holder.seat_J_layout.setVisibility(View.INVISIBLE); holder.seat_I_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==4) { holder.txt_seat_E.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==5) { holder.txt_seat_F.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==6) { holder.txt_seat_G.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==7) { holder.txt_seat_H.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_H_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_H_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_H_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 9) { holder.seat_J_layout.setVisibility(View.INVISIBLE); JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==4) { holder.txt_seat_E.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==5) { holder.txt_seat_F.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==6) { holder.txt_seat_G.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==7) { holder.txt_seat_H.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_H_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_H_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_H_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==8) { holder.txt_seat_J.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_I_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_I_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_I_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } else if(noOfSeats == 10) { JSONArray jsonArray = tabledeatils.getJSONArray("seat_details"); for(int i = 0; i < jsonArray.length(); i++) { JSONObject object = jsonArray.getJSONObject(i); if(i==0) { holder.txt_seat_A.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_A_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==1) { holder.txt_seat_B.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_B_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==2) { holder.txt_seat_C.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_C_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==3) { holder.txt_seat_D.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_D_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==4) { holder.txt_seat_E.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_E_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==5) { holder.txt_seat_F.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_F_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==6) { holder.txt_seat_G.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_G_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==7) { holder.txt_seat_H.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_H_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_H_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_H_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==8) { holder.txt_seat_J.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_I_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_I_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_I_layout.setBackgroundResource(R.drawable.ic_vacant_status); } else if(i==9) { holder.txt_seat_J.setText(object.getString("seat_name")); String Status = DashBoard.db.getSeatStstusBasedOnSeatId(object.getInt("seat_id")); if(Status != null) { if (Status.equals("") || Status.equals("null") || Status.equals("0")) holder.seat_J_layout.setBackgroundResource(R.drawable.ic_vacant_status); else holder.seat_J_layout.setBackgroundResource(R.drawable.ic_occupied_status); } else holder.seat_J_layout.setBackgroundResource(R.drawable.ic_vacant_status); } } } } catch (Exception ex) { } } } convertView.setTag(holder); return convertView; } public class ViewHolderGridView { public TextView txt_table_name; public TextView txt_seat_A,txt_seat_B,txt_seat_C,txt_seat_D,txt_seat_E,txt_seat_F,txt_seat_G,txt_seat_H,txt_seat_I,txt_seat_J; public LinearLayout tableview,seat_A_layout,seat_B_layout,seat_C_layout,seat_D_layout,seat_E_layout,seat_F_layout,seat_G_layout,seat_H_layout,seat_I_layout,seat_J_layout; } } public class DineHandler extends Handler { public static final int Upate_UI = 1; @Override public void handleMessage(@NonNull Message msg) { switch (msg.what) { case Upate_UI: JSONObject getSeatsStatus = DashBoard.db.getSeatsStatus(0); if(getSeatsStatus != null) { try { if(getSeatsStatus.has("total_seats")) { total_seat_txt.setText("Total: "+getSeatsStatus.getString("total_seats")); } if(getSeatsStatus.has("total_vacant_seat")) { txt_vacant.setText(""+getSeatsStatus.getString("total_vacant_seat")); } if(getSeatsStatus.has("total_occupied_seat")) { txt_occupied.setText(""+getSeatsStatus.getString("total_occupied_seat")); } } catch (Exception ex) { } } tableGridViewAdapter.notifyDataSetChanged(); break; } } } }
No comments:
Post a Comment