From a8cdc4a77161b6d3ee35269df1fa33acad8ecf12 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Thu, 4 Mar 2021 19:11:19 +0100 Subject: [PATCH 1/2] Move the wallet floating button away when scroll gets to the bottom at FileViewFragment (#1155) --- .../java/io/lbry/browser/MainActivity.java | 15 ++++++++++++ .../ui/findcontent/FileViewFragment.java | 24 +++++++++++++++++++ 2 files changed, 39 insertions(+) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index fcd34261..aa5b65c5 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -1,5 +1,6 @@ package io.lbry.browser; +import android.animation.ObjectAnimator; import android.annotation.SuppressLint; import android.app.Activity; import android.app.ActivityManager; @@ -824,6 +825,20 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener walletBalanceListeners.remove(listener); } + public void restoreWalletContainerPosition() { + View floatingBalance = findViewById(R.id.floating_balance_main_container); + + ObjectAnimator animation = ObjectAnimator.ofFloat(floatingBalance, "translationY", 0f); + animation.setDuration(250).start(); + } + + public void translateFloatingWallet(float initialY) { + if (findViewById(R.id.floating_balance_main_container).getY() == initialY) { + ObjectAnimator animation = ObjectAnimator.ofFloat(findViewById(R.id.floating_balance_main_container), "translationY", 2 * findViewById(R.id.floating_balance_main_container).getHeight()); + animation.setDuration(300).start(); + } + } + public void removeNavFragment(Class fragmentClass, int navItemId) { String key = buildNavFragmentKey(fragmentClass, navItemId, null); if (openNavFragments.containsKey(key)) { 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 5db02284..032aae1b 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 @@ -247,6 +247,8 @@ public class FileViewFragment extends BaseFragment implements // 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_file_view, container, false); @@ -802,6 +804,7 @@ public class FileViewFragment extends BaseFragment implements activity.removeSdkStatusListener(this); activity.removeStoragePermissionListener(this); activity.removeWalletBalanceListener(this); + activity.restoreWalletContainerPosition(); activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED); } @@ -1282,6 +1285,27 @@ public class FileViewFragment extends BaseFragment implements buttonUnfollow.setOnClickListener(followUnfollowListener); buttonBell.setOnClickListener(bellIconListener); + NestedScrollView scrollView = root.findViewById(R.id.file_view_scroll_view); + + // Store floating wallet balance vertical position when fragment was created + // This is used for animate it when user scrolls to the bottom of the screen + View floatingBalance = getActivity().findViewById(R.id.floating_balance_main_container); + floatingWalletPositionY = floatingBalance.getY(); + + scrollView.setOnScrollChangeListener(new NestedScrollView.OnScrollChangeListener() { + @Override + public void onScrollChange(NestedScrollView v, int scrollX, int scrollY, int oldScrollX, int oldScrollY) { + Context ctx = getContext(); + if (scrollY < oldScrollY && ctx instanceof MainActivity) { + // User has scrolled upwards + ((MainActivity) ctx).restoreWalletContainerPosition(); + } else if (scrollY == (v.getChildAt(0).getMeasuredHeight() - v.getMeasuredHeight()) && ctx instanceof MainActivity) { + // User is at the bottom of the screen + ((MainActivity) ctx).translateFloatingWallet(floatingWalletPositionY); + } + } + }); + commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>()); commentChannelSpinnerAdapter.addPlaceholder(false); From d0a8b3b218ad7f8e008aa43d089fac7441dd3065 Mon Sep 17 00:00:00 2001 From: Javi Rueda Date: Sat, 6 Mar 2021 00:32:12 +0100 Subject: [PATCH 2/2] Fix mass tips unlocking (#1157) --- .../browser/tasks/wallet/UnlockTipsTask.java | 35 +++---------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/tasks/wallet/UnlockTipsTask.java b/app/src/main/java/io/lbry/browser/tasks/wallet/UnlockTipsTask.java index c5513a87..b93ce330 100644 --- a/app/src/main/java/io/lbry/browser/tasks/wallet/UnlockTipsTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/wallet/UnlockTipsTask.java @@ -2,24 +2,16 @@ package io.lbry.browser.tasks.wallet; import android.os.AsyncTask; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; - -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; import io.lbry.browser.exceptions.ApiCallException; -import io.lbry.browser.model.WalletBalance; import io.lbry.browser.tasks.GenericTaskHandler; -import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Lbry; public class UnlockTipsTask extends AsyncTask { - private GenericTaskHandler handler; + private final GenericTaskHandler handler; private Exception error; public UnlockTipsTask(GenericTaskHandler handler) { @@ -27,35 +19,16 @@ public class UnlockTipsTask extends AsyncTask { } public Boolean doInBackground(Void... params) { - - List txids = new ArrayList<>(); - try { Map options = new HashMap<>(); options.put("type", "support"); options.put("is_not_my_input", true); - options.put("is_my_output", true); - JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_TXO_LIST, options); - if (result.has("items") && !result.isNull("items")) { - JSONArray items = result.getJSONArray("items"); - for (int i = 0; i < items.length(); i++) { - JSONObject item = items.getJSONObject(i); - String txid = Helper.getJSONString("txid", null, item); - if (!Helper.isNullOrEmpty(txid)) { - txids.add(txid); - } - } - } + options.put("blocking", true); - if (txids.size() > 0) { - options = new HashMap<>(); - options.put("txid", txids); - options.put("blocking", true); - Lbry.genericApiCall(Lbry.METHOD_TXO_SPEND, options); - } + Lbry.genericApiCall(Lbry.METHOD_TXO_SPEND, options); return true; - } catch (ApiCallException | ClassCastException | JSONException ex) { + } catch (ApiCallException | ClassCastException ex) { error = ex; return false; }