Search in sources :

Example 1 with TootEntity

use of com.keylesspalace.tusky.db.TootEntity in project Tusky by tuskyapp.

the class SavedTootAdapter method removeItem.

@Nullable
public TootEntity removeItem(int position) {
    if (position < 0 || position >= list.size()) {
        return null;
    }
    TootEntity toot = list.remove(position);
    notifyItemRemoved(position);
    return toot;
}
Also used : TootEntity(com.keylesspalace.tusky.db.TootEntity) Nullable(android.support.annotation.Nullable)

Example 2 with TootEntity

use of com.keylesspalace.tusky.db.TootEntity in project Tusky by tuskyapp.

the class ComposeActivity method saveTheToot.

@SuppressLint("StaticFieldLeak")
private boolean saveTheToot(String s, @Nullable String contentWarning) {
    if (TextUtils.isEmpty(s)) {
        return false;
    }
    // Get any existing file's URIs.
    ArrayList<String> existingUris = null;
    String savedJsonUrls = getIntent().getStringExtra("saved_json_urls");
    if (!TextUtils.isEmpty(savedJsonUrls)) {
        existingUris = new Gson().fromJson(savedJsonUrls, new TypeToken<ArrayList<String>>() {
        }.getType());
    }
    String mediaUrlsSerialized = null;
    if (!ListUtils.isEmpty(mediaQueued)) {
        List<String> savedList = saveMedia(existingUris);
        if (!ListUtils.isEmpty(savedList)) {
            mediaUrlsSerialized = new Gson().toJson(savedList);
            if (!ListUtils.isEmpty(existingUris)) {
                deleteMedia(setDifference(existingUris, savedList));
            }
        } else {
            return false;
        }
    } else if (!ListUtils.isEmpty(existingUris)) {
        /* If there were URIs in the previous draft, but they've now been removed, those files
             * can be deleted. */
        deleteMedia(existingUris);
    }
    final TootEntity toot = new TootEntity(savedTootUid, s, mediaUrlsSerialized, contentWarning, inReplyToId, getIntent().getStringExtra(REPLYING_STATUS_CONTENT_EXTRA), getIntent().getStringExtra(REPLYING_STATUS_AUTHOR_USERNAME_EXTRA), statusVisibility);
    new AsyncTask<Void, Void, Void>() {

        @Override
        protected Void doInBackground(Void... params) {
            tootDao.insertOrReplace(toot);
            return null;
        }
    }.execute();
    return true;
}
Also used : ArrayList(java.util.ArrayList) Gson(com.google.gson.Gson) TootEntity(com.keylesspalace.tusky.db.TootEntity) SuppressLint(android.annotation.SuppressLint)

Aggregations

TootEntity (com.keylesspalace.tusky.db.TootEntity)2 SuppressLint (android.annotation.SuppressLint)1 Nullable (android.support.annotation.Nullable)1 Gson (com.google.gson.Gson)1 ArrayList (java.util.ArrayList)1