Native rewrite #878

Merged
akinwale merged 65 commits from native-rewrite into master 2020-05-23 08:49:00 +02:00
9 changed files with 88 additions and 19 deletions
Showing only changes of commit fb2b798106 - Show all commits

View file

@ -38,7 +38,7 @@
android:label="@string/app_name" android:label="@string/app_name"
android:supportsPictureInPicture="true" android:supportsPictureInPicture="true"
android:theme="@style/AppTheme.NoActionBar" android:theme="@style/AppTheme.NoActionBar"
android:launchMode="singleInstance" android:launchMode="singleTask"
android:windowSoftInputMode="adjustPan"> android:windowSoftInputMode="adjustPan">
<intent-filter> <intent-filter>
<action android:name="android.intent.action.MAIN" /> <action android:name="android.intent.action.MAIN" />
@ -55,19 +55,19 @@
<activity <activity
android:name=".FirstRunActivity" android:name=".FirstRunActivity"
android:launchMode="singleInstance" android:launchMode="singleTask"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBarTranslucent" /> android:theme="@style/AppTheme.NoActionBarTranslucent" />
<activity <activity
android:name=".VerificationActivity" android:name=".VerificationActivity"
android:launchMode="singleInstance" android:launchMode="singleTask"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:theme="@style/AppTheme.NoActionBarTranslucent" android:theme="@style/AppTheme.NoActionBarTranslucent"
android:windowSoftInputMode="adjustResize" /> android:windowSoftInputMode="adjustResize" />
<activity <activity
android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout" android:configChanges="orientation|keyboardHidden|screenSize|smallestScreenSize|screenLayout"
android:name=".FileViewActivity" android:name=".FileViewActivity"
android:launchMode="singleInstance" android:launchMode="singleTask"
android:parentActivityName=".MainActivity" android:parentActivityName=".MainActivity"
android:supportsPictureInPicture="true" android:supportsPictureInPicture="true"
android:theme="@style/AppTheme.NoActionBarBlack" /> android:theme="@style/AppTheme.NoActionBarBlack" />

View file

@ -1,6 +1,8 @@
package io.lbry.browser; package io.lbry.browser;
import android.annotation.SuppressLint; import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.PictureInPictureParams; import android.app.PictureInPictureParams;
import android.content.BroadcastReceiver; import android.content.BroadcastReceiver;
import android.content.Context; import android.content.Context;
@ -32,6 +34,7 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog; import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity; import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout; import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.NavUtils;
import androidx.core.content.ContextCompat; import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView; import androidx.core.widget.NestedScrollView;
import androidx.preference.PreferenceManager; import androidx.preference.PreferenceManager;
@ -65,6 +68,7 @@ import java.text.NumberFormat;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
@ -111,6 +115,7 @@ public class FileViewActivity extends AppCompatActivity {
private static final int RELATED_CONTENT_SIZE = 16; private static final int RELATED_CONTENT_SIZE = 16;
private static boolean startingShareActivity; private static boolean startingShareActivity;
private boolean backStackLost;
private boolean loadingNewClaim; private boolean loadingNewClaim;
private boolean stopServiceReceived; private boolean stopServiceReceived;
private boolean downloadInProgress; private boolean downloadInProgress;
@ -357,7 +362,8 @@ public class FileViewActivity extends AppCompatActivity {
@Override @Override
public void onClick(View view) { public void onClick(View view) {
sendBroadcast(new Intent(MainActivity.ACTION_OPEN_WALLET_PAGE)); sendBroadcast(new Intent(MainActivity.ACTION_OPEN_WALLET_PAGE));
moveTaskToBack(true); bringMainTaskToFront();
finish();
} }
}); });
walletBalanceInitialized = true; walletBalanceInitialized = true;
@ -444,6 +450,7 @@ public class FileViewActivity extends AppCompatActivity {
protected void onResume() { protected void onResume() {
super.onResume(); super.onResume();
MainActivity.mainActive = false;
MainActivity.startingFileViewActivity = false; MainActivity.startingFileViewActivity = false;
if (Lbry.SDK_READY) { if (Lbry.SDK_READY) {
initFloatingWalletBalance(); initFloatingWalletBalance();
@ -657,7 +664,9 @@ public class FileViewActivity extends AppCompatActivity {
Intent intent = new Intent(MainActivity.ACTION_OPEN_CHANNEL_URL); Intent intent = new Intent(MainActivity.ACTION_OPEN_CHANNEL_URL);
intent.putExtra("url", !Helper.isNullOrEmpty(publisher.getShortUrl()) ? publisher.getShortUrl() : publisher.getPermanentUrl()); intent.putExtra("url", !Helper.isNullOrEmpty(publisher.getShortUrl()) ? publisher.getShortUrl() : publisher.getPermanentUrl());
sendBroadcast(intent); sendBroadcast(intent);
moveTaskToBack(true);
bringMainTaskToFront();
finish();
} }
} }
}); });
@ -765,7 +774,8 @@ public class FileViewActivity extends AppCompatActivity {
Intent intent = new Intent(MainActivity.ACTION_OPEN_ALL_CONTENT_TAG); Intent intent = new Intent(MainActivity.ACTION_OPEN_ALL_CONTENT_TAG);
intent.putExtra("tag", tag.getName()); intent.putExtra("tag", tag.getName());
sendBroadcast(intent); sendBroadcast(intent);
moveTaskToBack(true); bringMainTaskToFront();
finish();
} }
} }
}); });
@ -806,7 +816,8 @@ public class FileViewActivity extends AppCompatActivity {
Fee fee = streamMetadata.getFee(); Fee fee = streamMetadata.getFee();
if (fee != null && Helper.parseDouble(fee.getAmount(), 0) > 0) { if (fee != null && Helper.parseDouble(fee.getAmount(), 0) > 0) {
findViewById(R.id.file_view_fee_container).setVisibility(View.VISIBLE); findViewById(R.id.file_view_fee_container).setVisibility(View.VISIBLE);
((TextView) findViewById(R.id.file_view_fee)).setText(Helper.shortCurrencyFormat(Helper.parseDouble(fee.getAmount(), 0))); ((TextView) findViewById(R.id.file_view_fee)).setText(
Helper.shortCurrencyFormat(claim.getActualCost(Lbryio.LBCUSDRate).divide(new BigDecimal(100000000)).doubleValue()));
} }
} }
@ -934,7 +945,7 @@ public class FileViewActivity extends AppCompatActivity {
private void confirmPurchaseUrl() { private void confirmPurchaseUrl() {
if (claim != null) { if (claim != null) {
Fee fee = ((Claim.StreamMetadata) claim.getValue()).getFee(); Fee fee = ((Claim.StreamMetadata) claim.getValue()).getFee();
double cost = Helper.parseDouble(fee.getAmount(), 0); double cost = claim.getActualCost(Lbryio.LBCUSDRate).doubleValue();
String message = getResources().getQuantityString(R.plurals.confirm_purchase_message, cost == 1 ? 1 : 2, claim.getTitle(), cost); String message = getResources().getQuantityString(R.plurals.confirm_purchase_message, cost == 1 ? 1 : 2, claim.getTitle(), cost);
AlertDialog.Builder builder = new AlertDialog.Builder(this). AlertDialog.Builder builder = new AlertDialog.Builder(this).
setTitle(R.string.confirm_purchase). setTitle(R.string.confirm_purchase).
@ -945,7 +956,8 @@ public class FileViewActivity extends AppCompatActivity {
Bundle bundle = new Bundle(); Bundle bundle = new Bundle();
bundle.putString("uri", currentUrl); bundle.putString("uri", currentUrl);
bundle.putBoolean("paid", true); bundle.putBoolean("paid", true);
bundle.putDouble("amount", cost); bundle.putDouble("amount", Helper.parseDouble(fee.getAmount(), 0));
bundle.putDouble("lbc_amount", cost);
bundle.putString("currency", fee.getCurrency()); bundle.putString("currency", fee.getCurrency());
LbryAnalytics.logEvent(LbryAnalytics.EVENT_PURCHASE_URI, bundle); LbryAnalytics.logEvent(LbryAnalytics.EVENT_PURCHASE_URI, bundle);
@ -1169,9 +1181,11 @@ public class FileViewActivity extends AppCompatActivity {
Intent intent = new Intent(MainActivity.ACTION_OPEN_CHANNEL_URL); Intent intent = new Intent(MainActivity.ACTION_OPEN_CHANNEL_URL);
intent.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl()); intent.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
sendBroadcast(intent); sendBroadcast(intent);
moveTaskToBack(true); bringMainTaskToFront();
finish();
} else { } else {
Intent intent = new Intent(FileViewActivity.this, FileViewActivity.class); Intent intent = new Intent(FileViewActivity.this, FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("claimId", claim.getClaimId()); intent.putExtra("claimId", claim.getClaimId());
intent.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl()); intent.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
MainActivity.startingFileViewActivity = true; MainActivity.startingFileViewActivity = true;
@ -1214,6 +1228,10 @@ public class FileViewActivity extends AppCompatActivity {
return; return;
} }
bringMainTaskToFront();
}
private void startMainActivity() {
MainActivity.mainActive = true; MainActivity.mainActive = true;
Intent intent = new Intent(this, MainActivity.class); Intent intent = new Intent(this, MainActivity.class);
startActivity(intent); startActivity(intent);
@ -1229,13 +1247,10 @@ public class FileViewActivity extends AppCompatActivity {
} }
protected void onUserLeaveHint() { protected void onUserLeaveHint() {
if (stopServiceReceived || if (stopServiceReceived || claim == null || !claim.isPlayable() || !playbackStarted) {
claim == null ||
!claim.isPlayable()) {
return; return;
} }
if (startingShareActivity) { if (startingShareActivity) {
// share activity triggered this, so reset the flag at this point // share activity triggered this, so reset the flag at this point
new Handler().postDelayed(new Runnable() { new Handler().postDelayed(new Runnable() {
@ -1293,6 +1308,7 @@ public class FileViewActivity extends AppCompatActivity {
if (isInPictureInPictureMode) { if (isInPictureInPictureMode) {
renderPictureInPictureMode(); renderPictureInPictureMode();
} else { } else {
backStackLost = true;
renderFullMode(); renderFullMode();
} }
} }
@ -1572,4 +1588,21 @@ public class FileViewActivity extends AppCompatActivity {
return true; return true;
} }
} }
private void bringMainTaskToFront() {
if (backStackLost) {
ActivityManager activityManager = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
final List<ActivityManager.AppTask> appTasks = activityManager.getAppTasks();
for (ActivityManager.AppTask task : appTasks) {
final Intent baseIntent = task.getTaskInfo().baseIntent;
final Set<String> categories = baseIntent.getCategories();
if (categories != null && categories.contains(Intent.CATEGORY_LAUNCHER)) {
task.moveToFront();
return;
}
}
}
startMainActivity();
}
} }

View file

@ -233,7 +233,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
private BroadcastReceiver requestsReceiver; private BroadcastReceiver requestsReceiver;
private BroadcastReceiver userActionsReceiver; private BroadcastReceiver userActionsReceiver;
private boolean appStarted; private static boolean appStarted;
private boolean serviceRunning; private boolean serviceRunning;
private CheckSdkReadyTask checkSdkReadyTask; private CheckSdkReadyTask checkSdkReadyTask;
private boolean receivedStopService; private boolean receivedStopService;
@ -377,6 +377,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void onClick(View view) { public void onClick(View view) {
if (nowPlayingClaim != null) { if (nowPlayingClaim != null) {
Intent intent = new Intent(MainActivity.this, FileViewActivity.class); Intent intent = new Intent(MainActivity.this, FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("claimId", nowPlayingClaim.getClaimId()); intent.putExtra("claimId", nowPlayingClaim.getClaimId());
intent.putExtra("url", nowPlayingClaim.getPermanentUrl()); intent.putExtra("url", nowPlayingClaim.getPermanentUrl());
startingFileViewActivity = true; startingFileViewActivity = true;
@ -561,6 +562,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static void openFileUrl(String url, Context context) { public static void openFileUrl(String url, Context context) {
Intent intent = new Intent(context, FileViewActivity.class); Intent intent = new Intent(context, FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("url", url); intent.putExtra("url", url);
startingFileViewActivity = true; startingFileViewActivity = true;
context.startActivity(intent); context.startActivity(intent);
@ -568,6 +570,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static void openFileClaim(Claim claim, Context context) { public static void openFileClaim(Claim claim, Context context) {
Intent intent = new Intent(context, FileViewActivity.class); Intent intent = new Intent(context, FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("claimId", claim.getClaimId()); intent.putExtra("claimId", claim.getClaimId());
intent.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl()); intent.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
startingFileViewActivity = true; startingFileViewActivity = true;
@ -1756,7 +1759,16 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
if (specialRouteFragmentClassMap.containsKey(specialPath)) { if (specialRouteFragmentClassMap.containsKey(specialPath)) {
Class fragmentClass = specialRouteFragmentClassMap.get(specialPath); Class fragmentClass = specialRouteFragmentClassMap.get(specialPath);
if (fragmentClassNavIdMap.containsKey(fragmentClass)) { if (fragmentClassNavIdMap.containsKey(fragmentClass)) {
openFragment(specialRouteFragmentClassMap.get(specialPath), true, fragmentClassNavIdMap.get(fragmentClass)); Map<String, Object> params = new HashMap<>();
String tag = intent.getStringExtra("tag");
params.put("singleTag", tag);
openFragment(
specialRouteFragmentClassMap.get(specialPath),
true,
fragmentClassNavIdMap.get(fragmentClass),
!Helper.isNullOrEmpty(tag) ? params : null
);
} }
} }

View file

@ -24,6 +24,7 @@ import io.lbry.browser.listener.SelectionModeListener;
import io.lbry.browser.model.Claim; import io.lbry.browser.model.Claim;
import io.lbry.browser.utils.Helper; import io.lbry.browser.utils.Helper;
import io.lbry.browser.utils.LbryUri; import io.lbry.browser.utils.LbryUri;
import io.lbry.browser.utils.Lbryio;
import lombok.Getter; import lombok.Getter;
import lombok.Setter; import lombok.Setter;
@ -280,9 +281,9 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
into(vh.thumbnailView); into(vh.thumbnailView);
} }
BigDecimal cost = streamMetadata != null && streamMetadata.getFee() != null ? new BigDecimal(streamMetadata.getFee().getAmount()) : new BigDecimal(0); BigDecimal cost = item.getActualCost(Lbryio.LBCUSDRate);
vh.feeContainer.setVisibility(cost.doubleValue() > 0 ? View.VISIBLE : View.GONE); vh.feeContainer.setVisibility(cost.doubleValue() > 0 ? View.VISIBLE : View.GONE);
vh.feeView.setText(cost.doubleValue() > 0 ? Helper.shortCurrencyFormat(cost.divide(new BigDecimal(100000000)).doubleValue()) : null); vh.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.alphaView.setText(item.getName().substring(0, Math.min(5, item.getName().length() - 1)));
vh.publisherView.setText(signingChannel != null ? signingChannel.getName() : context.getString(R.string.anonymous)); vh.publisherView.setText(signingChannel != null ? signingChannel.getName() : context.getString(R.string.anonymous));
vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString( vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(

View file

@ -9,6 +9,7 @@ import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.lang.reflect.Type; import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.ArrayList; import java.util.ArrayList;
@ -101,6 +102,24 @@ public class Claim {
return fee == null || Helper.parseDouble(fee.getAmount(), 0) == 0; return fee == null || Helper.parseDouble(fee.getAmount(), 0) == 0;
} }
public BigDecimal getActualCost(double usdRate) {
if (!(value instanceof StreamMetadata)) {
return new BigDecimal(0);
}
Fee fee = ((StreamMetadata) value).getFee();
if (fee != null) {
double amount = Helper.parseDouble(fee.getAmount(), 0);
if ("usd".equalsIgnoreCase(fee.getCurrency())) {
return new BigDecimal(String.valueOf(amount / usdRate)).multiply(new BigDecimal(100000000)); // deweys
}
return new BigDecimal(String.valueOf(amount));
}
return new BigDecimal(0);
}
public String getMediaType() { public String getMediaType() {
if (value instanceof StreamMetadata) { if (value instanceof StreamMetadata) {
StreamMetadata metadata = (StreamMetadata) value; StreamMetadata metadata = (StreamMetadata) value;

View file

@ -451,6 +451,7 @@ public class AllContentFragment extends BaseFragment implements SharedPreference
} }
} else { } else {
Intent intent = new Intent(getContext(), FileViewActivity.class); Intent intent = new Intent(getContext(), FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("claimId", claimId); intent.putExtra("claimId", claimId);
intent.putExtra("url", url); intent.putExtra("url", url);
MainActivity.startingFileViewActivity = true; MainActivity.startingFileViewActivity = true;

View file

@ -260,6 +260,7 @@ public class ChannelContentFragment extends Fragment implements SharedPreference
} }
} else { } else {
Intent intent = new Intent(getContext(), FileViewActivity.class); Intent intent = new Intent(getContext(), FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("claimId", claimId); intent.putExtra("claimId", claimId);
intent.putExtra("url", url); intent.putExtra("url", url);
MainActivity.startingFileViewActivity = true; MainActivity.startingFileViewActivity = true;

View file

@ -118,6 +118,7 @@ public class EditorsChoiceFragment extends BaseFragment {
String url = item.getPermanentUrl(); String url = item.getPermanentUrl();
Intent intent = new Intent(getContext(), FileViewActivity.class); Intent intent = new Intent(getContext(), FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("url", url); intent.putExtra("url", url);
MainActivity.startingFileViewActivity = true; MainActivity.startingFileViewActivity = true;
startActivity(intent); startActivity(intent);

View file

@ -578,6 +578,7 @@ public class FollowingFragment extends BaseFragment implements
} }
} else { } else {
Intent intent = new Intent(getContext(), FileViewActivity.class); Intent intent = new Intent(getContext(), FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("claimId", claimId); intent.putExtra("claimId", claimId);
intent.putExtra("url", url); intent.putExtra("url", url);
MainActivity.startingFileViewActivity = true; MainActivity.startingFileViewActivity = true;