change launch mode from singleInstance to singleTask

This commit is contained in:
Akinwale Ariwodola 2020-05-14 13:33:27 +01:00
parent 7cf97feb9e
commit fb2b798106
9 changed files with 88 additions and 19 deletions

View file

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

View file

@ -1,6 +1,8 @@
package io.lbry.browser;
import android.annotation.SuppressLint;
import android.app.Activity;
import android.app.ActivityManager;
import android.app.PictureInPictureParams;
import android.content.BroadcastReceiver;
import android.content.Context;
@ -32,6 +34,7 @@ import android.widget.TextView;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.app.AppCompatActivity;
import androidx.constraintlayout.widget.ConstraintLayout;
import androidx.core.app.NavUtils;
import androidx.core.content.ContextCompat;
import androidx.core.widget.NestedScrollView;
import androidx.preference.PreferenceManager;
@ -65,6 +68,7 @@ import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Set;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;
@ -111,6 +115,7 @@ public class FileViewActivity extends AppCompatActivity {
private static final int RELATED_CONTENT_SIZE = 16;
private static boolean startingShareActivity;
private boolean backStackLost;
private boolean loadingNewClaim;
private boolean stopServiceReceived;
private boolean downloadInProgress;
@ -357,7 +362,8 @@ public class FileViewActivity extends AppCompatActivity {
@Override
public void onClick(View view) {
sendBroadcast(new Intent(MainActivity.ACTION_OPEN_WALLET_PAGE));
moveTaskToBack(true);
bringMainTaskToFront();
finish();
}
});
walletBalanceInitialized = true;
@ -444,6 +450,7 @@ public class FileViewActivity extends AppCompatActivity {
protected void onResume() {
super.onResume();
MainActivity.mainActive = false;
MainActivity.startingFileViewActivity = false;
if (Lbry.SDK_READY) {
initFloatingWalletBalance();
@ -657,7 +664,9 @@ public class FileViewActivity extends AppCompatActivity {
Intent intent = new Intent(MainActivity.ACTION_OPEN_CHANNEL_URL);
intent.putExtra("url", !Helper.isNullOrEmpty(publisher.getShortUrl()) ? publisher.getShortUrl() : publisher.getPermanentUrl());
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.putExtra("tag", tag.getName());
sendBroadcast(intent);
moveTaskToBack(true);
bringMainTaskToFront();
finish();
}
}
});
@ -806,7 +816,8 @@ public class FileViewActivity extends AppCompatActivity {
Fee fee = streamMetadata.getFee();
if (fee != null && Helper.parseDouble(fee.getAmount(), 0) > 0) {
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() {
if (claim != null) {
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);
AlertDialog.Builder builder = new AlertDialog.Builder(this).
setTitle(R.string.confirm_purchase).
@ -945,7 +956,8 @@ public class FileViewActivity extends AppCompatActivity {
Bundle bundle = new Bundle();
bundle.putString("uri", currentUrl);
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());
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.putExtra("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
sendBroadcast(intent);
moveTaskToBack(true);
bringMainTaskToFront();
finish();
} else {
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("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
MainActivity.startingFileViewActivity = true;
@ -1214,6 +1228,10 @@ public class FileViewActivity extends AppCompatActivity {
return;
}
bringMainTaskToFront();
}
private void startMainActivity() {
MainActivity.mainActive = true;
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
@ -1229,13 +1247,10 @@ public class FileViewActivity extends AppCompatActivity {
}
protected void onUserLeaveHint() {
if (stopServiceReceived ||
claim == null ||
!claim.isPlayable()) {
if (stopServiceReceived || claim == null || !claim.isPlayable() || !playbackStarted) {
return;
}
if (startingShareActivity) {
// share activity triggered this, so reset the flag at this point
new Handler().postDelayed(new Runnable() {
@ -1293,6 +1308,7 @@ public class FileViewActivity extends AppCompatActivity {
if (isInPictureInPictureMode) {
renderPictureInPictureMode();
} else {
backStackLost = true;
renderFullMode();
}
}
@ -1572,4 +1588,21 @@ public class FileViewActivity extends AppCompatActivity {
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 userActionsReceiver;
private boolean appStarted;
private static boolean appStarted;
private boolean serviceRunning;
private CheckSdkReadyTask checkSdkReadyTask;
private boolean receivedStopService;
@ -377,6 +377,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public void onClick(View view) {
if (nowPlayingClaim != null) {
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("url", nowPlayingClaim.getPermanentUrl());
startingFileViewActivity = true;
@ -561,6 +562,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static void openFileUrl(String url, Context context) {
Intent intent = new Intent(context, FileViewActivity.class);
//intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
intent.putExtra("url", url);
startingFileViewActivity = true;
context.startActivity(intent);
@ -568,6 +570,7 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
public static void openFileClaim(Claim claim, Context context) {
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("url", !Helper.isNullOrEmpty(claim.getShortUrl()) ? claim.getShortUrl() : claim.getPermanentUrl());
startingFileViewActivity = true;
@ -1756,7 +1759,16 @@ public class MainActivity extends AppCompatActivity implements SdkStatusListener
if (specialRouteFragmentClassMap.containsKey(specialPath)) {
Class fragmentClass = specialRouteFragmentClassMap.get(specialPath);
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.utils.Helper;
import io.lbry.browser.utils.LbryUri;
import io.lbry.browser.utils.Lbryio;
import lombok.Getter;
import lombok.Setter;
@ -280,9 +281,9 @@ public class ClaimListAdapter extends RecyclerView.Adapter<ClaimListAdapter.View
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.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.publisherView.setText(signingChannel != null ? signingChannel.getName() : context.getString(R.string.anonymous));
vh.publishTimeView.setText(DateUtils.getRelativeTimeSpanString(

View file

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

View file

@ -451,6 +451,7 @@ public class AllContentFragment extends BaseFragment implements SharedPreference
}
} else {
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("url", url);
MainActivity.startingFileViewActivity = true;

View file

@ -260,6 +260,7 @@ public class ChannelContentFragment extends Fragment implements SharedPreference
}
} else {
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("url", url);
MainActivity.startingFileViewActivity = true;

View file

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

View file

@ -578,6 +578,7 @@ public class FollowingFragment extends BaseFragment implements
}
} else {
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("url", url);
MainActivity.startingFileViewActivity = true;