Add background playback setting. Fix crash bugs.
This commit is contained in:
parent
084407e129
commit
8bcee90d68
16 changed files with 199 additions and 138 deletions
|
@ -265,6 +265,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
|
|||
public static final String ACTION_SAVE_SHARED_USER_STATE = "io.lbry.browser.Broadcast.SaveSharedUserState";
|
||||
|
||||
// preference keys
|
||||
public static final String PREFERENCE_KEY_BACKGROUND_PLAYBACK = "io.lbry.browser.preference.userinterface.BackgroundPlayback";
|
||||
public static final String PREFERENCE_KEY_DARK_MODE = "io.lbry.browser.preference.userinterface.DarkMode";
|
||||
public static final String PREFERENCE_KEY_SHOW_MATURE_CONTENT = "io.lbry.browser.preference.userinterface.ShowMatureContent";
|
||||
public static final String PREFERENCE_KEY_SHOW_URL_SUGGESTIONS = "io.lbry.browser.preference.userinterface.UrlSuggestions";
|
||||
|
|
|
@ -569,7 +569,11 @@ public class ChannelCommentsFragment extends Fragment implements SdkStatusListen
|
|||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
showError(error.getMessage());
|
||||
try {
|
||||
showError(error != null ? error.getMessage() : getString(R.string.comment_error));
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
afterPostComment();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -259,7 +259,9 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
|||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
if (contentListAdapter == null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, context);
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
|
@ -275,6 +277,7 @@ public class ChannelContentFragment extends Fragment implements DownloadActionLi
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
|
|
|
@ -180,10 +180,13 @@ public class ChannelFragment extends BaseFragment implements FetchChannelsListen
|
|||
@Override
|
||||
public void onTipSent(BigDecimal amount) {
|
||||
double sentAmount = amount.doubleValue();
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
String message = getResources().getQuantityString(
|
||||
R.plurals.you_sent_a_tip, sentAmount == 1.0 ? 1 : 2,
|
||||
new DecimalFormat("#,###.##").format(sentAmount));
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).show();
|
||||
Snackbar.make(view, message, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
}
|
||||
});
|
||||
Context context = getContext();
|
||||
|
|
|
@ -149,8 +149,9 @@ public class ChannelManagerFragment extends BaseFragment implements ActionMode.C
|
|||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
Lbry.ownChannels = Helper.filterDeletedClaims(new ArrayList<>(claims));
|
||||
Context context = getContext();
|
||||
if (adapter == null) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
adapter = new ClaimListAdapter(claims, context);
|
||||
adapter.setCanEnterSelectionMode(true);
|
||||
adapter.setSelectionModeListener(ChannelManagerFragment.this);
|
||||
|
@ -165,6 +166,7 @@ public class ChannelManagerFragment extends BaseFragment implements ActionMode.C
|
|||
if (channelList != null) {
|
||||
channelList.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
adapter.setItems(claims);
|
||||
}
|
||||
|
|
|
@ -446,7 +446,9 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
|||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
if (contentListAdapter == null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, context);
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
|
@ -462,6 +464,7 @@ public class AllContentFragment extends BaseFragment implements DownloadActionLi
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
|
|
|
@ -1719,12 +1719,15 @@ public class FileViewFragment extends BaseFragment implements
|
|||
Fee fee = ((Claim.StreamMetadata) claim.getValue()).getFee();
|
||||
double cost = claim.getActualCost(Lbryio.LBCUSDRate).doubleValue();
|
||||
String formattedCost = Helper.LBC_CURRENCY_FORMAT.format(cost);
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
try {
|
||||
String message = getResources().getQuantityString(
|
||||
R.plurals.confirm_purchase_message,
|
||||
cost == 1 ? 1 : 2,
|
||||
claim.getTitle(),
|
||||
formattedCost.equals("0") ? Helper.FULL_LBC_CURRENCY_FORMAT.format(cost) : formattedCost);
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context).
|
||||
setTitle(R.string.confirm_purchase).
|
||||
setMessage(message)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
|
@ -1738,12 +1741,19 @@ public class FileViewFragment extends BaseFragment implements
|
|||
bundle.putString("currency", fee.getCurrency());
|
||||
LbryAnalytics.logEvent(LbryAnalytics.EVENT_PURCHASE_URI, bundle);
|
||||
|
||||
getView().findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
|
||||
getView().findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
|
||||
View root = getView();
|
||||
if (root != null) {
|
||||
root.findViewById(R.id.file_view_main_action_button).setVisibility(View.INVISIBLE);
|
||||
root.findViewById(R.id.file_view_main_action_loading).setVisibility(View.VISIBLE);
|
||||
}
|
||||
handleMainActionForClaim();
|
||||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2973,7 +2983,11 @@ public class FileViewFragment extends BaseFragment implements
|
|||
|
||||
@Override
|
||||
public void onError(Exception error) {
|
||||
showError(error.getMessage());
|
||||
try {
|
||||
showError(error != null ? error.getMessage() : getString(R.string.comment_error));
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
afterPostComment();
|
||||
}
|
||||
});
|
||||
|
|
|
@ -598,7 +598,9 @@ public class FollowingFragment extends BaseFragment implements
|
|||
@Override
|
||||
public void onSuccess(List<Claim> claims, boolean hasReachedEnd) {
|
||||
if (contentListAdapter == null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, context);
|
||||
contentListAdapter.setListener(new ClaimListAdapter.ClaimListItemListener() {
|
||||
@Override
|
||||
public void onClaimClicked(Claim claim) {
|
||||
|
@ -614,6 +616,7 @@ public class FollowingFragment extends BaseFragment implements
|
|||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
|
|
|
@ -192,7 +192,7 @@ public class SearchFragment extends BaseFragment implements
|
|||
}
|
||||
if (resolved.isMature() && !canShowMatureContent) {
|
||||
resultListAdapter.removeFeaturedItem();
|
||||
} else {
|
||||
} else if (unresolved != null) {
|
||||
// only set the values we need
|
||||
unresolved.setClaimId(resolved.getClaimId());
|
||||
unresolved.setName(resolved.getName());
|
||||
|
|
|
@ -352,7 +352,9 @@ public class LibraryFragment extends BaseFragment implements
|
|||
}
|
||||
|
||||
private void initContentListAdapter(List<Claim> claims) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, getContext());
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
contentListAdapter = new ClaimListAdapter(claims, context);
|
||||
contentListAdapter.setCanEnterSelectionMode(currentFilter == FILTER_DOWNLOADS);
|
||||
contentListAdapter.setSelectionModeListener(this);
|
||||
contentListAdapter.setHideFee(currentFilter != FILTER_PURCHASES);
|
||||
|
@ -361,7 +363,7 @@ public class LibraryFragment extends BaseFragment implements
|
|||
public void onClaimClicked(Claim claim) {
|
||||
Context context = getContext();
|
||||
if (context instanceof MainActivity) {
|
||||
MainActivity activity = (MainActivity) getContext();
|
||||
MainActivity activity = (MainActivity) context;
|
||||
if (claim.getName().startsWith("@")) {
|
||||
activity.openChannelUrl(claim.getPermanentUrl());
|
||||
} else {
|
||||
|
@ -371,6 +373,7 @@ public class LibraryFragment extends BaseFragment implements
|
|||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
private void fetchDownloads() {
|
||||
contentListLoading = true;
|
||||
|
@ -391,7 +394,7 @@ public class LibraryFragment extends BaseFragment implements
|
|||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
if (contentListAdapter != null && contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
resolveMissingChannelNames(buildUrlsToResolve(claims));
|
||||
|
@ -423,7 +426,7 @@ public class LibraryFragment extends BaseFragment implements
|
|||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
if (contentListAdapter != null && contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
checkListEmpty();
|
||||
|
@ -459,7 +462,7 @@ public class LibraryFragment extends BaseFragment implements
|
|||
} else {
|
||||
contentListAdapter.addItems(claims);
|
||||
}
|
||||
if (contentList.getAdapter() == null) {
|
||||
if (contentListAdapter != null && contentList.getAdapter() == null) {
|
||||
contentList.setAdapter(contentListAdapter);
|
||||
}
|
||||
checkListEmpty();
|
||||
|
@ -637,9 +640,11 @@ public class LibraryFragment extends BaseFragment implements
|
|||
public boolean onActionItemClicked(androidx.appcompat.view.ActionMode actionMode, MenuItem menuItem) {
|
||||
if (R.id.action_delete == menuItem.getItemId()) {
|
||||
if (contentListAdapter != null && contentListAdapter.getSelectedCount() > 0) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
final List<Claim> selectedClaims = new ArrayList<>(contentListAdapter.getSelectedItems());
|
||||
String message = getResources().getQuantityString(R.plurals.confirm_delete_files, selectedClaims.size());
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(getContext()).
|
||||
AlertDialog.Builder builder = new AlertDialog.Builder(context).
|
||||
setTitle(R.string.delete_selection).
|
||||
setMessage(message)
|
||||
.setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
|
||||
|
@ -649,6 +654,7 @@ public class LibraryFragment extends BaseFragment implements
|
|||
}
|
||||
}).setNegativeButton(R.string.no, null);
|
||||
builder.show();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -728,7 +728,10 @@ public class PublishFormFragment extends BaseFragment implements
|
|||
|
||||
private void uploadThumbnail(String thumbnailPath) {
|
||||
if (uploading) {
|
||||
Snackbar.make(getView(), R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
Snackbar.make(view, R.string.wait_for_upload, Snackbar.LENGTH_LONG).show();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -1294,7 +1297,11 @@ public class PublishFormFragment extends BaseFragment implements
|
|||
@Override
|
||||
public void onStoragePermissionRefused() {
|
||||
if (!storageRefusedOnce) {
|
||||
try {
|
||||
showError(getString(R.string.storage_permission_rationale_images));
|
||||
} catch (IllegalStateException ex) {
|
||||
// pass
|
||||
}
|
||||
storageRefusedOnce = true;
|
||||
}
|
||||
launchPickerPending = false;
|
||||
|
|
|
@ -151,8 +151,9 @@ public class PublishesFragment extends BaseFragment implements ActionMode.Callba
|
|||
@Override
|
||||
public void onSuccess(List<Claim> claims) {
|
||||
Lbry.ownClaims = Helper.filterDeletedClaims(new ArrayList<>(claims));
|
||||
Context context = getContext();
|
||||
if (adapter == null) {
|
||||
Context context = getContext();
|
||||
if (context != null) {
|
||||
adapter = new ClaimListAdapter(claims, context);
|
||||
adapter.setCanEnterSelectionMode(true);
|
||||
adapter.setSelectionModeListener(PublishesFragment.this);
|
||||
|
@ -172,6 +173,7 @@ public class PublishesFragment extends BaseFragment implements ActionMode.Callba
|
|||
if (contentList != null) {
|
||||
contentList.setAdapter(adapter);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
adapter.setItems(claims);
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ 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;
|
||||
|
@ -243,8 +244,10 @@ public class WalletVerificationFragment extends Fragment {
|
|||
}
|
||||
|
||||
private void showError(String message) {
|
||||
Snackbar.make(getView(), message, Snackbar.LENGTH_LONG).setBackgroundTint(
|
||||
getResources().getColor(R.color.red)
|
||||
).show();
|
||||
View view = getView();
|
||||
if (view != null) {
|
||||
Snackbar.make(view, message, Snackbar.LENGTH_LONG).
|
||||
setBackgroundTint(Color.RED).setTextColor(Color.WHITE).show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -552,7 +552,11 @@ public final class Helper {
|
|||
split[1]
|
||||
};
|
||||
|
||||
try {
|
||||
return getDataColumn(context, contentUri, selection, selectionArgs);
|
||||
} catch (Exception ex) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
// MediaStore (and general)
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
<string name="comments">Comments</string>
|
||||
<string name="no_comments">No comments to display at this time.</string>
|
||||
<string name="sdk_initializing_comments">Comments will display after the background service is initialized.</string>
|
||||
<string name="comment_error">Your comment could not be posted at this time. Please try again later.</string>
|
||||
<string name="share_lbry_content">Share LBRY content</string>
|
||||
<string name="view">View</string>
|
||||
<string name="play">Play</string>
|
||||
|
@ -233,6 +234,7 @@
|
|||
<!-- Settings -->
|
||||
<string name="user_interface">Content & User interface</string>
|
||||
<string name="other">Other</string>
|
||||
<string name="enable_background_playback">Enable background playback</string>
|
||||
<string name="enable_dark_mode">Enable dark theme</string>
|
||||
<string name="show_mature_content">Show mature content</string>
|
||||
<string name="show_url_suggestions">Show URL suggestions</string>
|
||||
|
|
|
@ -5,6 +5,10 @@
|
|||
<PreferenceCategory
|
||||
android:title="@string/user_interface"
|
||||
app:iconSpaceReserved="false">
|
||||
<SwitchPreferenceCompat
|
||||
app:key="io.lbry.browser.preference.userinterface.BackgroundPlayback"
|
||||
app:title="@string/enable_background_playback"
|
||||
app:iconSpaceReserved="false" />
|
||||
<SwitchPreferenceCompat
|
||||
app:key="io.lbry.browser.preference.userinterface.DarkMode"
|
||||
app:title="@string/enable_dark_mode"
|
||||
|
|
Loading…
Reference in a new issue