use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.
the class Persistence method getObjectCount.
<E> int getObjectCount(final Class<E> entity, DataQueryBuilder queryBuilder) {
if (queryBuilder == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
BackendlessDataQuery dataQuery = queryBuilder.build();
Object[] args = new Object[] { BackendlessSerializer.getSimpleName(entity), dataQuery };
return Invoker.invokeSync(PERSISTENCE_MANAGER_SERVER_ALIAS, "count", args);
}
use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.
the class Persistence method loadRelations.
public <T> List<T> loadRelations(String parentType, String objectId, LoadRelationsQueryBuilder queryBuilder, Class<T> relatedType) throws BackendlessException {
StringUtils.checkEmpty(objectId, ExceptionMessage.NULL_ENTITY);
if (queryBuilder == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
BackendlessDataQuery dataQuery = queryBuilder.build();
String relationName = dataQuery.getQueryOptions().getRelated().iterator().next();
int pageSize = dataQuery.getPageSize();
int offset = dataQuery.getOffset();
Object[] args = new Object[] { parentType, objectId, relationName, pageSize, offset };
return Invoker.invokeSync(PERSISTENCE_MANAGER_SERVER_ALIAS, "loadRelations", args, ResponderHelper.getCollectionAdaptingResponder(relatedType));
}
use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.
the class Persistence method getView.
public void getView(String viewName, DataQueryBuilder queryBuilder, AsyncCallback<Map<String, Object>> responder) {
if (queryBuilder == null)
throw new IllegalArgumentException(ExceptionMessage.NULL_FIELD("queryBuilder"));
BackendlessDataQuery dataQuery = queryBuilder.build();
Object[] args = new Object[] { viewName, dataQuery };
Invoker.invokeAsync(PERSISTENCE_MANAGER_SERVER_ALIAS, "callStoredView", args, responder);
}
use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.
the class EditPreferencesActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.editpreference);
progressDialog = UIFactory.getDefaultProgressDialog(this);
TextView preferenceName = (TextView) findViewById(R.id.preferenceName);
preferencesContainer = (LinearLayout) findViewById(R.id.preferencesContainer);
preferenceTheme = PreferenceTheme.valueOf(getIntent().getStringExtra(Lifecycle.PREFERENCE_TYPE_TAG));
preferenceStore = Backendless.Persistence.of(UserPreferences.class);
// Naming the page
preferenceName.setText(preferenceTheme.getPreference());
((TextView) findViewById(R.id.preferenceLabel)).setText(getString(R.string.textfield_preferences_label_base) + " " + preferenceTheme.getPreference().toLowerCase() + ":");
// Getting preference structure
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery("theme = '" + preferenceTheme.getPreference() + "'");
QueryOptions queryOptions = new QueryOptions();
queryOptions.setPageSize(50);
queryOptions.addSortByOption("name");
backendlessDataQuery.setQueryOptions(queryOptions);
Backendless.Persistence.of(PreferencesDefaults.class).find(backendlessDataQuery, new AsyncCallback<Collection<PreferencesDefaults>>() {
@Override
public void handleResponse(Collection<PreferencesDefaults> preferencesDefaultsBackendlessCollection) {
// Creating a map with predefined checkboxes
List<PreferencesDefaults> preferencesDefaults = preferencesDefaultsBackendlessCollection.getCurrentPage();
for (PreferencesDefaults preference : preferencesDefaults) {
CheckBox checkBox = UIFactory.getPreferenceCheckbox(EditPreferencesActivity.this, preference);
checkBox.setOnClickListener(getCheckboxListener(checkBox));
preferencesContainer.addView(checkBox);
preferenceNameToCheckboxMap.put(preference.getName(), checkBox);
}
// Getting preferences, which should be enabled for current user
String whereClause = "email = '" + Backendless.UserService.CurrentUser().getEmail() + "'";
whereClause += " and theme = '" + preferenceTheme.getPreference() + "'";
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.setWhereClause(whereClause);
backendlessDataQuery.setQueryOptions(new QueryOptions(50, 0));
Backendless.Persistence.of(UserPreferences.class).find(backendlessDataQuery, new AsyncCallback<Collection<UserPreferences>>() {
@Override
public void handleResponse(Collection<UserPreferences> userPreferencesBackendlessCollection) {
List<UserPreferences> userPreferences = userPreferencesBackendlessCollection.getCurrentPage();
for (UserPreferences userPreference : userPreferences) {
CheckBox checkBox = preferenceNameToCheckboxMap.get(userPreference.getPreference());
preferenceNameToPreferenceMap.put(userPreference.getPreference(), userPreference);
checkBox.setChecked(true);
}
progressDialog.cancel();
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EditPreferencesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
@Override
public void handleFault(BackendlessFault backendlessFault) {
progressDialog.cancel();
Toast.makeText(EditPreferencesActivity.this, backendlessFault.getMessage(), Toast.LENGTH_LONG).show();
}
});
}
use of com.backendless.persistence.BackendlessDataQuery in project Android-SDK by Backendless.
the class PointCommentsActivity method onCreate.
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.act_point_comments);
photoBtn = (Button) findViewById(R.id.photoBtn);
photoBtn.setVisibility(View.INVISIBLE);
final TextView textViewComment = (TextView) findViewById(R.id.textViewComment);
TextView textPointComments = (TextView) findViewById(R.id.textPointComments);
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/verdana.ttf");
textPointComments.setTypeface(typeface);
textViewComment.setTypeface(typeface);
textViewComment.setVisibility(View.INVISIBLE);
final EditText editComment = (EditText) findViewById(R.id.editComment);
editComment.setVisibility(View.INVISIBLE);
photoBtn.setTypeface(typeface);
Intent intent = getIntent();
geoPointId = intent.getStringExtra(Default.GEO_POINT_ID);
userName = (String) Backendless.UserService.CurrentUser().getProperty("name");
if (userName == null)
userName = Backendless.UserService.CurrentUser().getEmail();
Bitmap bitmap = intent.getParcelableExtra(Default.SEND_BITMAP);
imageView = (ImageView) findViewById(R.id.photoView);
imageView.setImageBitmap(bitmap);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
final Button commentsBtn = (Button) findViewById(R.id.commentsBtn);
commentsBtn.setTypeface(typeface);
commentsBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
imageView.setVisibility(View.INVISIBLE);
commentsBtn.setEnabled(false);
BackendlessDataQuery backendlessDataQuery = new BackendlessDataQuery();
backendlessDataQuery.addProperty("name");
backendlessDataQuery.addProperty("message");
backendlessDataQuery.setWhereClause("geoPointId=" + "'" + geoPointId + "'");
progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
Backendless.Persistence.of(Comment.class).find(backendlessDataQuery, new AsyncCallback<Collection<Comment>>() {
@Override
public void handleResponse(Collection<Comment> response) {
Collection<Comment> comments = response;
for (int i = 0; i < comments.getCurrentPage().size(); i++) {
Comment comment = comments.getCurrentPage().get(i);
String userName = comment.getName();
commentsPoint.add(userName + " : " + comment.getMessage());
}
lvMain = (ListView) findViewById(R.id.commentList);
lvMain.setVisibility(View.VISIBLE);
adapter = new ArrayAdapter<String>(PointCommentsActivity.this, android.R.layout.simple_list_item_1, commentsPoint);
lvMain.setAdapter(adapter);
progressDialog.cancel();
textViewComment.setVisibility(View.VISIBLE);
editComment.setVisibility(View.VISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
commentsBtn.setVisibility(View.INVISIBLE);
photoBtn.setVisibility(View.VISIBLE);
}
@Override
public void handleFault(BackendlessFault fault) {
progressDialog.cancel();
Toast.makeText(PointCommentsActivity.this, fault.getMessage(), Toast.LENGTH_LONG).show();
textViewComment.setVisibility(View.VISIBLE);
editComment.setVisibility(View.VISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
commentsBtn.setVisibility(View.INVISIBLE);
photoBtn.setVisibility(View.VISIBLE);
}
});
}
});
addCommentBtn = (Button) findViewById(R.id.addCommentBtn);
addCommentBtn.setTypeface(typeface);
addCommentBtn.setVisibility(View.INVISIBLE);
addCommentBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
final String commentName = editComment.getText().toString();
if (TextUtils.isEmpty(commentName)) {
String alertMessage = "Please, fill in empty field!";
Toast.makeText(PointCommentsActivity.this, alertMessage, Toast.LENGTH_LONG).show();
return;
}
progressDialog = ProgressDialog.show(PointCommentsActivity.this, "", "Loading", true);
Comment commentPoint = new Comment(userName, commentName, geoPointId);
Backendless.Persistence.save(commentPoint, new BackendlessCallback<Comment>() {
@Override
public void handleResponse(Comment commentPoint) {
Intent categoryIntent = getIntent();
String name = categoryIntent.getStringExtra(Default.SEARCH_CATEGORY_NAME);
Intent intent = new Intent();
intent.putExtra(Default.SEARCH_CATEGORY_NAME, name);
setResult(Default.ADD_NEW_COMMENT, intent);
progressDialog.cancel();
finish();
Toast.makeText(PointCommentsActivity.this, "A new comment was successfully added", Toast.LENGTH_LONG).show();
}
});
}
});
photoBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
adapter.clear();
lvMain.setAdapter(adapter);
lvMain.setVisibility(View.INVISIBLE);
textViewComment.setVisibility(View.INVISIBLE);
editComment.setVisibility(View.INVISIBLE);
addCommentBtn.setVisibility(View.VISIBLE);
imageView.setVisibility(View.VISIBLE);
photoBtn.setVisibility(View.INVISIBLE);
commentsBtn.setVisibility(View.VISIBLE);
commentsBtn.setEnabled(true);
}
});
}
Aggregations