Search in sources :

Example 1 with QRCodeActivity

use of com.manan.dev.ec2018app.Fragments.QRCodeActivity in project EC2018App by Manan-YMCA.

the class EventRegister method registerEvent.

private void registerEvent() {
    String url = getResources().getString(R.string.event_register_api);
    RequestQueue queue = Volley.newRequestQueue(this);
    StringRequest request = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {

        @Override
        public void onResponse(String response) {
            try {
                JSONObject obj = new JSONObject(response);
                qrCodeString = (obj.getString("qrcode"));
                SharedPreferences prefs = getSharedPreferences(getResources().getString(R.string.sharedPrefName), MODE_PRIVATE);
                String phoneNumber = prefs.getString("Phone", null);
                if (phoneNumber == null) {
                    MDToast.makeText(EventRegister.this, "To view your Ticket Login with your registered Mobile Number", Toast.LENGTH_LONG, MDToast.TYPE_SUCCESS).show();
                }
                pd.dismiss();
                sendNotification();
                FragmentManager fm = getFragmentManager();
                Bundle bundle = new Bundle();
                bundle.putString("qrcodestring", qrCodeString);
                bundle.putString("eventid", eventId);
                bundle.putInt("activity", 1);
                bundle.putString("eventid", eventId);
                // set Fragmentclass Arguments
                QRCodeActivity fragobj = new QRCodeActivity();
                fragobj.setCancelable(true);
                fragobj.setArguments(bundle);
                fragobj.show(fm, "drff");
                final String phone = prefs.getString("Phone", null);
                if (phone == null) {
                }
                addTicket(phone);
            }// Try and catch are included to handle any errors due to JSON
             catch (Exception e) {
            // If an error occurs, this prints the error to the log
            }
        }
    }, new Response.ErrorListener() {

        @Override
        public void onErrorResponse(VolleyError error) {
            pd.dismiss();
        }
    }) {

        @Override
        protected Map<String, String> getParams() throws AuthFailureError {
            Map<String, String> map = new HashMap<String, String>();
            map.put("name", intentName);
            map.put("phone", intentPhone);
            map.put("email", intentMail);
            map.put("college", intentClg);
            map.put("eventid", eventId);
            return map;
        }
    };
    queue.add(request);
}
Also used : VolleyError(com.android.volley.VolleyError) SharedPreferences(android.content.SharedPreferences) HashMap(java.util.HashMap) Bundle(android.os.Bundle) StringRequest(com.android.volley.toolbox.StringRequest) Response(com.android.volley.Response) MyNotificationResponse(com.manan.dev.ec2018app.Notifications.MyNotificationResponse) FragmentManager(android.app.FragmentManager) JSONObject(org.json.JSONObject) RequestQueue(com.android.volley.RequestQueue) QRCodeActivity(com.manan.dev.ec2018app.Fragments.QRCodeActivity)

Example 2 with QRCodeActivity

use of com.manan.dev.ec2018app.Fragments.QRCodeActivity in project EC2018App by Manan-YMCA.

the class SingleEventActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_single_event);
    databaseController = new DatabaseController(this);
    default_image = getResources().getDrawable(R.drawable.default_image_1);
    // ATTENTION: This was auto-generated to handle app links.
    Intent appLinkIntent = getIntent();
    String appLinkAction = appLinkIntent.getAction();
    Uri appLinkData = appLinkIntent.getData();
    if (Intent.ACTION_VIEW.equals(appLinkAction) && appLinkData != null) {
        String revStr = new StringBuilder(appLinkData.toString()).reverse().toString();
        int i;
        for (i = 0; revStr.charAt(i) != 35; i++) {
        }
        revStr = revStr.substring(0, i);
        String eventName = new StringBuilder(revStr).reverse().toString().toUpperCase();
        eventName = eventName.replace("%20", " ");
        deep = true;
        eventId = databaseController.retrieveEventIdByName(eventName);
        if (eventId.equals("wrong")) {
            NO_DEEP_LINK_FLAG = false;
            MDToast.makeText(SingleEventActivity.this, "There's no such event.", MDToast.LENGTH_SHORT, MDToast.TYPE_WARNING).show();
            finish();
            startActivity(new Intent(this, SplashScreen.class));
        }
    } else {
        eventId = getIntent().getStringExtra("eventId");
    }
    container_se_view = findViewById(R.id.contaner_se);
    getEventDetails = new DatabaseController(SingleEventActivity.this);
    eventDetails = new EventDetails();
    registerButton = (Button) findViewById(R.id.btn_register);
    // barViewTicket = (ProgressBar) findViewById(R.id.pb_view_ticket);
    // barViewTicket.setIndeterminate(false);
    // barViewTicket.setVisibility(View.GONE);
    // barViewTicket.setProgress(0);
    // pd = new ProgressDialog(SingleEventActivity.this);
    // pd.setMessage("Loading Tickets...");
    // pd.setCancelable(false);
    // pd.setCanceledOnTouchOutside(false);
    pd = new ProgressDialog(SingleEventActivity.this);
    pd.setTitle("Loading Tickets");
    final Runnable progressRunnable = new Runnable() {

        @Override
        public void run() {
            pd.cancel();
        }
    };
    fragobj = new QRCodeActivity();
    barEventImage = (ProgressBar) findViewById(R.id.pb_event_image);
    eventDateTextView = (TextView) findViewById(R.id.tv_event_date);
    eventStartTimeTextView = (TextView) findViewById(R.id.tv_event_start_time);
    locationTextView = (TextView) findViewById(R.id.tv_event_location);
    eventEndTimeTextView = (TextView) findViewById(R.id.tv_event_end_time);
    // hostClubTextView = (TextView) findViewById(R.id.tv_host);
    feesTextView = (TextView) findViewById(R.id.tv_fees);
    typeOfEventTextView = (TextView) findViewById(R.id.tv_type_of_event);
    firstPrizeTextView = (TextView) findViewById(R.id.tv_prize_first);
    secondPrizeTextView = (TextView) findViewById(R.id.tv_prize_second);
    thirdPrizeTextView = (TextView) findViewById(R.id.tv_prize_third);
    descriptionTextView = (TextView) findViewById(R.id.tv_description);
    rulesTextView = (TextView) findViewById(R.id.tv_rules);
    eventNameView = (TextView) findViewById(R.id.tv_event_name);
    prizesRelativeLayout = (RelativeLayout) findViewById(R.id.rl_prizes);
    eventCategoryTextView = findViewById(R.id.tv_cat_name);
    // goingLinearLayout = (LinearLayout) findViewById(R.id.ll_people_going);
    sharebutton = findViewById(R.id.btn_share);
    categoryEventImageView = findViewById(R.id.iv_type_of_event);
    eventImageLinearLayout = (RelativeLayout) findViewById(R.id.ll_btn_register);
    line1 = (View) findViewById(R.id.line1);
    // line2 = (View) findViewById(R.id.line4);
    line3 = (View) findViewById(R.id.line5);
    line4 = (View) findViewById(R.id.line3);
    line4.setVisibility(View.GONE);
    // goingLinearLayout.setVisibility(View.GONE);
    dateTimeRelativeLayout = (RelativeLayout) findViewById(R.id.rl_time_date);
    locationRelativeLayout = (LinearLayout) findViewById(R.id.ll_location);
    coordsLinearLayout = (LinearLayout) findViewById(R.id.ll_coordinators);
    coordsHeading = (TextView) findViewById(R.id.tv_coords_heading);
    backbutton = (ImageView) findViewById(R.id.tv_back_button);
    if (NO_DEEP_LINK_FLAG) {
        eventDetails = getEventDetails.retreiveEventsByID(eventId);
        Calendar cal = Calendar.getInstance();
        cal.setTimeInMillis(eventDetails.getmStartTime());
        SimpleDateFormat sdf = new SimpleDateFormat("MMMM dd, yyyy", Locale.ENGLISH);
        formattedDate = sdf.format(cal.getTime());
        eventDateTextView.setText(formattedDate);
        SimpleDateFormat sdf1 = new SimpleDateFormat("kk:mm", Locale.US);
        Calendar endTimeMilis = Calendar.getInstance();
        endTimeMilis.setTimeInMillis(eventDetails.getmEndTime());
        startTime = sdf1.format(cal.getTime());
        endTime = sdf1.format(endTimeMilis.getTime());
        eventStartTimeTextView.setText(startTime);
        eventEndTimeTextView.setText(endTime);
        backbutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (deep) {
                    startActivity(new Intent(SingleEventActivity.this, UserLoginActivity.class).addFlags(Intent.FLAG_ACTIVITY_NEW_TASK).addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP));
                    finish();
                } else {
                    onBackPressed();
                }
            }
        });
        eventNameView.setText(eventDetails.getmName());
        if (eventDetails.getmCategory().equals("solo")) {
            categoryEventImageView.setImageDrawable(getResources().getDrawable(R.drawable.vector_single));
        }
        eventCategoryTextView.setText(eventDetails.getmCategory());
        locationTextView.setText(eventDetails.getmVenue());
        // hostClubTextView.setText(eventDetails.getmClubname());
        final Long fees = eventDetails.getmFees();
        if (fees == 0) {
            feesTextView.setText("Free");
        } else {
            feesTextView.setText(String.valueOf(fees));
        }
        if (eventDetails.getmEventTeamSize().equals("NA")) {
            registerButton.setVisibility(View.GONE);
            // line1.setVisibility(View.GONE);
            typeOfEventTextView.setText("Presentation Event");
            if (eventDetails.getmName().equals("XUNBAO")) {
                registerButton.setVisibility(View.VISIBLE);
                registerButton.setText("PLAY NOW!");
            }
        } else {
            typeOfEventTextView.setText(eventDetails.getmEventTeamSize());
        }
        for (final Coordinators coord : eventDetails.getmCoordinators()) {
            if (!coord.getmCoordName().equals("")) {
                View view = View.inflate(getApplicationContext(), R.layout.single_layout_event_coords, null);
                TextView coordNameView = (TextView) view.findViewById(R.id.tv_coords_name);
                TextView coordPhoneView = (TextView) view.findViewById(R.id.tv_coords_phone_no);
                coordNameView.setText(coord.getmCoordName());
                coordPhoneView.setText(String.valueOf(coord.getmCoordPhone()));
                // coordsPhoneList.add(coord.getmCoordPhone());
                coordCount++;
                coordsLinearLayout.addView(view);
                view.setOnClickListener(new View.OnClickListener() {

                    @Override
                    public void onClick(View v) {
                        phoneIntent = new Intent(Intent.ACTION_DIAL, Uri.parse("tel:" + coord.getmCoordPhone()));
                        if (ActivityCompat.checkSelfPermission(SingleEventActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED && !permission) {
                            final String[] PERMISSIONS_CALL = { Manifest.permission.CALL_PHONE };
                            // Asking request Permissions
                            ActivityCompat.requestPermissions(SingleEventActivity.this, PERMISSIONS_CALL, 9);
                            permission = true;
                        } else if (ActivityCompat.checkSelfPermission(SingleEventActivity.this, Manifest.permission.CALL_PHONE) != PackageManager.PERMISSION_GRANTED && permission) {
                            MDToast.makeText(SingleEventActivity.this, "Please grant Permissions first", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
                        } else {
                            permission = true;
                            startActivity(phoneIntent);
                        }
                    }
                });
            }
        }
        if (coordCount == 0) {
            coordsLinearLayout.setVisibility(View.GONE);
            coordsHeading.setVisibility(View.GONE);
        // line2.setVisibility(View.GONE);
        }
        firstPrizeTextView.setVisibility(View.GONE);
        secondPrizeTextView.setVisibility(View.GONE);
        thirdPrizeTextView.setVisibility(View.GONE);
        prizesRelativeLayout.setVisibility(View.GONE);
        line3.setVisibility(View.GONE);
        for (String prizes : eventDetails.getmPrizes()) {
            if (!prizes.equals("") && !prizes.equals("null") && prizeCount == 0) {
                line3.setVisibility(View.VISIBLE);
                firstPrizeTextView.setVisibility(View.VISIBLE);
                firstPrizeTextView.setText("First Prize: Rs " + prizes);
                prizesRelativeLayout.setVisibility(View.VISIBLE);
                prizeCount++;
            } else if (!prizes.equals("") && !prizes.equals("null") && prizeCount == 1) {
                secondPrizeTextView.setVisibility(View.VISIBLE);
                secondPrizeTextView.setText("Second Prize: Rs " + prizes);
                prizeCount++;
            } else if (!prizes.equals("") && !prizes.equals("null") && prizeCount == 2) {
                thirdPrizeTextView.setVisibility(View.VISIBLE);
                thirdPrizeTextView.setText("Third Prize: Rs " + prizes);
                prizeCount++;
            }
        }
        descriptionTextView.setText(eventDetails.getmDesc());
        rulesTextView.setText(eventDetails.getmRules());
        dateTimeRelativeLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                MDToast.makeText(SingleEventActivity.this, "Set a reminder!", MDToast.LENGTH_SHORT, MDToast.TYPE_INFO).show();
                try {
                    if (!permissionGranted(android.Manifest.permission.READ_CALENDAR, android.Manifest.permission.WRITE_CALENDAR)) {
                        askForPermission(android.Manifest.permission.READ_CALENDAR, android.Manifest.permission.WRITE_CALENDAR);
                    } else {
                        addToCalendar();
                    }
                } catch (Exception ex) {
                }
            }
        });
        locationRelativeLayout.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                MDToast.makeText(SingleEventActivity.this, "Search on Maps!", MDToast.LENGTH_SHORT, MDToast.TYPE_INFO).show();
                Intent intentMap = new Intent(SingleEventActivity.this, MapsActivity.class).setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
                startActivity(intentMap);
            }
        });
        registerButton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                if (registerButton.getText().toString().equals("View Ticket")) {
                    // barViewTicket.setVisibility(View.VISIBLE);
                    pd.show();
                    Handler pdCanceller = new Handler();
                    pdCanceller.postDelayed(progressRunnable, 3000);
                    FragmentManager fm = getFragmentManager();
                    Bundle bundle = new Bundle();
                    bundle.putString("qrcodestring", TicketModel.getQRcode());
                    bundle.putString("eventid", eventId);
                    bundle.putInt("activity", 0);
                    bundle.putInt("paymentStatus", TicketModel.getPaymentStatus());
                    bundle.putInt("arrivalStatus", TicketModel.getArrivalStatus());
                    fragobj.setArguments(bundle);
                    if (fragobj != null) {
                        fragobj.show(fm, "hiiiii");
                        pd.dismiss();
                    } else {
                        MDToast.makeText(SingleEventActivity.this, "Unable to load ticket.", Toast.LENGTH_SHORT, MDToast.TYPE_ERROR).show();
                        pd.dismiss();
                    }
                } else if (registerButton.getText().toString().equals("PLAY NOW!")) {
                    if (eventDetails.getmName().equals("XUNBAO"))
                        startActivity(new Intent(SingleEventActivity.this, XunbaoActivity.class));
                    else if (eventDetails.getmName().equals("HACKON")) {
                        // missing 'http://' will cause crashed
                        Uri uri = Uri.parse("http://www.elementsculmyca.com/schedule");
                        Intent intent = new Intent(Intent.ACTION_VIEW, uri);
                        startActivity(intent);
                    }
                } else {
                    startActivity(new Intent(SingleEventActivity.this, EventRegister.class).putExtra("eventName", eventDetails.getmName()).putExtra("eventId", eventDetails.getmEventId()).putExtra("eventType", eventDetails.getmEventTeamSize()));
                }
            }
        });
        sharebutton.setOnClickListener(new View.OnClickListener() {

            @Override
            public void onClick(View v) {
                String baseUrl = "http://elementsculmyca.com/event/";
                String parsedUrl = baseUrl + "#" + eventDetails.getmName().toString().replaceAll(" ", "%20");
                String message = "Elements Culmyca 2018:" + eventDetails.getmName().toString() + " View the event clicking the link: " + parsedUrl;
                shareEventMessage(message);
            }
        });
        showSnack(isConnected());
    }
}
Also used : Bundle(android.os.Bundle) Calendar(java.util.Calendar) Handler(android.os.Handler) DatabaseController(com.manan.dev.ec2018app.DatabaseHandler.DatabaseController) Intent(android.content.Intent) ProgressDialog(android.app.ProgressDialog) Uri(android.net.Uri) ImageView(android.widget.ImageView) View(android.view.View) TextView(android.widget.TextView) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) EventDetails(com.manan.dev.ec2018app.Models.EventDetails) FragmentManager(android.app.FragmentManager) TextView(android.widget.TextView) Coordinators(com.manan.dev.ec2018app.Models.Coordinators) SimpleDateFormat(java.text.SimpleDateFormat) QRCodeActivity(com.manan.dev.ec2018app.Fragments.QRCodeActivity)

Aggregations

FragmentManager (android.app.FragmentManager)2 Bundle (android.os.Bundle)2 QRCodeActivity (com.manan.dev.ec2018app.Fragments.QRCodeActivity)2 ProgressDialog (android.app.ProgressDialog)1 Intent (android.content.Intent)1 SharedPreferences (android.content.SharedPreferences)1 Uri (android.net.Uri)1 Handler (android.os.Handler)1 View (android.view.View)1 ImageView (android.widget.ImageView)1 TextView (android.widget.TextView)1 RequestQueue (com.android.volley.RequestQueue)1 Response (com.android.volley.Response)1 VolleyError (com.android.volley.VolleyError)1 StringRequest (com.android.volley.toolbox.StringRequest)1 DatabaseController (com.manan.dev.ec2018app.DatabaseHandler.DatabaseController)1 Coordinators (com.manan.dev.ec2018app.Models.Coordinators)1 EventDetails (com.manan.dev.ec2018app.Models.EventDetails)1 MyNotificationResponse (com.manan.dev.ec2018app.Notifications.MyNotificationResponse)1 IOException (java.io.IOException)1