@Override
 protected void onCancelled() {
   toggleMenu(SYNC_ALL);
   RapidFtrApplication.getApplicationInstance()
       .cancelNotification(recordSyncService.getNotificationId());
   RapidFtrApplication.getApplicationInstance().setSyncTask(null);
 }
 private void registerUser() throws IOException {
   String serverUrl = applicationContext.getSharedPreferences().getString(SERVER_URL_PREF, null);
   HttpResponse response = registerUserService.register(currentUser);
   if (response.getStatusLine().getStatusCode() == SC_OK) {
     currentUser.setServerUrl(serverUrl);
   } else {
     applicationContext.getSharedPreferences().edit().putString(SERVER_URL_PREF, "").commit();
   }
 }
 @Override
 protected Application createApplication() {
   RapidFtrApplication application = new RapidFtrApplication(INJECTOR);
   try {
     application.getSharedPreferences().edit().putString(SERVER_URL_PREF, "http://1.2.3.4:5");
     application.setFormSections(formSectionSeed);
     application.setCurrentUser(createUser());
   } catch (Exception e) {
     throw new RuntimeException(e);
   }
   return application;
 }
 @Override
 public void setUp() throws Exception {
   super.setUp();
   loginPage.login();
   Assert.assertTrue(solo.waitForText("Login Successful"));
   waitUntilTextDisappears("Login Successful");
   repository =
       RapidFtrApplication.getApplicationInstance()
           .getInjector()
           .getInstance(EnquiryRepository.class);
   childRepository =
       RapidFtrApplication.getApplicationInstance()
           .getInjector()
           .getInstance(ChildRepository.class);
 }
 public List<String> getIdsToDownload() throws IOException, JSONException, HttpException {
   // Default value is currently epoch
   long lastUpdateMillis =
       context.getSharedPreferences().getLong(RapidFtrApplication.LAST_CHILD_SYNC, 0);
   DateTime lastUpdate = new DateTime(lastUpdateMillis);
   return childEntityHttpDao.getUpdatedResourceUrls(lastUpdate);
 }
 @Override
 protected void onPreExecute() {
   RapidFtrApplication.getApplicationInstance().setSyncTask(this);
   toggleMenu(CANCEL_SYNC_ALL);
   initNotifiers();
   configureNotification();
 }
 @Override
 public void setLastSyncedAt() {
   RapidFtrApplication.getApplicationInstance()
       .getSharedPreferences()
       .edit()
       .putLong(RapidFtrApplication.LAST_CHILD_SYNC, System.currentTimeMillis())
       .commit();
 }
 public void testDisplayAllChildren() throws JSONException {
   ChildRepository repository =
       RapidFtrApplication.getInstance().getInjector().getInstance(ChildRepository.class);
   repository.createOrUpdate(new Child("id1", "rapidftr", "{\"name\":\"Test1\"}"));
   repository.createOrUpdate(new Child("id2", "rapidftr", "{\"name\":\"Test2\"}"));
   assertTrue(viewAllChildrenPage.isChildPresent("id1", "Test1"));
   assertTrue(viewAllChildrenPage.isChildPresent("id2", "Test2"));
 }
 @Override
 protected void onProgressUpdate(String... values) {
   RapidFtrApplication.getApplicationInstance()
       .showNotification(
           recordSyncService.getNotificationId(),
           recordSyncService.getNotificationTitle(),
           values[0]);
 }
  public void testClickOnChildShouldShowViewPage() throws JSONException {
    ChildRepository repository =
        RapidFtrApplication.getInstance().getInjector().getInstance(ChildRepository.class);
    Child child1 = new Child("id1", "rapidftr", "{\"name\":\"Test1\"}");
    repository.createOrUpdate(child1);
    Child child2 = new Child("id2", "rapidftr", "{\"name\":\"Test2\"}");
    repository.createOrUpdate(child2);

    viewAllChildrenPage.clickChild("id1");
    viewAllChildrenPage.verifyChildDetails(child1);
  }
 @Override
 protected void onPostExecute(Boolean result) {
   toggleMenu(SYNC_ALL);
   RapidFtrApplication.getApplicationInstance().setSyncTask(null);
   if (result) {
     RapidFtrApplication.getApplicationInstance()
         .showNotification(
             recordSyncService.getNotificationId(),
             recordSyncService.getNotificationTitle(),
             successMessage);
     Toast.makeText(
             RapidFtrApplication_.getApplicationInstance(), successMessage, Toast.LENGTH_LONG)
         .show();
   } else {
     Toast.makeText(
             RapidFtrApplication_.getApplicationInstance(),
             RapidFtrApplication_.getApplicationInstance().getString(R.string.sync_error),
             Toast.LENGTH_LONG)
         .show();
   }
 }
 protected void setProgressAndNotify(String statusText, int progress) {
   if (!isCancelled()) {
     RapidFtrApplication.getApplicationInstance()
         .showProgressNotification(
             recordSyncService.getNotificationId(),
             context.getString(R.string.sync_title),
             statusText,
             maxProgress,
             progress,
             false);
   }
 }
 public void testClickOnChildShouldShowViewPage() throws JSONException {
   ChildRepository repository =
       RapidFtrApplication.getApplicationInstance()
           .getInjector()
           .getInstance(ChildRepository.class);
   Child child1 = new Child(getAlphaNumeric(4), "rapidftr", "{\"name\":\"Test1\"}");
   repository.createOrUpdate(child1);
   Child child2 = new Child(getAlphaNumeric(6), "rapidftr", "{\"name\":\"Test2\"}");
   repository.createOrUpdate(child2);
   viewAllChildrenPage.navigateToViewAllPage();
   viewAllChildrenPage.clickChild(child1.getUniqueId());
   viewAllChildrenPage.verifyChildDetails(child1);
 }
  public void estShouldEditAnEnquiry() throws JSONException {
    Enquiry enquiry =
        new Enquiry(
            "CREATEDBY", "Enq2Reportername", new JSONObject("{enquirer_name:Enq2Enquirername}"));
    EnquiryRepository repository =
        RapidFtrApplication.getApplicationInstance()
            .getInjector()
            .getInstance(EnquiryRepository.class);
    List<String> updatedEnquirerDetails = asList("Nile");

    repository.createOrUpdate(enquiry);
    enquiry = repository.get(enquiry.getUniqueId());

    enquiryPage.navigateToEditPageOf(enquiry.getEnquirerName());
    enquiryPage.enterEnquirerDetails(updatedEnquirerDetails);
    enquiryPage.save();
  }
  @Override
  protected Boolean doInBackground(Object... notRelevant) {
    try {
      sync();
      return true;
    } catch (HttpException e) {
      Log.e("SyncAllDataTask", "HTTPError in sync", e);

      String message =
          RapidFtrApplication.getApplicationInstance().getString(R.string.session_timeout);
      if (e.getMessage() != null && e.getMessage().trim().length() > 0) {
        message = e.getMessage();
      }

      publishProgress(message);
      return false;
    } catch (Exception e) {
      Log.e("SyncAllDataTask", "Error in sync", e);
      publishProgress(context.getString(R.string.sync_error));
      return false;
    }
  }
 @Override
 protected void onCancelled() {
   RapidFtrApplication.getApplicationInstance().setSyncTask(null);
   toggleMenu(SYNC_ALL);
   notificationManager.cancel(NOTIFICATION_ID);
 }
 @Override
 public String getNotificationTitle() {
   return context.getString(R.string.child_sync_title);
 }
 @Override
 protected void onPostExecute(Boolean result) {
   RapidFtrApplication.getApplicationInstance().setSyncTask(null);
   toggleMenu(SYNC_ALL);
   notificationManager.cancel(NOTIFICATION_ID);
 }
 @Override
 protected void onProgressUpdate(String... values) {
   Toast.makeText(RapidFtrApplication.getApplicationInstance(), values[0], Toast.LENGTH_LONG)
       .show();
 }
 @Override
 protected void onPreExecute() {
   RapidFtrApplication.getApplicationInstance().setSyncTask(this);
   toggleMenu(CANCEL_SYNC_ALL);
 }