mirror of
https://github.com/LBRYFoundation/lbry-android.git
synced 2025-08-23 17:47:28 +00:00
* initial native rewrite commit * update gitlab CI script * add printVersionName gradle task * fix Gitlab CI script * Fix first time wallet sync. add Discover dialog to Following page. * Finish Following and All Content views. Add customize your tags view. * Wallet sync get and set preferences, update interval. * Editor's Choice. Reposts. Some ontent page tweaks. * display no related content view when none loaded * Search cache. File view updates. Floating wallet balance. * Send tip dialog. Channel page share and follow/unfollow. * Handle lbry:// url scheme. Properly set URL bar values. SDK 0.71.0. * Channel follow/unfollow fixes. Display stream cost. * Channel management and channel creation / editing * phone number verification and rewards page * add Invites page * tweak player loading and playback when loading new claims * tweak about page layout * display text and markdown content * purchase_uri for free content * don't display invites history if none exist * fix channel list adapters * change launch mode from singleInstance to singleTask * url history and player fixes * Library page. URL and view history. * bumpversion 0.15.0 --> 0.15.1 * Make file view a fragment to prevent headaches with multiple Android task recents * Better handling of file view URLs. Some issue list fixes. * Abandon channels and bulk delete files tasks. Some visual tweaks. * bumpversion 0.15.1 --> 0.15.2 * fix some events * Some visual tweaks. Wunderbar clear focus hotfix for some devices. * sdk 0.74.0. Publish and Publishes pages. * Fix displayed amounts. Send Firebase token with install_new. * Some dark theme and crash fixes. Implement publish form. * Fix minor typo for string in 'generate_address_hint'. * Publish form and publish creation flow. UI tweaks and fixes. * Basic native mobile publishing * remove closeDatabase calls causing crashes * Implement file and channel page delete actions. UI action cleanup. * publish drivers for unresolved file page and featured search result item * show URL suggestions and data network (DHT) settings * Filter own claims from downloads. Fix address input. * fix edit channel crash * fix for possible blank / invalid video thumbnails * adjust minimum deposit. fix channel edit mode. * quick skip and playback speed media controls * change play and pause icons * Fix file size display. Tweak playback speed control. * Add exoplayer mediasession extension. Set player auto attributes. * Inline publish address validation error. Increase image upload request timeout. * fix no related content display * Claim new_android reward. Use canonical_url for share links. * force US locale for amount / bid values sent with sdk requests * Afrikaans and Spanish strings * Add media player error handling policy. Use : in share links. * don't proceed with publish if optimization is in progress.
291 lines
10 KiB
Java
291 lines
10 KiB
Java
package io.lbry.browser.dialog;
|
|
|
|
import android.app.Dialog;
|
|
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.widget.AdapterView;
|
|
import android.widget.EditText;
|
|
import android.widget.ProgressBar;
|
|
import android.widget.TextView;
|
|
|
|
import androidx.appcompat.widget.AppCompatSpinner;
|
|
|
|
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
|
|
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.ArrayList;
|
|
import java.util.List;
|
|
|
|
import io.lbry.browser.MainActivity;
|
|
import io.lbry.browser.R;
|
|
import io.lbry.browser.adapter.InlineChannelSpinnerAdapter;
|
|
import io.lbry.browser.listener.WalletBalanceListener;
|
|
import io.lbry.browser.model.Claim;
|
|
import io.lbry.browser.model.WalletBalance;
|
|
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.StreamRepostTask;
|
|
import io.lbry.browser.utils.Helper;
|
|
import io.lbry.browser.utils.Lbry;
|
|
import io.lbry.browser.utils.LbryUri;
|
|
import lombok.Setter;
|
|
|
|
public class RepostClaimDialogFragment extends BottomSheetDialogFragment implements WalletBalanceListener {
|
|
public static final String TAG = "RepostClaimDialog";
|
|
|
|
private MaterialButton buttonRepost;
|
|
private View linkCancel;
|
|
private TextInputEditText inputDeposit;
|
|
private View inlineBalanceContainer;
|
|
private TextView inlineBalanceValue;
|
|
private ProgressBar repostProgress;
|
|
private TextView textTitle;
|
|
|
|
private AppCompatSpinner channelSpinner;
|
|
private InlineChannelSpinnerAdapter channelSpinnerAdapter;
|
|
private TextView textNamePrefix;
|
|
private EditText inputName;
|
|
private TextView linkToggleAdvanced;
|
|
private View advancedContainer;
|
|
|
|
@Setter
|
|
private RepostClaimListener listener;
|
|
@Setter
|
|
private Claim claim;
|
|
|
|
public static RepostClaimDialogFragment newInstance() {
|
|
return new RepostClaimDialogFragment();
|
|
}
|
|
|
|
@Override
|
|
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
|
View view = inflater.inflate(R.layout.dialog_repost_claim, container, false);
|
|
|
|
buttonRepost = view.findViewById(R.id.repost_button);
|
|
linkCancel = view.findViewById(R.id.repost_cancel_link);
|
|
inputDeposit = view.findViewById(R.id.repost_input_deposit);
|
|
inlineBalanceContainer = view.findViewById(R.id.repost_inline_balance_container);
|
|
inlineBalanceValue = view.findViewById(R.id.repost_inline_balance_value);
|
|
repostProgress = view.findViewById(R.id.repost_progress);
|
|
textTitle = view.findViewById(R.id.repost_title);
|
|
|
|
channelSpinner = view.findViewById(R.id.repost_channel_spinner);
|
|
textNamePrefix = view.findViewById(R.id.repost_name_prefix);
|
|
inputName = view.findViewById(R.id.repost_name_input);
|
|
linkToggleAdvanced = view.findViewById(R.id.repost_toggle_advanced);
|
|
advancedContainer = view.findViewById(R.id.repost_advanced_container);
|
|
|
|
textTitle.setText(getString(R.string.repost_title, claim.getTitle()));
|
|
inputName.setText(claim.getName());
|
|
inputDeposit.setText(R.string.min_deposit);
|
|
channelSpinner.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;
|
|
textNamePrefix.setText(String.format("%s%s/", LbryUri.PROTO_DEFAULT, claim.getName()));
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onNothingSelected(AdapterView<?> adapterView) {
|
|
|
|
}
|
|
});
|
|
|
|
inputDeposit.setOnFocusChangeListener(new View.OnFocusChangeListener() {
|
|
@Override
|
|
public void onFocusChange(View view, boolean hasFocus) {
|
|
inputDeposit.setHint(hasFocus ? getString(R.string.zero) : "");
|
|
inlineBalanceContainer.setVisibility(hasFocus ? View.VISIBLE : View.INVISIBLE);
|
|
}
|
|
});
|
|
|
|
linkCancel.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
dismiss();
|
|
}
|
|
});
|
|
|
|
linkToggleAdvanced.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
if (advancedContainer.getVisibility() != View.VISIBLE) {
|
|
advancedContainer.setVisibility(View.VISIBLE);
|
|
linkToggleAdvanced.setText(R.string.hide_advanced);
|
|
} else {
|
|
advancedContainer.setVisibility(View.GONE);
|
|
linkToggleAdvanced.setText(R.string.show_advanced);
|
|
}
|
|
}
|
|
});
|
|
|
|
buttonRepost.setOnClickListener(new View.OnClickListener() {
|
|
@Override
|
|
public void onClick(View view) {
|
|
validateAndRepostClaim();
|
|
}
|
|
});
|
|
|
|
onWalletBalanceUpdated(Lbry.walletBalance);
|
|
|
|
return view;
|
|
}
|
|
|
|
public void onResume() {
|
|
super.onResume();
|
|
Context context = getContext();
|
|
if (context instanceof MainActivity) {
|
|
((MainActivity) context).addWalletBalanceListener(this);
|
|
}
|
|
fetchChannels();
|
|
}
|
|
|
|
public void onPause() {
|
|
Context context = getContext();
|
|
if (context instanceof MainActivity) {
|
|
((MainActivity) context).removeWalletBalanceListener(this);
|
|
}
|
|
inputDeposit.clearFocus();
|
|
super.onPause();
|
|
}
|
|
|
|
|
|
private void fetchChannels() {
|
|
if (Lbry.ownChannels == null || Lbry.ownChannels.size() == 0) {
|
|
startLoading();
|
|
ClaimListTask task = new ClaimListTask(Claim.TYPE_CHANNEL, repostProgress, new ClaimListResultHandler() {
|
|
@Override
|
|
public void onSuccess(List<Claim> claims) {
|
|
Lbry.ownChannels = new ArrayList<>(claims);
|
|
loadChannels(claims);
|
|
finishLoading();
|
|
}
|
|
|
|
@Override
|
|
public void onError(Exception error) {
|
|
// could not fetch channels
|
|
Context context = getContext();
|
|
if (context instanceof MainActivity) {
|
|
((MainActivity) context).showError(error.getMessage());
|
|
}
|
|
dismiss();
|
|
}
|
|
});
|
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
} else {
|
|
loadChannels(Lbry.ownChannels);
|
|
}
|
|
}
|
|
|
|
private void loadChannels(List<Claim> channels) {
|
|
if (channelSpinnerAdapter == null) {
|
|
Context context = getContext();
|
|
channelSpinnerAdapter = new InlineChannelSpinnerAdapter(context, R.layout.spinner_item_channel, channels);
|
|
channelSpinnerAdapter.notifyDataSetChanged();
|
|
} else {
|
|
channelSpinnerAdapter.clear();
|
|
channelSpinnerAdapter.addAll(channels);
|
|
channelSpinnerAdapter.notifyDataSetChanged();
|
|
}
|
|
if (channelSpinner != null) {
|
|
channelSpinner.setAdapter(channelSpinnerAdapter);
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public void onWalletBalanceUpdated(WalletBalance walletBalance) {
|
|
if (walletBalance != null && inlineBalanceValue != null) {
|
|
inlineBalanceValue.setText(Helper.shortCurrencyFormat(walletBalance.getAvailable().doubleValue()));
|
|
}
|
|
}
|
|
|
|
private void validateAndRepostClaim() {
|
|
String name = Helper.getValue(inputName.getText());
|
|
if (Helper.isNullOrEmpty(name) || !LbryUri.isNameValid(name)) {
|
|
showError(getString(R.string.repost_name_invalid_characters));
|
|
return;
|
|
}
|
|
|
|
String depositString = Helper.getValue(inputDeposit.getText());
|
|
if (Helper.isNullOrEmpty(depositString)) {
|
|
showError(getString(R.string.invalid_amount));
|
|
return;
|
|
}
|
|
|
|
BigDecimal bid = new BigDecimal(depositString);
|
|
if (bid.doubleValue() > Lbry.walletBalance.getAvailable().doubleValue()) {
|
|
showError(getString(R.string.insufficient_balance));
|
|
return;
|
|
}
|
|
|
|
Claim channel = (Claim) channelSpinner.getSelectedItem();
|
|
StreamRepostTask task = new StreamRepostTask(name, bid, claim.getClaimId(), channel.getClaimId(), repostProgress, new ClaimResultHandler() {
|
|
@Override
|
|
public void beforeStart() {
|
|
startLoading();
|
|
}
|
|
|
|
@Override
|
|
public void onSuccess(Claim claimResult) {
|
|
if (listener != null) {
|
|
listener.onClaimReposted(claimResult);
|
|
}
|
|
finishLoading();
|
|
dismiss();
|
|
}
|
|
|
|
@Override
|
|
public void onError(Exception error) {
|
|
showError(error.getMessage());
|
|
finishLoading();
|
|
}
|
|
});
|
|
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR);
|
|
}
|
|
|
|
private void showError(String message) {
|
|
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).
|
|
setBackgroundTint(Color.RED).
|
|
setTextColor(Color.WHITE).
|
|
show();
|
|
}
|
|
|
|
private void startLoading() {
|
|
Dialog dialog = getDialog();
|
|
if (dialog != null) {
|
|
dialog.setCanceledOnTouchOutside(false);
|
|
}
|
|
linkCancel.setEnabled(false);
|
|
buttonRepost.setEnabled(false);
|
|
inputName.setEnabled(false);
|
|
channelSpinner.setEnabled(false);
|
|
linkToggleAdvanced.setVisibility(View.INVISIBLE);
|
|
}
|
|
private void finishLoading() {
|
|
Dialog dialog = getDialog();
|
|
if (dialog != null) {
|
|
dialog.setCanceledOnTouchOutside(true);
|
|
}
|
|
linkCancel.setEnabled(true);
|
|
buttonRepost.setEnabled(true);
|
|
inputName.setEnabled(true);
|
|
channelSpinner.setEnabled(true);
|
|
linkToggleAdvanced.setVisibility(View.VISIBLE);
|
|
}
|
|
|
|
public interface RepostClaimListener {
|
|
void onClaimReposted(Claim claim);
|
|
}
|
|
}
|