use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method onCreateView.
@Override
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View root = inflater.inflate(R.layout.fragment_file_view, container, false);
layoutLoadingState = root.findViewById(R.id.file_view_loading_state);
layoutNothingAtLocation = root.findViewById(R.id.container_nothing_at_location);
layoutResolving = root.findViewById(R.id.file_view_loading_container);
layoutDisplayArea = root.findViewById(R.id.file_view_claim_display_area);
buttonPublishSomething = root.findViewById(R.id.nothing_at_location_publish_button);
tipButton = root.findViewById(R.id.file_view_action_tip);
expandButton = root.findViewById(R.id.expand_commentarea_button);
singleCommentRoot = root.findViewById(R.id.collapsed_comment);
relatedContentTitle = root.findViewById(R.id.related_or_playlist);
containerCommentForm = root.findViewById(R.id.container_comment_form);
containerReplyToComment = root.findViewById(R.id.comment_form_reply_to_container);
textReplyingTo = root.findViewById(R.id.comment_form_replying_to_text);
textReplyToBody = root.findViewById(R.id.comment_form_reply_to_body);
buttonClearReplyToComment = root.findViewById(R.id.comment_form_clear_reply_to);
commentChannelSpinner = root.findViewById(R.id.comment_form_channel_spinner);
progressLoadingChannels = root.findViewById(R.id.comment_form_channels_loading);
progressPostComment = root.findViewById(R.id.comment_form_post_progress);
inputComment = root.findViewById(R.id.comment_form_body);
textCommentLimit = root.findViewById(R.id.comment_form_text_limit);
buttonPostComment = root.findViewById(R.id.comment_form_post);
buttonCreateChannel = root.findViewById(R.id.create_channel_button);
commentPostAsThumbnail = root.findViewById(R.id.comment_form_thumbnail);
commentPostAsNoThumbnail = root.findViewById(R.id.comment_form_no_thumbnail);
commentPostAsAlpha = root.findViewById(R.id.comment_form_thumbnail_alpha);
buttonCommentSignedInUserRequired = root.findViewById(R.id.sign_in_user_button);
textNothingAtLocation = root.findViewById(R.id.nothing_at_location_text);
commentLoadingArea = root.findViewById(R.id.file_comments_loading);
likeReactionAmount = root.findViewById(R.id.likes_amount);
dislikeReactionAmount = root.findViewById(R.id.dislikes_amount);
likeReactionIcon = root.findViewById(R.id.like_icon);
dislikeReactionIcon = root.findViewById(R.id.dislike_icon);
initUi(root);
fileViewPlayerListener = new Player.Listener() {
@Override
public void onPlaybackStateChanged(@Player.State int playbackState) {
if (playbackState == Player.STATE_READY) {
elapsedDuration = MainActivity.appPlayer.getCurrentPosition();
totalDuration = MainActivity.appPlayer.getDuration() < 0 ? 0 : MainActivity.appPlayer.getDuration();
if (!playbackStarted) {
logPlay(currentUrl, startTimeMillis);
playbackStarted = true;
long lastPosition = loadLastPlaybackPosition();
if (lastPosition > -1) {
MainActivity.appPlayer.seekTo(lastPosition);
}
}
renderTotalDuration();
scheduleElapsedPlayback();
hideBuffering();
if (loadingNewClaim) {
setPlaybackSpeedToDefault();
setPlayerQualityToDefault();
MainActivity.appPlayer.setPlayWhenReady(true);
loadingNewClaim = false;
}
} else if (playbackState == Player.STATE_BUFFERING) {
if (!loadingQualityChanged) {
Context ctx = getContext();
boolean sendBufferingEvents = true;
if (ctx != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(ctx);
sendBufferingEvents = sp.getBoolean(MainActivity.PREFERENCE_KEY_SEND_BUFFERING_EVENTS, true);
}
if (MainActivity.appPlayer != null && MainActivity.appPlayer.getCurrentPosition() > 0 && sendBufferingEvents) {
// we only want to log a buffer event after the media has already started playing
if (!Helper.isNullOrEmpty(currentMediaSourceUrl)) {
long duration = MainActivity.appPlayer.getDuration();
long position = MainActivity.appPlayer.getCurrentPosition();
String userIdHash = Lbryio.currentUser != null ? String.valueOf(Lbryio.currentUser.getId()) : "0";
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
BufferEventTask bufferEvent = new BufferEventTask(actualClaim.getPermanentUrl(), duration, position, 1, userIdHash);
bufferEvent.executeOnExecutor(AsyncTask.SERIAL_EXECUTOR);
}
}
}
loadingQualityChanged = false;
showBuffering();
} else if (playbackState == Player.STATE_ENDED) {
playNextItemInPlaylist();
} else {
hideBuffering();
}
}
@Override
public void onIsPlayingChanged(boolean isPlayng) {
isPlaying = isPlayng;
}
};
scrollView = root.findViewById(R.id.file_view_scroll_view);
return root;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method getLivestreamUrl.
/**
* @return The URL to connect to get the video stream, usually a .M3U8
*/
@AnyThread
private String getLivestreamUrl() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Supplier<JSONObject> task = new Supplier<JSONObject>() {
@Override
public JSONObject get() {
return getLivestreamData(actualClaim);
}
};
CompletableFuture<JSONObject> completableFuture = CompletableFuture.supplyAsync(task);
CompletableFuture<String> cf = completableFuture.thenApply(jsonData -> getLivestreamUrl(jsonData));
try {
return cf.get();
} catch (ExecutionException | InterruptedException e) {
e.printStackTrace();
}
} else {
ExecutorService executor = Executors.newSingleThreadExecutor();
Callable<JSONObject> callable = () -> getLivestreamData(actualClaim);
Future<JSONObject> future = executor.submit(callable);
for (; ; ) {
if (future.isDone()) {
try {
JSONObject jsonData = future.get();
return getLivestreamUrl(jsonData);
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}
return null;
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method checkIsFileComplete.
private void checkIsFileComplete() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim == null) {
return;
}
View root = getView();
if (root != null) {
if (actualClaim.getFile() != null && actualClaim.getFile().isCompleted()) {
Helper.setViewVisibility(root.findViewById(R.id.file_view_action_delete), View.VISIBLE);
Helper.setViewVisibility(root.findViewById(R.id.file_view_action_download), View.GONE);
} else {
Helper.setViewVisibility(root.findViewById(R.id.file_view_action_delete), View.GONE);
// Helper.setViewVisibility(root.findViewById(R.id.file_view_action_download), View.VISIBLE);
}
}
}
use of com.odysee.app.model.Claim in project odysee-android by OdyseeTeam.
the class FileViewFragment method loadFile.
private void loadFile() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
String claimId = actualClaim.getClaimId();
FileListTask task = new FileListTask(claimId, null, new FileListTask.FileListResultHandler() {
@Override
public void onSuccess(List<LbryFile> files, boolean hasReachedEnd) {
if (files.size() > 0) {
actualClaim.setFile(files.get(0));
checkIsFileComplete();
if (!actualClaim.isPlayable() && !actualClaim.isViewable()) {
showUnsupportedView();
}
} else {
if (!actualClaim.isPlayable() && !actualClaim.isViewable()) {
restoreMainActionButton();
}
}
// initialFileLoadDone = true;
}
@Override
public void onError(Exception error) {
// initialFileLoadDone = true;
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.model.Claim 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