Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void registerReceiptRegistration() {
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- connector.register(Uri.parse(ReceiptRegistrationProvider.CONTENT_URI_TEXT.toString()), new ReceiptRegistrationConnector.ReceiptRegistrationCallback<Void>());
- return null;
- }
- }.execute();
- }
- private void unregisterReceiptRegistration() {
- new AsyncTask<Void, Void, Void>() {
- @Override
- protected Void doInBackground(Void... params) {
- connector.unregister(Uri.parse(ReceiptRegistrationProvider.CONTENT_URI_TEXT.toString()), new ReceiptRegistrationConnector.ReceiptRegistrationCallback<Void>());
- return null;
- }
- @Override
- protected void onPostExecute(Void aVoid) {
- super.onPostExecute(aVoid);
- connector.disconnect();
- connector = null;
- }
- }.execute();
- }
- @Override
- protected void onPause() {
- disconnect();
- super.onPause();
- }
- private void connect() {
- disconnect();
- if (account != null) {
- connector = new ReceiptRegistrationConnector(this, account, new ServiceConnector.OnServiceConnectedListener() {
- @Override
- public void onServiceConnected(ServiceConnector<? extends IInterface> serviceConnector) {
- registerReceiptRegistration();
- }
- @Override
- public void onServiceDisconnected(ServiceConnector<? extends IInterface> serviceConnector) {
- }
- });
- connector.connect();
- orderConnector = new OrderConnector(this, account, null);
- orderConnector.connect();
- }
- }
- private void disconnect() {
- if (connector != null) {
- unregisterReceiptRegistration();
- }
- if (orderConnector != null) {
- orderConnector.disconnect();
- orderConnector = null;
- }
- }
- private class MyAsyncTask extends AsyncTask<Void, Void, Order> {
- @Override
- protected final Order doInBackground(Void... params) {
- String orderId = null;
- Cursor cursor = null;
- try {
- // Query the last order
- cursor = Home.this.getContentResolver().query(OrderContract.Summaries.contentUriWithAccount(account), new String[]{OrderContract.Summaries.ID}, null, null, OrderContract.Summaries.LAST_MODIFIED + " DESC LIMIT 1");
- if (cursor != null && cursor.moveToFirst()) {
- orderId = cursor.getString(cursor.getColumnIndex(OrderContract.Summaries.ID));
- }
- if (orderId == null) {
- return orderConnector.createOrder(new Order());
- } else {
- return orderConnector.getOrder(orderId);
- }
- } catch (RemoteException e) {
- e.printStackTrace();
- } catch (ClientException e) {
- e.printStackTrace();
- } catch (ServiceException e) {
- e.printStackTrace();
- } catch (BindingException e) {
- e.printStackTrace();
- } finally {
- if (cursor != null) {
- cursor.close();
- }
- }
- return null;
- }
- @Override
- protected final void onPostExecute(Order order) {
- PrintJob pj = new BillPrintJob.Builder().orderId(order.getId()).build();
- pj.print(Home.this, account);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement