<?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: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: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:orientation="horizontal"
android:layout_weight="1">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="30">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/totalOrder"
android:textStyle="normal"
android:gravity="center"
android:textSize="@dimen/text_size_medium"
android:fontFamily="@font/source_sans_pro_regular"
android:textColor="#343434"
android:text="Total orders ()"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="39">
<TextView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/totalrevenue"
android:textStyle="normal"
android:gravity="center"
android:fontFamily="@font/source_sans_pro_regular"
android:textSize="@dimen/text_size_medium"
android:textColor="#343434"
android:text=""/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="25">
<TextView
android:clickable="true"
android:focusable="true"
android:visibility="visible"
android:id="@+id/showAll"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center_vertical|right"
android:text="Show All"
android:tag="1"
android:layout_marginRight="@dimen/text_size_large"
android:textColor="#D2D2D2"
android:textSize="@dimen/text_size_medium_small"
android:textStyle="bold" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="20">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:background="@drawable/bg_corner_radius_layout"
android:layout_weight="2">
<EditText
android:id="@+id/edit_date"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="75"
android:enabled="false"
android:inputType="text"
android:layout_marginLeft="10dp"
android:imeOptions="actionDone"
android:singleLine="true"
android:maxLines="1"
android:fontFamily="@font/source_sans_pro_regular"
android:background="#00000000"
android:textSize="@dimen/text_size_small"
android:hint="Search by date"/>
<ImageView
android:id="@+id/date_picker_actions"
android:clickable="true"
android:layout_width="0dp"
android:layout_weight="25"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:layout_height="match_parent"
android:src="@drawable/ic_date_picker"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical"
android:layout_weight="2">
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D2D2D2"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_marginTop="@dimen/text_size_small"
android:layout_marginBottom="@dimen/text_size_small"
android:layout_weight="8">
<ListView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/orderDetailsdependsDate"
android:listSelector="@android:color/transparent"
android:divider="@android:color/transparent"
android:dividerHeight="@dimen/text_size_small"></ListView>
</LinearLayout>
</LinearLayout>
</LinearLayout>
2.:"
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:orientation="vertical"
android:layout_height="wrap_content">
<!--<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/date_txt"
android:textStyle="normal"
android:layout_marginBottom="5dp"
android:layout_marginLeft="@dimen/text_size_large"
android:textSize="@dimen/text_size_medium_small"
android:text=" "/>-->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_weight="2.5"
android:layout_height="wrap_content"
android:layout_gravity="center|left"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center|left"
android:id="@+id/date_txt"
android:textStyle="normal"
android:text=""
android:paddingLeft="@dimen/fixed_text_size_12"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="0.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=""
android:textColor="#343434"
android:textSize="@dimen/text_size_medium" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
></LinearLayout>
<TextView
android:id="@+id/today_revenue"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_gravity="center|right"
android:clickable="false"
android:focusable="false"
android:fontFamily="@font/source_sans_pro_regular"
android:gravity="center|right"
android:text="Revenue ()"
android:paddingRight="@dimen/fixed_text_size_12"
android:textStyle="normal"
android:paddingLeft="@dimen/fixed_text_size_12"
android:textSize="@dimen/text_size_medium_small"/>
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D2D2D2"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/text_size_more_large"
android:orientation="horizontal">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal"
>
<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_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="1.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="Order No."
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="1.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="Order type"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="1.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="Time"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="3"
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="Customer details"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="1.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="Amount"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:layout_width="0dp"
android:layout_weight="1.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="Status"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="#D2D2D2"></LinearLayout>
<ListView
android:id="@+id/order_history_dependsDate"
android:layout_width="match_parent"
android:listSelector="@android:color/transparent"
android:dividerHeight="0dp"
android:divider="@android:color/transparent"
android:layout_height="match_parent"></ListView>
</LinearLayout>
</LinearLayout>
3.:
<?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="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="@dimen/text_size_more_large"
android:orientation="horizontal"
>
<TextView
android:id="@+id/sno"
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_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/orderno"
android:layout_width="0dp"
android:layout_weight="1.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="Order No."
android:textColor="#006FFF"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/ordertype"
android:layout_width="0dp"
android:layout_weight="1.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="Order type"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/ordertime"
android:layout_width="0dp"
android:layout_weight="1.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="------"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/customerdeatils"
android:layout_width="0dp"
android:layout_weight="3"
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="Customer details"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/amount"
android:layout_width="0dp"
android:layout_weight="1.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="Amount"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
<LinearLayout
android:layout_width="1dp"
android:layout_height="match_parent"
android:background="#D2D2D2"></LinearLayout>
<TextView
android:id="@+id/status"
android:layout_width="0dp"
android:layout_weight="1.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="Status"
android:textColor="#343434"
android:textSize="@dimen/text_size_medium_small" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:background="#D2D2D2"
android:layout_height="1dp"></LinearLayout>
</LinearLayout>
</LinearLayout>
Sourse Code:
package com.dfoe.frimaster; import android.annotation.SuppressLint; import android.app.DatePickerDialog; import android.app.Dialog; import android.content.Context; import android.content.Intent; import android.graphics.Color; import android.os.Bundle; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.view.Window; import android.widget.BaseAdapter; import android.widget.DatePicker; import android.widget.EditText; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; import android.widget.TextView; import androidx.annotation.Nullable; import androidx.appcompat.app.AppCompatActivity; import com.dfoe.frimaster.DataBaseServices.MasterDB; import com.google.android.gms.common.internal.safeparcel.SafeParcelReader; import com.squareup.picasso.Callback; import com.squareup.picasso.Picasso; import org.json.JSONArray; import org.json.JSONObject; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Calendar; import java.util.Date; import de.hdodenhof.circleimageview.CircleImageView; public class OrderHistoryActivity extends AppCompatActivity implements View.OnClickListener { ListView orderDetailsdependsDate; ArrayList<String> OrderDates = new ArrayList<>(); MasterDB db; OrderHistoryListAdapter orderHistoryListAdapter; TextView totalOrder,totalrevenue; private DatePicker datePicker; private Calendar calendar; ImageView date_picker_actions; private int year, month, day; TextView masterName; TextView showAll; LinearLayout back_btn; EditText edit_date; public String RestaurantImage = ""; CircleImageView restuarnt_img; @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_order_history_layout); db = MasterDB.getInstance(OrderHistoryActivity.this); orderDetailsdependsDate = (ListView) findViewById(R.id.orderDetailsdependsDate); date_picker_actions = (ImageView) findViewById(R.id.date_picker_actions); masterName = (TextView) findViewById(R.id.masterName); masterName.setText(DashBoard.RestaurantName + " "); back_btn = (LinearLayout) findViewById(R.id.back_btn); edit_date = (EditText) findViewById(R.id.edit_date); back_btn.setOnClickListener(this); date_picker_actions.setOnClickListener(this); totalOrder = (TextView) findViewById(R.id.totalOrder); totalrevenue = (TextView) findViewById(R.id.totalrevenue); showAll = (TextView) findViewById(R.id.showAll); showAll.setOnClickListener(this); int totalOrderCount = db.getOrderCount(); OrderDates = db.getOrderHistorydates(); calendar = Calendar.getInstance(); year = calendar.get(Calendar.YEAR); month = calendar.get(Calendar.MONTH); day = calendar.get(Calendar.DAY_OF_MONTH); totalOrder.setText("Total orders (" + totalOrderCount + ")"); int totalRevenueCount = db.getRevCount(); totalrevenue.setText("Total revenue (" +DashBoard.currency+ "\t" +totalRevenueCount + ")"); restuarnt_img = (CircleImageView) findViewById(R.id.restuarnt_img); RestaurantImage = db.getRestaurantImage(); Picasso.with(OrderHistoryActivity.this).load(RestaurantImage).error(R.drawable.ic_fri_logo).into(restuarnt_img, new Callback() { @Override public void onSuccess() { } @Override public void onError() { } }); if (OrderDates != null) { if (OrderDates.size() > 0) { orderHistoryListAdapter = new OrderHistoryListAdapter(OrderHistoryActivity.this); orderDetailsdependsDate.setAdapter(orderHistoryListAdapter); } } super.onCreate(savedInstanceState); } @Override protected Dialog onCreateDialog(int id) { // TODO Auto-generated method stub if (id == 999) { return new DatePickerDialog(this, myDateListener, year, month, day); } return null; } private DatePickerDialog.OnDateSetListener myDateListener = new DatePickerDialog.OnDateSetListener() { @Override public void onDateSet(DatePicker arg0, int arg1, int arg2, int arg3) { // TODO Auto-generated method stub // arg1 = year // arg2 = month // arg3 = day int month = arg2 + 1; String monthStr = "" + month; String DateStr = "" + arg3; if (month < 9) { monthStr = "0" + month; } if (arg3 < 9) { DateStr = "0" + arg3; } String date = arg1 + "-" + monthStr + "-" + DateStr; ChangeReportDependUponDate(date); } }; public void ShowDatePickerDialog() { showDialog(999); } public void ChangeReportDependUponDate(String date) { edit_date.setText(date); showAll.setTag(2); showAll.setTextColor(Color.parseColor("#006FFF")); OrderDates = new ArrayList<>(); OrderDates.add(date); if (OrderDates.size() > 0) { JSONArray array = db.getOrderDetailsFromPayment(OrderDates.get(0)); if (array != null) { totalOrder.setText("Total orders (" + array.length() + ")"); } else totalOrder.setText("Total orders ( 0 )"); if (orderHistoryListAdapter == null) { orderHistoryListAdapter = new OrderHistoryListAdapter(OrderHistoryActivity.this); orderDetailsdependsDate.setAdapter(orderHistoryListAdapter); } else { orderHistoryListAdapter.notifyDataSetChanged(); } } } @Override public void onBackPressed() { } @Override public void onClick(View view) { switch (view.getId()) { case R.id.date_picker_actions: ShowDatePickerDialog(); break; case R.id.showAll: if (view.getTag().toString().equals("2")) { showAll.setTag(1); showAll.setTextColor(Color.parseColor("#D2D2D2")); edit_date.setText(""); OrderDates = db.getOrderHistorydates(); if (OrderDates != null) { if (OrderDates.size() > 0) { int totalOrderCount = db.getOrderCount(); totalOrder.setText("Total orders (" + totalOrderCount + ")"); if (orderHistoryListAdapter == null) { orderHistoryListAdapter = new OrderHistoryListAdapter(OrderHistoryActivity.this); orderDetailsdependsDate.setAdapter(orderHistoryListAdapter); } else { orderHistoryListAdapter.notifyDataSetChanged(); } } } } break; case R.id.back_btn: finish(); break; } } public class OrderHistoryListAdapter extends BaseAdapter { Context context; public OrderHistoryListAdapter(Context context) { this.context = context; } @Override public int getCount() { int count = OrderDates.size(); return count; } @Override public Object getItem(int position) { if (OrderDates == null) return null; if (position < 0) return null; return OrderDates.get(position); } @Override public long getItemId(int arg0) { return 0; } @Override public View getView(final int position, View convertView, ViewGroup parent) { TextView date_txt,today_revenue; ImageView seatStatus; ListView order_history_dependsDate; final LayoutInflater inflater = (LayoutInflater) OrderHistoryActivity.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.listview_item_for_order_history, null); date_txt = (TextView) convertView.findViewById(R.id.date_txt); today_revenue = (TextView) convertView.findViewById(R.id.today_revenue); order_history_dependsDate = (ListView) convertView.findViewById(R.id.order_history_dependsDate); JSONArray array = db.getOrderDetailsFromPayment(OrderDates.get(position)); if (array != null) { int value = context.getResources().getDimensionPixelSize(R.dimen.text_size_more_large) * array.length(); value += array.length(); value += context.getResources().getDimensionPixelSize(R.dimen.text_size_small); ViewGroup.LayoutParams params = order_history_dependsDate.getLayoutParams(); params.height = value; order_history_dependsDate.setLayoutParams(params); OrderHistoryDateByDateListAdapter orderHistoryDateByDateListAdapter = new OrderHistoryDateByDateListAdapter(OrderHistoryActivity.this, array); order_history_dependsDate.setAdapter(orderHistoryDateByDateListAdapter); } try { if (array != null) { Calendar now = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(OrderDates.get(position)); if (now.get(Calendar.DATE) == date.getDate()) { date_txt.setText("Today ( " + array.length() + " )"); } else if (now.get(Calendar.DATE) - date.getDate() == 1) { date_txt.setText("Yesterday ( " + array.length() + " )"); } else { SimpleDateFormat dateFormat1 = new SimpleDateFormat("dd/MM/YYYY"); String strDate1 = dateFormat1.format(date); date_txt.setText(strDate1 + " ( " + array.length() + " )"); } } else { Calendar now = Calendar.getInstance(); SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd"); Date date = dateFormat.parse(OrderDates.get(position)); if (now.get(Calendar.DATE) == date.getDate()) { date_txt.setText("Today ( " + 0 + " )"); } else if (now.get(Calendar.DATE) - date.getDate() == 1) { date_txt.setText("Yesterday ( " + 0 + " )"); } else { SimpleDateFormat dateFormat1 = new SimpleDateFormat("dd/MM/YYYY"); String strDate1 = dateFormat1.format(date); date_txt.setText(strDate1 + " ( " + 0 + " )"); } } int totalRevenueCount1 = db.getRevCountToday(OrderDates.get(position)); today_revenue.setText("Revenue (" +DashBoard.currency+ "\t" +totalRevenueCount1 + ")"); } catch (Exception ex) { } convertView.setTag(position); return convertView; } } public class OrderHistoryDateByDateListAdapter extends BaseAdapter { Context context; JSONArray array; public OrderHistoryDateByDateListAdapter(Context context, JSONArray array) { this.context = context; this.array = array; } @Override public int getCount() { int count = array.length(); return count; } @Override public Object getItem(int position) { try { if (array == null) return null; if (position < 0) return null; return array.get(position); } catch (Exception ex) { return null; } } @Override public long getItemId(int arg0) { return 0; } @SuppressLint("ResourceAsColor") @Override public View getView(final int position, View convertView, ViewGroup parent) { final TextView sno, orderno, ordertype, ordertime, customerdeatils, amount, status; ImageView seatStatus; final LayoutInflater inflater = (LayoutInflater) OrderHistoryActivity.this .getSystemService(Context.LAYOUT_INFLATER_SERVICE); convertView = inflater.inflate(R.layout.listview_oder_history_date_by_date_layout, null); sno = (TextView) convertView.findViewById(R.id.sno); orderno = (TextView) convertView.findViewById(R.id.orderno); ordertype = (TextView) convertView.findViewById(R.id.ordertype); ordertime = (TextView) convertView.findViewById(R.id.ordertime); customerdeatils = (TextView) convertView.findViewById(R.id.customerdeatils); amount = (TextView) convertView.findViewById(R.id.amount); status = (TextView) convertView.findViewById(R.id.status); int i = position + 1; sno.setText("" + i); try { JSONObject object = array.getJSONObject(position); if (object.has("order_no")) { orderno.setText(object.getString("order_no")); orderno.setTag(object.getString("order_no")); } if (object.has("time")) { ordertime.setText(convertTime(object.getString("time"))); } if (object.has("amount")) { amount.setText(object.getString("amount")); } if (object.has("table_number")) { if (object.getString("table_number").equals("0")) { ordertype.setText("Take-away"); } else { ordertype.setText("Dine-in"); } } if (object.has("name")) { //customerdeatils.setText(object.getString("name") + "\t" + " , " + object.getString("user_phone")); customerdeatils.setText(object.getString("name") + "\t" + " " + object.getString("user_phone")); // customerdeatils.setText(object.getString("name")); } // if(object.has("table_number")) {//// if (object.getString("table_number").equals("0")) {// status.setText("Declined");// status.setBackgroundColor(0xFFFF0000);// status.setTextColor(Color.WHITE);// } else {// status.setText("Completed");// status.setBackgroundColor(0xFF00FF00);// status.setTextColor(Color.WHITE);// }// } //Todo by basudev based on order status setting the status text if (object.has("order_status")) { if (object.getString("order_status").equals("2")) { status.setText("Declined"); status.setBackgroundColor(0xFFFF0000); status.setTextColor(Color.WHITE); } else if (object.getString("order_status").equals("3")) { status.setText("Cancelled"); status.setBackgroundColor(0xFF0000FF); status.setTextColor(Color.WHITE); } else { status.setText("Completed"); status.setBackgroundColor(0xFF00FF00); status.setTextColor(Color.WHITE); } } } catch (Exception ex) { } orderno.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { Intent j = new Intent(OrderHistoryActivity.this, OrderDeatilsActivity.class); j.putExtra("Order_no", Integer.parseInt(orderno.getTag().toString())); startActivity(j); // Toast.makeText(context,"Order no. "+orderno.getTag().toString(),Toast.LENGTH_LONG).show(); } }); convertView.setTag(position); return convertView; } private String convertTime(String time) { SimpleDateFormat format = new SimpleDateFormat("HH:mm:ss"); SimpleDateFormat format1 = new SimpleDateFormat("hh:mm aa"); java.util.Date date = null; try { try { date = format.parse(time); } catch (ParseException e) { e.printStackTrace(); } } catch (SafeParcelReader.ParseException e) { e.printStackTrace(); } String convertedDate = format1.format(date); return convertedDate; } } }
No comments:
Post a Comment