Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public void onActivityResult(int requestCode, int resultCode, Intent data)
- {
- if (resultCode == Activity.RESULT_OK && getActivity() != null)
- {
- if (requestCode == ZBAR_QR_SCANNER_REQUEST)
- {
- final ProgressDialog dialog = ProgressDialog.show(getActivity(), "Loading", "Checking reward...");
- String contents = data.getStringExtra(ZBarConstants.SCAN_RESULT);
- ParseQuery<ParseObject> locationParentCompanyCheckQuery = new ParseQuery<ParseObject>("RetailLocation");
- locationParentCompanyCheckQuery.whereEqualTo("appCompany", LocalUser.getInstance().getParentCompany());
- ParseQuery<ParseObject> qrCodequery = ParseQuery.getQuery(Constants.OBJECT_QRCODE);
- qrCodequery.whereMatchesQuery("location", locationParentCompanyCheckQuery);
- qrCodequery.whereEqualTo("objectId", contents);
- qrCodequery.include("location");
- qrCodequery.getFirstInBackground(new GetCallback<ParseObject>()
- {
- @Override
- public void done(final ParseObject qrCodeObject, ParseException e)
- {
- if (getActivity() != null)
- {
- dialog.cancel();
- if (e == null)
- {
- final ProgressDialog locationCheckDialog = ProgressDialog.show(getActivity(), "Loading", "Checking your location...");
- final ParseObject locationObject = qrCodeObject.getParseObject("location");
- ParseGeoPoint.getCurrentLocationInBackground(10000, new LocationCallback()
- {
- @Override
- public void done(ParseGeoPoint parseGeoPoint, ParseException e)
- {
- if (getActivity() != null && locationCheckDialog != null)
- {
- locationCheckDialog.dismiss();
- }
- if (e == null)
- {
- if (parseGeoPoint != null)
- {
- double distanceKilometers = parseGeoPoint.distanceInKilometersTo(locationObject.
- getParseGeoPoint("location"));
- double distanceMeters = distanceKilometers * 1000.0;
- if (distanceMeters <= locationObject.getDouble("vicinityRadius"))
- {
- int pointsToAward = qrCodeObject.getInt(Constants.POINTS_TO_AWARD);
- userData.put("rewardPoints", userData.getInt("rewardPoints") + pointsToAward);
- userData.put("qrScanDate", new Date());
- userData.saveInBackground(new SaveCallback()
- {
- @Override
- public void done(ParseException paramParseException)
- {
- updateRewardsTextView();
- }
- });
- }
- else
- {
- Toast.makeText(getActivity(), "You must scan this code in a store to win loyalty points", Toast.LENGTH_SHORT).show();
- }
- }
- else
- {
- Toast.makeText(getActivity(), "Error - couldn't fetch your location", Toast.LENGTH_SHORT).show();
- }
- }
- else
- {
- e.printStackTrace();
- }
- }
- });
- }
- else
- {
- Toast.makeText(getActivity(), "Invalid QR code", Toast.LENGTH_SHORT).show();
- }
- }
- }
- });
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement