Post Top Ad

Post Top Ad

Monday 3 February 2020

How to design Seatview Screen in android



1.:
<?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: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:id="@+id/back_btn"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="3">
                <ImageView
                    android:clickable="false"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerInside"
                    android:src="@drawable/ic_left_arrow"
                    />
            </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="bold"
                                android:textSize="@dimen/text_size_large"
                                android:fontFamily="@font/source_sans_pro_bold"
                                android:text="FruFresh "/>
                            <TextView
                                android:layout_width="wrap_content"
                                android:layout_height="match_parent"
                                android:gravity="center"
                                android:textSize="@dimen/text_size_large"
                                android:fontFamily="@font/source_sans_pro_regular"
                                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: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"></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_weight="1"
                    android:layout_height="match_parent">
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:gravity="center_vertical"
                        android:textColor="#717171"
                        android:text="Table #"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:textSize="@dimen/text_size_large"
                        android:id="@+id/table_name"/>
                </LinearLayout>
                <LinearLayout
                    android:layout_width="0dp"
                    android:layout_weight="1"
                    android:gravity="right"
                    android:layout_height="match_parent">
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="match_parent"
                        android:orientation="horizontal">
                        <LinearLayout
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1"></LinearLayout>
                        <TextView
                            android:visibility="invisible"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:textColor="#717171"
                            android:fontFamily="@font/source_sans_pro_regular"
                            android:text="Status: Active"
                            android:textSize="@dimen/text_size_large"
                            />
                        <LinearLayout
                            android:layout_width="@dimen/text_size_more_large"
                            android:layout_height="match_parent"
                            ></LinearLayout>
                        <TextView
                            android:visibility="invisible"
                            android:layout_width="wrap_content"
                            android:layout_height="match_parent"
                            android:gravity="center_vertical"
                            android:textColor="#D2D2D2"
                            android:fontFamily="@font/source_sans_pro_regular"
                            android:text="Make inactive"
                            android:textSize="@dimen/text_size_large"
                            />
                    </LinearLayout>
                </LinearLayout>
            </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="2dp"
            android:background="#D2D2D2"></LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="horizontal"
            android:layout_weight="6">
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="40">
                <ListView
                    android:layout_width="0dp"
                    android:id="@+id/table_seat_list"
                    android:divider="@android:color/transparent"
                    android:layout_height="match_parent"
                    android:layout_weight="25"></ListView>
            </LinearLayout>
            <LinearLayout
                android:layout_width="2dp"
                android:layout_height="match_parent"
                android:background="#D2D2D2"></LinearLayout>
            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:orientation="vertical"
                android:layout_weight="60">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:orientation="horizontal"
                    android:layout_weight="1">
                    <TextView
                        android:layout_width="0dp"
                        android:layout_weight="1"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:clickable="false"
                        android:focusable="false"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:gravity="center"
                        android:text="S.no"
                        android:textColor="#343434"
                        android:textSize="@dimen/text_size_small" />
                    <LinearLayout
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:background="#D2D2D2"></LinearLayout>
                    <TextView
                        android:layout_width="0dp"
                        android:layout_weight="5"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:clickable="false"
                        android:focusable="false"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:gravity="center"
                        android:text="Item"
                        android:textColor="#343434"
                        android:textSize="@dimen/text_size_small" />
                    <LinearLayout
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:background="#D2D2D2"></LinearLayout>
                    <TextView
                        android:layout_width="0dp"
                        android:layout_weight="2"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:clickable="false"
                        android:focusable="false"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:gravity="center"
                        android:text="Quantity"
                        android:textColor="#343434"
                        android:textSize="@dimen/text_size_small" />
                    <LinearLayout
                        android:layout_width="1dp"
                        android:layout_height="match_parent"
                        android:background="#D2D2D2"></LinearLayout>
                    <TextView
                        android:layout_width="0dp"
                        android:layout_weight="2"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"
                        android:clickable="false"
                        android:focusable="false"
                        android:fontFamily="@font/source_sans_pro_regular"
                        android:gravity="center"
                        android:text="Price"
                        android:textColor="#343434"
                        android:textSize="@dimen/text_size_small" />
                </LinearLayout>
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="1dp"
                    android:background="#D2D2D2"></LinearLayout>
                <ListView
                    android:layout_width="match_parent"
                    android:layout_height="0dp"
                    android:layout_weight="9"
                    android:id="@+id/orderDeatils_listview"
                    android:dividerHeight="1dp"
                    android:divider="#D2D2D2"
                    android:listSelector="@android:color/transparent"></ListView>
            </LinearLayout>
        </LinearLayout>
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:orientation="vertical"
            android:background="@drawable/bg_border_layout"
            android:layout_weight="1.5">
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.2"></LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.6">
                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="horizontal"

                    >
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="10"></LinearLayout>
                    <androidx.cardview.widget.CardView
                        android:id="@+id/cancel_seats"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:clickable="true"
                        android:focusable="true"
                        android:clipChildren="false"
                        android:visibility="visible"
                        app:cardCornerRadius="@dimen/text_size_large"
                        app:cardBackgroundColor="#FFFFFF"
                        android:background="@color/black"
                        android:layout_marginBottom="2dp"
                        app:cardPreventCornerOverlap="true"
                        app:cardUseCompatPadding="false"
                        android:layout_weight="27">

                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:clickable="false"
                            android:focusable="false"
                            android:fontFamily="@font/source_sans_pro_regular"
                            android:gravity="center"
                            android:text="Cancel order"
                            android:textColor="#FF0000"
                            android:textSize="@dimen/text_size_medium" />
                    </androidx.cardview.widget.CardView>
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="3"></LinearLayout>
                    <androidx.cardview.widget.CardView
                        android:id="@+id/btn_modify_order"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:clickable="true"
                        android:focusable="true"
                        android:clipChildren="false"
                        app:cardCornerRadius="@dimen/text_size_large"
                        app:cardBackgroundColor="#E41749"
                        android:background="@color/black"
                        android:layout_marginBottom="2dp"
                        app:cardPreventCornerOverlap="true"
                        app:cardUseCompatPadding="false"
                        android:layout_weight="27">
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:clickable="false"
                            android:focusable="false"
                            android:fontFamily="@font/source_sans_pro_regular"
                            android:gravity="center"
                            android:text="MODIFY ORDER"
                            android:textColor="@color/white"
                            android:textSize="@dimen/text_size_medium" />
                    </androidx.cardview.widget.CardView>
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="3"></LinearLayout>
                    <androidx.cardview.widget.CardView
                        android:id="@+id/btn_checkout"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:clickable="true"
                        android:focusable="true"
                        android:clipChildren="false"
                        app:cardCornerRadius="@dimen/text_size_large"
                        app:cardBackgroundColor="#30A400"
                        android:background="@color/black"
                        android:layout_marginBottom="2dp"
                        app:cardPreventCornerOverlap="true"
                        app:cardUseCompatPadding="false"
                        android:layout_weight="27">
                        <TextView
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center"
                            android:clickable="false"
                            android:focusable="false"
                            android:fontFamily="@font/source_sans_pro_regular"
                            android:gravity="center"
                            android:text="CHECKOUT"
                            android:textColor="@color/white"
                            android:textSize="@dimen/text_size_medium" />
                    </androidx.cardview.widget.CardView>
                    <LinearLayout
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="3"></LinearLayout>

                </LinearLayout>
            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="0.2"></LinearLayout>
        </LinearLayout>


    </LinearLayout>
</LinearLayout>


2:Seatlayout.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/main_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:paddingBottom="0dp"
        android:paddingLeft="0dp"
        android:paddingRight="0dp"
        android:paddingTop="0dp">
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"

            android:orientation="vertical">
            <LinearLayout
                android:paddingBottom="@dimen/text_size_small"
                android:paddingTop="@dimen/text_size_small"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1">
                <LinearLayout
                    android:layout_width="@dimen/text_size_medium"
                    android:layout_height="match_parent"></LinearLayout>
                <TextView
                    android:id="@+id/textSeatName"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center_vertical|center_horizontal"
                    android:fontFamily="@font/source_sans_pro_regular"
                    android:gravity="center_vertical|left"
                    android:text="TextView"
                    android:textColor="#343434"
                    android:textSize="@dimen/text_size_medium" />
                <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:layout_weight="0.2"></LinearLayout>
                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="0dp"
                        android:id="@+id/seatStatus"
                        android:layout_weight="0.6"
                        android:src="@drawable/connected_new_icon"/>
                    <LinearLayout
                        android:layout_width="match_parent"
                        android:layout_height="0dp"
                        android:layout_weight="0.2"></LinearLayout>
                </LinearLayout>



            </LinearLayout>
            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="2dp"
                android:background="#D2D2D2"></LinearLayout>
        </LinearLayout>

    </LinearLayout>
</LinearLayout>


3.ListView Item
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="horizontal" android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <LinearLayout
        android:layout_width="match_parent"
        android:orientation="horizontal"
        android:layout_height="wrap_content">
        <TextView
            android:layout_width="0dp"
            android:layout_weight="1"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"
            android:focusable="false"
            android:fontFamily="@font/source_sans_pro_regular"
            android:gravity="center"
            android:id="@+id/sno"
            android:text="S.no"
            android:textColor="#343434"
            android:textSize="@dimen/text_size_small" />
        <LinearLayout
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#D2D2D2"></LinearLayout>
        <LinearLayout
            android:layout_width="0dp"
            android:layout_weight="5"
            android:orientation="vertical"
            android:layout_height="wrap_content">
            <TextView
                android:id="@+id/menu_name"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:clickable="false"
                android:focusable="false"
                android:fontFamily="@font/source_sans_pro_regular"
                android:gravity="center"
                android:layout_marginBottom="2dp"
                android:text="Item"
                android:textColor="#343434"
                android:textSize="@dimen/text_size_small" />
            <TextView
                android:id="@+id/menu_status"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:clickable="false"
                android:focusable="false"
                android:fontFamily="@font/source_sans_pro_regular"
                android:gravity="center"
                android:text="Sent to kitchen"
                android:textColor="#FF9500"
                android:textSize="@dimen/text_size_smaller" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#D2D2D2"></LinearLayout>
        <TextView
            android:layout_width="0dp"
            android:id="@+id/item_quantity"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:clickable="false"
            android:focusable="false"
            android:fontFamily="@font/source_sans_pro_regular"
            android:gravity="center"
            android:text="Quantity"
            android:textColor="#343434"
            android:textSize="@dimen/text_size_small" />
        <LinearLayout
            android:layout_width="1dp"
            android:layout_height="match_parent"
            android:background="#D2D2D2"></LinearLayout>
        <TextView
            android:layout_width="0dp"
            android:layout_weight="2"
            android:layout_height="wrap_content"
            android:id="@+id/item_price"
            android:layout_gravity="center"
            android:clickable="false"
            android:focusable="false"
            android:fontFamily="@font/source_sans_pro_regular"
            android:gravity="center"
            android:text="Item"
            android:textColor="#343434"
            android:textSize="@dimen/text_size_small" />
    </LinearLayout>

</LinearLayout>


Sourse code:


import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.net.ConnectivityManager;
import android.net.NetworkInfo;
import android.os.Bundle;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.AdapterView;
import android.widget.BaseAdapter;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.ListView;
import android.widget.TextView;
import android.widget.Toast;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.cardview.widget.CardView;

import com.dfoe.frimaster.DataBaseServices.MasterDB;
import com.dfoe.frimaster.FragmentForDashBorad.DineInFragment;
import com.squareup.picasso.Callback;
import com.squareup.picasso.Picasso;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;

import de.hdodenhof.circleimageview.CircleImageView;

public class SeatViewLayout extends AppCompatActivity implements View.OnClickListener,ShowListenerResponse {
    public int table_id;
    MasterDB db;
    TextView table_name,masterName;
    ArrayList<Integer> SeatListId = new ArrayList<Integer>();
    ArrayList<String> SeatListName = new ArrayList<String>();
    ListView table_seat_list,orderDeatils_listview;
    SeatListAdapter seatListAdapter;
    public int seat_id;
    int currentIndex;
    CardView btn_modify_order,btn_checkout,cancel_seats;
    ArrayList<Integer> orderIds = new ArrayList<>();
    LinearLayout back_btn;
    OrderHistoryListAdapter orderHistoryListAdapter;
    int orderNo;
    double totalAmount;
    public String RestaurantImage = "";
    CircleImageView restuarnt_img;
    private EditText Reason_cancel;
    private boolean CancelMessage;
    private Basesalertdialog alertdialogs;

    @Override    protected void onCreate(@Nullable Bundle savedInstanceState) {
        requestWindowFeature(Window.FEATURE_NO_TITLE); //will hide the title        getSupportActionBar().hide(); // hide the title bar        setContentView(R.layout.activity_seat_view_layout);
        db = MasterDB.getInstance(SeatViewLayout.this);
        table_name = (TextView)findViewById(R.id.table_name);
        masterName = (TextView)findViewById(R.id.masterName);
        masterName.setText(DashBoard.RestaurantName+"  ");
        table_seat_list = (ListView)findViewById(R.id.table_seat_list);
        btn_modify_order = (CardView)findViewById(R.id.btn_modify_order);
        cancel_seats = (CardView)findViewById(R.id.cancel_seats);
        back_btn = (LinearLayout)findViewById(R.id.back_btn);
        back_btn.setOnClickListener(this);
        orderDeatils_listview = (ListView)findViewById(R.id.orderDeatils_listview);
        restuarnt_img = (CircleImageView)findViewById(R.id.restuarnt_img);

 /*         Reason_cancel =(EditText)findViewById(R.id.confirm_button);          String CancelMessage = Reason_cancel.getText().toString().trim();*/
        RestaurantImage = db.getRestaurantImage();
        Picasso.with(SeatViewLayout.this).load(RestaurantImage).error(R.drawable.ic_fri_logo).into(restuarnt_img, new Callback() {
            @Override            public void onSuccess() {
            }

            @Override            public void onError() {
            }
        });

       Bundle extras = getIntent().getExtras();
        if (extras != null) {
            table_id = Integer.parseInt(extras.getString("table_id"));
            seat_id = extras.getInt("seat_id");
        }
        JSONObject tabledeatils = db.RestaurantTableDeatils(table_id);
        if(tabledeatils != null) {
            try {
                if (tabledeatils.has("table_name")) {
                    table_name.setText("Table # "+tabledeatils.getString("table_name"));
                }
                if(tabledeatils.has("seat_details"))
                {
                    JSONArray seatsDeatils = tabledeatils.getJSONArray("seat_details");
                    for(int count = 0; count < seatsDeatils.length(); count++)
                    {
                        JSONObject seatDeatil = seatsDeatils.getJSONObject(count);
                        SeatListId.add(seatDeatil.getInt("seat_id"));
                        SeatListName.add(seatDeatil.getString("seat_name"));
                    }
                }
                if(SeatListId.size() > 0)
                {
                    if(seat_id == 0)
                        seat_id = SeatListId.get(0);
                    seatListAdapter = new SeatListAdapter(SeatViewLayout.this);
                    table_seat_list.setAdapter(seatListAdapter);
                    ShowOrderHistory(seat_id);
                }

            } catch (Exception ex) {

            }
        }
        table_seat_list.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override            public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
                seat_id = SeatListId.get(i);
                orderNo = 0;
                seatListAdapter.notifyDataSetChanged();
                ShowOrderHistory(seat_id);
            }
        });
        btn_checkout = (CardView)findViewById(R.id.btn_checkout);
        btn_checkout.setOnClickListener(this);
        btn_modify_order.setOnClickListener(this);
        cancel_seats.setOnClickListener(this);
        super.onCreate(savedInstanceState);

        alertdialogs = new Basesalertdialog(SeatViewLayout.this);
        ConnectivityManager cm =
                (ConnectivityManager) this.getSystemService(Context.CONNECTIVITY_SERVICE);
        NetworkInfo activeNetwork = cm.getActiveNetworkInfo();
        boolean isConnected = activeNetwork != null &&
                activeNetwork.isConnectedOrConnecting();

        if (!isConnected) {
            //finish();            new AlertDialog.Builder(this)
                    .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();
        }
    }


    @Override    protected void onDestroy() {
        super.onDestroy();
    }

    public void ShowOrderHistory(int seat_id)
    {
        orderIds = db.getOrderIDBasedOnseat_id(seat_id,table_id);
        orderDeatils_listview.setVisibility(View.INVISIBLE);
        if(orderIds !=  null)
        {
            if(orderIds.size() > 0)
            {
                orderDeatils_listview.setVisibility(View.VISIBLE);
                if(orderHistoryListAdapter == null) {
                    orderHistoryListAdapter = new OrderHistoryListAdapter(SeatViewLayout.this);
                    orderDeatils_listview.setAdapter(orderHistoryListAdapter);

                }
                else                {
                    orderHistoryListAdapter.notifyDataSetChanged();
                }
            }
            else            {
                orderHistoryListAdapter.notifyDataSetChanged();
            }
        }

    }



    @Override    public void onClick(View view) {
        switch (view.getId())
        {
            case R.id.btn_modify_order:
                Intent j = new Intent(SeatViewLayout.this, OrderMenuActivity.class);
                j.putExtra("table_id",table_id);
                j.putExtra("seat_id",seat_id);
                startActivity(j);
                finish();
                break;
            case R.id.btn_checkout:
                if(DashBoard.socketIoClass.client.connected())
                {
                    if(orderNo > 0)
                    {
                        Intent j1 = new Intent(SeatViewLayout.this, CheckoutActivity.class);
                        j1.putExtra("table_id",table_id);
                        j1.putExtra("seat_id",seat_id);
                        j1.putExtra("order_no",orderNo);
                        startActivity(j1);
                        finish();
                    }
                }

              //  CheckoutForSeat();                break;

            case R.id.back_btn:
                finish();
                break;

            case R.id.cancel_seats:

                if(orderNo > 0) {
                    showCancelOrder();

                }

                break;


        }
    }

    private void showCancelOrder() {
        final Dialog OrderQuantityDialog = new Dialog(SeatViewLayout.this, android.R.style.Theme_Black_NoTitleBar);
        OrderQuantityDialog.getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
        OrderQuantityDialog.setContentView(R.layout.dialog_cancel_layout);
        CardView cancel_button = (CardView)OrderQuantityDialog.findViewById(R.id.cancel_button);
        CardView confirm_button = (CardView)OrderQuantityDialog.findViewById(R.id.confirm_button);
        final EditText Reason_cancel = (EditText) OrderQuantityDialog.findViewById(R.id.Reason_cancel);
    //    final String CancelMessage = Reason_cancel.getText().toString().trim();        confirm_button.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {

                String CancelMessage = Reason_cancel.getText().toString();
                if(DashBoard.socketIoClass.client.connected())
                {
                    try {
                        JSONObject object = new JSONObject();
                        object.put("type", "cancel_order");
                        JSONObject messgae = new JSONObject();
                        messgae.put("SocketId", DashBoard.socketIoClass.mySocketId);
                        messgae.put("restaurant_id", DashBoard.restaurant_id);
                        messgae.put("order_no",orderNo);
                        messgae.put("user_id", DashBoard.user_id);
                        messgae.put("message",CancelMessage);
                        object.put("message", messgae);
                        DashBoard.socketIoClass.sendMessage(object);

                        Toast.makeText(SeatViewLayout.this, "Cancel Order", Toast.LENGTH_LONG).show();

                    /*    orderHistoryListAdapter.notifyDataSetChanged();                        if (DineInFragment.dineHandler != null) {                            DineInFragment.dineHandler.sendEmptyMessage(DineInFragment.DineHandler.Upate_UI);                        }*/                        OrderQuantityDialog.dismiss();
                        finish();

                    }
                    catch (Exception ex)
                    {

                    }


              }



            }
        });
        cancel_button.setOnClickListener(new View.OnClickListener() {
            @Override            public void onClick(View view) {
                OrderQuantityDialog.dismiss();
            }
        });
        OrderQuantityDialog.setCancelable(false);
        OrderQuantityDialog.show();
    }


    @Override    public void onBackPressed() {

    }

    @Override    public void callback(String value) {

    }


    public class SeatListAdapter extends BaseAdapter {
        Context context;

        public SeatListAdapter(Context context) {
            this.context = context;
        }

        @Override        public int getCount() {
            int count = SeatListId.size();
            return count;
        }

        @Override        public Object getItem(int position) {
            if (SeatListId == null)
                return null;
            if (position < 0)
                return null;
            return SeatListId.get(position);
        }

        @Override        public long getItemId(int arg0) {
            return 0;
        }



        @Override        public View getView(final int position, View convertView,
                            ViewGroup parent) {
            TextView SeatName;
            ImageView seatStatus;
            final LayoutInflater inflater = (LayoutInflater) SeatViewLayout.this                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.activity_teaxtview_seat_layout,
                    null);
            SeatName = (TextView) convertView.findViewById(R.id.textSeatName);
            int textviewmargin =(int)(DashBoard.screenHeight * 0.020);
            LinearLayout main_layout = (LinearLayout)convertView.findViewById(R.id.main_layout);
            LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params.gravity = Gravity.CENTER;
            params.setMargins(0,0,0,0);
            main_layout.setLayoutParams(params);
            LinearLayout.LayoutParams params1 = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
            params1.gravity = Gravity.CENTER;
            params1.setMargins(0,0,0,0);
            SeatName.setLayoutParams(params1);
            seatStatus = (ImageView)convertView.findViewById(R.id.seatStatus);
            convertView.setTag(position);
            if(seat_id == SeatListId.get(position))
                main_layout.setBackgroundColor(Color.parseColor("#5AC8FA"));
            else                main_layout.setBackgroundColor(Color.parseColor("#ffffff"));
            SeatName.setText("Seat " +SeatListName.get(position));
            String Status = db.getSeatStstusBasedOnSeatId(SeatListId.get(position));
            if(Status != null) {
                if (Status.equals("") || Status.equals("null") || Status.equals("0"))
                    seatStatus.setImageResource(R.drawable.connected_new_icon);
                else                    seatStatus.setImageResource(R.drawable.not_connected_new_icon);
            }
            else                seatStatus.setImageResource(R.drawable.connected_new_icon);
            return convertView;
        }

    }



    public class OrderHistoryListAdapter extends BaseAdapter {
        Context context;

        public OrderHistoryListAdapter(Context context) {
            this.context = context;
        }

        @Override        public int getCount() {
            int count = orderIds.size();
            return count;
        }

        @Override        public Object getItem(int position) {
            if (orderIds == null)
                return null;
            if (position < 0)
                return null;
            return orderIds.get(position);
        }

        @Override        public long getItemId(int arg0) {
            return 0;
        }


        @Override        public View getView(final int position, View convertView,
                            ViewGroup parent) {
            TextView sno,menu_name,item_quantity,item_price,menu_status;
            final LayoutInflater inflater = (LayoutInflater) SeatViewLayout.this                    .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            convertView = inflater.inflate(R.layout.listview_item_order_history_layout,
                    null);
            sno = (TextView)convertView.findViewById(R.id.sno);
            menu_name = (TextView)convertView.findViewById(R.id.menu_name);
            item_quantity = (TextView)convertView.findViewById(R.id.item_quantity);
            item_price = (TextView)convertView.findViewById(R.id.item_price);
            menu_status = (TextView)convertView.findViewById(R.id.menu_status);
            JSONObject object = db.getOrderDeatilsBasedOnId(orderIds.get(position));
            if(object != null)
            {
                int snumber = position + 1;
                sno.setText(""+snumber);
                try {

                    if(object.has("menu_name"))
                    {
                        menu_name.setText(object.getString("menu_name"));
                    }
                    if(object.has("price"))
                    {
                        item_price.setText(DashBoard.currency + " " + object.getString("price"));
                        totalAmount += Double.parseDouble(object.getString("price"));
                    }
                    if(object.has("item_quantity"))
                    {
                        item_quantity.setText(object.getString("item_quantity"));
                    }
                    if(object.has("order_no"))
                    {
                        orderNo = object.getInt("order_no");
                    }
                    if(object.has("served_status"))
                    {
                        int served_status = object.getInt("served_status");
                        if(served_status == 0)
                        {
                            menu_status.setTextColor(Color.parseColor("#FF9500"));
                            menu_status.setText("Sent to kitchen");
                        }
                        else if(served_status == 1)
                        {
                            menu_status.setTextColor(Color.parseColor("#D20638"));
                            menu_status.setText("Cooking");
                        }
                        else if(served_status == 2)
                        {
                            menu_status.setTextColor(Color.parseColor("#30A400"));
                            menu_status.setText("Ready to serve");
                        }
                    }
                }
                catch (Exception ex)
                {

                }
            }
            convertView.setTag(position);

            return convertView;
        }

    }


}

No comments:

Post a Comment