From 3f5104d60a47b42d6d12b76d58e3a4d3c34756d5 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 29 Mar 2021 17:38:51 +0200 Subject: [PATCH 1/7] Hide floating wallet on the Channel fragment (#1177) * Hide floating wallet on the Channel fragment * Unregister OnPageChangeCallback when exiting channel fragment --- .../browser/ui/channel/ChannelFragment.java | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java index c10ff3a0..5b731283 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelFragment.java @@ -73,6 +73,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen private TextView textFollowerCount; private TabLayout tabLayout; private ViewPager2 tabPager; + ViewPager2.OnPageChangeCallback opcc; private View buttonEdit; private View buttonDelete; @@ -91,6 +92,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen // if this is set, scroll to the specific comment on load private String commentHash; + private float floatingWalletPositionY; + public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View root = inflater.inflate(R.layout.fragment_channel, container, false); @@ -122,6 +125,25 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen tabLayout = root.findViewById(R.id.channel_view_tabs); tabPager.setSaveEnabled(false); + View floatingBalance = getActivity().findViewById(R.id.floating_balance_main_container); + floatingWalletPositionY = floatingBalance.getY(); + + opcc = new ViewPager2.OnPageChangeCallback() { + @Override + public void onPageSelected(int position) { + super.onPageSelected(position); + + if (position > 0) { + // Hide floating wallet for the About and the Comment tabs as they are mostly text + ((MainActivity) getContext()).translateFloatingWallet(floatingWalletPositionY); + } else { + ((MainActivity) getContext()).restoreWalletContainerPosition(); + } + } + }; + + tabPager.registerOnPageChangeCallback(opcc); + buttonEdit.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { @@ -380,6 +402,15 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen super.onPause(); } + public void onStop() { + Context context = getContext(); + if (context instanceof MainActivity) { + ((MainActivity) context ).restoreWalletContainerPosition(); + } + tabPager.unregisterOnPageChangeCallback(opcc); + super.onStop(); + } + private void checkParams() { boolean updateRequired = false; Map params = getParams(); -- 2.45.3 From 6e32f7724fbba901b16b60b32fa0286eb9444fc4 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 29 Mar 2021 17:39:27 +0200 Subject: [PATCH 2/7] Notification improvements (#1175) * Stop showing notification list when going from notification's content to related content * Add is_app_readable parameter to notification_list call * Return current fragment on main activity --- .../java/io/lbry/browser/MainActivity.java | 22 +++++++++++-------- .../tasks/lbryinc/NotificationListTask.java | 6 ++++- .../java/io/lbry/browser/ui/BaseFragment.java | 2 +- 3 files changed, 19 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 82fdcbfd..1c11f762 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -2781,15 +2781,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener } private Fragment getCurrentFragment() { - int backCount = getSupportFragmentManager().getBackStackEntryCount(); - if (backCount > 0) { - try { - return getSupportFragmentManager().getFragments().get(backCount - 1); - } catch (IndexOutOfBoundsException ex) { - return null; - } - } - return null; + return getSupportFragmentManager().findFragmentById(R.id.content_main); } public void hideActionBar() { @@ -3495,6 +3487,18 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener return; } + if (currentFragment != null && ((BaseFragment) currentFragment).getParams() != null + && ((BaseFragment) currentFragment).getParams().containsKey("source") + && ((BaseFragment) currentFragment).getParams().get("source").equals("notification")) { + + Map currentParams = new HashMap<>(1); + + if (((BaseFragment) currentFragment).getParams().containsKey("url")) + currentParams.put("url", ((BaseFragment) currentFragment).getParams().get("url")); + + ((BaseFragment) currentFragment).setParams(currentParams); + } + //fragment.setRetainInstance(true); FragmentManager manager = getSupportFragmentManager(); FragmentTransaction transaction = manager.beginTransaction().replace(R.id.content_main, fragment); diff --git a/app/src/main/java/io/lbry/browser/tasks/lbryinc/NotificationListTask.java b/app/src/main/java/io/lbry/browser/tasks/lbryinc/NotificationListTask.java index be8c64f6..69722037 100644 --- a/app/src/main/java/io/lbry/browser/tasks/lbryinc/NotificationListTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/lbryinc/NotificationListTask.java @@ -16,8 +16,10 @@ import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; import java.util.List; import java.util.Locale; +import java.util.Map; import io.lbry.browser.MainActivity; import io.lbry.browser.data.DatabaseHelper; @@ -47,7 +49,9 @@ public class NotificationListTask extends AsyncTask notifications = new ArrayList<>(); SQLiteDatabase db = null; try { - JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("notification", "list", context)); + Map parameters = new HashMap<>(1); + parameters.put("is_app_readable", "true"); + JSONArray array = (JSONArray) Lbryio.parseResponse(Lbryio.call("notification", "list", parameters, context)); if (array != null) { for (int i = 0; i < array.length(); i++) { JSONObject item = array.getJSONObject(i); diff --git a/app/src/main/java/io/lbry/browser/ui/BaseFragment.java b/app/src/main/java/io/lbry/browser/ui/BaseFragment.java index 9cbf3132..cbca31f8 100644 --- a/app/src/main/java/io/lbry/browser/ui/BaseFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/BaseFragment.java @@ -64,7 +64,7 @@ public class BaseFragment extends Fragment { } } - if (params != null && params.containsKey("source") && "notification".equalsIgnoreCase(params.get("source").toString())) { + if (params != null && params.containsKey("source") && params.get("source") != null && "notification".equalsIgnoreCase(params.get("source").toString())) { Context context = getContext(); if (context instanceof MainActivity) { ((MainActivity) context).navigateBackToNotifications(); -- 2.45.3 From a878d3bdd4f028b3d52b7d8333d306beb254a90a Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Wed, 31 Mar 2021 02:58:54 +0200 Subject: [PATCH 3/7] Pass has_source parameter to claim_search to ignore livestreamings --- .../ui/channel/ChannelContentFragment.java | 3 ++- .../ui/findcontent/AllContentFragment.java | 3 ++- .../ui/findcontent/EditorsChoiceFragment.java | 3 ++- .../ui/findcontent/FollowingFragment.java | 6 ++++-- .../ui/findcontent/ShuffleFragment.java | 3 ++- .../main/java/io/lbry/browser/utils/Lbry.java | 20 ++++++++++++++----- 6 files changed, 27 insertions(+), 11 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/ui/channel/ChannelContentFragment.java b/app/src/main/java/io/lbry/browser/ui/channel/ChannelContentFragment.java index 19d0043a..756c9d1f 100644 --- a/app/src/main/java/io/lbry/browser/ui/channel/ChannelContentFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/channel/ChannelContentFragment.java @@ -230,7 +230,8 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi 0, 0, currentClaimSearchPage == 0 ? 1 : currentClaimSearchPage, - Helper.CONTENT_PAGE_SIZE); + Helper.CONTENT_PAGE_SIZE, + true); } private List getContentSortOrder() { diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java index df62198e..353fefae 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/AllContentFragment.java @@ -421,7 +421,8 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi 0, 0, currentClaimSearchPage == 0 ? 1 : currentClaimSearchPage, - Helper.CONTENT_PAGE_SIZE); + Helper.CONTENT_PAGE_SIZE, + true); } private List getContentSortOrder() { diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java index 2a041e11..8026f0bf 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/EditorsChoiceFragment.java @@ -79,7 +79,8 @@ public class EditorsChoiceFragment extends BaseFragment { Arrays.asList(Claim.ORDER_BY_RELEASE_TIME), null, 1, - 99); + 99, + true); } public void onResume() { diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java index cc89d882..e3111820 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FollowingFragment.java @@ -415,7 +415,8 @@ public class FollowingFragment extends BaseFragment implements Arrays.asList(Claim.ORDER_BY_EFFECTIVE_AMOUNT), null, currentSuggestedPage == 0 ? 1 : currentSuggestedPage, - SUGGESTED_PAGE_SIZE); + SUGGESTED_PAGE_SIZE, + true); } private Map buildContentOptions() { @@ -437,7 +438,8 @@ public class FollowingFragment extends BaseFragment implements 0, 0, currentClaimSearchPage == 0 ? 1 : currentClaimSearchPage, - Helper.CONTENT_PAGE_SIZE); + Helper.CONTENT_PAGE_SIZE, + true); } private List getChannelIds() { diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/ShuffleFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/ShuffleFragment.java index 0d980c4e..8650ec0a 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/ShuffleFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/ShuffleFragment.java @@ -210,7 +210,8 @@ public class ShuffleFragment extends BaseFragment { 121, // 2 minutes or less 1, currentClaimSearchPage == 0 ? 1 : currentClaimSearchPage, - PAGE_SIZE); + PAGE_SIZE, + true); } public void onStart() { diff --git a/app/src/main/java/io/lbry/browser/utils/Lbry.java b/app/src/main/java/io/lbry/browser/utils/Lbry.java index b727948f..39381dc4 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbry.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbry.java @@ -373,7 +373,7 @@ public final class Lbry { // build claim search for surf mode public static Map buildClaimSearchOptions( - String claimType, List notTags, List channelIds, List orderBy, long maxDuration, int limitClaimsPerChannel, int page, int pageSize) { + String claimType, List notTags, List channelIds, List orderBy, long maxDuration, int limitClaimsPerChannel, int page, int pageSize, boolean hasSource) { return buildClaimSearchOptions( Collections.singletonList(claimType), null, @@ -385,7 +385,8 @@ public final class Lbry { maxDuration, limitClaimsPerChannel, page, - pageSize); + pageSize, + hasSource); } public static Map buildClaimSearchOptions( @@ -397,7 +398,8 @@ public final class Lbry { List orderBy, String releaseTime, int page, - int pageSize) { + int pageSize, + boolean hasSource) { return buildClaimSearchOptions( Collections.singletonList(claimType), anyTags, @@ -409,7 +411,8 @@ public final class Lbry { 0, 0, page, - pageSize); + pageSize, + hasSource); } public static Map buildClaimSearchOptions( @@ -423,7 +426,8 @@ public final class Lbry { long maxDuration, int limitClaimsPerChannel, int page, - int pageSize) { + int pageSize, + boolean hasSource) { Map options = new HashMap<>(); if (claimType != null && claimType.size() > 0) { options.put("claim_type", claimType); @@ -441,6 +445,12 @@ public final class Lbry { options.put("limit_claims_per_channel", limitClaimsPerChannel); } + if (hasSource) { + options.put("has_source", true); + } else { + options.put("has_no_source", true); + } + addClaimSearchListOption("any_tags", anyTags, options); addClaimSearchListOption("not_tags", notTags, options); addClaimSearchListOption("channel_ids", channelIds, options); -- 2.45.3 From 1436895acedfa9ec048c4a5ef755563a463fc470 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 12 Apr 2021 18:53:13 +0200 Subject: [PATCH 4/7] Copy file to public Downloads directory (#1180) --- .../ui/findcontent/FileViewFragment.java | 44 +++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index ecadbc56..5c7fbfd2 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -12,6 +12,7 @@ import android.graphics.Color; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; +import android.os.Environment; import android.text.Editable; import android.text.TextWatcher; import android.text.format.DateUtils; @@ -87,8 +88,12 @@ import org.json.JSONException; import org.json.JSONObject; import java.io.File; +import java.io.FileInputStream; import java.io.FileNotFoundException; +import java.io.FileOutputStream; import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; import java.text.DecimalFormat; import java.text.NumberFormat; import java.util.ArrayList; @@ -162,6 +167,10 @@ import io.lbry.lbrysdk.DownloadManager; import io.lbry.lbrysdk.LbrynetService; import io.lbry.lbrysdk.Utils; +import static android.os.Environment.DIRECTORY_DOWNLOADS; +import static android.os.Environment.DIRECTORY_MOVIES; +import static android.os.Environment.DIRECTORY_PICTURES; + public class FileViewFragment extends BaseFragment implements MainActivity.BackPressInterceptor, DownloadActionListener, @@ -2844,6 +2853,41 @@ public class FileViewFragment extends BaseFragment implements downloadInProgress = false; downloadProgressView.setProgress(100); Helper.setViewVisibility(downloadProgressView, View.GONE); + + // Copy file to shared Downloads folder + // TODO Assign this folder when downloading instead of copying the file + + File fileFolder; + + if (claimFile.getMimeType().contains("video")) + fileFolder = Environment.getExternalStoragePublicDirectory(DIRECTORY_MOVIES); + else if (claimFile.getMimeType().contains("image") || claimFile.getMimeType().contains("picture")) + fileFolder = Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES); + else + fileFolder = Environment.getExternalStoragePublicDirectory(DIRECTORY_DOWNLOADS); + + InputStream in = null; + OutputStream out; + try { + in = new FileInputStream(claimFile.getDownloadPath()); + + out = new FileOutputStream(new File(fileFolder, claimFile.getFileName())); + + byte[] buf = new byte[1024]; + int len; + + while ((len = in.read(buf)) > 0) { + out.write(buf, 0, len); + } + + in.close(); + out.close(); + } catch (IOException e) { + e.printStackTrace(); + } + + + playOrViewMedia(); } checkIsFileComplete(); -- 2.45.3 From 53554564984f284e0018a6e74d03efe8246d2a84 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 12 Apr 2021 18:53:59 +0200 Subject: [PATCH 5/7] Don't show link to Bittrex (#1181) --- .../browser/ui/wallet/WalletFragment.java | 50 +++++++++++++++++++ .../main/res/layout/card_wallet_balance.xml | 1 + 2 files changed, 51 insertions(+) diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java index bf89bae9..0e7cd3bc 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java @@ -33,6 +33,14 @@ import com.google.android.material.snackbar.Snackbar; import com.google.android.material.switchmaterial.SwitchMaterial; import com.google.android.material.textfield.TextInputEditText; +import org.json.JSONObject; + +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.ResponseBody; + +import java.io.IOException; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.net.URLEncoder; @@ -44,6 +52,10 @@ import java.text.DecimalFormatSymbols; import java.util.ArrayList; import java.util.List; import java.util.Locale; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; @@ -291,6 +303,44 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W } }); + ExecutorService executor = Executors.newSingleThreadExecutor(); + + // This will return /true/ if user IP is **not** on the US or the request fails + Future localeFuture = executor.submit(() -> { + Request request = new Request.Builder().url("https://api.lbry.com/locale/get").build(); + OkHttpClient okHttpClient = new OkHttpClient(); + + try (Response response = okHttpClient.newCall(request).execute()){ + ResponseBody responseBody = response.body(); + JSONObject responseJson; + + if (responseBody != null) + responseJson = new JSONObject(responseBody.string()); + else + return false; + + if (responseJson.has("data") && responseJson.getBoolean("success")) { + JSONObject dataJson = (JSONObject) responseJson.get("data"); + return !dataJson.getString("country").equals("US"); + } else { + return false; + } + } catch (IOException e) { + e.printStackTrace(); + } + return false; + }); + + try { + Boolean isNotUS = localeFuture.get(); + if (isNotUS) + textConvertCreditsBittrex.setVisibility(View.VISIBLE); + else + textConvertCreditsBittrex.setVisibility(View.GONE); + } catch (ExecutionException | InterruptedException e) { + e.printStackTrace(); + } + buttonSignUp.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { diff --git a/app/src/main/res/layout/card_wallet_balance.xml b/app/src/main/res/layout/card_wallet_balance.xml index c27a93af..8e5e8118 100644 --- a/app/src/main/res/layout/card_wallet_balance.xml +++ b/app/src/main/res/layout/card_wallet_balance.xml @@ -155,6 +155,7 @@ android:layout_height="wrap_content" android:layout_marginTop="8dp" android:layout_marginStart="16dp" + android:visibility="gone" android:fontFamily="@font/inter" android:text="@string/convert_credits_bittrex" android:textColorLink="@color/lbryGreen" -- 2.45.3 From 48d257ceafcd9091cc92fcc680d9f90b5a3811ab Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 19 Apr 2021 19:55:49 +0200 Subject: [PATCH 6/7] Show total wallet balance in USD instead of spendable balance conversion (#1186) --- app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java index 0e7cd3bc..089977ca 100644 --- a/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/wallet/WalletFragment.java @@ -688,7 +688,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W double totalBalance = walletBalance.getTotal().doubleValue(); double spendableBalance = walletBalance.getAvailable().doubleValue(); double supportingBalance = walletBalance.getClaims().doubleValue() + walletBalance.getTips().doubleValue() + walletBalance.getSupports().doubleValue(); - double usdBalance = spendableBalance * Lbryio.LBCUSDRate; + double usdBalance = totalBalance * Lbryio.LBCUSDRate; double tipsBalance = walletBalance.getTips().doubleValue(); if (detailRows == null) -- 2.45.3 From e4417dc51db9774f6d7a3361f4b0c76214508fb6 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 26 Apr 2021 15:10:02 +0200 Subject: [PATCH 7/7] Update to SDK 0.94.1 and allow user to view livestream content on Odysee --- app/build.gradle | 4 +- .../java/io/lbry/browser/model/Claim.java | 8 +++ .../ui/findcontent/FileViewFragment.java | 62 ++++++++++++------- .../java/io/lbry/browser/utils/LbryUri.java | 12 ++-- app/src/main/res/values/strings.xml | 2 + .../io/lbry/browser/utils/LbryUriTest.java | 13 ++++ build.gradle | 1 + 7 files changed, 75 insertions(+), 27 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 89ae00ea..0d9a362b 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -132,8 +132,8 @@ dependencies { androidTestImplementation 'androidx.test.ext:junit:1.1.2' androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0' - __32bitImplementation 'io.lbry:lbrysdk32:0.91.0' - __64bitImplementation 'io.lbry:lbrysdk64:0.91.0' + __32bitImplementation 'io.lbry:lbrysdk32:0.94.1' + __64bitImplementation 'io.lbry:lbrysdk64:0.94.1' } apply plugin: 'com.google.gms.google-services' diff --git a/app/src/main/java/io/lbry/browser/model/Claim.java b/app/src/main/java/io/lbry/browser/model/Claim.java index 88dd197e..45c03840 100644 --- a/app/src/main/java/io/lbry/browser/model/Claim.java +++ b/app/src/main/java/io/lbry/browser/model/Claim.java @@ -137,6 +137,14 @@ public class Claim { return null; } + public boolean hasSource() { + if (value instanceof StreamMetadata) { + StreamMetadata metadata = (StreamMetadata) value; + return metadata.getSource() != null; + } + return false; + } + public boolean isPlayable() { if (value instanceof StreamMetadata) { StreamMetadata metadata = (StreamMetadata) value; diff --git a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index ecadbc56..5e8f065a 100644 --- a/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java @@ -1617,7 +1617,7 @@ public class FileViewFragment extends BaseFragment implements root.findViewById(R.id.file_view_open_external_button).setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { - openClaimExternally(claim, claim.getMediaType()); + openClaimExternally(claim, claim.getMediaType(), !claim.hasSource()); } }); @@ -1675,12 +1675,16 @@ public class FileViewFragment extends BaseFragment implements restoreMainActionButton(); } - if (Lbry.SDK_READY && !claim.isPlayable() && !claim.isViewable() && Helper.isNullOrEmpty(commentHash)) { - if (claim.getFile() == null) { - loadFile(); - } else { - // file already loaded, but it's unsupported + if (Lbry.SDK_READY) { + if (!claim.hasSource()) { showUnsupportedView(); + } else if (!claim.isPlayable() && !claim.isViewable() && Helper.isNullOrEmpty(commentHash)) { + if (claim.getFile() == null) { + loadFile(); + } else { + // file already loaded, but it's unsupported + showUnsupportedView(); + } } } @@ -1724,13 +1728,19 @@ public class FileViewFragment extends BaseFragment implements if (root != null) { root.findViewById(R.id.file_view_exoplayer_container).setVisibility(View.GONE); root.findViewById(R.id.file_view_unsupported_container).setVisibility(View.VISIBLE); - String fileNameString = ""; - if (claim.getFile() != null && !Helper.isNullOrEmpty(claim.getFile().getDownloadPath())) { - LbryFile lbryFile = claim.getFile(); - File file = new File(lbryFile.getDownloadPath()); - fileNameString = String.format("\"%s\" ", file.getName()); + if (claim.hasSource()) { + String fileNameString = ""; + if (claim.getFile() != null && !Helper.isNullOrEmpty(claim.getFile().getDownloadPath())) { + LbryFile lbryFile = claim.getFile(); + File file = new File(lbryFile.getDownloadPath()); + fileNameString = String.format("\"%s\" ", file.getName()); + } + ((TextView) root.findViewById(R.id.file_view_unsupported_text)).setText(getString(R.string.unsupported_content_desc, fileNameString)); + ((MaterialButton) root.findViewById(R.id.file_view_open_external_button)).setText(getString(R.string.open)); + } else { + ((TextView) root.findViewById(R.id.file_view_unsupported_text)).setText(getString(R.string.unsupported_content_to_odysee_desc)); + ((MaterialButton) root.findViewById(R.id.file_view_open_external_button)).setText(getString(R.string.open_on_odysee_com)); } - ((TextView) root.findViewById(R.id.file_view_unsupported_text)).setText(getString(R.string.unsupported_content_desc, fileNameString)); } } @@ -2182,7 +2192,7 @@ public class FileViewFragment extends BaseFragment implements handled = true; } } else { - openClaimExternally(claim, mediaType); + openClaimExternally(claim, mediaType, false); } } @@ -2266,15 +2276,25 @@ public class FileViewFragment extends BaseFragment implements " "; } - private void openClaimExternally(Claim claim, String mediaType) { - Uri fileUri = Uri.parse(claim.getFile().getDownloadPath()); + private void openClaimExternally(Claim claim, String mediaType, boolean odyseeLink) { + if (odyseeLink) { + try { + LbryUri lbryUri = LbryUri.parse(claim.getCanonicalUrl()); + Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(lbryUri.toOdyseeString())); + startActivity(intent); + } catch (LbryUriException e) { + e.printStackTrace(); + } + } else { + Uri fileUri = Uri.parse(claim.getFile().getDownloadPath()); - Intent intent = new Intent(); - intent.setAction(Intent.ACTION_VIEW); - intent.setDataAndType(fileUri, mediaType.toLowerCase()); - intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); - Intent chooser = Intent.createChooser(intent, getString(R.string.choose_app)); - startActivityForResult(chooser, 419); + Intent intent = new Intent(); + intent.setAction(Intent.ACTION_VIEW); + intent.setDataAndType(fileUri, mediaType.toLowerCase()); + intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); + Intent chooser = Intent.createChooser(intent, getString(R.string.choose_app)); + startActivityForResult(chooser, 419); + } } public void showError(String message) { diff --git a/app/src/main/java/io/lbry/browser/utils/LbryUri.java b/app/src/main/java/io/lbry/browser/utils/LbryUri.java index a55dd0f2..1570ab96 100644 --- a/app/src/main/java/io/lbry/browser/utils/LbryUri.java +++ b/app/src/main/java/io/lbry/browser/utils/LbryUri.java @@ -16,6 +16,7 @@ import static org.apache.commons.codec.CharEncoding.UTF_8; @Data public class LbryUri { public static final String LBRY_TV_BASE_URL = "https://lbry.tv/"; + public static final String ODYSEE_COM_BASE_URL = "https://odysee.com/"; public static final String PROTO_DEFAULT = "lbry://"; public static final String REGEX_INVALID_URI = "[ =&#:$@%?;/\\\\\"<>%\\{\\}|^~\\[\\]`\u0000-\u0008\u000b-\u000c\u000e-\u001F\uD800-\uDFFF\uFFFE-\uFFFF]"; public static final String REGEX_ADDRESS = "^(b)(?=[^0OIl]{32,33})[0-9A-Za-z]{32,33}$"; @@ -202,7 +203,7 @@ public class LbryUri { } String primaryClaimName = null; - if (protocol.equals(LBRY_TV_BASE_URL) && Helper.isNullOrEmpty(formattedChannelName)) { + if ((protocol.equals(LBRY_TV_BASE_URL) || protocol.equals(ODYSEE_COM_BASE_URL)) && Helper.isNullOrEmpty(formattedChannelName)) { try { primaryClaimName = URLEncoder.encode(claimName, UTF_8); } catch (UnsupportedEncodingException e) { @@ -241,7 +242,7 @@ public class LbryUri { secondaryClaimName = contentName; } if (Helper.isNullOrEmpty(secondaryClaimName)) { - if (protocol.equals(LBRY_TV_BASE_URL)) { + if (protocol.equals(LBRY_TV_BASE_URL) || protocol.equals(ODYSEE_COM_BASE_URL)) { try { secondaryClaimName = !Helper.isNullOrEmpty(formattedChannelName) ? URLEncoder.encode(streamName, UTF_8) : null; } catch (UnsupportedEncodingException e) { @@ -254,7 +255,7 @@ public class LbryUri { String secondaryClaimId = !Helper.isNullOrEmpty(secondaryClaimName) ? streamClaimId : null; if (!Helper.isNullOrEmpty(primaryClaimId)) { - if (protocol.equals(LBRY_TV_BASE_URL)) + if (protocol.equals(LBRY_TV_BASE_URL) || protocol.equals(ODYSEE_COM_BASE_URL)) sb.append(':').append(primaryClaimId); else sb.append('#').append(primaryClaimId); @@ -269,7 +270,7 @@ public class LbryUri { } if (!Helper.isNullOrEmpty(secondaryClaimId)) { - if (protocol.equals(LBRY_TV_BASE_URL)) + if (protocol.equals(LBRY_TV_BASE_URL) || protocol.equals(ODYSEE_COM_BASE_URL)) sb.append(':').append(secondaryClaimId); else sb.append('#').append(secondaryClaimId); @@ -289,6 +290,9 @@ public class LbryUri { public String toTvString() { return build(true, LBRY_TV_BASE_URL, false); } + public String toOdyseeString() { + return build(true, ODYSEE_COM_BASE_URL, false); + } public String toVanityString() { return build(true, PROTO_DEFAULT, true); } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 8b4bce94..6fda4756 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -57,6 +57,7 @@ Delete Download Open + Open on ODYSEE.COM Report Loading decentralized data… Related Content @@ -71,6 +72,7 @@ Play Unsupported Content Sorry, we are unable to display this content in the app. You can find the file %1$sin your downloads folder. + Sorry, we are unable to display this content in the app. Click the button to open it on the Odysee website. There\'s nothing at this location. In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this content from our applications. <a href="https://lbry.com/faq/dmca">Read more</a> In response to a complaint we received under the US Digital Millennium Copyright Act, we have blocked access to this channel from our applications. <a href="https://lbry.com/faq/dmca">Read more</a> diff --git a/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java b/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java index 7dfa46af..45c0c943 100644 --- a/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java +++ b/app/src/test/java/io/lbry/browser/utils/LbryUriTest.java @@ -178,6 +178,19 @@ public class LbryUriTest { assertEquals("https://lbry.tv/@test:1/La-Peur%2C-Nos-Attentats%2C-c%27est-VOTRE-Se%CC%81curite%CC%81%21-Les-Guignols:6", obtained.toTvString()); } + @Test + public void lbryToOdyseeString() { + LbryUri obtained = new LbryUri(); + + try { + obtained = LbryUri.parse("lbry://@lbry#3f/lbryturns4#6",false); + } catch (LbryUriException e) { + e.printStackTrace(); + } + + assertEquals("https://odysee.com/@lbry:3f/lbryturns4:6", obtained.toOdyseeString()); + } + @NotNull private LbryUri sinthesizeExpected() { LbryUri expectedForChannel = new LbryUri(); diff --git a/build.gradle b/build.gradle index b7173582..2ff4ab4a 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,7 @@ allprojects { google() jcenter() maven { url "https://jitpack.io" } + maven { url "https://dl.bintray.com/lbryio/io.lbry" } } } -- 2.45.3