mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-17 19:29:02 +00:00
Merge pull request #303 from dlew/dlew/memory-leaks
Added LeakCanary and began fixing memory leaks
This commit is contained in:
commit
b4de4e4b15
8 changed files with 57 additions and 36 deletions
|
|
@ -86,6 +86,9 @@ dependencies {
|
|||
compile 'com.facebook.android:facebook-android-sdk:4.7.0'
|
||||
//Material Dialogs
|
||||
compile('com.github.afollestad.material-dialogs:core:0.8.5.0@aar')
|
||||
|
||||
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'
|
||||
releaseCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
|
||||
}
|
||||
|
||||
android {
|
||||
|
|
|
|||
|
|
@ -56,13 +56,11 @@ public class APIHelper implements ErrorHandler, Profiler {
|
|||
// I think we don't need the APIHelper anymore we could just use ApiService
|
||||
public final ApiService apiService;
|
||||
private final InAppPurchasesApiService inAppPurchasesService;
|
||||
private Context mContext;
|
||||
private HostConfig cfg;
|
||||
|
||||
//private OnHabitsAPIResult mResultListener;
|
||||
//private HostConfig mConfig;
|
||||
public APIHelper(Context c, final HostConfig cfg) {
|
||||
this.mContext = c;
|
||||
public APIHelper(final HostConfig cfg) {
|
||||
this.cfg = cfg;
|
||||
|
||||
RequestInterceptor requestInterceptor = new RequestInterceptor() {
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import android.content.Intent;
|
|||
import android.content.SharedPreferences;
|
||||
import android.database.DatabaseErrorHandler;
|
||||
import android.database.sqlite.SQLiteDatabase;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.support.annotation.NonNull;
|
||||
|
|
@ -14,11 +15,10 @@ import android.support.annotation.Nullable;
|
|||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
|
||||
import com.facebook.FacebookSdk;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
import com.raizlabs.android.dbflow.config.FlowManager;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import org.solovyev.android.checkout.Billing;
|
||||
import org.solovyev.android.checkout.Cache;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
|
|
@ -48,6 +48,11 @@ public class HabiticaApplication extends Application {
|
|||
|
||||
Instance = this;
|
||||
|
||||
// LeakCanary 1.3.1 has problems on Marshmallow; can remove check once updated with fixes
|
||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||
LeakCanary.install(this);
|
||||
}
|
||||
|
||||
createBillingAndCheckout();
|
||||
|
||||
FlowManager.init(this);
|
||||
|
|
@ -90,7 +95,7 @@ public class HabiticaApplication extends Application {
|
|||
|
||||
@Override
|
||||
public void onActivityDestroyed(Activity activity) {
|
||||
|
||||
currentActivity = null;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -123,7 +123,7 @@ public class LoginActivity extends AppCompatActivity
|
|||
if(hc ==null) {
|
||||
hc = new HostConfig(apiAddress, "80", "", "");
|
||||
}
|
||||
mApiHelper = new APIHelper(this,hc);
|
||||
mApiHelper = new APIHelper(hc);
|
||||
|
||||
this.isRegistering = true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,7 +21,8 @@ import android.view.View;
|
|||
import android.widget.FrameLayout;
|
||||
import android.widget.ImageView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import com.afollestad.materialdialogs.MaterialDialog;
|
||||
import com.crashlytics.android.Crashlytics;
|
||||
import com.crashlytics.android.core.CrashlyticsCore;
|
||||
|
|
@ -37,6 +38,7 @@ import com.habitrpg.android.habitica.prefs.PrefsActivity;
|
|||
import com.habitrpg.android.habitica.ui.AvatarWithBarsViewModel;
|
||||
import com.habitrpg.android.habitica.ui.MainDrawerBuilder;
|
||||
import com.habitrpg.android.habitica.ui.fragments.BaseFragment;
|
||||
import com.habitrpg.android.habitica.ui.fragments.GemsPurchaseFragment;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPicture;
|
||||
import com.habitrpg.android.habitica.userpicture.UserPictureRunnable;
|
||||
import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
||||
|
|
@ -59,9 +61,13 @@ import com.raizlabs.android.dbflow.sql.language.Delete;
|
|||
import com.raizlabs.android.dbflow.sql.language.From;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
import com.raizlabs.android.dbflow.sql.language.Where;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
|
|
@ -72,15 +78,9 @@ import java.util.Map;
|
|||
import java.util.TimeZone;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import retrofit.Callback;
|
||||
import retrofit.RetrofitError;
|
||||
import retrofit.client.Response;
|
||||
|
||||
public class MainActivity extends AppCompatActivity implements HabitRPGUserCallback.OnUserReceived, TaskScoringCallback.OnTaskScored {
|
||||
public class MainActivity extends AppCompatActivity implements HabitRPGUserCallback.OnUserReceived,
|
||||
TaskScoringCallback.OnTaskScored,
|
||||
GemsPurchaseFragment.Listener {
|
||||
|
||||
public enum SnackbarDisplayType {
|
||||
NORMAL, FAILURE, FAILURE_BLUE, DROP
|
||||
|
|
@ -113,7 +113,7 @@ public class MainActivity extends AppCompatActivity implements HabitRPGUserCallb
|
|||
private MaterialDialog faintDialog;
|
||||
|
||||
// Checkout needs to be in the Activity..
|
||||
public static ActivityCheckout checkout = null;
|
||||
public ActivityCheckout checkout = null;
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
|
|
@ -133,7 +133,7 @@ public class MainActivity extends AppCompatActivity implements HabitRPGUserCallb
|
|||
if(!HabiticaApplication.checkUserAuthentication(this, hostConfig))
|
||||
return;
|
||||
|
||||
HabiticaApplication.ApiHelper = this.mAPIHelper = new APIHelper(this, hostConfig);
|
||||
HabiticaApplication.ApiHelper = this.mAPIHelper = new APIHelper(hostConfig);
|
||||
|
||||
new Select().from(HabitRPGUser.class).where(Condition.column("id").eq(hostConfig.getUser())).async().querySingle(userTransactionListener);
|
||||
|
||||
|
|
@ -170,6 +170,10 @@ public class MainActivity extends AppCompatActivity implements HabitRPGUserCallb
|
|||
mAPIHelper.retrieveUser(new HabitRPGUserCallback(this));
|
||||
}
|
||||
|
||||
@Override
|
||||
public ActivityCheckout getActivityCheckout() {
|
||||
return checkout;
|
||||
}
|
||||
|
||||
private void saveLoginInformation() {
|
||||
HabiticaApplication.User = user;
|
||||
|
|
|
|||
|
|
@ -64,8 +64,6 @@ public class AvatarWithBarsViewModel implements View.OnClickListener {
|
|||
setValueBar(xpBar, 1, 1, context.getString(R.string.XP_default), R.color.xpColor, R.drawable.ic_header_exp);
|
||||
setValueBar(mpBar, 100, 100, context.getString(R.string.MP_default), R.color.mpColor, R.drawable.ic_header_magic);
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
|
||||
gemsText.setClickable(true);
|
||||
gemsText.setOnClickListener(this);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import com.habitrpg.android.habitica.HabiticaApplication;
|
||||
import com.habitrpg.android.habitica.MainActivity;
|
||||
import com.habitrpg.android.habitica.R;
|
||||
import com.habitrpg.android.habitica.events.BoughtGemsEvent;
|
||||
import com.habitrpg.android.habitica.ui.helpers.ViewHelper;
|
||||
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.BillingRequests;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
|
|
@ -19,12 +23,6 @@ import org.solovyev.android.checkout.Purchase;
|
|||
import org.solovyev.android.checkout.Purchases;
|
||||
import org.solovyev.android.checkout.RequestListener;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.InjectView;
|
||||
import butterknife.OnClick;
|
||||
import de.greenrobot.event.EventBus;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
||||
/**
|
||||
* Created by Negue on 24.11.2015.
|
||||
*/
|
||||
|
|
@ -32,11 +30,20 @@ public class GemsPurchaseFragment extends BaseFragment {
|
|||
|
||||
private static final int GEMS_TO_ADD = 21;
|
||||
|
||||
private Listener listener;
|
||||
|
||||
private BillingRequests billingRequests;
|
||||
|
||||
@InjectView(R.id.btn_purchase_gems)
|
||||
Button btnPurchaseGems;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
||||
listener = (Listener) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
|
@ -50,9 +57,11 @@ public class GemsPurchaseFragment extends BaseFragment {
|
|||
btnPurchaseGems.setEnabled(false);
|
||||
ViewHelper.SetBackgroundTint(btnPurchaseGems, container.getResources().getColor(R.color.brand));
|
||||
|
||||
MainActivity.checkout.destroyPurchaseFlow();
|
||||
final ActivityCheckout checkout = listener.getActivityCheckout();
|
||||
|
||||
MainActivity.checkout.createPurchaseFlow(new RequestListener<Purchase>() {
|
||||
checkout.destroyPurchaseFlow();
|
||||
|
||||
checkout.createPurchaseFlow(new RequestListener<Purchase>() {
|
||||
@Override
|
||||
public void onSuccess(Purchase purchase) {
|
||||
if(purchase.sku.equals(HabiticaApplication.Purchase20Gems)){
|
||||
|
|
@ -77,7 +86,7 @@ public class GemsPurchaseFragment extends BaseFragment {
|
|||
});
|
||||
|
||||
|
||||
MainActivity.checkout.whenReady(new Checkout.Listener() {
|
||||
checkout.whenReady(new Checkout.Listener() {
|
||||
@Override
|
||||
public void onReady(final BillingRequests billingRequests) {
|
||||
GemsPurchaseFragment.this.billingRequests = billingRequests;
|
||||
|
|
@ -132,7 +141,8 @@ public class GemsPurchaseFragment extends BaseFragment {
|
|||
public void onSuccess(Boolean aBoolean) {
|
||||
if (!aBoolean) {
|
||||
// no current product exist
|
||||
billingRequests.purchase(ProductTypes.IN_APP, HabiticaApplication.Purchase20Gems, null, MainActivity.checkout.getPurchaseFlow());
|
||||
final ActivityCheckout checkout = listener.getActivityCheckout();
|
||||
billingRequests.purchase(ProductTypes.IN_APP, HabiticaApplication.Purchase20Gems, null, checkout.getPurchaseFlow());
|
||||
}
|
||||
else{
|
||||
checkIfPendingPurchases();
|
||||
|
|
@ -147,4 +157,7 @@ public class GemsPurchaseFragment extends BaseFragment {
|
|||
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
ActivityCheckout getActivityCheckout();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ public class UpdateWidgetService extends Service implements HabitRPGUserCallback
|
|||
|
||||
HostConfig hc = PrefsActivity.fromContext(this);
|
||||
if (hc != null && hc.getApi() != null && !hc.getApi().equals("") && hc.getUser() != null && !hc.getUser().equals("")) {
|
||||
this.apiHelper = new APIHelper(this, hc);
|
||||
this.apiHelper = new APIHelper(hc);
|
||||
apiHelper.retrieveUser(new HabitRPGUserCallback(this));
|
||||
for (int widgetId : allWidgetIds) {
|
||||
RemoteViews remoteViews = new RemoteViews(this.getPackageName(), R.layout.simple_widget);
|
||||
|
|
|
|||
Loading…
Reference in a new issue