use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.
the class AllContentFragment method showCustomizeTagsDialog.
private void showCustomizeTagsDialog() {
CustomizeTagsDialogFragment dialog = CustomizeTagsDialogFragment.newInstance();
dialog.setListener(new TagListener() {
@Override
public void onTagAdded(Tag tag) {
// heavy-lifting
// save to local, save to wallet and then sync
FollowUnfollowTagTask task = new FollowUnfollowTagTask(tag, false, getContext(), followUnfollowHandler);
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
@Override
public void onTagRemoved(Tag tag) {
// heavy-lifting
// save to local, save to wallet and then sync
FollowUnfollowTagTask task = new FollowUnfollowTagTask(tag, true, getContext(), followUnfollowHandler);
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
dialog.show(activity.getSupportFragmentManager(), CustomizeTagsDialogFragment.TAG);
}
}
use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.
the class LoadSharedUserStateTask method doInBackground.
protected Boolean doInBackground(Void... params) {
// Get the previous saved state
try {
SQLiteDatabase db = null;
JSONObject result = (JSONObject) Lbry.authenticatedGenericApiCall(Lbry.METHOD_PREFERENCE_GET, Lbry.buildSingleParam("key", KEY), authToken);
if (result != null) {
MainActivity activity = null;
if (context instanceof MainActivity) {
activity = (MainActivity) context;
db = activity.getDbHelper().getWritableDatabase();
}
// get the built in collections
Map<String, OdyseeCollection> allCollections = null;
OdyseeCollection favoritesPlaylist = null;
OdyseeCollection watchlaterPlaylist = null;
if (db != null) {
allCollections = DatabaseHelper.loadAllCollections(db);
favoritesPlaylist = allCollections.get(OdyseeCollection.BUILT_IN_ID_FAVORITES);
watchlaterPlaylist = allCollections.get(OdyseeCollection.BUILT_IN_ID_WATCHLATER);
}
JSONObject shared = result.getJSONObject("shared");
if (shared.has("type") && "object".equalsIgnoreCase(shared.getString("type")) && shared.has("value")) {
JSONObject value = shared.getJSONObject("value");
JSONArray tags = value.has("tags") && !value.isNull("tags") ? value.getJSONArray("tags") : null;
JSONArray blocked = value.has("blocked") && !value.isNull("blocked") ? value.getJSONArray("blocked") : null;
JSONObject builtInCollections = Helper.getJSONObject("builtinCollections", value);
OdyseeCollection favoritesCollection = OdyseeCollection.fromJSONObject(OdyseeCollection.BUILT_IN_ID_FAVORITES, OdyseeCollection.VISIBILITY_PRIVATE, Helper.getJSONObject(OdyseeCollection.BUILT_IN_ID_FAVORITES, builtInCollections));
OdyseeCollection watchLaterCollection = OdyseeCollection.fromJSONObject(OdyseeCollection.BUILT_IN_ID_WATCHLATER, OdyseeCollection.VISIBILITY_PRIVATE, Helper.getJSONObject(OdyseeCollection.BUILT_IN_ID_WATCHLATER, builtInCollections));
if (activity != null) {
if (favoritesPlaylist == null || favoritesCollection.getUpdatedAtTimestamp() > favoritesPlaylist.getUpdatedAtTimestamp()) {
// only replace the locally saved collections if there are items
DatabaseHelper.saveCollection(favoritesCollection, db);
}
if (watchlaterPlaylist == null || watchLaterCollection.getUpdatedAtTimestamp() > watchlaterPlaylist.getUpdatedAtTimestamp()) {
DatabaseHelper.saveCollection(watchLaterCollection, db);
}
}
JSONObject unpublishedCollections = Helper.getJSONObject("unpublishedCollections", value);
Iterator<String> pcIdsIterator = unpublishedCollections.keys();
while (pcIdsIterator.hasNext()) {
String collectionId = pcIdsIterator.next();
JSONObject jsonCollection = Helper.getJSONObject(collectionId, unpublishedCollections);
OdyseeCollection thisCollection = OdyseeCollection.fromJSONObject(collectionId, OdyseeCollection.VISIBILITY_PRIVATE, jsonCollection);
boolean shouldSave = true;
if (allCollections.containsKey(collectionId)) {
OdyseeCollection priorLocalCollection = allCollections.get(collectionId);
shouldSave = thisCollection.getUpdatedAtTimestamp() > priorLocalCollection.getUpdatedAtTimestamp();
}
if (shouldSave) {
DatabaseHelper.saveCollection(thisCollection, db);
}
}
subscriptions = loadSubscriptionsFromSharedUserState(shared);
if (db != null) {
for (Subscription subscription : subscriptions) {
try {
DatabaseHelper.createOrUpdateSubscription(subscription, db);
} catch (IllegalStateException ex) {
// pass
}
}
}
if (tags != null) {
if (db != null && tags.length() > 0) {
try {
DatabaseHelper.setAllTagsUnfollowed(db);
} catch (IllegalStateException ex) {
// pass
}
}
followedTags = new ArrayList<>();
for (int i = 0; i < tags.length(); i++) {
String tagName = tags.getString(i);
Tag tag = new Tag(tagName);
tag.setFollowed(true);
followedTags.add(tag);
try {
if (db != null) {
DatabaseHelper.createOrUpdateTag(tag, db);
}
} catch (SQLiteException | IllegalStateException ex) {
// pass
}
}
}
if (blocked != null) {
blockedChannels = new ArrayList<>();
if (db != null) {
for (int i = 0; i < blocked.length(); i++) {
LbryUri uri = LbryUri.tryParse(blocked.getString(i));
if (uri != null) {
blockedChannels.add(uri);
DatabaseHelper.createOrUpdateBlockedChannel(uri.getClaimId(), uri.getClaimName(), db);
}
}
}
}
}
}
return true;
} catch (ApiCallException | JSONException ex) {
// failed
error = ex;
}
return false;
}
use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.
the class MainActivity method loadSharedUserState.
private void loadSharedUserState() {
// load wallet preferences
LoadSharedUserStateTask loadTask = new LoadSharedUserStateTask(MainActivity.this, new LoadSharedUserStateTask.LoadSharedUserStateHandler() {
@Override
public void onSuccess(List<Subscription> subscriptions, List<Tag> followedTags, List<LbryUri> blockedChannels) {
if (subscriptions != null && subscriptions.size() > 0) {
// reload subscriptions if wallet fragment is FollowingFragment
// openNavFragments.get
MergeSubscriptionsTask mergeTask = new MergeSubscriptionsTask(subscriptions, initialSubscriptionMergeDone(), MainActivity.this, new MergeSubscriptionsTask.MergeSubscriptionsHandler() {
@Override
public void onSuccess(List<Subscription> subscriptions, List<Subscription> diff) {
Lbryio.subscriptions = new ArrayList<>(subscriptions);
if (!diff.isEmpty()) {
saveSharedUserState();
}
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_SUBSCRIPTION_MERGE_DONE, true).apply();
Lbryio.cacheResolvedSubscriptions.clear();
FollowingFragment f = (FollowingFragment) getSupportFragmentManager().findFragmentByTag("FOLLOWING");
if (f != null) {
f.fetchLoadedSubscriptions(true);
}
}
@Override
public void onError(Exception error) {
Log.e(TAG, String.format("merge subscriptions failed: %s", error.getMessage()), error);
}
});
mergeTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if (followedTags != null && followedTags.size() > 0) {
List<Tag> previousTags = new ArrayList<>(Lbry.followedTags);
Lbry.followedTags = new ArrayList<>(followedTags);
AllContentFragment f = (AllContentFragment) getSupportFragmentManager().findFragmentByTag("HOME");
if (f != null) {
if (!f.isSingleTagView() && f.getCurrentContentScope() == ContentScopeDialogFragment.ITEM_TAGS && !previousTags.equals(followedTags)) {
f.fetchClaimSearchContent(true);
}
}
}
if (blockedChannels != null && !blockedChannels.isEmpty()) {
if (!initialBlockedListLoaded()) {
// first time the blocked list is loaded, so we attempt to merge the entries
List<LbryUri> newBlockedChannels = new ArrayList<>(Lbryio.blockedChannels);
for (LbryUri uri : blockedChannels) {
if (!newBlockedChannels.contains(uri)) {
newBlockedChannels.add(uri);
}
}
Lbryio.blockedChannels = new ArrayList<>(newBlockedChannels);
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_BLOCKED_LIST_LOADED, true).apply();
} else {
// replace the blocked channels list entirely
Lbryio.blockedChannels = new ArrayList<>(blockedChannels);
}
}
if (!initialCollectionsLoaded()) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(MainActivity.this);
sp.edit().putBoolean(PREFERENCE_KEY_INTERNAL_INITIAL_COLLECTIONS_LOADED, true).apply();
}
}
@Override
public void onError(Exception error) {
Log.e(TAG, String.format("load shared user state failed: %s", error != null ? error.getMessage() : "no error message"), error);
}
}, Lbryio.AUTH_TOKEN);
loadTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Tag in project odysee-android by OdyseeTeam.
the class Helper method mergeKnownTags.
public static List<Tag> mergeKnownTags(List<Tag> fetchedTags) {
List<Tag> allKnownTags = getTagObjectsForTags(Predefined.DEFAULT_KNOWN_TAGS);
List<Integer> followIndexes = new ArrayList<>();
for (Tag tag : fetchedTags) {
if (!allKnownTags.contains(tag)) {
allKnownTags.add(tag);
} else if (tag.isFollowed()) {
followIndexes.add(allKnownTags.indexOf(tag));
}
}
for (int index : followIndexes) {
allKnownTags.get(index).setFollowed(true);
}
return allKnownTags;
}
Aggregations