use of com.backendless.examples.endless.matchmaker.models.persistent.UserPreferences in project Android-SDK by Backendless.
the class CreateTablesActivity method saveDefaultColum.
private void saveDefaultColum(String email, String preference, String theme) {
UserPreferences userPreferences = new UserPreferences(email, preference, theme);
Backendless.Persistence.save(userPreferences, new BackendlessCallback<UserPreferences>() {
@Override
public void handleResponse(UserPreferences userPreferences) {
Toast.makeText(CreateTablesActivity.this, "A new comment was successfully added", Toast.LENGTH_LONG).show();
}
});
}
use of com.backendless.examples.endless.matchmaker.models.persistent.UserPreferences in project Android-SDK by Backendless.
the class EditPreferencesActivity method getCheckboxListener.
private View.OnClickListener getCheckboxListener(final CheckBox checkBox) {
return new View.OnClickListener() {
@Override
public void onClick(View view) {
final View check = view;
String preferenceName = ((CheckBox) view).getText().toString();
boolean isChecked = checkBox.isChecked();
UserPreferences currentPreference;
if (isChecked) {
check.setEnabled(false);
currentPreference = new UserPreferences(Backendless.UserService.CurrentUser().getEmail(), preferenceName, preferenceTheme.getPreference());
preferenceStore.save(currentPreference, new ResponseAsyncCallback<UserPreferences>(EditPreferencesActivity.this) {
@Override
public void handleResponse(UserPreferences response) {
preferenceNameToPreferenceMap.put(response.getPreference(), response);
check.setEnabled(true);
}
});
} else {
check.setEnabled(false);
currentPreference = preferenceNameToPreferenceMap.get(preferenceName);
preferenceStore.remove(currentPreference, new ResponseAsyncCallback<Long>(EditPreferencesActivity.this) {
@Override
public void handleResponse(Long response) {
check.setEnabled(true);
}
});
}
}
};
}
use of com.backendless.examples.endless.matchmaker.models.persistent.UserPreferences 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();
}
});
}
Aggregations