use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelManagerFragment method fetchChannels.
private void fetchChannels() {
Helper.setViewVisibility(emptyView, View.GONE);
AccountManager am = AccountManager.get(getContext());
Account odyseeAccount = Helper.getOdyseeAccount(am.getAccounts());
String authToken = am.peekAuthToken(odyseeAccount, "auth_token_type");
MainActivity activity = (MainActivity) getActivity();
final View progressView = getLoading();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
progressView.setVisibility(View.VISIBLE);
Supplier<List<Claim>> s = new ClaimListSupplier(Collections.singletonList(Claim.TYPE_CHANNEL), authToken);
CompletableFuture<List<Claim>> cf = CompletableFuture.supplyAsync(s);
cf.whenComplete((result, e) -> {
if (e != null && activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Throwable t = e.getCause();
if (t != null) {
activity.showError(t.getMessage());
}
}
});
}
if (result != null && activity != null) {
activity.runOnUiThread(new Runnable() {
public void run() {
Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(result));
if (adapter == null) {
Context context = getContext();
if (context != null) {
adapter = new ClaimListAdapter(result, context);
adapter.setCanEnterSelectionMode(true);
adapter.setSelectionModeListener(ChannelManagerFragment.this);
adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
if (context instanceof MainActivity) {
((MainActivity) context).openChannelClaim(claim);
}
}
});
if (channelList != null) {
channelList.setAdapter(adapter);
}
}
} else {
adapter.setItems(result);
}
checkNoChannels();
}
});
}
if (activity != null)
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
progressView.setVisibility(View.GONE);
}
});
});
} else {
ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, getLoading(), Lbryio.AUTH_TOKEN, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(claims));
if (adapter == null) {
Context context = getContext();
if (context != null) {
adapter = new ClaimListAdapter(claims, context);
adapter.setCanEnterSelectionMode(true);
adapter.setSelectionModeListener(ChannelManagerFragment.this);
adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
if (context instanceof MainActivity) {
((MainActivity) context).openChannelClaim(claim);
}
}
});
if (channelList != null) {
channelList.setAdapter(adapter);
}
}
} else {
adapter.setItems(claims);
}
checkNoChannels();
}
@Override
public void onError(Exception error) {
checkNoChannels();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method initCommentForm.
private void initCommentForm(View root) {
MainActivity activity = (MainActivity) getActivity();
if (activity != null) {
activity.refreshChannelCreationRequired(root);
}
textCommentLimit.setText(String.format("%d / %d", Helper.getValue(inputComment.getText()).length(), Comment.MAX_LENGTH));
buttonUserSignedInRequired.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
MainActivity activity = (MainActivity) getActivity();
if (activity != null) {
activity.simpleSignIn(0);
}
}
});
buttonClearReplyToComment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clearReplyToComment();
}
});
buttonPostComment.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
validateAndCheckPostComment();
}
});
buttonCreateChannel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (!fetchingChannels) {
showChannelCreator();
}
}
});
inputComment.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
int len = charSequence.length();
textCommentLimit.setText(String.format("%d / %d", len, Comment.MAX_LENGTH));
}
@Override
public void afterTextChanged(Editable editable) {
}
});
commentChannelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
Object item = adapterView.getItemAtPosition(position);
if (item instanceof Claim) {
Claim claim = (Claim) item;
if (claim.isPlaceholder()) {
if (!fetchingChannels) {
showChannelCreator();
if (commentChannelSpinnerAdapter.getCount() > 1) {
commentChannelSpinner.setSelection(commentChannelSpinnerAdapter.getCount() - 1);
}
}
} else {
updatePostAsChannel(claim);
}
}
}
@Override
public void onNothingSelected(AdapterView<?> adapterView) {
}
});
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelContentFragment method fetchClaimSearchContent.
private void fetchClaimSearchContent(boolean reset) {
if (reset && contentListAdapter != null) {
contentListAdapter.clearItems();
currentClaimSearchPage = 1;
}
contentClaimSearchLoading = true;
Helper.setViewVisibility(noContentView, View.GONE);
Map<String, Object> claimSearchOptions = buildContentOptions();
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.API_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
@Override
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
claims = Helper.filterClaimsByOutpoint(claims);
if (contentListAdapter == null) {
Context context = getContext();
if (context != null) {
contentListAdapter = new ClaimListAdapter(claims, context);
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
if (claim.getName().startsWith("@")) {
// channel claim
activity.openChannelClaim(claim);
} else {
activity.openFileClaim(claim);
}
}
}
});
}
} else {
contentListAdapter.addItems(claims);
}
if (contentList != null && contentList.getAdapter() == null) {
contentList.setAdapter(contentListAdapter);
}
contentHasReachedEnd = hasReachedEnd;
contentClaimSearchLoading = false;
checkNoContent();
}
@Override
public void onError(Exception error) {
contentClaimSearchLoading = false;
checkNoContent();
}
});
contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelFormFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_channel_form, container, false);
scrollView = root.findViewById(R.id.channel_form_scroll_view);
linkCancel = root.findViewById(R.id.channel_form_cancel_link);
linkShowOptional = root.findViewById(R.id.channel_form_toggle_optional);
buttonSave = root.findViewById(R.id.channel_form_save_button);
containerOptionalFields = root.findViewById(R.id.channel_form_optional_fields_container);
inputTitle = root.findViewById(R.id.channel_form_input_title);
inputChannelName = root.findViewById(R.id.channel_form_input_channel_name);
inputDeposit = root.findViewById(R.id.channel_form_input_deposit);
inputDescription = root.findViewById(R.id.channel_form_input_description);
inputWebsite = root.findViewById(R.id.channel_form_input_website);
inputEmail = root.findViewById(R.id.channel_form_input_email);
inputTagFilter = root.findViewById(R.id.form_tag_filter_input);
coverEditArea = root.findViewById(R.id.channel_form_cover_edit_area);
iconContainer = root.findViewById(R.id.channel_form_icon_container);
imageCover = root.findViewById(R.id.channel_form_cover_image);
imageThumbnail = root.findViewById(R.id.channel_form_thumbnail);
balanceView = root.findViewById(R.id.channel_form_balance);
uploadProgress = root.findViewById(R.id.channel_form_upload_progress);
channelSaveProgress = root.findViewById(R.id.channel_form_save_progress);
Context context = getContext();
FlexboxLayoutManager flm1 = new FlexboxLayoutManager(context);
FlexboxLayoutManager flm2 = new FlexboxLayoutManager(context);
addedTagsList = root.findViewById(R.id.form_added_tags);
addedTagsList.setLayoutManager(flm1);
suggestedTagsList = root.findViewById(R.id.form_suggested_tags);
suggestedTagsList.setLayoutManager(flm2);
addedTagsAdapter = new TagListAdapter(new ArrayList<>(), context);
addedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_REMOVE);
addedTagsAdapter.setClickListener(this);
addedTagsList.setAdapter(addedTagsAdapter);
suggestedTagsAdapter = new TagListAdapter(new ArrayList<>(), getContext());
suggestedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
suggestedTagsAdapter.setClickListener(this);
suggestedTagsList.setAdapter(suggestedTagsAdapter);
noTagsView = root.findViewById(R.id.form_no_added_tags);
noTagResultsView = root.findViewById(R.id.form_no_tag_results);
buttonSave = root.findViewById(R.id.channel_form_save_button);
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
Helper.setViewVisibility(balanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
}
});
linkShowOptional.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (containerOptionalFields.getVisibility() != View.VISIBLE) {
containerOptionalFields.setVisibility(View.VISIBLE);
linkShowOptional.setText(R.string.hide_optional_fields);
scrollView.post(new Runnable() {
@Override
public void run() {
scrollView.fullScroll(NestedScrollView.FOCUS_DOWN);
}
});
} else {
containerOptionalFields.setVisibility(View.GONE);
linkShowOptional.setText(R.string.show_optional_fields);
}
}
});
linkCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
clearInputFocus();
Context context = getContext();
if (context instanceof MainActivity) {
((MainActivity) context).onBackPressed();
}
}
});
coverEditArea.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (uploading) {
Snackbar.make(getView(), R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
return;
}
checkPermissionsAndLaunchFilePicker(true);
}
});
iconContainer.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (uploading) {
Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
return;
}
checkPermissionsAndLaunchFilePicker(false);
}
});
buttonSave.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (uploading) {
Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
return;
}
Claim claimToSave = buildChannelClaimToSave();
validateAndSaveClaim(claimToSave);
}
});
inputTagFilter.addTextChangedListener(new TextWatcher() {
@Override
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
}
@Override
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
String value = Helper.getValue(charSequence);
setFilter(value);
}
@Override
public void afterTextChanged(Editable editable) {
}
});
return root;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method ensureCommentListAdapterCreated.
private void ensureCommentListAdapterCreated(final List<Comment> comments) {
if (commentListAdapter == null) {
Context ctx = getContext();
View root = getView();
commentListAdapter = new CommentListAdapter(comments, ctx, claim, new CommentListAdapter.CommentListListener() {
@Override
public void onListChanged() {
checkNoComments();
}
@Override
public void onCommentReactClicked(Comment c, boolean liked) {
// Not used for now.
}
@Override
public void onReplyClicked(Comment comment) {
setReplyToComment(comment);
}
});
commentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
@Override
public void onClaimClicked(Claim claim, int position) {
if (!Helper.isNullOrEmpty(claim.getName()) && claim.getName().startsWith("@") && ctx instanceof MainActivity) {
((MainActivity) ctx).openChannelClaim(claim);
}
}
});
RecyclerView commentList = root.findViewById(R.id.channel_comments_list);
int marginInPx = Math.round(40 * ((float) ctx.getResources().getDisplayMetrics().densityDpi / DisplayMetrics.DENSITY_DEFAULT));
commentList.addItemDecoration(new CommentItemDecoration(marginInPx));
commentList.setAdapter(commentListAdapter);
commentListAdapter.notifyItemRangeInserted(0, comments.size());
commentListAdapter.setCollapsed(false);
checkNoComments();
resolveCommentPosters();
scrollToCommentHash();
}
}
Aggregations