mirror of
https://github.com/sudoxnym/habitica-android.git
synced 2026-05-23 14:17:15 +00:00
Handle unbinding in the base fragment
This commit is contained in:
parent
fcc2f51b3c
commit
de6a737126
5 changed files with 14 additions and 47 deletions
|
|
@ -1,9 +1,9 @@
|
|||
package com.habitrpg.android.habitica.ui.fragments;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.CallSuper;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.support.v4.app.DialogFragment;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
|
@ -23,6 +23,9 @@ import org.json.JSONObject;
|
|||
|
||||
import java.util.Date;
|
||||
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
public class BaseFragment extends DialogFragment {
|
||||
|
||||
private boolean registerEventBus = false;
|
||||
|
|
@ -30,6 +33,8 @@ public class BaseFragment extends DialogFragment {
|
|||
public String tutorialStepIdentifier;
|
||||
public String tutorialText;
|
||||
|
||||
private Unbinder unbinder;
|
||||
|
||||
@Override
|
||||
public void setUserVisibleHint(boolean isVisibleToUser) {
|
||||
super.setUserVisibleHint(isVisibleToUser);
|
||||
|
|
@ -69,11 +74,19 @@ public class BaseFragment extends DialogFragment {
|
|||
return null;
|
||||
}
|
||||
|
||||
@CallSuper
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (registerEventBus) {
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
unbinder.unbind();
|
||||
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,8 +4,6 @@ import android.content.Context;
|
|||
import android.os.Bundle;
|
||||
import android.support.design.widget.TabLayout;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.FrameLayout;
|
||||
|
|
@ -17,9 +15,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
|||
import com.raizlabs.android.dbflow.sql.builder.Condition;
|
||||
import com.raizlabs.android.dbflow.sql.language.Select;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.EventBusException;
|
||||
|
||||
public abstract class BaseMainFragment extends BaseFragment {
|
||||
|
||||
public MainActivity activity;
|
||||
|
|
@ -95,12 +90,6 @@ public abstract class BaseMainFragment extends BaseFragment {
|
|||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
|
||||
super.onCreateOptionsMenu(menu, inflater);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSaveInstanceState(Bundle outState) {
|
||||
if (user != null) {
|
||||
|
|
|
|||
|
|
@ -26,9 +26,7 @@ import org.solovyev.android.checkout.RequestListener;
|
|||
import org.solovyev.android.checkout.Sku;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.OnClick;
|
||||
import butterknife.Unbinder;
|
||||
import io.fabric.sdk.android.Fabric;
|
||||
|
||||
public class GemsPurchaseFragment extends BaseMainFragment {
|
||||
|
|
@ -42,8 +40,6 @@ public class GemsPurchaseFragment extends BaseMainFragment {
|
|||
@BindView(R.id.btn_purchase_gems)
|
||||
Button btnPurchaseGems;
|
||||
|
||||
private Unbinder unbinder;
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
|
|
@ -59,8 +55,6 @@ public class GemsPurchaseFragment extends BaseMainFragment {
|
|||
|
||||
View v = inflater.inflate(R.layout.fragment_gem_purchase, container, false);
|
||||
|
||||
unbinder = ButterKnife.bind(this, v);
|
||||
|
||||
btnPurchaseGems.setEnabled(false);
|
||||
ViewHelper.SetBackgroundTint(btnPurchaseGems, ContextCompat.getColor(container.getContext(), R.color.brand));
|
||||
|
||||
|
|
@ -188,12 +182,6 @@ public class GemsPurchaseFragment extends BaseMainFragment {
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
public interface Listener {
|
||||
ActivityCheckout getActivityCheckout();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -29,8 +29,6 @@ import org.greenrobot.eventbus.Subscribe;
|
|||
import java.util.List;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
public class SkillsFragment extends BaseMainFragment {
|
||||
|
||||
|
|
@ -61,14 +59,11 @@ public class SkillsFragment extends BaseMainFragment {
|
|||
RecyclerView mRecyclerView;
|
||||
|
||||
SkillsRecyclerViewAdapter adapter;
|
||||
Unbinder unbinder;
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(activity));
|
||||
mRecyclerView.setAdapter(adapter);
|
||||
}
|
||||
|
|
@ -144,11 +139,4 @@ public class SkillsFragment extends BaseMainFragment {
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -17,8 +17,6 @@ import com.magicmicky.habitrpgwrapper.lib.models.HabitRPGUser;
|
|||
import java.util.ArrayList;
|
||||
|
||||
import butterknife.BindView;
|
||||
import butterknife.ButterKnife;
|
||||
import butterknife.Unbinder;
|
||||
|
||||
/**
|
||||
* Created by Negue on 15.09.2015.
|
||||
|
|
@ -37,7 +35,6 @@ public class PartyMemberListFragment extends Fragment {
|
|||
}
|
||||
|
||||
private View view;
|
||||
private Unbinder unbinder;
|
||||
|
||||
@BindView(R.id.recyclerView)
|
||||
RecyclerView mRecyclerView;
|
||||
|
|
@ -55,8 +52,6 @@ public class PartyMemberListFragment extends Fragment {
|
|||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
unbinder = ButterKnife.bind(this, view);
|
||||
|
||||
mRecyclerView.setLayoutManager(new LinearLayoutManager(ctx));
|
||||
viewAdapter = new PartyMemberRecyclerViewAdapter();
|
||||
viewAdapter.context = this.ctx;
|
||||
|
|
@ -72,10 +67,4 @@ public class PartyMemberListFragment extends Fragment {
|
|||
viewAdapter.setMemberList(members);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
super.onDestroyView();
|
||||
unbinder.unbind();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue