From 2bacba2c87f8d67659534ff93bee3317b3c746dc Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 10:52:25 +0100 Subject: [PATCH 01/16] properly close all activities when service is stopped --- app/build.gradle | 4 +-- .../io/lbry/browser/FirstRunActivity.java | 33 +++++++++++-------- .../java/io/lbry/browser/MainActivity.java | 15 +++++++-- .../io/lbry/browser/VerificationActivity.java | 25 ++++++++++++++ .../ui/publish/PublishFormFragment.java | 6 +++- .../browser/ui/publish/PublishFragment.java | 13 ++++++-- .../java/io/lbry/browser/utils/Lbryio.java | 14 ++++++++ 7 files changed, 89 insertions(+), 21 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index c4496697..73499098 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId "io.lbry.browser" minSdkVersion 21 targetSdkVersion 29 - versionCode 1507 - versionName "0.15.7" + versionCode 1508 + versionName "0.15.8" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } diff --git a/app/src/main/java/io/lbry/browser/FirstRunActivity.java b/app/src/main/java/io/lbry/browser/FirstRunActivity.java index b4d42ee4..df618fe5 100644 --- a/app/src/main/java/io/lbry/browser/FirstRunActivity.java +++ b/app/src/main/java/io/lbry/browser/FirstRunActivity.java @@ -10,7 +10,6 @@ import android.os.Bundle; import android.text.method.LinkMovementMethod; import android.view.View; import android.widget.TextView; -import android.widget.Toast; import androidx.appcompat.app.AppCompatActivity; import androidx.core.text.HtmlCompat; @@ -20,10 +19,11 @@ import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Lbry; import io.lbry.browser.utils.LbryAnalytics; import io.lbry.browser.utils.Lbryio; +import io.lbry.lbrysdk.LbrynetService; public class FirstRunActivity extends AppCompatActivity { - private BroadcastReceiver sdkReadyReceiver; + private BroadcastReceiver sdkReceiver; private BroadcastReceiver authReceiver; @Override @@ -45,19 +45,26 @@ public class FirstRunActivity extends AppCompatActivity { registerAuthReceiver(); if (!Lbry.SDK_READY) { findViewById(R.id.welcome_wait_container).setVisibility(View.VISIBLE); - IntentFilter filter = new IntentFilter(); - filter.addAction(MainActivity.ACTION_SDK_READY); - sdkReadyReceiver = new BroadcastReceiver() { - @Override - public void onReceive(Context context, Intent intent) { - // authenticate after we receive the sdk ready event - authenticate(); - } - }; - registerReceiver(sdkReadyReceiver, filter); } else { authenticate(); } + + IntentFilter filter = new IntentFilter(); + filter.addAction(MainActivity.ACTION_SDK_READY); + filter.addAction(LbrynetService.ACTION_STOP_SERVICE); + sdkReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (MainActivity.ACTION_SDK_READY.equals(action)) { + // authenticate after we receive the sdk ready event + authenticate(); + } else if (LbrynetService.ACTION_STOP_SERVICE.equals(action)) { + finish(); + } + } + }; + registerReceiver(sdkReceiver, filter); } public void onResume() { @@ -122,7 +129,7 @@ public class FirstRunActivity extends AppCompatActivity { @Override protected void onDestroy() { Helper.unregisterReceiver(authReceiver, this); - Helper.unregisterReceiver(sdkReadyReceiver, this); + Helper.unregisterReceiver(sdkReceiver, this); super.onDestroy(); } diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index eace68dd..586ea4d4 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -921,7 +921,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener applyNavbarSigninPadding(); checkFirstRun(); checkNowPlaying(); - fetchRewards(); // check (and start) the LBRY SDK service serviceRunning = isServiceRunning(this, LbrynetService.class); @@ -1422,13 +1421,18 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); boolean firstRunCompleted = sp.getBoolean(PREFERENCE_KEY_INTERNAL_FIRST_RUN_COMPLETED, false); if (!firstRunCompleted) { + findViewById(R.id.drawer_layout).setVisibility(View.INVISIBLE); startActivity(new Intent(this, FirstRunActivity.class)); - } else if (!appStarted) { + return; + } + + if (!appStarted) { // first run completed, startup startup(); return; } + fetchRewards(); if (getSupportFragmentManager().getBackStackEntryCount() == 0) { openFragment(FollowingFragment.class, false, NavMenuItem.ID_ITEM_FOLLOWING); } @@ -1492,7 +1496,11 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener initFloatingWalletBalance(); - checkAndClaimNewAndroidReward(); + SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); + boolean firstRunCompleted = sp.getBoolean(PREFERENCE_KEY_INTERNAL_FIRST_RUN_COMPLETED, false); + if (firstRunCompleted) { + checkAndClaimNewAndroidReward(); + } } public void checkAndClaimNewAndroidReward() { @@ -2196,6 +2204,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener hideActionBar(); lockDrawer(); findViewById(R.id.splash_view).setVisibility(View.VISIBLE); + findViewById(R.id.drawer_layout).setVisibility(View.VISIBLE); LbryAnalytics.setCurrentScreen(MainActivity.this, "Splash", "Splash"); initStartupStages(); } diff --git a/app/src/main/java/io/lbry/browser/VerificationActivity.java b/app/src/main/java/io/lbry/browser/VerificationActivity.java index cf819cb6..32324e8d 100644 --- a/app/src/main/java/io/lbry/browser/VerificationActivity.java +++ b/app/src/main/java/io/lbry/browser/VerificationActivity.java @@ -1,6 +1,9 @@ package io.lbry.browser; +import android.content.BroadcastReceiver; +import android.content.Context; import android.content.Intent; +import android.content.IntentFilter; import android.graphics.Color; import android.os.AsyncTask; import android.os.Bundle; @@ -18,8 +21,10 @@ import io.lbry.browser.listener.SignInListener; import io.lbry.browser.listener.WalletSyncListener; import io.lbry.browser.model.lbryinc.User; import io.lbry.browser.tasks.lbryinc.FetchCurrentUserTask; +import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.LbryAnalytics; import io.lbry.browser.utils.Lbryio; +import io.lbry.lbrysdk.LbrynetService; public class VerificationActivity extends FragmentActivity implements SignInListener, WalletSyncListener { @@ -27,6 +32,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList public static final int VERIFICATION_FLOW_REWARDS = 2; public static final int VERIFICATION_FLOW_WALLET = 3; + private BroadcastReceiver sdkReceiver; private String email; private boolean signedIn; private int flow; @@ -54,6 +60,19 @@ public class VerificationActivity extends FragmentActivity implements SignInList return; } + IntentFilter filter = new IntentFilter(); + filter.addAction(LbrynetService.ACTION_STOP_SERVICE); + sdkReceiver = new BroadcastReceiver() { + @Override + public void onReceive(Context context, Intent intent) { + String action = intent.getAction(); + if (LbrynetService.ACTION_STOP_SERVICE.equals(action)) { + finish(); + } + } + }; + registerReceiver(sdkReceiver, filter); + setContentView(R.layout.activity_verification); ViewPager2 viewPager = findViewById(R.id.verification_pager); viewPager.setUserInputEnabled(false); @@ -269,4 +288,10 @@ public class VerificationActivity extends FragmentActivity implements SignInList public void onWalletSyncFailed(Exception error) { findViewById(R.id.verification_close_button).setVisibility(View.VISIBLE); } + + @Override + public void onDestroy() { + Helper.unregisterReceiver(sdkReceiver, this); + super.onDestroy(); + } } diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index 87a1665f..a8cb1580 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java @@ -102,6 +102,7 @@ public class PublishFormFragment extends BaseFragment implements private static final int MAX_VIDEO_DIMENSION = 1920; private static final int MAX_BITRATE = 5000000; // 5mbps + private boolean storageRefusedOnce; private static final int SUGGESTED_LIMIT = 8; private boolean editMode; @@ -1394,7 +1395,10 @@ public class PublishFormFragment extends BaseFragment implements @Override public void onStoragePermissionRefused() { - showError(getString(R.string.storage_permission_rationale_images)); + if (!storageRefusedOnce) { + showError(getString(R.string.storage_permission_rationale_images)); + storageRefusedOnce = true; + } launchPickerPending = false; } diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java index bd4dd9c8..8ec12b4e 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java @@ -53,6 +53,7 @@ public class PublishFragment extends BaseFragment implements CameraPermissionListener, FilePickerListener, StoragePermissionListener { private boolean cameraPreviewInitialized; + private boolean storageRefusedOnce; private PreviewView cameraPreview; private RecyclerView galleryGrid; private GalleryGridAdapter adapter; @@ -399,8 +400,16 @@ public class PublishFragment extends BaseFragment implements @Override public void onStoragePermissionRefused() { - Snackbar.make(getView(), R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + if (!storageRefusedOnce) { + View root = getView(); + if (root != null) { + Snackbar.make(root, R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + Helper.setViewText(noVideosLoaded, R.string.storage_permission_rationale_videos); + checkNoVideosLoaded(); + } + storageRefusedOnce = true; + } } public String getSuggestedPublishUrl() { diff --git a/app/src/main/java/io/lbry/browser/utils/Lbryio.java b/app/src/main/java/io/lbry/browser/utils/Lbryio.java index 8b96f6a7..f94fd3ac 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbryio.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbryio.java @@ -25,6 +25,7 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; +import io.lbry.browser.BuildConfig; import io.lbry.browser.MainActivity; import io.lbry.browser.exceptions.LbryioRequestException; import io.lbry.browser.exceptions.LbryioResponseException; @@ -81,6 +82,10 @@ public final class Lbryio { authToken = getAuthToken(context); } + if (BuildConfig.DEBUG) { + Log.d(TAG, String.format("Using authToken for request: %s", authToken)); + } + String url = String.format("%s/%s/%s", CONNECTION_STRING, resource, action); if (Helper.METHOD_GET.equalsIgnoreCase(method)) { Uri.Builder uriBuilder = Uri.parse(url).buildUpon(); @@ -94,6 +99,9 @@ public final class Lbryio { } url = uriBuilder.build().toString(); } + if (BuildConfig.DEBUG) { + Log.d(TAG, String.format("Request Method: %s, Sending request to URL: %s", method, url)); + } Request.Builder builder = new Request.Builder().url(url); if (Helper.METHOD_POST.equalsIgnoreCase(method)) { @@ -142,6 +150,9 @@ public final class Lbryio { } generatingAuthToken = true; + if (BuildConfig.DEBUG) { + Log.d(TAG, "Generating a new auth token"); + } Map options = new HashMap<>(); options.put("auth_token", ""); @@ -150,6 +161,9 @@ public final class Lbryio { Response response = Lbryio.call("user", "new", options, "post", context); try { JSONObject json = (JSONObject) parseResponse(response); + if (BuildConfig.DEBUG) { + Log.d(TAG, String.format("/user/new response: %s", json.toString(2))); + } if (!json.has(AUTH_TOKEN_PARAM)) { throw new LbryioResponseException("auth_token was not set in the response"); } -- 2.45.2 From a49cfe91daef23af0986e6879cfbaa64c3812f91 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 10:58:28 +0100 Subject: [PATCH 02/16] remove debug logs --- .../main/java/io/lbry/browser/utils/Lbryio.java | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/utils/Lbryio.java b/app/src/main/java/io/lbry/browser/utils/Lbryio.java index f94fd3ac..9ab3cdf9 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbryio.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbryio.java @@ -82,9 +82,9 @@ public final class Lbryio { authToken = getAuthToken(context); } - if (BuildConfig.DEBUG) { + /*if (BuildConfig.DEBUG) { Log.d(TAG, String.format("Using authToken for request: %s", authToken)); - } + }*/ String url = String.format("%s/%s/%s", CONNECTION_STRING, resource, action); if (Helper.METHOD_GET.equalsIgnoreCase(method)) { @@ -99,9 +99,9 @@ public final class Lbryio { } url = uriBuilder.build().toString(); } - if (BuildConfig.DEBUG) { + /*if (BuildConfig.DEBUG) { Log.d(TAG, String.format("Request Method: %s, Sending request to URL: %s", method, url)); - } + }*/ Request.Builder builder = new Request.Builder().url(url); if (Helper.METHOD_POST.equalsIgnoreCase(method)) { @@ -150,9 +150,9 @@ public final class Lbryio { } generatingAuthToken = true; - if (BuildConfig.DEBUG) { + /*if (BuildConfig.DEBUG) { Log.d(TAG, "Generating a new auth token"); - } + }*/ Map options = new HashMap<>(); options.put("auth_token", ""); @@ -161,9 +161,9 @@ public final class Lbryio { Response response = Lbryio.call("user", "new", options, "post", context); try { JSONObject json = (JSONObject) parseResponse(response); - if (BuildConfig.DEBUG) { + /*if (BuildConfig.DEBUG) { Log.d(TAG, String.format("/user/new response: %s", json.toString(2))); - } + }*/ if (!json.has(AUTH_TOKEN_PARAM)) { throw new LbryioResponseException("auth_token was not set in the response"); } -- 2.45.2 From c844c4f896933ec3a1688f80e83fe4f0a12d701b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 11:20:51 +0100 Subject: [PATCH 03/16] fix PIP mode display for Android version < 10 --- .../java/io/lbry/browser/MainActivity.java | 22 +++++++++++++++- .../browser/listener/PIPModeListener.java | 6 +++++ .../ui/findcontent/FileViewFragment.java | 25 ++++++++++++++++--- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 app/src/main/java/io/lbry/browser/listener/PIPModeListener.java diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 586ea4d4..755236bd 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -115,6 +115,7 @@ import io.lbry.browser.listener.DownloadActionListener; import io.lbry.browser.listener.FetchChannelsListener; import io.lbry.browser.listener.FetchClaimsListener; import io.lbry.browser.listener.FilePickerListener; +import io.lbry.browser.listener.PIPModeListener; import io.lbry.browser.listener.ScreenOrientationListener; import io.lbry.browser.listener.SdkStatusListener; import io.lbry.browser.listener.StoragePermissionListener; @@ -316,6 +317,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener private List cameraPermissionListeners; private List downloadActionListeners; private List filePickerListeners; + private List pipModeListeners; private List screenOrientationListeners; private List sdkStatusListeners; private List storagePermissionListeners; @@ -426,6 +428,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener fetchChannelsListeners = new ArrayList<>(); fetchClaimsListeners = new ArrayList<>(); filePickerListeners = new ArrayList<>(); + pipModeListeners = new ArrayList<>(); screenOrientationListeners = new ArrayList<>(); sdkStatusListeners = new ArrayList<>(); storagePermissionListeners = new ArrayList<>(); @@ -598,6 +601,16 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener filePickerListeners.remove(listener); } + public void addPIPModeListener(PIPModeListener listener) { + if (!pipModeListeners.contains(listener)) { + pipModeListeners.add(listener); + } + } + + public void removePIPModeListener(PIPModeListener listener) { + pipModeListeners.remove(listener); + } + public void addCameraPermissionListener(CameraPermissionListener listener) { if (!cameraPermissionListeners.contains(listener)) { cameraPermissionListeners.add(listener); @@ -808,6 +821,10 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener findViewById(R.id.app_bar_main_container).setFitsSystemWindows(true); hideActionBar(); + for (PIPModeListener listener : pipModeListeners) { + listener.onEnterPIPMode(); + } + PlayerView pipPlayer = findViewById(R.id.pip_player); pipPlayer.setVisibility(View.VISIBLE); pipPlayer.setPlayer(appPlayer); @@ -838,6 +855,9 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener if (!Lbry.SDK_READY && !inFullscreenMode) { findViewById(R.id.global_sdk_initializing_status).setVisibility(View.VISIBLE); } + for (PIPModeListener listener : pipModeListeners) { + listener.onExitPIPMode(); + } PlayerView pipPlayer = findViewById(R.id.pip_player); pipPlayer.setVisibility(View.INVISIBLE); @@ -996,7 +1016,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener public boolean canShowUrlSuggestions() { SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - return sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_URL_SUGGESTIONS, false); + return sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_URL_SUGGESTIONS, true); } public boolean keepSdkBackground() { diff --git a/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java b/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java new file mode 100644 index 00000000..0638e6be --- /dev/null +++ b/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java @@ -0,0 +1,6 @@ +package io.lbry.browser.listener; + +public interface PIPModeListener { + void onEnterPIPMode(); + void onExitPIPMode(); +} 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 61e328b7..b86c13e1 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 @@ -9,7 +9,6 @@ import android.content.Intent; import android.content.SharedPreferences; import android.content.pm.ActivityInfo; import android.graphics.Color; -import android.graphics.drawable.Drawable; import android.net.Uri; import android.os.AsyncTask; import android.os.Bundle; @@ -31,7 +30,6 @@ import android.widget.RelativeLayout; import android.widget.TextView; import androidx.annotation.NonNull; -import androidx.annotation.Nullable; import androidx.appcompat.app.AlertDialog; import androidx.constraintlayout.widget.ConstraintLayout; import androidx.core.content.ContextCompat; @@ -97,6 +95,7 @@ import io.lbry.browser.dialog.SendTipDialogFragment; import io.lbry.browser.exceptions.LbryUriException; import io.lbry.browser.listener.DownloadActionListener; import io.lbry.browser.listener.FetchClaimsListener; +import io.lbry.browser.listener.PIPModeListener; import io.lbry.browser.listener.ScreenOrientationListener; import io.lbry.browser.listener.SdkStatusListener; import io.lbry.browser.listener.StoragePermissionListener; @@ -140,8 +139,10 @@ import io.lbry.lbrysdk.LbrynetService; import io.lbry.lbrysdk.Utils; public class FileViewFragment extends BaseFragment implements - MainActivity.BackPressInterceptor, DownloadActionListener, + MainActivity.BackPressInterceptor, + DownloadActionListener, FetchClaimsListener, + PIPModeListener, ScreenOrientationListener, SdkStatusListener, StoragePermissionListener, @@ -240,6 +241,7 @@ public class FileViewFragment extends BaseFragment implements activity.setBackPressInterceptor(this); activity.addDownloadActionListener(this); activity.addFetchClaimsListener(this); + activity.addPIPModeListener(this); activity.addScreenOrientationListener(this); activity.addWalletBalanceListener(this); if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { @@ -584,6 +586,7 @@ public class FileViewFragment extends BaseFragment implements MainActivity activity = (MainActivity) context; activity.removeDownloadActionListener(this); activity.removeFetchClaimsListener(this); + activity.removePIPModeListener(this); activity.removeScreenOrientationListener(this); activity.removeSdkStatusListener(this); activity.removeStoragePermissionListener(this); @@ -2351,4 +2354,20 @@ public class FileViewFragment extends BaseFragment implements return Integer.MAX_VALUE; } } + + public void onEnterPIPMode() { + View root = getView(); + if (root != null) { + PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view); + playerView.setVisibility(View.GONE); + } + } + + public void onExitPIPMode() { + View root = getView(); + if (root != null) { + PlayerView playerView = root.findViewById(R.id.file_view_exoplayer_view); + playerView.setVisibility(View.VISIBLE); + } + } } -- 2.45.2 From a8596829540181ba0b43f6bfbe972ee590336a36 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 22:56:07 +0100 Subject: [PATCH 04/16] fix permission request handling for permanently denied permissions --- .../java/io/lbry/browser/MainActivity.java | 12 +++++++--- .../browser/ui/publish/PublishFragment.java | 23 ++++++++++--------- 2 files changed, 21 insertions(+), 14 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 755236bd..95bf8181 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -2915,11 +2915,17 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener public static void requestPermission(String permission, int requestCode, String rationale, Context context, boolean forceRequest) { if (ContextCompat.checkSelfPermission(context, permission) != PackageManager.PERMISSION_GRANTED) { - if (!forceRequest && ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) { - Toast.makeText(context, rationale, Toast.LENGTH_LONG).show(); - } else { + if (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) { + if (context instanceof MainActivity) { + ((MainActivity) context).showMessage(rationale); + } + } else if (forceRequest) { startingPermissionRequest = true; ActivityCompat.requestPermissions((Activity) context, new String[] { permission }, requestCode); + } else { + if (context instanceof MainActivity) { + ((MainActivity) context).showError(rationale); + } } } } diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java index 8ec12b4e..d0603176 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java @@ -255,7 +255,9 @@ public class PublishFragment extends BaseFragment implements } } - checkStoragePermissionAndLoadVideos(); + if (!storageRefusedOnce) { + checkStoragePermissionAndLoadVideos(); + } } @SuppressLint("RestrictedApi") @@ -394,22 +396,21 @@ public class PublishFragment extends BaseFragment implements } if (launchFilePickerPending) { launchFilePickerPending = false; - launchFilePicker(); + launchFilePicker();e } } @Override public void onStoragePermissionRefused() { - if (!storageRefusedOnce) { - View root = getView(); - if (root != null) { - Snackbar.make(root, R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); - Helper.setViewText(noVideosLoaded, R.string.storage_permission_rationale_videos); - checkNoVideosLoaded(); - } - storageRefusedOnce = true; + storageRefusedOnce = true; + View root = getView(); + if (root != null) { + Snackbar.make(root, R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + Helper.setViewText(noVideosLoaded, R.string.storage_permission_rationale_videos); } + + checkNoVideosLoaded(); } public String getSuggestedPublishUrl() { -- 2.45.2 From 7cf9de8c2aab46dbdc2341f245449e43190a73ed Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 23:01:00 +0100 Subject: [PATCH 05/16] fix typo --- .../main/java/io/lbry/browser/ui/publish/PublishFragment.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java index d0603176..3e1668fb 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java @@ -396,7 +396,7 @@ public class PublishFragment extends BaseFragment implements } if (launchFilePickerPending) { launchFilePickerPending = false; - launchFilePicker();e + launchFilePicker(); } } -- 2.45.2 From 6c63eb7d66829dc90940a6844916b7c2ab597945 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 23:11:09 +0100 Subject: [PATCH 06/16] better handling of permanent storage permission denial on file view page --- .../ui/findcontent/FileViewFragment.java | 26 +++++++++++++++++-- .../browser/ui/publish/PublishFragment.java | 7 +++-- 2 files changed, 27 insertions(+), 6 deletions(-) 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 b86c13e1..6931e898 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 @@ -175,6 +175,7 @@ public class FileViewFragment extends BaseFragment implements private long startTimeMillis; private GetFileTask getFileTask; + private boolean storagePermissionRefusedOnce; private View buttonPublishSomething; private View layoutLoadingState; private View layoutNothingAtLocation; @@ -1022,6 +1023,12 @@ public class FileViewFragment extends BaseFragment implements if (MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { startDownload(); } else { + if (storagePermissionRefusedOnce) { + showStoragePermissionRefusedError(); + restoreMainActionButton(); + return; + } + startDownloadPending = true; MainActivity.requestPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE, @@ -1035,6 +1042,12 @@ public class FileViewFragment extends BaseFragment implements private void checkStoragePermissionAndFileGet() { Context context = getContext(); if (!MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) { + if (storagePermissionRefusedOnce) { + showStoragePermissionRefusedError(); + restoreMainActionButton(); + return; + } + fileGetPending = true; MainActivity.requestPermission( Manifest.permission.WRITE_EXTERNAL_STORAGE, @@ -1082,11 +1095,12 @@ public class FileViewFragment extends BaseFragment implements } } public void onStoragePermissionRefused() { + storagePermissionRefusedOnce = true; fileGetPending = false; startDownloadPending = false; onDownloadAborted(); - Snackbar.make(getView(), R.string.storage_permission_rationale_download, Snackbar.LENGTH_LONG). - setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + + showStoragePermissionRefusedError(); } public void startDownload() { @@ -2370,4 +2384,12 @@ public class FileViewFragment extends BaseFragment implements playerView.setVisibility(View.VISIBLE); } } + + private void showStoragePermissionRefusedError() { + View root = getView(); + if (root != null) { + Snackbar.make(root, R.string.storage_permission_rationale_download, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); + } + } } diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java index 3e1668fb..d2dff01b 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFragment.java @@ -12,7 +12,6 @@ import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.TextView; -import android.widget.Toast; import androidx.annotation.NonNull; import androidx.camera.core.Camera; @@ -53,7 +52,7 @@ public class PublishFragment extends BaseFragment implements CameraPermissionListener, FilePickerListener, StoragePermissionListener { private boolean cameraPreviewInitialized; - private boolean storageRefusedOnce; + private boolean storagePermissionRefusedOnce; private PreviewView cameraPreview; private RecyclerView galleryGrid; private GalleryGridAdapter adapter; @@ -255,7 +254,7 @@ public class PublishFragment extends BaseFragment implements } } - if (!storageRefusedOnce) { + if (!storagePermissionRefusedOnce) { checkStoragePermissionAndLoadVideos(); } } @@ -402,7 +401,7 @@ public class PublishFragment extends BaseFragment implements @Override public void onStoragePermissionRefused() { - storageRefusedOnce = true; + storagePermissionRefusedOnce = true; View root = getView(); if (root != null) { Snackbar.make(root, R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG). -- 2.45.2 From 83a41ca6ce2db9a569e29edeebee0a96044fbd42 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 23:16:25 +0100 Subject: [PATCH 07/16] auto-rotate video to sensor landscape orientation --- app/src/main/java/io/lbry/browser/MainActivity.java | 4 +++- .../java/io/lbry/browser/ui/findcontent/FileViewFragment.java | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/MainActivity.java b/app/src/main/java/io/lbry/browser/MainActivity.java index 95bf8181..71b05652 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -395,7 +395,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener return ViewCompat.onApplyWindowInsets(v, insets.replaceSystemWindowInsets( - insets.getSystemWindowInsetLeft(), + 0, 0, 0, insets.getSystemWindowInsetBottom())); @@ -1388,6 +1388,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener } findViewById(R.id.global_sdk_initializing_status).setVisibility(View.GONE); findViewById(R.id.app_bar_main_container).setFitsSystemWindows(false); + lockDrawer(); View decorView = getWindow().getDecorView(); decorView.setSystemUiVisibility( @@ -1424,6 +1425,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener if (actionBar != null) { actionBar.show(); } + unlockDrawer(); inFullscreenMode = false; } 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 6931e898..fc32c947 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 @@ -1915,7 +1915,7 @@ public class FileViewFragment extends BaseFragment implements int statusBarHeight = activity.getStatusBarHeight(); exoplayerContainer.setPadding(0, 0, 0, statusBarHeight); - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); } } -- 2.45.2 From 3283b3a60738b9070b60f617660e72912002a61c Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Wed, 27 May 2020 23:22:08 +0100 Subject: [PATCH 08/16] fix channel links on history page --- app/src/main/java/io/lbry/browser/model/Claim.java | 3 +++ 1 file changed, 3 insertions(+) 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 31e8b5fb..640b30a5 100644 --- a/app/src/main/java/io/lbry/browser/model/Claim.java +++ b/app/src/main/java/io/lbry/browser/model/Claim.java @@ -289,6 +289,9 @@ public class Claim { Claim signingChannel = new Claim(); signingChannel.setClaimId(viewHistory.getPublisherClaimId()); signingChannel.setName(viewHistory.getPublisherName()); + + LbryUri channelUrl = LbryUri.tryParse(String.format("%s#%s", signingChannel.getName(), signingChannel.getClaimId())); + signingChannel.setPermanentUrl(channelUrl != null ? channelUrl.toString() : null); if (!Helper.isNullOrEmpty(viewHistory.getPublisherTitle())) { GenericMetadata channelValue = new GenericMetadata(); channelValue.setTitle(viewHistory.getPublisherTitle()); -- 2.45.2 From ddeb209d515181e821b1fac70f075db0353ea79c Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 28 May 2020 03:22:20 +0100 Subject: [PATCH 09/16] fix publish release time and crash bug on publish form --- .../browser/adapter/InlineChannelSpinnerAdapter.java | 2 +- .../io/lbry/browser/tasks/claim/PublishClaimTask.java | 8 ++++++++ .../io/lbry/browser/ui/publish/PublishFormFragment.java | 9 +++++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java index 9924a67a..e3713b58 100644 --- a/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java @@ -44,7 +44,7 @@ public class InlineChannelSpinnerAdapter extends ArrayAdapter { public int getItemPosition(Claim item) { for (int i = 0; i < channels.size(); i++) { Claim channel = channels.get(i); - if (item.getClaimId().equalsIgnoreCase(channel.getClaimId())) { + if (item.getClaimId() != null && item.getClaimId().equalsIgnoreCase(channel.getClaimId())) { return i; } } diff --git a/app/src/main/java/io/lbry/browser/tasks/claim/PublishClaimTask.java b/app/src/main/java/io/lbry/browser/tasks/claim/PublishClaimTask.java index 418f114b..d5e59397 100644 --- a/app/src/main/java/io/lbry/browser/tasks/claim/PublishClaimTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/claim/PublishClaimTask.java @@ -73,6 +73,14 @@ public class PublishClaimTask extends AsyncTask { options.put("license_url", metadata.getLicenseUrl()); } + if (metadata.getReleaseTime() > 0) { + options.put("release_time", metadata.getReleaseTime()); + } else if (claim.getTimestamp() > 0) { + options.put("release_time", claim.getTimestamp()); + } else { + options.put("release_time", Double.valueOf(Math.floor(System.currentTimeMillis() / 1000.0)).intValue()); + } + Claim claimResult = null; try { JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PUBLISH, options); diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index a8cb1580..f67776d4 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java @@ -1038,6 +1038,15 @@ public class PublishFormFragment extends BaseFragment implements metadata.setLicenseUrl(selectedLicense.getUrl()); } + // set release time from current claim (on edit) + if (currentClaim != null) { + Claim.StreamMetadata currentMetadata = (Claim.StreamMetadata) currentClaim.getValue(); + metadata.setReleaseTime(currentMetadata.getReleaseTime()); + if (metadata.getReleaseTime() == 0) { + metadata.setReleaseTime(currentClaim.getTimestamp()); + } + } + claim.setValueType(Claim.TYPE_STREAM); claim.setValue(metadata); -- 2.45.2 From e6a5d97fb835baf5b1d7fee14115a1076b8727ee Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 28 May 2020 03:23:45 +0100 Subject: [PATCH 10/16] bumpversion 0.15.8 --> 0.15.9 --- app/build.gradle | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/build.gradle b/app/build.gradle index 73499098..eb6de88c 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId "io.lbry.browser" minSdkVersion 21 targetSdkVersion 29 - versionCode 1508 - versionName "0.15.8" + versionCode 1509 + versionName "0.15.9" testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" } -- 2.45.2 From e6861c8436059579e870031eb5ae52b3c9c45420 Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 28 May 2020 03:25:42 +0100 Subject: [PATCH 11/16] set timestamp when building claim object from edited claim --- .../java/io/lbry/browser/ui/publish/PublishFormFragment.java | 1 + 1 file changed, 1 insertion(+) diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index f67776d4..0c5a259e 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java @@ -1045,6 +1045,7 @@ public class PublishFormFragment extends BaseFragment implements if (metadata.getReleaseTime() == 0) { metadata.setReleaseTime(currentClaim.getTimestamp()); } + claim.setTimestamp(currentClaim.getTimestamp()); } claim.setValueType(Claim.TYPE_STREAM); -- 2.45.2 From a40c160ac673a12e13b9f60ad52cbf33edd1de4b Mon Sep 17 00:00:00 2001 From: Akinwale Ariwodola Date: Thu, 28 May 2020 03:45:56 +0100 Subject: [PATCH 12/16] fix selection mode for reposts on Publishes page --- .../main/java/io/lbry/browser/adapter/ClaimListAdapter.java | 2 +- .../java/io/lbry/browser/ui/publish/PublishesFragment.java | 3 ++- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java index 96963112..15651a8d 100644 --- a/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java +++ b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java @@ -327,7 +327,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter Date: Thu, 28 May 2020 03:16:56 -0400 Subject: [PATCH 13/16] Added ability to read comments on claims --- .../browser/adapter/CommentListAdapter.java | 52 +++++++++++ .../java/io/lbry/browser/model/Comment.java | 53 +++++++++++ .../browser/tasks/CommentListHandler.java | 10 +++ .../lbry/browser/tasks/CommentListTask.java | 73 +++++++++++++++ .../ui/findcontent/FileViewFragment.java | 68 +++++++++++++- .../main/java/io/lbry/browser/utils/Lbry.java | 2 + .../main/res/layout/fragment_file_view.xml | 88 +++++++++++++++++-- app/src/main/res/layout/list_item_comment.xml | 36 ++++++++ app/src/main/res/values/strings.xml | 3 + 9 files changed, 373 insertions(+), 12 deletions(-) create mode 100644 app/src/main/java/io/lbry/browser/adapter/CommentListAdapter.java create mode 100644 app/src/main/java/io/lbry/browser/model/Comment.java create mode 100644 app/src/main/java/io/lbry/browser/tasks/CommentListHandler.java create mode 100644 app/src/main/java/io/lbry/browser/tasks/CommentListTask.java create mode 100644 app/src/main/res/layout/list_item_comment.xml diff --git a/app/src/main/java/io/lbry/browser/adapter/CommentListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/CommentListAdapter.java new file mode 100644 index 00000000..128b6a54 --- /dev/null +++ b/app/src/main/java/io/lbry/browser/adapter/CommentListAdapter.java @@ -0,0 +1,52 @@ +package io.lbry.browser.adapter; + +import android.content.Context; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import java.util.List; + +import androidx.recyclerview.widget.RecyclerView; +import io.lbry.browser.R; +import io.lbry.browser.model.Comment; + +public class CommentListAdapter extends RecyclerView.Adapter { + private List items; + private Context context; + + public CommentListAdapter(List items, Context context) { + this.items = items; + this.context = context; + } + + @Override + public int getItemCount() { + return items != null ? items.size() : 0; + } + + public static class ViewHolder extends RecyclerView.ViewHolder { + protected TextView channelName; + protected TextView commentText; + + public ViewHolder (View v) { + super(v); + channelName = v.findViewById(R.id.comment_channel_name); + commentText = v.findViewById(R.id.comment_text); + } + } + + @Override + public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + View v = LayoutInflater.from(context).inflate(R.layout.list_item_comment, parent, false); + return new CommentListAdapter.ViewHolder(v); + } + + @Override + public void onBindViewHolder(ViewHolder holder, int position) { + Comment comment = items.get(position); + holder.channelName.setText(comment.getChannelName()); + holder.commentText.setText(comment.getText()); + } +} \ No newline at end of file diff --git a/app/src/main/java/io/lbry/browser/model/Comment.java b/app/src/main/java/io/lbry/browser/model/Comment.java new file mode 100644 index 00000000..f43e45ac --- /dev/null +++ b/app/src/main/java/io/lbry/browser/model/Comment.java @@ -0,0 +1,53 @@ +package io.lbry.browser.model; + +import android.util.Log; + +import org.json.JSONException; +import org.json.JSONObject; + +import androidx.annotation.NonNull; + +public class Comment { + private String channelName, text, id, parentId; + + public Comment(String channelName, String text, String id, String parentId) { + this.channelName = channelName; + this.text = text; + this.id = id; + this.parentId = parentId; + } + + public static Comment fromJSONObject(JSONObject jsonObject) { + try { + String parentId = null; + if (jsonObject.has("parent_id")) { + parentId = jsonObject.getString("parent_id"); + } + + return new Comment( + jsonObject.getString("channel_name"), + jsonObject.getString("comment"), + jsonObject.getString("comment_id"), + parentId + ); + } catch (JSONException ex) { + // TODO: Throw exception + Log.e("Comments", ex.toString()); + return null; + } + } + + @NonNull + @Override + public String toString() { + return "Channel: " + channelName + " text: " + text + " id: " + id + " parentId: " + parentId; + } + + public String getText() { + return text; + } + + public String getChannelName() { + return channelName; + } +} diff --git a/app/src/main/java/io/lbry/browser/tasks/CommentListHandler.java b/app/src/main/java/io/lbry/browser/tasks/CommentListHandler.java new file mode 100644 index 00000000..a84a8585 --- /dev/null +++ b/app/src/main/java/io/lbry/browser/tasks/CommentListHandler.java @@ -0,0 +1,10 @@ +package io.lbry.browser.tasks; + +import java.util.List; + +import io.lbry.browser.model.Comment; + +public interface CommentListHandler { + void onSuccess(List comments); + void onError(Exception error); +} diff --git a/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java new file mode 100644 index 00000000..089c02fa --- /dev/null +++ b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java @@ -0,0 +1,73 @@ +package io.lbry.browser.tasks; + +import android.os.AsyncTask; +import android.view.View; +import android.widget.ProgressBar; + +import org.json.JSONArray; +import org.json.JSONObject; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import io.lbry.browser.model.Comment; +import io.lbry.browser.utils.Helper; +import io.lbry.browser.utils.Lbry; + +public class CommentListTask extends AsyncTask> { + private String claim; + private ProgressBar progressBar; + private CommentListHandler handler; + private Exception error; + + public CommentListTask(String claim, ProgressBar progressBar, CommentListHandler handler) { + this.claim = claim; + this.progressBar = progressBar; + this.handler = handler; + } + + protected void onPreExecute() { + Helper.setViewVisibility(progressBar, View.VISIBLE); + } + + protected List doInBackground(Void... voids) { + List comments = null; + + try { + Map options = new HashMap<>(); + + options.put("claim_id", claim); + options.put("page", 1); + options.put("page_size", 999); + options.put("include_replies", false); + options.put("is_channel_signature_valid", true); + options.put("visible", true); + options.put("hidden", false); + + JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_COMMENT_LIST, options); + JSONArray items = result.getJSONArray("items"); + comments = new ArrayList<>(); + for (int i = 0; i < items.length(); i++) { + comments.add(Comment.fromJSONObject(items.getJSONObject(i))); + } + } catch (Exception ex) { + error = ex; + } + return comments; + } + + protected void onPostExecute(List comments) { + Helper.setViewVisibility(progressBar, View.GONE); + if (handler != null) { + if (comments != null && error == null) { + handler.onSuccess(comments); + } else { + handler.onError(error); + if (error != null) { + } + } + } + } +} 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 61e328b7..2d1771ea 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 @@ -91,6 +91,7 @@ import java.util.concurrent.TimeUnit; import io.lbry.browser.MainActivity; import io.lbry.browser.R; import io.lbry.browser.adapter.ClaimListAdapter; +import io.lbry.browser.adapter.CommentListAdapter; import io.lbry.browser.adapter.TagListAdapter; import io.lbry.browser.dialog.RepostClaimDialogFragment; import io.lbry.browser.dialog.SendTipDialogFragment; @@ -103,6 +104,7 @@ import io.lbry.browser.listener.StoragePermissionListener; import io.lbry.browser.listener.WalletBalanceListener; import io.lbry.browser.model.Claim; import io.lbry.browser.model.ClaimCacheKey; +import io.lbry.browser.model.Comment; import io.lbry.browser.model.Fee; import io.lbry.browser.model.LbryFile; import io.lbry.browser.model.NavMenuItem; @@ -111,6 +113,8 @@ import io.lbry.browser.model.UrlSuggestion; import io.lbry.browser.model.WalletBalance; import io.lbry.browser.model.lbryinc.Reward; import io.lbry.browser.model.lbryinc.Subscription; +import io.lbry.browser.tasks.CommentListHandler; +import io.lbry.browser.tasks.CommentListTask; import io.lbry.browser.tasks.GenericTaskHandler; import io.lbry.browser.tasks.LighthouseSearchTask; import io.lbry.browser.tasks.ReadTextFileTask; @@ -163,6 +167,7 @@ public class FileViewFragment extends BaseFragment implements private Claim claim; private String currentUrl; private ClaimListAdapter relatedContentAdapter; + private CommentListAdapter commentListAdapter; private BroadcastReceiver sdkReceiver; private Player.EventListener fileViewPlayerListener; @@ -314,6 +319,7 @@ public class FileViewFragment extends BaseFragment implements if (claim != null) { Helper.saveViewHistory(currentUrl, claim); checkAndLoadRelatedContent(); + checkAndLoadComments(); renderClaim(); if (claim.getFile() == null) { loadFile(); @@ -448,6 +454,7 @@ public class FileViewFragment extends BaseFragment implements loadFile(); } checkOwnClaim(); + checkAndLoadComments(); } private String getStreamingUrl() { @@ -529,6 +536,7 @@ public class FileViewFragment extends BaseFragment implements if (claim != null) { Helper.saveViewHistory(url, claim); checkAndLoadRelatedContent(); + checkAndLoadComments(); renderClaim(); } } @@ -568,7 +576,7 @@ public class FileViewFragment extends BaseFragment implements loadAndScheduleDurations(); } - if (Lbry.SDK_READY) { + if (!Lbry.SDK_READY) { if (context instanceof MainActivity) { ((MainActivity) context).addSdkStatusListener(this); } @@ -648,6 +656,7 @@ public class FileViewFragment extends BaseFragment implements loadFile(); checkAndLoadRelatedContent(); + checkAndLoadComments(); renderClaim(); } else { // render nothing at location @@ -985,9 +994,13 @@ public class FileViewFragment extends BaseFragment implements }); RecyclerView relatedContentList = root.findViewById(R.id.file_view_related_content_list); + RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list); relatedContentList.setNestedScrollingEnabled(false); - LinearLayoutManager llm = new LinearLayoutManager(getContext()); - relatedContentList.setLayoutManager(llm); + commentsList.setNestedScrollingEnabled(false); + LinearLayoutManager relatedContentListLLM = new LinearLayoutManager(getContext()); + LinearLayoutManager commentsListLLM = new LinearLayoutManager(getContext()); + relatedContentList.setLayoutManager(relatedContentListLLM); + commentsList.setLayoutManager(commentsListLLM); } private void deleteCurrentClaim() { @@ -1300,6 +1313,22 @@ public class FileViewFragment extends BaseFragment implements } } + private void checkAndLoadComments() { + View root = getView(); + if (root != null) { + RecyclerView commentsList = root.findViewById(R.id.file_view_comments_list); + if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) { + TextView commentsSDKInitializing = root.findViewById(R.id.file_view_comments_sdk_initializing); + if (Lbry.SDK_READY) { + Helper.setViewVisibility(commentsSDKInitializing, View.GONE); + loadComments(); + } else { + Helper.setViewVisibility(commentsSDKInitializing, View.VISIBLE); + } + } + } + } + private void showUnsupportedView() { View root = getView(); if (root != null) { @@ -1839,6 +1868,39 @@ public class FileViewFragment extends BaseFragment implements } } + private void loadComments() { + View root = getView(); + ProgressBar relatedLoading = root.findViewById(R.id.file_view_comments_progress); + if (claim != null && root != null) { + CommentListTask relatedTask = new CommentListTask(claim.getClaimId(), relatedLoading, new CommentListHandler() { + @Override + public void onSuccess(List comments) { + Context ctx = getContext(); + if (ctx != null) { + commentListAdapter = new CommentListAdapter(comments, ctx); + + View v = getView(); + if (v != null) { + RecyclerView relatedContentList = root.findViewById(R.id.file_view_comments_list); + relatedContentList.setAdapter(commentListAdapter); + commentListAdapter.notifyDataSetChanged(); + + Helper.setViewVisibility( + v.findViewById(R.id.file_view_no_comments), + commentListAdapter == null || commentListAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE); + } + } + } + + @Override + public void onError(Exception error) { + + } + }); + relatedTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR); + } + } + public boolean onBackPressed() { if (isInFullscreenMode()) { disableFullScreenMode(); 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 4e7c8046..c9ff7460 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbry.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbry.java @@ -102,6 +102,8 @@ public final class Lbry { public static final String METHOD_STREAM_ABANDON = "stream_abandon"; public static final String METHOD_STREAM_REPOST = "stream_repost"; + public static final String METHOD_COMMENT_LIST = "comment_list"; + public static KeyStore KEYSTORE; public static boolean SDK_READY = false; diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index ad9a6cc4..1a9a6d3f 100644 --- a/app/src/main/res/layout/fragment_file_view.xml +++ b/app/src/main/res/layout/fragment_file_view.xml @@ -480,23 +480,24 @@ android:layout_height="wrap_content" android:layout_marginLeft="16dp" android:layout_marginRight="16dp"> + + android:layout_height="wrap_content" + android:clickable="true" + android:orientation="vertical"> + + android:textColor="@color/lbryGreen" + android:textFontWeight="600" + android:textSize="14sp" /> + + + + + + + + + + + + + + + + + diff --git a/app/src/main/res/layout/list_item_comment.xml b/app/src/main/res/layout/list_item_comment.xml new file mode 100644 index 00000000..a4e78a55 --- /dev/null +++ b/app/src/main/res/layout/list_item_comment.xml @@ -0,0 +1,36 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 3774caca..6d742a0d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -59,6 +59,9 @@ Report Loading decentralized data... Related Content + Comments + No comments to display. + Comments will display once the background service is done initializing. Share LBRY content View Play -- 2.45.2 From e88706e500a29a7225c9f2741f5a62b8375b335e Mon Sep 17 00:00:00 2001 From: Clayton Hickey Date: Thu, 28 May 2020 19:28:48 -0400 Subject: [PATCH 14/16] Switched to lombok to replace boilerplate methods for Comment class --- .../java/io/lbry/browser/model/Comment.java | 19 +++---------------- 1 file changed, 3 insertions(+), 16 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/model/Comment.java b/app/src/main/java/io/lbry/browser/model/Comment.java index f43e45ac..c1f6ca72 100644 --- a/app/src/main/java/io/lbry/browser/model/Comment.java +++ b/app/src/main/java/io/lbry/browser/model/Comment.java @@ -5,10 +5,11 @@ import android.util.Log; import org.json.JSONException; import org.json.JSONObject; -import androidx.annotation.NonNull; +import lombok.Data; +@Data public class Comment { - private String channelName, text, id, parentId; + private final String channelName, text, id, parentId; public Comment(String channelName, String text, String id, String parentId) { this.channelName = channelName; @@ -36,18 +37,4 @@ public class Comment { return null; } } - - @NonNull - @Override - public String toString() { - return "Channel: " + channelName + " text: " + text + " id: " + id + " parentId: " + parentId; - } - - public String getText() { - return text; - } - - public String getChannelName() { - return channelName; - } } -- 2.45.2 From 9e6acd9a0d986e77846c206cd866c759970f8db1 Mon Sep 17 00:00:00 2001 From: Clayton Hickey Date: Thu, 28 May 2020 20:42:00 -0400 Subject: [PATCH 15/16] Added simple handling for pagination in CommentListTask --- .../java/io/lbry/browser/tasks/CommentListTask.java | 12 ++++++++---- .../browser/ui/findcontent/FileViewFragment.java | 2 +- 2 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java index 089c02fa..e64f0308 100644 --- a/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java +++ b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java @@ -17,12 +17,16 @@ import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Lbry; public class CommentListTask extends AsyncTask> { - private String claim; + private final int page; + private final int pageSize; + private final String claim; private ProgressBar progressBar; private CommentListHandler handler; private Exception error; - public CommentListTask(String claim, ProgressBar progressBar, CommentListHandler handler) { + public CommentListTask(int page, int pageSize, String claim, ProgressBar progressBar, CommentListHandler handler) { + this.page = page; + this.pageSize = pageSize; this.claim = claim; this.progressBar = progressBar; this.handler = handler; @@ -39,8 +43,8 @@ public class CommentListTask extends AsyncTask> { Map options = new HashMap<>(); options.put("claim_id", claim); - options.put("page", 1); - options.put("page_size", 999); + options.put("page", page); + options.put("page_size", pageSize); options.put("include_replies", false); options.put("is_channel_signature_valid", true); options.put("visible", true); 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 2d1771ea..ae81c05e 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 @@ -1872,7 +1872,7 @@ public class FileViewFragment extends BaseFragment implements View root = getView(); ProgressBar relatedLoading = root.findViewById(R.id.file_view_comments_progress); if (claim != null && root != null) { - CommentListTask relatedTask = new CommentListTask(claim.getClaimId(), relatedLoading, new CommentListHandler() { + CommentListTask relatedTask = new CommentListTask(1, 999, claim.getClaimId(), relatedLoading, new CommentListHandler() { @Override public void onSuccess(List comments) { Context ctx = getContext(); -- 2.45.2 From c1853b88427b78e738fa5efd68c444ba375621ef Mon Sep 17 00:00:00 2001 From: Clayton Hickey Date: Thu, 28 May 2020 20:52:47 -0400 Subject: [PATCH 16/16] Remove unnecessary top margin on the divider between relatec content and comments in fragment_file_view --- app/src/main/res/layout/fragment_file_view.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index 1a9a6d3f..9e335b04 100644 --- a/app/src/main/res/layout/fragment_file_view.xml +++ b/app/src/main/res/layout/fragment_file_view.xml @@ -612,12 +612,12 @@ android:layout_width="match_parent" android:layout_height="wrap_content" /> + + android:background="@color/divider" />