diff --git a/app/build.gradle b/app/build.gradle index eb6de88c..c4496697 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -16,8 +16,8 @@ android { applicationId "io.lbry.browser" minSdkVersion 21 targetSdkVersion 29 - versionCode 1509 - versionName "0.15.9" + versionCode 1507 + versionName "0.15.7" 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 df618fe5..b4d42ee4 100644 --- a/app/src/main/java/io/lbry/browser/FirstRunActivity.java +++ b/app/src/main/java/io/lbry/browser/FirstRunActivity.java @@ -10,6 +10,7 @@ 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; @@ -19,11 +20,10 @@ 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 sdkReceiver; + private BroadcastReceiver sdkReadyReceiver; private BroadcastReceiver authReceiver; @Override @@ -45,26 +45,19 @@ 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() { @@ -129,7 +122,7 @@ public class FirstRunActivity extends AppCompatActivity { @Override protected void onDestroy() { Helper.unregisterReceiver(authReceiver, this); - Helper.unregisterReceiver(sdkReceiver, this); + Helper.unregisterReceiver(sdkReadyReceiver, 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 71b05652..eace68dd 100644 --- a/app/src/main/java/io/lbry/browser/MainActivity.java +++ b/app/src/main/java/io/lbry/browser/MainActivity.java @@ -115,7 +115,6 @@ 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; @@ -317,7 +316,6 @@ 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; @@ -395,7 +393,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener return ViewCompat.onApplyWindowInsets(v, insets.replaceSystemWindowInsets( - 0, + insets.getSystemWindowInsetLeft(), 0, 0, insets.getSystemWindowInsetBottom())); @@ -428,7 +426,6 @@ 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<>(); @@ -601,16 +598,6 @@ 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); @@ -821,10 +808,6 @@ 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); @@ -855,9 +838,6 @@ 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); @@ -941,6 +921,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener applyNavbarSigninPadding(); checkFirstRun(); checkNowPlaying(); + fetchRewards(); // check (and start) the LBRY SDK service serviceRunning = isServiceRunning(this, LbrynetService.class); @@ -1016,7 +997,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, true); + return sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_URL_SUGGESTIONS, false); } public boolean keepSdkBackground() { @@ -1388,7 +1369,6 @@ 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( @@ -1425,7 +1405,6 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener if (actionBar != null) { actionBar.show(); } - unlockDrawer(); inFullscreenMode = false; } @@ -1443,18 +1422,13 @@ 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)); - return; - } - - if (!appStarted) { + } else if (!appStarted) { // first run completed, startup startup(); return; } - fetchRewards(); if (getSupportFragmentManager().getBackStackEntryCount() == 0) { openFragment(FollowingFragment.class, false, NavMenuItem.ID_ITEM_FOLLOWING); } @@ -1518,11 +1492,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener initFloatingWalletBalance(); - SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(this); - boolean firstRunCompleted = sp.getBoolean(PREFERENCE_KEY_INTERNAL_FIRST_RUN_COMPLETED, false); - if (firstRunCompleted) { - checkAndClaimNewAndroidReward(); - } + checkAndClaimNewAndroidReward(); } public void checkAndClaimNewAndroidReward() { @@ -2226,7 +2196,6 @@ 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(); } @@ -2917,17 +2886,11 @@ 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 (ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) { - if (context instanceof MainActivity) { - ((MainActivity) context).showMessage(rationale); - } - } else if (forceRequest) { + if (!forceRequest && ActivityCompat.shouldShowRequestPermissionRationale((Activity) context, permission)) { + Toast.makeText(context, rationale, Toast.LENGTH_LONG).show(); + } else { 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/VerificationActivity.java b/app/src/main/java/io/lbry/browser/VerificationActivity.java index 32324e8d..cf819cb6 100644 --- a/app/src/main/java/io/lbry/browser/VerificationActivity.java +++ b/app/src/main/java/io/lbry/browser/VerificationActivity.java @@ -1,9 +1,6 @@ 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; @@ -21,10 +18,8 @@ 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 { @@ -32,7 +27,6 @@ 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; @@ -60,19 +54,6 @@ 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); @@ -288,10 +269,4 @@ 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/adapter/ClaimListAdapter.java b/app/src/main/java/io/lbry/browser/adapter/ClaimListAdapter.java index 15651a8d..96963112 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 { + 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/adapter/InlineChannelSpinnerAdapter.java b/app/src/main/java/io/lbry/browser/adapter/InlineChannelSpinnerAdapter.java index e3713b58..9924a67a 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() != null && item.getClaimId().equalsIgnoreCase(channel.getClaimId())) { + if (item.getClaimId().equalsIgnoreCase(channel.getClaimId())) { return i; } } diff --git a/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java b/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java deleted file mode 100644 index 0638e6be..00000000 --- a/app/src/main/java/io/lbry/browser/listener/PIPModeListener.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.lbry.browser.listener; - -public interface PIPModeListener { - void onEnterPIPMode(); - void onExitPIPMode(); -} 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 640b30a5..31e8b5fb 100644 --- a/app/src/main/java/io/lbry/browser/model/Claim.java +++ b/app/src/main/java/io/lbry/browser/model/Claim.java @@ -289,9 +289,6 @@ 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()); 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..c1f6ca72 --- /dev/null +++ b/app/src/main/java/io/lbry/browser/model/Comment.java @@ -0,0 +1,40 @@ +package io.lbry.browser.model; + +import android.util.Log; + +import org.json.JSONException; +import org.json.JSONObject; + +import lombok.Data; + +@Data +public class Comment { + private final 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; + } + } +} 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..e64f0308 --- /dev/null +++ b/app/src/main/java/io/lbry/browser/tasks/CommentListTask.java @@ -0,0 +1,77 @@ +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 final int page; + private final int pageSize; + private final String claim; + private ProgressBar progressBar; + private CommentListHandler handler; + private Exception error; + + 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; + } + + 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", page); + options.put("page_size", pageSize); + 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/tasks/claim/PublishClaimTask.java b/app/src/main/java/io/lbry/browser/tasks/claim/PublishClaimTask.java index d5e59397..418f114b 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,14 +73,6 @@ 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/findcontent/FileViewFragment.java b/app/src/main/java/io/lbry/browser/ui/findcontent/FileViewFragment.java index fc32c947..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 @@ -9,6 +9,7 @@ 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; @@ -30,6 +31,7 @@ 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; @@ -89,19 +91,20 @@ 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; 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; 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; @@ -110,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; @@ -139,10 +144,8 @@ 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, @@ -164,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; @@ -175,7 +179,6 @@ public class FileViewFragment extends BaseFragment implements private long startTimeMillis; private GetFileTask getFileTask; - private boolean storagePermissionRefusedOnce; private View buttonPublishSomething; private View layoutLoadingState; private View layoutNothingAtLocation; @@ -242,7 +245,6 @@ 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)) { @@ -317,6 +319,7 @@ public class FileViewFragment extends BaseFragment implements if (claim != null) { Helper.saveViewHistory(currentUrl, claim); checkAndLoadRelatedContent(); + checkAndLoadComments(); renderClaim(); if (claim.getFile() == null) { loadFile(); @@ -451,6 +454,7 @@ public class FileViewFragment extends BaseFragment implements loadFile(); } checkOwnClaim(); + checkAndLoadComments(); } private String getStreamingUrl() { @@ -532,6 +536,7 @@ public class FileViewFragment extends BaseFragment implements if (claim != null) { Helper.saveViewHistory(url, claim); checkAndLoadRelatedContent(); + checkAndLoadComments(); renderClaim(); } } @@ -571,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); } @@ -587,7 +592,6 @@ 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); @@ -652,6 +656,7 @@ public class FileViewFragment extends BaseFragment implements loadFile(); checkAndLoadRelatedContent(); + checkAndLoadComments(); renderClaim(); } else { // render nothing at location @@ -989,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() { @@ -1023,12 +1032,6 @@ 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, @@ -1042,12 +1045,6 @@ 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, @@ -1095,12 +1092,11 @@ public class FileViewFragment extends BaseFragment implements } } public void onStoragePermissionRefused() { - storagePermissionRefusedOnce = true; fileGetPending = false; startDownloadPending = false; onDownloadAborted(); - - showStoragePermissionRefusedError(); + Snackbar.make(getView(), R.string.storage_permission_rationale_download, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); } public void startDownload() { @@ -1317,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) { @@ -1856,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(1, 999, 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(); @@ -1915,7 +1960,7 @@ public class FileViewFragment extends BaseFragment implements int statusBarHeight = activity.getStatusBarHeight(); exoplayerContainer.setPadding(0, 0, 0, statusBarHeight); - activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE); + activity.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE); } } @@ -2368,28 +2413,4 @@ 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); - } - } - - 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/PublishFormFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishFormFragment.java index 0c5a259e..87a1665f 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,7 +102,6 @@ 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; @@ -1038,16 +1037,6 @@ 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.setTimestamp(currentClaim.getTimestamp()); - } - claim.setValueType(Claim.TYPE_STREAM); claim.setValue(metadata); @@ -1405,10 +1394,7 @@ public class PublishFormFragment extends BaseFragment implements @Override public void onStoragePermissionRefused() { - if (!storageRefusedOnce) { - showError(getString(R.string.storage_permission_rationale_images)); - storageRefusedOnce = true; - } + showError(getString(R.string.storage_permission_rationale_images)); 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 d2dff01b..bd4dd9c8 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,6 +12,7 @@ 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; @@ -52,7 +53,6 @@ public class PublishFragment extends BaseFragment implements CameraPermissionListener, FilePickerListener, StoragePermissionListener { private boolean cameraPreviewInitialized; - private boolean storagePermissionRefusedOnce; private PreviewView cameraPreview; private RecyclerView galleryGrid; private GalleryGridAdapter adapter; @@ -254,9 +254,7 @@ public class PublishFragment extends BaseFragment implements } } - if (!storagePermissionRefusedOnce) { - checkStoragePermissionAndLoadVideos(); - } + checkStoragePermissionAndLoadVideos(); } @SuppressLint("RestrictedApi") @@ -401,15 +399,8 @@ public class PublishFragment extends BaseFragment implements @Override public void onStoragePermissionRefused() { - storagePermissionRefusedOnce = 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(); + Snackbar.make(getView(), R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG). + setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show(); } public String getSuggestedPublishUrl() { diff --git a/app/src/main/java/io/lbry/browser/ui/publish/PublishesFragment.java b/app/src/main/java/io/lbry/browser/ui/publish/PublishesFragment.java index 95ebd1d6..14050b76 100644 --- a/app/src/main/java/io/lbry/browser/ui/publish/PublishesFragment.java +++ b/app/src/main/java/io/lbry/browser/ui/publish/PublishesFragment.java @@ -239,8 +239,7 @@ public class PublishesFragment extends BaseFragment implements ActionMode.Callba @Override public boolean onPrepareActionMode(androidx.appcompat.view.ActionMode actionMode, Menu menu) { int selectionCount = adapter != null ? adapter.getSelectedCount() : 0; - menu.findItem(R.id.action_edit).setVisible(selectionCount == 1 && - Claim.TYPE_STREAM.equalsIgnoreCase(adapter.getSelectedItems().get(0).getValueType())); + menu.findItem(R.id.action_edit).setVisible(selectionCount == 1); return true; } 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/java/io/lbry/browser/utils/Lbryio.java b/app/src/main/java/io/lbry/browser/utils/Lbryio.java index 9ab3cdf9..8b96f6a7 100644 --- a/app/src/main/java/io/lbry/browser/utils/Lbryio.java +++ b/app/src/main/java/io/lbry/browser/utils/Lbryio.java @@ -25,7 +25,6 @@ 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; @@ -82,10 +81,6 @@ 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(); @@ -99,9 +94,6 @@ 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)) { @@ -150,9 +142,6 @@ 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", ""); @@ -161,9 +150,6 @@ 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"); } diff --git a/app/src/main/res/layout/fragment_file_view.xml b/app/src/main/res/layout/fragment_file_view.xml index ad9a6cc4..9e335b04 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