use of com.odysee.app.MainActivity 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);
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class ChannelFragment method onPause.
public void onPause() {
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.updateMiniPlayerMargins(true);
activity.removeFetchChannelsListener(this);
}
super.onPause();
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class ChannelManagerFragment method onResume.
public void onResume() {
super.onResume();
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
LbryAnalytics.setCurrentScreen(activity, "Channel Manager", "ChannelManager");
MainActivity.suspendGlobalPlayer(context);
}
if (adapter != null && channelList != null) {
channelList.setAdapter(adapter);
}
fetchChannels();
}
use of com.odysee.app.MainActivity 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.MainActivity 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) {
}
});
}
Aggregations