Search in sources :

Example 1 with Util

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;
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) CommentEntity(com.ushahidi.android.app.entities.CommentEntity)

Example 2 with Util

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);
}
Also used : ReportsApi(com.ushahidi.android.app.api.ReportsApi) CategoriesApi(com.ushahidi.android.app.api.CategoriesApi) Util(com.ushahidi.android.app.util.Util)

Example 3 with Util

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;
}
Also used : Category(com.ushahidi.java.sdk.api.Category) JsonSyntaxException(com.google.gson.JsonSyntaxException) Util(com.ushahidi.android.app.util.Util) UshahidiException(com.ushahidi.java.sdk.UshahidiException) Category(com.ushahidi.java.sdk.api.Category) CategoryEntity(com.ushahidi.android.app.entities.CategoryEntity)

Example 4 with Util

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();
        }
    }
}
Also used : PackageManager(android.content.pm.PackageManager) Util(com.ushahidi.android.app.util.Util) ComponentName(android.content.ComponentName)

Aggregations

Util (com.ushahidi.android.app.util.Util)4 JsonSyntaxException (com.google.gson.JsonSyntaxException)2 UshahidiException (com.ushahidi.java.sdk.UshahidiException)2 ComponentName (android.content.ComponentName)1 PackageManager (android.content.pm.PackageManager)1 CategoriesApi (com.ushahidi.android.app.api.CategoriesApi)1 ReportsApi (com.ushahidi.android.app.api.ReportsApi)1 CategoryEntity (com.ushahidi.android.app.entities.CategoryEntity)1 CommentEntity (com.ushahidi.android.app.entities.CommentEntity)1 Category (com.ushahidi.java.sdk.api.Category)1