Compare commits
34
Commits
commenting
..
0.15.2
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9aaa4db5f0 | ||
|
|
d4d58d7508 | ||
|
|
5eb35e3283 | ||
|
|
a42442b13b | ||
|
|
f317aa2174 | ||
|
|
82dc0255f1 | ||
|
|
244d54ed39 | ||
|
|
47f56950a5 | ||
|
|
fb2b798106 | ||
|
|
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
|
||||
+9
-20
@@ -1,5 +1,3 @@
|
||||
import com.google.gms.googleservices.GoogleServicesPlugin
|
||||
|
||||
apply plugin: 'com.android.application'
|
||||
|
||||
android {
|
||||
@@ -16,8 +14,8 @@ android {
|
||||
applicationId "io.lbry.browser"
|
||||
minSdkVersion 21
|
||||
targetSdkVersion 29
|
||||
versionCode 1509
|
||||
versionName "0.15.9"
|
||||
versionCode 1502
|
||||
versionName "0.15.2"
|
||||
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
@@ -54,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'
|
||||
@@ -64,24 +62,17 @@ 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.webkit:webkit:1.3.0-alpha02'
|
||||
implementation 'androidx.camera:camera-core:1.0.0-beta03'
|
||||
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.1'
|
||||
implementation 'com.google.firebase:firebase-analytics:17.4.0'
|
||||
implementation 'com.google.android.gms:play-services-base:17.2.1'
|
||||
implementation 'com.google.firebase:firebase-messaging:20.1.7'
|
||||
implementation 'com.google.firebase:firebase-messaging:20.1.6'
|
||||
|
||||
implementation 'com.google.code.gson:gson:2.8.6'
|
||||
implementation 'com.google.android.exoplayer:exoplayer-core:2.11.4'
|
||||
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'
|
||||
|
||||
@@ -90,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'
|
||||
@@ -100,9 +89,9 @@ 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'
|
||||
GoogleServicesPlugin.config.disableVersionCheck = true
|
||||
com.google.gms.googleservices.GoogleServicesPlugin.config.disableVersionCheck = true
|
||||
Binary file not shown.
BIN
Binary file not shown.
@@ -3,19 +3,17 @@
|
||||
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"
|
||||
|
||||
@@ -10,6 +10,7 @@ import android.os.Bundle;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
@@ -19,11 +20,10 @@ import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import io.lbry.lbrysdk.LbrynetService;
|
||||
|
||||
public class FirstRunActivity extends AppCompatActivity {
|
||||
|
||||
private BroadcastReceiver sdkReceiver;
|
||||
private BroadcastReceiver sdkReadyReceiver;
|
||||
private BroadcastReceiver authReceiver;
|
||||
|
||||
@Override
|
||||
@@ -45,26 +45,19 @@ public class FirstRunActivity extends AppCompatActivity {
|
||||
registerAuthReceiver();
|
||||
if (!Lbry.SDK_READY) {
|
||||
findViewById(R.id.welcome_wait_container).setVisibility(View.VISIBLE);
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(MainActivity.ACTION_SDK_READY);
|
||||
sdkReadyReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
// authenticate after we receive the sdk ready event
|
||||
authenticate();
|
||||
}
|
||||
};
|
||||
registerReceiver(sdkReadyReceiver, filter);
|
||||
} else {
|
||||
authenticate();
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(MainActivity.ACTION_SDK_READY);
|
||||
filter.addAction(LbrynetService.ACTION_STOP_SERVICE);
|
||||
sdkReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (MainActivity.ACTION_SDK_READY.equals(action)) {
|
||||
// authenticate after we receive the sdk ready event
|
||||
authenticate();
|
||||
} else if (LbrynetService.ACTION_STOP_SERVICE.equals(action)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(sdkReceiver, filter);
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
@@ -104,8 +97,7 @@ public class FirstRunActivity extends AppCompatActivity {
|
||||
}
|
||||
|
||||
private void handleAuthenticationFailed() {
|
||||
findViewById(R.id.welcome_progress_bar).setVisibility(View.GONE);
|
||||
((TextView) findViewById(R.id.welcome_wait_text)).setText(R.string.startup_failed);
|
||||
Toast.makeText(this, "Authentication failed.", Toast.LENGTH_LONG).show();
|
||||
}
|
||||
|
||||
private void authenticate() {
|
||||
@@ -129,7 +121,7 @@ public class FirstRunActivity extends AppCompatActivity {
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
Helper.unregisterReceiver(authReceiver, this);
|
||||
Helper.unregisterReceiver(sdkReceiver, this);
|
||||
Helper.unregisterReceiver(sdkReadyReceiver, this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
||||
File diff suppressed because it is too large.
Load diff
@@ -1,9 +1,6 @@
|
||||
package io.lbry.browser;
|
||||
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.IntentFilter;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
@@ -21,10 +18,8 @@ import io.lbry.browser.listener.SignInListener;
|
||||
import io.lbry.browser.listener.WalletSyncListener;
|
||||
import io.lbry.browser.model.lbryinc.User;
|
||||
import io.lbry.browser.tasks.lbryinc.FetchCurrentUserTask;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import io.lbry.lbrysdk.LbrynetService;
|
||||
|
||||
public class VerificationActivity extends FragmentActivity implements SignInListener, WalletSyncListener {
|
||||
|
||||
@@ -32,7 +27,6 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
public static final int VERIFICATION_FLOW_REWARDS = 2;
|
||||
public static final int VERIFICATION_FLOW_WALLET = 3;
|
||||
|
||||
private BroadcastReceiver sdkReceiver;
|
||||
private String email;
|
||||
private boolean signedIn;
|
||||
private int flow;
|
||||
@@ -60,19 +54,6 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
return;
|
||||
}
|
||||
|
||||
IntentFilter filter = new IntentFilter();
|
||||
filter.addAction(LbrynetService.ACTION_STOP_SERVICE);
|
||||
sdkReceiver = new BroadcastReceiver() {
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
String action = intent.getAction();
|
||||
if (LbrynetService.ACTION_STOP_SERVICE.equals(action)) {
|
||||
finish();
|
||||
}
|
||||
}
|
||||
};
|
||||
registerReceiver(sdkReceiver, filter);
|
||||
|
||||
setContentView(R.layout.activity_verification);
|
||||
ViewPager2 viewPager = findViewById(R.id.verification_pager);
|
||||
viewPager.setUserInputEnabled(false);
|
||||
@@ -177,7 +158,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
|
||||
showFetchUserError(error.getMessage());
|
||||
hideLoading();
|
||||
}
|
||||
});
|
||||
@@ -213,7 +194,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
}
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
|
||||
showFetchUserError(error.getMessage());
|
||||
hideLoading();
|
||||
}
|
||||
});
|
||||
@@ -250,7 +231,7 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
showFetchUserError(error != null ? error.getMessage() : getString(R.string.fetch_current_user_error));
|
||||
showFetchUserError(error.getMessage());
|
||||
hideLoading();
|
||||
}
|
||||
});
|
||||
@@ -258,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
|
||||
@@ -288,10 +268,4 @@ public class VerificationActivity extends FragmentActivity implements SignInList
|
||||
public void onWalletSyncFailed(Exception error) {
|
||||
findViewById(R.id.verification_close_button).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
Helper.unregisterReceiver(sdkReceiver, this);
|
||||
super.onDestroy();
|
||||
}
|
||||
}
|
||||
@@ -97,7 +97,7 @@ public class ChannelFilterListAdapter extends RecyclerView.Adapter<ChannelFilter
|
||||
vh.titleView.setText(Helper.isNullOrEmpty(claim.getTitle()) ? claim.getName() : claim.getTitle());
|
||||
String thumbnailUrl = claim.getThumbnailUrl();
|
||||
if (!Helper.isNullOrEmpty(thumbnailUrl) && context != null) {
|
||||
Glide.with(context.getApplicationContext()).asBitmap().load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
|
||||
Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
|
||||
}
|
||||
vh.alphaContainer.setVisibility(claim.isPlaceholder() || Helper.isNullOrEmpty(thumbnailUrl) ? View.VISIBLE : View.GONE);
|
||||
vh.thumbnailView.setVisibility(claim.isPlaceholder() || Helper.isNullOrEmpty(thumbnailUrl) ? View.GONE : View.VISIBLE);
|
||||
|
||||
@@ -8,6 +8,7 @@ import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -42,8 +43,6 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
private Map<String, Boolean> notFoundClaimIdMap;
|
||||
private Map<String, Boolean> notFoundClaimUrlMap;
|
||||
|
||||
@Setter
|
||||
private boolean hideFee;
|
||||
@Setter
|
||||
private boolean canEnterSelectionMode;
|
||||
private Context context;
|
||||
@@ -93,31 +92,10 @@ 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();
|
||||
@@ -297,13 +275,17 @@ 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 = Helper.getScaledValue(paddingTop, scale);
|
||||
int paddingBottomScaled = Helper.getScaledValue(paddingBottom, scale);
|
||||
int paddingTopScaled = getScaledValue(paddingTop);
|
||||
int paddingBottomScaled = getScaledValue(paddingBottom);
|
||||
vh.itemView.setPadding(vh.itemView.getPaddingLeft(), paddingTopScaled, vh.itemView.getPaddingRight(), paddingBottomScaled);
|
||||
|
||||
Claim original = items.get(position);
|
||||
@@ -323,22 +305,19 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
}
|
||||
|
||||
boolean isPending = item.getConfirmations() == 0;
|
||||
boolean isSelected = isClaimSelected(original);
|
||||
boolean isSelected = isClaimSelected(item);
|
||||
vh.itemView.setSelected(isSelected);
|
||||
vh.selectedOverlayView.setVisibility(isSelected ? View.VISIBLE : View.GONE);
|
||||
vh.itemView.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (isPending) {
|
||||
Snackbar snackbar = Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG);
|
||||
TextView snackbarText = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
|
||||
snackbarText.setMaxLines(5);
|
||||
snackbar.show();
|
||||
Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
if (inSelectionMode) {
|
||||
toggleSelectedClaim(original);
|
||||
toggleSelectedClaim(item);
|
||||
} else {
|
||||
if (listener != null) {
|
||||
listener.onClaimClicked(item);
|
||||
@@ -354,10 +333,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
}
|
||||
|
||||
if (isPending) {
|
||||
Snackbar snackbar = Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG);
|
||||
TextView snackbarText = snackbar.getView().findViewById(com.google.android.material.R.id.snackbar_text);
|
||||
snackbarText.setMaxLines(5);
|
||||
snackbar.show();
|
||||
Snackbar.make(vh.itemView, R.string.item_pending_blockchain, Snackbar.LENGTH_LONG).show();
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -367,7 +343,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
selectionModeListener.onEnterSelectionMode();
|
||||
}
|
||||
}
|
||||
toggleSelectedClaim(original);
|
||||
toggleSelectedClaim(item);
|
||||
return true;
|
||||
}
|
||||
});
|
||||
@@ -414,18 +390,14 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
long duration = item.getDuration();
|
||||
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
|
||||
Glide.with(context.getApplicationContext()).
|
||||
asBitmap().
|
||||
load(thumbnailUrl).
|
||||
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.feeContainer.setVisibility(cost.doubleValue() > 0 ? View.VISIBLE : View.GONE);
|
||||
vh.feeView.setText(cost.doubleValue() > 0 ? Helper.shortCurrencyFormat(cost.doubleValue()) : "Paid");
|
||||
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));
|
||||
@@ -438,10 +410,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
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()) {
|
||||
if (claimFile != null && !claimFile.isCompleted() && claimFile.getWrittenBytes() < claimFile.getTotalBytes()) {
|
||||
isDownloading = true;
|
||||
progress = claimFile.getTotalBytes() > 0 ?
|
||||
Double.valueOf(((double) claimFile.getWrittenBytes() / (double) claimFile.getTotalBytes()) * 100.0).intValue() : 0;
|
||||
@@ -450,7 +419,7 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
|
||||
Helper.formatBytes(claimFile.getTotalBytes(), false));
|
||||
}
|
||||
|
||||
Helper.setViewText(vh.fileSizeView, claimFile != null && !Helper.isNullOrEmpty(claimFile.getDownloadPath()) ? fileSizeString : null);
|
||||
Helper.setViewText(vh.fileSizeView, fileSizeString);
|
||||
Helper.setViewVisibility(vh.downloadProgressView, isDownloading ? View.VISIBLE : View.INVISIBLE);
|
||||
Helper.setViewProgress(vh.downloadProgressView, progress);
|
||||
Helper.setViewText(vh.deviceView, item.getDevice());
|
||||
|
||||
@@ -1,218 +0,0 @@
|
||||
package io.lbry.browser.adapter;
|
||||
|
||||
import android.content.Context;
|
||||
import android.text.format.DateUtils;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.ClaimCacheKey;
|
||||
import io.lbry.browser.model.Comment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import lombok.Setter;
|
||||
|
||||
public class CommentListAdapter extends RecyclerView.Adapter<CommentListAdapter.ViewHolder> {
|
||||
private List<Comment> items;
|
||||
private Context context;
|
||||
private boolean nested;
|
||||
private float scale;
|
||||
@Setter
|
||||
private ClaimListAdapter.ClaimListItemListener listener;
|
||||
@Setter
|
||||
private ReplyClickListener replyListener;
|
||||
|
||||
public CommentListAdapter(List<Comment> items, Context context) {
|
||||
this(items, context, false);
|
||||
}
|
||||
|
||||
public CommentListAdapter(List<Comment> items, Context context, boolean nested) {
|
||||
this.items = new ArrayList<>(items);
|
||||
this.context = context;
|
||||
this.nested = nested;
|
||||
if (context != null) {
|
||||
scale = context.getResources().getDisplayMetrics().density;
|
||||
}
|
||||
for (Comment item : this.items) {
|
||||
ClaimCacheKey key = new ClaimCacheKey();
|
||||
key.setClaimId(item.getChannelId());
|
||||
if (Lbry.claimCache.containsKey(key)) {
|
||||
item.setPoster(Lbry.claimCache.get(key));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void clearItems() {
|
||||
items.clear();
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return items != null ? items.size() : 0;
|
||||
}
|
||||
|
||||
public List<String> getClaimUrlsToResolve() {
|
||||
List<String> urls = new ArrayList<>();
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Comment item = items.get(i);
|
||||
if (item.getPoster() == null) {
|
||||
LbryUri url = LbryUri.tryParse(String.format("%s#%s", item.getChannelName(), item.getChannelId()));
|
||||
if (url != null && !urls.contains(url.toString())) {
|
||||
urls.add(url.toString());
|
||||
}
|
||||
}
|
||||
if (item.getReplies().size() > 0) {
|
||||
for (int j = 0; j < item.getReplies().size(); j++) {
|
||||
Comment reply = item.getReplies().get(j);
|
||||
if (reply.getPoster() == null) {
|
||||
LbryUri url = LbryUri.tryParse(String.format("%s#%s", reply.getChannelName(), reply.getChannelId()));
|
||||
if (url != null && !urls.contains(url.toString())) {
|
||||
urls.add(url.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return urls;
|
||||
}
|
||||
|
||||
public static class ViewHolder extends RecyclerView.ViewHolder {
|
||||
protected TextView channelName;
|
||||
protected TextView commentText;
|
||||
protected ImageView thumbnailView;
|
||||
protected View noThumbnailView;
|
||||
protected TextView alphaView;
|
||||
protected TextView commentTimeView;
|
||||
protected View replyLink;
|
||||
protected RecyclerView repliesList;
|
||||
|
||||
public ViewHolder (View v) {
|
||||
super(v);
|
||||
channelName = v.findViewById(R.id.comment_channel_name);
|
||||
commentTimeView = v.findViewById(R.id.comment_time);
|
||||
commentText = v.findViewById(R.id.comment_text);
|
||||
replyLink = v.findViewById(R.id.comment_reply_link);
|
||||
thumbnailView = v.findViewById(R.id.comment_thumbnail);
|
||||
noThumbnailView = v.findViewById(R.id.comment_no_thumbnail);
|
||||
alphaView = v.findViewById(R.id.comment_thumbnail_alpha);
|
||||
repliesList = v.findViewById(R.id.comment_replies);
|
||||
}
|
||||
}
|
||||
|
||||
public void insert(int index, Comment comment) {
|
||||
if (!items.contains(comment)) {
|
||||
items.add(index, comment);
|
||||
notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
public void addReply(Comment comment) {
|
||||
for (int i = 0; i < items.size(); i++) {
|
||||
Comment parent = items.get(i);
|
||||
if (parent.getId().equalsIgnoreCase(comment.getParentId())) {
|
||||
parent.addReply(comment);
|
||||
notifyDataSetChanged();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void updatePosterForComment(String channelId, Claim channel) {
|
||||
for (int i = 0 ; i < items.size(); i++) {
|
||||
Comment item = items.get(i);
|
||||
List<Comment> replies = item.getReplies();
|
||||
if (replies != null && replies.size() > 0) {
|
||||
for (int j = 0; j < replies.size(); j++) {
|
||||
Comment reply = item.getReplies().get(j);
|
||||
if (channelId.equalsIgnoreCase(reply.getChannelId())) {
|
||||
reply.setPoster(channel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (channelId.equalsIgnoreCase(item.getChannelId())) {
|
||||
item.setPoster(channel);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
||||
View v = LayoutInflater.from(context).inflate(R.layout.list_item_comment, parent, false);
|
||||
return new CommentListAdapter.ViewHolder(v);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(ViewHolder holder, int position) {
|
||||
Comment comment = items.get(position);
|
||||
holder.itemView.setPadding(
|
||||
nested ? Helper.getScaledValue(56, scale) : holder.itemView.getPaddingLeft(),
|
||||
holder.itemView.getPaddingTop(),
|
||||
nested ? 0 : holder.itemView.getPaddingRight(),
|
||||
holder.itemView.getPaddingBottom());
|
||||
|
||||
holder.channelName.setText(comment.getChannelName());
|
||||
holder.commentTimeView.setText(DateUtils.getRelativeTimeSpanString(
|
||||
(comment.getTimestamp() * 1000), System.currentTimeMillis(), 0, DateUtils.FORMAT_ABBREV_RELATIVE));
|
||||
holder.commentText.setText(comment.getText());
|
||||
holder.replyLink.setVisibility(!nested ? View.VISIBLE : View.GONE);
|
||||
|
||||
boolean hasThumbnail = comment.getPoster() != null && !Helper.isNullOrEmpty(comment.getPoster().getThumbnailUrl());
|
||||
holder.thumbnailView.setVisibility(hasThumbnail ? View.VISIBLE : View.INVISIBLE);
|
||||
holder.noThumbnailView.setVisibility(!hasThumbnail ? View.VISIBLE : View.INVISIBLE);
|
||||
int bgColor = Helper.generateRandomColorForValue(comment.getChannelId());
|
||||
Helper.setIconViewBackgroundColor(holder.noThumbnailView, bgColor, false, context);
|
||||
if (hasThumbnail) {
|
||||
Glide.with(context.getApplicationContext()).asBitmap().load(comment.getPoster().getThumbnailUrl()).
|
||||
apply(RequestOptions.circleCropTransform()).into(holder.thumbnailView);
|
||||
}
|
||||
holder.alphaView.setText(comment.getChannelName() != null ? comment.getChannelName().substring(1, 2).toUpperCase() : null);
|
||||
List<Comment> replies = comment.getReplies();
|
||||
boolean hasReplies = replies != null && replies.size() > 0;
|
||||
if (hasReplies) {
|
||||
holder.repliesList.setLayoutManager(new LinearLayoutManager(context));
|
||||
holder.repliesList.setAdapter(new CommentListAdapter(replies, context, true));
|
||||
} else {
|
||||
holder.repliesList.setAdapter(null);
|
||||
}
|
||||
|
||||
holder.channelName.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (listener != null && comment.getPoster() != null) {
|
||||
listener.onClaimClicked(comment.getPoster());
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
holder.replyLink.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (replyListener != null) {
|
||||
replyListener.onReplyClicked(comment);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public interface ReplyClickListener {
|
||||
void onReplyClicked(Comment comment);
|
||||
}
|
||||
}
|
||||
@@ -95,7 +95,6 @@ public class EditorsChoiceItemAdapter extends RecyclerView.Adapter<EditorsChoice
|
||||
vh.descriptionView.setText(item.getDescription());
|
||||
if (!Helper.isNullOrEmpty(item.getThumbnailUrl())) {
|
||||
Glide.with(context.getApplicationContext()).
|
||||
asBitmap().
|
||||
load(item.getThumbnailUrl()).
|
||||
centerCrop().
|
||||
placeholder(R.drawable.bg_thumbnail_placeholder).
|
||||
|
||||
@@ -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() != null && 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
|
||||
@@ -168,10 +168,6 @@ public class RewardListAdapter extends RecyclerView.Adapter<RewardListAdapter.Vi
|
||||
return;
|
||||
}
|
||||
|
||||
if (vh.inputCustomCode != null && !vh.inputCustomCode.hasFocus()) {
|
||||
vh.inputCustomCode.requestFocus();
|
||||
}
|
||||
|
||||
if (clickListener != null) {
|
||||
clickListener.onRewardClicked(reward, vh.loading);
|
||||
}
|
||||
@@ -201,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;
|
||||
}
|
||||
|
||||
|
||||
@@ -97,7 +97,7 @@ public class SuggestedChannelGridAdapter extends RecyclerView.Adapter<SuggestedC
|
||||
vh.alphaView.setText(claim.getName().substring(1, 2));
|
||||
if (!Helper.isNullOrEmpty(thumbnailUrl)) {
|
||||
vh.thumbnailView.setVisibility(View.VISIBLE);
|
||||
Glide.with(context.getApplicationContext()).asBitmap().load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
|
||||
Glide.with(context.getApplicationContext()).load(thumbnailUrl).apply(RequestOptions.circleCropTransform()).into(vh.thumbnailView);
|
||||
} else {
|
||||
vh.thumbnailView.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
@@ -72,9 +72,7 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionList
|
||||
vh.claimView.setText(item.getClaim());
|
||||
vh.feeView.setText(context.getString(R.string.tx_list_fee, TX_LIST_AMOUNT_FORMAT.format(item.getFee().doubleValue())));
|
||||
vh.txidLinkView.setText(item.getTxid().substring(0, 7));
|
||||
vh.dateView.setVisibility(item.getConfirmations() > 0 ? View.VISIBLE : View.GONE);
|
||||
vh.dateView.setText(item.getConfirmations() > 0 ? TX_LIST_DATE_FORMAT.format(item.getTxDate()) : null);
|
||||
vh.pendingView.setVisibility(item.getConfirmations() == 0 ? View.VISIBLE : View.GONE);
|
||||
vh.dateView.setText(TX_LIST_DATE_FORMAT.format(item.getTxDate()));
|
||||
|
||||
vh.infoFeeContainer.setVisibility(!Helper.isNullOrEmpty(item.getClaim()) || Math.abs(item.getFee().doubleValue()) > 0 ?
|
||||
View.VISIBLE : View.GONE);
|
||||
@@ -113,7 +111,6 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionList
|
||||
protected TextView feeView;
|
||||
protected TextView txidLinkView;
|
||||
protected TextView dateView;
|
||||
protected TextView pendingView;
|
||||
protected View infoFeeContainer;
|
||||
|
||||
public ViewHolder(View v) {
|
||||
@@ -124,7 +121,6 @@ public class TransactionListAdapter extends RecyclerView.Adapter<TransactionList
|
||||
feeView = v.findViewById(R.id.transaction_fee);
|
||||
txidLinkView = v.findViewById(R.id.transaction_id_link);
|
||||
dateView = v.findViewById(R.id.transaction_date);
|
||||
pendingView = v.findViewById(R.id.transaction_pending_text);
|
||||
infoFeeContainer = v.findViewById(R.id.transaction_info_fee_container);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ 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;
|
||||
|
||||
@@ -40,7 +40,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,10 +58,6 @@ 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";
|
||||
@@ -73,9 +68,9 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
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 (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||
"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_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 " +
|
||||
"SELECT url, claim_id, claim_name, cost, 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";
|
||||
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 = ?";
|
||||
@@ -87,8 +82,6 @@ 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;
|
||||
@@ -105,11 +98,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) {
|
||||
|
||||
@@ -153,7 +142,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(),
|
||||
@@ -178,7 +166,6 @@ public class DatabaseHelper extends SQLiteOpenHelper {
|
||||
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++));
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -86,7 +86,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) {
|
||||
@@ -231,11 +231,6 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
|
||||
}
|
||||
|
||||
Claim channel = (Claim) channelSpinner.getSelectedItem();
|
||||
if (channel == null) {
|
||||
showError(getString(R.string.please_select_repost_channel));
|
||||
return;
|
||||
}
|
||||
|
||||
StreamRepostTask task = new StreamRepostTask(name, bid, claim.getClaimId(), channel.getClaimId(), repostProgress, new ClaimResultHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
@@ -261,13 +256,10 @@ public class RepostClaimDialogFragment extends BottomSheetDialogFragment impleme
|
||||
}
|
||||
|
||||
private void showError(String message) {
|
||||
View view = getView();
|
||||
if (view != null && !Helper.isNullOrEmpty(message)) {
|
||||
Snackbar.make(view, message, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).
|
||||
setTextColor(Color.WHITE).
|
||||
show();
|
||||
}
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).
|
||||
setTextColor(Color.WHITE).
|
||||
show();
|
||||
}
|
||||
|
||||
private void startLoading() {
|
||||
|
||||
@@ -91,13 +91,11 @@ public class SendTipDialogFragment extends BottomSheetDialogFragment implements
|
||||
|
||||
TextView infoText = view.findViewById(R.id.tip_info);
|
||||
infoText.setMovementMethod(LinkMovementMethod.getInstance());
|
||||
if (claim != null) {
|
||||
infoText.setText(HtmlCompat.fromHtml(
|
||||
Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType()) ?
|
||||
getString(R.string.send_tip_info_channel, claim.getTitleOrName()) :
|
||||
getString(R.string.send_tip_info_content, claim.getTitleOrName()),
|
||||
HtmlCompat.FROM_HTML_MODE_LEGACY));
|
||||
}
|
||||
infoText.setText(HtmlCompat.fromHtml(
|
||||
Claim.TYPE_CHANNEL.equalsIgnoreCase(claim.getValueType()) ?
|
||||
getString(R.string.send_tip_info_channel, claim.getTitleOrName()) :
|
||||
getString(R.string.send_tip_info_content, claim.getTitleOrName()),
|
||||
HtmlCompat.FROM_HTML_MODE_LEGACY));
|
||||
|
||||
sendButton.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
|
||||
@@ -1,8 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface CameraPermissionListener {
|
||||
void onCameraPermissionGranted();
|
||||
void onCameraPermissionRefused();
|
||||
void onRecordAudioPermissionGranted();
|
||||
void onRecordAudioPermissionRefused();
|
||||
}
|
||||
@@ -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 PIPModeListener {
|
||||
void onEnterPIPMode();
|
||||
void onExitPIPMode();
|
||||
}
|
||||
@@ -1,6 +0,0 @@
|
||||
package io.lbry.browser.listener;
|
||||
|
||||
public interface ScreenOrientationListener {
|
||||
void onPortraitOrientationEntered();
|
||||
void onLandscapeOrientationEntered();
|
||||
}
|
||||
@@ -19,7 +19,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;
|
||||
|
||||
@@ -122,7 +121,7 @@ public class Claim {
|
||||
return new BigDecimal(String.valueOf(amount / usdRate));
|
||||
}
|
||||
|
||||
return new BigDecimal(String.valueOf(amount)); // deweys
|
||||
return new BigDecimal(String.valueOf(amount)).divide(new BigDecimal(100000000)); // deweys
|
||||
}
|
||||
|
||||
return new BigDecimal(0);
|
||||
@@ -157,17 +156,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) {
|
||||
@@ -279,8 +267,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);
|
||||
@@ -289,9 +276,6 @@ public class Claim {
|
||||
Claim signingChannel = new Claim();
|
||||
signingChannel.setClaimId(viewHistory.getPublisherClaimId());
|
||||
signingChannel.setName(viewHistory.getPublisherName());
|
||||
|
||||
LbryUri channelUrl = LbryUri.tryParse(String.format("%s#%s", signingChannel.getName(), signingChannel.getClaimId()));
|
||||
signingChannel.setPermanentUrl(channelUrl != null ? channelUrl.toString() : null);
|
||||
if (!Helper.isNullOrEmpty(viewHistory.getPublisherTitle())) {
|
||||
GenericMetadata channelValue = new GenericMetadata();
|
||||
channelValue.setTitle(viewHistory.getPublisherTitle());
|
||||
@@ -378,8 +362,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);
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
package io.lbry.browser.model;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.Array;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
public class Comment {
|
||||
public static final double COST = 0.25;
|
||||
public static final int MAX_LENGTH = 2000;
|
||||
|
||||
private Claim poster;
|
||||
private String claimId;
|
||||
private List<Comment> replies;
|
||||
private long timestamp;
|
||||
private String channelId;
|
||||
private String channelName, text, id, parentId;
|
||||
|
||||
public Comment(String channelId, String channelName, String text, String id, String parentId) {
|
||||
this.channelId = channelId;
|
||||
this.channelName = channelName;
|
||||
this.text = text;
|
||||
this.id = id;
|
||||
this.parentId = parentId;
|
||||
|
||||
this.replies = new ArrayList<>();
|
||||
}
|
||||
|
||||
public Comment() {
|
||||
replies = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void addReply(Comment reply) {
|
||||
if (replies == null) {
|
||||
replies = new ArrayList<>();
|
||||
}
|
||||
if (!replies.contains(reply)) {
|
||||
replies.add(reply);
|
||||
}
|
||||
}
|
||||
|
||||
public static Comment fromJSONObject(JSONObject jsonObject) {
|
||||
try {
|
||||
String parentId = null;
|
||||
if (jsonObject.has("parent_id")) {
|
||||
parentId = jsonObject.getString("parent_id");
|
||||
}
|
||||
|
||||
Comment comment = new Comment(
|
||||
Helper.getJSONString("channel_id", null, jsonObject),
|
||||
jsonObject.getString("channel_name"),
|
||||
jsonObject.getString("comment"),
|
||||
jsonObject.getString("comment_id"),
|
||||
parentId
|
||||
);
|
||||
comment.setClaimId(Helper.getJSONString("claim_id", null, jsonObject));
|
||||
comment.setTimestamp(Helper.getJSONLong("timestamp", 0, jsonObject));
|
||||
return comment;
|
||||
} catch (JSONException ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -5,9 +5,7 @@ import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.exceptions.LbryUriException;
|
||||
@@ -55,22 +53,13 @@ public class Transaction {
|
||||
|
||||
int descStringId = -1;
|
||||
TransactionInfo info = null;
|
||||
List<TransactionInfo> infos = new ArrayList<>();
|
||||
try {
|
||||
if (jsonObject.has("abandon_info")) {
|
||||
JSONArray array = jsonObject.getJSONArray("abandon_info");
|
||||
if (array.length() > 0) {
|
||||
if (array.length() == 1) {
|
||||
info = TransactionInfo.fromJSONObject(array.getJSONObject(0));
|
||||
descStringId = info.getBalanceDelta().doubleValue() == info.getAmount().doubleValue() ? R.string.unlock : R.string.abandon;
|
||||
transaction.setAbandonInfo(info);
|
||||
} else {
|
||||
// multiple abandon infos (txo_spend unlock tip)
|
||||
descStringId = R.string.unlock;
|
||||
for (int i = 0; i < array.length(); i++) {
|
||||
infos.add(TransactionInfo.fromJSONObject(array.getJSONObject(i)));
|
||||
}
|
||||
}
|
||||
info = TransactionInfo.fromJSONObject(array.getJSONObject(0));
|
||||
descStringId = R.string.abandon;
|
||||
transaction.setAbandonInfo(info);
|
||||
}
|
||||
}
|
||||
if (info == null && jsonObject.has("claim_info")) {
|
||||
@@ -105,18 +94,8 @@ public class Transaction {
|
||||
// pass
|
||||
}
|
||||
|
||||
|
||||
|
||||
if (transaction.getValue().doubleValue() == 0) {
|
||||
if (info != null && info.getBalanceDelta().doubleValue() != 0) {
|
||||
transaction.setValue(info.getBalanceDelta());
|
||||
} else if (infos.size() > 0) {
|
||||
BigDecimal total = new BigDecimal(0);
|
||||
for (TransactionInfo txInfo : infos) {
|
||||
total = total.add(txInfo.getAmount());
|
||||
}
|
||||
transaction.setValue(total);
|
||||
}
|
||||
if (transaction.getValue().doubleValue() == 0 && info != null && info.getBalanceDelta().doubleValue() != 0) {
|
||||
transaction.setValue(info.getBalanceDelta());
|
||||
}
|
||||
|
||||
if (descStringId == -1) {
|
||||
|
||||
@@ -14,7 +14,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,9 +40,7 @@ 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(claim.getActualCost(Lbryio.LBCUSDRate));
|
||||
}
|
||||
}
|
||||
if (history.getReleaseTime() == 0) {
|
||||
|
||||
@@ -1,10 +1,7 @@
|
||||
package io.lbry.browser.model;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import lombok.Data;
|
||||
|
||||
@Data
|
||||
@@ -24,18 +21,4 @@ public class WalletBalance {
|
||||
tips = new BigDecimal(0);
|
||||
total = new BigDecimal(0);
|
||||
}
|
||||
|
||||
public static WalletBalance fromJSONObject(JSONObject json) {
|
||||
WalletBalance balance = new WalletBalance();
|
||||
JSONObject reservedSubtotals = Helper.getJSONObject("reserved_subtotals", json);
|
||||
balance.setAvailable(new BigDecimal(Helper.getJSONString("available", "0", json)));
|
||||
balance.setReserved(new BigDecimal(Helper.getJSONString("reserved", "0", json)));
|
||||
balance.setTotal(new BigDecimal(Helper.getJSONString("total", "0", json)));
|
||||
if (reservedSubtotals != null) {
|
||||
balance.setClaims(new BigDecimal(Helper.getJSONString("claims", "0", reservedSubtotals)));
|
||||
balance.setSupports(new BigDecimal(Helper.getJSONString("supports", "0", reservedSubtotals)));
|
||||
balance.setTips(new BigDecimal(Helper.getJSONString("tips", "0", reservedSubtotals)));
|
||||
}
|
||||
return balance;
|
||||
}
|
||||
}
|
||||
+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;
|
||||
@@ -1,103 +0,0 @@
|
||||
package io.lbry.browser.tasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
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 java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.model.Comment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class CommentCreateWithTipTask extends AsyncTask<Void, Void, Comment> {
|
||||
private static final String STATUS_ENDPOINT = "https://comments.lbry.com";
|
||||
|
||||
private Comment comment;
|
||||
private BigDecimal amount;
|
||||
private View progressView;
|
||||
private CommentCreateWithTipHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public CommentCreateWithTipTask(Comment comment, BigDecimal amount, View progressView, CommentCreateWithTipHandler handler) {
|
||||
this.comment = comment;
|
||||
this.amount = amount;
|
||||
this.progressView = progressView;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
Helper.setViewVisibility(progressView, View.VISIBLE);
|
||||
}
|
||||
|
||||
public Comment doInBackground(Void... params) {
|
||||
Comment createdComment = null;
|
||||
try {
|
||||
// check comments status endpoint
|
||||
Request request = new Request.Builder().url(STATUS_ENDPOINT).build();
|
||||
OkHttpClient client = new OkHttpClient.Builder().
|
||||
writeTimeout(30, TimeUnit.SECONDS).
|
||||
readTimeout(30, TimeUnit.SECONDS).
|
||||
build();
|
||||
Response response = client.newCall(request).execute();
|
||||
JSONObject status = new JSONObject(response.body().string());
|
||||
String statusText = Helper.getJSONString("text", null, status);
|
||||
boolean isRunning = Helper.getJSONBoolean("is_running", false, status);
|
||||
if (!"ok".equalsIgnoreCase(statusText) || !isRunning) {
|
||||
throw new ApiCallException("The comment server is not available at this time. Please try again later.");
|
||||
}
|
||||
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("blocking", true);
|
||||
options.put("claim_id", comment.getClaimId());
|
||||
options.put("amount", new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).format(amount.doubleValue()));
|
||||
options.put("tip", true);
|
||||
Lbry.genericApiCall(Lbry.METHOD_SUPPORT_CREATE, options);
|
||||
|
||||
options = new HashMap<>();
|
||||
options.put("comment", comment.getText());
|
||||
options.put("claim_id", comment.getClaimId());
|
||||
options.put("channel_id", comment.getChannelId());
|
||||
options.put("channel_name", comment.getChannelName());
|
||||
if (!Helper.isNullOrEmpty(comment.getParentId())) {
|
||||
options.put("parent_id", comment.getParentId());
|
||||
}
|
||||
JSONObject jsonObject = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_COMMENT_CREATE, options);
|
||||
createdComment = Comment.fromJSONObject(jsonObject);
|
||||
} catch (ApiCallException | ClassCastException | IOException | JSONException ex) {
|
||||
error = ex;
|
||||
}
|
||||
|
||||
return createdComment;
|
||||
}
|
||||
|
||||
protected void onPostExecute(Comment createdComment) {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
if (createdComment != null) {
|
||||
handler.onSuccess(createdComment);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface CommentCreateWithTipHandler {
|
||||
void onSuccess(Comment createdComment);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +0,0 @@
|
||||
package io.lbry.browser.tasks;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.model.Comment;
|
||||
|
||||
public interface CommentListHandler {
|
||||
void onSuccess(List<Comment> comments, boolean hasReachedEnd);
|
||||
void onError(Exception error);
|
||||
}
|
||||
@@ -1,93 +0,0 @@
|
||||
package io.lbry.browser.tasks;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
import android.widget.ProgressBar;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.model.Comment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class CommentListTask extends AsyncTask<Void, Void, List<Comment>> {
|
||||
private final int page;
|
||||
private final int pageSize;
|
||||
private final String claim;
|
||||
private ProgressBar progressBar;
|
||||
private CommentListHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public CommentListTask(int page, int pageSize, String claim, ProgressBar progressBar, CommentListHandler handler) {
|
||||
this.page = page;
|
||||
this.pageSize = pageSize;
|
||||
this.claim = claim;
|
||||
this.progressBar = progressBar;
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
protected void onPreExecute() {
|
||||
Helper.setViewVisibility(progressBar, View.VISIBLE);
|
||||
}
|
||||
|
||||
protected List<Comment> doInBackground(Void... voids) {
|
||||
List<Comment> comments = null;
|
||||
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
|
||||
options.put("claim_id", claim);
|
||||
options.put("page", page);
|
||||
options.put("page_size", pageSize);
|
||||
options.put("include_replies", false);
|
||||
options.put("is_channel_signature_valid", true);
|
||||
options.put("visible", true);
|
||||
options.put("hidden", false);
|
||||
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_COMMENT_LIST, options);
|
||||
JSONArray items = result.getJSONArray("items");
|
||||
|
||||
List<Comment> children = new ArrayList<>();
|
||||
comments = new ArrayList<>();
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
Comment comment = Comment.fromJSONObject(items.getJSONObject(i));
|
||||
if (comment != null) {
|
||||
if (!Helper.isNullOrEmpty(comment.getParentId())) {
|
||||
children.add(comment);
|
||||
} else {
|
||||
comments.add(comment);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (Comment child : children) {
|
||||
for (Comment parent : comments) {
|
||||
if (parent.getId().equalsIgnoreCase(child.getParentId())) {
|
||||
parent.addReply(child);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
error = ex;
|
||||
}
|
||||
return comments;
|
||||
}
|
||||
|
||||
protected void onPostExecute(List<Comment> comments) {
|
||||
Helper.setViewVisibility(progressBar, View.GONE);
|
||||
if (handler != null) {
|
||||
if (comments != null) {
|
||||
handler.onSuccess(comments, comments.size() < pageSize);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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>> {
|
||||
@@ -84,13 +83,9 @@ public class MergeSubscriptionsTask extends AsyncTask<Void, Void, List<Subscript
|
||||
try {
|
||||
LbryUri uri = LbryUri.parse(local.getUrl());
|
||||
Map<String, String> options = new HashMap<>();
|
||||
String channelClaimId = uri.getChannelClaimId();
|
||||
String channelName = Helper.normalizeChannelName(local.getChannelName());
|
||||
if (!Helper.isNullOrEmpty(channelClaimId) && !Helper.isNullOrEmpty(channelName)) {
|
||||
options.put("claim_id", channelClaimId);
|
||||
options.put("channel_name", channelName);
|
||||
Lbryio.parseResponse(Lbryio.call("subscription", "new", options, context));
|
||||
}
|
||||
options.put("claim_id", uri.getChannelClaimId());
|
||||
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);
|
||||
@@ -113,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;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -45,15 +36,10 @@ public class UpdateSuggestedTagsTask extends AsyncTask<Void, Void, List<Tag>> {
|
||||
if (suggestedTagsAdapter != null && !clearPrevious) {
|
||||
tags = new ArrayList<>(suggestedTagsAdapter.getTags());
|
||||
}
|
||||
if (Lbry.knownTags.size() > 0) {
|
||||
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);
|
||||
}
|
||||
while (tags.size() < limit) {
|
||||
Tag randomTag = Lbry.knownTags.get(random.nextInt(Lbry.knownTags.size()));
|
||||
if (!Lbry.followedTags.contains(randomTag) && (addedTagsAdapter == null || !addedTagsAdapter.getTags().contains(randomTag))) {
|
||||
tags.add(randomTag);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
@@ -63,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);
|
||||
|
||||
@@ -42,7 +42,7 @@ public class AbandonChannelTask extends AsyncTask<Void, Void, Boolean> {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("claim_id", claimId);
|
||||
options.put("blocking", true);
|
||||
options.put("blocking", false);
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CHANNEL_ABANDON, options);
|
||||
successfulClaimIds.add(claimId);
|
||||
} catch (ApiCallException ex) {
|
||||
|
||||
@@ -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);
|
||||
@@ -62,8 +58,7 @@ public class ClaimListTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
if (claims != null) {
|
||||
// TODO: Add fix for handling invalid reposts in ClaimListAdapter
|
||||
handler.onSuccess(Helper.filterInvalidReposts(claims));
|
||||
handler.onSuccess(claims);
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
|
||||
@@ -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 Lbry.claimSearch(options, connectionString);
|
||||
return Helper.filterInvalidReposts(Lbry.claimSearch(options, connectionString));
|
||||
} catch (ApiCallException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
@@ -39,11 +40,15 @@ public class ClaimSearchTask extends AsyncTask<Void, Void, List<Claim>> {
|
||||
Helper.setViewVisibility(progressView, View.GONE);
|
||||
if (handler != null) {
|
||||
if (claims != null) {
|
||||
handler.onSuccess(Helper.filterInvalidReposts(claims), claims.size() < Helper.parseInt(options.get("page_size"), 0));
|
||||
handler.onSuccess(claims, claims.size() < Helper.parseInt(options.get("page_size"), 0));
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public interface ClaimSearchResultHandler {
|
||||
void onSuccess(List<Claim> claims, boolean hasReachedEnd);
|
||||
void onError(Exception error);
|
||||
}
|
||||
}
|
||||
@@ -1,114 +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());
|
||||
}
|
||||
|
||||
if (metadata.getReleaseTime() > 0) {
|
||||
options.put("release_time", metadata.getReleaseTime());
|
||||
} else if (claim.getTimestamp() > 0) {
|
||||
options.put("release_time", claim.getTimestamp());
|
||||
} else {
|
||||
options.put("release_time", Double.valueOf(Math.floor(System.currentTimeMillis() / 1000.0)).intValue());
|
||||
}
|
||||
|
||||
Claim claimResult = null;
|
||||
try {
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_PUBLISH, options);
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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);
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -4,12 +4,9 @@ import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.view.View;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -17,8 +14,6 @@ import io.lbry.browser.R;
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.exceptions.LbryioRequestException;
|
||||
import io.lbry.browser.exceptions.LbryioResponseException;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.lbryinc.Reward;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
@@ -27,15 +22,15 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||
|
||||
private Context context;
|
||||
private String type;
|
||||
private String rewardCode;
|
||||
private String claimCode;
|
||||
private View progressView;
|
||||
private double amountClaimed;
|
||||
private ClaimRewardHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public ClaimRewardTask(String type, String rewardCode, View progressView, Context context, ClaimRewardHandler handler) {
|
||||
public ClaimRewardTask(String type, String claimCode, View progressView, Context context, ClaimRewardHandler handler) {
|
||||
this.type = type;
|
||||
this.rewardCode = rewardCode;
|
||||
this.claimCode = claimCode;
|
||||
this.progressView = progressView;
|
||||
this.context = context;
|
||||
this.handler = handler;
|
||||
@@ -48,27 +43,15 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||
public String doInBackground(Void... params) {
|
||||
String message = null;
|
||||
try {
|
||||
String txid = null;
|
||||
if (Reward.TYPE_FIRST_CHANNEL.equalsIgnoreCase(type)) {
|
||||
// fetch a channel
|
||||
txid = fetchSingleClaimTxid(Claim.TYPE_CHANNEL);
|
||||
} else if (Reward.TYPE_FIRST_PUBLISH.equalsIgnoreCase(type)) {
|
||||
// fetch a publish
|
||||
txid = fetchSingleClaimTxid(Claim.TYPE_STREAM);
|
||||
}
|
||||
|
||||
// Get a new wallet address for the reward
|
||||
String address = (String) Lbry.genericApiCall(Lbry.METHOD_ADDRESS_UNUSED);
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("reward_type", type);
|
||||
options.put("wallet_address", address);
|
||||
if (!Helper.isNullOrEmpty(rewardCode)) {
|
||||
options.put("code", rewardCode);
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(txid)) {
|
||||
options.put("transaction_id", txid);
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(claimCode)) {
|
||||
options.put("claim_code", claimCode);
|
||||
|
||||
}
|
||||
JSONObject reward = (JSONObject) Lbryio.parseResponse(
|
||||
Lbryio.call("reward", "claim", options, Helper.METHOD_POST, null));
|
||||
amountClaimed = Helper.getJSONDouble("reward_amount", 0, reward);
|
||||
@@ -78,7 +61,7 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||
amountClaimed == 1 ? 1 : 2,
|
||||
new DecimalFormat(Helper.LBC_CURRENCY_FORMAT_PATTERN).format(amountClaimed)) : "";
|
||||
message = Helper.getJSONString("reward_notification", defaultMessage, reward);
|
||||
} catch (ApiCallException | JSONException | LbryioRequestException | LbryioResponseException ex) {
|
||||
} catch (ApiCallException | LbryioRequestException | LbryioResponseException ex) {
|
||||
error = ex;
|
||||
}
|
||||
|
||||
@@ -96,23 +79,6 @@ public class ClaimRewardTask extends AsyncTask<Void, Void, String> {
|
||||
}
|
||||
}
|
||||
|
||||
private String fetchSingleClaimTxid(String claimType) throws ApiCallException, JSONException {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("claim_type", claimType);
|
||||
options.put("page", 1);
|
||||
options.put("page_size", 1);
|
||||
options.put("resolve", true);
|
||||
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_CLAIM_LIST, options);
|
||||
JSONArray items = result.getJSONArray("items");
|
||||
if (items.length() > 0) {
|
||||
Claim claim = Claim.fromJSONObject(items.getJSONObject(0));
|
||||
return claim.getTxid();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public interface ClaimRewardHandler {
|
||||
void onSuccess(double amountClaimed, String message);
|
||||
void onError(Exception error);
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -1,137 +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 LIMIT 150", MediaStore.MediaColumns.DATE_MODIFIED));
|
||||
if (cursor != null) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
}
|
||||
}
|
||||
@@ -91,11 +91,7 @@ public class LoadSharedUserStateTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
if (tags != null) {
|
||||
if (db != null && tags.length() > 0) {
|
||||
try {
|
||||
DatabaseHelper.setAllTagsUnfollowed(db);
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
DatabaseHelper.setAllTagsUnfollowed(db);
|
||||
}
|
||||
|
||||
followedTags = new ArrayList<>();
|
||||
@@ -109,7 +105,7 @@ public class LoadSharedUserStateTask extends AsyncTask<Void, Void, Boolean> {
|
||||
if (db != null) {
|
||||
DatabaseHelper.createOrUpdateTag(tag, db);
|
||||
}
|
||||
} catch (SQLiteException | IllegalStateException ex) {
|
||||
} catch (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;
|
||||
@@ -40,9 +38,8 @@ public class SupportCreateTask extends AsyncTask<Void, Void, Boolean> {
|
||||
protected Boolean doInBackground(Void... params) {
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("blocking", true);
|
||||
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) {
|
||||
|
||||
@@ -1,77 +0,0 @@
|
||||
package io.lbry.browser.tasks.wallet;
|
||||
|
||||
import android.os.AsyncTask;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.exceptions.ApiCallException;
|
||||
import io.lbry.browser.model.WalletBalance;
|
||||
import io.lbry.browser.tasks.GenericTaskHandler;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
|
||||
public class UnlockTipsTask extends AsyncTask<Void, Void, Boolean> {
|
||||
|
||||
private GenericTaskHandler handler;
|
||||
private Exception error;
|
||||
|
||||
public UnlockTipsTask(GenericTaskHandler handler) {
|
||||
this.handler = handler;
|
||||
}
|
||||
|
||||
public Boolean doInBackground(Void... params) {
|
||||
|
||||
List<String> txids = new ArrayList<>();
|
||||
List<String> claimIds = new ArrayList<>();
|
||||
|
||||
try {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
options.put("type", "support");
|
||||
options.put("is_not_my_input", true);
|
||||
options.put("is_my_output", true);
|
||||
JSONObject result = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_TXO_LIST, options);
|
||||
if (result.has("items") && !result.isNull("items")) {
|
||||
JSONArray items = result.getJSONArray("items");
|
||||
for (int i = 0; i < items.length(); i++) {
|
||||
JSONObject item = items.getJSONObject(i);
|
||||
String txid = Helper.getJSONString("txid", null, item);
|
||||
String claimId = Helper.getJSONString("claim_id", null, item);
|
||||
if (!Helper.isNullOrEmpty(txid) && !Helper.isNullOrEmpty(claimId)) {
|
||||
txids.add(txid);
|
||||
claimIds.add(claimId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (txids.size() > 0 && txids.size() == claimIds.size()) {
|
||||
options = new HashMap<>();
|
||||
options.put("txid", txids);
|
||||
options.put("claim_id", claimIds);
|
||||
options.put("blocking", true);
|
||||
Lbry.genericApiCall(Lbry.METHOD_TXO_SPEND, options);
|
||||
}
|
||||
|
||||
return true;
|
||||
} catch (ApiCallException | ClassCastException | JSONException ex) {
|
||||
error = ex;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
protected void onPostExecute(Boolean result) {
|
||||
if (handler != null) {
|
||||
if (result) {
|
||||
handler.onSuccess();
|
||||
} else {
|
||||
handler.onError(error);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,10 +20,19 @@ public class WalletBalanceTask extends AsyncTask<Void, Void, WalletBalance> {
|
||||
}
|
||||
|
||||
protected WalletBalance doInBackground(Void... params) {
|
||||
WalletBalance balance;
|
||||
WalletBalance balance = new WalletBalance();
|
||||
try {
|
||||
JSONObject json = (JSONObject) Lbry.genericApiCall(Lbry.METHOD_WALLET_BALANCE);
|
||||
balance = WalletBalance.fromJSONObject(json);
|
||||
JSONObject reservedSubtotals = Helper.getJSONObject("reserved_subtotals", json);
|
||||
|
||||
balance.setAvailable(new BigDecimal(Helper.getJSONString("available", "0", json)));
|
||||
balance.setReserved(new BigDecimal(Helper.getJSONString("reserved", "0", json)));
|
||||
balance.setTotal(new BigDecimal(Helper.getJSONString("total", "0", json)));
|
||||
if (reservedSubtotals != null) {
|
||||
balance.setClaims(new BigDecimal(Helper.getJSONString("claims", "0", reservedSubtotals)));
|
||||
balance.setSupports(new BigDecimal(Helper.getJSONString("supports", "0", reservedSubtotals)));
|
||||
balance.setTips(new BigDecimal(Helper.getJSONString("tips", "0", reservedSubtotals)));
|
||||
}
|
||||
} catch (ApiCallException | ClassCastException ex) {
|
||||
error = ex;
|
||||
return null;
|
||||
|
||||
@@ -1,36 +1,13 @@
|
||||
package io.lbry.browser.ui;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.BuildConfig;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.InlineChannelSpinnerAdapter;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.WalletBalance;
|
||||
import io.lbry.browser.tasks.claim.ChannelCreateUpdateTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimResultHandler;
|
||||
import io.lbry.browser.tasks.lbryinc.LogPublishTask;
|
||||
import io.lbry.browser.ui.wallet.RewardsFragment;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.ui.following.FileViewFragment;
|
||||
import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@@ -38,36 +15,6 @@ public class BaseFragment extends Fragment {
|
||||
@Getter
|
||||
@Setter
|
||||
private Map<String, Object> params;
|
||||
private boolean rewardDriverClickListenerSet;
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
rewardDriverClickListenerSet = false;
|
||||
super.onStop();
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
@@ -76,7 +23,7 @@ public class BaseFragment extends Fragment {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.setSelectedMenuItemForFragment(this);
|
||||
|
||||
if (shouldHideGlobalPlayer()) {
|
||||
if (this instanceof FileViewFragment) {
|
||||
activity.hideGlobalNowPlaying();
|
||||
} else {
|
||||
activity.checkNowPlaying();
|
||||
@@ -84,159 +31,4 @@ public class BaseFragment extends Fragment {
|
||||
}
|
||||
}
|
||||
|
||||
public void checkRewardsDriverCard(String rewardDriverText, double minCost) {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
View rewardDriverCard = root.findViewById(R.id.reward_driver_card);
|
||||
if (rewardDriverCard != null) {
|
||||
if (!rewardDriverClickListenerSet) {
|
||||
rewardDriverCard.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openRewards();
|
||||
}
|
||||
}
|
||||
});
|
||||
rewardDriverClickListenerSet = true;
|
||||
}
|
||||
|
||||
// only apply to fragments that have the card present
|
||||
((TextView) rewardDriverCard.findViewById(R.id.reward_driver_text)).setText(rewardDriverText);
|
||||
boolean showRewardsDriver = Lbry.walletBalance == null ||
|
||||
minCost == 0 && Lbry.walletBalance.getAvailable().doubleValue() == 0 |
|
||||
Lbry.walletBalance.getAvailable().doubleValue() < Math.max(minCost, Helper.MIN_DEPOSIT);
|
||||
rewardDriverCard.setVisibility(showRewardsDriver ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void showError(String message) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void setupInlineChannelCreator(
|
||||
View container,
|
||||
TextInputEditText inputChannelName,
|
||||
TextInputEditText inputDeposit,
|
||||
View inlineBalanceView,
|
||||
TextView inlineBalanceValue,
|
||||
View linkCancel,
|
||||
MaterialButton buttonCreate,
|
||||
View progressView,
|
||||
AppCompatSpinner channelSpinner,
|
||||
InlineChannelSpinnerAdapter channelSpinnerAdapter) {
|
||||
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean hasFocus) {
|
||||
Helper.setViewVisibility(inlineBalanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
linkCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Helper.setViewText(inputChannelName, null);
|
||||
Helper.setViewText(inputDeposit, null);
|
||||
Helper.setViewVisibility(container, View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// validate deposit and channel name
|
||||
String channelNameString = Helper.normalizeChannelName(Helper.getValue(inputChannelName.getText()));
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
|
||||
double depositAmount = 0;
|
||||
try {
|
||||
depositAmount = Double.valueOf(depositString);
|
||||
} catch (NumberFormatException ex) {
|
||||
// pass
|
||||
showError(getString(R.string.please_enter_valid_deposit));
|
||||
return;
|
||||
}
|
||||
if (depositAmount == 0) {
|
||||
String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
|
||||
showError(error);
|
||||
return;
|
||||
}
|
||||
if (Lbry.walletBalance == null || Lbry.walletBalance.getAvailable().doubleValue() < depositAmount) {
|
||||
showError(getString(R.string.deposit_more_than_balance));
|
||||
return;
|
||||
}
|
||||
|
||||
ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(
|
||||
claimToSave, new BigDecimal(depositString), false, progressView, new ClaimResultHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
Helper.setViewEnabled(inputChannelName, false);
|
||||
Helper.setViewEnabled(inputDeposit, false);
|
||||
Helper.setViewEnabled(buttonCreate, false);
|
||||
Helper.setViewEnabled(linkCancel, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Claim claimResult) {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
LogPublishTask logPublishTask = new LogPublishTask(claimResult);
|
||||
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
|
||||
if (channelSpinnerAdapter != null) {
|
||||
channelSpinnerAdapter.add(claimResult);
|
||||
}
|
||||
if (channelSpinner != null && channelSpinnerAdapter != null) {
|
||||
channelSpinner.setSelection(channelSpinnerAdapter.getCount() - 1);
|
||||
}
|
||||
|
||||
Helper.setViewEnabled(inputChannelName, true);
|
||||
Helper.setViewEnabled(inputDeposit, true);
|
||||
Helper.setViewEnabled(buttonCreate, true);
|
||||
Helper.setViewEnabled(linkCancel, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Helper.setViewEnabled(inputChannelName, true);
|
||||
Helper.setViewEnabled(inputDeposit, true);
|
||||
Helper.setViewEnabled(buttonCreate, true);
|
||||
Helper.setViewEnabled(linkCancel, true);
|
||||
showError(error.getMessage());
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
|
||||
Helper.setViewText(inlineBalanceValue, Helper.shortCurrencyFormat(Lbry.walletBalance.getAvailable().doubleValue()));
|
||||
}
|
||||
}
|
||||
+5
-4
@@ -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;
|
||||
@@ -14,6 +15,7 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.exoplayer2.offline.Download;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
|
||||
import org.json.JSONException;
|
||||
@@ -36,7 +38,6 @@ 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;
|
||||
@@ -407,7 +408,7 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
||||
}
|
||||
|
||||
return Lbry.buildClaimSearchOptions(
|
||||
(List) null,
|
||||
null,
|
||||
(currentContentScope == ContentScopeDialogFragment.ITEM_EVERYONE) ? null : tags,
|
||||
canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS),
|
||||
null,
|
||||
@@ -442,7 +443,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) {
|
||||
@@ -1,705 +0,0 @@
|
||||
package io.lbry.browser.ui.channel;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.text.Editable;
|
||||
import android.text.TextWatcher;
|
||||
import android.text.method.LinkMovementMethod;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.core.text.HtmlCompat;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.bumptech.glide.Glide;
|
||||
import com.bumptech.glide.request.RequestOptions;
|
||||
import com.google.android.material.button.MaterialButton;
|
||||
import com.google.android.material.snackbar.Snackbar;
|
||||
import com.google.android.material.textfield.TextInputEditText;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.text.DecimalFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import io.lbry.browser.BuildConfig;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.adapter.ClaimListAdapter;
|
||||
import io.lbry.browser.adapter.CommentListAdapter;
|
||||
import io.lbry.browser.adapter.InlineChannelSpinnerAdapter;
|
||||
import io.lbry.browser.listener.SdkStatusListener;
|
||||
import io.lbry.browser.listener.WalletBalanceListener;
|
||||
import io.lbry.browser.model.Claim;
|
||||
import io.lbry.browser.model.Comment;
|
||||
import io.lbry.browser.model.WalletBalance;
|
||||
import io.lbry.browser.tasks.CommentCreateWithTipTask;
|
||||
import io.lbry.browser.tasks.CommentListHandler;
|
||||
import io.lbry.browser.tasks.CommentListTask;
|
||||
import io.lbry.browser.tasks.claim.ChannelCreateUpdateTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimListResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ClaimListTask;
|
||||
import io.lbry.browser.tasks.claim.ClaimResultHandler;
|
||||
import io.lbry.browser.tasks.claim.ResolveTask;
|
||||
import io.lbry.browser.tasks.lbryinc.LogPublishTask;
|
||||
import io.lbry.browser.utils.Helper;
|
||||
import io.lbry.browser.utils.Lbry;
|
||||
import io.lbry.browser.utils.LbryAnalytics;
|
||||
import io.lbry.browser.utils.LbryUri;
|
||||
import io.lbry.browser.utils.Lbryio;
|
||||
import lombok.Setter;
|
||||
|
||||
public class ChannelCommentsFragment extends Fragment implements SdkStatusListener, WalletBalanceListener {
|
||||
|
||||
@Setter
|
||||
private Claim claim;
|
||||
private CommentListAdapter commentListAdapter;
|
||||
|
||||
private Comment replyToComment;
|
||||
private View containerReplyToComment;
|
||||
private TextView textReplyingTo;
|
||||
private TextView textReplyToBody;
|
||||
private View buttonClearReplyToComment;
|
||||
|
||||
private boolean postingComment;
|
||||
private boolean fetchingChannels;
|
||||
private View progressLoadingChannels;
|
||||
private View progressPostComment;
|
||||
private InlineChannelSpinnerAdapter commentChannelSpinnerAdapter;
|
||||
private AppCompatSpinner commentChannelSpinner;
|
||||
private TextInputEditText inputComment;
|
||||
private TextView textCommentLimit;
|
||||
private MaterialButton buttonPostComment;
|
||||
private ImageView commentPostAsThumbnail;
|
||||
private View commentPostAsNoThumbnail;
|
||||
private TextView commentPostAsAlpha;
|
||||
|
||||
private View inlineChannelCreator;
|
||||
private TextInputEditText inlineChannelCreatorInputName;
|
||||
private TextInputEditText inlineChannelCreatorInputDeposit;
|
||||
private View inlineChannelCreatorInlineBalance;
|
||||
private TextView inlineChannelCreatorInlineBalanceValue;
|
||||
private View inlineChannelCreatorCancelLink;
|
||||
private View inlineChannelCreatorProgress;
|
||||
private MaterialButton inlineChannelCreatorCreateButton;
|
||||
|
||||
public View onCreateView(@NonNull LayoutInflater inflater,
|
||||
ViewGroup container, Bundle savedInstanceState) {
|
||||
View root = inflater.inflate(R.layout.fragment_channel_comments, container, false);
|
||||
|
||||
containerReplyToComment = root.findViewById(R.id.comment_form_reply_to_container);
|
||||
textReplyingTo = root.findViewById(R.id.comment_form_replying_to_text);
|
||||
textReplyToBody = root.findViewById(R.id.comment_form_reply_to_body);
|
||||
buttonClearReplyToComment = root.findViewById(R.id.comment_form_clear_reply_to);
|
||||
|
||||
commentChannelSpinner = root.findViewById(R.id.comment_form_channel_spinner);
|
||||
progressLoadingChannels = root.findViewById(R.id.comment_form_channels_loading);
|
||||
progressPostComment = root.findViewById(R.id.comment_form_post_progress);
|
||||
inputComment = root.findViewById(R.id.comment_form_body);
|
||||
textCommentLimit = root.findViewById(R.id.comment_form_text_limit);
|
||||
buttonPostComment = root.findViewById(R.id.comment_form_post);
|
||||
commentPostAsThumbnail = root.findViewById(R.id.comment_form_thumbnail);
|
||||
commentPostAsNoThumbnail = root.findViewById(R.id.comment_form_no_thumbnail);
|
||||
commentPostAsAlpha = root.findViewById(R.id.comment_form_thumbnail_alpha);
|
||||
|
||||
inlineChannelCreator = root.findViewById(R.id.container_inline_channel_form_create);
|
||||
inlineChannelCreatorInputName = root.findViewById(R.id.inline_channel_form_input_name);
|
||||
inlineChannelCreatorInputDeposit = root.findViewById(R.id.inline_channel_form_input_deposit);
|
||||
inlineChannelCreatorInlineBalance = root.findViewById(R.id.inline_channel_form_inline_balance_container);
|
||||
inlineChannelCreatorInlineBalanceValue = root.findViewById(R.id.inline_channel_form_inline_balance_value);
|
||||
inlineChannelCreatorProgress = root.findViewById(R.id.inline_channel_form_create_progress);
|
||||
inlineChannelCreatorCancelLink = root.findViewById(R.id.inline_channel_form_cancel_link);
|
||||
inlineChannelCreatorCreateButton = root.findViewById(R.id.inline_channel_form_create_button);
|
||||
|
||||
RecyclerView commentList = root.findViewById(R.id.channel_comments_list);
|
||||
commentList.setLayoutManager(new LinearLayoutManager(getContext()));
|
||||
|
||||
initCommentForm(root);
|
||||
setupInlineChannelCreator(
|
||||
inlineChannelCreator,
|
||||
inlineChannelCreatorInputName,
|
||||
inlineChannelCreatorInputDeposit,
|
||||
inlineChannelCreatorInlineBalance,
|
||||
inlineChannelCreatorInlineBalanceValue,
|
||||
inlineChannelCreatorCancelLink,
|
||||
inlineChannelCreatorCreateButton,
|
||||
inlineChannelCreatorProgress,
|
||||
commentChannelSpinner,
|
||||
commentChannelSpinnerAdapter
|
||||
);
|
||||
|
||||
return root;
|
||||
}
|
||||
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
Context context = getContext();
|
||||
if (!Lbry.SDK_READY) {
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).addSdkStatusListener(this);
|
||||
}
|
||||
} else {
|
||||
onSdkReady();
|
||||
}
|
||||
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).addWalletBalanceListener(this);
|
||||
}
|
||||
checkCommentSdkInitializing();
|
||||
}
|
||||
|
||||
public void onStop() {
|
||||
super.onStop();
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.removeSdkStatusListener(this);
|
||||
activity.removeWalletBalanceListener(this);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkCommentSdkInitializing() {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
TextView commentsSDKInitializing = root.findViewById(R.id.channel_comments_sdk_initializing);
|
||||
Helper.setViewVisibility(commentsSDKInitializing, Lbry.SDK_READY ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSdkReady() {
|
||||
fetchChannels();
|
||||
checkAndLoadComments();
|
||||
}
|
||||
|
||||
private void checkAndLoadComments() {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
checkCommentSdkInitializing();
|
||||
RecyclerView commentsList = root.findViewById(R.id.channel_comments_list);
|
||||
if (commentsList == null || commentsList.getAdapter() == null || commentsList.getAdapter().getItemCount() == 0) {
|
||||
loadComments();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void loadComments() {
|
||||
View root = getView();
|
||||
ProgressBar relatedLoading = root.findViewById(R.id.channel_comments_progress);
|
||||
if (claim != null && root != null) {
|
||||
CommentListTask task = new CommentListTask(1, 500, claim.getClaimId(), relatedLoading, new CommentListHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Comment> comments, boolean hasReachedEnd) {
|
||||
Context ctx = getContext();
|
||||
View root = getView();
|
||||
if (ctx != null && root != null) {
|
||||
commentListAdapter = new CommentListAdapter(comments, ctx);
|
||||
commentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
if (!Helper.isNullOrEmpty(claim.getName()) &&
|
||||
claim.getName().startsWith("@") &&
|
||||
ctx instanceof MainActivity) {
|
||||
((MainActivity) ctx).openChannelClaim(claim);
|
||||
}
|
||||
}
|
||||
});
|
||||
commentListAdapter.setReplyListener(new CommentListAdapter.ReplyClickListener() {
|
||||
@Override
|
||||
public void onReplyClicked(Comment comment) {
|
||||
setReplyToComment(comment);
|
||||
}
|
||||
});
|
||||
|
||||
RecyclerView relatedContentList = root.findViewById(R.id.channel_comments_list);
|
||||
relatedContentList.setAdapter(commentListAdapter);
|
||||
commentListAdapter.notifyDataSetChanged();
|
||||
|
||||
checkNoComments();
|
||||
resolveCommentPosters();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
// pass
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
|
||||
private void resolveCommentPosters() {
|
||||
if (commentListAdapter != null) {
|
||||
List<String> urlsToResolve = new ArrayList<>(commentListAdapter.getClaimUrlsToResolve());
|
||||
if (urlsToResolve.size() > 0) {
|
||||
ResolveTask task = new ResolveTask(urlsToResolve, Lbry.SDK_CONNECTION_STRING, null, new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
if (commentListAdapter != null) {
|
||||
for (Claim claim : claims) {
|
||||
if (claim.getClaimId() != null) {
|
||||
commentListAdapter.updatePosterForComment(claim.getClaimId(), claim);
|
||||
}
|
||||
}
|
||||
commentListAdapter.notifyDataSetChanged();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
// pass
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletBalanceUpdated(WalletBalance walletBalance) {
|
||||
if (walletBalance != null && inlineChannelCreatorInlineBalanceValue != null) {
|
||||
inlineChannelCreatorInlineBalanceValue.setText(Helper.shortCurrencyFormat(walletBalance.getAvailable().doubleValue()));
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchChannels() {
|
||||
if (Lbry.ownChannels != null && Lbry.ownChannels.size() > 0) {
|
||||
updateChannelList(Lbry.ownChannels);
|
||||
return;
|
||||
}
|
||||
|
||||
fetchingChannels = true;
|
||||
disableChannelSpinner();
|
||||
ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, progressLoadingChannels, new ClaimListResultHandler() {
|
||||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
Lbry.ownChannels = new ArrayList<>(claims);
|
||||
updateChannelList(Lbry.ownChannels);
|
||||
enableChannelSpinner();
|
||||
fetchingChannels = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
enableChannelSpinner();
|
||||
fetchingChannels = false;
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
private void disableChannelSpinner() {
|
||||
Helper.setViewEnabled(commentChannelSpinner, false);
|
||||
hideInlineChannelCreator();
|
||||
}
|
||||
private void enableChannelSpinner() {
|
||||
Helper.setViewEnabled(commentChannelSpinner, true);
|
||||
if (commentChannelSpinner != null) {
|
||||
Claim selectedClaim = (Claim) commentChannelSpinner.getSelectedItem();
|
||||
if (selectedClaim != null) {
|
||||
if (selectedClaim.isPlaceholder()) {
|
||||
showInlineChannelCreator();
|
||||
} else {
|
||||
hideInlineChannelCreator();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
private void showInlineChannelCreator() {
|
||||
Helper.setViewVisibility(inlineChannelCreator, View.VISIBLE);
|
||||
}
|
||||
private void hideInlineChannelCreator() {
|
||||
Helper.setViewVisibility(inlineChannelCreator, View.GONE);
|
||||
}
|
||||
|
||||
private void updateChannelList(List<Claim> channels) {
|
||||
if (commentChannelSpinnerAdapter == null) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
commentChannelSpinnerAdapter = new InlineChannelSpinnerAdapter(context, R.layout.spinner_item_channel, new ArrayList<>(channels));
|
||||
commentChannelSpinnerAdapter.addPlaceholder(false);
|
||||
commentChannelSpinnerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
} else {
|
||||
commentChannelSpinnerAdapter.clear();
|
||||
commentChannelSpinnerAdapter.addAll(channels);
|
||||
commentChannelSpinnerAdapter.addPlaceholder(false);
|
||||
commentChannelSpinnerAdapter.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
if (commentChannelSpinner != null) {
|
||||
commentChannelSpinner.setAdapter(commentChannelSpinnerAdapter);
|
||||
}
|
||||
|
||||
if (commentChannelSpinnerAdapter != null && commentChannelSpinner != null) {
|
||||
if (commentChannelSpinnerAdapter.getCount() > 1) {
|
||||
commentChannelSpinner.setSelection(1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void initCommentForm(View root) {
|
||||
double amount = Comment.COST / Lbryio.LBCUSDRate;
|
||||
String buttonText = getResources().getQuantityString(R.plurals.post_for_credits, amount == 1 ? 1 : 2, Helper.LBC_CURRENCY_FORMAT.format(amount));
|
||||
buttonPostComment.setText(buttonText);
|
||||
textCommentLimit.setText(String.format("%d / %d", Helper.getValue(inputComment.getText()).length(), Comment.MAX_LENGTH));
|
||||
|
||||
buttonClearReplyToComment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
clearReplyToComment();
|
||||
}
|
||||
});
|
||||
|
||||
buttonPostComment.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (!Lbry.SDK_READY) {
|
||||
Snackbar.make(root.findViewById(R.id.channel_comments_area), R.string.sdk_initializing_functionality, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
validateAndCheckPostComment(amount);
|
||||
}
|
||||
});
|
||||
|
||||
inputComment.addTextChangedListener(new TextWatcher() {
|
||||
@Override
|
||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
||||
int len = charSequence.length();
|
||||
textCommentLimit.setText(String.format("%d / %d", len, Comment.MAX_LENGTH));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterTextChanged(Editable editable) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
commentChannelSpinner.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
|
||||
@Override
|
||||
public void onItemSelected(AdapterView<?> adapterView, View view, int position, long l) {
|
||||
Object item = adapterView.getItemAtPosition(position);
|
||||
if (item instanceof Claim) {
|
||||
Claim claim = (Claim) item;
|
||||
if (claim.isPlaceholder()) {
|
||||
if (!fetchingChannels) {
|
||||
showInlineChannelCreator();
|
||||
}
|
||||
} else {
|
||||
hideInlineChannelCreator();
|
||||
updatePostAsChannel(claim);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNothingSelected(AdapterView<?> adapterView) {
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void validateAndCheckPostComment(double amount) {
|
||||
String comment = Helper.getValue(inputComment.getText());
|
||||
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
|
||||
|
||||
if (Helper.isNullOrEmpty(comment)) {
|
||||
showError(getString(R.string.please_enter_comment));
|
||||
return;
|
||||
}
|
||||
if (channel == null || Helper.isNullOrEmpty(channel.getClaimId())) {
|
||||
showError(getString(R.string.please_select_channel));
|
||||
return;
|
||||
}
|
||||
if (Lbry.walletBalance == null || amount > Lbry.walletBalance.getAvailable().doubleValue()) {
|
||||
showError(getString(R.string.insufficient_balance));
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
String confirmText = getResources().getQuantityString(
|
||||
R.plurals.confirm_post_comment,
|
||||
amount == 1 ? 1 : 2,
|
||||
Helper.LBC_CURRENCY_FORMAT.format(amount),
|
||||
claim.getTitleOrName());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context).
|
||||
setTitle(R.string.post_comment).
|
||||
setMessage(confirmText)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
postComment(amount);
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
|
||||
private void updatePostAsChannel(Claim channel) {
|
||||
boolean hasThumbnail = !Helper.isNullOrEmpty(channel.getThumbnailUrl());
|
||||
Helper.setViewVisibility(commentPostAsThumbnail, hasThumbnail ? View.VISIBLE : View.INVISIBLE);
|
||||
Helper.setViewVisibility(commentPostAsNoThumbnail, !hasThumbnail ? View.VISIBLE : View.INVISIBLE);
|
||||
Helper.setViewText(commentPostAsAlpha, channel.getName() != null ? channel.getName().substring(1, 2).toUpperCase() : null);
|
||||
|
||||
Context context = getContext();
|
||||
int bgColor = Helper.generateRandomColorForValue(channel.getClaimId());
|
||||
Helper.setIconViewBackgroundColor(commentPostAsNoThumbnail, bgColor, false, context);
|
||||
|
||||
if (hasThumbnail && context != null) {
|
||||
Glide.with(context.getApplicationContext()).
|
||||
asBitmap().
|
||||
load(channel.getThumbnailUrl()).
|
||||
apply(RequestOptions.circleCropTransform()).
|
||||
into(commentPostAsThumbnail);
|
||||
}
|
||||
}
|
||||
|
||||
private void beforePostComment() {
|
||||
postingComment = true;
|
||||
Helper.setViewEnabled(commentChannelSpinner, false);
|
||||
Helper.setViewEnabled(inputComment, false);
|
||||
Helper.setViewEnabled(buttonClearReplyToComment, false);
|
||||
Helper.setViewEnabled(buttonPostComment, false);
|
||||
}
|
||||
|
||||
private void afterPostComment() {
|
||||
Helper.setViewEnabled(commentChannelSpinner, true);
|
||||
Helper.setViewEnabled(inputComment, true);
|
||||
Helper.setViewEnabled(buttonClearReplyToComment, true);
|
||||
Helper.setViewEnabled(buttonPostComment, true);
|
||||
postingComment = false;
|
||||
}
|
||||
|
||||
private Comment buildPostComment() {
|
||||
Comment comment = new Comment();
|
||||
Claim channel = (Claim) commentChannelSpinner.getSelectedItem();
|
||||
comment.setClaimId(claim.getClaimId());
|
||||
comment.setChannelId(channel.getClaimId());
|
||||
comment.setChannelName(channel.getName());
|
||||
comment.setText(Helper.getValue(inputComment.getText()));
|
||||
comment.setPoster(channel);
|
||||
if (replyToComment != null) {
|
||||
comment.setParentId(replyToComment.getId());
|
||||
}
|
||||
|
||||
return comment;
|
||||
}
|
||||
|
||||
private void setReplyToComment(Comment comment) {
|
||||
replyToComment = comment;
|
||||
Helper.setViewText(textReplyingTo, getString(R.string.replying_to, comment.getChannelName()));
|
||||
Helper.setViewText(textReplyToBody, comment.getText());
|
||||
Helper.setViewVisibility(containerReplyToComment, View.VISIBLE);
|
||||
|
||||
inputComment.requestFocus();
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
imm.showSoftInput(inputComment, InputMethodManager.SHOW_FORCED);
|
||||
}
|
||||
}
|
||||
|
||||
private void clearReplyToComment() {
|
||||
Helper.setViewText(textReplyingTo, null);
|
||||
Helper.setViewText(textReplyToBody, null);
|
||||
Helper.setViewVisibility(containerReplyToComment, View.GONE);
|
||||
replyToComment = null;
|
||||
}
|
||||
|
||||
private void postComment(double tipAmount) {
|
||||
if (postingComment) {
|
||||
return;
|
||||
}
|
||||
|
||||
Comment comment = buildPostComment();
|
||||
// only use 2 decimal places
|
||||
BigDecimal amount = new BigDecimal(new DecimalFormat(Helper.PLAIN_CURRENCY_FORMAT_PATTERN).format(tipAmount));
|
||||
|
||||
beforePostComment();
|
||||
CommentCreateWithTipTask task = new CommentCreateWithTipTask(comment, amount, progressPostComment, new CommentCreateWithTipTask.CommentCreateWithTipHandler() {
|
||||
@Override
|
||||
public void onSuccess(Comment createdComment) {
|
||||
inputComment.setText(null);
|
||||
clearReplyToComment();
|
||||
|
||||
if (commentListAdapter != null) {
|
||||
createdComment.setPoster(comment.getPoster());
|
||||
if (!Helper.isNullOrEmpty(createdComment.getParentId())) {
|
||||
commentListAdapter.addReply(createdComment);
|
||||
} else {
|
||||
commentListAdapter.insert(0, createdComment);
|
||||
}
|
||||
}
|
||||
afterPostComment();
|
||||
checkNoComments();
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).showMessage(R.string.comment_posted);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
showError(error.getMessage());
|
||||
afterPostComment();
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void showError(String message) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).showError(message);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkNoComments() {
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
Helper.setViewVisibility(root.findViewById(R.id.channel_no_comments),
|
||||
commentListAdapter == null || commentListAdapter.getItemCount() == 0 ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
}
|
||||
|
||||
private void setupInlineChannelCreator(
|
||||
View container,
|
||||
TextInputEditText inputChannelName,
|
||||
TextInputEditText inputDeposit,
|
||||
View inlineBalanceView,
|
||||
TextView inlineBalanceValue,
|
||||
View linkCancel,
|
||||
MaterialButton buttonCreate,
|
||||
View progressView,
|
||||
AppCompatSpinner channelSpinner,
|
||||
InlineChannelSpinnerAdapter channelSpinnerAdapter) {
|
||||
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean hasFocus) {
|
||||
Helper.setViewVisibility(inlineBalanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
linkCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Helper.setViewText(inputChannelName, null);
|
||||
Helper.setViewText(inputDeposit, null);
|
||||
Helper.setViewVisibility(container, View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// validate deposit and channel name
|
||||
String channelNameString = Helper.normalizeChannelName(Helper.getValue(inputChannelName.getText()));
|
||||
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)) {
|
||||
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;
|
||||
}
|
||||
|
||||
double depositAmount = 0;
|
||||
try {
|
||||
depositAmount = Double.valueOf(depositString);
|
||||
} catch (NumberFormatException ex) {
|
||||
// pass
|
||||
showError(getString(R.string.please_enter_valid_deposit));
|
||||
return;
|
||||
}
|
||||
if (depositAmount == 0) {
|
||||
String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
|
||||
showError(error);
|
||||
return;
|
||||
}
|
||||
if (Lbry.walletBalance == null || Lbry.walletBalance.getAvailable().doubleValue() < depositAmount) {
|
||||
showError(getString(R.string.deposit_more_than_balance));
|
||||
return;
|
||||
}
|
||||
|
||||
ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(
|
||||
claimToSave, new BigDecimal(depositString), false, progressView, new ClaimResultHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
Helper.setViewEnabled(inputChannelName, false);
|
||||
Helper.setViewEnabled(inputDeposit, false);
|
||||
Helper.setViewEnabled(buttonCreate, false);
|
||||
Helper.setViewEnabled(linkCancel, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Claim claimResult) {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
LogPublishTask logPublishTask = new LogPublishTask(claimResult);
|
||||
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
|
||||
if (channelSpinnerAdapter != null) {
|
||||
channelSpinnerAdapter.add(claimResult);
|
||||
}
|
||||
if (channelSpinner != null && channelSpinnerAdapter != null) {
|
||||
channelSpinner.setSelection(channelSpinnerAdapter.getCount() - 1);
|
||||
}
|
||||
|
||||
Helper.setViewEnabled(inputChannelName, true);
|
||||
Helper.setViewEnabled(inputDeposit, true);
|
||||
Helper.setViewEnabled(buttonCreate, true);
|
||||
Helper.setViewEnabled(linkCancel, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Helper.setViewEnabled(inputChannelName, true);
|
||||
Helper.setViewEnabled(inputDeposit, true);
|
||||
Helper.setViewEnabled(buttonCreate, true);
|
||||
Helper.setViewEnabled(linkCancel, true);
|
||||
showError(error.getMessage());
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
|
||||
Helper.setViewText(inlineBalanceValue, Helper.shortCurrencyFormat(Lbry.walletBalance.getAvailable().doubleValue()));
|
||||
}
|
||||
}
|
||||
@@ -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;
|
||||
@@ -20,7 +21,6 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
@@ -32,7 +32,6 @@ 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;
|
||||
@@ -215,12 +214,12 @@ 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);
|
||||
}
|
||||
|
||||
return Lbry.buildClaimSearchOptions(
|
||||
(List) null,
|
||||
null,
|
||||
null,
|
||||
canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS),
|
||||
Arrays.asList(channelId),
|
||||
@@ -233,7 +232,7 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
||||
|
||||
private List<String> getContentSortOrder() {
|
||||
if (contentSortOrder == null) {
|
||||
return Collections.singletonList(Claim.ORDER_BY_RELEASE_TIME);
|
||||
return Arrays.asList(Claim.ORDER_BY_RELEASE_TIME);
|
||||
}
|
||||
return contentSortOrder;
|
||||
}
|
||||
@@ -255,7 +254,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) {
|
||||
|
||||
@@ -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,7 +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;
|
||||
@@ -47,7 +45,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;
|
||||
@@ -58,7 +56,7 @@ import io.lbry.browser.utils.LbryUri;
|
||||
import lombok.Getter;
|
||||
|
||||
public class ChannelFormFragment extends BaseFragment implements
|
||||
FilePickerListener, StoragePermissionListener, TagListAdapter.TagClickListener, WalletBalanceListener {
|
||||
StoragePermissionListener, TagListAdapter.TagClickListener, WalletBalanceListener {
|
||||
|
||||
private static final int SUGGESTED_LIMIT = 8;
|
||||
|
||||
@@ -72,7 +70,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 +111,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 +136,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 +145,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 +167,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);
|
||||
@@ -211,7 +199,7 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (uploading) {
|
||||
Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
|
||||
Snackbar.make(getView(), R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -222,11 +210,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
buttonSave.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (uploading) {
|
||||
Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Claim claimToSave = buildChannelClaimToSave();
|
||||
validateAndSaveClaim(claimToSave);
|
||||
}
|
||||
@@ -254,13 +237,7 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
|
||||
private void checkParams() {
|
||||
Map<String, Object> params = getParams();
|
||||
if (params == null) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).onBackPressed();
|
||||
return;
|
||||
}
|
||||
} else if (params.containsKey("claim")) {
|
||||
if (params.containsKey("claim")) {
|
||||
Claim claim = (Claim) params.get("claim");
|
||||
if (claim != null && !claim.equals(this.currentClaim)) {
|
||||
this.currentClaim = claim;
|
||||
@@ -300,17 +277,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;
|
||||
@@ -377,6 +353,13 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void showError(String message) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).setBackgroundTint(Color.RED).show();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkPermissionsAndLaunchFilePicker(boolean isCover) {
|
||||
Context context = getContext();
|
||||
if (MainActivity.hasPermission(Manifest.permission.WRITE_EXTERNAL_STORAGE, context)) {
|
||||
@@ -460,9 +443,9 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
if (getContext() != null) {
|
||||
showError(getString(R.string.image_upload_failed));
|
||||
}
|
||||
Snackbar.make(getView(), R.string.image_upload_failed, Snackbar.LENGTH_LONG).setBackgroundTint(
|
||||
ContextCompat.getColor(context, R.color.red)
|
||||
).show();
|
||||
if (coverFilePickerActive) {
|
||||
// cover selected
|
||||
imageCover.setImageResource(R.drawable.default_channel_cover);
|
||||
@@ -503,12 +486,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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -528,7 +511,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
activity.restoreToggle();
|
||||
activity.showFloatingWalletBalance();
|
||||
if (!MainActivity.startingFilePickerActivity) {
|
||||
activity.removeFilePickerListener(this);
|
||||
activity.removeNavFragment(ChannelFormFragment.class, NavMenuItem.ID_ITEM_CHANNELS);
|
||||
}
|
||||
}
|
||||
@@ -538,7 +520,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
checkParams();
|
||||
checkRewardsDriver();
|
||||
updateFieldsFromCurrentClaim();
|
||||
|
||||
Context context = getContext();
|
||||
@@ -547,7 +528,10 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
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());
|
||||
@@ -565,11 +549,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);
|
||||
@@ -580,6 +561,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();
|
||||
@@ -591,7 +573,6 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
if (walletBalance != null && inlineBalanceValue != null) {
|
||||
inlineBalanceValue.setText(Helper.shortCurrencyFormat(walletBalance.getAvailable().doubleValue()));
|
||||
}
|
||||
checkRewardsDriver();
|
||||
}
|
||||
|
||||
public void setFilter(String filter) {
|
||||
@@ -600,14 +581,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) {
|
||||
@@ -630,13 +604,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());
|
||||
}
|
||||
|
||||
@@ -695,13 +669,4 @@ public class ChannelFormFragment extends BaseFragment implements
|
||||
removeTag(tag);
|
||||
}
|
||||
}
|
||||
|
||||
private void checkRewardsDriver() {
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
String rewardsDriverText = String.format("%s\n%s",
|
||||
getString(R.string.channel_creation_requires_credits), getString(R.string.tap_here_to_get_some));
|
||||
checkRewardsDriverCard(rewardsDriverText, Helper.MIN_DEPOSIT);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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,12 +26,12 @@ 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;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
import io.lbry.browser.data.DatabaseHelper;
|
||||
import io.lbry.browser.dialog.SendTipDialogFragment;
|
||||
import io.lbry.browser.exceptions.LbryUriException;
|
||||
import io.lbry.browser.listener.FetchChannelsListener;
|
||||
@@ -43,15 +39,13 @@ 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 +76,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 +122,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 +134,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 +228,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, Snackbar.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);
|
||||
@@ -322,21 +281,19 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
boolean updateRequired = false;
|
||||
Map<String, Object> params = getParams();
|
||||
|
||||
if (params != null) {
|
||||
if (params.containsKey("claim")) {
|
||||
Claim claim = (Claim) params.get("claim");
|
||||
if (claim != null && !claim.equals(this.claim)) {
|
||||
this.claim = claim;
|
||||
updateRequired = true;
|
||||
}
|
||||
if (params.containsKey("claim")) {
|
||||
Claim claim = (Claim) params.get("claim");
|
||||
if (claim != null && !claim.equals(this.claim)) {
|
||||
this.claim = claim;
|
||||
updateRequired = true;
|
||||
}
|
||||
if (params.containsKey("url")) {
|
||||
String newUrl = params.get("url").toString();
|
||||
if (claim == null || !newUrl.equalsIgnoreCase(url)) {
|
||||
this.claim = null;
|
||||
this.url = newUrl;
|
||||
updateRequired = true;
|
||||
}
|
||||
}
|
||||
if (params.containsKey("url")) {
|
||||
String newUrl = params.get("url").toString();
|
||||
if (claim == null || !newUrl.equalsIgnoreCase(url)) {
|
||||
this.claim = null;
|
||||
this.url = newUrl;
|
||||
updateRequired = true;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -367,8 +324,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
}
|
||||
|
||||
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) {
|
||||
@@ -421,12 +377,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()).asBitmap().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);
|
||||
@@ -440,23 +395,19 @@ 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()));
|
||||
}
|
||||
new TabLayoutMediator(tabLayout, tabPager, new TabLayoutMediator.TabConfigurationStrategy() {
|
||||
@Override
|
||||
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
||||
switch (position) {
|
||||
case 0: tab.setText(R.string.content); break;
|
||||
case 1: tab.setText(R.string.about); break;
|
||||
case 2: tab.setText(R.string.comments); break;
|
||||
}
|
||||
}
|
||||
}).attach();
|
||||
} catch (IllegalStateException ex) {
|
||||
// TODO: Fix why this is happening
|
||||
// pass
|
||||
}
|
||||
new TabLayoutMediator(tabLayout, tabPager, new TabLayoutMediator.TabConfigurationStrategy() {
|
||||
@Override
|
||||
public void onConfigureTab(@NonNull TabLayout.Tab tab, int position) {
|
||||
tab.setText(position == 0 ? R.string.content : R.string.about);
|
||||
}
|
||||
}).attach();
|
||||
}
|
||||
|
||||
private void resetSubCount() {
|
||||
@@ -520,13 +471,6 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
// pass
|
||||
}
|
||||
return aboutFragment;
|
||||
|
||||
case 2:
|
||||
ChannelCommentsFragment commentsFragment = ChannelCommentsFragment.class.newInstance();
|
||||
if (channelClaim != null) {
|
||||
commentsFragment.setClaim(channelClaim);
|
||||
}
|
||||
return commentsFragment;
|
||||
}
|
||||
|
||||
return null;
|
||||
@@ -538,7 +482,7 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return 3;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
+3
-3
@@ -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;
|
||||
@@ -26,7 +27,6 @@ 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 +105,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);
|
||||
+255
-1264
File diff suppressed because it is too large.
Load diff
+21
-32
@@ -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;
|
||||
@@ -40,7 +41,6 @@ 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;
|
||||
@@ -248,8 +248,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
discoverLink.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
|
||||
Helper.setViewEnabled(discoverLink, false);
|
||||
buildChannelIdsAndUrls();
|
||||
currentSuggestedPage = 1;
|
||||
discoverDialog = DiscoverDialogFragment.newInstance();
|
||||
@@ -270,7 +268,6 @@ public class FollowingFragment extends BaseFragment implements
|
||||
if (suggestedChannelAdapter != null) {
|
||||
suggestedChannelAdapter.clearItems();
|
||||
}
|
||||
Helper.setViewEnabled(discoverLink, true);
|
||||
}
|
||||
@Override
|
||||
public void onResume() {
|
||||
@@ -399,12 +396,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,
|
||||
@@ -427,7 +420,7 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
return Lbry.buildClaimSearchOptions(
|
||||
Arrays.asList(Claim.TYPE_STREAM, Claim.TYPE_REPOST),
|
||||
Claim.TYPE_STREAM,
|
||||
null,
|
||||
canShowMatureContent ? null : new ArrayList<>(Predefined.MATURE_TAGS),
|
||||
getChannelIds(),
|
||||
@@ -527,9 +520,8 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private void updateChannelFilterListAdapter(List<Claim> resolvedSubs, boolean reset) {
|
||||
Context context = getContext();
|
||||
if (channelFilterListAdapter == null && context != null) {
|
||||
channelFilterListAdapter = new ChannelFilterListAdapter(context);
|
||||
if (channelFilterListAdapter == null) {
|
||||
channelFilterListAdapter = new ChannelFilterListAdapter(getContext());
|
||||
channelFilterListAdapter.setListener(new ChannelItemSelectionListener() {
|
||||
@Override
|
||||
public void onChannelItemSelected(Claim claim) {
|
||||
@@ -564,16 +556,14 @@ public class FollowingFragment extends BaseFragment implements
|
||||
});
|
||||
}
|
||||
|
||||
if (channelFilterListAdapter != null) {
|
||||
if (horizontalChannelList != null && horizontalChannelList.getAdapter() == null) {
|
||||
horizontalChannelList.setAdapter(channelFilterListAdapter);
|
||||
}
|
||||
if (reset) {
|
||||
channelFilterListAdapter.clearClaims();
|
||||
channelFilterListAdapter.setSelectedItem(null);
|
||||
}
|
||||
channelFilterListAdapter.addClaims(resolvedSubs);
|
||||
if (horizontalChannelList != null && horizontalChannelList.getAdapter() == null) {
|
||||
horizontalChannelList.setAdapter(channelFilterListAdapter);
|
||||
}
|
||||
if (reset) {
|
||||
channelFilterListAdapter.clearClaims();
|
||||
channelFilterListAdapter.setSelectedItem(null);
|
||||
}
|
||||
channelFilterListAdapter.addClaims(resolvedSubs);
|
||||
}
|
||||
|
||||
private void fetchClaimSearchContent() {
|
||||
@@ -589,7 +579,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) {
|
||||
@@ -632,12 +622,11 @@ public class FollowingFragment extends BaseFragment implements
|
||||
}
|
||||
|
||||
private void updateSuggestedDoneButtonText() {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
int selected = suggestedChannelAdapter == null ? 0 : suggestedChannelAdapter.getSelectedCount();
|
||||
int remaining = MIN_SUGGESTED_SUBSCRIBE_COUNT - selected;
|
||||
String buttonText = remaining <= 0 ? getString(R.string.done) : getString(R.string.n_remaining, remaining);
|
||||
Helper.setViewText(suggestedDoneButton, buttonText);
|
||||
int selected = suggestedChannelAdapter == null ? 0 : suggestedChannelAdapter.getSelectedCount();
|
||||
int remaining = MIN_SUGGESTED_SUBSCRIBE_COUNT - selected;
|
||||
String buttonText = remaining <= 0 ? getString(R.string.done) : getString(R.string.n_remaining, remaining);
|
||||
if (suggestedDoneButton != null) {
|
||||
suggestedDoneButton.setText(buttonText);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -656,7 +645,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;
|
||||
@@ -26,10 +26,12 @@ import com.google.android.material.snackbar.Snackbar;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.nio.channels.AsynchronousChannel;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.R;
|
||||
@@ -40,27 +42,25 @@ 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.NavMenuItem;
|
||||
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.claim.AbandonChannelTask;
|
||||
import io.lbry.browser.tasks.claim.AbandonHandler;
|
||||
import io.lbry.browser.tasks.file.BulkDeleteFilesTask;
|
||||
import io.lbry.browser.tasks.file.DeleteFileTask;
|
||||
import io.lbry.browser.tasks.file.FileListTask;
|
||||
import io.lbry.browser.tasks.localdata.FetchViewHistoryTask;
|
||||
import io.lbry.browser.ui.BaseFragment;
|
||||
import io.lbry.browser.ui.channel.ChannelFormFragment;
|
||||
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 FILTER_HISTORY = 2;
|
||||
private static final int PAGE_SIZE = 50;
|
||||
|
||||
private ActionMode actionMode;
|
||||
@@ -71,7 +71,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
private ClaimListAdapter contentListAdapter;
|
||||
private ProgressBar listLoading;
|
||||
private TextView linkFilterDownloads;
|
||||
private TextView linkFilterPurchases;
|
||||
private TextView linkFilterHistory;
|
||||
private View layoutListEmpty;
|
||||
private TextView textListEmpty;
|
||||
@@ -79,7 +78,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
private Date lastDate;
|
||||
private boolean listReachedEnd;
|
||||
private boolean contentListLoading;
|
||||
private boolean initialOwnClaimsFetched;
|
||||
|
||||
private CardView cardStats;
|
||||
private TextView linkStats;
|
||||
@@ -118,7 +116,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
|
||||
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);
|
||||
@@ -131,12 +128,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
showDownloads();
|
||||
}
|
||||
});
|
||||
linkFilterPurchases.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
showPurchases();
|
||||
}
|
||||
});
|
||||
linkFilterHistory.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
@@ -213,7 +204,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
super.onResume();
|
||||
|
||||
Context context = getContext();
|
||||
Helper.setWunderbarValue(null, context);
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
LbryAnalytics.setCurrentScreen(activity, "Library", "Library");
|
||||
@@ -248,18 +238,14 @@ public class LibraryFragment extends BaseFragment implements
|
||||
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);
|
||||
}
|
||||
@@ -268,76 +254,19 @@ public class LibraryFragment extends BaseFragment implements
|
||||
checkStatsLink();
|
||||
layoutSdkInitializing.setVisibility(Lbry.SDK_READY ? View.GONE : View.VISIBLE);
|
||||
currentPage = 1;
|
||||
currentFiles = new ArrayList<>();
|
||||
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(false);
|
||||
}
|
||||
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);
|
||||
}
|
||||
@@ -353,9 +282,8 @@ public class LibraryFragment extends BaseFragment implements
|
||||
|
||||
private void initContentListAdapter(List<Claim> claims) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
contentListAdapter.setCanEnterSelectionMode(currentFilter == FILTER_DOWNLOADS);
|
||||
contentListAdapter.setCanEnterSelectionMode(true);
|
||||
contentListAdapter.setSelectionModeListener(this);
|
||||
contentListAdapter.setHideFee(currentFilter != FILTER_PURCHASES);
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
@@ -382,6 +310,7 @@ public class LibraryFragment extends BaseFragment implements
|
||||
listReachedEnd = hasReachedEnd;
|
||||
List<LbryFile> filteredFiles = Helper.filterDownloads(files);
|
||||
List<Claim> claims = Helper.claimsFromFiles(filteredFiles);
|
||||
|
||||
addFiles(filteredFiles);
|
||||
updateStats();
|
||||
checkStatsLink();
|
||||
@@ -391,10 +320,7 @@ public class LibraryFragment extends BaseFragment implements
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
resolveMissingChannelNames(buildUrlsToResolve(claims));
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
@@ -410,36 +336,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
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);
|
||||
@@ -459,9 +355,7 @@ public class LibraryFragment extends BaseFragment implements
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
checkListEmpty();
|
||||
contentListLoading = false;
|
||||
}
|
||||
@@ -495,13 +389,7 @@ public class LibraryFragment extends BaseFragment implements
|
||||
|
||||
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);
|
||||
textListEmpty.setText(currentFilter == FILTER_DOWNLOADS ? R.string.library_no_downloads : R.string.library_no_history);
|
||||
}
|
||||
|
||||
private void addFiles(List<LbryFile> files) {
|
||||
@@ -591,8 +479,7 @@ public class LibraryFragment extends BaseFragment implements
|
||||
private void checkStatsLink() {
|
||||
linkStats.setVisibility(cardStats.getVisibility() == View.VISIBLE ||
|
||||
listLoading.getVisibility() == View.VISIBLE ||
|
||||
currentFilter != FILTER_DOWNLOADS ||
|
||||
!Lbry.SDK_READY ?
|
||||
currentFilter == FILTER_HISTORY ?
|
||||
View.GONE : View.VISIBLE);
|
||||
}
|
||||
|
||||
@@ -677,50 +564,6 @@ public class LibraryFragment extends BaseFragment implements
|
||||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -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,448 +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 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 boolean cameraPreviewInitialized;
|
||||
private boolean storagePermissionRefusedOnce;
|
||||
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 && MainActivity.hasPermission(Manifest.permission.CAMERA, context)) {
|
||||
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()));
|
||||
cameraPreviewInitialized = true;
|
||||
}
|
||||
} 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();
|
||||
}
|
||||
}
|
||||
|
||||
if (!storagePermissionRefusedOnce) {
|
||||
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);
|
||||
}
|
||||
}
|
||||
if (cameraPreviewInitialized) {
|
||||
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, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
return;
|
||||
}
|
||||
|
||||
recordPending = false;
|
||||
Snackbar.make(getView(), R.string.camera_permission_rationale_record, Snackbar.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() {
|
||||
storagePermissionRefusedOnce = true;
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
Snackbar.make(root, R.string.storage_permission_rationale_videos, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
Helper.setViewText(noVideosLoaded, R.string.storage_permission_rationale_videos);
|
||||
}
|
||||
|
||||
checkNoVideosLoaded();
|
||||
}
|
||||
|
||||
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,326 +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 activity = (MainActivity) context;
|
||||
if (claim.getName().startsWith("@")) {
|
||||
activity.openChannelClaim(claim);
|
||||
} else {
|
||||
activity.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 &&
|
||||
Claim.TYPE_STREAM.equalsIgnoreCase(adapter.getSelectedItems().get(0).getValueType()));
|
||||
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);
|
||||
}
|
||||
}
|
||||
+42
-71
@@ -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,12 +15,12 @@ import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
import com.google.android.exoplayer2.offline.Download;
|
||||
|
||||
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;
|
||||
@@ -29,13 +29,11 @@ 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;
|
||||
@@ -184,26 +182,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,49 +214,39 @@ 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;
|
||||
searchLoading = false;
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
if (resultListAdapter == null) {
|
||||
resultListAdapter = new ClaimListAdapter(claims, context);
|
||||
resultListAdapter.addFeaturedItem(buildFeaturedItem(query));
|
||||
resolveFeaturedItem(buildVanityUrl(query));
|
||||
resultListAdapter.setListener(SearchFragment.this);
|
||||
if (resultList != null) {
|
||||
resultList.setAdapter(resultListAdapter);
|
||||
}
|
||||
} else {
|
||||
resultListAdapter.addItems(claims);
|
||||
}
|
||||
|
||||
int itemCount = resultListAdapter.getItemCount();
|
||||
Helper.setViewVisibility(noQueryView, View.GONE);
|
||||
Helper.setViewVisibility(noResultsView, itemCount == 0 ? View.VISIBLE : View.GONE);
|
||||
Helper.setViewText(noResultsView, getString(R.string.search_no_results, currentQuery));
|
||||
if (resultListAdapter == null) {
|
||||
resultListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
resultListAdapter.addFeaturedItem(buildFeaturedItem(query));
|
||||
resolveFeaturedItem(buildVanityUrl(query));
|
||||
resultListAdapter.setListener(SearchFragment.this);
|
||||
if (resultList != null) {
|
||||
resultList.setAdapter(resultListAdapter);
|
||||
}
|
||||
} else {
|
||||
resultListAdapter.addItems(claims);
|
||||
}
|
||||
|
||||
int itemCount = resultListAdapter.getItemCount();
|
||||
noQueryView.setVisibility(View.GONE);
|
||||
noResultsView.setVisibility(itemCount == 0 ? View.VISIBLE : View.GONE);
|
||||
noResultsView.setText(getString(R.string.search_no_results, currentQuery));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Context context = getContext();
|
||||
int itemCount = resultListAdapter == null ? 0 : resultListAdapter.getItemCount();
|
||||
Helper.setViewVisibility(noQueryView, View.GONE);
|
||||
Helper.setViewVisibility(noResultsView, itemCount == 0 ? View.VISIBLE : View.GONE);
|
||||
if (context != null) {
|
||||
Helper.setViewText(noResultsView, getString(R.string.search_no_results, currentQuery));
|
||||
}
|
||||
noQueryView.setVisibility(View.GONE);
|
||||
noResultsView.setVisibility(itemCount == 0 ? View.VISIBLE : View.GONE);
|
||||
noResultsView.setText(getString(R.string.search_no_results, currentQuery));
|
||||
searchLoading = false;
|
||||
}
|
||||
});
|
||||
@@ -281,20 +259,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) getContext()).openFileClaim(claim);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,14 +1,10 @@
|
||||
package io.lbry.browser.ui.verification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
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.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -70,12 +66,8 @@ public class EmailVerificationFragment extends Fragment {
|
||||
inputEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean hasFocus) {
|
||||
try {
|
||||
String layoutHint = !hasFocus ? "" : getString(R.string.email);
|
||||
inputLayoutEmail.setHint(layoutHint);
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
String layoutHint = !hasFocus ? "" : getString(R.string.email);
|
||||
inputLayoutEmail.setHint(layoutHint);
|
||||
}
|
||||
});
|
||||
buttonContinue.setOnClickListener(new View.OnClickListener() {
|
||||
@@ -102,21 +94,11 @@ public class EmailVerificationFragment extends Fragment {
|
||||
|
||||
private void addEmail() {
|
||||
currentEmail = Helper.getValue(inputEmail.getText());
|
||||
if (Helper.isNullOrEmpty(currentEmail) || !currentEmail.contains("@")) {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
Snackbar.make(view, R.string.provide_valid_email, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
if (Helper.isNullOrEmpty(currentEmail) || currentEmail.indexOf("@") == -1) {
|
||||
Snackbar.make(getView(), R.string.provide_valid_email, Snackbar.LENGTH_LONG).setBackgroundTint(getResources().getColor(R.color.red)).show();
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(inputEmail.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
EmailNewTask task = new EmailNewTask(currentEmail, emailAddProgress, new EmailNewTask.EmailNewHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
@@ -143,11 +125,7 @@ public class EmailVerificationFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
View view = getView();
|
||||
if (view != null && error != null) {
|
||||
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);
|
||||
}
|
||||
});
|
||||
@@ -204,20 +182,13 @@ public class EmailVerificationFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
Snackbar.make(view, R.string.please_follow_instructions, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
Snackbar.make(getView(), R.string.please_follow_instructions, Snackbar.LENGTH_LONG).show();
|
||||
Helper.setViewEnabled(buttonResend, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
View view = getView();
|
||||
if (view != null && error != null) {
|
||||
Snackbar.make(view, 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);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package io.lbry.browser.ui.verification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
@@ -8,7 +7,6 @@ import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.EditText;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
@@ -76,17 +74,10 @@ 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;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(inputPhoneNumber.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
addPhoneNumber();
|
||||
}
|
||||
});
|
||||
@@ -96,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);
|
||||
@@ -119,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
|
||||
@@ -129,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);
|
||||
@@ -153,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
|
||||
@@ -162,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);
|
||||
|
||||
@@ -1,13 +1,10 @@
|
||||
package io.lbry.browser.ui.verification;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
@@ -62,13 +59,6 @@ public class WalletVerificationFragment extends Fragment {
|
||||
showError(getString(R.string.please_enter_your_password));
|
||||
return;
|
||||
}
|
||||
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
InputMethodManager imm = (InputMethodManager) context.getSystemService(Activity.INPUT_METHOD_SERVICE);
|
||||
imm.hideSoftInputFromWindow(inputPassword.getWindowToken(), 0);
|
||||
}
|
||||
|
||||
if (listener != null) {
|
||||
listener.onWalletSyncProcessing();
|
||||
}
|
||||
@@ -99,14 +89,9 @@ public class WalletVerificationFragment extends Fragment {
|
||||
verificationStarted = true;
|
||||
Helper.setViewVisibility(loading, View.VISIBLE);
|
||||
Helper.setViewVisibility(textLoading, View.VISIBLE);
|
||||
// attempt to load secure value from versions pre-0.15.0
|
||||
String prevVersionPassword = Utils.getSecureValue(MainActivity.SECURE_VALUE_FIRST_RUN_PASSWORD, getContext(), Lbry.KEYSTORE);
|
||||
String password = Utils.getSecureValue(MainActivity.SECURE_VALUE_KEY_SAVED_PASSWORD, getContext(), Lbry.KEYSTORE);
|
||||
// start verification process
|
||||
SyncGetTask task = new SyncGetTask(!Helper.isNullOrEmpty(prevVersionPassword) ? prevVersionPassword : password,
|
||||
false,
|
||||
null,
|
||||
new DefaultSyncTaskHandler() {
|
||||
SyncGetTask task = new SyncGetTask(password, false, null, new DefaultSyncTaskHandler() {
|
||||
@Override
|
||||
public void onSyncGetSuccess(WalletSync walletSync) {
|
||||
currentWalletSync = walletSync;
|
||||
|
||||
@@ -16,7 +16,6 @@ import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.widget.AppCompatSpinner;
|
||||
import androidx.cardview.widget.CardView;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
|
||||
@@ -42,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;
|
||||
@@ -79,7 +78,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
private View progressLoadingInviteByEmail;
|
||||
private View progressLoadingStatus;
|
||||
|
||||
private CardView rewardDriverCard;
|
||||
private View inlineChannelCreator;
|
||||
private TextInputEditText inlineChannelCreatorInputName;
|
||||
private TextInputEditText inlineChannelCreatorInputDeposit;
|
||||
@@ -97,7 +95,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
layoutSdkInitializing = root.findViewById(R.id.container_sdk_initializing);
|
||||
textLearnMoreLink = root.findViewById(R.id.invites_account_driver_learn_more);
|
||||
buttonGetStarted = root.findViewById(R.id.invites_get_started_button);
|
||||
rewardDriverCard = root.findViewById(R.id.reward_driver_card);
|
||||
|
||||
textInviteLink = root.findViewById(R.id.invites_invite_link);
|
||||
buttonCopyInviteLink = root.findViewById(R.id.invites_copy_invite_link);
|
||||
@@ -134,16 +131,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
layoutSdkInitializing.setVisibility(Lbry.SDK_READY ? View.GONE : View.VISIBLE);
|
||||
Helper.applyHtmlForTextView(textLearnMoreLink);
|
||||
|
||||
rewardDriverCard.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
((MainActivity) context).openRewards();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
inputEmail.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean hasFocus) {
|
||||
@@ -248,8 +235,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
}
|
||||
});
|
||||
|
||||
channelSpinnerAdapter = new InlineChannelSpinnerAdapter(getContext(), R.layout.spinner_item_channel, new ArrayList<>());
|
||||
channelSpinnerAdapter.addPlaceholder(false);
|
||||
setupInlineChannelCreator(
|
||||
inlineChannelCreator,
|
||||
inlineChannelCreatorInputName,
|
||||
@@ -258,9 +243,7 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
inlineChannelCreatorInlineBalanceValue,
|
||||
inlineChannelCreatorCancelLink,
|
||||
inlineChannelCreatorCreateButton,
|
||||
inlineChannelCreatorProgress,
|
||||
channelSpinner,
|
||||
channelSpinnerAdapter
|
||||
inlineChannelCreatorProgress
|
||||
);
|
||||
}
|
||||
|
||||
@@ -306,7 +289,6 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
layoutAccountDriver.setVisibility(Lbryio.isSignedIn() ? View.GONE : View.VISIBLE);
|
||||
checkRewardsDriver();
|
||||
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
@@ -459,19 +441,134 @@ public class InvitesFragment extends BaseFragment implements SdkStatusListener,
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
|
||||
private void setupInlineChannelCreator(
|
||||
View container,
|
||||
TextInputEditText inputChannelName,
|
||||
TextInputEditText inputDeposit,
|
||||
View inlineBalanceView,
|
||||
TextView inlineBalanceValue,
|
||||
View linkCancel,
|
||||
MaterialButton buttonCreate,
|
||||
View progressView) {
|
||||
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
||||
@Override
|
||||
public void onFocusChange(View view, boolean hasFocus) {
|
||||
Helper.setViewVisibility(inlineBalanceView, hasFocus ? View.VISIBLE : View.INVISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
linkCancel.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
Helper.setViewText(inputChannelName, null);
|
||||
Helper.setViewText(inputDeposit, null);
|
||||
Helper.setViewVisibility(container, View.GONE);
|
||||
}
|
||||
});
|
||||
|
||||
buttonCreate.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
// validate deposit and channel name
|
||||
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 (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;
|
||||
}
|
||||
|
||||
double depositAmount = 0;
|
||||
try {
|
||||
depositAmount = Double.valueOf(depositString);
|
||||
} catch (NumberFormatException ex) {
|
||||
// pass
|
||||
showError(getString(R.string.please_enter_valid_deposit));
|
||||
return;
|
||||
}
|
||||
if (depositAmount == 0) {
|
||||
String error = getResources().getQuantityString(R.plurals.min_deposit_required, depositAmount == 1 ? 1 : 2, String.valueOf(Helper.MIN_DEPOSIT));
|
||||
showError(error);
|
||||
return;
|
||||
}
|
||||
if (Lbry.walletBalance == null || Lbry.walletBalance.getAvailable().doubleValue() < depositAmount) {
|
||||
showError(getString(R.string.deposit_more_than_balance));
|
||||
return;
|
||||
}
|
||||
|
||||
ChannelCreateUpdateTask task = new ChannelCreateUpdateTask(
|
||||
claimToSave, new BigDecimal(depositString), false, progressView, new ClaimResultHandler() {
|
||||
@Override
|
||||
public void beforeStart() {
|
||||
Helper.setViewEnabled(inputChannelName, false);
|
||||
Helper.setViewEnabled(inputDeposit, false);
|
||||
Helper.setViewEnabled(buttonCreate, false);
|
||||
Helper.setViewEnabled(linkCancel, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSuccess(Claim claimResult) {
|
||||
if (!BuildConfig.DEBUG) {
|
||||
LogPublishTask logPublishTask = new LogPublishTask(claimResult);
|
||||
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);
|
||||
|
||||
Helper.setViewEnabled(inputChannelName, true);
|
||||
Helper.setViewEnabled(inputDeposit, true);
|
||||
Helper.setViewEnabled(buttonCreate, true);
|
||||
Helper.setViewEnabled(linkCancel, true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
Helper.setViewEnabled(inputChannelName, true);
|
||||
Helper.setViewEnabled(inputDeposit, true);
|
||||
Helper.setViewEnabled(buttonCreate, true);
|
||||
Helper.setViewEnabled(linkCancel, true);
|
||||
showError(error.getMessage());
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
});
|
||||
|
||||
Helper.setViewText(inlineBalanceValue, Helper.shortCurrencyFormat(Lbry.walletBalance.getAvailable().doubleValue()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onWalletBalanceUpdated(WalletBalance walletBalance) {
|
||||
if (walletBalance != null && inlineChannelCreatorInlineBalanceValue != null) {
|
||||
inlineChannelCreatorInlineBalanceValue.setText(Helper.shortCurrencyFormat(walletBalance.getAvailable().doubleValue()));
|
||||
}
|
||||
checkRewardsDriver();
|
||||
}
|
||||
|
||||
private void checkRewardsDriver() {
|
||||
Context ctx = getContext();
|
||||
View root = getView();
|
||||
if (ctx != null && root != null) {
|
||||
Helper.setViewText(root.findViewById(R.id.reward_driver_text), R.string.earn_credits_for_inviting);
|
||||
private void showError(String message) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
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,10 +278,7 @@ public class RewardsFragment extends BaseFragment implements RewardListAdapter.R
|
||||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
View view = getView();
|
||||
if (view != null && error != null && !Helper.isNullOrEmpty(error.getMessage())) {
|
||||
Snackbar.make(view, 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,7 +156,7 @@ 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());
|
||||
|
||||
@@ -3,7 +3,6 @@ package io.lbry.browser.ui.wallet;
|
||||
import android.content.ClipData;
|
||||
import android.content.ClipboardManager;
|
||||
import android.content.Context;
|
||||
import android.content.DialogInterface;
|
||||
import android.content.SharedPreferences;
|
||||
import android.graphics.Color;
|
||||
import android.os.AsyncTask;
|
||||
@@ -18,8 +17,6 @@ import android.widget.ProgressBar;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AlertDialog;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.preference.PreferenceManager;
|
||||
import androidx.recyclerview.widget.DividerItemDecoration;
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
@@ -32,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;
|
||||
@@ -48,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;
|
||||
@@ -68,9 +62,6 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
private TextView textSupportsBalance;
|
||||
private ProgressBar walletSendProgress;
|
||||
|
||||
private TextView linkUnlockTips;
|
||||
private ProgressBar progressUnlockTips;
|
||||
|
||||
private View loadingRecentContainer;
|
||||
private View inlineBalanceContainer;
|
||||
private TextView textWalletInlineBalance;
|
||||
@@ -119,9 +110,6 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
textSupportsBalance = root.findViewById(R.id.wallet_balance_staked_supports);
|
||||
textWalletHintSyncStatus = root.findViewById(R.id.wallet_hint_sync_status);
|
||||
|
||||
linkUnlockTips = root.findViewById(R.id.wallet_unlock_tips_link);
|
||||
progressUnlockTips = root.findViewById(R.id.wallet_unlock_tips_progress);
|
||||
|
||||
recentTransactionsList = root.findViewById(R.id.wallet_recent_transactions_list);
|
||||
linkViewAll = root.findViewById(R.id.wallet_link_view_all);
|
||||
textNoRecentTransactions = root.findViewById(R.id.wallet_no_recent_transactions);
|
||||
@@ -166,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();
|
||||
}
|
||||
@@ -209,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;
|
||||
}
|
||||
|
||||
@@ -219,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;
|
||||
}
|
||||
}
|
||||
@@ -246,36 +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);
|
||||
|
||||
linkUnlockTips.setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View view) {
|
||||
if (context != null) {
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context).
|
||||
setTitle(R.string.unlock_tips).
|
||||
setMessage(R.string.confirm_unlock_tips)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(DialogInterface dialogInterface, int i) {
|
||||
unlockTips();
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
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
|
||||
@@ -409,22 +349,13 @@ 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 = null;
|
||||
try {
|
||||
amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT, new DecimalFormatSymbols(Locale.US)).
|
||||
format(new BigDecimal(amountString).doubleValue());
|
||||
} catch (NumberFormatException ex) {
|
||||
Snackbar.make(getView(), R.string.invalid_amount, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
return;
|
||||
}
|
||||
String amount = new DecimalFormat(Helper.SDK_AMOUNT_FORMAT).format(new BigDecimal(amountString).doubleValue());
|
||||
|
||||
disableSendControls();
|
||||
double actualSendAmount = Double.valueOf(amount);
|
||||
WalletSendTask task = new WalletSendTask(recipientAddress, amount, walletSendProgress, new WalletSendTask.WalletSendHandler() {
|
||||
@Override
|
||||
public void onSuccess() {
|
||||
double sentAmount = actualSendAmount;
|
||||
double sentAmount = Double.valueOf(amount);
|
||||
String message = getResources().getQuantityString(
|
||||
R.plurals.you_sent_credits, sentAmount == 1.0 ? 1 : 2,
|
||||
new DecimalFormat("#,###.##").format(sentAmount));
|
||||
@@ -437,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();
|
||||
}
|
||||
});
|
||||
@@ -445,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();
|
||||
@@ -497,7 +424,6 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.setWunderbarValue(null);
|
||||
activity.addWalletBalanceListener(this);
|
||||
activity.hideFloatingWalletBalance();
|
||||
}
|
||||
}
|
||||
@@ -517,6 +443,7 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
activity.syncWalletAndLoadPreferences();
|
||||
activity.addWalletBalanceListener(this);
|
||||
}
|
||||
|
||||
// update view
|
||||
@@ -525,8 +452,6 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
}
|
||||
|
||||
checkReceiveAddress();
|
||||
checkRewardsDriver();
|
||||
checkTips();
|
||||
fetchRecentTransactions();
|
||||
}
|
||||
|
||||
@@ -538,11 +463,8 @@ public class WalletFragment extends BaseFragment implements SdkStatusListener, W
|
||||
}
|
||||
@Override
|
||||
public void onSuccess(String newAddress) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
sp.edit().putString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, newAddress).apply();
|
||||
}
|
||||
SharedPreferences sp = PreferenceManager.getDefaultSharedPreferences(getContext());
|
||||
sp.edit().putString(MainActivity.PREFERENCE_KEY_INTERNAL_WALLET_RECEIVE_ADDRESS, newAddress).apply();
|
||||
Helper.setViewText(textWalletReceiveAddress, newAddress);
|
||||
Helper.setViewEnabled(buttonGetNewAddress, true);
|
||||
}
|
||||
@@ -561,61 +483,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)));
|
||||
}
|
||||
|
||||
checkTips();
|
||||
checkRewardsDriver();
|
||||
}
|
||||
|
||||
private void unlockTips() {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
linkUnlockTips.setVisibility(View.GONE);
|
||||
progressUnlockTips.setVisibility(View.VISIBLE);
|
||||
((MainActivity) context).unlockTips();
|
||||
}
|
||||
}
|
||||
|
||||
public void checkTips() {
|
||||
checkTips(false);
|
||||
}
|
||||
|
||||
public void checkTips(boolean forceHideLink) {
|
||||
WalletBalance walletBalance = Lbry.walletBalance;
|
||||
double tipBalance = walletBalance == null ? 0 : walletBalance.getTips().doubleValue();
|
||||
boolean unlocking = false;
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) context;
|
||||
unlocking = activity.isUnlockingTips();
|
||||
}
|
||||
|
||||
Helper.setViewVisibility(linkUnlockTips, !forceHideLink && tipBalance > 0 && !unlocking ? View.VISIBLE : View.GONE);
|
||||
Helper.setViewVisibility(progressUnlockTips, unlocking ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
|
||||
private void checkRewardsDriver() {
|
||||
// check rewards driver
|
||||
Context ctx = getContext();
|
||||
if (ctx != null) {
|
||||
String rewardsDriverText = getString(R.string.free_credits_available);
|
||||
if (Lbryio.totalUnclaimedRewardAmount > 0) {
|
||||
rewardsDriverText = getResources().getQuantityString(
|
||||
Lbryio.isSignedIn() ? R.plurals.wallet_signed_in_free_credits : R.plurals.wallet_get_free_credits,
|
||||
Lbryio.totalUnclaimedRewardAmount == 1 ? 1 : 2,
|
||||
Helper.shortCurrencyFormat(Lbryio.totalUnclaimedRewardAmount));
|
||||
}
|
||||
checkRewardsDriverCard(rewardsDriverText, 0);
|
||||
Helper.setViewText(textWalletBalanceUSD, String.format("≈$%s", Helper.USD_CURRENCY_FORMAT.format(usdBalance)));
|
||||
Helper.setViewText(textTipsBalanceUSD, String.format("≈$%s", Helper.USD_CURRENCY_FORMAT.format(tipsUsdBalance)));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -18,17 +18,12 @@ 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 +33,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;
|
||||
@@ -69,18 +63,13 @@ 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 String PLAIN_CURRENCY_FORMAT_PATTERN = "####.##";
|
||||
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;
|
||||
}
|
||||
@@ -88,14 +77,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;
|
||||
@@ -319,11 +300,11 @@ public final class Helper {
|
||||
return "0";
|
||||
}
|
||||
|
||||
return format.format(value).equals("0") ? FULL_LBC_CURRENCY_FORMAT.format(value) : format.format(value);
|
||||
return format.format(value);
|
||||
}
|
||||
|
||||
public static String getValue(CharSequence cs) {
|
||||
return cs != null ? cs.toString().trim() : "";
|
||||
return cs != null ? cs.toString() : "";
|
||||
}
|
||||
|
||||
public static List<String> buildContentSortOrder(int sortBy) {
|
||||
@@ -452,14 +433,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);
|
||||
@@ -660,14 +633,6 @@ public final class Helper {
|
||||
List<LbryFile> filtered = new ArrayList<>();
|
||||
for (int i = 0; i < files.size(); i++) {
|
||||
LbryFile file = files.get(i);
|
||||
// remove own claims as well
|
||||
if (Lbry.ownClaims != null && Lbry.ownClaims.size() > 0) {
|
||||
for (Claim own : Lbry.ownClaims) {
|
||||
if (own.getClaimId().equalsIgnoreCase(file.getClaimId())) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!Helper.isNullOrEmpty(file.getDownloadPath())) {
|
||||
filtered.add(file);
|
||||
}
|
||||
@@ -709,56 +674,4 @@ public final class Helper {
|
||||
new SaveViewHistoryTask(viewHistory, dbHelper, null).executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
||||
}
|
||||
}
|
||||
public static String normalizeChannelName(String channelName) {
|
||||
if (Helper.isNullOrEmpty(channelName)) {
|
||||
return "";
|
||||
}
|
||||
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.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -66,7 +65,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";
|
||||
@@ -89,23 +87,13 @@ public final class Lbry {
|
||||
public static final String METHOD_PREFERENCE_GET = "preference_get";
|
||||
public static final String METHOD_PREFERENCE_SET = "preference_set";
|
||||
|
||||
public static final String METHOD_COMMENT_CREATE = "comment_create";
|
||||
|
||||
public static final String METHOD_TXO_LIST = "txo_list";
|
||||
public static final String METHOD_TXO_SPEND = "txo_spend";
|
||||
|
||||
public static final String METHOD_CHANNEL_ABANDON = "channel_abandon";
|
||||
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 final String METHOD_COMMENT_LIST = "comment_list";
|
||||
|
||||
public static KeyStore KEYSTORE;
|
||||
public static boolean SDK_READY = false;
|
||||
|
||||
@@ -379,30 +367,8 @@ public final class Lbry {
|
||||
String releaseTime,
|
||||
int page,
|
||||
int pageSize) {
|
||||
return buildClaimSearchOptions(
|
||||
Collections.singletonList(claimType),
|
||||
anyTags,
|
||||
notTags,
|
||||
channelIds,
|
||||
notChannelIds,
|
||||
orderBy,
|
||||
releaseTime,
|
||||
page,
|
||||
pageSize);
|
||||
}
|
||||
|
||||
public static Map<String, Object> buildClaimSearchOptions(
|
||||
List<String> claimType,
|
||||
List<String> anyTags,
|
||||
List<String> notTags,
|
||||
List<String> channelIds,
|
||||
List<String> notChannelIds,
|
||||
List<String> orderBy,
|
||||
String releaseTime,
|
||||
int page,
|
||||
int pageSize) {
|
||||
Map<String, Object> options = new HashMap<>();
|
||||
if (claimType != null && claimType.size() > 0) {
|
||||
if (!Helper.isNullOrEmpty(claimType)) {
|
||||
options.put("claim_type", claimType);
|
||||
}
|
||||
options.put("no_totals", true);
|
||||
|
||||
@@ -8,7 +8,7 @@ import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
|
||||
public class LbryAnalytics {
|
||||
|
||||
public static final String EVENT_APP_ERROR = "app_error";
|
||||
public static final String EVENT_APP_EXCEPTION = "app_exception";
|
||||
public static final String EVENT_APP_LAUNCH = "app_launch";
|
||||
public static final String EVENT_EMAIL_ADDED = "email_added";
|
||||
public static final String EVENT_EMAIL_VERIFIED = "email_verified";
|
||||
@@ -23,7 +23,6 @@ public class LbryAnalytics {
|
||||
public static final String EVENT_TAG_FOLLOW = "tag_follow";
|
||||
public static final String EVENT_TAG_UNFOLLOW = "tag_unfollow";
|
||||
public static final String EVENT_PUBLISH = "publish";
|
||||
public static final String EVENT_PUBLISH_UPDATE = "publish_update";
|
||||
public static final String EVENT_CHANNEL_CREATE = "channel_create";
|
||||
public static final String EVENT_SEARCH = "search";
|
||||
|
||||
@@ -33,17 +32,8 @@ public class LbryAnalytics {
|
||||
analytics = FirebaseAnalytics.getInstance(context);
|
||||
}
|
||||
|
||||
public static void checkInitAnalytics(Context context) {
|
||||
if (analytics == null && context != null) {
|
||||
analytics = FirebaseAnalytics.getInstance(context);
|
||||
}
|
||||
}
|
||||
|
||||
public static void setCurrentScreen(Activity activity, String name, String className) {
|
||||
checkInitAnalytics(activity);
|
||||
if (analytics != null) {
|
||||
analytics.setCurrentScreen(activity, name, className);
|
||||
}
|
||||
analytics.setCurrentScreen(activity, name, className);
|
||||
}
|
||||
|
||||
public static void logEvent(String name) {
|
||||
@@ -51,15 +41,13 @@ public class LbryAnalytics {
|
||||
}
|
||||
|
||||
public static void logEvent(String name, Bundle bundle) {
|
||||
if (analytics != null) {
|
||||
analytics.logEvent(name, bundle);
|
||||
}
|
||||
analytics.logEvent(name, bundle);
|
||||
}
|
||||
|
||||
public static void logError(String message, String exceptionName) {
|
||||
public static void logException(String message, String exceptionName) {
|
||||
Bundle bundle = new Bundle();
|
||||
bundle.putString("message", message);
|
||||
bundle.putString("name", exceptionName);
|
||||
logEvent(EVENT_APP_ERROR, bundle);
|
||||
logEvent("app_exception", bundle);
|
||||
}
|
||||
}
|
||||
@@ -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) {
|
||||
@@ -66,10 +66,6 @@ public class LbryUri {
|
||||
REGEX_PART_MODIFIER_SEPARATOR));
|
||||
|
||||
String cleanUrl = url, queryString = null;
|
||||
if (Helper.isNullOrEmpty(url)) {
|
||||
throw new LbryUriException("Invalid url parameter.");
|
||||
}
|
||||
|
||||
Matcher qsMatcher = PATTERN_SEPARATE_QUERY_STRING.matcher(url);
|
||||
if (qsMatcher.matches()) {
|
||||
queryString = qsMatcher.group(2);
|
||||
@@ -264,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();
|
||||
}
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ import com.google.gson.Gson;
|
||||
import com.google.gson.GsonBuilder;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@@ -23,9 +24,7 @@ import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import io.lbry.browser.BuildConfig;
|
||||
import io.lbry.browser.MainActivity;
|
||||
import io.lbry.browser.exceptions.LbryioRequestException;
|
||||
import io.lbry.browser.exceptions.LbryioResponseException;
|
||||
@@ -45,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;
|
||||
@@ -82,10 +81,6 @@ public final class Lbryio {
|
||||
authToken = getAuthToken(context);
|
||||
}
|
||||
|
||||
/*if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, String.format("Using authToken for request: %s", authToken));
|
||||
}*/
|
||||
|
||||
String url = String.format("%s/%s/%s", CONNECTION_STRING, resource, action);
|
||||
if (Helper.METHOD_GET.equalsIgnoreCase(method)) {
|
||||
Uri.Builder uriBuilder = Uri.parse(url).buildUpon();
|
||||
@@ -99,9 +94,6 @@ public final class Lbryio {
|
||||
}
|
||||
url = uriBuilder.build().toString();
|
||||
}
|
||||
/*if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, String.format("Request Method: %s, Sending request to URL: %s", method, url));
|
||||
}*/
|
||||
|
||||
Request.Builder builder = new Request.Builder().url(url);
|
||||
if (Helper.METHOD_POST.equalsIgnoreCase(method)) {
|
||||
@@ -110,10 +102,7 @@ public final class Lbryio {
|
||||
}
|
||||
|
||||
Request request = builder.build();
|
||||
OkHttpClient client = new OkHttpClient.Builder().
|
||||
writeTimeout(120, TimeUnit.SECONDS).
|
||||
readTimeout(120, TimeUnit.SECONDS).
|
||||
build();
|
||||
OkHttpClient client = new OkHttpClient();
|
||||
try {
|
||||
return client.newCall(request).execute();
|
||||
} catch (IOException ex) {
|
||||
@@ -132,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 = "&";
|
||||
}
|
||||
}
|
||||
@@ -150,9 +139,6 @@ public final class Lbryio {
|
||||
}
|
||||
|
||||
generatingAuthToken = true;
|
||||
/*if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, "Generating a new auth token");
|
||||
}*/
|
||||
|
||||
Map<String, String> options = new HashMap<>();
|
||||
options.put("auth_token", "");
|
||||
@@ -161,9 +147,6 @@ public final class Lbryio {
|
||||
Response response = Lbryio.call("user", "new", options, "post", context);
|
||||
try {
|
||||
JSONObject json = (JSONObject) parseResponse(response);
|
||||
/*if (BuildConfig.DEBUG) {
|
||||
Log.d(TAG, String.format("/user/new response: %s", json.toString(2)));
|
||||
}*/
|
||||
if (!json.has(AUTH_TOKEN_PARAM)) {
|
||||
throw new LbryioResponseException("auth_token was not set in the response");
|
||||
}
|
||||
@@ -171,7 +154,6 @@ public final class Lbryio {
|
||||
AUTH_TOKEN = json.getString(AUTH_TOKEN_PARAM);
|
||||
broadcastAuthTokenGenerated(context);
|
||||
} catch (JSONException | ClassCastException ex) {
|
||||
LbryAnalytics.logError(String.format("/user/new failed: %s", ex.getMessage()), ex.getClass().getName());
|
||||
throw new LbryioResponseException("auth_token was not set in the response", ex);
|
||||
} finally {
|
||||
generatingAuthToken = false;
|
||||
@@ -211,7 +193,7 @@ public final class Lbryio {
|
||||
User user = gson.fromJson(object.toString(), type);
|
||||
return user;
|
||||
} catch (LbryioRequestException | LbryioResponseException | ClassCastException | IllegalStateException ex) {
|
||||
LbryAnalytics.logError(String.format("/user/me failed: %s", ex.getMessage()), ex.getClass().getName());
|
||||
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);
|
||||
return null;
|
||||
}
|
||||
@@ -230,12 +212,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="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>
|
||||
@@ -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="M17,10.5V7c0,-0.55 -0.45,-1 -1,-1H4c-0.55,0 -1,0.45 -1,1v10c0,0.55 0.45,1 1,1h12c0.55,0 1,-0.45 1,-1v-3.5l4,4v-11l-4,4z"/>
|
||||
</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="M12,5L12,1L7,6l5,5L12,7c3.3,0 6,2.7 6,6s-2.7,6 -6,6 -6,-2.7 -6,-6L4,13c0,4.4 3.6,8 8,8s8,-3.6 8,-8 -3.6,-8 -8,-8zM10.9,16L10,16v-3.3L9,13v-0.7l1.8,-0.6h0.1L10.9,16zM15.2,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.1c0.2,0.1 0.3,0.2 0.5,0.3s0.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="M9,16h6v-6h4l-7,-7 -7,7h4zM5,18h14v2L5,20z"/>
|
||||
</vector>
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 466 B |
Binary file not shown.
|
Before Width: | Height: | Size: 121 B |
Binary file not shown.
|
Before Width: | Height: | Size: 350 B |
Binary file not shown.
|
Before Width: | Height: | Size: 201 B |
Loaded 100 of 181 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user