use of com.odysee.app.tasks.lbryinc.LogPublishTask in project odysee-android by OdyseeTeam.
the class PublishFormFragment method publishClaim.
private void publishClaim(Claim claim) {
String finalFilePath = transcodedFilePath;
if (Helper.isNullOrEmpty(finalFilePath)) {
finalFilePath = currentGalleryItem != null ? currentGalleryItem.getFilePath() : currentFilePath;
}
saveInProgress = true;
PublishClaimTask task = new PublishClaimTask(claim, finalFilePath, progressPublish, new ClaimResultHandler() {
@Override
public void beforeStart() {
preSave();
}
@Override
public void onSuccess(Claim claimResult) {
postSave();
// Run the logPublish task
if (!BuildConfig.DEBUG) {
claimResult.setSigningChannel(claim.getSigningChannel());
LogPublishTask logPublish = new LogPublishTask(claimResult);
logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// publish done
Bundle bundle = new Bundle();
bundle.putString("claim_id", claimResult.getClaimId());
bundle.putString("claim_name", claimResult.getName());
LbryAnalytics.logEvent(editMode ? LbryAnalytics.EVENT_PUBLISH_UPDATE : LbryAnalytics.EVENT_PUBLISH, bundle);
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.showMessage(R.string.publish_successful);
activity.sendBroadcast(new Intent(MainActivity.ACTION_PUBLISH_SUCCESSFUL));
}
}
@Override
public void onError(Exception error) {
showError(error.getMessage());
postSave();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.tasks.lbryinc.LogPublishTask in project odysee-android by OdyseeTeam.
the class ChannelCommentsFragment method setupInlineChannelCreator.
private void setupInlineChannelCreator(View container, TextInputEditText inputChannelName, TextInputEditText inputDeposit, View inlineBalanceView, TextView inlineBalanceValue, View linkCancel, MaterialButton buttonCreate, View progressView, AppCompatSpinner channelSpinner, InlineChannelSpinnerAdapter channelSpinnerAdapter) {
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
@Override
public void onFocusChange(View view, boolean hasFocus) {
Helper.setViewVisibility(inlineBalanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
}
});
linkCancel.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Helper.setViewText(inputChannelName, null);
Helper.setViewText(inputDeposit, null);
Helper.setViewVisibility(container, View.GONE);
}
});
buttonCreate.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 = 0;
try {
depositAmount = Double.valueOf(depositString);
} catch (NumberFormatException ex) {
// pass
showError(getString(R.string.please_enter_valid_deposit));
return;
}
if (depositAmount <= 0.000001) {
String error = getResources().getQuantityString(R.plurals.min_deposit_required, Math.abs(depositAmount - 1.0) <= 0.000001 ? 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;
}
ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(claimToSave, new BigDecimal(depositString), false, progressView, Lbryio.AUTH_TOKEN, new ClaimResultHandler() {
@Override
public void beforeStart() {
Helper.setViewEnabled(inputChannelName, false);
Helper.setViewEnabled(inputDeposit, false);
Helper.setViewEnabled(buttonCreate, false);
Helper.setViewEnabled(linkCancel, false);
}
@Override
public void onSuccess(Claim claimResult) {
if (!BuildConfig.DEBUG) {
LogPublishTask logPublishTask = new LogPublishTask(claimResult);
logPublishTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
// channel created
Bundle bundle = new Bundle();
bundle.putString("claim_id", claimResult.getClaimId());
bundle.putString("claim_name", claimResult.getName());
LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
// add the claim to the channel list and set it as the selected item
if (channelSpinnerAdapter != null) {
channelSpinnerAdapter.add(claimResult);
}
if (channelSpinner != null && channelSpinnerAdapter != null) {
channelSpinner.setSelection(channelSpinnerAdapter.getCount() - 1);
}
Helper.setViewEnabled(inputChannelName, true);
Helper.setViewEnabled(inputDeposit, true);
Helper.setViewEnabled(buttonCreate, true);
Helper.setViewEnabled(linkCancel, true);
}
@Override
public void onError(Exception error) {
Helper.setViewEnabled(inputChannelName, true);
Helper.setViewEnabled(inputDeposit, true);
Helper.setViewEnabled(buttonCreate, true);
Helper.setViewEnabled(linkCancel, true);
showError(error.getMessage());
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
});
Helper.setViewText(inlineBalanceValue, Helper.shortCurrencyFormat(Lbry.getAvailableBalance()));
}
use of com.odysee.app.tasks.lbryinc.LogPublishTask 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.tasks.lbryinc.LogPublishTask in project odysee-android by OdyseeTeam.
the class ChannelFormFragment method validateAndSaveClaim.
private void validateAndSaveClaim(Claim claim) {
if (!editMode && Helper.isNullOrEmpty(claim.getName())) {
showError(getString(R.string.please_enter_channel_name));
return;
}
String channelName = claim.getName().startsWith("@") ? claim.getName().substring(1) : claim.getName();
if (!LbryUri.isNameValid(channelName)) {
showError(getString(R.string.channel_name_invalid_characters));
return;
}
if (!editMode) {
if (Helper.channelExists(channelName)) {
showError(getString(R.string.channel_name_already_created));
return;
}
}
String depositString = Helper.getValue(inputDeposit.getText());
double depositAmount = 0;
try {
depositAmount = Double.parseDouble(depositString);
} catch (NumberFormatException ex) {
// pass
showError(getString(R.string.please_enter_valid_deposit));
return;
}
if (depositAmount < Helper.MIN_DEPOSIT) {
String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
showError(error);
return;
}
if (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");
ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(claim, new BigDecimal(depositString), editMode, channelSaveProgress, authToken, new ClaimResultHandler() {
@Override
public void beforeStart() {
preSave();
}
@Override
public void onSuccess(Claim claimResult) {
postSave();
// Run the logPublish task
if (!BuildConfig.DEBUG) {
LogPublishTask logPublish = new LogPublishTask(claimResult);
logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
if (!editMode) {
// channel created
Bundle bundle = new Bundle();
bundle.putString("claim_id", claimResult.getClaimId());
bundle.putString("claim_name", claimResult.getName());
LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
}
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.showMessage(R.string.channel_save_successful);
activity.onBackPressed();
}
}
@Override
public void onError(Exception error) {
showError(error != null ? error.getMessage() : getString(R.string.channel_save_failed));
postSave();
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
Aggregations