mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-04-14 19:56:32 +00:00
move checkout system creation to dagger
This commit is contained in:
parent
bbf3728b03
commit
a1aff4e47c
4 changed files with 55 additions and 49 deletions
|
|
@ -53,18 +53,6 @@ public class HabiticaApplication extends MultiDexApplication {
|
|||
@Inject
|
||||
Lazy<APIHelper> lazyApiHelper;
|
||||
private AppComponent component;
|
||||
/**
|
||||
* For better performance billing class should be used as singleton
|
||||
*/
|
||||
@NonNull
|
||||
private Billing billing;
|
||||
/**
|
||||
* Application wide {@link org.solovyev.android.checkout.Checkout} instance (can be used
|
||||
* anywhere in the app).
|
||||
* This instance contains all available products in the app.
|
||||
*/
|
||||
@NonNull
|
||||
private Checkout checkout;
|
||||
|
||||
public static HabiticaApplication getInstance(Context context) {
|
||||
return (HabiticaApplication) context.getApplicationContext();
|
||||
|
|
@ -125,7 +113,6 @@ public class HabiticaApplication extends MultiDexApplication {
|
|||
setupFlowManager();
|
||||
setupFacebookSdk();
|
||||
setupCrashlytics();
|
||||
createBillingAndCheckout();
|
||||
registerActivityLifecycleCallbacks();
|
||||
Amplitude.getInstance().initialize(this, getString(R.string.amplitude_app_id)).enableForegroundTracking(this);
|
||||
Fresco.initialize(this);
|
||||
|
|
@ -269,34 +256,6 @@ public class HabiticaApplication extends MultiDexApplication {
|
|||
return new File(getExternalFilesDir(null), "HabiticaDatabase/" + name);
|
||||
}
|
||||
|
||||
private void createBillingAndCheckout() {
|
||||
billing = new Billing(this, new Billing.DefaultConfiguration() {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPublicKey() {
|
||||
return "DONT-NEED-IT";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Cache getCache() {
|
||||
return Billing.newCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PurchaseVerifier getPurchaseVerifier() {
|
||||
return new HabiticaPurchaseVerifier(HabiticaApplication.this);
|
||||
}
|
||||
});
|
||||
|
||||
checkout = Checkout.forApplication(billing, Products.create().add(ProductTypes.IN_APP, Arrays.asList(Purchase20Gems)));
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public Checkout getCheckout() {
|
||||
return checkout;
|
||||
}
|
||||
|
||||
// endregion
|
||||
|
||||
public AppComponent getComponent() {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,25 @@
|
|||
package com.habitrpg.android.habitica.modules;
|
||||
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.HabiticaPurchaseVerifier;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.helpers.TagsHelper;
|
||||
|
||||
import org.solovyev.android.checkout.Billing;
|
||||
import org.solovyev.android.checkout.Cache;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
import org.solovyev.android.checkout.Products;
|
||||
import org.solovyev.android.checkout.PurchaseVerifier;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v7.preference.PreferenceManager;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import javax.inject.Named;
|
||||
import javax.inject.Singleton;
|
||||
|
||||
|
|
@ -46,4 +58,34 @@ public class AppModule {
|
|||
public TagsHelper providesTagsHelper() {
|
||||
return new TagsHelper();
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public Billing providesBilling() {
|
||||
return new Billing(application, new Billing.DefaultConfiguration() {
|
||||
@NonNull
|
||||
@Override
|
||||
public String getPublicKey() {
|
||||
return "DONT-NEED-IT";
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Cache getCache() {
|
||||
return Billing.newCache();
|
||||
}
|
||||
|
||||
@Override
|
||||
public PurchaseVerifier getPurchaseVerifier() {
|
||||
return new HabiticaPurchaseVerifier(application);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Provides
|
||||
@Singleton
|
||||
public Checkout providesCheckout(Billing billing) {
|
||||
return Checkout.forApplication(billing, Products.create().add(ProductTypes.IN_APP, Arrays.asList(HabiticaApplication.Purchase20Gems)));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -145,7 +145,11 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
public static final int SELECT_CLASS_RESULT = 11;
|
||||
private static final int MIN_LEVEL_FOR_SKILLS = 11;
|
||||
// Checkout needs to be in the Activity..
|
||||
public ActivityCheckout checkout = null;
|
||||
|
||||
@Inject
|
||||
public Checkout checkout;
|
||||
private ActivityCheckout activityCheckout;
|
||||
|
||||
@Inject
|
||||
public APIHelper apiHelper;
|
||||
@Inject
|
||||
|
|
@ -269,13 +273,13 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
}
|
||||
|
||||
private void setupCheckout() {
|
||||
checkout = Checkout.forActivity(this, HabiticaApplication.getInstance(this).getCheckout());
|
||||
checkout.start();
|
||||
activityCheckout = Checkout.forActivity(this, checkout);
|
||||
activityCheckout.start();
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityCheckout getActivityCheckout() {
|
||||
return checkout;
|
||||
return activityCheckout;
|
||||
}
|
||||
|
||||
private void saveLoginInformation() {
|
||||
|
|
@ -720,7 +724,7 @@ public class MainActivity extends BaseActivity implements Action1<Throwable>, Ha
|
|||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
checkout.onActivityResult(requestCode, resultCode, data);
|
||||
activityCheckout.onActivityResult(requestCode, resultCode, data);
|
||||
if (resultCode == SELECT_CLASS_RESULT) {
|
||||
if (this.apiHelper != null) {
|
||||
this.apiHelper.retrieveUser(true)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.components.AppComponent;
|
||||
|
|
@ -92,7 +93,7 @@ public class GemsPurchaseFragment extends BaseMainFragment {
|
|||
|
||||
@Override
|
||||
public void onError(int i, @NonNull Exception e) {
|
||||
Fabric.getLogger().e("Purchase", "Error", e);
|
||||
Crashlytics.logException(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
@ -160,7 +161,7 @@ public class GemsPurchaseFragment extends BaseMainFragment {
|
|||
|
||||
@Override
|
||||
public void onError(int i, @NonNull Exception e) {
|
||||
Fabric.getLogger().e("Purchase", "getAllPurchases", e);
|
||||
Crashlytics.logException(e);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
@ -182,7 +183,7 @@ public class GemsPurchaseFragment extends BaseMainFragment {
|
|||
|
||||
@Override
|
||||
public void onError(int i, @NonNull Exception e) {
|
||||
Fabric.getLogger().e("Purchase", "Error", e);
|
||||
Crashlytics.logException(e);
|
||||
}
|
||||
});
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue