Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
Merge branch 'prerelease' into release
Browse files Browse the repository at this point in the history
  • Loading branch information
Zorica Stojchevska committed May 28, 2021
2 parents 7b17a4d + 0d0564a commit 9772159
Show file tree
Hide file tree
Showing 58 changed files with 46 additions and 1,141 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ app/src/beta/google-services.json
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries/**
.idea/assetWizardSettings.xml
# Do not exclude project Dictionary
!.idea/**/dictionaries/project.xml
.idea/**/shelf
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@
<activity
android:name=".activities.UpsellingActivity"
android:exported="false"
android:label="@string/upgrade_donate"
android:label="@string/upgrade"
android:screenOrientation="portrait"
android:windowSoftInputMode="stateHidden|adjustPan" />
<activity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import ch.protonmail.android.core.ProtonMailApplication;
import ch.protonmail.android.events.LogoutEvent;
import ch.protonmail.android.jobs.CheckUsernameAvailableJob;
import ch.protonmail.android.jobs.DonateJob;
import ch.protonmail.android.jobs.GetCurrenciesPlansJob;
import ch.protonmail.android.utils.AppUtil;
import ch.protonmail.android.utils.UiUtil;
Expand Down Expand Up @@ -262,12 +261,6 @@ public void onPaymentOptionChosen(Constants.CurrencyType currency, int amount, S
// TODO: payment
}

@Override
public void donateForPaymentToken(int amount, Constants.CurrencyType currency, String paymentToken) {
DonateJob job = new DonateJob(paymentToken, amount, currency);
mJobManager.addJobInBackground(job);
}

@Override
public Constants.CurrencyType getCurrency() {
return currency;
Expand Down Expand Up @@ -330,15 +323,6 @@ public void replaceFragment(Fragment fragment, String backstackName) {
// noop
}

@Override
public void donateDone() {
Intent intent = new Intent();
intent.putExtra(EXTRA_SUCCESS, true);
setResult(RESULT_OK, intent);
saveLastInteraction();
finish();
}

@Override
public void getAvailableDomains() {
// noop
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ abstract class NavigationActivity :
if (hasPin) {
add(Primary.Static(Type.LOCK, R.string.lock_the_app, R.drawable.notification_icon))
}
add(Primary.Static(Type.UPSELLING, R.string.upselling, R.drawable.cubes))
add(Primary.Static(Type.UPSELLING, R.string.upgrade, R.drawable.cubes))
add(Primary.Static(Type.SIGNOUT, R.string.logout, R.drawable.signout))
}.toList()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,16 @@

import android.app.AlertDialog;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.MenuItem;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.TextView;
import android.widget.Toast;

import androidx.appcompat.app.ActionBar;
import androidx.lifecycle.ViewModelProvider;
Expand Down Expand Up @@ -73,37 +69,20 @@
public class UpsellingActivity extends BaseActivity {

public static final String EXTRA_OPEN_UPGRADE_CONTAINER = "EXTRA_OPEN_UPGRADE";
private static final int REQUEST_CODE_DONATE = 1;
private static final int REQUEST_CODE_UPGRADE = 2;

@BindView(R.id.upgrade_container)
View upgradeContainer;
@BindView(R.id.donate_container)
View donateContainer;
@BindView(R.id.main_container)
View mainContainer;
@BindView(R.id.expand_upgrade)
View upgradeExpand;
@BindView(R.id.contract_upgrade)
View upgradeContract;
@BindView(R.id.expand_donate)
View donateExpand;
@BindView(R.id.contract_donate)
View donateContract;
@BindView(R.id.upgrade_header_title)
TextView upgradeHeaderTitle;
@BindView(R.id.amount_5)
Button btnAmount5;
@BindView(R.id.amount_15)
Button btnAmount15;
@BindView(R.id.amount_50)
Button btnAmount50;
@BindView(R.id.amount_100)
Button btnAmount100;
@BindView(R.id.upgrade_header)
View upgradeHeader;
@BindView(R.id.custom_amount)
EditText donateCustomAmountEditText;
@BindView(R.id.upselling_progress_container)
View upsellingProgress;
@BindView(R.id.billing_info)
Expand All @@ -116,20 +95,7 @@ public class UpsellingActivity extends BaseActivity {
private UpsellingViewModel viewModel;

private State upgradeContainerState;
private State donateContainerState;

private int donationAmount;
private int donationAmountPosition;
View.OnTouchListener pressListener = new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
resetAmountButtonsState();
v.setPressed(!v.isPressed());
donationAmount = getPresetChosenAmount();
donateCustomAmountEditText.setText(String.valueOf(donationAmount));
return true;
}
};

private double selectedAnnualMonthlyPrice;
private double selectedMonthlyPrice;
private int fullAnnualMonthlyPriceCents;
Expand All @@ -154,14 +120,6 @@ protected void onCreate(Bundle savedInstanceState) {
viewModel = new ViewModelProvider(this).get(UpsellingViewModel.class);
boolean openUpgrade = getIntent().getBooleanExtra(EXTRA_OPEN_UPGRADE_CONTAINER, false);
fetchPlan(Constants.CurrencyType.EUR);
donateContainerState = State.CLOSED;
btnAmount5.setOnTouchListener(pressListener);
btnAmount15.setOnTouchListener(pressListener);
btnAmount50.setOnTouchListener(pressListener);
btnAmount100.setOnTouchListener(pressListener);
btnAmount15.setPressed(true);
donationAmountPosition = 1;
donationAmount = getPresetChosenAmount();
User user = mUserManager.getUser();
Organization organization = ProtonMailApplication.getApplication().getOrganization();
if (user != null && organization != null) {
Expand Down Expand Up @@ -220,8 +178,6 @@ protected void onResume() {
if (upsellingProgress != null) {
upsellingProgress.setVisibility(View.GONE);
}
resetAmountButtonsState();
setPressedByPosition();
}

@Override
Expand All @@ -236,25 +192,6 @@ protected void onStop() {
ProtonMailApplication.getApplication().getBus().unregister(this);
}

private void setPressedByPosition() {
if (donationAmountPosition == 0) {
btnAmount5.setPressed(true);
} else if (donationAmountPosition == 1) {
btnAmount15.setPressed(true);
} else if (donationAmountPosition == 2) {
btnAmount50.setPressed(true);
} else if (donationAmountPosition == 3) {
btnAmount100.setPressed(true);
}
}

private void resetAmountButtonsState() {
btnAmount5.setPressed(false);
btnAmount15.setPressed(false);
btnAmount50.setPressed(false);
btnAmount100.setPressed(false);
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
if (item.getItemId() == android.R.id.home) {
Expand All @@ -272,38 +209,13 @@ protected int getLayoutId() {
public void onUpgradeHeaderClick() {
if (upgradeContainerState == State.CLOSED) {
upgradeContainerState = State.OPENED;
donateContainerState = State.CLOSED;
openUpgradeContainer();
} else {
upgradeContainerState = State.CLOSED;
donateContainerState = State.CLOSED;
closeUpgradeContainer();
}
}

@OnClick(R.id.donate_paypal)
public void onDonatePaypalClicked() {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(getString(R.string.donate_paypal)));
if (intent.resolveActivity(getPackageManager()) != null) {
startActivity(intent);
} else {
TextExtensions.showToast(this, R.string.no_browser_found, Toast.LENGTH_SHORT);
}
}

@OnClick(R.id.donate_header)
public void onDonateHeaderClick() {
if (donateContainerState == State.CLOSED) {
upgradeContainerState = State.CLOSED;
donateContainerState = State.OPENED;
openDonateContainer();
} else {
upgradeContainerState = State.CLOSED;
donateContainerState = State.CLOSED;
closeDonateContainer();
}
}

@OnClick(R.id.upgrade)
public void onUpgradeClicked() {
if (currencyAndDurationSelected) {
Expand All @@ -313,29 +225,11 @@ public void onUpgradeClicked() {
}
}

@OnClick(R.id.donate)
public void onDonateClicked() {
int amount;
String customAmount = donateCustomAmountEditText.getText().toString();
if (!TextUtils.isEmpty(customAmount)) {
amount = Integer.valueOf(customAmount);
} else {
amount = donationAmount;
}
if (amount <= 0) {
return;
}
Intent billingIntent = new Intent(this, BillingActivity.class);
billingIntent.putExtra(BillingActivity.EXTRA_AMOUNT, amount * 100); // amount in cents
billingIntent.putExtra(BillingActivity.EXTRA_BILLING_TYPE, Constants.BillingType.DONATE);
startActivityForResult(AppUtil.decorInAppIntent(billingIntent), REQUEST_CODE_DONATE);
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (resultCode == RESULT_OK) {
Bundle extras = data.getExtras();
if (requestCode == REQUEST_CODE_DONATE || requestCode == REQUEST_CODE_UPGRADE) {
if (requestCode == REQUEST_CODE_UPGRADE) {
boolean success = extras.getBoolean(BillingActivity.EXTRA_SUCCESS);
if (success) {
Intent intent = new Intent();
Expand Down Expand Up @@ -375,64 +269,21 @@ private void showUpgradeError(String error, String errorDescription) {
alert.show();
}

private int getPresetChosenAmount() {
if (btnAmount5.isPressed()) {
donationAmountPosition = 0;
return 5;
}
if (btnAmount15.isPressed()) {
donationAmountPosition = 1;
return 15;
}
if (btnAmount50.isPressed()) {
donationAmountPosition = 2;
return 50;
}
if (btnAmount100.isPressed()) {
donationAmountPosition = 3;
return 100;
}
return 0;
}

private void openUpgradeContainer() {
upgradeContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 6f));
donateContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
mainContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
upgradeExpand.setVisibility(View.GONE);
upgradeContract.setVisibility(View.VISIBLE);
donateExpand.setVisibility(View.VISIBLE);
donateContract.setVisibility(View.GONE);
}

private void openDonateContainer() {
donateContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 6f));
upgradeContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
mainContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
donateExpand.setVisibility(View.GONE);
donateContract.setVisibility(View.VISIBLE);
if (!paidUser) {
upgradeExpand.setVisibility(View.VISIBLE);
upgradeContract.setVisibility(View.GONE);
}
}

private void closeUpgradeContainer() {
upgradeContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
donateContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
mainContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 6f));
upgradeExpand.setVisibility(View.VISIBLE);
upgradeContract.setVisibility(View.GONE);
}

private void closeDonateContainer() {
donateContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
upgradeContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 0f));
mainContainer.setLayoutParams(new LinearLayout.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, 0, 6f));
donateExpand.setVisibility(View.VISIBLE);
donateContract.setVisibility(View.GONE);
}

private void onCheckSubscriptionEvent(CheckSubscriptionResult result) {
Timber.v("CheckSubscriptionEvent result:%s", result);
if (result instanceof CheckSubscriptionResult.Success) {
Expand Down
Loading

0 comments on commit 9772159

Please sign in to comment.