use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method logFileView.
private void logFileView(String url, long timeToStart) {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null) {
String authToken = Lbryio.AUTH_TOKEN;
Map<String, String> options = new HashMap<>();
options.put("uri", url);
options.put("claim_id", actualClaim.getClaimId());
options.put("outpoint", String.format("%s:%d", actualClaim.getTxid(), actualClaim.getNout()));
if (timeToStart > 0) {
options.put("time_to_start", String.valueOf(timeToStart));
}
if (!Helper.isNullOrEmpty(authToken)) {
options.put("auth_token", authToken);
}
Activity activity = getActivity();
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.M) {
Supplier<Boolean> s = new Supplier<Boolean>() {
@Override
public Boolean get() {
try {
Lbryio.call("file", "view", options, null).close();
return true;
} catch (LbryioRequestException | LbryioResponseException ex) {
return false;
}
}
};
CompletableFuture<Boolean> cf = CompletableFuture.supplyAsync(s);
cf.whenComplete((result, ex) -> {
if (result) {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
claimEligibleRewards();
}
});
}
if (ex != null) {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((MainActivity) activity).showError(ex.getMessage());
}
});
}
}
}
});
} else {
Thread t = new Thread(new Runnable() {
@Override
public void run() {
try {
Lbryio.call("file", "view", options, null).close();
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
claimEligibleRewards();
}
});
}
} catch (LbryioRequestException | LbryioResponseException ex) {
if (activity != null) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
((MainActivity) activity).showError(ex.getMessage());
}
});
}
}
}
});
t.start();
}
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method loadRelatedContent.
private void loadRelatedContent() {
// reset the list view
View root = getView();
if (fileClaim != null && root != null) {
Context context = getContext();
List<Claim> loadingPlaceholders = new ArrayList<>();
int loadingPlaceholdersLength = Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) ? fileClaim.getClaimIds().size() : 15;
for (int i = 0; i < loadingPlaceholdersLength; i++) {
Claim placeholder = new Claim();
placeholder.setLoadingPlaceholder(true);
loadingPlaceholders.add(placeholder);
}
relatedContentAdapter = new ClaimListAdapter(loadingPlaceholders, context);
relatedContentAdapter.setContextGroupId(FILE_CONTEXT_GROUP_ID);
RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list);
relatedContentList.setAdapter(relatedContentAdapter);
ProgressBar relatedLoading = root.findViewById(R.id.file_view_related_content_progress);
boolean canShowMatureContent = false;
if (context != null) {
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
}
if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType())) {
String title = fileClaim.getTitle();
String claimId = fileClaim.getClaimId();
final boolean nsfw = canShowMatureContent;
relatedLoading.setVisibility(View.VISIBLE);
// Making a request which explicitly uses a certain value form the amount of results needed
// and no processing any possible exception, so using a callable instead of an AsyncTask
// makes sense for all Android API Levels
Thread t = new Thread(new Runnable() {
@Override
public void run() {
ExecutorService executor = Executors.newSingleThreadExecutor();
LighthouseSearch callable = new LighthouseSearch(title, RELATED_CONTENT_SIZE, 0, nsfw, claimId);
Future<List<Claim>> future = executor.submit(callable);
try {
List<Claim> result = future.get();
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
}
MainActivity a = (MainActivity) getActivity();
if (a != null) {
a.runOnUiThread(new Runnable() {
@Override
public void run() {
relatedContentRequestSuccedded(result);
relatedLoading.setVisibility(View.GONE);
}
});
}
} catch (InterruptedException | ExecutionException e) {
if (executor != null && !executor.isShutdown()) {
executor.shutdown();
}
e.printStackTrace();
}
}
});
t.start();
} else {
TextView relatedOrPlayList = root.findViewById(R.id.related_or_playlist);
relatedOrPlayList.setText(fileClaim.getTitle());
relatedOrPlayList.setCompoundDrawablesRelativeWithIntrinsicBounds(R.drawable.ic_cast_connected, 0, 0, 0);
relatedOrPlayList.setPadding(0, 0, 0, 16);
relatedOrPlayList.setTypeface(null, Typeface.BOLD);
Map<String, Object> claimSearchOptions = new HashMap<>(3);
claimSearchOptions.put("claim_ids", fileClaim.getClaimIds());
claimSearchOptions.put("not_tags", canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS));
claimSearchOptions.put("page_size", fileClaim.getClaimIds().size());
ExecutorService executor = Executors.newSingleThreadExecutor();
Future<List<Claim>> future = executor.submit(new Search(claimSearchOptions));
try {
List<Claim> playlistClaimItems = future.get();
if (playlistClaimItems != null) {
relatedContentAdapter.setItems(playlistClaimItems);
relatedContentAdapter.setListener(FileViewFragment.this);
View v = getView();
if (v != null) {
relatedContentList.setAdapter(relatedContentAdapter);
relatedContentAdapter.notifyDataSetChanged();
Helper.setViewVisibility(v.findViewById(R.id.file_view_no_related_content), relatedContentAdapter == null || relatedContentAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
}
scrollToCommentHash();
}
} catch (InterruptedException | ExecutionException e) {
e.printStackTrace();
}
}
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method resolveUrl.
private void resolveUrl(String url) {
// resolving = true;
Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
ResolveTask task = new ResolveTask(url, Lbry.API_CONNECTION_STRING, layoutResolving, new ClaimListResultHandler() {
@Override
public void onSuccess(List<Claim> claims) {
if (!claims.isEmpty() && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
fileClaim = claims.get(0);
if (Claim.TYPE_REPOST.equalsIgnoreCase(fileClaim.getValueType())) {
fileClaim = fileClaim.getRepostedClaim();
// cache the reposted claim too for subsequent loads
Lbry.addClaimToCache(fileClaim);
if (fileClaim.getName().startsWith("@")) {
// this is a reposted channel, so finish this activity and launch the channel url
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.getSupportFragmentManager().popBackStack();
activity.openChannelUrl(!Helper.isNullOrEmpty(fileClaim.getShortUrl()) ? fileClaim.getShortUrl() : fileClaim.getPermanentUrl());
}
return;
}
} else {
Lbry.addClaimToCache(fileClaim);
}
if (Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getValueType()) && fileClaim.getClaimIds() != null && fileClaim.getClaimIds().size() > 0) {
collectionClaimItem = null;
}
Helper.saveUrlHistory(url, fileClaim.getTitle(), UrlSuggestion.TYPE_FILE);
// do not save collections to view history
if (!Claim.TYPE_COLLECTION.equalsIgnoreCase(fileClaim.getType())) {
// also save view history
Helper.saveViewHistory(url, fileClaim);
}
checkAndResetNowPlayingClaim();
if (Helper.isClaimBlocked(fileClaim)) {
renderClaimBlocked();
} else {
loadFile();
checkAndLoadRelatedContent();
checkAndLoadComments();
renderClaim();
}
} else {
// render nothing at location
renderNothingAtLocation();
}
}
@Override
public void onError(Exception error) {
// resolving = false;
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method onStart.
@Override
public void onStart() {
super.onStart();
Context context = getContext();
if (context instanceof MainActivity) {
MainActivity activity = (MainActivity) context;
activity.hideToolbar();
activity.setBackPressInterceptor(this);
activity.addDownloadActionListener(this);
activity.addFetchClaimsListener(this);
activity.addPIPModeListener(this);
activity.addScreenOrientationListener(this);
if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
activity.addStoragePermissionListener(this);
}
}
}
use of com.odysee.app.MainActivity in project odysee-android by OdyseeTeam.
the class FileViewFragment method deleteCurrentClaim.
private void deleteCurrentClaim() {
Claim actualClaim = collectionClaimItem != null ? collectionClaimItem : fileClaim;
if (actualClaim != null) {
Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
Helper.setViewVisibility(layoutNothingAtLocation, View.GONE);
AbandonStreamTask task = new AbandonStreamTask(Arrays.asList(actualClaim.getClaimId()), layoutResolving, new AbandonHandler() {
@Override
public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
Context context = getContext();
if (context instanceof MainActivity) {
if (failedClaimIds.size() == 0) {
MainActivity activity = (MainActivity) context;
activity.showMessage(R.string.content_deleted);
activity.onBackPressed();
} else {
showError(getString(R.string.content_failed_delete));
}
}
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
}
}
Aggregations