use of com.ushahidi.android.app.util.Util in project Ushahidi_Android by ushahidi.
the class CommentsApi method getCommentsList.
/**
* Fetch report's comments using the Ushahidi API
*
* @param reportId
* The report ID
* @return
*/
public List<CommentEntity> getCommentsList(int reportId) {
new Util().log("Save comments");
if (processingResult) {
try {
for (com.ushahidi.java.sdk.api.Comment c : task.reportId(reportId)) {
CommentEntity comment = new CommentEntity();
comment.addComment(c);
comments.add(comment);
}
} catch (UshahidiException e) {
processingResult = false;
log("CommentsApi getCommentsList", e);
} catch (JsonSyntaxException e) {
processingResult = false;
log("CommentsApi getCommentsList", e);
}
}
return comments;
}
use of com.ushahidi.android.app.util.Util in project Ushahidi_Android by ushahidi.
the class FetchReports method executeTask.
@Override
protected void executeTask(Intent intent) {
new Util().log("executeTask() executing this task");
clearCachedData();
ApiUtils.updateDomain(this);
// fetch categories
new CategoriesApi().getCategoriesList();
// fetch reports
status = new ReportsApi().saveReports(this) ? 0 : 99;
statusIntent.putExtra("status", status);
sendBroadcast(statusIntent);
}
use of com.ushahidi.android.app.util.Util in project Ushahidi_Android by ushahidi.
the class CategoriesApi method getCategoriesList.
/**
* Fetch categories using the Ushahidi API
*
* @return boolean Successful return true otherwise return false
*/
public boolean getCategoriesList() {
new Util().log("Save categories list");
if (processingResult) {
try {
List<Category> cats = task.all();
if (cats != null) {
for (com.ushahidi.java.sdk.api.Category cat : cats) {
CategoryEntity category = new CategoryEntity();
category.addCategory(cat);
categories.add(category);
}
return saveCategories(categories);
}
} catch (UshahidiException e) {
log("UshahidiException", e);
processingResult = false;
} catch (JsonSyntaxException e) {
log("JSONSyntaxException", e);
}
}
return false;
}
use of com.ushahidi.android.app.util.Util in project Ushahidi_Android by ushahidi.
the class SyncServices method onHandleIntent.
/**
* {@inheritDoc} Perform a task as implemented by the executeTask()
*/
@Override
protected void onHandleIntent(Intent intent) {
new Util().log("onHandleIntent(): running service");
try {
boolean isConnected = Util.isConnected(this);
// check if we have internet
if (!isConnected) {
// Enable the Connectivity Changed Receiver to listen for
// connection
// to a network
// so we can execute pending messages.
PackageManager pm = getPackageManager();
ComponentName connectivityReceiver = new ComponentName(this, ConnectivityChangedReceiver.class);
pm.setComponentEnabledSetting(connectivityReceiver, PackageManager.COMPONENT_ENABLED_STATE_ENABLED, PackageManager.DONT_KILL_APP);
} else {
// execute the scheduled task
executeTask(intent);
}
} finally {
if (getPhoneWakeLock(this.getApplicationContext()).isHeld() && getPhoneWakeLock(this.getApplicationContext()) != null) {
getPhoneWakeLock(this.getApplicationContext()).release();
}
if (getPhoneWifiLock(this.getApplicationContext()).isHeld() && getPhoneWifiLock(this.getApplicationContext()) != null) {
getPhoneWifiLock(this.getApplicationContext()).release();
}
}
}
Aggregations