use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method validateAndCheckPostComment.
private void validateAndCheckPostComment() {
String comment = Helper.getValue(inputComment.getText());
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
if (Helper.isNullOrEmpty(comment)) {
showError(getString(R.string.please_enter_comment));
return;
}
if (channel == null || Helper.isNullOrEmpty(channel.getClaimId())) {
showError(getString(R.string.please_select_channel));
return;
}
postComment();
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class ChannelCreateDialogFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View v = inflater.inflate(R.layout.channel_form_bottom_sheet, container, false);
View balanceView = v.findViewById(R.id.channel_form_balanceview);
TextInputEditText inputDeposit = v.findViewById(R.id.inline_channel_form_input_deposit);
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
Helper.setViewVisibility(balanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
}
});
TextInputEditText inputChannelName = v.findViewById(R.id.inline_channel_form_input_name);
TextView linkCancel = v.findViewById(R.id.inline_channel_form_cancel_link);
linkCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
inputChannelName.setText("");
inputDeposit.setText(R.string.min_deposit);
dismiss();
}
});
View progressView = v.findViewById(R.id.inline_channel_form_create_progress);
Button createButton = v.findViewById(R.id.inline_channel_form_create_button);
createButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
// validate deposit and channel name
String channelNameString = Helper.normalizeChannelName(Helper.getValue(inputChannelName.getText()));
Claim claimToSave = new Claim();
claimToSave.setName(channelNameString);
String channelName = claimToSave.getName().startsWith("@") ? claimToSave.getName().substring(1) : claimToSave.getName();
String depositString = Helper.getValue(inputDeposit.getText());
if ("@".equals(channelName) || Helper.isNullOrEmpty(channelName)) {
showError(getString(R.string.please_enter_channel_name));
return;
}
if (!LbryUri.isNameValid(channelName)) {
showError(getString(R.string.channel_name_invalid_characters));
return;
}
if (Helper.channelExists(channelName)) {
showError(getString(R.string.channel_name_already_created));
return;
}
double depositAmount;
try {
depositAmount = Double.parseDouble(depositString);
} catch (NumberFormatException ex) {
// pass
showError(getString(R.string.please_enter_valid_deposit));
return;
}
if (depositAmount == 0) {
String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
showError(error);
return;
}
if (Lbry.walletBalance == null || Lbry.getAvailableBalance() < depositAmount) {
showError(getString(R.string.deposit_more_than_balance));
return;
}
AccountManager am = AccountManager.get(getContext());
String authToken = am.peekAuthToken(Helper.getOdyseeAccount(am.getAccounts()), "auth_token_type");
MainActivity activity = (MainActivity) getActivity();
enableViews(inputChannelName, inputDeposit, createButton, linkCancel, false);
Helper.setViewVisibility(progressView, View.VISIBLE);
Callable<Claim> c = new ChannelCreateUpdate(claimToSave, new BigDecimal(depositString), false, authToken);
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<Claim> future = executor.submit(c);
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Claim result = future.get();
if (result != null) {
if (!BuildConfig.DEBUG) {
LogPublishTask logPublishTask = new LogPublishTask(result);
logPublishTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// channel created
Bundle bundle = new Bundle();
bundle.putString("claim_id", result.getClaimId());
bundle.putString("claim_name", result.getName());
LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
if (listener != null) {
listener.onChannelCreated(result);
}
}
});
}
}
} catch (ExecutionException ex) {
Throwable cause = ex.getCause();
if (cause instanceof ApiCallException) {
showError(cause.getMessage());
}
} catch (Exception ex) {
ex.printStackTrace();
} finally {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
Helper.setViewVisibility(progressView, View.GONE);
enableViews(inputChannelName, inputDeposit, createButton, linkCancel, true);
dismiss();
}
});
}
}
}
});
t.start();
}
});
Helper.setViewText((TextView) balanceView, Helper.shortCurrencyFormat(Lbry.getAvailableBalance()));
return v;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method checkRewardsDriver.
private void checkRewardsDriver() {
Context ctx = getContext();
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (ctx != null && actualClaim != null && !actualClaim.isFree() && actualClaim.getFile() == null) {
String rewardsDriverText = getString(R.string.earn_some_credits_to_access);
checkRewardsDriverCard(rewardsDriverText, actualClaim.getActualCost(Lbryio.LBCUSDRate).doubleValue());
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FollowingFragment 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);
claims = Helper.filterClaimsByBlockedChannels(claims, Lbryio.blockedChannels);
Date d = new Date();
Calendar cal = new GregorianCalendar();
cal.setTime(d);
// Remove claims with a release time in the future
claims.removeIf(e -> {
Claim.GenericMetadata metadata = e.getValue();
return metadata instanceof Claim.StreamMetadata && (((Claim.StreamMetadata) metadata).getReleaseTime()) > (cal.getTimeInMillis() / 1000L);
});
// Sort claims so those which are livestreaming now are shwon on the top of the list
Collections.sort(claims, new Comparator<Claim>() {
@Override
public int compare(Claim claim, Claim t1) {
if (claim.isLive() && !t1.isLive())
return -1;
else if (!claim.isLive() && t1.isLive())
return 1;
else
return 0;
}
});
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(false);
}
@Override
public void onError(Exception error) {
contentClaimSearchLoading = false;
checkNoContent(false);
}
});
contentClaimSearchTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FollowingFragment method fetchAndResolveChannelList.
private void fetchAndResolveChannelList() {
buildChannelIdsAndUrls();
if (!channelIds.isEmpty()) {
ResolveTask resolveSubscribedTask = new ResolveTask(channelUrls, Lbry.API_CONNECTION_STRING, channelListLoading, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
updateChannelFilterListAdapter(claims, true);
Lbryio.cacheResolvedSubscriptions = claims;
}
@Override
public void onError(Exception error) {
handler.postDelayed(FollowingFragment.this::fetchAndResolveChannelList, 5_000);
}
});
resolveSubscribedTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
fetchClaimSearchContent();
}
}
Aggregations