Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package codelabs.ambarrukmo.fragment;
- import android.app.DatePickerDialog;
- import android.app.Dialog;
- import android.app.TimePickerDialog;
- import android.content.Context;
- import android.content.Intent;
- import android.graphics.Color;
- import android.graphics.drawable.ColorDrawable;
- import android.net.Uri;
- import android.os.Bundle;
- import android.os.CountDownTimer;
- import android.support.annotation.NonNull;
- import android.support.annotation.Nullable;
- import android.support.v4.app.Fragment;
- import android.support.v4.app.FragmentManager;
- import android.support.v4.app.FragmentTransaction;
- import android.support.v7.app.AlertDialog;
- import android.text.TextUtils;
- import android.text.format.DateFormat;
- import android.view.Gravity;
- import android.view.LayoutInflater;
- import android.view.View;
- import android.view.ViewGroup;
- import android.view.Window;
- import android.widget.Button;
- import android.widget.DatePicker;
- import android.widget.EditText;
- import android.widget.LinearLayout;
- import android.widget.PopupMenu;
- import android.widget.ScrollView;
- import android.widget.TextView;
- import android.widget.TimePicker;
- import android.widget.Toast;
- import java.text.ParseException;
- import java.text.SimpleDateFormat;
- import java.util.Calendar;
- import java.util.Date;
- import java.util.HashMap;
- import java.util.Locale;
- import java.util.Map;
- import javax.annotation.Nonnull;
- import butterknife.BindView;
- import butterknife.ButterKnife;
- import butterknife.OnClick;
- import butterknife.Unbinder;
- import codelabs.ambarrukmo.R;
- import codelabs.ambarrukmo.activity.LoginActivity;
- import codelabs.ambarrukmo.activity.ProfileActivity;
- import codelabs.ambarrukmo.activity.RegisterActivity;
- import codelabs.ambarrukmo.connection.ApiUtils;
- import codelabs.ambarrukmo.connection.AppConstant;
- import codelabs.ambarrukmo.connection.DataManager;
- import codelabs.ambarrukmo.connection.RetrofitInterface;
- import codelabs.ambarrukmo.dialog.DialogProgress;
- import codelabs.ambarrukmo.model.DoPost;
- import codelabs.ambarrukmo.model.GetValletNumber;
- import codelabs.ambarrukmo.utils.MyLog;
- import codelabs.ambarrukmo.utils.RecentUtils;
- import retrofit2.Call;
- import retrofit2.Callback;
- import retrofit2.Response;
- public class AddParkingValleyFragment extends Fragment implements View.OnClickListener {
- private static final String ARG_TEXT = "param1";
- public static final String IS_TASK="IS_TASK";
- private GetValletNumber.DATABean responseDataValet;
- protected DialogProgress dialogProgress;
- @BindView(R.id.tv_error)
- TextView tvError;
- @BindView(R.id.tv_error_desc)
- TextView tvErrorDesc;
- @BindView(R.id.container_error)
- LinearLayout containerError;
- @BindView(R.id.tv_loading)
- TextView tvLoading;
- @BindView(R.id.tv_loading_desc)
- TextView tvLoadingDesc;
- @BindView(R.id.container_loading)
- LinearLayout containerLoading;
- @BindView(R.id.no_valley)
- TextView tvNoValley;
- @BindView(R.id.edt_brand)
- EditText edtBrand;
- @BindView(R.id.edt_colour)
- EditText edtColour;
- @BindView(R.id.edt_police_no)
- EditText edtPoliceNo;
- @BindView(R.id.edt_date)
- EditText edtDate;
- @BindView(R.id.edt_time)
- EditText edtTime;
- @BindView(R.id.tv_note_valley)
- TextView tvNoteValley;
- @BindView(R.id.btn_booking_valley)
- Button btnBooking;
- @BindView(R.id.edt_type)
- EditText edtType;
- @BindView(R.id.tv_total_vallet)
- TextView tvTotalVallet;
- @Nullable
- private int pageText;
- Dialog myDialog;
- Unbinder unbinder;
- private Toast mToast;
- private Context mContext;
- private Call<GetValletNumber> callVallet;
- public AddParkingValleyFragment() {
- // Required empty public constructor
- }
- public static AddParkingValleyFragment newInstance(@NonNull final int pageText) {
- AddParkingValleyFragment fragment = new AddParkingValleyFragment();
- Bundle args = new Bundle();
- args.putInt(ARG_TEXT, pageText);
- fragment.setArguments(args);
- return fragment;
- }
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- if (getArguments() !=null) {
- pageText = getArguments().getInt(ARG_TEXT);
- }
- }
- @Override
- public void onResume() {
- super.onResume();
- // Set title
- // ((AppCompatActivity) getActivity()).getSupportActionBar().setTitle(getResources().getString(R.string.setting_menu));
- }
- @Override
- public void onDestroyView() {
- super.onDestroyView();
- unbinder.unbind();
- if (callVallet!=null) {
- callVallet.cancel();
- }
- }
- // @Override
- // public void onStop() {
- // super.onStop();
- // unbinder.unbind();
- //
- // }
- @Override
- public View onCreateView(LayoutInflater inflater, ViewGroup container,
- Bundle savedInstanceState) {
- // Inflate the layout for this fragment
- View view = inflater.inflate(R.layout.fragment_add_parking_valley, container, false);
- unbinder = ButterKnife.bind(this, view);
- myDialog = new Dialog(getContext());
- initListeners();
- initVariables();
- callFunctions();
- return view;
- }
- private void initVariables(){
- // tvNoValley.setOnClickListener(this);
- edtBrand.setOnClickListener(this);
- edtColour.setOnClickListener(this);
- edtPoliceNo.setOnClickListener(this);
- // edtDate.setOnClickListener(this);
- // edtTime.setOnClickListener(this);
- btnBooking.setOnClickListener(this);
- edtType.setOnClickListener(this);
- }
- private void initListeners(){
- }
- private void callFunctions(){
- hideContainer();
- loadDataValet();
- }
- @OnClick(R.id.btn_booking_valley)
- public void onViewClicked() {
- // doSubmit();
- // ShowPopup();
- }
- public void ShowPopup(){
- myDialog.setContentView(R.layout.dialog_parking_valley);
- Button btnOk;
- TextView tvNoValet;
- TextView tv_total_minutes;
- tv_total_minutes = (TextView) myDialog.findViewById(R.id.tv_total_minutes);
- tvNoValet = (TextView) myDialog.findViewById(R.id.no_valley);
- tvNoValet.setText("#" +" " +responseDataValet.getVallet_number());
- btnOk = (Button) myDialog.findViewById(R.id.btn_ok_valley);
- btnOk.setOnClickListener(new View.OnClickListener() {
- @Override
- public void onClick(View v) {
- myDialog.dismiss();
- Fragment fragment = new HistoryValleyFragment();
- FragmentManager fragmentManager = getActivity().getSupportFragmentManager();
- FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
- fragmentTransaction.replace(R.id.fragment_container, fragment);
- fragmentTransaction.addToBackStack(null);
- fragmentTransaction.commit();
- }
- });
- myDialog.getWindow().setBackgroundDrawable(new ColorDrawable(Color.TRANSPARENT));
- myDialog.show();
- }
- private void doSubmit() {
- String vallet_number = tvNoValley.getText().toString();
- String brand = edtBrand.getText().toString();
- String type = edtType.getText().toString();
- String color = edtColour.getText().toString();
- String policeNo = edtPoliceNo.getText().toString();
- // String date = edtDate.getText().toString();
- // String time = edtTime.getText().toString();
- if (TextUtils.isEmpty(brand)){
- showToast("Please enter car brand");
- return;
- }
- if (TextUtils.isEmpty(type)){
- showToast("Please select type car");
- }
- if (TextUtils.isEmpty(color)){
- showToast("Please enter color car");
- }
- if (TextUtils.isEmpty(policeNo)){
- showToast("Please enter police number");
- }
- // if (TextUtils.isEmpty(date)){
- // showToast("Please select date");
- // }
- // if (TextUtils.isEmpty(time)) {
- // showToast("Please select time");
- // }
- showDialogProgress(getString(R.string.get_valet));
- // FragmentTransaction ft = getFragmentManager().beginTransaction();
- // ft.detach(AddParkingValleyFragment.this).attach(AddParkingValleyFragment.this).commit();
- Map<String, String> params = new HashMap<>();
- params.put("vallet_number", vallet_number);
- params.put("no_pol", policeNo);
- params.put("car_brand", brand);
- params.put("car_type", type);
- params.put("car_color", color);
- // params.put("vallet_date", date);
- // params.put("vallet_time", time);
- RetrofitInterface apiService = ApiUtils.getAPIService();
- String auth = AppConstant.AuthValue + DataManager.getInstance().getToken();
- Call<DoPost> call = apiService.doCreateVallet(auth, params);
- call.enqueue(new Callback<DoPost>() {
- @Override
- public void onResponse(@NonNull Call<DoPost> call, @NonNull Response<DoPost> data) {
- hideDialogProgress();
- if (data.isSuccessful()) {
- DoPost response = data.body();
- if (response != null) {
- if (response.getSTATUS() == 200) {
- ShowPopup();
- // FragmentTransaction ft = getFragmentManager().beginTransaction();
- // ft.detach(AddParkingValleyFragment.this).attach(AddParkingValleyFragment.this).commit();
- } else {
- showToast(response.getMESSAGE());
- }
- } else {
- showToast(getString(R.string.no_response));
- }
- } else {
- RecentUtils.handleRetrofitError(data.code());
- }
- }
- @Override
- public void onFailure(@NonNull Call<DoPost> call,@NonNull Throwable t) {
- if (!call.isCanceled()) {
- hideDialogProgress();
- showToast(getString(R.string.network_error));
- }
- }
- });
- }
- // private void openDate() {
- //
- // final Calendar c = Calendar.getInstance();
- // final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd", Locale.getDefault());
- // final SimpleDateFormat toFormat = new SimpleDateFormat("dd MMMM yyyy", Locale.getDefault());
- // String dt = edtDate.getText().toString();
- // if (!TextUtils.isEmpty(dt)) {
- // try {
- // c.setTime(simpleDateFormat.parse(dt));
- // } catch (ParseException e) {
- // e.printStackTrace();
- // }
- // }
- //
- // int year = c.get(Calendar.YEAR);
- // int month = c.get(Calendar.MONTH);
- // int day = c.get(Calendar.DAY_OF_MONTH);
- //
- //
- // // Create a new instance of DatePickerDialog and return it
- // DatePickerDialog datePicker = new DatePickerDialog(getContext(), new DatePickerDialog.OnDateSetListener() {
- // @Override
- // public void onDateSet(DatePicker datePicker, int year, int month, int day) {
- // String dd;
- // if (day < 10) {
- // dd = "0" + day;
- // } else {
- // dd = "" + day;
- // }
- // String mm;
- // month = month + 1;
- // if (month < 10) {
- // mm = "0" + month;
- // } else {
- // mm = "" + month;
- // }
- //
- // String fullDate = year + "-" + mm + "-" + dd;
- // edtDate.setText(fullDate);
- //
- // }
- // }, day, month, year);
- // datePicker.getDatePicker().setMinDate(new Date().getTime());
- // datePicker.show();
- // }
- // private void openTime() {
- // final Calendar c = Calendar.getInstance();
- //
- // SimpleDateFormat simpleDateFormat = new SimpleDateFormat("HH:mm", Locale.getDefault());
- // String dt = edtTime.getText().toString();
- // if (!TextUtils.isEmpty(dt)) {
- // try {
- // c.setTime(simpleDateFormat.parse(dt));
- // } catch (ParseException e) {
- // e.printStackTrace();
- // }
- // }
- //
- // int hour = c.get(Calendar.HOUR_OF_DAY);
- // int minute = c.get(Calendar.MINUTE);
- //
- // // Create a new instance of TimePickerDialog and return it
- // TimePickerDialog timePickerDialog = new TimePickerDialog(getContext(), new TimePickerDialog.OnTimeSetListener() {
- // @Override
- // public void onTimeSet(TimePicker timePicker, int hourOfDay, int minute) {
- //
- // String hour;
- // if(hourOfDay<10){
- // hour="0"+hourOfDay;
- // }else{
- // hour=hourOfDay+"";
- // }
- //
- //
- // String min;
- // if(minute<10){
- // min="0"+minute;
- // }else{
- // min=minute+"";
- // }
- //
- // String time = hour+":"+min;
- // edtTime.setText(time);
- //
- // }
- // }, hour, minute, DateFormat.is24HourFormat(getContext()));
- // timePickerDialog.show();
- // }
- public void showDialogProgress(String message) {
- if (message != null) {
- dialogProgress = new DialogProgress(getContext(), message, true);
- dialogProgress.setCancelable(false);
- dialogProgress.show();
- } else {
- dialogProgress = new DialogProgress(getContext(), "Loading ...", false);
- dialogProgress.setCancelable(false);
- dialogProgress.show();
- }
- }
- public void hideDialogProgress() {
- if (dialogProgress != null) {
- if (dialogProgress.isShowing()) {
- dialogProgress.dismiss();
- }
- }
- }
- public void showToast(String val){
- if (mToast != null) mToast.cancel();
- mToast = Toast.makeText(getContext(), val, Toast.LENGTH_SHORT);
- mToast.show();
- }
- private void loadDataValet() {
- // tvLoading.setText("Getting Valet Number");
- // tvLoadingDesc.setText("Please wait for getting about");
- // containerLoading.setVisibility(View.VISIBLE);
- showDialogProgress("Getting data");
- RetrofitInterface apiService = ApiUtils.getAPIService();
- String auth = AppConstant.AuthValue + DataManager.getInstance().getToken();
- // Call<GetValletNumber> call = apiService.gettingValetNumber(auth);
- callVallet = apiService.gettingValetNumber(auth);
- callVallet.enqueue(new Callback<GetValletNumber>() {
- @Override
- public void onResponse(@Nonnull Call<GetValletNumber> call,@NonNull Response<GetValletNumber> data) {
- // containerLoading.setVisibility(View.GONE);
- hideDialogProgress();
- if (data.isSuccessful()) {
- GetValletNumber response = data.body();
- if (response != null) {
- if (response.getSTATUS() == 200) {
- // containerContent.setVisibility(View.VISIBLE);
- responseDataValet = response.getDATA();
- processValetNumber();
- } else {
- // containerError.setVisibility(View.VISIBLE);
- // tvError.setText(response.getMESSAGE());
- }
- } else {
- // containerError.setVisibility(View.VISIBLE);
- // tvError.setText(getString(R.string.no_response));
- }
- } else {
- // containerError.setVisibility(View.VISIBLE);
- // RecentUtils.handleRetrofitError(data.code(), tvError);
- }
- }
- @Override
- public void onFailure(@NonNull Call<GetValletNumber> call, @NonNull Throwable t) {
- if (!call.isCanceled()) {
- hideDialogProgress();
- // MyLog.logE(t.getMessage());
- // containerLoading.setVisibility(View.GONE);
- // containerError.setVisibility(View.VISIBLE);
- // tvError.setText(getString(R.string.network_error));
- }
- }
- });
- }
- private void processValetNumber() {
- tvNoValley.setText(responseDataValet.getVallet_number());
- tvTotalVallet.setText(responseDataValet.getTotal_booked()+ "/" + (responseDataValet.getTotal_slot()));
- // tvTotalVallet.setText(responseDataValet.get());
- }
- public void hideContainer() {
- // containerContent.setVisibility(View.GONE);
- containerError.setVisibility(View.GONE);
- containerLoading.setVisibility(View.GONE);
- }
- @Override
- public void onClick(View view) {
- if (view == btnBooking) {
- doSubmit();
- // FragmentTransaction ft = getFragmentManager().beginTransaction();
- // ft.detach(AddParkingValleyFragment.this).attach(AddParkingValleyFragment.this).commit();
- // ShowPopup();
- // } else if (view == edtDate){
- // openDate();
- // } else if (view == edtTime){
- // openTime();
- }
- }}
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement