Google Analytics services updated + memory leaks fixed
This commit is contained in:
@@ -5,15 +5,21 @@ import android.util.AttributeSet;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.google.android.gms.ads.AdListener;
|
||||
import com.google.android.gms.ads.AdRequest;
|
||||
|
||||
import org.solovyev.android.Check;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public class AdView extends FrameLayout {
|
||||
|
||||
@Nullable
|
||||
private com.google.android.gms.ads.AdView admobView;
|
||||
@Nullable
|
||||
private AdView.AdViewListener admobListener;
|
||||
|
||||
public AdView(Context context) {
|
||||
super(context);
|
||||
@@ -28,8 +34,18 @@ public class AdView extends FrameLayout {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
destroyAdmobView();
|
||||
}
|
||||
|
||||
private void destroyAdmobView() {
|
||||
if (admobView != null) {
|
||||
admobView.destroy();
|
||||
admobView.setAdListener(null);
|
||||
admobView = null;
|
||||
}
|
||||
if(admobListener != null) {
|
||||
admobListener.destroy();
|
||||
admobListener = null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,22 +68,13 @@ public class AdView extends FrameLayout {
|
||||
|
||||
LayoutInflater.from(getContext()).inflate(R.layout.admob, this);
|
||||
admobView = (com.google.android.gms.ads.AdView) findViewById(R.id.admob);
|
||||
if (admobView == null) throw new AssertionError();
|
||||
Check.isNotNull(admobView);
|
||||
if (admobView == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
admobView.setAdListener(new AdListener() {
|
||||
@Override
|
||||
public void onAdFailedToLoad(int errorCode) {
|
||||
hide();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLoaded() {
|
||||
if (admobView != null) {
|
||||
admobView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
setVisibility(VISIBLE);
|
||||
}
|
||||
});
|
||||
admobListener = new AdView.AdViewListener(this);
|
||||
admobView.setAdListener(admobListener);
|
||||
|
||||
final AdRequest.Builder b = new AdRequest.Builder();
|
||||
b.addTestDevice(AdRequest.DEVICE_ID_EMULATOR);
|
||||
@@ -87,7 +94,40 @@ public class AdView extends FrameLayout {
|
||||
|
||||
admobView.setVisibility(View.GONE);
|
||||
admobView.pause();
|
||||
admobView.destroy();
|
||||
admobView = null;
|
||||
destroyAdmobView();
|
||||
}
|
||||
|
||||
private static class AdViewListener extends AdListener {
|
||||
|
||||
@Nullable
|
||||
private AdView adView;
|
||||
|
||||
public AdViewListener(@Nonnull AdView adView) {
|
||||
this.adView = adView;
|
||||
}
|
||||
|
||||
void destroy() {
|
||||
adView = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdFailedToLoad(int errorCode) {
|
||||
if (adView != null) {
|
||||
adView.hide();
|
||||
adView = null;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdLoaded() {
|
||||
if (adView != null) {
|
||||
final com.google.android.gms.ads.AdView admobView = adView.admobView;
|
||||
if (admobView != null) {
|
||||
admobView.setVisibility(View.VISIBLE);
|
||||
}
|
||||
adView.setVisibility(VISIBLE);
|
||||
adView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -41,7 +41,7 @@ import javax.annotation.Nonnull;
|
||||
public class CalculatorDisplayFragment extends Fragment {
|
||||
|
||||
@Nonnull
|
||||
private FragmentUi fragmentHelper;
|
||||
private FragmentUi fragmentUi;
|
||||
@Nonnull
|
||||
private AndroidCalculatorDisplayView displayView;
|
||||
|
||||
@@ -52,17 +52,17 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this.getActivity());
|
||||
final Preferences.Gui.Layout layout = Preferences.Gui.getLayout(prefs);
|
||||
if (!layout.isOptimized()) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display_mobile, R.string.result);
|
||||
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display_mobile, R.string.result);
|
||||
} else {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display, R.string.result);
|
||||
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(R.layout.cpp_app_display, R.string.result);
|
||||
}
|
||||
|
||||
fragmentHelper.onCreate(this);
|
||||
fragmentUi.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentHelper.onCreateView(this, inflater, container);
|
||||
return fragmentUi.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -73,7 +73,7 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
displayView.init(getActivity());
|
||||
Locator.getInstance().getDisplay().setView(displayView);
|
||||
|
||||
fragmentHelper.onViewCreated(this, root);
|
||||
fragmentUi.onViewCreated(this, root);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -85,12 +85,12 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
fragmentHelper.onResume(this);
|
||||
fragmentUi.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
fragmentHelper.onPause(this);
|
||||
fragmentUi.onPause(this);
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
@@ -98,12 +98,13 @@ public class CalculatorDisplayFragment extends Fragment {
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
Locator.getInstance().getDisplay().clearView(displayView);
|
||||
fragmentUi.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
fragmentHelper.onDestroy(this);
|
||||
fragmentUi.onDestroy(this);
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
|
@@ -105,6 +105,7 @@ public class CalculatorEditorFragment extends Fragment {
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
Locator.getInstance().getEditor().clearView(editorView);
|
||||
fragmentUi.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
|
@@ -40,18 +40,18 @@ import javax.annotation.Nonnull;
|
||||
public abstract class CalculatorFragment extends Fragment {
|
||||
|
||||
@Nonnull
|
||||
private final FragmentUi fragmentHelper;
|
||||
private final FragmentUi fragmentUi;
|
||||
|
||||
protected CalculatorFragment(int layoutResId, int titleResId) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
|
||||
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
|
||||
}
|
||||
|
||||
protected CalculatorFragment(@Nonnull CalculatorFragmentType fragmentType) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||
fragmentUi = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||
}
|
||||
|
||||
protected CalculatorFragment(@Nonnull FragmentUi fragmentHelper) {
|
||||
this.fragmentHelper = fragmentHelper;
|
||||
protected CalculatorFragment(@Nonnull FragmentUi fragmentUi) {
|
||||
this.fragmentUi = fragmentUi;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,43 +63,44 @@ public abstract class CalculatorFragment extends Fragment {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
fragmentHelper.onCreate(this);
|
||||
fragmentUi.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentHelper.onCreateView(this, inflater, container);
|
||||
return fragmentUi.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
fragmentHelper.onViewCreated(this, view);
|
||||
fragmentUi.onViewCreated(this, view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
this.fragmentHelper.onResume(this);
|
||||
this.fragmentUi.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
this.fragmentHelper.onPause(this);
|
||||
this.fragmentUi.onPause(this);
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
fragmentUi.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
fragmentHelper.onDestroy(this);
|
||||
fragmentUi.onDestroy(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
@@ -109,6 +110,6 @@ public abstract class CalculatorFragment extends Fragment {
|
||||
}
|
||||
|
||||
public boolean isPaneFragment() {
|
||||
return fragmentHelper.isPane(this);
|
||||
return fragmentUi.isPane(this);
|
||||
}
|
||||
}
|
||||
|
@@ -89,6 +89,12 @@ public class CalculatorKeyboardFragment extends Fragment implements SharedPrefer
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
ui.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
@@ -40,18 +40,18 @@ import javax.annotation.Nonnull;
|
||||
public abstract class CalculatorListFragment extends ListFragment {
|
||||
|
||||
@Nonnull
|
||||
private final FragmentUi fragmentHelper;
|
||||
private final FragmentUi ui;
|
||||
|
||||
protected CalculatorListFragment(int layoutResId, int titleResId) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
|
||||
ui = CalculatorApplication.getInstance().createFragmentHelper(layoutResId, titleResId);
|
||||
}
|
||||
|
||||
protected CalculatorListFragment(@Nonnull CalculatorFragmentType fragmentType) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||
}
|
||||
|
||||
protected CalculatorListFragment(@Nonnull FragmentUi fragmentHelper) {
|
||||
this.fragmentHelper = fragmentHelper;
|
||||
protected CalculatorListFragment(@Nonnull FragmentUi ui) {
|
||||
this.ui = ui;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -63,43 +63,42 @@ public abstract class CalculatorListFragment extends ListFragment {
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
fragmentHelper.onCreate(this);
|
||||
ui.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentHelper.onCreateView(this, inflater, container);
|
||||
return ui.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View view, Bundle savedInstanceState) {
|
||||
super.onViewCreated(view, savedInstanceState);
|
||||
|
||||
fragmentHelper.onViewCreated(this, view);
|
||||
ui.onViewCreated(this, view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
this.fragmentHelper.onResume(this);
|
||||
this.ui.onResume(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
this.fragmentHelper.onPause(this);
|
||||
|
||||
this.ui.onPause(this);
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
ui.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
fragmentHelper.onDestroy(this);
|
||||
ui.onDestroy(this);
|
||||
super.onDestroy();
|
||||
}
|
||||
|
||||
|
@@ -27,15 +27,18 @@ import android.support.v4.app.FragmentActivity;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.ViewParent;
|
||||
import android.widget.TextView;
|
||||
|
||||
import org.solovyev.android.checkout.ActivityCheckout;
|
||||
import org.solovyev.android.checkout.Checkout;
|
||||
import org.solovyev.android.checkout.Inventory;
|
||||
import org.solovyev.android.checkout.ProductTypes;
|
||||
|
||||
import java.util.Locale;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* User: serso
|
||||
@@ -169,11 +172,6 @@ public class FragmentUi extends BaseUi {
|
||||
}
|
||||
|
||||
public void onDestroy(@Nonnull Fragment fragment) {
|
||||
if (adView != null) {
|
||||
adView.destroy();
|
||||
adView = null;
|
||||
}
|
||||
|
||||
if (listenersOnCreate) {
|
||||
if (fragment instanceof CalculatorEventListener) {
|
||||
Locator.getInstance().getCalculator().removeCalculatorEventListener((CalculatorEventListener) fragment);
|
||||
@@ -189,4 +187,11 @@ public class FragmentUi extends BaseUi {
|
||||
public View onCreateView(@Nonnull Fragment fragment, @Nonnull LayoutInflater inflater, @Nullable ViewGroup container) {
|
||||
return inflater.inflate(layoutId, container, false);
|
||||
}
|
||||
|
||||
public void onDestroyView(@Nonnull Fragment fragment) {
|
||||
if (adView != null) {
|
||||
adView.destroy();
|
||||
adView = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -32,15 +32,36 @@ import android.preference.PreferenceManager;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.util.Log;
|
||||
import android.view.*;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.Menu;
|
||||
import android.view.MenuInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import org.solovyev.android.calculator.*;
|
||||
|
||||
import org.solovyev.android.calculator.App;
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.FragmentUi;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.Preferences;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.android.menu.*;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.ActivityMenu;
|
||||
import org.solovyev.android.menu.AndroidMenuHelper;
|
||||
import org.solovyev.android.menu.ContextMenuBuilder;
|
||||
import org.solovyev.android.menu.IdentifiableMenuItem;
|
||||
import org.solovyev.android.menu.ListActivityMenu;
|
||||
import org.solovyev.android.menu.ListContextMenu;
|
||||
import org.solovyev.common.JPredicate;
|
||||
import org.solovyev.common.collections.Collections;
|
||||
import org.solovyev.common.equals.Equalizer;
|
||||
@@ -48,12 +69,13 @@ import org.solovyev.common.filter.Filter;
|
||||
import org.solovyev.common.filter.FilterRulesChain;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import static org.solovyev.android.calculator.CalculatorEventType.clear_history_requested;
|
||||
|
||||
public abstract class BaseHistoryFragment extends ListFragment implements CalculatorEventListener {
|
||||
@@ -97,7 +119,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
private HistoryArrayAdapter adapter;
|
||||
|
||||
@Nonnull
|
||||
private FragmentUi fragmentHelper;
|
||||
private FragmentUi ui;
|
||||
|
||||
private final ActivityMenu<Menu, MenuItem> menu = ListActivityMenu.fromResource(R.menu.history_menu, HistoryMenu.class, AndroidMenuHelper.getInstance(), new HistoryMenuFilter());
|
||||
|
||||
@@ -119,14 +141,14 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
private AlertDialog clearDialog;
|
||||
|
||||
protected BaseHistoryFragment(@Nonnull CalculatorFragmentType fragmentType) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false);
|
||||
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId(), false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
fragmentHelper.onCreate(this);
|
||||
ui.onCreate(this);
|
||||
|
||||
setHasOptionsMenu(true);
|
||||
|
||||
@@ -139,7 +161,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentHelper.onCreateView(this, inflater, container);
|
||||
return ui.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -149,7 +171,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
final SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(getActivity());
|
||||
final Boolean showDatetime = Preferences.History.showDatetime.getPreference(preferences);
|
||||
|
||||
fragmentHelper.onViewCreated(this, root);
|
||||
ui.onViewCreated(this, root);
|
||||
|
||||
adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), org.solovyev.android.calculator.R.id.history_item, new ArrayList<CalculatorHistoryState>(), showDatetime);
|
||||
setListAdapter(adapter);
|
||||
@@ -213,7 +235,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
this.fragmentHelper.onResume(this);
|
||||
this.ui.onResume(this);
|
||||
|
||||
updateAdapter();
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).registerOnSharedPreferenceChangeListener(preferencesListener);
|
||||
@@ -223,11 +245,17 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
public void onPause() {
|
||||
PreferenceManager.getDefaultSharedPreferences(getActivity()).unregisterOnSharedPreferenceChangeListener(preferencesListener);
|
||||
|
||||
this.fragmentHelper.onPause(this);
|
||||
this.ui.onPause(this);
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
ui.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
logDebug("onDestroy");
|
||||
@@ -235,7 +263,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
clearDialog.dismiss();
|
||||
clearDialog = null;
|
||||
}
|
||||
fragmentHelper.onDestroy(this);
|
||||
ui.onDestroy(this);
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -425,7 +453,7 @@ public abstract class BaseHistoryFragment extends ListFragment implements Calcul
|
||||
if (menuItem instanceof IdentifiableMenuItem<?>) {
|
||||
switch (((IdentifiableMenuItem) menuItem).getItemId()) {
|
||||
case R.id.menu_history_fullscreen:
|
||||
result = !fragmentHelper.isPane(BaseHistoryFragment.this);
|
||||
result = !ui.isPane(BaseHistoryFragment.this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@@ -25,6 +25,7 @@ package org.solovyev.android.calculator.math.edit;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -33,20 +34,13 @@ import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import org.solovyev.android.calculator.CalculatorApplication;
|
||||
import org.solovyev.android.calculator.CalculatorEventData;
|
||||
import org.solovyev.android.calculator.CalculatorEventListener;
|
||||
import org.solovyev.android.calculator.CalculatorEventType;
|
||||
import org.solovyev.android.calculator.FragmentUi;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.CalculatorMathRegistry;
|
||||
import org.solovyev.android.calculator.Locator;
|
||||
import org.solovyev.android.calculator.FragmentUi;
|
||||
import org.solovyev.android.calculator.R;
|
||||
import org.solovyev.android.menu.AMenuItem;
|
||||
import org.solovyev.android.menu.ContextMenuBuilder;
|
||||
@@ -58,7 +52,11 @@ import org.solovyev.common.filter.Filter;
|
||||
import org.solovyev.common.math.MathEntity;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import android.support.v4.app.ListFragment;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
|
||||
/**
|
||||
@@ -94,13 +92,13 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
|
||||
private String category;
|
||||
|
||||
@Nonnull
|
||||
private final FragmentUi fragmentHelper;
|
||||
private final FragmentUi ui;
|
||||
|
||||
@Nonnull
|
||||
private final Handler uiHandler = new Handler();
|
||||
|
||||
protected AbstractMathEntityListFragment(@Nonnull CalculatorFragmentType fragmentType) {
|
||||
fragmentHelper = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||
ui = CalculatorApplication.getInstance().createFragmentHelper(fragmentType.getDefaultLayoutId(), fragmentType.getDefaultTitleResId());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -112,19 +110,19 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
|
||||
category = bundle.getString(MATH_ENTITY_CATEGORY_EXTRA_STRING);
|
||||
}
|
||||
|
||||
fragmentHelper.onCreate(this);
|
||||
ui.onCreate(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||
return fragmentHelper.onCreateView(this, inflater, container);
|
||||
return ui.onCreateView(this, inflater, container);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewCreated(View root, Bundle savedInstanceState) {
|
||||
super.onViewCreated(root, savedInstanceState);
|
||||
|
||||
fragmentHelper.onViewCreated(this, root);
|
||||
ui.onViewCreated(this, root);
|
||||
|
||||
final ListView lv = getListView();
|
||||
lv.setTextFilterEnabled(true);
|
||||
@@ -161,9 +159,15 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
|
||||
@Nullable
|
||||
protected abstract AMenuItem<T> getOnClickAction();
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
ui.onDestroyView(this);
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
fragmentHelper.onDestroy(this);
|
||||
ui.onDestroy(this);
|
||||
|
||||
super.onDestroy();
|
||||
}
|
||||
@@ -173,7 +177,7 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
this.fragmentHelper.onPause(this);
|
||||
this.ui.onPause(this);
|
||||
|
||||
super.onPause();
|
||||
}
|
||||
@@ -182,7 +186,7 @@ public abstract class AbstractMathEntityListFragment<T extends MathEntity> exten
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
|
||||
this.fragmentHelper.onResume(this);
|
||||
this.ui.onResume(this);
|
||||
|
||||
adapter = new MathEntityArrayAdapter<T>(getDescriptionGetter(), this.getActivity(), getMathEntitiesByCategory());
|
||||
setListAdapter(adapter);
|
||||
|
@@ -172,6 +172,30 @@ public class PreferencesFragment extends org.solovyev.android.material.preferenc
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onResume() {
|
||||
super.onResume();
|
||||
if (adView != null) {
|
||||
adView.resume();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPause() {
|
||||
if (adView != null) {
|
||||
adView.pause();
|
||||
}
|
||||
super.onPause();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroyView() {
|
||||
if (adView != null) {
|
||||
adView.destroy();
|
||||
}
|
||||
super.onDestroyView();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
App.getPreferences().unregisterOnSharedPreferenceChangeListener(this);
|
||||
|
Reference in New Issue
Block a user