Compare commits
25
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cf97feb9e | ||
|
|
d1faaa9362 | ||
|
|
aad718c714 | ||
|
|
6bed7bfd2f | ||
|
|
df4785fb5f | ||
|
|
9eb7177a15 | ||
|
|
103565d57c | ||
|
|
da4591fb2e | ||
|
|
6ac4a25715 | ||
|
|
b4599ec7c5 | ||
|
|
bc2e8b7ec0 | ||
|
|
2df4d76927 | ||
|
|
f45c517048 | ||
|
|
c78f669fb1 | ||
|
|
78dd587901 | ||
|
|
8cb51f5c17 | ||
|
|
f4b28c4d90 | ||
|
|
cfa7e07eba | ||
|
|
5ceb081972 | ||
|
|
1d1c761d3f | ||
|
|
59584c1be7 | ||
|
|
10175470de | ||
|
|
2604baa221 | ||
|
|
1adf073de6 | ||
|
|
cf052f9c80 |
No files matched your search
@@ -0,0 +1,3 @@
|
||||
.buildozer
|
||||
.buildozer-downloads
|
||||
.gradle
|
||||
+6
-13
@@ -14,8 +14,8 @@ android {
|
||||
applicationId "io.lbry.browser"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 1503
|
||||
versionName "0.15.3"
|
||||
versionCode 1500
|
||||
versionName "0.15.0"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -52,9 +52,9 @@ task printVersionName {
|
||||
dependencies {
|
||||
implementation fileTree(dir: 'libs', include: ['*.jar'])
|
||||
|
||||
implementation 'androidx.appcompat:appcompat:1.2.0-rc01'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.2.0-alpha06'
|
||||
implementation 'com.google.android.material:material:1.1.0'
|
||||
implementation "androidx.cardview:cardview:1.0.0"
|
||||
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
|
||||
implementation 'androidx.navigation:navigation-fragment:2.2.2'
|
||||
@@ -62,10 +62,6 @@ dependencies {
|
||||
implementation 'androidx.lifecycle:lifecycle-extensions:2.2.0'
|
||||
implementation 'androidx.localbroadcastmanager:localbroadcastmanager:1.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.1'
|
||||
implementation 'androidx.camera:camera-camera2:1.0.0-beta03'
|
||||
implementation 'androidx.camera:camera-lifecycle:1.0.0-beta03'
|
||||
implementation 'androidx.camera:camera-view:1.0.0-alpha10'
|
||||
|
||||
implementation 'com.github.bumptech.glide:glide:4.11.0'
|
||||
implementation 'com.squareup.okhttp3:okhttp:4.4.1'
|
||||
implementation 'com.google.firebase:firebase-analytics:17.4.0'
|
||||
@@ -77,7 +73,6 @@ dependencies {
|
||||
implementation 'com.google.android.exoplayer:exoplayer-dash:2.11.4'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-ui:2.11.4'
|
||||
implementation 'com.google.android.exoplayer:extension-cast:2.11.4'
|
||||
implementation 'com.google.android.exoplayer:extension-mediasession:2.11.4'
|
||||
|
||||
implementation 'com.google.android:flexbox:2.0.1'
|
||||
|
||||
@@ -86,8 +81,6 @@ dependencies {
|
||||
implementation 'com.github.chrisbanes:PhotoView:2.3.0'
|
||||
implementation 'com.atlassian.commonmark:commonmark:0.14.0'
|
||||
|
||||
implementation 'com.arthenica:mobile-ffmpeg-full-gpl:4.3.1.LTS'
|
||||
|
||||
compileOnly 'org.projectlombok:lombok:1.18.10'
|
||||
annotationProcessor 'org.projectlombok:lombok:1.18.10'
|
||||
annotationProcessor 'com.github.bumptech.glide:compiler:4.11.0'
|
||||
@@ -96,8 +89,8 @@ dependencies {
|
||||
androidTestImplementation 'androidx.test.ext:junit:1.1.1'
|
||||
androidTestImplementation 'androidx.test.espresso:espresso-core:3.2.0'
|
||||
|
||||
__32bitImplementation files('libs/lbrysdk-0.74.0-release__arm.aar')
|
||||
__64bitImplementation files('libs/lbrysdk-0.74.0-release__arm64.aar')
|
||||
__32bitImplementation files('libs/lbrysdk-0.73.1-release__arm.aar')
|
||||
__64bitImplementation files('libs/lbrysdk-0.73.1-release__arm64.aar')
|
||||
}
|
||||
|
||||
apply plugin: 'com.google.gms.google-services'
|
||||
|
||||
Binary file not shown.
BIN
Binary file not shown.
@@ -3,28 +3,23 @@
|
||||
package="io.lbry.browser"
|
||||
android:installLocation="auto">
|
||||
|
||||
<uses-feature android:name="android.hardware.camera" android:required="false" />
|
||||
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
<uses-permission android:name="android.permission.CAMERA" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
||||
<uses-permission android:name="android.permission.RECORD_AUDIO" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:largeHeap="true"
|
||||
android:requestLegacyExternalStorage="true"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/AppTheme"
|
||||
android:usesCleartextTraffic="true">
|
||||
|
||||
<meta-data android:name="com.google.android.gms.cast.framework.OPTIONS_PROVIDER_CLASS_NAME"
|
||||
android:value="com.google.android.exoplayer2.ext.cast.DefaultCastOptionsProvider"/>
|
||||
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_icon"
|
||||
android:resource="@drawable/ic_lbry" />
|
||||
@@ -43,8 +38,8 @@
|
||||
android:label="@string/app_name"
|
||||
android:supportsPictureInPicture="true"
|
||||
android:theme="@style/AppTheme.NoActionBar"
|
||||
android:launchMode="singleTask"
|
||||
android:windowSoftInputMode="adjustResize">
|
||||
android:launchMode="singleInstance"
|
||||
android:windowSoftInputMode="adjustPan">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
@@ -60,15 +55,22 @@
|
||||
|
||||
<activity
|
||||
android:name=".FirstRunActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleInstance"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBarTranslucent" />
|
||||
<activity
|
||||
android:name=".VerificationActivity"
|
||||
android:launchMode="singleTask"
|
||||
android:launchMode="singleInstance"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:theme="@style/AppTheme.NoActionBarTranslucent"
|
||||
android:windowSoftInputMode="adjustResize" />
|
||||
<activity
|
||||
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
|
||||
android:name=".FileViewActivity"
|
||||
android:launchMode="singleInstance"
|
||||
android:parentActivityName=".MainActivity"
|
||||
android:supportsPictureInPicture="true"
|
||||
android:theme="@style/AppTheme.NoActionBarBlack" />
|
||||
|
||||
<service
|
||||
android:name="io.lbry.browser.LbrynetMessagingService"
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
File diff suppressed because it is too large.
Load diff
@@ -239,8 +239,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
}
|
||||
|
||||
private void showFetchUserError(String message) {
|
||||
Snackbar.make(findViewById(R.id.verification_pager), message, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(findViewById(R.id.verification_pager), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -101,7 +101,7 @@ public class ChannelFilterListAdapter extends RecyclerView.Adapter<ChannelFilter
|
||||
}
|
||||
vh.alphaContainer.setVisibility(claim.isPlaceholder() || Helper.isNullOrEmpty(thumbnailUrl) ? View.VISIBLE : View.GONE);
|
||||
vh.thumbnailView.setVisibility(claim.isPlaceholder() || Helper.isNullOrEmpty(thumbnailUrl) ? View.GONE : View.VISIBLE);
|
||||
vh.alphaView.setText(claim.isPlaceholder() ? null : claim.getName() != null ? claim.getName().substring(1, 2) : "");
|
||||
vh.alphaView.setText(claim.isPlaceholder() ? null : claim.getName().substring(1, 2));
|
||||
|
||||
int bgColor = Helper.generateRandomColorForValue(claim.getClaimId());
|
||||
Helper.setIconViewBackgroundColor(vh.alphaContainer, bgColor, claim.isPlaceholder(), context);
|
||||
|
||||
@@ -6,7 +6,6 @@ import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
@@ -18,18 +17,13 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.listener.SelectionModeListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -38,13 +32,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
private static final int VIEW_TYPE_CHANNEL = 2;
|
||||
private static final int VIEW_TYPE_FEATURED = 3; // featured search result
|
||||
|
||||
private Map<String, Claim> quickClaimIdMap;
|
||||
private Map<String, Claim> quickClaimUrlMap;
|
||||
private Map<String, Boolean> notFoundClaimIdMap;
|
||||
private Map<String, Boolean> notFoundClaimUrlMap;
|
||||
|
||||
@Setter
|
||||
private boolean hideFee;
|
||||
@Setter
|
||||
private boolean canEnterSelectionMode;
|
||||
private Context context;
|
||||
@@ -57,19 +44,11 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
private boolean inSelectionMode;
|
||||
@Setter
|
||||
private SelectionModeListener selectionModeListener;
|
||||
private float scale;
|
||||
|
||||
public ClaimListAdapter(List<Claim> items, Context context) {
|
||||
this.context = context;
|
||||
this.items = new ArrayList<>(items);
|
||||
this.selectedItems = new ArrayList<>();
|
||||
quickClaimIdMap = new HashMap<>();
|
||||
quickClaimUrlMap = new HashMap<>();
|
||||
notFoundClaimIdMap = new HashMap<>();
|
||||
notFoundClaimUrlMap = new HashMap<>();
|
||||
if (context != null) {
|
||||
scale = context.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
}
|
||||
|
||||
public List<Claim> getSelectedItems() {
|
||||
@@ -94,45 +73,12 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
return null;
|
||||
}
|
||||
|
||||
public void removeFeaturedItem() {
|
||||
int featuredIndex = -1;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
if (items.get(i).isFeatured()) {
|
||||
featuredIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (featuredIndex > -1) {
|
||||
items.remove(featuredIndex);
|
||||
}
|
||||
}
|
||||
|
||||
public List<Claim> getItems() {
|
||||
return new ArrayList<>(this.items);
|
||||
}
|
||||
|
||||
public void updateSigningChannelForClaim(Claim resolvedClaim) {
|
||||
for (Claim claim : items) {
|
||||
if (claim.getClaimId().equalsIgnoreCase(resolvedClaim.getClaimId())) {
|
||||
claim.setSigningChannel(resolvedClaim.getSigningChannel());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
clearSelectedItems();
|
||||
this.items.clear();
|
||||
quickClaimIdMap.clear();
|
||||
quickClaimUrlMap.clear();
|
||||
notFoundClaimIdMap.clear();
|
||||
notFoundClaimUrlMap.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public Claim getLastItem() {
|
||||
return items.size() > 0 ? items.get(items.size() - 1) : null;
|
||||
}
|
||||
|
||||
public void addFeaturedItem(Claim claim) {
|
||||
items.add(0, claim);
|
||||
notifyDataSetChanged();
|
||||
@@ -144,9 +90,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
items.add(claim);
|
||||
}
|
||||
}
|
||||
|
||||
notFoundClaimUrlMap.clear();
|
||||
notFoundClaimIdMap.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
public void setItems(List<Claim> claims) {
|
||||
@@ -154,11 +97,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeItems(List<Claim> claims) {
|
||||
items.removeAll(claims);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void removeItem(Claim claim) {
|
||||
items.remove(claim);
|
||||
selectedItems.remove(claim);
|
||||
@@ -180,9 +118,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
protected View repostInfoView;
|
||||
protected TextView repostChannelView;
|
||||
protected View selectedOverlayView;
|
||||
protected TextView fileSizeView;
|
||||
protected ProgressBar downloadProgressView;
|
||||
protected TextView deviceView;
|
||||
public ViewHolder(View v) {
|
||||
super(v);
|
||||
feeContainer = v.findViewById(R.id.claim_fee_container);
|
||||
@@ -199,9 +134,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
repostInfoView = v.findViewById(R.id.claim_repost_info);
|
||||
repostChannelView = v.findViewById(R.id.claim_repost_channel);
|
||||
selectedOverlayView = v.findViewById(R.id.claim_selected_overlay);
|
||||
fileSizeView = v.findViewById(R.id.claim_file_size);
|
||||
downloadProgressView = v.findViewById(R.id.claim_download_progress);
|
||||
deviceView = v.findViewById(R.id.claim_view_device);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -223,68 +155,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
return Claim.TYPE_CHANNEL.equalsIgnoreCase(actualClaim.getValueType()) ? VIEW_TYPE_CHANNEL : VIEW_TYPE_STREAM;
|
||||
}
|
||||
|
||||
public void updateFileForClaimByIdOrUrl(LbryFile file, String claimId, String url) {
|
||||
updateFileForClaimByIdOrUrl(file, claimId, url, false);
|
||||
}
|
||||
public void updateFileForClaimByIdOrUrl(LbryFile file, String claimId, String url, boolean skipNotFound) {
|
||||
if (!skipNotFound) {
|
||||
if (notFoundClaimIdMap.containsKey(claimId) && notFoundClaimUrlMap.containsKey(url)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (quickClaimIdMap.containsKey(claimId)) {
|
||||
quickClaimIdMap.get(claimId).setFile(file);
|
||||
notifyDataSetChanged();
|
||||
return;
|
||||
}
|
||||
if (quickClaimUrlMap.containsKey(claimId)) {
|
||||
quickClaimUrlMap.get(claimId).setFile(file);
|
||||
notifyDataSetChanged();
|
||||
return;
|
||||
}
|
||||
|
||||
boolean claimFound = false;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Claim claim = items.get(i);
|
||||
if (claimId.equalsIgnoreCase(claim.getClaimId()) || url.equalsIgnoreCase(claim.getPermanentUrl())) {
|
||||
quickClaimIdMap.put(claimId, claim);
|
||||
quickClaimUrlMap.put(url, claim);
|
||||
claim.setFile(file);
|
||||
notifyDataSetChanged();
|
||||
claimFound = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!claimFound) {
|
||||
notFoundClaimIdMap.put(claimId, true);
|
||||
notFoundClaimUrlMap.put(url, true);
|
||||
}
|
||||
}
|
||||
public void clearFileForClaimOrUrl(String outpoint, String url) {
|
||||
clearFileForClaimOrUrl(outpoint, url, false);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
public void clearFileForClaimOrUrl(String outpoint, String url, boolean remove) {
|
||||
int claimIndex = -1;
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Claim claim = items.get(i);
|
||||
if (outpoint.equalsIgnoreCase(claim.getOutpoint()) || url.equalsIgnoreCase(claim.getPermanentUrl())) {
|
||||
claimIndex = i;
|
||||
claim.setFile(null);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (remove && claimIndex > -1) {
|
||||
Claim removed = items.remove(claimIndex);
|
||||
selectedItems.remove(removed);
|
||||
}
|
||||
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ClaimListAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
int viewResourceId = -1;
|
||||
@@ -298,18 +168,9 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
return new ClaimListAdapter.ViewHolder(v);
|
||||
}
|
||||
|
||||
public int getScaledValue(int value) {
|
||||
return (int) (value * scale + 0.5f);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ClaimListAdapter.ViewHolder vh, int position) {
|
||||
int type = getItemViewType(position);
|
||||
int paddingTop = position == 0 ? 16 : 8;
|
||||
int paddingBottom = position == getItemCount() - 1 ? 16 : 8;
|
||||
int paddingTopScaled = getScaledValue(paddingTop);
|
||||
int paddingBottomScaled = getScaledValue(paddingBottom);
|
||||
vh.itemView.setPadding(vh.itemView.getPaddingLeft(), paddingTopScaled, vh.itemView.getPaddingRight(), paddingBottomScaled);
|
||||
|
||||
Claim original = items.get(position);
|
||||
boolean isRepost = Claim.TYPE_REPOST.equalsIgnoreCase(original.getValueType());
|
||||
@@ -340,7 +201,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
}
|
||||
|
||||
if (inSelectionMode) {
|
||||
toggleSelectedClaim(original);
|
||||
toggleSelectedClaim(item);
|
||||
} else {
|
||||
if (listener != null) {
|
||||
listener.onClaimClicked(item);
|
||||
@@ -366,7 +227,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
selectionModeListener.onEnterSelectionMode();
|
||||
}
|
||||
}
|
||||
toggleSelectedClaim(original);
|
||||
toggleSelectedClaim(item);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -417,41 +278,17 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
centerCrop().
|
||||
placeholder(R.drawable.bg_thumbnail_placeholder).
|
||||
into(vh.thumbnailView);
|
||||
vh.thumbnailView.setVisibility(View.VISIBLE);
|
||||
} else {
|
||||
vh.thumbnailView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
BigDecimal cost = item.getActualCost(Lbryio.LBCUSDRate);
|
||||
vh.feeContainer.setVisibility(cost.doubleValue() > 0 && !hideFee ? View.VISIBLE : View.GONE);
|
||||
vh.feeView.setText(cost.doubleValue() > 0 ? Helper.shortCurrencyFormat(cost.doubleValue()) : "Paid");
|
||||
BigDecimal cost = streamMetadata != null && streamMetadata.getFee() != null ? new BigDecimal(streamMetadata.getFee().getAmount()) : new BigDecimal(0);
|
||||
vh.feeContainer.setVisibility(cost.doubleValue() > 0 ? View.VISIBLE : View.GONE);
|
||||
vh.feeView.setText(cost.doubleValue() > 0 ? Helper.shortCurrencyFormat(cost.divide(new BigDecimal(100000000)).doubleValue()) : null);
|
||||
vh.alphaView.setText(item.getName().substring(0, Math.min(5, item.getName().length() - 1)));
|
||||
vh.publisherView.setText(signingChannel != null ? signingChannel.getName() : context.getString(R.string.anonymous));
|
||||
vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(
|
||||
publishTime, System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
|
||||
vh.durationView.setVisibility(duration > 0 ? View.VISIBLE : View.GONE);
|
||||
vh.durationView.setText(Helper.formatDuration(duration));
|
||||
|
||||
LbryFile claimFile = item.getFile();
|
||||
boolean isDownloading = false;
|
||||
int progress = 0;
|
||||
String fileSizeString = claimFile == null ? null : Helper.formatBytes(claimFile.getTotalBytes(), false);
|
||||
if (claimFile != null &&
|
||||
!Helper.isNullOrEmpty(claimFile.getDownloadPath()) &&
|
||||
!claimFile.isCompleted() &&
|
||||
claimFile.getWrittenBytes() < claimFile.getTotalBytes()) {
|
||||
isDownloading = true;
|
||||
progress = claimFile.getTotalBytes() > 0 ?
|
||||
Double.valueOf(((double) claimFile.getWrittenBytes() / (double) claimFile.getTotalBytes()) * 100.0).intValue() : 0;
|
||||
fileSizeString = String.format("%s / %s",
|
||||
Helper.formatBytes(claimFile.getWrittenBytes(), false),
|
||||
Helper.formatBytes(claimFile.getTotalBytes(), false));
|
||||
}
|
||||
|
||||
Helper.setViewText(vh.fileSizeView, claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath()) ? fileSizeString : null);
|
||||
Helper.setViewVisibility(vh.downloadProgressView, isDownloading ? View.VISIBLE : View.INVISIBLE);
|
||||
Helper.setViewProgress(vh.downloadProgressView, progress);
|
||||
Helper.setViewText(vh.deviceView, item.getDevice());
|
||||
} else if (Claim.TYPE_CHANNEL.equalsIgnoreCase(item.getValueType())) {
|
||||
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
|
||||
Glide.with(context.getApplicationContext()).
|
||||
|
||||
@@ -1,119 +0,0 @@
|
||||
package io.lbry.browser.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Rect;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.model.GalleryItem;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import lombok.Setter;
|
||||
|
||||
public class GalleryGridAdapter extends RecyclerView.Adapter<GalleryGridAdapter.ViewHolder> {
|
||||
private Context context;
|
||||
private List<GalleryItem> items;
|
||||
@Setter
|
||||
private GalleryItemClickListener listener;
|
||||
|
||||
public GalleryGridAdapter(List<GalleryItem> items, Context context) {
|
||||
this.items = new ArrayList<>(items);
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
protected ImageView thumbnailView;
|
||||
protected TextView durationView;
|
||||
public ViewHolder(View v) {
|
||||
super(v);
|
||||
thumbnailView = v.findViewById(R.id.gallery_item_thumbnail);
|
||||
durationView = v.findViewById(R.id.gallery_item_duration);
|
||||
}
|
||||
}
|
||||
|
||||
public int getItemCount() {
|
||||
return items != null ? items.size() : 0;
|
||||
}
|
||||
|
||||
public void addItem(GalleryItem item) {
|
||||
if (!items.contains(item)) {
|
||||
items.add(item);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void addItems(List<GalleryItem> items) {
|
||||
for (GalleryItem item : items) {
|
||||
if (!this.items.contains(item)) {
|
||||
this.items.add(item);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
items.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public GalleryGridAdapter.ViewHolder onCreateViewHolder(ViewGroup root, int viewType) {
|
||||
View v = LayoutInflater.from(context).inflate(R.layout.list_item_gallery, root, false);
|
||||
return new GalleryGridAdapter.ViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(GalleryGridAdapter.ViewHolder vh, int position) {
|
||||
GalleryItem item = items.get(position);
|
||||
String thumbnailUrl = item.getThumbnailPath();
|
||||
Glide.with(context.getApplicationContext()).load(thumbnailUrl).centerCrop().into(vh.thumbnailView);
|
||||
vh.durationView.setVisibility(item.getDuration() > 0 ? View.VISIBLE : View.INVISIBLE);
|
||||
vh.durationView.setText(item.getDuration() > 0 ? Helper.formatDuration(Double.valueOf(item.getDuration() / 1000.0).longValue()) : null);
|
||||
|
||||
vh.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null) {
|
||||
listener.onGalleryItemClicked(item);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface GalleryItemClickListener {
|
||||
void onGalleryItemClicked(GalleryItem item);
|
||||
}
|
||||
|
||||
public static class GalleryGridItemDecoration extends RecyclerView.ItemDecoration {
|
||||
|
||||
private int spanCount;
|
||||
private int spacing;
|
||||
|
||||
public GalleryGridItemDecoration(int spanCount, int spacing) {
|
||||
this.spanCount = spanCount;
|
||||
this.spacing = spacing;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getItemOffsets(Rect outRect, View view, RecyclerView parent, RecyclerView.State state) {
|
||||
int position = parent.getChildAdapterPosition(view); // item position
|
||||
int column = position % spanCount; // item column
|
||||
|
||||
outRect.left = column * spacing / spanCount; // column * ((1f / spanCount) * spacing)
|
||||
outRect.right = spacing - (column + 1) * spacing / spanCount; // spacing - (column + 1) * ((1f / spanCount) * spacing)
|
||||
if (position >= spanCount) {
|
||||
outRect.top = spacing; // item top
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -41,16 +41,6 @@ public class InlineChannelSpinnerAdapter extends ArrayAdapter<Claim> {
|
||||
}
|
||||
}
|
||||
|
||||
public int getItemPosition(Claim item) {
|
||||
for (int i = 0; i < channels.size(); i++) {
|
||||
Claim channel = channels.get(i);
|
||||
if (item.getClaimId().equalsIgnoreCase(channel.getClaimId())) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View view, ViewGroup parent) {
|
||||
return createView(position, view, parent);
|
||||
|
||||
@@ -1,53 +0,0 @@
|
||||
package io.lbry.browser.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.Language;
|
||||
import io.lbry.browser.utils.Predefined;
|
||||
|
||||
public class LanguageSpinnerAdapter extends ArrayAdapter<Language> {
|
||||
private int layoutResourceId;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public LanguageSpinnerAdapter(Context context, int resource) {
|
||||
super(context, resource, 0, Predefined.PUBLISH_LANGUAGES);
|
||||
inflater = LayoutInflater.from(context);
|
||||
layoutResourceId = resource;
|
||||
}
|
||||
|
||||
public int getItemPosition(String languageCode) {
|
||||
for (int i = 0; i < Predefined.PUBLISH_LANGUAGES.size(); i++) {
|
||||
Language lang = Predefined.PUBLISH_LANGUAGES.get(i);
|
||||
if (lang.getCode().equalsIgnoreCase(languageCode)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {
|
||||
return createView(position, view, parent);
|
||||
}
|
||||
@Override
|
||||
public View getView(int position, View view, @NonNull ViewGroup parent) {
|
||||
return createView(position, view, parent);
|
||||
}
|
||||
private View createView(int position, View convertView, ViewGroup parent) {
|
||||
Language item = getItem(position);
|
||||
View view = inflater.inflate(layoutResourceId, parent, false);
|
||||
TextView label = view.findViewById(R.id.item_display_name);
|
||||
label.setText(item != null ? item.getStringResourceId() : 0);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -1,52 +0,0 @@
|
||||
package io.lbry.browser.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.model.Language;
|
||||
import io.lbry.browser.model.License;
|
||||
import io.lbry.browser.utils.Predefined;
|
||||
|
||||
public class LicenseSpinnerAdapter extends ArrayAdapter<License> {
|
||||
private int layoutResourceId;
|
||||
private LayoutInflater inflater;
|
||||
|
||||
public LicenseSpinnerAdapter(Context context, int resource) {
|
||||
super(context, resource, 0, Predefined.LICENSES);
|
||||
inflater = LayoutInflater.from(context);
|
||||
layoutResourceId = resource;
|
||||
}
|
||||
public int getItemPosition(String name) {
|
||||
for (int i = 0; i < Predefined.LICENSES.size(); i++) {
|
||||
License lic = Predefined.LICENSES.get(i);
|
||||
if (lic.getName().equalsIgnoreCase(name)) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View getDropDownView(int position, View view, @NonNull ViewGroup parent) {
|
||||
return createView(position, view, parent);
|
||||
}
|
||||
@Override
|
||||
public View getView(int position, View view, @NonNull ViewGroup parent) {
|
||||
return createView(position, view, parent);
|
||||
}
|
||||
private View createView(int position, View convertView, ViewGroup parent) {
|
||||
License item = getItem(position);
|
||||
View view = inflater.inflate(layoutResourceId, parent, false);
|
||||
TextView label = view.findViewById(R.id.item_display_name);
|
||||
label.setText(item != null ? item.getStringResourceId() : 0);
|
||||
|
||||
return view;
|
||||
}
|
||||
}
|
||||
@@ -159,7 +159,7 @@ public class RewardListAdapter extends RecyclerView.Adapter<RewardListAdapter.Vi
|
||||
});
|
||||
|
||||
vh.textUsdValue.setText(reward.isCustom() || Lbryio.LBCUSDRate == 0 ? null :
|
||||
String.format("≈$%s", Helper.SIMPLE_CURRENCY_FORMAT.format(rewardAmount * Lbryio.LBCUSDRate)));
|
||||
String.format("≈$%s", Helper.USD_CURRENCY_FORMAT.format(rewardAmount * Lbryio.LBCUSDRate)));
|
||||
|
||||
vh.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -197,8 +197,7 @@ public class RewardListAdapter extends RecyclerView.Adapter<RewardListAdapter.Vi
|
||||
public void onClick(View view) {
|
||||
String claimCode = Helper.getValue(vh.inputCustomCode.getText());
|
||||
if (Helper.isNullOrEmpty(claimCode)) {
|
||||
Snackbar.make(view, R.string.please_enter_claim_code, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(view, R.string.please_enter_claim_code, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -56,11 +56,6 @@ public class SuggestedChannelGridAdapter extends RecyclerView.Adapter<SuggestedC
|
||||
|
||||
public int getSelectedCount() { return selectedItems.size(); }
|
||||
|
||||
public void clearItems() {
|
||||
items.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public List<Claim> getSelectedItems() {
|
||||
return this.selectedItems;
|
||||
}
|
||||
|
||||
@@ -16,7 +16,6 @@ import io.lbry.browser.exceptions.LbryUriException;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.UrlSuggestion;
|
||||
import io.lbry.browser.ui.controls.SolidIconView;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -97,7 +96,7 @@ public class UrlSuggestionListAdapter extends RecyclerView.Adapter<UrlSuggestion
|
||||
iconStringId = R.string.fa_at;
|
||||
fullTitle = item.getTitle();
|
||||
desc = item.getClaim() != null ? item.getClaim().getTitle() :
|
||||
((item.isUseTextAsDescription() && !Helper.isNullOrEmpty(item.getText())) ? item.getText() : String.format(context.getString(R.string.view_channel_url_desc), item.getText()));
|
||||
(item.isUseTextAsDescription() ? item.getText() : String.format(context.getString(R.string.view_channel_url_desc), item.getText()));
|
||||
break;
|
||||
case UrlSuggestion.TYPE_TAG:
|
||||
iconStringId = R.string.fa_hashtag;
|
||||
@@ -114,7 +113,7 @@ public class UrlSuggestionListAdapter extends RecyclerView.Adapter<UrlSuggestion
|
||||
iconStringId = R.string.fa_file;
|
||||
fullTitle = item.getTitle();
|
||||
desc = item.getClaim() != null ? item.getClaim().getTitle() :
|
||||
((item.isUseTextAsDescription() && !Helper.isNullOrEmpty(item.getText())) ? item.getText() : String.format(context.getString(R.string.view_file_url_desc), item.getText()));
|
||||
(item.isUseTextAsDescription() ? item.getText() : String.format(context.getString(R.string.view_file_url_desc), item.getText()));
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,10 +4,7 @@ import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteOpenHelper;
|
||||
import android.opengl.Visibility;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
@@ -22,9 +19,8 @@ import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
|
||||
public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
public static final int DATABASE_VERSION = 2;
|
||||
public static final int DATABASE_VERSION = 1;
|
||||
public static final String DATABASE_NAME = "LbryApp.db";
|
||||
private static DatabaseHelper instance;
|
||||
|
||||
private static final String[] SQL_CREATE_TABLES = {
|
||||
// local subscription store
|
||||
@@ -40,7 +36,6 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
", claim_id TEXT" +
|
||||
", claim_name TEXT" +
|
||||
", cost REAL " +
|
||||
", currency TEXT " +
|
||||
", title TEXT " +
|
||||
", publisher_claim_id TEXT" +
|
||||
", publisher_name TEXT" +
|
||||
@@ -59,24 +54,17 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
"CREATE INDEX idx_view_history_device ON view_history (device)"
|
||||
};
|
||||
|
||||
private static final String[] SQL_V1_V2_UPGRADE = {
|
||||
"ALTER TABLE view_history ADD COLUMN currency TEXT"
|
||||
};
|
||||
|
||||
private static final String SQL_INSERT_SUBSCRIPTION = "REPLACE INTO subscriptions (channel_name, url) VALUES (?, ?)";
|
||||
private static final String SQL_DELETE_SUBSCRIPTION = "DELETE FROM subscriptions WHERE url = ?";
|
||||
private static final String SQL_GET_SUBSCRIPTIONS = "SELECT channel_name, url FROM subscriptions";
|
||||
|
||||
private static final String SQL_INSERT_URL_HISTORY = "REPLACE INTO url_history (value, url, type, timestamp) VALUES (?, ?, ?, ?)";
|
||||
private static final String SQL_INSERT_URL_HISTORY = "REPLACE INTO url_history (value, url, type, timestamp) VALUES (?, ?, ?)";
|
||||
private static final String SQL_CLEAR_URL_HISTORY = "DELETE FROM url_history";
|
||||
private static final String SQL_CLEAR_URL_HISTORY_BEFORE_TIME = "DELETE FROM url_history WHERE timestamp < ?";
|
||||
private static final String SQL_GET_RECENT_URL_HISTORY = "SELECT value, url, type FROM url_history ORDER BY timestamp DESC LIMIT 10";
|
||||
|
||||
private static final String SQL_INSERT_VIEW_HISTORY =
|
||||
"REPLACE INTO view_history (url, claim_id, claim_name, cost, currency, title, publisher_claim_id, publisher_name, publisher_title, thumbnail_url, device, release_time, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String SQL_GET_VIEW_HISTORY =
|
||||
"SELECT url, claim_id, claim_name, cost, currency, title, publisher_claim_id, publisher_name, publisher_title, thumbnail_url, device, release_time, timestamp " +
|
||||
"FROM view_history WHERE '' = ? OR timestamp < ? ORDER BY timestamp DESC LIMIT %d";
|
||||
"REPLACE INTO view_history (url, claim_id, claim_name, cost, title, publisher_claim_id, publisher_name, publisher_title, thumbnail_url, device, release_time, timestamp) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
private static final String SQL_CLEAR_VIEW_HISTORY = "DELETE FROM view_history";
|
||||
private static final String SQL_CLEAR_VIEW_HISTORY_BY_DEVICE = "DELETE FROM view_history WHERE device = ?";
|
||||
private static final String SQL_CLEAR_VIEW_HISTORY_BEFORE_TIME = "DELETE FROM view_history WHERE timestamp < ?";
|
||||
@@ -87,14 +75,8 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
private static final String SQL_UNFOLLOW_TAGS = "UPDATE tags SET is_followed = 0";
|
||||
private static final String SQL_GET_FOLLOWED_TAGS = "SELECT name FROM tags WHERE is_followed = 1";
|
||||
|
||||
|
||||
|
||||
public DatabaseHelper(Context context) {
|
||||
super(context, String.format("%s/%s", context.getFilesDir().getAbsolutePath(), DATABASE_NAME), null, DATABASE_VERSION);
|
||||
instance = this;
|
||||
}
|
||||
public static DatabaseHelper getInstance() {
|
||||
return instance;
|
||||
}
|
||||
public void onCreate(SQLiteDatabase db) {
|
||||
for (String sql : SQL_CREATE_TABLES) {
|
||||
@@ -105,11 +87,7 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
}
|
||||
public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
if (oldVersion < 2) {
|
||||
for (String sql : SQL_V1_V2_UPGRADE) {
|
||||
db.execSQL(sql);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
public void onDowngrade(SQLiteDatabase db, int oldVersion, int newVersion) {
|
||||
|
||||
@@ -135,9 +113,13 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
while (cursor.moveToNext()) {
|
||||
UrlSuggestion suggestion = new UrlSuggestion();
|
||||
suggestion.setText(cursor.getString(0));
|
||||
suggestion.setUri(cursor.isNull(1) ? null : LbryUri.tryParse(cursor.getString(1)));
|
||||
suggestion.setType(cursor.getInt(2));
|
||||
suggestion.setTitleUrlOnly(true);
|
||||
|
||||
try {
|
||||
suggestion.setUri(cursor.isNull(1) ? null : LbryUri.parse(cursor.getString(1)));
|
||||
} catch (LbryUriException ex) {
|
||||
// don't fail if the LbryUri is invalid
|
||||
}
|
||||
suggestions.add(suggestion);
|
||||
}
|
||||
} finally {
|
||||
@@ -153,7 +135,6 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
viewHistory.getClaimId(),
|
||||
viewHistory.getClaimName(),
|
||||
viewHistory.getCost() != null ? viewHistory.getCost().doubleValue() : 0,
|
||||
viewHistory.getCurrency(),
|
||||
viewHistory.getTitle(),
|
||||
viewHistory.getPublisherClaimId(),
|
||||
viewHistory.getPublisherName(),
|
||||
@@ -165,42 +146,6 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
});
|
||||
}
|
||||
|
||||
public static List<ViewHistory> getViewHistory(String lastTimestamp, int pageLimit, SQLiteDatabase db) {
|
||||
List<ViewHistory> history = new ArrayList<>();
|
||||
Cursor cursor = null;
|
||||
try {
|
||||
String arg = lastTimestamp == null ? "" : lastTimestamp;
|
||||
cursor = db.rawQuery(String.format(SQL_GET_VIEW_HISTORY, pageLimit), new String[] { arg, arg });
|
||||
while (cursor.moveToNext()) {
|
||||
ViewHistory item = new ViewHistory();
|
||||
int cursorIndex = 0;
|
||||
item.setUri(LbryUri.tryParse(cursor.getString(cursorIndex++)));
|
||||
item.setClaimId(cursor.getString(cursorIndex++));
|
||||
item.setClaimName(cursor.getString(cursorIndex++));
|
||||
item.setCost(new BigDecimal(cursor.getDouble(cursorIndex++)));
|
||||
item.setCurrency(cursor.getString(cursorIndex++));
|
||||
item.setTitle(cursor.getString(cursorIndex++));
|
||||
item.setPublisherClaimId(cursor.getString(cursorIndex++));
|
||||
item.setPublisherName(cursor.getString(cursorIndex++));
|
||||
item.setPublisherTitle(cursor.getString(cursorIndex++));
|
||||
item.setThumbnailUrl(cursor.getString(cursorIndex++));
|
||||
item.setDevice(cursor.getString(cursorIndex++));
|
||||
item.setReleaseTime(cursor.getLong(cursorIndex++));
|
||||
try {
|
||||
item.setTimestamp(new SimpleDateFormat(Helper.ISO_DATE_FORMAT_PATTERN).parse(cursor.getString(cursorIndex)));
|
||||
} catch (ParseException ex) {
|
||||
// invalid timestamp (which shouldn't happen). Skip this item
|
||||
continue;
|
||||
}
|
||||
|
||||
history.add(item);
|
||||
}
|
||||
} finally {
|
||||
Helper.closeCursor(cursor);
|
||||
}
|
||||
return history;
|
||||
}
|
||||
|
||||
public static void createOrUpdateTag(Tag tag, SQLiteDatabase db) {
|
||||
db.execSQL(SQL_INSERT_TAG, new Object[] { tag.getLowercaseName(), tag.isFollowed() ? 1 : 0 });
|
||||
}
|
||||
|
||||
@@ -159,13 +159,7 @@ public class CustomizeTagsDialogFragment extends BottomSheetDialogFragment {
|
||||
}
|
||||
|
||||
private void updateKnownTags(String filter, int limit, boolean clearPrevious) {
|
||||
UpdateSuggestedTagsTask task = new UpdateSuggestedTagsTask(
|
||||
filter,
|
||||
SUGGESTED_LIMIT,
|
||||
followedTagsAdapter,
|
||||
suggestedTagsAdapter,
|
||||
clearPrevious,
|
||||
false, new UpdateSuggestedTagsTask.KnownTagsHandler() {
|
||||
UpdateSuggestedTagsTask task = new UpdateSuggestedTagsTask(filter, SUGGESTED_LIMIT, followedTagsAdapter, suggestedTagsAdapter, clearPrevious, new UpdateSuggestedTagsTask.KnownTagsHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Tag> tags) {
|
||||
if (suggestedTagsAdapter == null) {
|
||||
|
||||
@@ -84,16 +84,10 @@ public class DiscoverDialogFragment extends BottomSheetDialogFragment {
|
||||
dialogActionsListener.onResume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCancel(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
if (dialogActionsListener != null) {
|
||||
dialogActionsListener.onCancel();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onDismiss(DialogInterface dialog) {
|
||||
super.onDismiss(dialog);
|
||||
super.onCancel(dialog);
|
||||
if (dialogActionsListener != null) {
|
||||
dialogActionsListener.onCancel();
|
||||
}
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.FileViewActivity;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.InlineChannelSpinnerAdapter;
|
||||
@@ -86,7 +87,7 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
|
||||
|
||||
textTitle.setText(getString(R.string.repost_title, claim.getTitle()));
|
||||
inputName.setText(claim.getName());
|
||||
inputDeposit.setText(R.string.min_deposit);
|
||||
inputDeposit.setText(R.string.min_repost_deposit);
|
||||
channelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
@@ -146,16 +147,16 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).addWalletBalanceListener(this);
|
||||
if (context instanceof FileViewActivity) {
|
||||
((FileViewActivity) context).addWalletBalanceListener(this);
|
||||
}
|
||||
fetchChannels();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).removeWalletBalanceListener(this);
|
||||
if (context instanceof FileViewActivity) {
|
||||
((FileViewActivity) context).removeWalletBalanceListener(this);
|
||||
}
|
||||
inputDeposit.clearFocus();
|
||||
super.onPause();
|
||||
@@ -177,8 +178,8 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
|
||||
public void onError(Exception error) {
|
||||
// could not fetch channels
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).showError(error.getMessage());
|
||||
if (context instanceof FileViewActivity) {
|
||||
((FileViewActivity) context).showError(error.getMessage());
|
||||
}
|
||||
dismiss();
|
||||
}
|
||||
|
||||
@@ -23,6 +23,7 @@ import com.google.android.material.textfield.TextInputEditText;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
|
||||
import io.lbry.browser.FileViewActivity;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.listener.WalletBalanceListener;
|
||||
@@ -163,15 +164,15 @@ public class SendTipDialogFragment extends BottomSheetDialogFragment implements
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).addWalletBalanceListener(this);
|
||||
if (context instanceof FileViewActivity) {
|
||||
((FileViewActivity) context).addWalletBalanceListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).removeWalletBalanceListener(this);
|
||||
if (context instanceof FileViewActivity) {
|
||||
((FileViewActivity) context).removeWalletBalanceListener(this);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface CameraPermissionListener {
|
||||
void onCameraPermissionGranted();
|
||||
void onCameraPermissionRefused();
|
||||
void onRecordAudioPermissionGranted();
|
||||
void onRecordAudioPermissionRefused();
|
||||
}
|
||||
@@ -1,5 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface DownloadActionListener {
|
||||
void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.model.Claim;
|
||||
|
||||
public interface FetchClaimsListener {
|
||||
void onClaimsFetched(List<Claim> claims);
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface FilePickerListener {
|
||||
void onFilePicked(String filePath);
|
||||
void onFilePickerCancelled();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface ScreenOrientationListener {
|
||||
void onPortraitOrientationEntered();
|
||||
void onLandscapeOrientationEntered();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface StoragePermissionListener {
|
||||
void onStoragePermissionGranted();
|
||||
void onStoragePermissionRefused();
|
||||
}
|
||||
@@ -9,7 +9,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
@@ -19,7 +18,6 @@ import java.util.stream.Stream;
|
||||
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.utils.Predefined;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@@ -83,9 +81,6 @@ public class Claim {
|
||||
private GenericMetadata value;
|
||||
private LbryFile file; // associated file if it exists
|
||||
|
||||
// device it was viewed on (for view history)
|
||||
private String device;
|
||||
|
||||
public static Claim claimFromOutput(JSONObject item) {
|
||||
// we only need name, permanent_url, txid and nout
|
||||
Claim claim = new Claim();
|
||||
@@ -97,10 +92,6 @@ public class Claim {
|
||||
return claim;
|
||||
}
|
||||
|
||||
public String getOutpoint() {
|
||||
return String.format("%s:%d", txid, nout);
|
||||
}
|
||||
|
||||
public boolean isFree() {
|
||||
if (!(value instanceof StreamMetadata)) {
|
||||
return true;
|
||||
@@ -110,24 +101,6 @@ public class Claim {
|
||||
return fee == null || Helper.parseDouble(fee.getAmount(), 0) == 0;
|
||||
}
|
||||
|
||||
public BigDecimal getActualCost(double usdRate) {
|
||||
if (!(value instanceof StreamMetadata)) {
|
||||
return new BigDecimal(0);
|
||||
}
|
||||
|
||||
Fee fee = ((StreamMetadata) value).getFee();
|
||||
if (fee != null) {
|
||||
double amount = Helper.parseDouble(fee.getAmount(), 0);
|
||||
if ("usd".equalsIgnoreCase(fee.getCurrency())) {
|
||||
return new BigDecimal(String.valueOf(amount / usdRate));
|
||||
}
|
||||
|
||||
return new BigDecimal(String.valueOf(amount)); // deweys
|
||||
}
|
||||
|
||||
return new BigDecimal(0);
|
||||
}
|
||||
|
||||
public String getMediaType() {
|
||||
if (value instanceof StreamMetadata) {
|
||||
StreamMetadata metadata = (StreamMetadata) value;
|
||||
@@ -157,17 +130,6 @@ public class Claim {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public boolean isMature() {
|
||||
List<String> tags = getTags();
|
||||
if (tags != null && tags.size() > 0) {
|
||||
for (String tag : tags) {
|
||||
if (Predefined.MATURE_TAGS.contains(tag.toLowerCase())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public String getThumbnailUrl() {
|
||||
if (value != null && value.getThumbnail() != null) {
|
||||
@@ -265,8 +227,6 @@ public class Claim {
|
||||
claim.setName(viewHistory.getClaimName());
|
||||
claim.setValueType(TYPE_STREAM);
|
||||
claim.setPermanentUrl(viewHistory.getUri().toString());
|
||||
claim.setDevice(viewHistory.getDevice());
|
||||
claim.setConfirmations(1);
|
||||
|
||||
StreamMetadata value = new StreamMetadata();
|
||||
value.setTitle(viewHistory.getTitle());
|
||||
@@ -279,8 +239,7 @@ public class Claim {
|
||||
if (viewHistory.getCost() != null && viewHistory.getCost().doubleValue() > 0) {
|
||||
Fee fee = new Fee();
|
||||
fee.setAmount(String.valueOf(viewHistory.getCost().doubleValue()));
|
||||
fee.setCurrency(viewHistory.getCurrency());
|
||||
value.setFee(fee);
|
||||
fee.setCurrency("LBC"); // always LBC
|
||||
}
|
||||
|
||||
claim.setValue(value);
|
||||
@@ -375,8 +334,7 @@ public class Claim {
|
||||
Fee fee = null;
|
||||
if (feeAmount > 0) {
|
||||
fee = new Fee();
|
||||
fee.setAmount(String.valueOf(new BigDecimal(String.valueOf(feeAmount)).divide(new BigDecimal(100000000))));
|
||||
fee.setCurrency("LBC");
|
||||
fee.setAmount(String.valueOf(feeAmount));
|
||||
}
|
||||
|
||||
((StreamMetadata) metadata).setFee(fee);
|
||||
@@ -395,10 +353,9 @@ public class Claim {
|
||||
Claim signingChannel = new Claim();
|
||||
signingChannel.setClaimId(searchResultObject.getString("channel_claim_id"));
|
||||
signingChannel.setName(searchResultObject.getString("channel"));
|
||||
LbryUri channelUri = new LbryUri();
|
||||
channelUri.setChannelClaimId(signingChannel.getClaimId());
|
||||
channelUri.setChannelName(signingChannel.getName());
|
||||
signingChannel.setPermanentUrl(channelUri.toString());
|
||||
|
||||
claimUri.setChannelClaimId(signingChannel.getClaimId());
|
||||
claimUri.setChannelName(signingChannel.getName());
|
||||
|
||||
claim.setSigningChannel(signingChannel);
|
||||
}
|
||||
|
||||
@@ -5,36 +5,34 @@ import androidx.annotation.Nullable;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
import lombok.ToString;
|
||||
|
||||
/**
|
||||
* Class to represent a key to check equality with another object
|
||||
*/
|
||||
@ToString
|
||||
public class ClaimCacheKey {
|
||||
@Getter
|
||||
@Setter
|
||||
private String claimId;
|
||||
@Getter
|
||||
@Setter
|
||||
private String url;
|
||||
|
||||
public static ClaimCacheKey fromClaimShortUrl(Claim claim) {
|
||||
ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setUrl(claim.getShortUrl());
|
||||
return key;
|
||||
}
|
||||
|
||||
public static ClaimCacheKey fromClaimPermanentUrl(Claim claim) {
|
||||
ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setUrl(claim.getPermanentUrl());
|
||||
return key;
|
||||
}
|
||||
private String canonicalUrl;
|
||||
@Getter
|
||||
@Setter
|
||||
private String permanentUrl;
|
||||
@Getter
|
||||
@Setter
|
||||
private String shortUrl;
|
||||
@Getter
|
||||
@Setter
|
||||
private String vanityUrl;
|
||||
|
||||
public static ClaimCacheKey fromClaim(Claim claim) {
|
||||
ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setClaimId(claim.getClaimId());
|
||||
key.setUrl(!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
|
||||
key.setCanonicalUrl(claim.getCanonicalUrl());
|
||||
key.setPermanentUrl(claim.getPermanentUrl());
|
||||
key.setShortUrl(claim.getShortUrl());
|
||||
|
||||
return key;
|
||||
}
|
||||
|
||||
@@ -43,24 +41,44 @@ public class ClaimCacheKey {
|
||||
if (obj == null || !(obj instanceof ClaimCacheKey)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
ClaimCacheKey key = (ClaimCacheKey) obj;
|
||||
if (!Helper.isNullOrEmpty(claimId) && !Helper.isNullOrEmpty(key.getClaimId())) {
|
||||
return claimId.equalsIgnoreCase(key.getClaimId());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(url) && !Helper.isNullOrEmpty(key.getUrl())) {
|
||||
return url.equalsIgnoreCase(key.getUrl());
|
||||
if (!Helper.isNullOrEmpty(permanentUrl) && !Helper.isNullOrEmpty(key.getPermanentUrl())) {
|
||||
return permanentUrl.equalsIgnoreCase(key.getPermanentUrl());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(canonicalUrl) && !Helper.isNullOrEmpty(key.getCanonicalUrl())) {
|
||||
return canonicalUrl.equalsIgnoreCase(key.getCanonicalUrl());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(shortUrl) && !Helper.isNullOrEmpty(key.getShortUrl())) {
|
||||
return shortUrl.equalsIgnoreCase(key.getShortUrl());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(vanityUrl) && !Helper.isNullOrEmpty(key.getVanityUrl())) {
|
||||
return vanityUrl.equalsIgnoreCase(key.getVanityUrl());
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
if (!Helper.isNullOrEmpty(url)) {
|
||||
return url.hashCode();
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claimId)) {
|
||||
return claimId.hashCode();
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(permanentUrl)) {
|
||||
return permanentUrl.hashCode();
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(canonicalUrl)) {
|
||||
return canonicalUrl.hashCode();
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(shortUrl)) {
|
||||
return shortUrl.hashCode();
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(vanityUrl)) {
|
||||
return vanityUrl.hashCode();
|
||||
}
|
||||
|
||||
return super.hashCode();
|
||||
}
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
package io.lbry.browser.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class GalleryItem {
|
||||
private String id;
|
||||
private String name;
|
||||
private String filePath;
|
||||
private String type;
|
||||
private String thumbnailPath;
|
||||
private long duration;
|
||||
}
|
||||
@@ -1,16 +0,0 @@
|
||||
package io.lbry.browser.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Language {
|
||||
private String code;
|
||||
private String name;
|
||||
private int stringResourceId;
|
||||
|
||||
public Language(String code, String name, int stringResourceId) {
|
||||
this.code = code;
|
||||
this.name = name;
|
||||
this.stringResourceId = stringResourceId;
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,9 @@ import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Type;
|
||||
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import lombok.Data;
|
||||
import lombok.EqualsAndHashCode;
|
||||
|
||||
@Data
|
||||
@EqualsAndHashCode(onlyExplicitlyIncluded = true)
|
||||
public class LbryFile {
|
||||
private Claim.StreamMetadata metadata;
|
||||
private long addedOn;
|
||||
@@ -23,7 +20,6 @@ public class LbryFile {
|
||||
private int blobsRemaining;
|
||||
private String channelClaimId;
|
||||
private String channelName;
|
||||
@EqualsAndHashCode.Include
|
||||
private String claimId;
|
||||
private String claimName;
|
||||
private boolean completed;
|
||||
@@ -43,50 +39,16 @@ public class LbryFile {
|
||||
private String streamName;
|
||||
private String streamingUrl;
|
||||
private String suggestedFileName;
|
||||
private long timestamp;
|
||||
private long totalBytes;
|
||||
private long totalBytesLowerBound;
|
||||
private String txid;
|
||||
private long writtenBytes;
|
||||
|
||||
private Claim generatedClaim;
|
||||
|
||||
public Claim getClaim() {
|
||||
if (generatedClaim != null) {
|
||||
return generatedClaim;
|
||||
}
|
||||
|
||||
generatedClaim = new Claim();
|
||||
generatedClaim.setValueType(Claim.TYPE_STREAM);
|
||||
generatedClaim.setPermanentUrl(LbryUri.tryParse(String.format("%s#%s", claimName, claimId)).toString());
|
||||
generatedClaim.setClaimId(claimId);
|
||||
generatedClaim.setName(claimName);
|
||||
generatedClaim.setValue(metadata);
|
||||
generatedClaim.setConfirmations(1);
|
||||
generatedClaim.setTxid(txid);
|
||||
generatedClaim.setNout(nout);
|
||||
generatedClaim.setFile(this);
|
||||
|
||||
if (channelClaimId != null) {
|
||||
Claim signingChannel = new Claim();
|
||||
signingChannel.setClaimId(channelClaimId);
|
||||
signingChannel.setName(channelName);
|
||||
signingChannel.setPermanentUrl(LbryUri.tryParse(String.format("%s#%s", claimName, claimId)).toString());
|
||||
generatedClaim.setSigningChannel(signingChannel);
|
||||
}
|
||||
|
||||
return generatedClaim;
|
||||
}
|
||||
|
||||
public static LbryFile fromJSONObject(JSONObject fileObject) {
|
||||
String fileJson = fileObject.toString();
|
||||
Type type = new TypeToken<LbryFile>(){}.getType();
|
||||
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
|
||||
LbryFile file = gson.fromJson(fileJson, type);
|
||||
|
||||
if (file.getMetadata() != null && file.getMetadata().getReleaseTime() == 0) {
|
||||
file.getMetadata().setReleaseTime(file.getTimestamp());
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package io.lbry.browser.model;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class License {
|
||||
private String name;
|
||||
private String url;
|
||||
private int stringResourceId;
|
||||
|
||||
public License(String name, int stringResourceId) {
|
||||
this.name = name;
|
||||
this.stringResourceId = stringResourceId;
|
||||
}
|
||||
public License(String name, String url, int stringResourceId) {
|
||||
this.name = name;
|
||||
this.url = url;
|
||||
this.stringResourceId = stringResourceId;
|
||||
}
|
||||
}
|
||||
@@ -15,7 +15,6 @@ public class UrlSuggestion {
|
||||
private LbryUri uri;
|
||||
private Claim claim; // associated claim if resolved
|
||||
private boolean titleTextOnly;
|
||||
private boolean titleUrlOnly;
|
||||
private boolean useTextAsDescription;
|
||||
|
||||
public UrlSuggestion() {
|
||||
@@ -35,10 +34,6 @@ public class UrlSuggestion {
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
if (titleUrlOnly && (type == TYPE_CHANNEL || type == TYPE_FILE)) {
|
||||
return uri.toString();
|
||||
}
|
||||
|
||||
if (!titleTextOnly) {
|
||||
switch (type) {
|
||||
case TYPE_CHANNEL:
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.Date;
|
||||
|
||||
import io.lbry.browser.exceptions.LbryUriException;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -14,7 +13,6 @@ public class ViewHistory {
|
||||
private String claimId;
|
||||
private String claimName;
|
||||
private BigDecimal cost;
|
||||
private String currency;
|
||||
private String title;
|
||||
private String publisherClaimId;
|
||||
private String publisherName;
|
||||
@@ -41,14 +39,9 @@ public class ViewHistory {
|
||||
Claim.StreamMetadata value = (Claim.StreamMetadata) metadata;
|
||||
history.setReleaseTime(value.getReleaseTime());
|
||||
if (value.getFee() != null) {
|
||||
Fee fee = value.getFee();
|
||||
history.setCost(new BigDecimal(fee.getAmount()));
|
||||
history.setCurrency(fee.getCurrency());
|
||||
history.setCost(new BigDecimal(value.getFee().getAmount()));
|
||||
}
|
||||
}
|
||||
if (history.getReleaseTime() == 0) {
|
||||
history.setReleaseTime(claim.getTimestamp());
|
||||
}
|
||||
|
||||
Claim signingChannel = claim.getSigningChannel();
|
||||
if (signingChannel != null) {
|
||||
|
||||
@@ -8,13 +8,9 @@ public class WalletSync {
|
||||
private String data;
|
||||
private boolean changed;
|
||||
|
||||
public WalletSync(String hash, String data) {
|
||||
public WalletSync(String hash, String data, boolean changed) {
|
||||
this.hash = hash;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public WalletSync(String hash, String data, boolean changed) {
|
||||
this(hash, data);
|
||||
this.changed = changed;
|
||||
}
|
||||
}
|
||||
@@ -24,19 +24,6 @@ public class User {
|
||||
private String primaryEmail;
|
||||
private String rewardStatusChangeTrigger;
|
||||
private String updatedAt;
|
||||
private List<YoutubeChannel> youtubeChannels;
|
||||
private List<String> youtubeChannels;
|
||||
private List<String> deviceTypes;
|
||||
|
||||
@Data
|
||||
public static class YoutubeChannel {
|
||||
String ytChannelName;
|
||||
String lbryChannelName;
|
||||
String channelClaimId;
|
||||
String syncStatus;
|
||||
String statusToken;
|
||||
boolean transferable;
|
||||
String transferState;
|
||||
List<String> publishToAddress;
|
||||
String publicKey;
|
||||
}
|
||||
}
|
||||
+9
-25
@@ -1,4 +1,4 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
package io.lbry.browser.tasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
@@ -9,9 +9,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
@@ -49,28 +47,14 @@ public class ChannelCreateUpdateTask extends AsyncTask<Void, Void, Claim> {
|
||||
} else {
|
||||
options.put("claim_id", claim.getClaimId());
|
||||
}
|
||||
options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(deposit.doubleValue()));
|
||||
if (!Helper.isNullOrEmpty(claim.getTitle())) {
|
||||
options.put("title", claim.getTitle());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claim.getCoverUrl())) {
|
||||
options.put("cover_url", claim.getCoverUrl());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claim.getThumbnailUrl())) {
|
||||
options.put("thumbnail_url", claim.getThumbnailUrl());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claim.getDescription())) {
|
||||
options.put("description", claim.getDescription());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claim.getWebsiteUrl())) {
|
||||
options.put("website_url", claim.getWebsiteUrl());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claim.getEmail())) {
|
||||
options.put("email", claim.getEmail());
|
||||
}
|
||||
if (claim.getTags() != null && claim.getTags().size() > 0) {
|
||||
options.put("tags", claim.getTags());
|
||||
}
|
||||
options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT).format(deposit.doubleValue()));
|
||||
options.put("title", claim.getTitle());
|
||||
options.put("cover_url", claim.getCoverUrl());
|
||||
options.put("thumbnail_url", claim.getThumbnailUrl());
|
||||
options.put("description", claim.getDescription());
|
||||
options.put("website_url", claim.getWebsiteUrl());
|
||||
options.put("email", claim.getEmail());
|
||||
options.put("tags", claim.getTags());
|
||||
options.put("blocking", true);
|
||||
|
||||
Claim claimResult = null;
|
||||
@@ -9,7 +9,7 @@ import java.util.List;
|
||||
import io.lbry.browser.exceptions.LbryRequestException;
|
||||
import io.lbry.browser.exceptions.LbryResponseException;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchTask;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lighthouse;
|
||||
|
||||
@@ -19,11 +19,11 @@ public class LighthouseSearchTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
private int from;
|
||||
private boolean nsfw;
|
||||
private String relatedTo;
|
||||
private ClaimSearchResultHandler handler;
|
||||
private ClaimSearchTask.ClaimSearchResultHandler handler;
|
||||
private ProgressBar progressBar;
|
||||
private Exception error;
|
||||
|
||||
public LighthouseSearchTask(String rawQuery, int size, int from, boolean nsfw, String relatedTo, ProgressBar progressBar, ClaimSearchResultHandler handler) {
|
||||
public LighthouseSearchTask(String rawQuery, int size, int from, boolean nsfw, String relatedTo, ProgressBar progressBar, ClaimSearchTask.ClaimSearchResultHandler handler) {
|
||||
this.rawQuery = rawQuery;
|
||||
this.size = size;
|
||||
this.from = from;
|
||||
|
||||
@@ -24,7 +24,6 @@ import io.lbry.browser.model.lbryinc.Subscription;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import okhttp3.Response;
|
||||
|
||||
// background task to create a diff of local and remote subscriptions and try to merge
|
||||
public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscription>> {
|
||||
@@ -85,8 +84,8 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
||||
LbryUri uri = LbryUri.parse(local.getUrl());
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("claim_id", uri.getChannelClaimId());
|
||||
options.put("channel_name", Helper.normalizeChannelName(local.getChannelName()));
|
||||
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context));
|
||||
options.put("channel_name", local.getChannelName());
|
||||
Lbryio.call("subscription", "new", options, context);
|
||||
} catch (LbryUriException | LbryioRequestException | LbryioResponseException ex) {
|
||||
// pass
|
||||
Log.e(TAG, String.format("subscription/new failed: %s", ex.getMessage()), ex);
|
||||
@@ -109,9 +108,11 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException | SQLiteException ex) {
|
||||
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | SQLiteException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
} finally {
|
||||
Helper.closeDatabase(db);
|
||||
}
|
||||
|
||||
return combined;
|
||||
|
||||
@@ -1,45 +0,0 @@
|
||||
package io.lbry.browser.tasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class SetSdkSettingTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private String key;
|
||||
private String value;
|
||||
private GenericTaskHandler handler;
|
||||
private Exception error;
|
||||
public SetSdkSettingTask(String key, String value, GenericTaskHandler handler) {
|
||||
this.key = key;
|
||||
this.value = value;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("key", key);
|
||||
options.put("value", value);
|
||||
Lbry.genericApiCall("setting_set", options);
|
||||
return true;
|
||||
} catch (ApiCallException ex) {
|
||||
error = ex;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (handler != null) {
|
||||
if (result) {
|
||||
handler.onSuccess();
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -14,27 +14,18 @@ import io.lbry.browser.utils.Lbry;
|
||||
public class UpdateSuggestedTagsTask extends AsyncTask<Void, Void, List<Tag>> {
|
||||
|
||||
private boolean clearPrevious;
|
||||
private boolean excludeMature;
|
||||
private int limit;
|
||||
private String filter;
|
||||
private TagListAdapter addedTagsAdapter;
|
||||
private TagListAdapter suggestedTagsAdapter;
|
||||
private KnownTagsHandler handler;
|
||||
|
||||
public UpdateSuggestedTagsTask(
|
||||
String filter,
|
||||
int limit,
|
||||
TagListAdapter addedTagsAdapter,
|
||||
TagListAdapter suggestedTagsAdapter,
|
||||
boolean clearPrevious,
|
||||
boolean excludeMature,
|
||||
KnownTagsHandler handler) {
|
||||
public UpdateSuggestedTagsTask(String filter, int limit, TagListAdapter addedTagsAdapter, TagListAdapter suggestedTagsAdapter, boolean clearPrevious, KnownTagsHandler handler) {
|
||||
this.filter = filter;
|
||||
this.limit = limit;
|
||||
this.addedTagsAdapter = addedTagsAdapter;
|
||||
this.suggestedTagsAdapter = suggestedTagsAdapter;
|
||||
this.clearPrevious = clearPrevious;
|
||||
this.excludeMature = excludeMature;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
@@ -47,9 +38,6 @@ public class UpdateSuggestedTagsTask extends AsyncTask<Void, Void, List<Tag>> {
|
||||
}
|
||||
while (tags.size() < limit) {
|
||||
Tag randomTag = Lbry.knownTags.get(random.nextInt(Lbry.knownTags.size()));
|
||||
if (excludeMature && randomTag.isMature()) {
|
||||
continue;
|
||||
}
|
||||
if (!Lbry.followedTags.contains(randomTag) && (addedTagsAdapter == null || !addedTagsAdapter.getTags().contains(randomTag))) {
|
||||
tags.add(randomTag);
|
||||
}
|
||||
@@ -61,9 +49,6 @@ public class UpdateSuggestedTagsTask extends AsyncTask<Void, Void, List<Tag>> {
|
||||
}
|
||||
for (int i = 0; i < Lbry.knownTags.size() && tags.size() < limit - 1; i++) {
|
||||
Tag knownTag = Lbry.knownTags.get(i);
|
||||
if (excludeMature && knownTag.isMature()) {
|
||||
continue;
|
||||
}
|
||||
if ((knownTag.getLowercaseName().startsWith(filter) || knownTag.getLowercaseName().matches(filter)) &&
|
||||
(!tags.contains(knownTag) &&
|
||||
!Lbry.followedTags.contains(knownTag) && (addedTagsAdapter == null || !addedTagsAdapter.getTags().contains(knownTag)))) {
|
||||
|
||||
@@ -7,9 +7,9 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.Random;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.lbry.browser.exceptions.LbryResponseException;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
@@ -47,17 +47,14 @@ public class UploadImageTask extends AsyncTask<Void, Void, String> {
|
||||
}
|
||||
String fileType = String.format("image/%s", extension);
|
||||
RequestBody body = new MultipartBody.Builder().setType(MultipartBody.FORM).
|
||||
addFormDataPart("name", Helper.makeid(24)).
|
||||
addFormDataPart("name", makeid()).
|
||||
addFormDataPart("file", fileName, RequestBody.create(file, MediaType.parse(fileType))).
|
||||
build();
|
||||
Request request = new Request.Builder().url("https://spee.ch/api/claim/publish").post(body).build();
|
||||
OkHttpClient client = new OkHttpClient.Builder().
|
||||
writeTimeout(300, TimeUnit.SECONDS).
|
||||
readTimeout(300, TimeUnit.SECONDS).
|
||||
build();
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
Response response = client.newCall(request).execute();
|
||||
JSONObject json = new JSONObject(response.body().string());
|
||||
if (json.has("success") && Helper.getJSONBoolean("success", false, json)) {
|
||||
if (json.has("success")) {
|
||||
JSONObject data = json.getJSONObject("data");
|
||||
String url = Helper.getJSONString("url", null, data);
|
||||
if (Helper.isNullOrEmpty(url)) {
|
||||
@@ -65,15 +62,9 @@ public class UploadImageTask extends AsyncTask<Void, Void, String> {
|
||||
}
|
||||
|
||||
thumbnailUrl = String.format("%s.%s", url, extension);
|
||||
} else if (json.has("error") || json.has("message")) {
|
||||
JSONObject error = Helper.getJSONObject("error", json);
|
||||
String message = null;
|
||||
if (error != null) {
|
||||
message = Helper.getJSONString("message", null, error);
|
||||
}
|
||||
if (Helper.isNullOrEmpty(message)) {
|
||||
message = Helper.getJSONString("message", null, json);
|
||||
}
|
||||
} else if (json.has("error")) {
|
||||
JSONObject error = json.getJSONObject("error");
|
||||
String message = Helper.getJSONString("message", null, error);
|
||||
throw new LbryResponseException(Helper.isNullOrEmpty(message) ? "The image failed to upload." : message);
|
||||
}
|
||||
} catch (IOException | JSONException | LbryResponseException ex) {
|
||||
@@ -93,6 +84,16 @@ public class UploadImageTask extends AsyncTask<Void, Void, String> {
|
||||
}
|
||||
}
|
||||
|
||||
private static String makeid() {
|
||||
Random random = new Random();
|
||||
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
StringBuilder id = new StringBuilder();
|
||||
for (int i = 0; i < 24; i++) {
|
||||
id.append(chars.charAt(random.nextInt(chars.length())));
|
||||
}
|
||||
return id.toString();
|
||||
}
|
||||
|
||||
public interface UploadThumbnailHandler {
|
||||
void onSuccess(String url);
|
||||
void onError(Exception error);
|
||||
|
||||
@@ -1,63 +0,0 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class AbandonChannelTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private List<String> claimIds;
|
||||
private List<String> successfulClaimIds;
|
||||
private List<String> failedClaimIds;
|
||||
private List<Exception> failedExceptions;
|
||||
private View progressView;
|
||||
private AbandonHandler handler;
|
||||
|
||||
public AbandonChannelTask(List<String> claimIds, View progressView, AbandonHandler handler) {
|
||||
this.claimIds = claimIds;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
Helper.setViewVisibility(progressView, View.VISIBLE);
|
||||
}
|
||||
|
||||
public Boolean doInBackground(Void... params) {
|
||||
successfulClaimIds = new ArrayList<>();
|
||||
failedClaimIds = new ArrayList<>();
|
||||
failedExceptions = new ArrayList<>();
|
||||
|
||||
for (String claimId : claimIds) {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("claim_id", claimId);
|
||||
options.put("blocking", true);
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CHANNEL_ABANDON, options);
|
||||
successfulClaimIds.add(claimId);
|
||||
} catch (ApiCallException ex) {
|
||||
failedClaimIds.add(claimId);
|
||||
failedExceptions.add(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean result) {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
handler.onComplete(successfulClaimIds, failedClaimIds, failedExceptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +0,0 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface AbandonHandler {
|
||||
void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors);
|
||||
}
|
||||
@@ -1,63 +0,0 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class AbandonStreamTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private List<String> claimIds;
|
||||
private List<String> successfulClaimIds;
|
||||
private List<String> failedClaimIds;
|
||||
private List<Exception> failedExceptions;
|
||||
private View progressView;
|
||||
private AbandonHandler handler;
|
||||
|
||||
public AbandonStreamTask(List<String> claimIds, View progressView, AbandonHandler handler) {
|
||||
this.claimIds = claimIds;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
Helper.setViewVisibility(progressView, View.VISIBLE);
|
||||
}
|
||||
|
||||
public Boolean doInBackground(Void... params) {
|
||||
successfulClaimIds = new ArrayList<>();
|
||||
failedClaimIds = new ArrayList<>();
|
||||
failedExceptions = new ArrayList<>();
|
||||
|
||||
for (String claimId : claimIds) {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("claim_id", claimId);
|
||||
options.put("blocking", true);
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_STREAM_ABANDON, options);
|
||||
successfulClaimIds.add(claimId);
|
||||
} catch (ApiCallException ex) {
|
||||
failedClaimIds.add(claimId);
|
||||
failedExceptions.add(ex);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean result) {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
handler.onComplete(successfulClaimIds, failedClaimIds, failedExceptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -19,16 +18,13 @@ import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class ClaimListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
private List<String> types;
|
||||
private String type;
|
||||
private View progressView;
|
||||
private ClaimListResultHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public ClaimListTask(String type, View progressView, ClaimListResultHandler handler) {
|
||||
this(Arrays.asList(type), progressView, handler);
|
||||
}
|
||||
public ClaimListTask(List<String> types, View progressView, ClaimListResultHandler handler) {
|
||||
this.types = types;
|
||||
this.type = type;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
@@ -40,8 +36,8 @@ public class ClaimListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
if (types != null && types.size() > 0) {
|
||||
options.put("claim_type", types);
|
||||
if (!Helper.isNullOrEmpty(type)) {
|
||||
options.put("claim_type", type);
|
||||
}
|
||||
options.put("page", 1);
|
||||
options.put("page_size", 999);
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.model.Claim;
|
||||
|
||||
public interface ClaimSearchResultHandler {
|
||||
void onSuccess(List<Claim> claims, boolean hasReachedEnd);
|
||||
void onError(Exception error);
|
||||
}
|
||||
@@ -2,6 +2,7 @@ package io.lbry.browser.tasks.claim;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
@@ -29,7 +30,7 @@ public class ClaimSearchTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
}
|
||||
protected List<Claim> doInBackground(Void... params) {
|
||||
try {
|
||||
return Helper.filterInvalidReposts(Lbry.claimSearch(options, connectionString));
|
||||
return Lbry.claimSearch(options, connectionString);
|
||||
} catch (ApiCallException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
@@ -46,4 +47,8 @@ public class ClaimSearchTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
}
|
||||
}
|
||||
|
||||
public interface ClaimSearchResultHandler {
|
||||
void onSuccess(List<Claim> claims, boolean hasReachedEnd);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
||||
@@ -1,106 +0,0 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class PublishClaimTask extends AsyncTask<Void, Void, Claim> {
|
||||
private Claim claim;
|
||||
private String filePath;
|
||||
private View progressView;
|
||||
private ClaimResultHandler handler;
|
||||
private Exception error;
|
||||
public PublishClaimTask(Claim claim, String filePath, View progressView, ClaimResultHandler handler) {
|
||||
this.claim = claim;
|
||||
this.filePath = filePath;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
protected void onPreExecute() {
|
||||
Helper.setViewVisibility(progressView, View.VISIBLE);
|
||||
if (handler != null) {
|
||||
handler.beforeStart();
|
||||
}
|
||||
}
|
||||
protected Claim doInBackground(Void... params) {
|
||||
Claim.StreamMetadata metadata = (Claim.StreamMetadata) claim.getValue();
|
||||
DecimalFormat amountFormat = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US));
|
||||
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("blocking", true);
|
||||
options.put("name", claim.getName());
|
||||
options.put("bid", amountFormat.format(new BigDecimal(claim.getAmount()).doubleValue()));
|
||||
options.put("title", Helper.isNullOrEmpty(claim.getTitle()) ? "" : claim.getTitle());
|
||||
options.put("description", Helper.isNullOrEmpty(claim.getDescription()) ? "" : claim.getDescription());
|
||||
options.put("thumbnail_url", Helper.isNullOrEmpty(claim.getThumbnailUrl()) ? "" : claim.getThumbnailUrl());
|
||||
|
||||
if (!Helper.isNullOrEmpty(filePath)) {
|
||||
options.put("file_path", filePath);
|
||||
}
|
||||
if (claim.getTags() != null && claim.getTags().size() > 0) {
|
||||
options.put("tags", new ArrayList<>(claim.getTags()));
|
||||
}
|
||||
if (metadata.getFee() != null) {
|
||||
options.put("fee_currency", metadata.getFee().getCurrency());
|
||||
options.put("fee_amount", amountFormat.format(new BigDecimal(metadata.getFee().getAmount()).doubleValue()));
|
||||
}
|
||||
if (claim.getSigningChannel() != null) {
|
||||
options.put("channel_id", claim.getSigningChannel().getClaimId());
|
||||
}
|
||||
if (metadata.getLanguages() != null && metadata.getLanguages().size() > 0) {
|
||||
options.put("languages", metadata.getLanguages());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(metadata.getLicense())) {
|
||||
options.put("license", metadata.getLicense());
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(metadata.getLicenseUrl())) {
|
||||
options.put("license_url", metadata.getLicenseUrl());
|
||||
}
|
||||
|
||||
Claim claimResult = null;
|
||||
try {
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PUBLISH, options);
|
||||
if (result.has("outputs")) {
|
||||
JSONArray outputs = result.getJSONArray("outputs");
|
||||
for (int i = 0; i < outputs.length(); i++) {
|
||||
JSONObject output = outputs.getJSONObject(i);
|
||||
if (output.has("claim_id") && output.has("claim_op")) {
|
||||
claimResult = Claim.claimFromOutput(output);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (ApiCallException | ClassCastException | JSONException ex) {
|
||||
error = ex;
|
||||
}
|
||||
|
||||
return claimResult;
|
||||
|
||||
}
|
||||
protected void onPostExecute(Claim result) {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
if (result != null) {
|
||||
handler.onSuccess(result);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,70 +0,0 @@
|
||||
package io.lbry.browser.tasks.claim;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class PurchaseListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
private int page;
|
||||
private int pageSize;
|
||||
private ClaimSearchResultHandler handler;
|
||||
private View progressView;
|
||||
private Exception error;
|
||||
|
||||
public PurchaseListTask(int page, int pageSize, View progressView, ClaimSearchResultHandler handler) {
|
||||
this.page = page;
|
||||
this.pageSize = pageSize;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
Helper.setViewVisibility(progressView, View.VISIBLE);
|
||||
}
|
||||
protected List<Claim> doInBackground(Void... params) {
|
||||
List<Claim> claims = null;
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("page", page);
|
||||
options.put("page_size", pageSize);
|
||||
options.put("resolve", true);
|
||||
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PURCHASE_LIST, options);
|
||||
JSONArray items = result.getJSONArray("items");
|
||||
claims = new ArrayList<>();
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
Claim claim = Claim.fromJSONObject(items.getJSONObject(i).getJSONObject("claim"));
|
||||
claims.add(claim);
|
||||
|
||||
Lbry.addClaimToCache(claim);
|
||||
}
|
||||
} catch (ApiCallException | JSONException | ClassCastException ex) {
|
||||
error = ex;
|
||||
}
|
||||
|
||||
return claims;
|
||||
}
|
||||
protected void onPostExecute(List<Claim> claims) {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
if (claims != null) {
|
||||
handler.onSuccess(claims, claims.size() < pageSize);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,7 @@ public class ResolveTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
}
|
||||
protected List<Claim> doInBackground(Void... params) {
|
||||
try {
|
||||
return Helper.filterInvalidReposts(Lbry.resolve(urls, connectionString));
|
||||
return Lbry.resolve(urls, connectionString);
|
||||
} catch (ApiCallException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
|
||||
@@ -9,9 +9,7 @@ import org.json.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
@@ -42,7 +40,7 @@ public class StreamRepostTask extends AsyncTask<Void, Void, Claim> {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("name", name);
|
||||
options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(bid.doubleValue()));
|
||||
options.put("bid", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT).format(bid.doubleValue()));
|
||||
options.put("claim_id", claimId);
|
||||
options.put("channel_id", channelId);
|
||||
|
||||
|
||||
@@ -1,32 +0,0 @@
|
||||
package io.lbry.browser.tasks.file;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
// Just run delete on the specified claim IDs (no need for a handler)
|
||||
public class BulkDeleteFilesTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private List<String> claimIds;
|
||||
public BulkDeleteFilesTask(List<String> claimIds) {
|
||||
this.claimIds = claimIds;
|
||||
}
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
for (String claimId : claimIds) {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("claim_id", claimId);
|
||||
options.put("delete_from_download_dir", true);
|
||||
Lbry.genericApiCall(Lbry.METHOD_FILE_DELETE, options);
|
||||
} catch (ApiCallException ex) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -26,7 +26,6 @@ public class DeleteFileTask extends AsyncTask<Void, Void, Boolean> {
|
||||
options.put("delete_from_download_dir", true);
|
||||
return (boolean) Lbry.genericApiCall(Lbry.METHOD_FILE_DELETE, options);
|
||||
} catch (ApiCallException ex) {
|
||||
error = ex;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,18 +12,12 @@ import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class FileListTask extends AsyncTask<Void, Void, List<LbryFile>> {
|
||||
private String claimId;
|
||||
private boolean downloads;
|
||||
private int page;
|
||||
private int pageSize;
|
||||
private FileListResultHandler handler;
|
||||
private View progressView;
|
||||
private ApiCallException error;
|
||||
|
||||
public FileListTask(int page, int pageSize, boolean downloads, View progressView, FileListResultHandler handler) {
|
||||
public FileListTask(View progressView, FileListResultHandler handler) {
|
||||
this(null, progressView, handler);
|
||||
this.page = page;
|
||||
this.pageSize = pageSize;
|
||||
this.downloads = downloads;
|
||||
}
|
||||
|
||||
public FileListTask(String claimId, View progressView, FileListResultHandler handler) {
|
||||
@@ -36,7 +30,7 @@ public class FileListTask extends AsyncTask<Void, Void, List<LbryFile>> {
|
||||
}
|
||||
protected List<LbryFile> doInBackground(Void... params) {
|
||||
try {
|
||||
return Lbry.fileList(claimId, downloads, page, pageSize);
|
||||
return Lbry.fileList(claimId);
|
||||
} catch (ApiCallException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
@@ -46,7 +40,7 @@ public class FileListTask extends AsyncTask<Void, Void, List<LbryFile>> {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
if (files != null) {
|
||||
handler.onSuccess(files, files.size() < pageSize);
|
||||
handler.onSuccess(files);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
@@ -54,7 +48,7 @@ public class FileListTask extends AsyncTask<Void, Void, List<LbryFile>> {
|
||||
}
|
||||
|
||||
public interface FileListResultHandler {
|
||||
void onSuccess(List<LbryFile> files, boolean hasReachedEnd);
|
||||
void onSuccess(List<LbryFile> files);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,8 @@ public class ChannelSubscribeTask extends AsyncTask<Void, Void, Boolean> {
|
||||
} catch (LbryioRequestException | LbryioResponseException | SQLiteException ex) {
|
||||
error = ex;
|
||||
return false;
|
||||
} finally {
|
||||
Helper.closeDatabase(db);
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
@@ -64,6 +64,8 @@ public class FetchSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
||||
} catch (ClassCastException | LbryioRequestException | LbryioResponseException | JSONException | IllegalStateException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
} finally {
|
||||
Helper.closeDatabase(db);
|
||||
}
|
||||
|
||||
return subscriptions;
|
||||
|
||||
+7
-12
@@ -9,21 +9,21 @@ import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.model.UrlSuggestion;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
|
||||
public class SaveUrlHistoryTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private DatabaseHelper dbHelper;
|
||||
public class CreateUrlHistoryTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private Context context;
|
||||
private UrlSuggestion suggestion;
|
||||
private SaveUrlHistoryHandler handler;
|
||||
private GenericTaskHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public SaveUrlHistoryTask(UrlSuggestion suggestion, DatabaseHelper dbHelper, SaveUrlHistoryHandler handler) {
|
||||
public CreateUrlHistoryTask(UrlSuggestion suggestion, Context context, GenericTaskHandler handler) {
|
||||
this.suggestion = suggestion;
|
||||
this.dbHelper = dbHelper;
|
||||
this.context = context;
|
||||
this.handler = handler;
|
||||
|
||||
}
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
try {
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
SQLiteDatabase db = ((MainActivity) context).getDbHelper().getWritableDatabase();
|
||||
DatabaseHelper.createOrUpdateUrlHistoryItem(suggestion.getText(), suggestion.getUri().toString(), suggestion.getType(), db);
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
@@ -35,15 +35,10 @@ public class SaveUrlHistoryTask extends AsyncTask<Void, Void, Boolean> {
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (handler != null) {
|
||||
if (result) {
|
||||
handler.onSuccess(suggestion);
|
||||
handler.onSuccess();
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface SaveUrlHistoryHandler {
|
||||
void onSuccess(UrlSuggestion item);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
||||
@@ -1,37 +0,0 @@
|
||||
package io.lbry.browser.tasks.localdata;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.model.UrlSuggestion;
|
||||
|
||||
public class FetchRecentUrlHistoryTask extends AsyncTask<Void, Void, List<UrlSuggestion>> {
|
||||
private DatabaseHelper dbHelper;
|
||||
private FetchRecentUrlHistoryHandler handler;
|
||||
public FetchRecentUrlHistoryTask(DatabaseHelper dbHelper, FetchRecentUrlHistoryHandler handler) {
|
||||
this.dbHelper = dbHelper;
|
||||
this.handler = handler;
|
||||
}
|
||||
protected List<UrlSuggestion> doInBackground(Void... params) {
|
||||
try {
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
return DatabaseHelper.getRecentHistory(db);
|
||||
} catch (SQLiteException ex) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
protected void onPostExecute(List<UrlSuggestion> recentHistory) {
|
||||
if (handler != null) {
|
||||
handler.onSuccess(recentHistory);
|
||||
}
|
||||
}
|
||||
|
||||
public interface FetchRecentUrlHistoryHandler {
|
||||
void onSuccess(List<UrlSuggestion> recentHistory);
|
||||
}
|
||||
}
|
||||
@@ -1,46 +0,0 @@
|
||||
package io.lbry.browser.tasks.localdata;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.model.UrlSuggestion;
|
||||
import io.lbry.browser.model.ViewHistory;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
|
||||
public class FetchViewHistoryTask extends AsyncTask<Void, Void, List<ViewHistory>> {
|
||||
private DatabaseHelper dbHelper;
|
||||
private FetchViewHistoryHandler handler;
|
||||
private int pageSize;
|
||||
private Date lastDate;
|
||||
public FetchViewHistoryTask(Date lastDate, int pageSize, DatabaseHelper dbHelper, FetchViewHistoryHandler handler) {
|
||||
this.lastDate = lastDate;
|
||||
this.pageSize = pageSize;
|
||||
this.dbHelper = dbHelper;
|
||||
this.handler = handler;
|
||||
}
|
||||
protected List<ViewHistory> doInBackground(Void... params) {
|
||||
try {
|
||||
SQLiteDatabase db = dbHelper.getReadableDatabase();
|
||||
return DatabaseHelper.getViewHistory(
|
||||
lastDate == null ? null : new SimpleDateFormat(Helper.ISO_DATE_FORMAT_PATTERN).format(lastDate), pageSize, db);
|
||||
} catch (SQLiteException ex) {
|
||||
return new ArrayList<>();
|
||||
}
|
||||
}
|
||||
protected void onPostExecute(List<ViewHistory> history) {
|
||||
if (handler != null) {
|
||||
handler.onSuccess(history, history.size() < pageSize);
|
||||
}
|
||||
}
|
||||
|
||||
public interface FetchViewHistoryHandler {
|
||||
void onSuccess(List<ViewHistory> history, boolean hasReachedEnd);
|
||||
}
|
||||
}
|
||||
@@ -1,136 +0,0 @@
|
||||
package io.lbry.browser.tasks.localdata;
|
||||
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Context;
|
||||
import android.database.Cursor;
|
||||
import android.database.sqlite.SQLiteException;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.provider.MediaStore;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.model.GalleryItem;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
|
||||
public class LoadGalleryItemsTask extends AsyncTask<Void, GalleryItem, List<GalleryItem>> {
|
||||
private static final String TAG = "LoadGalleryItemsTask";
|
||||
private LoadGalleryHandler handler;
|
||||
private View progressView;
|
||||
private Context context;
|
||||
|
||||
public LoadGalleryItemsTask(View progressView, Context context, LoadGalleryHandler handler) {
|
||||
this.progressView = progressView;
|
||||
this.context = context;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected void onPreExecute(Void... params) {
|
||||
Helper.setViewVisibility(progressView, View.VISIBLE);
|
||||
}
|
||||
|
||||
protected List<GalleryItem> doInBackground(Void... params) {
|
||||
List<GalleryItem> items = new ArrayList<>();
|
||||
List<GalleryItem> itemsWithThumbnails = new ArrayList<>();
|
||||
Cursor cursor = null;
|
||||
if (context != null) {
|
||||
ContentResolver resolver = context.getContentResolver();
|
||||
try {
|
||||
String[] projection = {
|
||||
MediaStore.MediaColumns._ID,
|
||||
MediaStore.MediaColumns.DATA,
|
||||
MediaStore.MediaColumns.DISPLAY_NAME,
|
||||
MediaStore.MediaColumns.MIME_TYPE,
|
||||
MediaStore.Video.Media.DURATION
|
||||
};
|
||||
cursor = resolver.query(
|
||||
MediaStore.Video.Media.EXTERNAL_CONTENT_URI,
|
||||
projection, null, null,
|
||||
String.format("%s DESC", MediaStore.MediaColumns.DATE_MODIFIED));
|
||||
while (cursor.moveToNext()) {
|
||||
int idColumn = cursor.getColumnIndex(MediaStore.MediaColumns._ID);
|
||||
int nameColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DISPLAY_NAME);
|
||||
int typeColumn = cursor.getColumnIndex(MediaStore.MediaColumns.MIME_TYPE);
|
||||
int pathColumn = cursor.getColumnIndex(MediaStore.MediaColumns.DATA);
|
||||
int durationColumn = cursor.getColumnIndex(MediaStore.Video.Media.DURATION);
|
||||
|
||||
GalleryItem item = new GalleryItem();
|
||||
item.setId(cursor.getString(idColumn));
|
||||
item.setName(cursor.getString(nameColumn));
|
||||
item.setType(cursor.getString(typeColumn));
|
||||
item.setFilePath(cursor.getString(pathColumn));
|
||||
item.setDuration(cursor.getLong(durationColumn));
|
||||
items.add(item);
|
||||
}
|
||||
} catch (SQLiteException ex) {
|
||||
|
||||
// failed to load videos. log and pass
|
||||
Log.e(TAG, ex.getMessage(), ex);
|
||||
} finally {
|
||||
Helper.closeCursor(cursor);
|
||||
}
|
||||
|
||||
// load (or generate) thumbnail for each item
|
||||
for (GalleryItem item : items) {
|
||||
String id = item.getId();
|
||||
File cacheDir = context.getExternalCacheDir();
|
||||
File thumbnailsDir = new File(String.format("%s/thumbnails", cacheDir.getAbsolutePath()));
|
||||
if (!thumbnailsDir.isDirectory()) {
|
||||
thumbnailsDir.mkdirs();
|
||||
}
|
||||
|
||||
String thumbnailPath = String.format("%s/%s.png", thumbnailsDir.getAbsolutePath(), id);
|
||||
File file = new File(thumbnailPath);
|
||||
if (!file.exists()) {
|
||||
// save the thumbnail to the path
|
||||
BitmapFactory.Options options = new BitmapFactory.Options();
|
||||
options.inSampleSize = 1;
|
||||
Bitmap thumbnail = MediaStore.Video.Thumbnails.getThumbnail(
|
||||
resolver, Long.parseLong(id), MediaStore.Video.Thumbnails.MINI_KIND, options);
|
||||
if (thumbnail != null) {
|
||||
try (FileOutputStream os = new FileOutputStream(thumbnailPath)) {
|
||||
thumbnail.compress(Bitmap.CompressFormat.PNG, 80, os);
|
||||
} catch (IOException ex) {
|
||||
// skip
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (file.exists() && file.length() > 0) {
|
||||
item.setThumbnailPath(file.getAbsolutePath());
|
||||
itemsWithThumbnails.add(item);
|
||||
publishProgress(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return itemsWithThumbnails;
|
||||
}
|
||||
|
||||
protected void onProgressUpdate(GalleryItem... items) {
|
||||
if (handler != null) {
|
||||
for (GalleryItem item : items) {
|
||||
handler.onItemLoaded(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(List<GalleryItem> items) {
|
||||
if (handler != null) {
|
||||
handler.onAllItemsLoaded(items);
|
||||
}
|
||||
}
|
||||
|
||||
public interface LoadGalleryHandler {
|
||||
void onItemLoaded(GalleryItem item);
|
||||
void onAllItemsLoaded(List<GalleryItem> items);
|
||||
}
|
||||
}
|
||||
@@ -1,45 +0,0 @@
|
||||
package io.lbry.browser.tasks.localdata;
|
||||
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.model.ViewHistory;
|
||||
|
||||
public class SaveViewHistoryTask extends AsyncTask<Void, Void, Boolean> {
|
||||
private DatabaseHelper dbHelper;
|
||||
private ViewHistory history;
|
||||
private SaveViewHistoryHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public SaveViewHistoryTask(ViewHistory history, DatabaseHelper dbHelper, SaveViewHistoryHandler handler) {
|
||||
this.history = history;
|
||||
this.dbHelper = dbHelper;
|
||||
this.handler = handler;
|
||||
}
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
try {
|
||||
SQLiteDatabase db = dbHelper.getWritableDatabase();
|
||||
DatabaseHelper.createOrUpdateViewHistoryItem(history, db);
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (handler != null) {
|
||||
if (result) {
|
||||
handler.onSuccess(history);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface SaveViewHistoryHandler {
|
||||
void onSuccess(ViewHistory item);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
||||
@@ -83,7 +83,7 @@ public class LoadSharedUserStateTask extends AsyncTask<Void, Void, Boolean> {
|
||||
if (db != null) {
|
||||
DatabaseHelper.createOrUpdateSubscription(subscription, db);
|
||||
}
|
||||
} catch (LbryUriException | SQLiteException | IllegalStateException ex) {
|
||||
} catch (LbryUriException | SQLiteException ex) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,7 @@ import android.view.View;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.HashMap;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
@@ -41,7 +39,7 @@ public class SupportCreateTask extends AsyncTask<Void, Void, Boolean> {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("claim_id", claimId);
|
||||
options.put("amount", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(amount.doubleValue()));
|
||||
options.put("amount", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT).format(amount.doubleValue()));
|
||||
options.put("tip", tip);
|
||||
Lbry.genericApiCall(Lbry.METHOD_SUPPORT_CREATE, options);
|
||||
} catch (ApiCallException ex) {
|
||||
|
||||
@@ -45,7 +45,7 @@ public class SyncSetTask extends AsyncTask<Void, Void, String> {
|
||||
if (handler != null) {
|
||||
if (!Helper.isNullOrEmpty(hash)) {
|
||||
handler.onSyncSetSuccess(hash);
|
||||
} else {
|
||||
} else if (error != null) {
|
||||
handler.onSyncSetError(error);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15,46 +15,11 @@ public class BaseFragment extends Fragment {
|
||||
@Setter
|
||||
private Map<String, Object> params;
|
||||
|
||||
public boolean shouldHideGlobalPlayer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean shouldSuspendGlobalPlayer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
if (shouldSuspendGlobalPlayer()) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity.suspendGlobalPlayer(context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
if (shouldSuspendGlobalPlayer()) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity.resumeGlobalPlayer(context);
|
||||
}
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.setSelectedMenuItemForFragment(this);
|
||||
|
||||
if (shouldHideGlobalPlayer()) {
|
||||
activity.hideGlobalNowPlaying();
|
||||
} else {
|
||||
activity.checkNowPlaying();
|
||||
}
|
||||
((MainActivity) context).setSelectedMenuItemForFragment(this);
|
||||
}
|
||||
}
|
||||
}
|
||||
+22
-46
@@ -1,6 +1,7 @@
|
||||
package io.lbry.browser.ui.findcontent;
|
||||
package io.lbry.browser.ui.allcontent;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -16,14 +17,12 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.FileViewActivity;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ClaimListAdapter;
|
||||
@@ -31,12 +30,9 @@ import io.lbry.browser.dialog.ContentFromDialogFragment;
|
||||
import io.lbry.browser.dialog.ContentScopeDialogFragment;
|
||||
import io.lbry.browser.dialog.ContentSortDialogFragment;
|
||||
import io.lbry.browser.dialog.CustomizeTagsDialogFragment;
|
||||
import io.lbry.browser.listener.DownloadActionListener;
|
||||
import io.lbry.browser.listener.TagListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.model.Tag;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchTask;
|
||||
import io.lbry.browser.tasks.FollowUnfollowTagTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
@@ -47,7 +43,7 @@ import io.lbry.browser.utils.Predefined;
|
||||
import lombok.Getter;
|
||||
|
||||
// TODO: Similar code to FollowingFragment and Channel page fragment. Probably make common operations (sorting/filtering) into a control
|
||||
public class AllContentFragment extends BaseFragment implements DownloadActionListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class AllContentFragment extends BaseFragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Getter
|
||||
private boolean singleTagView;
|
||||
@@ -211,7 +207,6 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
singleTagView = true;
|
||||
tags = Arrays.asList(tagName);
|
||||
titleView.setText(Helper.capitalize(tagName));
|
||||
Helper.setViewVisibility(customizeLink, View.GONE);
|
||||
} else {
|
||||
singleTagView = false;
|
||||
// default to followed Tags scope if any tags are followed
|
||||
@@ -223,8 +218,8 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
titleView.setText(getString(R.string.all_content));
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(forPrefix, singleTagView ? View.GONE : View.VISIBLE);
|
||||
Helper.setViewVisibility(scopeLink, singleTagView ? View.GONE : View.VISIBLE);
|
||||
forPrefix.setVisibility(singleTagView ? View.GONE : View.VISIBLE);
|
||||
scopeLink.setVisibility(singleTagView ? View.GONE : View.VISIBLE);
|
||||
|
||||
if (reload) {
|
||||
fetchClaimSearchContent(true);
|
||||
@@ -379,7 +374,6 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
} else {
|
||||
LbryAnalytics.setCurrentScreen(activity, "All Content", "AllContent");
|
||||
}
|
||||
activity.addDownloadActionListener(this);
|
||||
}
|
||||
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
||||
@@ -390,11 +384,7 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
((MainActivity) context).removeDownloadActionListener(this);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -442,7 +432,7 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
contentClaimSearchLoading = true;
|
||||
Helper.setViewVisibility(noContentView, View.GONE);
|
||||
Map<String, Object> claimSearchOptions = buildContentOptions();
|
||||
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.LBRY_TV_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
|
||||
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.LBRY_TV_CONNECTION_STRING, getLoadingView(), new ClaimSearchTask.ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
if (contentListAdapter == null) {
|
||||
@@ -450,15 +440,21 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (claim.getName().startsWith("@")) {
|
||||
// channel claim
|
||||
activity.openChannelClaim(claim);
|
||||
} else {
|
||||
activity.openFileClaim(claim);
|
||||
String claimId = claim.getClaimId();
|
||||
String url = !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl();
|
||||
|
||||
if (claim.getName().startsWith("@")) {
|
||||
// channel claim
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openChannelClaim(claim);
|
||||
}
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), FileViewActivity.class);
|
||||
intent.putExtra("claimId", claimId);
|
||||
intent.putExtra("url", url);
|
||||
MainActivity.startingFileViewActivity = true;
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -494,24 +490,4 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
fetchClaimSearchContent(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
|
||||
if ("abort".equals(downloadAction)) {
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.clearFileForClaimOrUrl(outpoint, uri);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject fileInfo = new JSONObject(fileInfoJson);
|
||||
LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
|
||||
String claimId = claimFile.getClaimId();
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri);
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
// invalid file info for download
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
package io.lbry.browser.ui.channel;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -15,30 +16,25 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.FileViewActivity;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ClaimListAdapter;
|
||||
import io.lbry.browser.dialog.ContentFromDialogFragment;
|
||||
import io.lbry.browser.dialog.ContentSortDialogFragment;
|
||||
import io.lbry.browser.listener.DownloadActionListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchTask;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.Predefined;
|
||||
import lombok.Setter;
|
||||
|
||||
public class ChannelContentFragment extends Fragment implements DownloadActionListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
public class ChannelContentFragment extends Fragment implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
@Setter
|
||||
private String channelId;
|
||||
@@ -193,20 +189,12 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
((MainActivity) context).addDownloadActionListener(this);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
||||
fetchClaimSearchContent();
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
((MainActivity) context).removeDownloadActionListener(this);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).registerOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -214,7 +202,7 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
||||
Context context = getContext();
|
||||
boolean canShowMatureContent = false;
|
||||
if (context != null) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
}
|
||||
|
||||
@@ -254,7 +242,7 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
||||
contentClaimSearchLoading = true;
|
||||
Helper.setViewVisibility(noContentView, View.GONE);
|
||||
Map<String, Object> claimSearchOptions = buildContentOptions();
|
||||
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.LBRY_TV_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
|
||||
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.LBRY_TV_CONNECTION_STRING, getLoadingView(), new ClaimSearchTask.ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
if (contentListAdapter == null) {
|
||||
@@ -262,15 +250,20 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (claim.getName().startsWith("@")) {
|
||||
// channel claim
|
||||
activity.openChannelClaim(claim);
|
||||
} else {
|
||||
activity.openFileClaim(claim);
|
||||
String claimId = claim.getClaimId();
|
||||
String url = !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl();
|
||||
if (claim.getName().startsWith("@")) {
|
||||
// channel claim
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openChannelClaim(claim);
|
||||
}
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), FileViewActivity.class);
|
||||
intent.putExtra("claimId", claimId);
|
||||
intent.putExtra("url", url);
|
||||
MainActivity.startingFileViewActivity = true;
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -306,24 +299,4 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
||||
fetchClaimSearchContent(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
|
||||
if ("abort".equals(downloadAction)) {
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.clearFileForClaimOrUrl(outpoint, uri);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject fileInfo = new JSONObject(fileInfoJson);
|
||||
LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
|
||||
String claimId = claimFile.getClaimId();
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri);
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
// invalid file info for download
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,7 +18,6 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.widget.NestedScrollView;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
@@ -38,8 +37,6 @@ import io.lbry.browser.BuildConfig;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.TagListAdapter;
|
||||
import io.lbry.browser.listener.FilePickerListener;
|
||||
import io.lbry.browser.listener.StoragePermissionListener;
|
||||
import io.lbry.browser.listener.WalletBalanceListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.NavMenuItem;
|
||||
@@ -47,7 +44,7 @@ import io.lbry.browser.model.Tag;
|
||||
import io.lbry.browser.model.WalletBalance;
|
||||
import io.lbry.browser.tasks.UpdateSuggestedTagsTask;
|
||||
import io.lbry.browser.tasks.UploadImageTask;
|
||||
import io.lbry.browser.tasks.claim.ChannelCreateUpdateTask;
|
||||
import io.lbry.browser.tasks.ChannelCreateUpdateTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimResultHandler;
|
||||
import io.lbry.browser.tasks.lbryinc.LogPublishTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
@@ -57,8 +54,7 @@ import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ChannelFormFragment extends BaseFragment implements
|
||||
FilePickerListener, StoragePermissionListener, TagListAdapter.TagClickListener, WalletBalanceListener {
|
||||
public class ChannelFormFragment extends BaseFragment implements WalletBalanceListener, TagListAdapter.TagClickListener {
|
||||
|
||||
private static final int SUGGESTED_LIMIT = 8;
|
||||
|
||||
@@ -72,7 +68,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
private TextView linkShowOptional;
|
||||
private MaterialButton buttonSave;
|
||||
|
||||
private NestedScrollView scrollView;
|
||||
private View inlineBalanceContainer;
|
||||
private TextView inlineBalanceValue;
|
||||
private View uploadProgress;
|
||||
@@ -114,7 +109,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_channel_form, container, false);
|
||||
|
||||
scrollView = root.findViewById(R.id.channel_form_scroll_view);
|
||||
linkCancel = root.findViewById(R.id.channel_form_cancel_link);
|
||||
linkShowOptional = root.findViewById(R.id.channel_form_toggle_optional);
|
||||
buttonSave = root.findViewById(R.id.channel_form_save_button);
|
||||
@@ -140,7 +134,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
Context context = getContext();
|
||||
FlexboxLayoutManager flm1 = new FlexboxLayoutManager(context);
|
||||
FlexboxLayoutManager flm2 = new FlexboxLayoutManager(context);
|
||||
FlexboxLayoutManager flm3 = new FlexboxLayoutManager(context);
|
||||
addedTagsList = root.findViewById(R.id.form_added_tags);
|
||||
addedTagsList.setLayoutManager(flm1);
|
||||
suggestedTagsList = root.findViewById(R.id.form_suggested_tags);
|
||||
@@ -150,7 +143,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
addedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_REMOVE);
|
||||
addedTagsAdapter.setClickListener(this);
|
||||
addedTagsList.setAdapter(addedTagsAdapter);
|
||||
|
||||
suggestedTagsAdapter = new TagListAdapter(new ArrayList<>(), getContext());
|
||||
suggestedTagsAdapter.setCustomizeMode(TagListAdapter.CUSTOMIZE_MODE_ADD);
|
||||
suggestedTagsAdapter.setClickListener(this);
|
||||
@@ -173,12 +165,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
if (containerOptionalFields.getVisibility() != View.VISIBLE) {
|
||||
containerOptionalFields.setVisibility(View.VISIBLE);
|
||||
linkShowOptional.setText(R.string.hide_optional_fields);
|
||||
scrollView.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
scrollView.fullScroll(NestedScrollView.FOCUS_DOWN);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
containerOptionalFields.setVisibility(View.GONE);
|
||||
linkShowOptional.setText(R.string.show_optional_fields);
|
||||
@@ -289,17 +275,16 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private void validateAndSaveClaim(Claim claim) {
|
||||
if (!editMode && Helper.isNullOrEmpty(claim.getName())) {
|
||||
showError(getString(R.string.please_enter_channel_name));
|
||||
return;
|
||||
}
|
||||
|
||||
String channelName = claim.getName().startsWith("@") ? claim.getName().substring(1) : claim.getName();
|
||||
if (!LbryUri.isNameValid(channelName)) {
|
||||
showError(getString(R.string.channel_name_invalid_characters));
|
||||
return;
|
||||
}
|
||||
if (!editMode) {
|
||||
String channelName = claim.getName().startsWith("@") ? claim.getName().substring(1) : claim.getName();
|
||||
if (Helper.isNullOrEmpty(channelName)) {
|
||||
showError(getString(R.string.please_enter_channel_name));
|
||||
return;
|
||||
}
|
||||
if (!LbryUri.isNameValid(channelName)) {
|
||||
showError(getString(R.string.channel_name_invalid_characters));
|
||||
return;
|
||||
}
|
||||
if (Helper.channelExists(channelName)) {
|
||||
showError(getString(R.string.channel_name_already_created));
|
||||
return;
|
||||
@@ -341,14 +326,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
logPublish.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
if (!editMode) {
|
||||
// channel created
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("claim_id", claimResult.getClaimId());
|
||||
bundle.putString("claim_name", claimResult.getName());
|
||||
LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
@@ -369,7 +346,7 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
private void showError(String message) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -456,15 +433,9 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
if (getContext() != null) {
|
||||
showError(getString(R.string.image_upload_failed));
|
||||
}
|
||||
if (coverFilePickerActive) {
|
||||
// cover selected
|
||||
imageCover.setImageResource(R.drawable.default_channel_cover);
|
||||
} else if (thumbnailFilePickerActive) {
|
||||
imageThumbnail.setImageDrawable(null);
|
||||
}
|
||||
Snackbar.make(getView(), R.string.image_upload_failed, Snackbar.LENGTH_LONG).setBackgroundTint(
|
||||
ContextCompat.getColor(context, R.color.red)
|
||||
).show();
|
||||
coverFilePickerActive = false;
|
||||
thumbnailFilePickerActive = false;
|
||||
uploading = false;
|
||||
@@ -499,12 +470,12 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
activity.showNavigationBackIcon();
|
||||
activity.lockDrawer();
|
||||
activity.hideFloatingWalletBalance();
|
||||
|
||||
activity.addFilePickerListener(this);
|
||||
activity.addWalletBalanceListener(this);
|
||||
|
||||
activity.setActionBarTitle(editMode ? R.string.edit_channel : R.string.create_a_channel);
|
||||
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(editMode ? R.string.edit_channel : R.string.create_a_channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -519,12 +490,10 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) getContext();
|
||||
activity.removeStoragePermissionListener(this);
|
||||
activity.removeWalletBalanceListener(this);
|
||||
activity.restoreToggle();
|
||||
activity.showFloatingWalletBalance();
|
||||
if (!MainActivity.startingFilePickerActivity) {
|
||||
activity.removeFilePickerListener(this);
|
||||
activity.removeNavFragment(ChannelFormFragment.class, NavMenuItem.ID_ITEM_CHANNELS);
|
||||
}
|
||||
}
|
||||
@@ -540,9 +509,11 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Channel Form", "ChannelForm");
|
||||
activity.addStoragePermissionListener(this);
|
||||
if (editMode) {
|
||||
activity.setActionBarTitle(R.string.edit_channel);
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(R.string.edit_channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
String filterText = Helper.getValue(inputTagFilter.getText());
|
||||
@@ -560,11 +531,8 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
Snackbar.make(getView(), getString(R.string.tag_already_added, tag.getName()), Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
if (addedTagsAdapter.getItemCount() == 5) {
|
||||
Snackbar.make(getView(), R.string.tag_limit_reached, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
tag.setFollowed(true);
|
||||
addedTagsAdapter.addTag(tag);
|
||||
if (suggestedTagsAdapter != null) {
|
||||
suggestedTagsAdapter.removeTag(tag);
|
||||
@@ -575,6 +543,7 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
checkNoTagResults();
|
||||
}
|
||||
public void removeTag(Tag tag) {
|
||||
tag.setFollowed(false);
|
||||
addedTagsAdapter.removeTag(tag);
|
||||
updateSuggestedTags(currentFilter, SUGGESTED_LIMIT, false);
|
||||
checkNoAddedTags();
|
||||
@@ -594,14 +563,7 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private void updateSuggestedTags(String filter, int limit, boolean clearPrevious) {
|
||||
UpdateSuggestedTagsTask task = new UpdateSuggestedTagsTask(
|
||||
filter,
|
||||
limit,
|
||||
addedTagsAdapter,
|
||||
suggestedTagsAdapter,
|
||||
clearPrevious,
|
||||
false,
|
||||
new UpdateSuggestedTagsTask.KnownTagsHandler() {
|
||||
UpdateSuggestedTagsTask task = new UpdateSuggestedTagsTask(filter, limit, addedTagsAdapter, suggestedTagsAdapter, clearPrevious, new UpdateSuggestedTagsTask.KnownTagsHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Tag> tags) {
|
||||
if (suggestedTagsAdapter == null) {
|
||||
@@ -624,13 +586,13 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
|
||||
private Claim buildChannelClaimToSave() {
|
||||
Claim claim = new Claim();
|
||||
String name = Helper.getValue(inputChannelName.getText());
|
||||
if (!name.startsWith("@")) {
|
||||
name = String.format("@%s", name);
|
||||
}
|
||||
claim.setName(name);
|
||||
|
||||
if (currentClaim != null) {
|
||||
if (!editMode) {
|
||||
String name = Helper.getValue(inputChannelName.getText());
|
||||
if (!name.startsWith("@")) {
|
||||
name = String.format("@%s", name);
|
||||
}
|
||||
claim.setName(name);
|
||||
} else if (currentClaim != null) {
|
||||
claim.setClaimId(currentClaim.getClaimId());
|
||||
}
|
||||
|
||||
|
||||
@@ -1,9 +1,7 @@
|
||||
package io.lbry.browser.ui.channel;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -11,10 +9,8 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
@@ -30,7 +26,6 @@ import com.google.android.material.tabs.TabLayoutMediator;
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -40,18 +35,14 @@ import io.lbry.browser.dialog.SendTipDialogFragment;
|
||||
import io.lbry.browser.exceptions.LbryUriException;
|
||||
import io.lbry.browser.listener.FetchChannelsListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.ClaimCacheKey;
|
||||
import io.lbry.browser.model.UrlSuggestion;
|
||||
import io.lbry.browser.model.lbryinc.Subscription;
|
||||
import io.lbry.browser.tasks.claim.AbandonChannelTask;
|
||||
import io.lbry.browser.tasks.claim.AbandonHandler;
|
||||
import io.lbry.browser.tasks.lbryinc.ChannelSubscribeTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ResolveTask;
|
||||
import io.lbry.browser.tasks.lbryinc.FetchStatCountTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.ui.controls.SolidIconView;
|
||||
import io.lbry.browser.ui.findcontent.FollowingFragment;
|
||||
import io.lbry.browser.ui.following.FollowingFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
@@ -82,6 +73,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
private View buttonFollowUnfollow;
|
||||
private int subCount;
|
||||
private SolidIconView iconFollowUnfollow;
|
||||
|
||||
private View layoutNothingAtLocation;
|
||||
private View layoutLoadingState;
|
||||
|
||||
@@ -127,16 +119,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (claim != null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
|
||||
setTitle(R.string.delete_channel).
|
||||
setMessage(R.string.confirm_delete_channel)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
deleteCurrentClaim();
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
// show confirmation?
|
||||
// delete claim task and redirect
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -147,8 +131,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
if (claim != null) {
|
||||
try {
|
||||
String shareUrl = LbryUri.parse(
|
||||
!Helper.isNullOrEmpty(claim.getCanonicalUrl()) ? claim.getCanonicalUrl() :
|
||||
(!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl())).toTvString();
|
||||
!Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl()).toTvString();
|
||||
Intent shareIntent = new Intent();
|
||||
shareIntent.setAction(Intent.ACTION_SEND);
|
||||
shareIntent.setType("text/plain");
|
||||
@@ -242,33 +225,6 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
return root;
|
||||
}
|
||||
|
||||
private void deleteCurrentClaim() {
|
||||
if (claim != null) {
|
||||
Helper.setViewVisibility(layoutDisplayArea, View.GONE);
|
||||
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
|
||||
AbandonChannelTask task = new AbandonChannelTask(Arrays.asList(claim.getClaimId()), layoutResolving, new AbandonHandler() {
|
||||
@Override
|
||||
public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
if (failedClaimIds.size() == 0) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.showMessage(R.string.channel_deleted);
|
||||
activity.onBackPressed();
|
||||
} else {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
Snackbar.make(root, R.string.channel_failed_delete, Toast.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkIsFollowing() {
|
||||
if (claim != null) {
|
||||
boolean isFollowing = Lbryio.isFollowing(claim);
|
||||
@@ -329,53 +285,36 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
updateRequired = true;
|
||||
}
|
||||
}
|
||||
if (params.containsKey("url")) {
|
||||
if (!updateRequired && params.containsKey("url")) {
|
||||
String newUrl = params.get("url").toString();
|
||||
if (claim == null || !newUrl.equalsIgnoreCase(url)) {
|
||||
if (!newUrl.equalsIgnoreCase(url) || claim == null) {
|
||||
this.claim = null;
|
||||
this.url = newUrl;
|
||||
updateRequired = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (updateRequired) {
|
||||
resetSubCount();
|
||||
if (!Helper.isNullOrEmpty(url)) {
|
||||
// check if the claim is already cached
|
||||
ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setUrl(url);
|
||||
if (Lbry.claimCache.containsKey(key)) {
|
||||
claim = Lbry.claimCache.get(key);
|
||||
} else {
|
||||
resolveUrl();
|
||||
}
|
||||
resolveUrl();
|
||||
} else if (claim == null) {
|
||||
// nothing at this location
|
||||
renderNothingAtLocation();
|
||||
}
|
||||
}
|
||||
|
||||
if (!Helper.isNullOrEmpty(url)) {
|
||||
Helper.saveUrlHistory(url, claim != null ? claim.getTitle() : null, UrlSuggestion.TYPE_CHANNEL);
|
||||
}
|
||||
|
||||
if (claim != null) {
|
||||
renderClaim();
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveUrl() {
|
||||
Helper.setViewVisibility(layoutDisplayArea, View.INVISIBLE);
|
||||
Helper.setViewVisibility(layoutLoadingState, View.VISIBLE);
|
||||
layoutDisplayArea.setVisibility(View.INVISIBLE);
|
||||
ResolveTask task = new ResolveTask(url, Lbry.LBRY_TV_CONNECTION_STRING, layoutResolving, new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
if (claims.size() > 0 && !Helper.isNullOrEmpty(claims.get(0).getClaimId())) {
|
||||
claim = claims.get(0);
|
||||
if (!Helper.isNullOrEmpty(url)) {
|
||||
Helper.saveUrlHistory(url, claim.getTitle(), UrlSuggestion.TYPE_CHANNEL);
|
||||
}
|
||||
|
||||
renderClaim();
|
||||
checkOwnChannel();
|
||||
} else {
|
||||
@@ -419,12 +358,11 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
String coverUrl = claim.getCoverUrl();
|
||||
textTitle.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle());
|
||||
|
||||
Context context = getContext();
|
||||
if (context != null && !Helper.isNullOrEmpty(coverUrl)) {
|
||||
Glide.with(context.getApplicationContext()).load(coverUrl).centerCrop().into(imageCover);
|
||||
if (!Helper.isNullOrEmpty(coverUrl)) {
|
||||
Glide.with(getContext().getApplicationContext()).load(coverUrl).centerCrop().into(imageCover);
|
||||
}
|
||||
if (context != null && !Helper.isNullOrEmpty(thumbnailUrl)) {
|
||||
Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(imageThumbnail);
|
||||
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
|
||||
Glide.with(getContext().getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(imageThumbnail);
|
||||
noThumbnailView.setVisibility(View.GONE);
|
||||
} else {
|
||||
imageThumbnail.setVisibility(View.GONE);
|
||||
@@ -438,8 +376,8 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
}
|
||||
|
||||
try {
|
||||
if (tabPager.getAdapter() == null && context instanceof MainActivity) {
|
||||
tabPager.setAdapter(new ChannelPagerAdapter(claim, (MainActivity) context));
|
||||
if (tabPager.getAdapter() == null) {
|
||||
tabPager.setAdapter(new ChannelPagerAdapter(claim, (MainActivity) getContext()));
|
||||
}
|
||||
} catch (IllegalStateException ex) {
|
||||
// TODO: Fix why this is happening
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.lbry.browser.ui.channel;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -20,7 +19,6 @@ import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
@@ -34,8 +32,6 @@ import io.lbry.browser.listener.SdkStatusListener;
|
||||
import io.lbry.browser.listener.SelectionModeListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.NavMenuItem;
|
||||
import io.lbry.browser.tasks.claim.AbandonChannelTask;
|
||||
import io.lbry.browser.tasks.claim.AbandonHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
@@ -148,7 +144,7 @@ public class ChannelManagerFragment extends BaseFragment implements ActionMode.C
|
||||
ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, getLoading(), new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(claims));
|
||||
Lbry.ownChannels = new ArrayList<>(claims);
|
||||
Context context = getContext();
|
||||
if (adapter == null) {
|
||||
adapter = new ClaimListAdapter(claims, context);
|
||||
@@ -264,7 +260,7 @@ public class ChannelManagerFragment extends BaseFragment implements ActionMode.C
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
handleDeleteSelectedClaims(selectedClaims);
|
||||
//handleDeleteSelectedClaims(selectedClaims);
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
@@ -274,48 +270,4 @@ public class ChannelManagerFragment extends BaseFragment implements ActionMode.C
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleDeleteSelectedClaims(List<Claim> selectedClaims) {
|
||||
List<String> claimIds = new ArrayList<>();
|
||||
|
||||
for (Claim claim : selectedClaims) {
|
||||
claimIds.add(claim.getClaimId());
|
||||
}
|
||||
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(channelList, View.INVISIBLE);
|
||||
Helper.setViewVisibility(fabNewChannel, View.INVISIBLE);
|
||||
AbandonChannelTask task = new AbandonChannelTask(claimIds, bigLoading, new AbandonHandler() {
|
||||
@Override
|
||||
public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
if (failedClaimIds.size() > 0) {
|
||||
Snackbar.make(root, R.string.one_or_more_channels_failed_abandon, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
} else if (successfulClaimIds.size() == claimIds.size()) {
|
||||
try {
|
||||
String message = getResources().getQuantityString(R.plurals.channels_deleted, successfulClaimIds.size());
|
||||
Snackbar.make(root, message, Snackbar.LENGTH_LONG).show();
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lbry.abandonedClaimIds.addAll(successfulClaimIds);
|
||||
if (adapter != null) {
|
||||
adapter.setItems(Helper.filterDeletedClaims(adapter.getItems()));
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(channelList, View.VISIBLE);
|
||||
Helper.setViewVisibility(fabNewChannel, View.VISIBLE);
|
||||
checkNoChannels();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
+9
-7
@@ -1,6 +1,7 @@
|
||||
package io.lbry.browser.ui.findcontent;
|
||||
package io.lbry.browser.ui.editorschoice;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -21,12 +22,12 @@ import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.FileViewActivity;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.EditorsChoiceItemAdapter;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.EditorsChoiceItem;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
@@ -105,7 +106,7 @@ public class EditorsChoiceFragment extends BaseFragment {
|
||||
}
|
||||
|
||||
contentLoading = true;
|
||||
ClaimSearchTask task = new ClaimSearchTask(buildContentOptions(), Lbry.LBRY_TV_CONNECTION_STRING, loading, new ClaimSearchResultHandler() {
|
||||
ClaimSearchTask task = new ClaimSearchTask(buildContentOptions(), Lbry.LBRY_TV_CONNECTION_STRING, loading, new ClaimSearchTask.ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> items, boolean hasReachedEnd) {
|
||||
List<EditorsChoiceItem> data = buildDataFromClaims(items);
|
||||
@@ -115,10 +116,11 @@ public class EditorsChoiceFragment extends BaseFragment {
|
||||
@Override
|
||||
public void onEditorsChoiceItemClicked(EditorsChoiceItem item) {
|
||||
String url = item.getPermanentUrl();
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openFileUrl(url);
|
||||
}
|
||||
|
||||
Intent intent = new Intent(getContext(), FileViewActivity.class);
|
||||
intent.putExtra("url", url);
|
||||
MainActivity.startingFileViewActivity = true;
|
||||
startActivity(intent);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
File diff suppressed because it is too large.
Load diff
+39
-75
@@ -1,6 +1,7 @@
|
||||
package io.lbry.browser.ui.findcontent;
|
||||
package io.lbry.browser.ui.following;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -19,14 +20,12 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.FileViewActivity;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ChannelFilterListAdapter;
|
||||
@@ -36,11 +35,8 @@ import io.lbry.browser.dialog.ContentFromDialogFragment;
|
||||
import io.lbry.browser.dialog.ContentSortDialogFragment;
|
||||
import io.lbry.browser.dialog.DiscoverDialogFragment;
|
||||
import io.lbry.browser.exceptions.LbryUriException;
|
||||
import io.lbry.browser.listener.DownloadActionListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.model.lbryinc.Subscription;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.lbryinc.ChannelSubscribeTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchTask;
|
||||
@@ -57,9 +53,7 @@ import io.lbry.browser.utils.Predefined;
|
||||
|
||||
public class FollowingFragment extends BaseFragment implements
|
||||
FetchSubscriptionsTask.FetchSubscriptionsHandler,
|
||||
ChannelItemSelectionListener,
|
||||
DownloadActionListener,
|
||||
SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
ChannelItemSelectionListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
public static boolean resetClaimSearchContent;
|
||||
private static final int SUGGESTED_PAGE_SIZE = 45;
|
||||
@@ -89,7 +83,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
private boolean contentClaimSearchLoading = false;
|
||||
private boolean suggestedClaimSearchLoading = false;
|
||||
private View noContentView;
|
||||
private boolean subscriptionsShown;
|
||||
|
||||
private List<Integer> queuedContentPages = new ArrayList<>();
|
||||
private List<Integer> queuedSuggestedPages = new ArrayList<>();
|
||||
@@ -249,8 +242,8 @@ public class FollowingFragment extends BaseFragment implements
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
buildChannelIdsAndUrls();
|
||||
currentSuggestedPage = 1;
|
||||
discoverDialog = DiscoverDialogFragment.newInstance();
|
||||
excludeChannelIdsForDiscover = channelIds != null ? new ArrayList<>(channelIds) : null;
|
||||
discoverDialog.setAdapter(suggestedChannelAdapter);
|
||||
discoverDialog.setDialogActionsListener(new DiscoverDialogFragment.DiscoverDialogListener() {
|
||||
@Override
|
||||
@@ -265,9 +258,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
public void onCancel() {
|
||||
discoverDialog = null;
|
||||
excludeChannelIdsForDiscover = null;
|
||||
if (suggestedChannelAdapter != null) {
|
||||
suggestedChannelAdapter.clearItems();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
@@ -344,7 +334,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Subscriptions", "Subscriptions");
|
||||
activity.addDownloadActionListener(this);
|
||||
}
|
||||
|
||||
// check if subscriptions exist
|
||||
@@ -356,20 +345,16 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
if (Lbryio.subscriptions != null && Lbryio.subscriptions.size() > 0) {
|
||||
fetchLoadedSubscriptions(true);
|
||||
fetchLoadedSubscriptions();
|
||||
} else {
|
||||
fetchSubscriptions();
|
||||
}
|
||||
}
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).removeDownloadActionListener(this);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
public void fetchLoadedSubscriptions(boolean showSubscribed) {
|
||||
public void fetchLoadedSubscriptions() {
|
||||
subscriptionsList = new ArrayList<>(Lbryio.subscriptions);
|
||||
buildChannelIdsAndUrls();
|
||||
if (Lbryio.cacheResolvedSubscriptions.size() > 0) {
|
||||
@@ -380,9 +365,7 @@ public class FollowingFragment extends BaseFragment implements
|
||||
|
||||
fetchClaimSearchContent(resetClaimSearchContent);
|
||||
resetClaimSearchContent = false;
|
||||
if (showSubscribed && subscriptionsList.size() > 0) {
|
||||
showSubscribedContent();
|
||||
}
|
||||
showSubscribedContent();
|
||||
}
|
||||
|
||||
public void loadFollowing() {
|
||||
@@ -396,12 +379,8 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private Map<String, Object> buildSuggestedOptions() {
|
||||
Context context = getContext();
|
||||
boolean canShowMatureContent = false;
|
||||
if (context != null) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
}
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
|
||||
return Lbry.buildClaimSearchOptions(
|
||||
Claim.TYPE_CHANNEL,
|
||||
@@ -467,7 +446,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private void showSubscribedContent() {
|
||||
subscriptionsShown = true;
|
||||
Helper.setViewText(titleView, R.string.channels_you_follow);
|
||||
|
||||
Helper.setViewVisibility(horizontalChannelList, View.VISIBLE);
|
||||
@@ -494,8 +472,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
excludeChannelIdsForDiscover = channelIds != null ? new ArrayList<>(channelIds) : null;
|
||||
}
|
||||
|
||||
private void fetchAndResolveChannelList() {
|
||||
@@ -583,7 +559,7 @@ public class FollowingFragment extends BaseFragment implements
|
||||
contentClaimSearchLoading = true;
|
||||
Helper.setViewVisibility(noContentView, View.GONE);
|
||||
Map<String, Object> claimSearchOptions = buildContentOptions();
|
||||
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.LBRY_TV_CONNECTION_STRING, getLoadingView(), new ClaimSearchResultHandler() {
|
||||
contentClaimSearchTask = new ClaimSearchTask(claimSearchOptions, Lbry.LBRY_TV_CONNECTION_STRING, getLoadingView(), new ClaimSearchTask.ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
if (contentListAdapter == null) {
|
||||
@@ -591,15 +567,21 @@ public class FollowingFragment extends BaseFragment implements
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (claim.getName().startsWith("@")) {
|
||||
// channel claim
|
||||
activity.openChannelClaim(claim);
|
||||
} else {
|
||||
activity.openFileClaim(claim);
|
||||
String claimId = claim.getClaimId();
|
||||
String url = !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl();
|
||||
|
||||
if (claim.getName().startsWith("@")) {
|
||||
// channel claim
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openChannelClaim(claim);
|
||||
}
|
||||
} else {
|
||||
Intent intent = new Intent(getContext(), FileViewActivity.class);
|
||||
intent.putExtra("claimId", claimId);
|
||||
intent.putExtra("url", url);
|
||||
MainActivity.startingFileViewActivity = true;
|
||||
startActivity(intent);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -649,7 +631,7 @@ public class FollowingFragment extends BaseFragment implements
|
||||
buildSuggestedOptions(),
|
||||
Lbry.LBRY_TV_CONNECTION_STRING,
|
||||
suggestedChannelAdapter == null || suggestedChannelAdapter.getItemCount() == 0 ? bigContentLoading : contentLoading,
|
||||
new ClaimSearchResultHandler() {
|
||||
new ClaimSearchTask.ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
suggestedHasReachedEnd = hasReachedEnd;
|
||||
@@ -723,11 +705,12 @@ public class FollowingFragment extends BaseFragment implements
|
||||
ChannelSubscribeTask task = new ChannelSubscribeTask(getContext(), channelClaimId, subscription, false, new ChannelSubscribeTask.ChannelSubscribeHandler() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Lbryio.addSubscription(subscription);
|
||||
Lbryio.addCachedResolvedSubscription(claim);
|
||||
resetClaimSearchContent = true;
|
||||
fetchLoadedSubscriptions(subscriptionsShown);
|
||||
|
||||
if (discoverDialog != null) {
|
||||
Lbryio.addSubscription(subscription);
|
||||
Lbryio.addCachedResolvedSubscription(claim);
|
||||
resetClaimSearchContent = true;
|
||||
fetchLoadedSubscriptions();
|
||||
}
|
||||
saveSharedUserState();
|
||||
}
|
||||
|
||||
@@ -744,11 +727,12 @@ public class FollowingFragment extends BaseFragment implements
|
||||
ChannelSubscribeTask task = new ChannelSubscribeTask(getContext(), channelClaimId, subscription, true, new ChannelSubscribeTask.ChannelSubscribeHandler() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
Lbryio.removeSubscription(subscription);
|
||||
Lbryio.removeCachedResolvedSubscription(claim);
|
||||
resetClaimSearchContent = true;
|
||||
fetchLoadedSubscriptions(subscriptionsShown);
|
||||
|
||||
if (discoverDialog != null) {
|
||||
Lbryio.removeSubscription(subscription);
|
||||
Lbryio.removeCachedResolvedSubscription(claim);
|
||||
resetClaimSearchContent = true;
|
||||
fetchLoadedSubscriptions();
|
||||
}
|
||||
saveSharedUserState();
|
||||
}
|
||||
|
||||
@@ -782,24 +766,4 @@ public class FollowingFragment extends BaseFragment implements
|
||||
fetchClaimSearchContent(true);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
|
||||
if ("abort".equals(downloadAction)) {
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.clearFileForClaimOrUrl(outpoint, uri);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject fileInfo = new JSONObject(fileInfoJson);
|
||||
LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
|
||||
String claimId = claimFile.getClaimId();
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri);
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
// invalid file info for download
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,741 +0,0 @@
|
||||
package io.lbry.browser.ui.library;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Typeface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.view.ActionMode;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ClaimListAdapter;
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.listener.DownloadActionListener;
|
||||
import io.lbry.browser.listener.SdkStatusListener;
|
||||
import io.lbry.browser.listener.SelectionModeListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.model.ViewHistory;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.PurchaseListTask;
|
||||
import io.lbry.browser.tasks.claim.ResolveTask;
|
||||
import io.lbry.browser.tasks.file.BulkDeleteFilesTask;
|
||||
import io.lbry.browser.tasks.file.FileListTask;
|
||||
import io.lbry.browser.tasks.localdata.FetchViewHistoryTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
|
||||
public class LibraryFragment extends BaseFragment implements
|
||||
ActionMode.Callback, DownloadActionListener, SelectionModeListener, SdkStatusListener {
|
||||
|
||||
private static final int FILTER_DOWNLOADS = 1;
|
||||
private static final int FILTER_PURCHASES = 2;
|
||||
private static final int FILTER_HISTORY = 3;
|
||||
private static final int PAGE_SIZE = 50;
|
||||
|
||||
private ActionMode actionMode;
|
||||
private int currentFilter;
|
||||
private List<LbryFile> currentFiles;
|
||||
private View layoutSdkInitializing;
|
||||
private RecyclerView contentList;
|
||||
private ClaimListAdapter contentListAdapter;
|
||||
private ProgressBar listLoading;
|
||||
private TextView linkFilterDownloads;
|
||||
private TextView linkFilterPurchases;
|
||||
private TextView linkFilterHistory;
|
||||
private View layoutListEmpty;
|
||||
private TextView textListEmpty;
|
||||
private int currentPage;
|
||||
private Date lastDate;
|
||||
private boolean listReachedEnd;
|
||||
private boolean contentListLoading;
|
||||
private boolean initialOwnClaimsFetched;
|
||||
|
||||
private CardView cardStats;
|
||||
private TextView linkStats;
|
||||
private TextView linkHide;
|
||||
private View viewStatsDistribution;
|
||||
private View viewVideoStatsBar;
|
||||
private View viewAudioStatsBar;
|
||||
private View viewImageStatsBar;
|
||||
private View viewOtherStatsBar;
|
||||
private TextView textStatsTotalSize;
|
||||
private TextView textStatsTotalSizeUnits;
|
||||
private TextView textStatsVideoSize;
|
||||
private TextView textStatsAudioSize;
|
||||
private TextView textStatsImageSize;
|
||||
private TextView textStatsOtherSize;
|
||||
private View legendVideo;
|
||||
private View legendAudio;
|
||||
private View legendImage;
|
||||
private View legendOther;
|
||||
|
||||
private long totalBytes;
|
||||
private long totalVideoBytes;
|
||||
private long totalAudioBytes;
|
||||
private long totalImageBytes;
|
||||
private long totalOtherBytes;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_library, container, false);
|
||||
|
||||
layoutSdkInitializing = root.findViewById(R.id.container_library_sdk_initializing);
|
||||
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||
contentList = root.findViewById(R.id.library_list);
|
||||
contentList.setLayoutManager(llm);
|
||||
|
||||
listLoading = root.findViewById(R.id.library_list_loading);
|
||||
linkFilterDownloads = root.findViewById(R.id.library_filter_link_downloads);
|
||||
linkFilterPurchases = root.findViewById(R.id.library_filter_link_purchases);
|
||||
linkFilterHistory = root.findViewById(R.id.library_filter_link_history);
|
||||
|
||||
layoutListEmpty = root.findViewById(R.id.library_empty_container);
|
||||
textListEmpty = root.findViewById(R.id.library_list_empty_text);
|
||||
|
||||
currentFilter = FILTER_DOWNLOADS;
|
||||
linkFilterDownloads.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showDownloads();
|
||||
}
|
||||
});
|
||||
linkFilterPurchases.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showPurchases();
|
||||
}
|
||||
});
|
||||
linkFilterHistory.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showHistory();
|
||||
}
|
||||
});
|
||||
contentList.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
public void onScrolled(@NonNull RecyclerView recyclerView, int dx, int dy) {
|
||||
if (contentListLoading) {
|
||||
return;
|
||||
}
|
||||
|
||||
LinearLayoutManager lm = (LinearLayoutManager) recyclerView.getLayoutManager();
|
||||
if (lm != null) {
|
||||
int visibleItemCount = lm.getChildCount();
|
||||
int totalItemCount = lm.getItemCount();
|
||||
int pastVisibleItems = lm.findFirstVisibleItemPosition();
|
||||
if (pastVisibleItems + visibleItemCount >= totalItemCount) {
|
||||
if (!listReachedEnd) {
|
||||
// load more
|
||||
if (currentFilter == FILTER_DOWNLOADS) {
|
||||
currentPage++;
|
||||
fetchDownloads();
|
||||
} else if (currentFilter == FILTER_HISTORY) {
|
||||
fetchHistory();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// stats
|
||||
linkStats = root.findViewById(R.id.library_show_stats);
|
||||
linkHide = root.findViewById(R.id.library_hide_stats);
|
||||
cardStats = root.findViewById(R.id.library_storage_stats_card);
|
||||
viewStatsDistribution = root.findViewById(R.id.library_storage_stat_distribution);
|
||||
viewVideoStatsBar = root.findViewById(R.id.library_storage_stat_video_bar);
|
||||
viewAudioStatsBar = root.findViewById(R.id.library_storage_stat_audio_bar);
|
||||
viewImageStatsBar = root.findViewById(R.id.library_storage_stat_image_bar);
|
||||
viewOtherStatsBar = root.findViewById(R.id.library_storage_stat_other_bar);
|
||||
textStatsTotalSize = root.findViewById(R.id.library_storage_stat_used);
|
||||
textStatsTotalSizeUnits = root.findViewById(R.id.library_storage_stat_unit);
|
||||
textStatsVideoSize = root.findViewById(R.id.library_storage_stat_video_size);
|
||||
textStatsAudioSize = root.findViewById(R.id.library_storage_stat_audio_size);
|
||||
textStatsImageSize = root.findViewById(R.id.library_storage_stat_image_size);
|
||||
textStatsOtherSize = root.findViewById(R.id.library_storage_stat_other_size);
|
||||
legendVideo = root.findViewById(R.id.library_storage_legend_video);
|
||||
legendAudio = root.findViewById(R.id.library_storage_legend_audio);
|
||||
legendImage = root.findViewById(R.id.library_storage_legend_image);
|
||||
legendOther = root.findViewById(R.id.library_storage_legend_other);
|
||||
|
||||
linkStats.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
updateStats();
|
||||
cardStats.setVisibility(View.VISIBLE);
|
||||
checkStatsLink();
|
||||
}
|
||||
});
|
||||
linkHide.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
cardStats.setVisibility(View.GONE);
|
||||
checkStatsLink();
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Library", "Library");
|
||||
activity.addDownloadActionListener(this);
|
||||
}
|
||||
|
||||
layoutSdkInitializing.setVisibility(
|
||||
!Lbry.SDK_READY && currentFilter == FILTER_DOWNLOADS ? View.VISIBLE : View.GONE);
|
||||
if (!Lbry.SDK_READY) {
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.addSdkStatusListener(this);
|
||||
}
|
||||
} else {
|
||||
onSdkReady();
|
||||
}
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.removeSdkStatusListener(this);
|
||||
activity.removeDownloadActionListener(this);
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
public void onSdkReady() {
|
||||
layoutSdkInitializing.setVisibility(View.GONE);
|
||||
if (currentFilter == FILTER_DOWNLOADS) {
|
||||
showDownloads();
|
||||
} else if (currentFilter == FILTER_HISTORY) {
|
||||
showHistory();
|
||||
} else if (currentFilter == FILTER_PURCHASES) {
|
||||
showPurchases();
|
||||
}
|
||||
}
|
||||
|
||||
private void showDownloads() {
|
||||
currentFilter = FILTER_DOWNLOADS;
|
||||
linkFilterDownloads.setTypeface(null, Typeface.BOLD);
|
||||
linkFilterPurchases.setTypeface(null, Typeface.NORMAL);
|
||||
linkFilterHistory.setTypeface(null, Typeface.NORMAL);
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.setHideFee(false);
|
||||
contentListAdapter.clearItems();
|
||||
contentListAdapter.setCanEnterSelectionMode(true);
|
||||
}
|
||||
listReachedEnd = false;
|
||||
|
||||
checkStatsLink();
|
||||
layoutSdkInitializing.setVisibility(Lbry.SDK_READY ? View.GONE : View.VISIBLE);
|
||||
currentPage = 1;
|
||||
if (Lbry.SDK_READY) {
|
||||
if (!initialOwnClaimsFetched) {
|
||||
fetchOwnClaimsAndShowDownloads();
|
||||
} else {
|
||||
fetchDownloads();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchOwnClaimsAndShowDownloads() {
|
||||
if (Lbry.ownClaims != null && Lbry.ownClaims.size() > 0) {
|
||||
initialOwnClaimsFetched = true;
|
||||
fetchDownloads();
|
||||
return;
|
||||
}
|
||||
|
||||
linkStats.setVisibility(View.INVISIBLE);
|
||||
ClaimListTask task = new ClaimListTask(Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST), listLoading, new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims));
|
||||
initialOwnClaimsFetched = true;
|
||||
if (currentFilter == FILTER_DOWNLOADS) {
|
||||
fetchDownloads();
|
||||
}
|
||||
checkStatsLink();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
initialOwnClaimsFetched = true;
|
||||
checkStatsLink();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void showPurchases() {
|
||||
currentFilter = FILTER_PURCHASES;
|
||||
linkFilterDownloads.setTypeface(null, Typeface.NORMAL);
|
||||
linkFilterPurchases.setTypeface(null, Typeface.BOLD);
|
||||
linkFilterHistory.setTypeface(null, Typeface.NORMAL);
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.setHideFee(true);
|
||||
contentListAdapter.clearItems();
|
||||
contentListAdapter.setCanEnterSelectionMode(true);
|
||||
}
|
||||
listReachedEnd = false;
|
||||
|
||||
cardStats.setVisibility(View.GONE);
|
||||
checkStatsLink();
|
||||
|
||||
layoutSdkInitializing.setVisibility(Lbry.SDK_READY ? View.GONE : View.VISIBLE);
|
||||
currentPage = 1;
|
||||
if (Lbry.SDK_READY) {
|
||||
fetchPurchases();
|
||||
}
|
||||
}
|
||||
|
||||
private void showHistory() {
|
||||
currentFilter = FILTER_HISTORY;
|
||||
linkFilterDownloads.setTypeface(null, Typeface.NORMAL);
|
||||
linkFilterPurchases.setTypeface(null, Typeface.NORMAL);
|
||||
linkFilterHistory.setTypeface(null, Typeface.BOLD);
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.setHideFee(false);
|
||||
contentListAdapter.clearItems();
|
||||
contentListAdapter.setCanEnterSelectionMode(false);
|
||||
}
|
||||
listReachedEnd = false;
|
||||
|
||||
cardStats.setVisibility(View.GONE);
|
||||
checkStatsLink();
|
||||
|
||||
layoutSdkInitializing.setVisibility(View.GONE);
|
||||
lastDate = null;
|
||||
fetchHistory();
|
||||
}
|
||||
|
||||
private void initContentListAdapter(List<Claim> claims) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
contentListAdapter.setCanEnterSelectionMode(true);
|
||||
contentListAdapter.setSelectionModeListener(this);
|
||||
contentListAdapter.setHideFee(currentFilter != FILTER_PURCHASES);
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) getContext();
|
||||
if (claim.getName().startsWith("@")) {
|
||||
activity.openChannelUrl(claim.getPermanentUrl());
|
||||
} else {
|
||||
activity.openFileUrl(claim.getPermanentUrl());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void fetchDownloads() {
|
||||
contentListLoading = true;
|
||||
Helper.setViewVisibility(linkStats, View.GONE);
|
||||
Helper.setViewVisibility(layoutListEmpty, View.GONE);
|
||||
FileListTask task = new FileListTask(currentPage, PAGE_SIZE, true, listLoading, new FileListTask.FileListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<LbryFile> files, boolean hasReachedEnd) {
|
||||
listReachedEnd = hasReachedEnd;
|
||||
List<LbryFile> filteredFiles = Helper.filterDownloads(files);
|
||||
List<Claim> claims = Helper.claimsFromFiles(filteredFiles);
|
||||
|
||||
addFiles(filteredFiles);
|
||||
updateStats();
|
||||
checkStatsLink();
|
||||
|
||||
if (contentListAdapter == null) {
|
||||
initContentListAdapter(claims);
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
resolveMissingChannelNames(buildUrlsToResolve(claims));
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
// pass
|
||||
checkStatsLink();
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void fetchPurchases() {
|
||||
contentListLoading = true;
|
||||
Helper.setViewVisibility(linkStats, View.GONE);
|
||||
Helper.setViewVisibility(layoutListEmpty, View.GONE);
|
||||
PurchaseListTask task = new PurchaseListTask(currentPage, PAGE_SIZE, listLoading, new ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
listReachedEnd = hasReachedEnd;
|
||||
if (contentListAdapter == null) {
|
||||
initContentListAdapter(claims);
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
checkStatsLink();
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void fetchHistory() {
|
||||
contentListLoading = true;
|
||||
Helper.setViewVisibility(layoutListEmpty, View.GONE);
|
||||
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
|
||||
if (dbHelper != null) {
|
||||
FetchViewHistoryTask task = new FetchViewHistoryTask(lastDate, PAGE_SIZE, dbHelper, new FetchViewHistoryTask.FetchViewHistoryHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<ViewHistory> history, boolean hasReachedEnd) {
|
||||
listReachedEnd = hasReachedEnd;
|
||||
if (history.size() > 0) {
|
||||
lastDate = history.get(history.size() - 1).getTimestamp();
|
||||
}
|
||||
|
||||
List<Claim> claims = Helper.claimsFromViewHistory(history);
|
||||
if (contentListAdapter == null) {
|
||||
initContentListAdapter(claims);
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
} else {
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
}
|
||||
|
||||
public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
|
||||
if ("abort".equals(downloadAction)) {
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.clearFileForClaimOrUrl(outpoint, uri, currentFilter == FILTER_DOWNLOADS);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject fileInfo = new JSONObject(fileInfoJson);
|
||||
LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
|
||||
String claimId = claimFile.getClaimId();
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri, true);
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
// invalid file info for download
|
||||
}
|
||||
}
|
||||
|
||||
private void checkListEmpty() {
|
||||
layoutListEmpty.setVisibility(contentListAdapter == null || contentListAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
int stringResourceId;
|
||||
switch (currentFilter) {
|
||||
case FILTER_DOWNLOADS: default: stringResourceId = R.string.library_no_downloads; break;
|
||||
case FILTER_HISTORY: stringResourceId = R.string.library_no_history; break;
|
||||
case FILTER_PURCHASES: stringResourceId = R.string.library_no_purchases; break;
|
||||
}
|
||||
textListEmpty.setText(stringResourceId);
|
||||
}
|
||||
|
||||
private void addFiles(List<LbryFile> files) {
|
||||
if (currentFiles == null) {
|
||||
currentFiles = new ArrayList<>();
|
||||
}
|
||||
for (LbryFile file : files) {
|
||||
if (!currentFiles.contains(file)) {
|
||||
currentFiles.add(file);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateStats() {
|
||||
totalBytes = 0;
|
||||
totalVideoBytes = 0;
|
||||
totalAudioBytes = 0;
|
||||
totalImageBytes = 0;
|
||||
totalOtherBytes = 0;
|
||||
if (currentFiles != null) {
|
||||
for (LbryFile file : currentFiles) {
|
||||
long writtenBytes = file.getWrittenBytes();
|
||||
String mime = file.getMimeType();
|
||||
if (mime != null) {
|
||||
if (mime.startsWith("video/")) {
|
||||
totalVideoBytes += writtenBytes;
|
||||
} else if (mime.startsWith("audio/")) {
|
||||
totalAudioBytes += writtenBytes;
|
||||
} else if (mime.startsWith("image/")) {
|
||||
totalImageBytes += writtenBytes;
|
||||
} else {
|
||||
totalOtherBytes += writtenBytes;
|
||||
}
|
||||
}
|
||||
|
||||
totalBytes += writtenBytes;
|
||||
}
|
||||
}
|
||||
|
||||
renderStats();
|
||||
}
|
||||
|
||||
private void renderStats() {
|
||||
String[] totalSizeParts = Helper.formatBytesParts(totalBytes, false);
|
||||
textStatsTotalSize.setText(totalSizeParts[0]);
|
||||
textStatsTotalSizeUnits.setText(totalSizeParts[1]);
|
||||
|
||||
viewStatsDistribution.setVisibility(totalBytes > 0 ? View.VISIBLE : View.GONE);
|
||||
|
||||
int percentVideo = normalizePercent((double) totalVideoBytes / (double) totalBytes * 100.0);
|
||||
legendVideo.setVisibility(totalVideoBytes > 0 ? View.VISIBLE : View.GONE);
|
||||
textStatsVideoSize.setText(Helper.formatBytes(totalVideoBytes, false));
|
||||
applyLayoutWeight(viewVideoStatsBar, percentVideo);
|
||||
|
||||
int percentAudio = normalizePercent((double) totalAudioBytes / (double) totalBytes * 100.0);
|
||||
legendAudio.setVisibility(totalAudioBytes > 0 ? View.VISIBLE : View.GONE);
|
||||
textStatsAudioSize.setText(Helper.formatBytes(totalAudioBytes, false));
|
||||
applyLayoutWeight(viewAudioStatsBar, percentAudio);
|
||||
|
||||
int percentImage = normalizePercent((double) totalImageBytes / (double) totalBytes * 100.0);
|
||||
legendImage.setVisibility(totalImageBytes > 0 ? View.VISIBLE : View.GONE);
|
||||
textStatsImageSize.setText(Helper.formatBytes(totalImageBytes, false));
|
||||
applyLayoutWeight(viewImageStatsBar, percentImage);
|
||||
|
||||
int percentOther = normalizePercent((double) totalOtherBytes / (double) totalBytes * 100.0);
|
||||
legendOther.setVisibility(totalOtherBytes > 0 ? View.VISIBLE : View.GONE);
|
||||
textStatsOtherSize.setText(Helper.formatBytes(totalOtherBytes, false));
|
||||
applyLayoutWeight(viewOtherStatsBar, percentOther);
|
||||
|
||||
// We have to get to 100 (or adjust the container accordingly)
|
||||
int totalPercent = percentVideo + percentAudio + percentImage + percentOther;
|
||||
((LinearLayout) viewStatsDistribution).setWeightSum(totalPercent);
|
||||
}
|
||||
|
||||
private void applyLayoutWeight(View view, int weight) {
|
||||
LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) view.getLayoutParams();
|
||||
params.weight = weight;
|
||||
}
|
||||
|
||||
private static int normalizePercent(double value) {
|
||||
if (value > 0 && value < 1) {
|
||||
return 1;
|
||||
}
|
||||
return Double.valueOf(Math.floor(value)).intValue();
|
||||
}
|
||||
|
||||
private void checkStatsLink() {
|
||||
linkStats.setVisibility(cardStats.getVisibility() == View.VISIBLE ||
|
||||
listLoading.getVisibility() == View.VISIBLE ||
|
||||
currentFilter != FILTER_DOWNLOADS ||
|
||||
!Lbry.SDK_READY ?
|
||||
View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
|
||||
this.actionMode = actionMode;
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (!activity.isDarkMode()) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
actionMode.getMenuInflater().inflate(R.menu.menu_claim_list, menu);
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode actionMode) {
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.clearSelectedItems();
|
||||
contentListAdapter.setInSelectionMode(false);
|
||||
contentListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (!activity.isDarkMode()) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
}
|
||||
this.actionMode = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPrepareActionMode(androidx.appcompat.view.ActionMode actionMode, Menu menu) {
|
||||
menu.findItem(R.id.action_edit).setVisible(false);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
|
||||
if (R.id.action_delete == menuItem.getItemId()) {
|
||||
if (contentListAdapter != null && contentListAdapter.getSelectedCount() > 0) {
|
||||
final List<Claim> selectedClaims = new ArrayList<>(contentListAdapter.getSelectedItems());
|
||||
String message = getResources().getQuantityString(R.plurals.confirm_delete_files, selectedClaims.size());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
|
||||
setTitle(R.string.delete_selection).
|
||||
setMessage(message)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
handleDeleteSelectedClaims(selectedClaims);
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleDeleteSelectedClaims(List<Claim> selectedClaims) {
|
||||
List<String> claimIds = new ArrayList<>();
|
||||
for (Claim claim : selectedClaims) {
|
||||
claimIds.add(claim.getClaimId());
|
||||
}
|
||||
|
||||
new BulkDeleteFilesTask(claimIds).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
Lbry.unsetFilesForCachedClaims(claimIds);
|
||||
if (currentFilter == FILTER_DOWNLOADS) {
|
||||
contentListAdapter.removeItems(selectedClaims);
|
||||
}
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
String message = getResources().getQuantityString(R.plurals.files_deleted, claimIds.size());
|
||||
Snackbar.make(root, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> buildUrlsToResolve(List<Claim> claims) {
|
||||
List<String> urls = new ArrayList<>();
|
||||
for (Claim claim : claims) {
|
||||
Claim channel = claim.getSigningChannel();
|
||||
if (channel != null && Helper.isNullOrEmpty(channel.getName()) && !Helper.isNullOrEmpty(channel.getClaimId())) {
|
||||
LbryUri uri = LbryUri.tryParse(String.format("%s#%s", claim.getName(), claim.getClaimId()));
|
||||
if (uri != null) {
|
||||
urls.add(uri.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
private void resolveMissingChannelNames(List<String> urls) {
|
||||
if (urls.size() > 0) {
|
||||
ResolveTask task = new ResolveTask(urls, Lbry.SDK_CONNECTION_STRING, null, new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
boolean updated = false;
|
||||
for (Claim claim : claims) {
|
||||
if (claim.getClaimId() == null) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (contentListAdapter != null) {
|
||||
contentListAdapter.updateSigningChannelForClaim(claim);
|
||||
updated = true;
|
||||
}
|
||||
}
|
||||
if (updated) {
|
||||
contentListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
||||
public void onEnterSelectionMode() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.startSupportActionMode(this);
|
||||
}
|
||||
}
|
||||
public void onItemSelectionToggled() {
|
||||
if (actionMode != null) {
|
||||
actionMode.setTitle(String.valueOf(contentListAdapter.getSelectedCount()));
|
||||
actionMode.invalidate();
|
||||
}
|
||||
}
|
||||
public void onExitSelectionMode() {
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -180,7 +180,10 @@ public class AboutFragment extends BaseFragment implements SdkStatusListener {
|
||||
activity.lockDrawer();
|
||||
activity.hideFloatingWalletBalance();
|
||||
|
||||
activity.setActionBarTitle(R.string.about_lbry);
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(R.string.about_lbry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -190,7 +193,7 @@ public class AboutFragment extends BaseFragment implements SdkStatusListener {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "About", "About");
|
||||
LbryAnalytics.setCurrentScreen(activity, "Settings", "Settings");
|
||||
|
||||
if (!Lbry.SDK_READY) {
|
||||
activity.addSdkStatusListener(this);
|
||||
|
||||
@@ -2,7 +2,6 @@ package io.lbry.browser.ui.other;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
@@ -10,14 +9,9 @@ import androidx.appcompat.app.AppCompatDelegate;
|
||||
import androidx.preference.PreferenceFragmentCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.lbrysdk.Utils;
|
||||
|
||||
public class SettingsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
@Override
|
||||
@@ -35,7 +29,10 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
||||
activity.lockDrawer();
|
||||
activity.hideFloatingWalletBalance();
|
||||
|
||||
activity.setActionBarTitle(R.string.settings);
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(R.string.settings);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -43,18 +40,15 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
|
||||
if (context instanceof MainActivity) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).registerOnSharedPreferenceChangeListener(this);
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Settings", "Settings");
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
@Override
|
||||
@@ -72,29 +66,13 @@ public class SettingsFragment extends PreferenceFragmentCompat implements Shared
|
||||
if (key.equalsIgnoreCase(MainActivity.PREFERENCE_KEY_DARK_MODE)) {
|
||||
boolean darkMode = sp.getBoolean(MainActivity.PREFERENCE_KEY_DARK_MODE, false);
|
||||
AppCompatDelegate.setDefaultNightMode(darkMode ? AppCompatDelegate.MODE_NIGHT_YES : AppCompatDelegate.MODE_NIGHT_NO);
|
||||
} else if (key.equalsIgnoreCase(MainActivity.PREFERENCE_KEY_PARTICIPATE_DATA_NETWORK)) {
|
||||
boolean dhtEnabled = sp.getBoolean(MainActivity.PREFERENCE_KEY_PARTICIPATE_DATA_NETWORK, false);
|
||||
updateDHTFileSetting(dhtEnabled);
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.getDelegate().applyDayNight();
|
||||
activity.recreate();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void updateDHTFileSetting(final boolean enabled) {
|
||||
Context context = getContext();
|
||||
(new AsyncTask<Void, Void, Void>() {
|
||||
protected Void doInBackground(Void... params) {
|
||||
PrintStream out = null;
|
||||
try {
|
||||
String fileContent = enabled ? "on" : "off";
|
||||
String path = String.format("%s/%s", Utils.getAppInternalStorageDir(context), "dht");
|
||||
out = new PrintStream(new FileOutputStream(path));
|
||||
out.print(fileContent);
|
||||
} catch (Exception ex) {
|
||||
// pass
|
||||
} finally {
|
||||
Helper.closeCloseable(out);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,436 +0,0 @@
|
||||
package io.lbry.browser.ui.publish;
|
||||
|
||||
import android.Manifest;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
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;
|
||||
import androidx.camera.core.CameraSelector;
|
||||
import androidx.camera.core.CameraX;
|
||||
import androidx.camera.core.Preview;
|
||||
import androidx.camera.lifecycle.ProcessCameraProvider;
|
||||
import androidx.camera.view.PreviewView;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.lifecycle.LifecycleOwner;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.common.util.concurrent.ListenableFuture;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.GalleryGridAdapter;
|
||||
import io.lbry.browser.listener.CameraPermissionListener;
|
||||
import io.lbry.browser.listener.FilePickerListener;
|
||||
import io.lbry.browser.listener.StoragePermissionListener;
|
||||
import io.lbry.browser.model.GalleryItem;
|
||||
import io.lbry.browser.model.NavMenuItem;
|
||||
import io.lbry.browser.tasks.localdata.LoadGalleryItemsTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
|
||||
public class PublishFragment extends BaseFragment implements
|
||||
CameraPermissionListener, FilePickerListener, StoragePermissionListener {
|
||||
|
||||
private PreviewView cameraPreview;
|
||||
private RecyclerView galleryGrid;
|
||||
private GalleryGridAdapter adapter;
|
||||
private TextView noVideosLoaded;
|
||||
private View loading;
|
||||
|
||||
private View buttonRecord;
|
||||
private View buttonTakePhoto;
|
||||
private View buttonUpload;
|
||||
|
||||
private boolean loadGalleryItemsPending;
|
||||
private boolean launchFilePickerPending;
|
||||
private boolean recordPending;
|
||||
private boolean takePhotoPending;
|
||||
private ListenableFuture<ProcessCameraProvider> cameraProviderFuture;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_publish, container, false);
|
||||
|
||||
noVideosLoaded = root.findViewById(R.id.publish_grid_no_videos);
|
||||
loading = root.findViewById(R.id.publish_grid_loading);
|
||||
cameraPreview = root.findViewById(R.id.publish_camera_preview);
|
||||
|
||||
Context context = getContext();
|
||||
galleryGrid = root.findViewById(R.id.publish_video_grid);
|
||||
GridLayoutManager glm = new GridLayoutManager(context, 3);
|
||||
galleryGrid.setLayoutManager(glm);
|
||||
galleryGrid.addItemDecoration(new GalleryGridAdapter.GalleryGridItemDecoration(
|
||||
3, Helper.getScaledValue(3, context.getResources().getDisplayMetrics().density)));
|
||||
|
||||
buttonRecord = root.findViewById(R.id.publish_record_button);
|
||||
buttonTakePhoto = root.findViewById(R.id.publish_photo_button);
|
||||
buttonUpload = root.findViewById(R.id.publish_upload_button);
|
||||
|
||||
buttonRecord.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkCameraPermissionAndRecord();
|
||||
}
|
||||
});
|
||||
buttonTakePhoto.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkCameraPermissionAndTakePhoto();
|
||||
}
|
||||
});
|
||||
buttonUpload.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
checkStoragePermissionAndLaunchFilePicker();
|
||||
}
|
||||
});
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private boolean cameraAvailable() {
|
||||
Context context = getContext();
|
||||
return context != null && context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA_ANY);
|
||||
}
|
||||
|
||||
private void showCameraPreview() {
|
||||
buttonRecord.setBackgroundColor(Color.TRANSPARENT);
|
||||
buttonTakePhoto.setBackgroundColor(Color.TRANSPARENT);
|
||||
displayPreviewWithCameraX();
|
||||
}
|
||||
|
||||
private void displayPreviewWithCameraX() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
cameraProviderFuture = ProcessCameraProvider.getInstance(context);
|
||||
cameraProviderFuture.addListener(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
|
||||
if (cameraProvider != null) {
|
||||
Preview preview = new Preview.Builder().build();
|
||||
CameraSelector cameraSelector = new CameraSelector.Builder()
|
||||
.requireLensFacing(CameraSelector.LENS_FACING_BACK)
|
||||
.build();
|
||||
|
||||
Camera camera = cameraProvider.bindToLifecycle((LifecycleOwner) context, cameraSelector, preview);
|
||||
preview.setSurfaceProvider(cameraPreview.createSurfaceProvider(camera.getCameraInfo()));
|
||||
}
|
||||
} catch (ExecutionException | InterruptedException ex) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}, ContextCompat.getMainExecutor(context));
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCameraPermissionAndRecord() {
|
||||
if (!Lbry.SDK_READY) {
|
||||
Snackbar.make(getView(), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (!MainActivity.hasPermission(Manifest.permission.CAMERA, context)) {
|
||||
recordPending = true;
|
||||
MainActivity.requestPermission(
|
||||
Manifest.permission.CAMERA,
|
||||
MainActivity.REQUEST_CAMERA_PERMISSION,
|
||||
getString(R.string.camera_permission_rationale_record),
|
||||
context,
|
||||
true);
|
||||
} else {
|
||||
record();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCameraPermissionAndTakePhoto() {
|
||||
if (!Lbry.SDK_READY) {
|
||||
Snackbar.make(getView(), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (!MainActivity.hasPermission(Manifest.permission.CAMERA, context)) {
|
||||
takePhotoPending = true;
|
||||
MainActivity.requestPermission(
|
||||
Manifest.permission.CAMERA,
|
||||
MainActivity.REQUEST_CAMERA_PERMISSION,
|
||||
getString(R.string.camera_permission_rationale_photo),
|
||||
context,
|
||||
true);
|
||||
} else {
|
||||
takePhoto();
|
||||
}
|
||||
}
|
||||
|
||||
private void takePhoto() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
takePhotoPending = false;
|
||||
((MainActivity) context).requestTakePhoto();
|
||||
}
|
||||
}
|
||||
|
||||
private void record() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
recordPending = false;
|
||||
((MainActivity) context).requestVideoCapture();
|
||||
}
|
||||
}
|
||||
|
||||
private void checkStoragePermissionAndLaunchFilePicker() {
|
||||
if (!Lbry.SDK_READY) {
|
||||
Snackbar.make(getView(), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
|
||||
launchFilePickerPending = false;
|
||||
launchFilePicker();
|
||||
} else {
|
||||
launchFilePickerPending = true;
|
||||
MainActivity.requestPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
MainActivity.REQUEST_STORAGE_PERMISSION,
|
||||
getString(R.string.storage_permission_rationale_images),
|
||||
context,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
private void launchFilePicker() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity.startingFilePickerActivity = true;
|
||||
Intent intent = new Intent(Intent.ACTION_OPEN_DOCUMENT);
|
||||
intent.setType("*/*");
|
||||
((MainActivity) context).startActivityForResult(
|
||||
Intent.createChooser(intent, getString(R.string.upload_file)),
|
||||
MainActivity.REQUEST_FILE_PICKER);
|
||||
}
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
Helper.setWunderbarValue(null, context);
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Publish", "Publish");
|
||||
activity.addCameraPermissionListener(this);
|
||||
activity.addFilePickerListener(this);
|
||||
activity.addStoragePermissionListener(this);
|
||||
activity.hideFloatingWalletBalance();
|
||||
|
||||
|
||||
if (cameraAvailable() && MainActivity.hasPermission(Manifest.permission.CAMERA, context)) {
|
||||
showCameraPreview();
|
||||
}
|
||||
}
|
||||
|
||||
checkStoragePermissionAndLoadVideos();
|
||||
}
|
||||
|
||||
@SuppressLint("RestrictedApi")
|
||||
public void onStop() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.removeCameraPermissionListener(this);
|
||||
activity.removeStoragePermissionListener(this);
|
||||
activity.showFloatingWalletBalance();
|
||||
if (!MainActivity.startingFilePickerActivity) {
|
||||
activity.removeFilePickerListener(this);
|
||||
}
|
||||
}
|
||||
CameraX.unbindAll();
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
private void checkStoragePermissionAndLoadVideos() {
|
||||
Context context = getContext();
|
||||
if (MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
|
||||
loadGalleryItems();
|
||||
} else {
|
||||
loadGalleryItemsPending = true;
|
||||
MainActivity.requestPermission(
|
||||
Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
MainActivity.REQUEST_STORAGE_PERMISSION,
|
||||
getString(R.string.storage_permission_rationale_download),
|
||||
context,
|
||||
true);
|
||||
}
|
||||
}
|
||||
|
||||
private void loadGalleryItems() {
|
||||
Context context = getContext();
|
||||
Helper.setViewVisibility(noVideosLoaded, View.GONE);
|
||||
LoadGalleryItemsTask task = new LoadGalleryItemsTask(loading, context, new LoadGalleryItemsTask.LoadGalleryHandler() {
|
||||
@Override
|
||||
public void onItemLoaded(GalleryItem item) {
|
||||
if (context != null) {
|
||||
if (adapter == null) {
|
||||
adapter = new GalleryGridAdapter(Arrays.asList(item), context);
|
||||
adapter.setListener(new GalleryGridAdapter.GalleryItemClickListener() {
|
||||
@Override
|
||||
public void onGalleryItemClicked(GalleryItem item) {
|
||||
if (!Lbry.SDK_READY) {
|
||||
Snackbar.make(getView(), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("galleryItem", item);
|
||||
params.put("suggestedUrl", getSuggestedPublishUrl());
|
||||
((MainActivity) context).openFragment(PublishFormFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
adapter.addItem(item);
|
||||
}
|
||||
|
||||
if (galleryGrid.getAdapter() == null) {
|
||||
galleryGrid.setAdapter(adapter);
|
||||
}
|
||||
Helper.setViewVisibility(loading, adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAllItemsLoaded(List<GalleryItem> items) {
|
||||
if (context != null) {
|
||||
if (adapter == null) {
|
||||
adapter = new GalleryGridAdapter(items, context);
|
||||
} else {
|
||||
adapter.addItems(items);
|
||||
}
|
||||
|
||||
if (galleryGrid.getAdapter() == null) {
|
||||
galleryGrid.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
checkNoVideosLoaded();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public void checkNoVideosLoaded() {
|
||||
Helper.setViewVisibility(noVideosLoaded, adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraPermissionGranted() {
|
||||
if (recordPending) {
|
||||
// record video
|
||||
record();
|
||||
} else if (takePhotoPending) {
|
||||
// take a photo
|
||||
takePhoto();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCameraPermissionRefused() {
|
||||
if (takePhotoPending) {
|
||||
takePhotoPending = false;
|
||||
Snackbar.make(getView(), R.string.camera_permission_rationale_photo, Toast.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
return;
|
||||
}
|
||||
|
||||
recordPending = false;
|
||||
Snackbar.make(getView(), R.string.camera_permission_rationale_record, Toast.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordAudioPermissionGranted() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRecordAudioPermissionRefused() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoragePermissionGranted() {
|
||||
if (loadGalleryItemsPending) {
|
||||
loadGalleryItemsPending = false;
|
||||
loadGalleryItems();
|
||||
}
|
||||
if (launchFilePickerPending) {
|
||||
launchFilePickerPending = false;
|
||||
launchFilePicker();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStoragePermissionRefused() {
|
||||
Snackbar.make(getView(), R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG).setBackgroundTint(
|
||||
ContextCompat.getColor(getContext(), R.color.red)
|
||||
).show();
|
||||
}
|
||||
|
||||
public String getSuggestedPublishUrl() {
|
||||
Map<String, Object> params = getParams();
|
||||
if (params != null && params.containsKey("suggestedUrl")) {
|
||||
return (String) params.get("suggestedUrl");
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldHideGlobalPlayer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldSuspendGlobalPlayer() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilePicked(String filePath) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("directFilePath", filePath);
|
||||
params.put("suggestedUrl", getSuggestedPublishUrl());
|
||||
((MainActivity) context).openFragment(PublishFormFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFilePickerCancelled() {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,320 +0,0 @@
|
||||
package io.lbry.browser.ui.publish;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.view.ActionMode;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.material.floatingactionbutton.FloatingActionButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ClaimListAdapter;
|
||||
import io.lbry.browser.listener.SdkStatusListener;
|
||||
import io.lbry.browser.listener.SelectionModeListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.NavMenuItem;
|
||||
import io.lbry.browser.tasks.claim.AbandonHandler;
|
||||
import io.lbry.browser.tasks.claim.AbandonStreamTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
|
||||
public class PublishesFragment extends BaseFragment implements ActionMode.Callback, SelectionModeListener, SdkStatusListener {
|
||||
|
||||
private Button buttonNewPublish;
|
||||
private FloatingActionButton fabNewPublish;
|
||||
private ActionMode actionMode;
|
||||
private View emptyView;
|
||||
private View layoutSdkInitializing;
|
||||
private ProgressBar loading;
|
||||
private ProgressBar bigLoading;
|
||||
private RecyclerView contentList;
|
||||
private ClaimListAdapter adapter;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_publishes, container, false);
|
||||
|
||||
buttonNewPublish = root.findViewById(R.id.publishes_create_button);
|
||||
fabNewPublish = root.findViewById(R.id.publishes_fab_new_publish);
|
||||
buttonNewPublish.setOnClickListener(newPublishClickListener);
|
||||
fabNewPublish.setOnClickListener(newPublishClickListener);
|
||||
|
||||
emptyView = root.findViewById(R.id.publishes_empty_container);
|
||||
layoutSdkInitializing = root.findViewById(R.id.container_sdk_initializing);
|
||||
contentList = root.findViewById(R.id.publishes_list);
|
||||
LinearLayoutManager llm = new LinearLayoutManager(getContext());
|
||||
contentList.setLayoutManager(llm);
|
||||
loading = root.findViewById(R.id.publishes_list_loading);
|
||||
bigLoading = root.findViewById(R.id.publishes_list_big_loading);
|
||||
|
||||
layoutSdkInitializing.setVisibility(Lbry.SDK_READY ? View.GONE : View.VISIBLE);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
private View.OnClickListener newPublishClickListener = new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openFragment(PublishFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@Override
|
||||
public void onStart() {
|
||||
super.onStart();
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.hideFloatingWalletBalance();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onStop() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.showFloatingWalletBalance();
|
||||
}
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.setWunderbarValue(null);
|
||||
LbryAnalytics.setCurrentScreen(activity, "Publishes", "Publishes");
|
||||
}
|
||||
|
||||
if (!Lbry.SDK_READY) {
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.addSdkStatusListener(this);
|
||||
}
|
||||
} else {
|
||||
onSdkReady();
|
||||
}
|
||||
}
|
||||
|
||||
public void onSdkReady() {
|
||||
Helper.setViewVisibility(layoutSdkInitializing, View.GONE);
|
||||
Helper.setViewVisibility(fabNewPublish, View.VISIBLE);
|
||||
if (adapter != null && contentList != null) {
|
||||
contentList.setAdapter(adapter);
|
||||
}
|
||||
fetchPublishes();
|
||||
}
|
||||
|
||||
public View getLoading() {
|
||||
return (adapter == null || adapter.getItemCount() == 0) ? bigLoading : loading;
|
||||
}
|
||||
|
||||
private void checkNoPublishes() {
|
||||
Helper.setViewVisibility(emptyView, adapter == null || adapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void fetchPublishes() {
|
||||
Helper.setViewVisibility(emptyView, View.GONE);
|
||||
ClaimListTask task = new ClaimListTask(Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST), getLoading(), new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims));
|
||||
Context context = getContext();
|
||||
if (adapter == null) {
|
||||
adapter = new ClaimListAdapter(claims, context);
|
||||
adapter.setCanEnterSelectionMode(true);
|
||||
adapter.setSelectionModeListener(PublishesFragment.this);
|
||||
adapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openFileClaim(claim);
|
||||
}
|
||||
}
|
||||
});
|
||||
if (contentList != null) {
|
||||
contentList.setAdapter(adapter);
|
||||
}
|
||||
} else {
|
||||
adapter.setItems(claims);
|
||||
}
|
||||
|
||||
checkNoPublishes();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
checkNoPublishes();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
public void onEnterSelectionMode() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.startSupportActionMode(this);
|
||||
}
|
||||
}
|
||||
public void onItemSelectionToggled() {
|
||||
if (actionMode != null) {
|
||||
actionMode.setTitle(String.valueOf(adapter.getSelectedCount()));
|
||||
actionMode.invalidate();
|
||||
}
|
||||
}
|
||||
public void onExitSelectionMode() {
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateActionMode(ActionMode actionMode, Menu menu) {
|
||||
this.actionMode = actionMode;
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (!activity.isDarkMode()) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
actionMode.getMenuInflater().inflate(R.menu.menu_claim_list, menu);
|
||||
return true;
|
||||
}
|
||||
@Override
|
||||
public void onDestroyActionMode(ActionMode actionMode) {
|
||||
if (adapter != null) {
|
||||
adapter.clearSelectedItems();
|
||||
adapter.setInSelectionMode(false);
|
||||
adapter.notifyDataSetChanged();
|
||||
}
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (!activity.isDarkMode()) {
|
||||
activity.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LIGHT_STATUS_BAR);
|
||||
}
|
||||
}
|
||||
this.actionMode = null;
|
||||
}
|
||||
|
||||
@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);
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
|
||||
if (R.id.action_edit == menuItem.getItemId()) {
|
||||
if (adapter != null && adapter.getSelectedCount() > 0) {
|
||||
Claim claim = adapter.getSelectedItems().get(0);
|
||||
// start channel editor with the claim
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openPublishForm(claim);
|
||||
}
|
||||
|
||||
actionMode.finish();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
if (R.id.action_delete == menuItem.getItemId()) {
|
||||
if (adapter != null && adapter.getSelectedCount() > 0) {
|
||||
final List<Claim> selectedClaims = new ArrayList<>(adapter.getSelectedItems());
|
||||
String message = getResources().getQuantityString(R.plurals.confirm_delete_publishes, selectedClaims.size());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
|
||||
setTitle(R.string.delete_selection).
|
||||
setMessage(message)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
handleDeleteSelectedClaims(selectedClaims);
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private void handleDeleteSelectedClaims(List<Claim> selectedClaims) {
|
||||
List<String> claimIds = new ArrayList<>();
|
||||
|
||||
for (Claim claim : selectedClaims) {
|
||||
claimIds.add(claim.getClaimId());
|
||||
}
|
||||
|
||||
if (actionMode != null) {
|
||||
actionMode.finish();
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(contentList, View.INVISIBLE);
|
||||
Helper.setViewVisibility(fabNewPublish, View.INVISIBLE);
|
||||
AbandonStreamTask task = new AbandonStreamTask(claimIds, bigLoading, new AbandonHandler() {
|
||||
@Override
|
||||
public void onComplete(List<String> successfulClaimIds, List<String> failedClaimIds, List<Exception> errors) {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
if (failedClaimIds.size() > 0) {
|
||||
Snackbar.make(root, R.string.one_or_more_publishes_failed_abandon, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
} else if (successfulClaimIds.size() == claimIds.size()) {
|
||||
try {
|
||||
String message = getResources().getQuantityString(R.plurals.publishes_deleted, successfulClaimIds.size());
|
||||
Snackbar.make(root, message, Snackbar.LENGTH_LONG).show();
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Lbry.abandonedClaimIds.addAll(successfulClaimIds);
|
||||
if (adapter != null) {
|
||||
adapter.setItems(Helper.filterDeletedClaims(adapter.getItems()));
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(contentList, View.VISIBLE);
|
||||
Helper.setViewVisibility(fabNewPublish, View.VISIBLE);
|
||||
checkNoPublishes();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
+26
-82
@@ -1,4 +1,4 @@
|
||||
package io.lbry.browser.ui.findcontent;
|
||||
package io.lbry.browser.ui.search;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
@@ -15,27 +15,18 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ClaimListAdapter;
|
||||
import io.lbry.browser.listener.DownloadActionListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.ClaimCacheKey;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.model.NavMenuItem;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimSearchTask;
|
||||
import io.lbry.browser.tasks.LighthouseSearchTask;
|
||||
import io.lbry.browser.tasks.claim.ResolveTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.ui.publish.PublishFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
@@ -43,10 +34,10 @@ import io.lbry.browser.utils.LbryUri;
|
||||
import lombok.Setter;
|
||||
|
||||
public class SearchFragment extends BaseFragment implements
|
||||
ClaimListAdapter.ClaimListItemListener, DownloadActionListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
ClaimListAdapter.ClaimListItemListener, SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
private ClaimListAdapter resultListAdapter;
|
||||
private static final int PAGE_SIZE = 25;
|
||||
|
||||
private ClaimListAdapter resultListAdapter;
|
||||
private ProgressBar loadingView;
|
||||
private RecyclerView resultList;
|
||||
private TextView noQueryView;
|
||||
@@ -104,7 +95,6 @@ public class SearchFragment extends BaseFragment implements
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Search", "Search");
|
||||
activity.addDownloadActionListener(this);
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(currentQuery)) {
|
||||
logSearch(currentQuery);
|
||||
@@ -116,11 +106,7 @@ public class SearchFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
public void onPause() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
((MainActivity) context).removeDownloadActionListener(this);
|
||||
}
|
||||
PreferenceManager.getDefaultSharedPreferences(context).unregisterOnSharedPreferenceChangeListener(this);
|
||||
PreferenceManager.getDefaultSharedPreferences(getContext()).unregisterOnSharedPreferenceChangeListener(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@@ -155,7 +141,7 @@ public class SearchFragment extends BaseFragment implements
|
||||
|
||||
private void resolveFeaturedItem(String vanityUrl) {
|
||||
final ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setUrl(vanityUrl);
|
||||
key.setVanityUrl(vanityUrl);
|
||||
if (Lbry.claimCache.containsKey(key)) {
|
||||
Claim cachedClaim = Lbry.claimCache.get(key);
|
||||
updateFeaturedItemFromResolvedClaim(cachedClaim);
|
||||
@@ -184,26 +170,16 @@ public class SearchFragment extends BaseFragment implements
|
||||
if (resultListAdapter != null) {
|
||||
Claim unresolved = resultListAdapter.getFeaturedItem();
|
||||
|
||||
Context context = getContext();
|
||||
boolean canShowMatureContent = false;
|
||||
if (context != null) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
}
|
||||
if (resolved.isMature() && !canShowMatureContent) {
|
||||
resultListAdapter.removeFeaturedItem();
|
||||
} else {
|
||||
// only set the values we need
|
||||
unresolved.setClaimId(resolved.getClaimId());
|
||||
unresolved.setName(resolved.getName());
|
||||
unresolved.setTimestamp(resolved.getTimestamp());
|
||||
unresolved.setValueType(resolved.getValueType());
|
||||
unresolved.setPermanentUrl(resolved.getPermanentUrl());
|
||||
unresolved.setValue(resolved.getValue());
|
||||
unresolved.setSigningChannel(resolved.getSigningChannel());
|
||||
unresolved.setUnresolved(false);
|
||||
unresolved.setConfirmations(resolved.getConfirmations());
|
||||
}
|
||||
// only set the values we need
|
||||
unresolved.setClaimId(resolved.getClaimId());
|
||||
unresolved.setName(resolved.getName());
|
||||
unresolved.setTimestamp(resolved.getTimestamp());
|
||||
unresolved.setValueType(resolved.getValueType());
|
||||
unresolved.setPermanentUrl(resolved.getPermanentUrl());
|
||||
unresolved.setValue(resolved.getValue());
|
||||
unresolved.setSigningChannel(resolved.getSigningChannel());
|
||||
unresolved.setUnresolved(false);
|
||||
unresolved.setConfirmations(resolved.getConfirmations());
|
||||
|
||||
resultListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
@@ -226,15 +202,10 @@ public class SearchFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
searchLoading = true;
|
||||
Context context = getContext();
|
||||
boolean canShowMatureContent = false;
|
||||
if (context != null) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
}
|
||||
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
boolean canShowMatureContent = sp.getBoolean(MainActivity.PREFERENCE_KEY_SHOW_MATURE_CONTENT, false);
|
||||
LighthouseSearchTask task = new LighthouseSearchTask(
|
||||
currentQuery, PAGE_SIZE, currentFrom, canShowMatureContent, null, loadingView, new ClaimSearchResultHandler() {
|
||||
currentQuery, PAGE_SIZE, currentFrom, canShowMatureContent, null, loadingView, new ClaimSearchTask.ClaimSearchResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
contentHasReachedEnd = hasReachedEnd;
|
||||
@@ -276,20 +247,13 @@ public class SearchFragment extends BaseFragment implements
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (claim.isUnresolved()) {
|
||||
// open the publish page
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("suggestedUrl", claim.getName());
|
||||
activity.openFragment(PublishFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH, params);
|
||||
} else if (claim.getName().startsWith("@")) {
|
||||
activity.openChannelUrl(claim.getPermanentUrl());
|
||||
} else {
|
||||
// not a channel
|
||||
activity.openFileClaim(claim);
|
||||
}
|
||||
if (claim.isUnresolved()) {
|
||||
// open the publish page
|
||||
} else if (claim.getName().startsWith("@")) {
|
||||
((MainActivity) getContext()).openChannelUrl(claim.getPermanentUrl());
|
||||
} else {
|
||||
// not a channel
|
||||
MainActivity.openFileClaim(claim, getContext());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -298,24 +262,4 @@ public class SearchFragment extends BaseFragment implements
|
||||
search(currentQuery, currentFrom);
|
||||
}
|
||||
}
|
||||
|
||||
public void onDownloadAction(String downloadAction, String uri, String outpoint, String fileInfoJson, double progress) {
|
||||
if ("abort".equals(downloadAction)) {
|
||||
if (resultListAdapter != null) {
|
||||
resultListAdapter.clearFileForClaimOrUrl(outpoint, uri);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
JSONObject fileInfo = new JSONObject(fileInfoJson);
|
||||
LbryFile claimFile = LbryFile.fromJSONObject(fileInfo);
|
||||
String claimId = claimFile.getClaimId();
|
||||
if (resultListAdapter != null) {
|
||||
resultListAdapter.updateFileForClaimByIdOrUrl(claimFile, claimId, uri);
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
// invalid file info for download
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.lbry.browser.ui.verification;
|
||||
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
@@ -96,8 +95,7 @@ public class EmailVerificationFragment extends Fragment {
|
||||
private void addEmail() {
|
||||
currentEmail = Helper.getValue(inputEmail.getText());
|
||||
if (Helper.isNullOrEmpty(currentEmail) || currentEmail.indexOf("@") == -1) {
|
||||
Snackbar.make(getView(), R.string.provide_valid_email, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), R.string.provide_valid_email, Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -127,8 +125,7 @@ public class EmailVerificationFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
Helper.setViewVisibility(buttonContinue, View.VISIBLE);
|
||||
}
|
||||
});
|
||||
@@ -191,8 +188,7 @@ public class EmailVerificationFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
Helper.setViewEnabled(buttonResend, true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -74,8 +74,7 @@ public class PhoneVerificationFragment extends Fragment {
|
||||
currentPhoneNumber = Helper.getValue(inputPhoneNumber.getText());
|
||||
|
||||
if (Helper.isNullOrEmpty(currentPhoneNumber) || !countryCodePicker.isValidFullNumber()) {
|
||||
Snackbar.make(getView(), R.string.please_enter_valid_phone, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), R.string.please_enter_valid_phone, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -88,8 +87,7 @@ public class PhoneVerificationFragment extends Fragment {
|
||||
public void onClick(View view) {
|
||||
String code = Helper.getValue(inputVerificationCode.getText());
|
||||
if (Helper.isNullOrEmpty(code)) {
|
||||
Snackbar.make(getView(), R.string.please_enter_verification_code, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), R.string.please_enter_verification_code, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
return;
|
||||
}
|
||||
verifyPhoneNumber(code);
|
||||
@@ -111,8 +109,8 @@ public class PhoneVerificationFragment extends Fragment {
|
||||
PhoneNewVerifyTask task = new PhoneNewVerifyTask(currentCountryCode, currentPhoneNumber, null, newLoading, new GenericTaskHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
Helper.setViewEnabled(continueButton, false);
|
||||
Helper.setViewVisibility(continueButton, View.GONE);
|
||||
continueButton.setEnabled(false);
|
||||
continueButton.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -121,21 +119,18 @@ public class PhoneVerificationFragment extends Fragment {
|
||||
listener.onPhoneAdded(currentCountryCode, currentPhoneNumber);
|
||||
}
|
||||
|
||||
Helper.setViewText(textVerifyParagraph, getString(R.string.enter_phone_verify_code, countryCodePicker.getFullNumberWithPlus()));
|
||||
Helper.setViewVisibility(layoutCollect, View.GONE);
|
||||
Helper.setViewVisibility(layoutVerify, View.VISIBLE);
|
||||
Helper.setViewEnabled(continueButton, true);
|
||||
Helper.setViewVisibility(continueButton, View.VISIBLE);
|
||||
textVerifyParagraph.setText(getString(R.string.enter_phone_verify_code, countryCodePicker.getFullNumberWithPlus()));
|
||||
layoutCollect.setVisibility(View.GONE);
|
||||
layoutVerify.setVisibility(View.VISIBLE);
|
||||
continueButton.setEnabled(true);
|
||||
continueButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
if (error != null && getView() != null) {
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
Helper.setViewEnabled(continueButton, true);
|
||||
Helper.setViewVisibility(continueButton, View.VISIBLE);
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
continueButton.setEnabled(true);
|
||||
continueButton.setVisibility(View.VISIBLE);
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
@@ -145,8 +140,8 @@ public class PhoneVerificationFragment extends Fragment {
|
||||
PhoneNewVerifyTask task = new PhoneNewVerifyTask(currentCountryCode, currentPhoneNumber, verificationCode, verifyLoading, new GenericTaskHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
Helper.setViewEnabled(verifyButton, false);
|
||||
Helper.setViewEnabled(editButton, false);
|
||||
verifyButton.setEnabled(false);
|
||||
editButton.setEnabled(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,18 +149,15 @@ public class PhoneVerificationFragment extends Fragment {
|
||||
if (listener != null) {
|
||||
listener.onPhoneVerified();
|
||||
}
|
||||
Helper.setViewEnabled(verifyButton, true);
|
||||
Helper.setViewEnabled(editButton, true);
|
||||
verifyButton.setEnabled(true);
|
||||
editButton.setEnabled(true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
if (getView() != null && error != null) {
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
Helper.setViewEnabled(verifyButton, true);
|
||||
Helper.setViewEnabled(editButton, true);
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
verifyButton.setEnabled(true);
|
||||
editButton.setEnabled(true);
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
|
||||
@@ -41,7 +41,7 @@ import io.lbry.browser.model.lbryinc.Invitee;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
import io.lbry.browser.tasks.claim.ChannelCreateUpdateTask;
|
||||
import io.lbry.browser.tasks.ChannelCreateUpdateTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimResultHandler;
|
||||
import io.lbry.browser.tasks.lbryinc.LogPublishTask;
|
||||
import io.lbry.browser.tasks.lbryinc.FetchInviteStatusTask;
|
||||
@@ -248,10 +248,7 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
}
|
||||
|
||||
private void updateInviteLink(Claim claim) {
|
||||
LbryUri canonical = LbryUri.tryParse(claim.getCanonicalUrl());
|
||||
String link = String.format(INVITE_LINK_FORMAT,
|
||||
canonical != null ? String.format("@%s", canonical.getChannelName()) : claim.getName(),
|
||||
canonical != null ? canonical.getChannelClaimId() : claim.getClaimId());
|
||||
String link = String.format(INVITE_LINK_FORMAT, claim.getName(), claim.getClaimId());
|
||||
textInviteLink.setText(link);
|
||||
}
|
||||
private void copyInviteLink() {
|
||||
@@ -470,12 +467,15 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// validate deposit and channel name
|
||||
String channelNameString = Helper.normalizeChannelName(Helper.getValue(inputChannelName.getText()));
|
||||
String channelNameString = Helper.getValue(inputChannelName.getText());
|
||||
if (!channelNameString.startsWith("@")) {
|
||||
channelNameString = String.format("@%s", channelNameString);
|
||||
}
|
||||
Claim claimToSave = new Claim();
|
||||
claimToSave.setName(channelNameString);
|
||||
String channelName = claimToSave.getName().startsWith("@") ? claimToSave.getName().substring(1) : claimToSave.getName();
|
||||
String depositString = Helper.getValue(inputDeposit.getText());
|
||||
if ("@".equals(channelName) || Helper.isNullOrEmpty(channelName)) {
|
||||
if (Helper.isNullOrEmpty(channelName)) {
|
||||
showError(getString(R.string.please_enter_channel_name));
|
||||
return;
|
||||
}
|
||||
@@ -523,12 +523,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
logPublishTask.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
// channel created
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("claim_id", claimResult.getClaimId());
|
||||
bundle.putString("claim_name", claimResult.getName());
|
||||
LbryAnalytics.logEvent(LbryAnalytics.EVENT_CHANNEL_CREATE, bundle);
|
||||
|
||||
// add the claim to the channel list and set it as the selected item
|
||||
channelSpinnerAdapter.add(claimResult);
|
||||
channelSpinner.setSelection(channelSpinnerAdapter.getCount() - 1);
|
||||
@@ -565,8 +559,7 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
private void showError(String message) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -233,15 +233,10 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R
|
||||
Helper.shortCurrencyFormat(Lbryio.totalUnclaimedRewardAmount));
|
||||
double unclaimedRewardAmountUsd = Lbryio.totalUnclaimedRewardAmount * Lbryio.LBCUSDRate;
|
||||
Helper.setViewText(textAccountDriverTitle, accountDriverTitle);
|
||||
Helper.setViewText(textFreeCreditsWorth, getString(R.string.free_credits_worth, Helper.SIMPLE_CURRENCY_FORMAT.format(unclaimedRewardAmountUsd)));
|
||||
Helper.setViewText(textFreeCreditsWorth, getString(R.string.free_credits_worth, Helper.USD_CURRENCY_FORMAT.format(unclaimedRewardAmountUsd)));
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).updateRewardsUsdVale();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -273,10 +268,7 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R
|
||||
amountClaimed == 1 ? 1 : 2,
|
||||
new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed));
|
||||
}
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).show();
|
||||
Helper.setViewEnabled(buttonClaim, true);
|
||||
Helper.setViewEnabled(inputClaimCode, true);
|
||||
rewardClaimInProgress = false;
|
||||
@@ -286,8 +278,7 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Snackbar.make(getView(), error.getMessage(), Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
Helper.setViewEnabled(buttonClaim, true);
|
||||
Helper.setViewEnabled(inputClaimCode, true);
|
||||
rewardClaimInProgress = false;
|
||||
|
||||
@@ -10,7 +10,6 @@ import android.widget.ProgressBar;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.ActionBar;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
@@ -49,9 +48,7 @@ public class TransactionHistoryFragment extends BaseFragment implements Transact
|
||||
Context context = getContext();
|
||||
LinearLayoutManager llm = new LinearLayoutManager(context);
|
||||
transactionList.setLayoutManager(llm);
|
||||
DividerItemDecoration itemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
|
||||
itemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.thin_divider));
|
||||
transactionList.addItemDecoration(itemDecoration);
|
||||
transactionList.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
||||
|
||||
transactionList.addOnScrollListener(new RecyclerView.OnScrollListener() {
|
||||
@Override
|
||||
@@ -136,7 +133,10 @@ public class TransactionHistoryFragment extends BaseFragment implements Transact
|
||||
activity.showNavigationBackIcon();
|
||||
activity.lockDrawer();
|
||||
|
||||
activity.setActionBarTitle(R.string.transaction_history);
|
||||
ActionBar actionBar = activity.getSupportActionBar();
|
||||
if (actionBar != null) {
|
||||
actionBar.setTitle(R.string.transaction_history);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -156,12 +156,12 @@ public class TransactionHistoryFragment extends BaseFragment implements Transact
|
||||
}
|
||||
public void onClaimUrlClicked(LbryUri uri) {
|
||||
Context context = getContext();
|
||||
if (uri != null && context instanceof MainActivity) {
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (uri.isChannel()) {
|
||||
activity.openChannelUrl(uri.toString());
|
||||
} else {
|
||||
activity.openFileUrl(uri.toString());
|
||||
MainActivity.openFileUrl(uri.toString(), context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,7 +17,6 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -30,9 +29,7 @@ import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.DecimalFormatSymbols;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
@@ -46,7 +43,6 @@ import io.lbry.browser.tasks.wallet.TransactionListTask;
|
||||
import io.lbry.browser.tasks.wallet.WalletAddressUnusedTask;
|
||||
import io.lbry.browser.tasks.wallet.WalletSendTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.ui.publish.PublishFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
@@ -158,25 +154,6 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
public void onSuccess(List<Transaction> transactions, boolean hasReachedEnd) {
|
||||
hasFetchedRecentTransactions = true;
|
||||
recentTransactionsAdapter = new TransactionListAdapter(transactions, getContext());
|
||||
recentTransactionsAdapter.setListener(new TransactionListAdapter.TransactionClickListener() {
|
||||
@Override
|
||||
public void onTransactionClicked(Transaction transaction) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onClaimUrlClicked(LbryUri uri) {
|
||||
Context context = getContext();
|
||||
if (uri != null && context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (uri.isChannel()) {
|
||||
activity.openChannelUrl(uri.toString());
|
||||
} else {
|
||||
activity.openFileUrl(uri.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
recentTransactionsList.setAdapter(recentTransactionsAdapter);
|
||||
displayNoRecentTransactions();
|
||||
}
|
||||
@@ -201,7 +178,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
String amountString = Helper.getValue(inputSendAmount.getText());
|
||||
if (!recipientAddress.matches(LbryUri.REGEX_ADDRESS)) {
|
||||
Snackbar.make(getView(), R.string.invalid_recipient_address, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
setBackgroundTint(Color.RED).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -211,13 +188,13 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
double availableAmount = Lbry.walletBalance.getAvailable().doubleValue();
|
||||
if (availableAmount < amountValue) {
|
||||
Snackbar.make(getView(), R.string.insufficient_balance, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
return false;
|
||||
}
|
||||
} catch (NumberFormatException ex) {
|
||||
// pass
|
||||
Snackbar.make(getView(), R.string.invalid_amount, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -238,18 +215,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
Context context = getContext();
|
||||
LinearLayoutManager llm = new LinearLayoutManager(context);
|
||||
recentTransactionsList.setLayoutManager(llm);
|
||||
DividerItemDecoration itemDecoration = new DividerItemDecoration(context, DividerItemDecoration.VERTICAL);
|
||||
itemDecoration.setDrawable(ContextCompat.getDrawable(context, R.drawable.thin_divider));
|
||||
recentTransactionsList.addItemDecoration(itemDecoration);
|
||||
|
||||
textEarnMoreTips.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openFragment(PublishFragment.class, true, NavMenuItem.ID_ITEM_NEW_PUBLISH);
|
||||
}
|
||||
}
|
||||
});
|
||||
recentTransactionsList.addItemDecoration(new DividerItemDecoration(context, DividerItemDecoration.VERTICAL));
|
||||
|
||||
buttonSignUp.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
@@ -383,8 +349,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
// wallet_send task
|
||||
String recipientAddress = Helper.getValue(inputSendAddress.getText());
|
||||
String amountString = Helper.getValue(inputSendAmount.getText());
|
||||
String amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).
|
||||
format(new BigDecimal(amountString).doubleValue());
|
||||
String amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT).format(new BigDecimal(amountString).doubleValue());
|
||||
|
||||
disableSendControls();
|
||||
WalletSendTask task = new WalletSendTask(recipientAddress, amount, walletSendProgress, new WalletSendTask.WalletSendHandler() {
|
||||
@@ -403,7 +368,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Snackbar.make(getView(), R.string.send_credit_error, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
enableSendControls();
|
||||
}
|
||||
});
|
||||
@@ -411,12 +376,8 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
}
|
||||
|
||||
private void checkReceiveAddress() {
|
||||
Context context = getContext();
|
||||
String receiveAddress = null;
|
||||
if (context != null) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
receiveAddress = sp.getString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, null);
|
||||
}
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
String receiveAddress = sp.getString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, null);
|
||||
if (Helper.isNullOrEmpty(receiveAddress)) {
|
||||
if (Lbry.SDK_READY) {
|
||||
generateNewAddress();
|
||||
@@ -440,11 +401,11 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
LbryAnalytics.setCurrentScreen(activity, "Wallet", "Wallet");
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(layoutAccountRecommended, hasSkippedAccount() || Lbryio.isSignedIn() ? View.GONE : View.VISIBLE);
|
||||
if (!Lbry.SDK_READY) {
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.addSdkStatusListener(this);
|
||||
activity.addWalletBalanceListener(this);
|
||||
}
|
||||
|
||||
checkReceiveAddress();
|
||||
@@ -480,9 +441,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
public void onSdkReady() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.syncWalletAndLoadPreferences();
|
||||
activity.addWalletBalanceListener(this);
|
||||
((MainActivity) context).removeSdkStatusListener(this);
|
||||
}
|
||||
|
||||
// update view
|
||||
@@ -522,16 +481,15 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
double tipsBalance = walletBalance.getTips().doubleValue();
|
||||
double tipsUsdBalance = tipsBalance * Lbryio.LBCUSDRate;
|
||||
|
||||
String formattedBalance = Helper.SIMPLE_CURRENCY_FORMAT.format(balance);
|
||||
Helper.setViewText(textWalletBalance, balance > 0 && formattedBalance.equals("0") ? Helper.FULL_LBC_CURRENCY_FORMAT.format(balance) : formattedBalance);
|
||||
Helper.setViewText(textWalletBalance, Helper.LBC_CURRENCY_FORMAT.format(balance));
|
||||
Helper.setViewText(textTipsBalance, Helper.shortCurrencyFormat(tipsBalance));
|
||||
Helper.setViewText(textClaimsBalance, Helper.shortCurrencyFormat(walletBalance.getClaims().doubleValue()));
|
||||
Helper.setViewText(textSupportsBalance, Helper.shortCurrencyFormat(walletBalance.getSupports().doubleValue()));
|
||||
Helper.setViewText(textWalletInlineBalance, Helper.shortCurrencyFormat(balance));
|
||||
if (Lbryio.LBCUSDRate > 0) {
|
||||
// only update display usd values if the rate is loaded
|
||||
Helper.setViewText(textWalletBalanceUSD, String.format("≈$%s", Helper.SIMPLE_CURRENCY_FORMAT.format(usdBalance)));
|
||||
Helper.setViewText(textTipsBalanceUSD, String.format("≈$%s", Helper.SIMPLE_CURRENCY_FORMAT.format(tipsUsdBalance)));
|
||||
Helper.setViewText(textWalletBalanceUSD, String.format("≈$%s", Helper.USD_CURRENCY_FORMAT.format(usdBalance)));
|
||||
Helper.setViewText(textTipsBalanceUSD, String.format("≈$%s", Helper.USD_CURRENCY_FORMAT.format(tipsUsdBalance)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -12,23 +12,16 @@ import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.graphics.drawable.ShapeDrawable;
|
||||
import android.net.Uri;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
import android.os.Environment;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.provider.MediaStore;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.recyclerview.widget.GridLayoutManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
@@ -38,7 +31,6 @@ import java.io.Closeable;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.DecimalFormat;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Calendar;
|
||||
@@ -48,16 +40,10 @@ import java.util.Map;
|
||||
import java.util.Random;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.dialog.ContentFromDialogFragment;
|
||||
import io.lbry.browser.dialog.ContentSortDialogFragment;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.LbryFile;
|
||||
import io.lbry.browser.model.Tag;
|
||||
import io.lbry.browser.model.UrlSuggestion;
|
||||
import io.lbry.browser.model.ViewHistory;
|
||||
import io.lbry.browser.tasks.localdata.SaveUrlHistoryTask;
|
||||
import io.lbry.browser.tasks.localdata.SaveViewHistoryTask;
|
||||
import okhttp3.MediaType;
|
||||
|
||||
public final class Helper {
|
||||
@@ -69,17 +55,12 @@ public final class Helper {
|
||||
public static final MediaType FORM_MEDIA_TYPE = MediaType.parse("application/x-www-form-urlencoded");
|
||||
public static final MediaType JSON_MEDIA_TYPE = MediaType.get("application/json; charset=utf-8");
|
||||
public static final int CONTENT_PAGE_SIZE = 25;
|
||||
public static final double MIN_DEPOSIT = 0.001;
|
||||
public static final double MIN_DEPOSIT = 0.05;
|
||||
public static final String LBC_CURRENCY_FORMAT_PATTERN = "#,###.##";
|
||||
public static final String FILE_SIZE_FORMAT_PATTERN = "#,###.#";
|
||||
public static final DecimalFormat LBC_CURRENCY_FORMAT = new DecimalFormat(LBC_CURRENCY_FORMAT_PATTERN);
|
||||
public static final DecimalFormat FULL_LBC_CURRENCY_FORMAT = new DecimalFormat("#,###.########");
|
||||
public static final DecimalFormat SIMPLE_CURRENCY_FORMAT = new DecimalFormat("#,##0.00");
|
||||
public static final SimpleDateFormat FILESTAMP_FORMAT = new SimpleDateFormat("yyyyMMdd_HHmmss");
|
||||
public static final DecimalFormat USD_CURRENCY_FORMAT = new DecimalFormat("#,##0.00");
|
||||
public static final String EXPLORER_TX_PREFIX = "https://explorer.lbry.com/tx";
|
||||
|
||||
public static final List<Double> PLAYBACK_SPEEDS = Arrays.asList(0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75, 2.0);
|
||||
|
||||
public static boolean isNull(String value) {
|
||||
return value == null;
|
||||
}
|
||||
@@ -87,14 +68,6 @@ public final class Helper {
|
||||
return value == null || value.trim().length() == 0;
|
||||
}
|
||||
|
||||
public static void buildPlaybackSpeedMenu(ContextMenu menu) {
|
||||
int order = 0;
|
||||
DecimalFormat formatter = new DecimalFormat("0.##");
|
||||
for (Double speed : PLAYBACK_SPEEDS) {
|
||||
menu.add(0, Double.valueOf(speed * 100).intValue(), ++order, String.format("%sx", formatter.format(speed)));
|
||||
}
|
||||
}
|
||||
|
||||
public static String capitalize(String value) {
|
||||
StringBuilder sb = new StringBuilder();
|
||||
boolean capitalizeNext = true;
|
||||
@@ -144,12 +117,6 @@ public final class Helper {
|
||||
}
|
||||
}
|
||||
|
||||
public static void setViewProgress(ProgressBar progressBar, int progress) {
|
||||
if (progressBar != null) {
|
||||
progressBar.setProgress(progress);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setViewText(TextView view, int stringResourceId) {
|
||||
if (view != null) {
|
||||
view.setText(stringResourceId);
|
||||
@@ -212,43 +179,6 @@ public final class Helper {
|
||||
}
|
||||
return String.format("%d:%02d", minutes, seconds);
|
||||
}
|
||||
public static String[] formatBytesParts(long bytes, boolean showTB) {
|
||||
DecimalFormat formatter = new DecimalFormat(FILE_SIZE_FORMAT_PATTERN);
|
||||
if (bytes < 1048576) {
|
||||
// less than 1MB
|
||||
return new String[] { formatter.format(bytes / 1024.0), "KB" };
|
||||
}
|
||||
if (bytes < 1073741824) {
|
||||
// less than 1GB
|
||||
return new String[] { formatter.format(bytes / (1024.0 * 1024.0)), "MB" };
|
||||
}
|
||||
if (showTB) {
|
||||
if (bytes < (1073741824L * 1024L)) {
|
||||
return new String[] { formatter.format(bytes / (1024.0 * 1024.0 * 1024.0)), "GB" };
|
||||
}
|
||||
return new String[] { formatter.format(bytes / (1024.0 * 1024.0 * 1024.0 * 1024.0)), "TB" };
|
||||
}
|
||||
return new String[] { formatter.format(bytes / (1024.0 * 1024.0 * 1024.0)), "GB" };
|
||||
}
|
||||
|
||||
public static String formatBytes(long bytes, boolean showTB) {
|
||||
DecimalFormat formatter = new DecimalFormat(FILE_SIZE_FORMAT_PATTERN);
|
||||
if (bytes < 1048576) {
|
||||
// less than 1MB
|
||||
return String.format("%sKB", formatter.format(bytes / 1024.0));
|
||||
}
|
||||
if (bytes < 1073741824) {
|
||||
// less than 1GB
|
||||
return String.format("%sMB", formatter.format(bytes / (1024.0 * 1024.0)));
|
||||
}
|
||||
if (showTB) {
|
||||
if (bytes < (1073741824L * 1024L)) {
|
||||
return String.format("%sGB", formatter.format(bytes / (1024.0 * 1024.0 * 1024.0)));
|
||||
}
|
||||
return String.format("%sTB", formatter.format(bytes / (1024.0 * 1024.0 * 1024.0 * 1024.0)));
|
||||
}
|
||||
return String.format("%sGB", formatter.format(bytes / (1024.0 * 1024.0 * 1024.0)));
|
||||
}
|
||||
|
||||
public static JSONObject getJSONObject(String name, JSONObject object) {
|
||||
try {
|
||||
@@ -303,22 +233,21 @@ public final class Helper {
|
||||
}
|
||||
|
||||
public static String shortCurrencyFormat(double value) {
|
||||
DecimalFormat format = new DecimalFormat("#,###.#");
|
||||
if (value > 1000000000.00) {
|
||||
return String.format("%sB", format.format(value / 1000000000.0));
|
||||
return String.format("%.1fB", value / 1000000000.0);
|
||||
}
|
||||
if (value > 1000000.0) {
|
||||
return String.format("%sM",format.format( value / 1000000.0));
|
||||
return String.format("%.1fM", value / 1000000.0);
|
||||
}
|
||||
if (value > 1000.0) {
|
||||
return String.format("%sK", format.format(value / 1000.0));
|
||||
return String.format("%.1fK", value / 1000.0);
|
||||
}
|
||||
|
||||
if (value == 0) {
|
||||
return "0";
|
||||
}
|
||||
|
||||
return format.format(value).equals("0") ? FULL_LBC_CURRENCY_FORMAT.format(value) : format.format(value);
|
||||
return new DecimalFormat("###.##").format(value);
|
||||
}
|
||||
|
||||
public static String getValue(CharSequence cs) {
|
||||
@@ -420,15 +349,6 @@ public final class Helper {
|
||||
}
|
||||
return followedTags;
|
||||
}
|
||||
public static List<Claim> filterDeletedClaims(List<Claim> claims) {
|
||||
List<Claim> filtered = new ArrayList<>();
|
||||
for (Claim claim : claims) {
|
||||
if (!Lbry.abandonedClaimIds.contains(claim.getClaimId())) {
|
||||
filtered.add(claim);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static void setWunderbarValue(String value, Context context) {
|
||||
if (context instanceof MainActivity) {
|
||||
@@ -451,14 +371,6 @@ public final class Helper {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
public static boolean claimNameExists(String claimName) {
|
||||
for (Claim claim : Lbry.ownClaims) {
|
||||
if (claimName.equalsIgnoreCase(claim.getName())) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static String getRealPathFromURI_API19(final Context context, final Uri uri) {
|
||||
return getRealPathFromURI_API19(context, uri, false);
|
||||
@@ -643,114 +555,4 @@ public final class Helper {
|
||||
textView.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
textView.setText(HtmlCompat.fromHtml(textView.getText().toString(), HtmlCompat.FROM_HTML_MODE_LEGACY));
|
||||
}
|
||||
|
||||
public static List<Claim> filterInvalidReposts(List<Claim> claims) {
|
||||
List<Claim> filtered = new ArrayList<>();
|
||||
for (Claim claim : claims) {
|
||||
if (Claim.TYPE_REPOST.equalsIgnoreCase(claim.getValueType()) && claim.getRepostedClaim() == null) {
|
||||
continue;
|
||||
}
|
||||
filtered.add(claim);
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static List<LbryFile> filterDownloads(List<LbryFile> files) {
|
||||
List<LbryFile> filtered = new ArrayList<>();
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
LbryFile file = files.get(i);
|
||||
// remove own claims as well
|
||||
if (file.getClaim() != null && Lbry.ownClaims.contains(file.getClaim())) {
|
||||
continue;
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(file.getDownloadPath())) {
|
||||
filtered.add(file);
|
||||
}
|
||||
}
|
||||
return filtered;
|
||||
}
|
||||
|
||||
public static List<Claim> claimsFromFiles(List<LbryFile> files) {
|
||||
List<Claim> claims = new ArrayList<>();
|
||||
for (LbryFile file : files) {
|
||||
claims.add(file.getClaim());
|
||||
}
|
||||
return claims;
|
||||
}
|
||||
|
||||
public static List<Claim> claimsFromViewHistory(List<ViewHistory> history) {
|
||||
List<Claim> claims = new ArrayList<>();
|
||||
for (ViewHistory item : history) {
|
||||
claims.add(Claim.fromViewHistory(item));
|
||||
}
|
||||
return claims;
|
||||
}
|
||||
|
||||
public static void saveUrlHistory(String url, String title, int type) {
|
||||
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
|
||||
if (dbHelper != null) {
|
||||
UrlSuggestion suggestion = new UrlSuggestion();
|
||||
suggestion.setUri(LbryUri.tryParse(url));
|
||||
suggestion.setType(type);
|
||||
suggestion.setText(Helper.isNull(title) ? "" : title);
|
||||
new SaveUrlHistoryTask(suggestion, dbHelper, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
||||
public static void saveViewHistory(String url, Claim claim) {
|
||||
DatabaseHelper dbHelper = DatabaseHelper.getInstance();
|
||||
if (dbHelper != null) {
|
||||
ViewHistory viewHistory = ViewHistory.fromClaimWithUrlAndDeviceName(claim, url, getDeviceName());
|
||||
new SaveViewHistoryTask(viewHistory, dbHelper, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
public static String normalizeChannelName(String channelName) {
|
||||
if (!channelName.startsWith("@")) {
|
||||
return String.format("@%s", channelName);
|
||||
}
|
||||
return channelName;
|
||||
}
|
||||
|
||||
public static int getScaledValue(int value, float scale) {
|
||||
return (int) (value * scale + 0.5f);
|
||||
}
|
||||
|
||||
public static String generateUrl() {
|
||||
Random random = new Random();
|
||||
StringBuilder sb = new StringBuilder();
|
||||
sb.append(Predefined.ADJECTIVES.get(random.nextInt(Predefined.ADJECTIVES.size()))).append("-").
|
||||
append(Predefined.ADJECTIVES.get(random.nextInt(Predefined.ADJECTIVES.size()))).append("-").
|
||||
append(Predefined.ANIMALS.get(random.nextInt(Predefined.ANIMALS.size())));
|
||||
return sb.toString().toLowerCase();
|
||||
}
|
||||
|
||||
public static void refreshRecyclerView(RecyclerView rv) {
|
||||
if (rv == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
RecyclerView.Adapter adapter = rv.getAdapter();
|
||||
int prevScrollPosition = 0;
|
||||
|
||||
RecyclerView.LayoutManager lm = rv.getLayoutManager();
|
||||
if (lm instanceof LinearLayoutManager) {
|
||||
prevScrollPosition = ((LinearLayoutManager) lm).findLastCompletelyVisibleItemPosition();
|
||||
} else if (lm instanceof GridLayoutManager) {
|
||||
prevScrollPosition = ((GridLayoutManager) lm).findLastCompletelyVisibleItemPosition();
|
||||
}
|
||||
|
||||
rv.setAdapter(null);
|
||||
rv.setAdapter(adapter);
|
||||
rv.scrollToPosition(prevScrollPosition > 0 ? prevScrollPosition : 0);
|
||||
}
|
||||
|
||||
public static String makeid(int length) {
|
||||
Random random = new Random();
|
||||
String chars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
StringBuilder id = new StringBuilder();
|
||||
for (int i = 0; i < length; i++) {
|
||||
id.append(chars.charAt(random.nextInt(chars.length())));
|
||||
}
|
||||
return id.toString();
|
||||
}
|
||||
}
|
||||
@@ -8,7 +8,6 @@ import java.io.IOException;
|
||||
import java.security.KeyStore;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
@@ -27,9 +26,6 @@ import io.lbry.browser.model.Tag;
|
||||
import io.lbry.browser.model.Transaction;
|
||||
import io.lbry.browser.model.WalletBalance;
|
||||
import io.lbry.lbrysdk.Utils;
|
||||
import kotlin.Pair;
|
||||
import okhttp3.CacheControl;
|
||||
import okhttp3.Headers;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
@@ -44,7 +40,6 @@ public final class Lbry {
|
||||
public static List<Tag> followedTags = new ArrayList<>();
|
||||
public static List<Claim> ownClaims = new ArrayList<>();
|
||||
public static List<Claim> ownChannels = new ArrayList<>(); // Make this a subset of ownClaims?
|
||||
public static List<String> abandonedClaimIds = new ArrayList<>();
|
||||
|
||||
public static final int TTL_CLAIM_SEARCH_VALUE = 120000; // 2-minute TTL for cache
|
||||
public static final String SDK_CONNECTION_STRING = "http://127.0.0.1:5279";
|
||||
@@ -65,7 +60,6 @@ public final class Lbry {
|
||||
public static final String METHOD_FILE_LIST = "file_list";
|
||||
public static final String METHOD_FILE_DELETE = "file_delete";
|
||||
public static final String METHOD_GET = "get";
|
||||
public static final String METHOD_PUBLISH = "publish";
|
||||
|
||||
public static final String METHOD_WALLET_BALANCE = "wallet_balance";
|
||||
public static final String METHOD_WALLET_ENCRYPT = "wallet_encrypt";
|
||||
@@ -92,17 +86,13 @@ public final class Lbry {
|
||||
public static final String METHOD_CHANNEL_CREATE = "channel_create";
|
||||
public static final String METHOD_CHANNEL_UPDATE = "channel_update";
|
||||
|
||||
|
||||
public static final String METHOD_CLAIM_LIST = "claim_list";
|
||||
public static final String METHOD_PURCHASE_LIST = "purchase_list";
|
||||
public static final String METHOD_STREAM_ABANDON = "stream_abandon";
|
||||
public static final String METHOD_STREAM_REPOST = "stream_repost";
|
||||
|
||||
public static KeyStore KEYSTORE;
|
||||
public static boolean SDK_READY = false;
|
||||
|
||||
public static void startupInit() {
|
||||
abandonedClaimIds = new ArrayList<>();
|
||||
ownChannels = new ArrayList<>();
|
||||
ownClaims = new ArrayList<>();
|
||||
knownTags = new ArrayList<>();
|
||||
@@ -171,7 +161,7 @@ public final class Lbry {
|
||||
if (value instanceof Double) {
|
||||
jsonParams.put(param.getKey(), (double) value);
|
||||
} else {
|
||||
jsonParams.put(param.getKey(), value == null ? JSONObject.NULL : value);
|
||||
jsonParams.put(param.getKey(), value);
|
||||
}
|
||||
}
|
||||
} catch (JSONException ex) {
|
||||
@@ -260,7 +250,9 @@ public final class Lbry {
|
||||
Claim claim = Claim.fromJSONObject(result.getJSONObject(keys.next()));
|
||||
claims.add(claim);
|
||||
|
||||
addClaimToCache(claim);
|
||||
// TODO: Add/remove/prune entries claim cache management
|
||||
ClaimCacheKey key = ClaimCacheKey.fromClaim(claim);
|
||||
claimCache.put(key, claim);
|
||||
}
|
||||
}
|
||||
} catch (LbryRequestException | LbryResponseException | JSONException ex) {
|
||||
@@ -317,22 +309,12 @@ public final class Lbry {
|
||||
return file;
|
||||
}
|
||||
|
||||
public static List<LbryFile> fileList(String claimId, boolean downloads, int page, int pageSize) throws ApiCallException {
|
||||
public static List<LbryFile> fileList(String claimId) throws ApiCallException {
|
||||
List<LbryFile> files = new ArrayList<>();
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
if (!Helper.isNullOrEmpty(claimId)) {
|
||||
params.put("claim_id", claimId);
|
||||
}
|
||||
if (downloads) {
|
||||
params.put("download_path", null);
|
||||
params.put("comparison", "ne");
|
||||
}
|
||||
if (page > 0) {
|
||||
params.put("page", page);
|
||||
}
|
||||
if (pageSize > 0) {
|
||||
params.put("page_size", pageSize);
|
||||
}
|
||||
try {
|
||||
JSONObject result = (JSONObject) parseResponse(apiCall(METHOD_FILE_LIST, params));
|
||||
JSONArray items = result.getJSONArray("items");
|
||||
@@ -414,7 +396,8 @@ public final class Lbry {
|
||||
Claim claim = Claim.fromJSONObject(items.getJSONObject(i));
|
||||
claims.add(claim);
|
||||
|
||||
addClaimToCache(claim);
|
||||
ClaimCacheKey key = ClaimCacheKey.fromClaim(claim);
|
||||
claimCache.put(key, claim);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -469,25 +452,4 @@ public final class Lbry {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void addClaimToCache(Claim claim) {
|
||||
ClaimCacheKey fullKey = ClaimCacheKey.fromClaim(claim);
|
||||
ClaimCacheKey shortUrlKey = ClaimCacheKey.fromClaimShortUrl(claim);
|
||||
ClaimCacheKey permanentUrlKey = ClaimCacheKey.fromClaimPermanentUrl(claim);
|
||||
claimCache.put(fullKey, claim);
|
||||
claimCache.put(permanentUrlKey, claim);
|
||||
if (!Helper.isNullOrEmpty(shortUrlKey.getUrl())) {
|
||||
claimCache.put(shortUrlKey, claim);
|
||||
}
|
||||
}
|
||||
|
||||
public static void unsetFilesForCachedClaims(List<String> claimIds) {
|
||||
for (String claimId : claimIds) {
|
||||
ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setClaimId(claimId);
|
||||
if (claimCache.containsKey(key)) {
|
||||
claimCache.get(key).setFile(null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -44,7 +44,7 @@ public class LbryUri {
|
||||
}
|
||||
|
||||
public static boolean isNameValid(String name) {
|
||||
return !Pattern.compile(REGEX_INVALID_URI).matcher(name).find();
|
||||
return !name.matches(REGEX_INVALID_URI);
|
||||
}
|
||||
|
||||
public static LbryUri tryParse(String url) {
|
||||
@@ -260,14 +260,21 @@ public class LbryUri {
|
||||
String secondaryClaimId = !Helper.isNullOrEmpty(secondaryClaimName) ? streamClaimId : null;
|
||||
|
||||
if (!Helper.isNullOrEmpty(primaryClaimId)) {
|
||||
sb.append(':').append(primaryClaimId);
|
||||
sb.append('#').append(primaryClaimId);
|
||||
}
|
||||
if (primaryClaimSequence > 0) {
|
||||
sb.append(':').append(primaryClaimSequence);
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(secondaryClaimName)) {
|
||||
sb.append('/').append(secondaryClaimName);
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(secondaryClaimId)) {
|
||||
sb.append(':').append(secondaryClaimId);
|
||||
sb.append('#').append(secondaryClaimId);
|
||||
}
|
||||
if (secondaryClaimSequence > 0) {
|
||||
sb.append(':').append(secondaryClaimSequence);
|
||||
}
|
||||
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import okhttp3.Response;
|
||||
public final class Lbryio {
|
||||
|
||||
// TODO: Get this from the bundled aar
|
||||
public static String SDK_VERSION = "0.74.0";
|
||||
public static String SDK_VERSION = "0.73.1";
|
||||
|
||||
public static User currentUser;
|
||||
public static boolean userHasSyncedWallet = false;
|
||||
@@ -121,7 +121,7 @@ public final class Lbryio {
|
||||
|
||||
if (options != null) {
|
||||
for (Map.Entry<String, String> option : options.entrySet()) {
|
||||
qs.append(delim).append(option.getKey()).append("=").append(URLEncoder.encode(Helper.isNull(option.getValue()) ? "" : option.getValue(), "UTF8"));
|
||||
qs.append(delim).append(option.getKey()).append("=").append(URLEncoder.encode(option.getValue(), "UTF8"));
|
||||
delim = "&";
|
||||
}
|
||||
}
|
||||
@@ -192,9 +192,8 @@ public final class Lbryio {
|
||||
Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
|
||||
User user = gson.fromJson(object.toString(), type);
|
||||
return user;
|
||||
} catch (LbryioRequestException | LbryioResponseException | ClassCastException | IllegalStateException ex) {
|
||||
LbryAnalytics.logException(String.format("/user/me failed: %s", ex.getMessage()), ex.getClass().getName());
|
||||
android.util.Log.e(TAG, "Could not retrieve the current user", ex);
|
||||
} catch (LbryioRequestException | LbryioResponseException | ClassCastException ex) {
|
||||
android.util.Log.e(TAG, "Cannot retrieve the current user", ex);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -212,12 +211,7 @@ public final class Lbryio {
|
||||
}
|
||||
|
||||
Map<String, String> options = new HashMap<>();
|
||||
if (context instanceof MainActivity) {
|
||||
String firebaseToken = ((MainActivity) context).getFirebaseMessagingToken();
|
||||
if (!Helper.isNullOrEmpty(firebaseToken)) {
|
||||
options.put("firebase_token", firebaseToken);
|
||||
}
|
||||
}
|
||||
//options.put("firebase_token", null);
|
||||
options.put("app_version", appVersion);
|
||||
options.put("app_id", Lbry.INSTALLATION_ID);
|
||||
options.put("node_id", "");
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M21,3L3,3c-1.1,0 -2,0.9 -2,2v3h2L3,5h18v14h-7v2h7c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2zM1,18v3h3c0,-1.66 -1.34,-3 -3,-3zM1,14v2c2.76,0 5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM1,10v2c4.97,0 9,4.03 9,9h2c0,-6.08 -4.93,-11 -11,-11z"/>
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M1,18v3h3c0,-1.66 -1.34,-3 -3,-3zM1,14v2c2.76,0 5,2.24 5,5h2c0,-3.87 -3.13,-7 -7,-7zM19,7L5,7v1.63c3.96,1.28 7.09,4.41 8.37,8.37L19,17L19,7zM1,10v2c4.97,0 9,4.03 9,9h2c0,-6.08 -4.93,-11 -11,-11zM21,3L3,3c-1.1,0 -2,0.9 -2,2v3h2L3,5h18v14h-7v2h7c1.1,0 2,-0.9 2,-2L23,5c0,-1.1 -0.9,-2 -2,-2z"/>
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M4,13c0,4.4 3.6,8 8,8s8,-3.6 8,-8h-2c0,3.3 -2.7,6 -6,6s-6,-2.7 -6,-6 2.7,-6 6,-6v4l5,-5 -5,-5v4c-4.4,0 -8,3.6 -8,8zM10.8,16L10,16v-3.3L9,13v-0.7l1.8,-0.6h0.1L10.9,16zM15.1,14.2c0,0.3 0,0.6 -0.1,0.8l-0.3,0.6s-0.3,0.3 -0.5,0.3 -0.4,0.1 -0.6,0.1 -0.4,0 -0.6,-0.1 -0.3,-0.2 -0.5,-0.3 -0.2,-0.3 -0.3,-0.6 -0.1,-0.5 -0.1,-0.8v-0.7c0,-0.3 0,-0.6 0.1,-0.8l0.3,-0.6s0.3,-0.3 0.5,-0.3 0.4,-0.1 0.6,-0.1 0.4,0 0.6,0.1 0.3,0.2 0.5,0.3 0.2,0.3 0.3,0.6 0.1,0.5 0.1,0.8v0.7zM14.3,13.4v-0.5s-0.1,-0.2 -0.1,-0.3 -0.1,-0.1 -0.2,-0.2 -0.2,-0.1 -0.3,-0.1 -0.2,0 -0.3,0.1l-0.2,0.2s-0.1,0.2 -0.1,0.3v2s0.1,0.2 0.1,0.3 0.1,0.1 0.2,0.2 0.2,0.1 0.3,0.1 0.2,0 0.3,-0.1l0.2,-0.2s0.1,-0.2 0.1,-0.3v-1.5z"/>
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M6,19h4L10,5L6,5v14zM14,5v14h4L18,5h-4z"/>
|
||||
</vector>
|
||||
@@ -1,14 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M12,12m-3.2,0a3.2,3.2 0,1 1,6.4 0a3.2,3.2 0,1 1,-6.4 0"/>
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M9,2L7.17,4L4,4c-1.1,0 -2,0.9 -2,2v12c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2h-3.17L15,2L9,2zM12,17c-2.76,0 -5,-2.24 -5,-5s2.24,-5 5,-5 5,2.24 5,5 -2.24,5 -5,5z"/>
|
||||
</vector>
|
||||
@@ -1,11 +0,0 @@
|
||||
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:width="24dp"
|
||||
android:height="24dp"
|
||||
android:viewportWidth="24"
|
||||
android:viewportHeight="24"
|
||||
android:tint="#FFFFFF"
|
||||
android:alpha="0.8">
|
||||
<path
|
||||
android:fillColor="#FF000000"
|
||||
android:pathData="M8,5v14l11,-7z"/>
|
||||
</vector>
|
||||
Loaded 100 of 170 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user