From 252f602053ca18aa10c2390867c80fd85630dd9b Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Tue, 23 Mar 2021 17:41:59 +0100 Subject: [PATCH 1/3] Copy file to public Downloads directory --- .../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.2 From 3f5104d60a47b42d6d12b76d58e3a4d3c34756d5 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 29 Mar 2021 17:38:51 +0200 Subject: [PATCH 2/3] 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.2 From 6e32f7724fbba901b16b60b32fa0286eb9444fc4 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Mon, 29 Mar 2021 17:39:27 +0200 Subject: [PATCH 3/3] 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.2