This commit is contained in:
2023-10-19 20:05:45 +05:30
parent 2478725588
commit 0d91373e28
23 changed files with 1173 additions and 524 deletions

View File

@@ -1,11 +1,13 @@
package com.app.simplitend.appblocking;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.ApplicationInfo;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.ResolveInfo;
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.Bundle;
import android.provider.MediaStore;
import android.provider.Settings;
@@ -270,6 +272,20 @@ public class FUAActivity extends AppCompatActivity {
// do nothing
}
// maps
try {
Intent mapsIntent = new Intent(android.content.Intent.ACTION_VIEW,
Uri.parse("https://www.google.com/maps/dir/?api=1&destination=" + "19,20" + "&travelmode=walking"));
ActivityInfo info = mapsIntent.resolveActivityInfo(getPackageManager(), 0);
if (info != null && info.packageName != null){
appsName.remove(info.packageName);
}
}catch (Exception e){
// do nothing
}
mySharedPref.setArrayList("APP_LIST", appsName);
}

View File

@@ -238,6 +238,20 @@ public abstract class AppUtil {
return returnString.toString();
}
public static String formatDate(@NonNull String fromFormat,
@NonNull String toFormat,
String fromDate){
SimpleDateFormat fromSdf = new SimpleDateFormat(fromFormat, Locale.getDefault());
SimpleDateFormat toSdf = new SimpleDateFormat(toFormat, Locale.getDefault());
try {
Date date = fromSdf.parse(fromDate);
return toSdf.format(date);
}catch (Exception e){
return null;
}
}
public static void callPhone(Activity activity, String phone_number){
if (activity.checkSelfPermission(Manifest.permission.CALL_PHONE) == PackageManager.PERMISSION_GRANTED){
Intent intent = new Intent(Intent.ACTION_CALL, Uri.fromParts("tel",

View File

@@ -13,6 +13,7 @@ import com.onesignal.Continue;
import com.onesignal.OneSignal;
import com.onesignal.debug.LogLevel;
import com.app.simplitend.R;
import com.stripe.android.PaymentConfiguration;
import java.util.List;

View File

@@ -1,5 +1,12 @@
package com.app.simplitend.caregiverdashboard.activities;
import static com.app.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.ACTIVITY_F;
import static com.app.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.CONTACTS_F;
import static com.app.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.MED_INFO_F;
import static com.app.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.MED_REMINDER_F;
import static com.app.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.WHICH_FRAGMENT;
import static com.app.simplitend.cg_geofencing.CgGeoFencingActivity.GEOFENCE_DETAILS_KEY;
import android.app.ProgressDialog;
import android.content.Intent;
import android.os.Bundle;
@@ -7,22 +14,25 @@ import android.os.Handler;
import android.view.View;
import android.widget.Toast;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.lifecycle.ViewModelProvider;
import com.app.simplitend.R;
import com.app.simplitend.apputils.AppUtil;
import com.app.simplitend.apputils.CaregiverDataCache;
import com.app.simplitend.caregiverdashboard.mvvm.CaregiverMainViewModel;
import com.app.simplitend.caregiverdashboard.mvvm.CgHomeContracts;
import com.app.simplitend.caregiverdashboard.mvvm.models.GeoFenceDetails;
import com.bumptech.glide.Glide;
import com.app.simplitend.R;
import com.app.simplitend.apputils.CaregiverDataCache;
import com.app.simplitend.cg_geofencing.CgGeoFencingActivity;
import com.app.simplitend.databinding.ActivityCgProfileProgressBinding;
import com.app.simplitend.welcome.welcomecg.mvvm.CareGiverData;
import static com.app.simplitend.caregiverdashboard.activities.PatientProfileShowerActivity.*;
import static com.app.simplitend.cg_geofencing.CgGeoFencingActivity.GEOFENCE_DETAILS_KEY;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
public class CgProfileProgressActivity extends AppCompatActivity implements CgHomeContracts.GetGeoFenceCallback {
@@ -44,6 +54,34 @@ public class CgProfileProgressActivity extends AppCompatActivity implements CgHo
viewModel = new ViewModelProvider(this).get(CaregiverMainViewModel.class);
progressDialog = new ProgressDialog(this);
Glide.with(this)
.asGif()
.load(R.raw.done_anim_primary)
.listener(new RequestListener<GifDrawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
if (resource == null) return false;
resource.setLoopCount(1);
return false;
}
})
.into(binding.animIv);
binding.linkBtn.setOnClickListener(v -> {
binding.paySuccessCompleteView.setVisibility(View.GONE);
binding.loadingView.setVisibility(View.VISIBLE);
syncPatientData();
});
}
private void syncPatientData() {
startAnimation();
new Handler().postDelayed(() -> {
@@ -58,7 +96,6 @@ public class CgProfileProgressActivity extends AppCompatActivity implements CgHo
clickEvents();
}), false);
}, 3000);
}
private void startAnimation() {

View File

@@ -13,6 +13,7 @@ import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.net.Uri;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;

View File

@@ -27,7 +27,6 @@ import com.app.simplitend.cg_subscription.mvp.SubscriptionCredentials;
import com.app.simplitend.cg_subscription.mvp.SubscriptionPresenter;
import com.app.simplitend.databinding.CgSubscriptionLayoutBinding;
import com.app.simplitend.welcome.welcomecg.mvvm.CareGiverData;
import com.stripe.android.PaymentConfiguration;
import com.stripe.android.paymentsheet.PaymentSheet;
import com.stripe.android.paymentsheet.PaymentSheetResult;
@@ -43,7 +42,7 @@ import okhttp3.RequestBody;
public class CgSubscriptionActivity extends AppCompatActivity
implements SubscriptionContracts.GetSubPlansCallback,
SubscriptionContracts.PaySubscriptionCallback,
SubscriptionContracts.CreateSubscriptionCallback, SubscriptionContracts.GetCurrentPlanCallback {
SubscriptionContracts.CreateSubscriptionCallback, SubscriptionContracts.GetCurrentPlanCallback, SubscriptionContracts.CancelSubscriptionCallback {
private static final String TAG = "CgSubscriptionActivity";
@@ -59,7 +58,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
private CareGiverData careGiverData;
private String payment_intent_id, stripe_price_id;
private String current_subscription_plan_id;
@Override
protected void onCreate(@Nullable Bundle savedInstanceState) {
@@ -76,16 +75,16 @@ public class CgSubscriptionActivity extends AppCompatActivity
CaregiverDataCache.getCaregiverData(this, (careGiverData -> {
this.careGiverData = careGiverData;
if (careGiverData != null){
if (careGiverData.isCaregiverTakeSubscription != 1){
if (careGiverData != null) {
if (careGiverData.isCaregiverTakeSubscription != 1) {
// not subscribed thus, load plans
loadPlans();
paymentSheet = new PaymentSheet(this, this::onPaymentSheetResult);
}else{
paymentSheet = new PaymentSheet(this, this::onPaymentSheetResult);
} else {
// Already subscribed thus, loading current plans
loadCurrentPlans();
}
}else{
} else {
binding.plansView.setVisibility(View.GONE);
}
@@ -98,8 +97,8 @@ public class CgSubscriptionActivity extends AppCompatActivity
private void loadCurrentPlans() {
CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
this.careGiverData = careGiverData1;
if (careGiverData1 == null){
if (careGiverData1 == null) {
binding.plansView.setVisibility(View.GONE);
return;
}
@@ -110,8 +109,9 @@ public class CgSubscriptionActivity extends AppCompatActivity
progressDialog.show();
String token = "Bearer " + AppUtil.getCgToken(this);
presenter.getCurrentSubscriptionPlan(careGiverData.caregiver_xid,
presenter.getCurrentSubscriptionPlan(careGiverData.caregiver_xid,
token, this);
}), true);
}
@@ -119,14 +119,28 @@ public class CgSubscriptionActivity extends AppCompatActivity
binding.makePayment.setOnClickListener(view -> {
CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
this.careGiverData = careGiverData1;
if (careGiverData1 != null){
if (careGiverData.isCaregiverTakeSubscription == 1){
if (careGiverData1 != null) {
if (careGiverData.isCaregiverTakeSubscription == 1) {
// no sub
Toast.makeText(this, "Cancel subscription", Toast.LENGTH_SHORT).show();
}else{
payForSubscription();
if (current_subscription_plan_id != null){
AppUtil.showAlert(this,
"Cancel subscription",
"Are you sure you want to cancel the current subscribed plan?\nThis will stop the recurring payments",
getString(R.string.no),
((dialogInterface, i) -> {}),
getString(R.string.yes),
((dialogInterface, i) -> {
// yes click
cancelSubscription();
}));
}else{
Toast.makeText(this, "Please try again later.", Toast.LENGTH_SHORT).show();
}
} else {
payForSubscription(); // uses payment sheet
// showCardDetailsWidget(); // uses custom elements
}
}else{
} else {
Toast.makeText(this, "Couldn't load data", Toast.LENGTH_SHORT).show();
}
}), true);
@@ -143,16 +157,15 @@ public class CgSubscriptionActivity extends AppCompatActivity
binding.retry.setOnClickListener(v -> {
CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
this.careGiverData = careGiverData1;
if (careGiverData != null){
careGiverData.isCaregiverTakeSubscription = 0;
if (careGiverData.isCaregiverTakeSubscription != 1){
if (careGiverData != null) {
if (careGiverData.isCaregiverTakeSubscription != 1) {
// no sub
loadPlans();
}else{
} else {
loadCurrentPlans();
}
}else{
} else {
Toast.makeText(this, "Couldn't load data", Toast.LENGTH_SHORT).show();
}
}), true);
@@ -160,24 +173,40 @@ public class CgSubscriptionActivity extends AppCompatActivity
}
private void cancelSubscription() {
if (current_subscription_plan_id == null){
Toast.makeText(this, "Please try again later.", Toast.LENGTH_SHORT).show();
return;
}
progressDialog.setTitle("Please wait...");
progressDialog.setMessage("while we cancel your subscription");
progressDialog.setCancelable(false);
progressDialog.show();
presenter.cancelSubscription(current_subscription_plan_id,
AppUtil.getCgToken(this),
this);
}
private void payForSubscription() {
if (careGiverData == null || subscriptionPlans == null) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show();
return;
}
if (!binding.monthCheck.isSelected() && !binding.yearCheck.isSelected()){
if (!binding.monthCheck.isSelected() && !binding.yearCheck.isSelected()) {
Toast.makeText(this, "Please select a plan", Toast.LENGTH_SHORT).show();
return;
}
int position = 0;
if (binding.yearCheck.isSelected()){
if (binding.yearCheck.isSelected()) {
position = 1;
}
if (position >= subscriptionPlans.size()){
if (position >= subscriptionPlans.size()) {
Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show();
return;
}
@@ -206,6 +235,9 @@ public class CgSubscriptionActivity extends AppCompatActivity
RequestBody price_body = RequestBody.create(plan_price, MediaType.parse("text/plain"));
body.put("price", price_body);
RequestBody price_id_body = RequestBody.create(plan.stripe_price_id, MediaType.parse("text/plain"));
body.put("price_id", price_id_body);
RequestBody subscription_xid_body = RequestBody.create(plan.id + "", MediaType.parse("text/plain"));
body.put("subscription_xid", subscription_xid_body);
@@ -214,8 +246,6 @@ public class CgSubscriptionActivity extends AppCompatActivity
String token = "Bearer " + AppUtil.getCgToken(this);
this.stripe_price_id = plan.stripe_price_id;
presenter.getPaymentCred(token, body, this);
} catch (Exception e) {
progressDialog.dismiss();
@@ -256,7 +286,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
CaregiverDataCache.getCaregiverData(this, (careGiverData1 -> {
this.careGiverData = careGiverData1;
if (careGiverData1 == null){
if (careGiverData1 == null) {
binding.plansView.setVisibility(View.GONE);
return;
}
@@ -292,85 +322,144 @@ public class CgSubscriptionActivity extends AppCompatActivity
Toast.makeText(this, "Payment failed.", Toast.LENGTH_SHORT).show();
} else if (paymentSheetResult instanceof PaymentSheetResult.Completed) {
// Display for example, an order confirmation screen
Log.d(TAG, "Payment successful");
Toast.makeText(this, "Payment successful.", Toast.LENGTH_SHORT).show();
// creating subscription
createSubscription();
Intent intent = new Intent(this, CgProfileProgressActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
finish();
}
}
private void createSubscription() {
if (this.stripe_price_id == null || this.payment_intent_id == null) {
// something went wrong
Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show();
return;
}
// private void createSubscription() {
// if (this.stripe_price_id == null || this.payment_intent_id == null) {
// // something went wrong
// Toast.makeText(this, "Something went wrong", Toast.LENGTH_SHORT).show();
// return;
// }
//
// progressDialog.setTitle("Almost there...");
// progressDialog.setMessage("We are verifying your payment.\nDon't leave the app screen.");
// progressDialog.setCancelable(false);
// progressDialog.show();
//
// Map<String, RequestBody> bodyMap = new HashMap<>();
//
// RequestBody pay_intent_id_body = RequestBody.create(this.payment_intent_id, MediaType.parse("text/plain"));
// bodyMap.put("payment_intent_id", pay_intent_id_body);
//
// RequestBody price_id_body = RequestBody.create(this.stripe_price_id, MediaType.parse("text/plain"));
// bodyMap.put("price_id", price_id_body);
//
// presenter.createSubscription(bodyMap,
// "Bearer " + AppUtil.getCgToken(this),
// this);
//
// }
progressDialog.setTitle("Almost there...");
progressDialog.setMessage("We are verifying your payment.\nDon't leave the app screen.");
progressDialog.setCancelable(false);
progressDialog.show();
private void inflateCurrentPlan(CurrentPlan currentPlan) {
binding.datesView.setVisibility(View.VISIBLE); // to show expiry and cancelled dates
Map<String, RequestBody> bodyMap = new HashMap<>();
RequestBody pay_intent_id_body = RequestBody.create(this.payment_intent_id, MediaType.parse("text/plain"));
bodyMap.put("payment_intent_id", pay_intent_id_body);
RequestBody price_id_body = RequestBody.create(this.stripe_price_id, MediaType.parse("text/plain"));
bodyMap.put("price_id", price_id_body);
presenter.createSubscription(bodyMap,
"Bearer " + AppUtil.getCgToken(this),
this);
}
private void inflateCurrentPlan(CurrentPlan currentPlan){
binding.makePayment.setVisibility(View.VISIBLE);
binding.makePayment.setText(R.string.cancel_subscription);
if ("2".equals(currentPlan.is_subscription_completed)){
// subscription is cancelled
binding.makePayment.setVisibility(View.GONE);
String cancelled_date = AppUtil.formatDate("yyyy-mm-dd", "mm-dd-yyyy", currentPlan.ended_at);
if (cancelled_date != null){
binding.cancelledDate.setText(cancelled_date);
binding.cancelledDate.setVisibility(View.VISIBLE);
binding.cancelledDateText.setVisibility(View.VISIBLE);
}else {
binding.cancelledDateText.setVisibility(View.GONE);
binding.cancelledDate.setVisibility(View.GONE);
}
}
binding.yourPlan.setVisibility(View.VISIBLE);
SubscriptionPlan plan = currentPlan.plan;
if (getString(R.string.monthly).equals(plan.plan_name)){
String per_duration = null;
// re-using per month card for showing current plan
if (getString(R.string.monthly).equals(plan.plan_name)) {
// monthly
binding.monthlyName.setText(plan.plan_name);
binding.monthCheck.setSelected(true);
String price = "$" + plan.plan_value;
String price = "$" + plan.plan_value;
binding.monthlyPrice.setText(price);
per_duration = "/mo";
binding.monthCard.setVisibility(View.VISIBLE);
binding.yearCard.setVisibility(View.GONE);
}else if (getString(R.string.year).equals(plan.plan_name)){
} else if (getString(R.string.year).equals(plan.plan_name)) {
// yearly
binding.yearlyName.setText(plan.plan_name);
binding.yearCheck.setSelected(true);
// code to show discounts and other values.
// binding.yearlyName.setText(plan.plan_name);
//
// binding.yearCheck.setSelected(true);
//
// String price = "$" + plan.plan_value;
// binding.yearDiscountedPrice.setText(price);
//
// binding.yearActualPrice.setVisibility(View.GONE);
// binding.yearDiscount.setVisibility(View.GONE);
//
// try {
// BigDecimal year_price_d = new BigDecimal(plan.plan_value);
// String yearly_month_price = year_price_d.divide(new BigDecimal(12), RoundingMode.DOWN).toString();
// yearly_month_price = "$" + yearly_month_price;
// binding.yearlyMonthPrice.setText(yearly_month_price);
// } catch (Exception e) {
// binding.yearlyMonthPrice.setVisibility(View.GONE);
// }
// code to only show name
binding.monthlyName.setText(plan.plan_name);
binding.monthCheck.setSelected(true);
String price = "$" + plan.plan_value;
binding.yearDiscountedPrice.setText(price);
binding.monthlyPrice.setText(price);
binding.yearActualPrice.setVisibility(View.GONE);
binding.yearDiscount.setVisibility(View.GONE);
per_duration = "/year";
try {
BigDecimal year_price_d = new BigDecimal(plan.plan_value);
String yearly_month_price = year_price_d.divide(new BigDecimal(12), RoundingMode.DOWN).toString();
yearly_month_price = "$" + yearly_month_price;
binding.yearlyMonthPrice.setText(yearly_month_price);
}catch (Exception e){
binding.yearlyMonthPrice.setVisibility(View.GONE);
binding.monthCard.setVisibility(View.VISIBLE);
binding.yearCard.setVisibility(View.GONE);
}
if (per_duration != null) {
binding.perMonthText.setText(per_duration);
}else{
binding.perMonthText.setVisibility(View.GONE);
}
// next due date
String next_due_date = AppUtil.formatDate("yyyy-mm-dd", "mm-dd-yyyy", currentPlan.current_period_end);
if (next_due_date != null){
binding.nextDueDate.setText(next_due_date);
binding.nextDueDate.setVisibility(View.VISIBLE);
String next_due_text;
if ("2".equals(currentPlan.is_subscription_completed)){
// cancelled subscription
next_due_text = "Your current plan will expire on";
}else{
next_due_text = "Next payment is due on";
}
binding.monthCard.setVisibility(View.GONE);
binding.yearCard.setVisibility(View.VISIBLE);
binding.nextDueDateText.setText(next_due_text);
binding.nextDueDateText.setVisibility(View.VISIBLE);
}
}
private void inflatePlans() {
@@ -382,7 +471,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
binding.yearCard.setVisibility(View.VISIBLE);
binding.yearCard.setOnClickListener(v -> {
if (!binding.yearCheck.isSelected()){
if (!binding.yearCheck.isSelected()) {
// not selected
binding.monthCheck.setSelected(false);
binding.yearCheck.setSelected(true);
@@ -391,7 +480,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
binding.monthCard.setVisibility(View.VISIBLE);
binding.monthCard.setOnClickListener(v -> {
if (!binding.monthCheck.isActivated()){
if (!binding.monthCheck.isActivated()) {
binding.yearCheck.setSelected(false);
binding.monthCheck.setSelected(true);
}
@@ -401,12 +490,12 @@ public class CgSubscriptionActivity extends AppCompatActivity
String monthly_price = null;
String yearly_price = null;
for (SubscriptionPlan plan: subscriptionPlans){
if (getString(R.string.monthly).equals(plan.plan_name)){
for (SubscriptionPlan plan : subscriptionPlans) {
if (getString(R.string.monthly).equals(plan.plan_name)) {
// monthly
binding.monthlyName.setText(plan.plan_name);
monthly_price = plan.plan_value;
}else if (getString(R.string.year).equals(plan.plan_name)){
} else if (getString(R.string.year).equals(plan.plan_name)) {
// yearly
binding.yearlyName.setText(plan.plan_name);
yearly_price = plan.plan_value;
@@ -425,7 +514,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
BigDecimal actual_year_price = month_price_d.multiply(TWELVE);
String strike_actual_year_price = "<strike>$" + actual_year_price + "</strike>";
String strike_actual_year_price = "<strike>$" + actual_year_price + "</strike>";
binding.yearActualPrice.setText(Html.fromHtml(strike_actual_year_price));
String yearly_month_price = year_price_d.divide(TWELVE, RoundingMode.DOWN).toString();
@@ -441,7 +530,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
binding.plansView.setVisibility(View.VISIBLE);
}catch (Exception e){
} catch (Exception e) {
binding.plansView.setVisibility(View.GONE);
}
}
@@ -455,32 +544,21 @@ public class CgSubscriptionActivity extends AppCompatActivity
return;
}
this.payment_intent_id = credentials.payment_intent_id;
final PaymentSheet.CustomerConfiguration customerConfig = new PaymentSheet.CustomerConfiguration(
credentials.customerId,
credentials.ephemeralKey
);
String paymentIntentClientSecret = credentials.paymentIntent;
PaymentConfiguration.init(getApplicationContext(), credentials.stripe_publish_key);
// dismissing dialog now
progressDialog.dismiss();
final PaymentSheet.Configuration configuration = new PaymentSheet.Configuration.Builder("SimpliTend")
.customer(customerConfig)
.billingDetailsCollectionConfiguration(new PaymentSheet.BillingDetailsCollectionConfiguration(
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic,
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic,
PaymentSheet.BillingDetailsCollectionConfiguration.CollectionMode.Automatic,
PaymentSheet.BillingDetailsCollectionConfiguration.AddressCollectionMode.Automatic,
true
))
.allowsDelayedPaymentMethods(true)
.build();
paymentSheet.presentWithPaymentIntent(
paymentIntentClientSecret,
credentials.clientSecret,
configuration
);
@@ -527,7 +605,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
progressDialog.dismiss();
AppUtil.showAlert(this,
getString(R.string.something_went_wrong),
message ,
message,
"OK",
((dialogInterface, i) -> {
@@ -538,6 +616,7 @@ public class CgSubscriptionActivity extends AppCompatActivity
public void currentPlan(@NonNull CurrentPlan currentPlan) {
progressDialog.dismiss();
inflateCurrentPlan(currentPlan);
this.current_subscription_plan_id = currentPlan.subscription_id;
}
@Override
@@ -545,4 +624,18 @@ public class CgSubscriptionActivity extends AppCompatActivity
progressDialog.dismiss();
binding.plansView.setVisibility(View.GONE);
}
@Override
public void subscriptionCancelled(@NonNull CurrentPlan currentPlan) {
progressDialog.dismiss();
Toast.makeText(this, "Subscription cancelled.", Toast.LENGTH_SHORT).show();
inflateCurrentPlan(currentPlan);
this.current_subscription_plan_id = null;
}
@Override
public void subscriptionCancelFailed(Throwable t, String message) {
progressDialog.dismiss();
Toast.makeText(this, "" + message, Toast.LENGTH_SHORT).show();
}
}

View File

@@ -8,6 +8,7 @@ import java.util.Map;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.http.Body;
import retrofit2.http.GET;
import retrofit2.http.Header;
import retrofit2.http.Multipart;
@@ -38,4 +39,8 @@ public interface SubscriptionApiService {
Call<CallResponse<CurrentPlan>> getCurrentPlan(@Query("caregiver_id") long c_id,
@Header("Authorization") String token);
@POST("api/cancel-subscription")
Call<CallResponse<CurrentPlan>> cancelSubscription(@Body Map<String, String> body,
@Header("Authorization") String token);
}

View File

@@ -34,4 +34,9 @@ public interface SubscriptionContracts {
void currentPlan(@NonNull CurrentPlan currentPlan);
void failedCurrentPlan(Throwable t, String message);
}
interface CancelSubscriptionCallback{
void subscriptionCancelled(@NonNull CurrentPlan currentPlan);
void subscriptionCancelFailed(Throwable t, String message);
}
}

View File

@@ -2,11 +2,10 @@ package com.app.simplitend.cg_subscription.mvp;
public class SubscriptionCredentials{
public String customerId;
public String paymentIntent;
public String ephemeralKey;
public String stripe_publish_key;
public String payment_intent_id;
public String clientSecret;
public String subscriptionId;
public SubscriptionCredentials(){}
}

View File

@@ -7,6 +7,7 @@ import com.app.simplitend.cg_subscription.SubscriptionPlan;
import com.app.simplitend.welcome.welcomepatient.mvvm.models.CallResponse;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import okhttp3.RequestBody;
@@ -20,31 +21,31 @@ public class SubscriptionPresenter {
private final SubscriptionApiService apiService;
private SubscriptionPresenter(){
private SubscriptionPresenter() {
apiService = RetrofitHelper.getRetrofit().create(SubscriptionApiService.class);
}
public static synchronized SubscriptionPresenter getPresenter(){
if (presenter == null){
public static synchronized SubscriptionPresenter getPresenter() {
if (presenter == null) {
presenter = new SubscriptionPresenter();
}
return presenter;
}
public void getSubscriptionPlans(@NonNull String token, @NonNull SubscriptionContracts.GetSubPlansCallback subPlansCallback){
public void getSubscriptionPlans(@NonNull String token, @NonNull SubscriptionContracts.GetSubPlansCallback subPlansCallback) {
apiService.getSubscriptionPlans(token)
.enqueue(new Callback<CallResponse<ArrayList<SubscriptionPlan>>>() {
@Override
public void onResponse(Call<CallResponse<ArrayList<SubscriptionPlan>>> call, Response<CallResponse<ArrayList<SubscriptionPlan>>> response) {
if (response.body() != null){
if (response.body().status != 200 || response.body().result == null){
if (response.body() != null) {
if (response.body().status != 200 || response.body().result == null) {
subPlansCallback.onSubsFetchFailed(new Exception(), response.body().message);
return;
}
subPlansCallback.onSubscriptionFetched(response.body().result);
}else{
} else {
subPlansCallback.onSubsFetchFailed(new Exception(), "Please try again later.");
}
}
@@ -58,20 +59,20 @@ public class SubscriptionPresenter {
public void getPaymentCred(@NonNull String token,
Map<String, RequestBody> body,
@NonNull SubscriptionContracts.PaySubscriptionCallback paySubscriptionCallback){
@NonNull SubscriptionContracts.PaySubscriptionCallback paySubscriptionCallback) {
apiService.paySubscription(token, body)
.enqueue(new Callback<CallResponse<SubscriptionCredentials>>() {
@Override
public void onResponse(Call<CallResponse<SubscriptionCredentials>> call, Response<CallResponse<SubscriptionCredentials>> response) {
if (response.body() != null){
if (response.body().status != 200 || response.body().result == null){
if (response.body() != null) {
if (response.body().status != 200 || response.body().result == null) {
paySubscriptionCallback.onPaymentCredFetchFailed(new Exception(), response.body().message);
return;
}
paySubscriptionCallback.onPaymentCredFetched(response.body().result);
}else{
} else {
paySubscriptionCallback.onPaymentCredFetchFailed(new Exception(), "Please try again later.");
}
}
@@ -86,19 +87,19 @@ public class SubscriptionPresenter {
public void createSubscription(Map<String, RequestBody> bodyMap,
@NonNull String token,
@NonNull SubscriptionContracts.CreateSubscriptionCallback createSubscriptionCallback){
@NonNull SubscriptionContracts.CreateSubscriptionCallback createSubscriptionCallback) {
apiService.createSubscription(token, bodyMap)
.enqueue(new Callback<CallResponse<Object>>() {
@Override
public void onResponse(Call<CallResponse<Object>> call, Response<CallResponse<Object>> response) {
if (response.body() != null){
if (response.body().status != 200){
if (response.body() != null) {
if (response.body().status != 200) {
createSubscriptionCallback.onSubscriptionCreateFailed(new Exception(), response.body().message);
return;
}
createSubscriptionCallback.onSubscriptionCreated();
}else{
} else {
createSubscriptionCallback.onSubscriptionCreateFailed(new Exception(), "Please try again later.");
}
}
@@ -112,19 +113,19 @@ public class SubscriptionPresenter {
public void getCurrentSubscriptionPlan(long c_id,
@NonNull String token,
@NonNull SubscriptionContracts.GetCurrentPlanCallback callback){
@NonNull SubscriptionContracts.GetCurrentPlanCallback callback) {
apiService.getCurrentPlan(c_id, token)
.enqueue(new Callback<CallResponse<CurrentPlan>>() {
@Override
public void onResponse(Call<CallResponse<CurrentPlan>> call, Response<CallResponse<CurrentPlan>> response) {
if (response.body() != null){
if (response.body().status != 200 || response.body().error_code == 1 || response.body().result == null){
if (response.body() != null) {
if (response.body().status != 200 || response.body().error_code == 1 || response.body().result == null) {
callback.failedCurrentPlan(new Exception(), response.body().message);
return;
}
callback.currentPlan(response.body().result);
}else{
} else {
callback.failedCurrentPlan(new Exception(), "Please try again later.");
}
}
@@ -136,4 +137,35 @@ public class SubscriptionPresenter {
});
}
public void cancelSubscription(@NonNull String subscriptionId,
String token,
@NonNull SubscriptionContracts.CancelSubscriptionCallback callback) {
Map<String, String> body = new HashMap<>();
body.put("subscription_id", subscriptionId);
apiService.cancelSubscription(body,
"Bearer " + token).enqueue(new Callback<CallResponse<CurrentPlan>>() {
@Override
public void onResponse(Call<CallResponse<CurrentPlan>> call, Response<CallResponse<CurrentPlan>> response) {
if (response.body() != null) {
if (response.body().status != 200 || response.body().error_code == 1 || response.body().result == null) {
callback.subscriptionCancelFailed(new Exception(), response.body().message);
return;
}
callback.subscriptionCancelled(response.body().result);
} else {
callback.subscriptionCancelFailed(new Exception(), "Please try again later.");
}
}
@Override
public void onFailure(Call<CallResponse<CurrentPlan>> call, Throwable t) {
callback.subscriptionCancelFailed(new Exception(), t.getLocalizedMessage());
}
});
}
}

View File

@@ -147,7 +147,7 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
});
binding.dosageDrop.setOnClickListener(v -> {
binding.doseShortName.setOnClickListener(v -> {
AppUtil.closeKeyboard(requireActivity());
binding.dosageSpinner.show();
});
@@ -306,6 +306,17 @@ public class AddReminderFragment extends Fragment implements CompoundButton.OnCh
binding.medicationsSpinner.setError(null);
});
binding.dosageSpinner.setOnSpinnerItemSelectedListener((OnSpinnerItemSelectedListener<String>) (i, s, i1, t1) -> {
String short_name;
try {
short_name = String.valueOf(dosageTypeList.get(binding.dosageSpinner.getSelectedIndex()).value);
} catch (Exception e) {
short_name = "Other";
}
binding.doseShortName.setText(short_name);
});
// load into spinner
loadFreqNMedType();

View File

@@ -23,6 +23,11 @@ import com.app.simplitend.databinding.ConnectCaregiverFragmentBinding;
import com.app.simplitend.welcome.welcomecg.WelcomeContracts;
import com.app.simplitend.welcome.welcomecg.mvvm.CgWelcomeViewModel;
import com.app.simplitend.welcome.welcomecg.mvvm.ConnectCgResult;
import com.bumptech.glide.load.DataSource;
import com.bumptech.glide.load.engine.GlideException;
import com.bumptech.glide.load.resource.gif.GifDrawable;
import com.bumptech.glide.request.RequestListener;
import com.bumptech.glide.request.target.Target;
import java.util.HashMap;
import java.util.Map;
@@ -88,6 +93,14 @@ public class CgConnectFragment extends Fragment implements
viewModel.resendCgCode(body, token, this);
});
binding.proceed.setOnClickListener(v -> {
// go to cg dash board
Intent intent = new Intent(requireActivity(), CgAuthActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
requireActivity().finish();
});
}
private void connectCG() {
@@ -164,14 +177,25 @@ public class CgConnectFragment extends Fragment implements
public void onCgConnected(ConnectCgResult result) {
progressDialog.dismiss();
Toast.makeText(requireContext(), "Caregiver connected.", Toast.LENGTH_SHORT).show();
binding.connectView.setVisibility(View.GONE);
binding.connectCompleteView.setVisibility(View.VISIBLE);
// go to cg dash board
Intent intent = new Intent(requireActivity(), CgAuthActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
startActivity(intent);
requireActivity().finish();
Glide.with(this)
.asGif()
.load(R.raw.done_anim_primary)
.listener(new RequestListener<GifDrawable>() {
@Override
public boolean onLoadFailed(@Nullable GlideException e, Object model, Target<GifDrawable> target, boolean isFirstResource) {
return false;
}
@Override
public boolean onResourceReady(GifDrawable resource, Object model, Target<GifDrawable> target, DataSource dataSource, boolean isFirstResource) {
resource.setLoopCount(1);
return false;
}
})
.into(binding.animIv);
}
@Override