From 8b87de2f295beccb5ecc69b9ca935412e5653540 Mon Sep 17 00:00:00 2001 From: serso Date: Sat, 20 Feb 2016 14:34:23 +0100 Subject: [PATCH] FragmentUi removed, AdUi added --- .../android/calculator/AppComponent.java | 2 +- .../android/calculator/BaseFragment.java | 99 +++++++-------- .../android/calculator/DisplayFragment.java | 7 +- .../android/calculator/EditorFragment.java | 11 +- .../android/calculator/FragmentTab.java | 25 ++-- .../android/calculator/FragmentUi.java | 117 ------------------ .../android/calculator/KeyboardFragment.java | 10 +- .../calculator/about/AboutActivity.java | 5 - .../calculator/about/AboutFragment.java | 10 +- .../about/ReleaseNotesFragment.java | 11 +- .../solovyev/android/calculator/ads/AdUi.java | 109 ++++++++++++++++ .../entities/BaseEntitiesFragment.java | 6 +- .../functions/FunctionsFragment.java | 12 +- .../history/BaseHistoryFragment.java | 1 + .../history/RecentHistoryFragment.java | 11 -- .../history/SavedHistoryFragment.java | 12 -- .../calculator/matrix/EditMatrixFragment.java | 13 +- .../operators/OperatorsFragment.java | 11 +- .../variables/VariablesFragment.java | 8 +- 19 files changed, 199 insertions(+), 281 deletions(-) delete mode 100644 app/src/main/java/org/solovyev/android/calculator/FragmentUi.java create mode 100644 app/src/main/java/org/solovyev/android/calculator/ads/AdUi.java diff --git a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java index a98a17b8..caa73c47 100644 --- a/app/src/main/java/org/solovyev/android/calculator/AppComponent.java +++ b/app/src/main/java/org/solovyev/android/calculator/AppComponent.java @@ -27,7 +27,6 @@ public interface AppComponent { void inject(CalculatorApplication application); void inject(EditorFragment fragment); void inject(BaseUi ui); - void inject(FragmentUi ui); void inject(FloatingCalculatorService service); void inject(BaseHistoryFragment fragment); void inject(BaseDialogFragment fragment); @@ -49,4 +48,5 @@ public interface AppComponent { void inject(BaseKeyboardUi ui); void inject(FloatingCalculatorView view); void inject(DragButtonWizardStep fragment); + void inject(BaseFragment fragment); } diff --git a/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java b/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java index 8f3eb063..ef228806 100644 --- a/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/BaseFragment.java @@ -1,71 +1,72 @@ package org.solovyev.android.calculator; import android.os.Bundle; +import android.support.annotation.LayoutRes; import android.support.annotation.StringRes; import android.support.v4.app.Fragment; import android.view.*; +import org.solovyev.android.calculator.ads.AdUi; import javax.annotation.Nonnull; +import javax.inject.Inject; import static android.view.Menu.NONE; import static org.solovyev.android.calculator.App.cast; public abstract class BaseFragment extends Fragment { - protected FragmentUi ui; + private final int layout; + @Inject + AdUi adUi; - @Override - public void onCreate(Bundle savedInstanceState) { - super.onCreate(savedInstanceState); - inject(cast(getActivity().getApplication()).getComponent()); - ui = createUi(); - ui.onCreate(this); - } - - @Nonnull - protected abstract FragmentUi createUi(); - - @Nonnull - protected final FragmentUi createUi(@Nonnull FragmentTab tab) { - return new FragmentUi(tab.layout); - } - - protected void inject(@Nonnull AppComponent component) { - } - - @Override - public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = ui.onCreateView(inflater, container); - ui.onCreateView(this, view); - return view; - } - - @Override - public void onResume() { - super.onResume(); - ui.onResume(); - } - - @Override - public void onPause() { - ui.onPause(); - super.onPause(); - } - - @Override - public void onDestroyView() { - ui.onDestroyView(); - super.onDestroyView(); - } - - @Override - public void onDestroy() { - ui.onDestroy(); - super.onDestroy(); + protected BaseFragment(@LayoutRes int layout) { + this.layout = layout; } @Nonnull public static MenuItem addMenu(@Nonnull ContextMenu menu, @StringRes int label, @Nonnull MenuItem.OnMenuItemClickListener listener) { return menu.add(NONE, label, NONE, label).setOnMenuItemClickListener(listener); } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + inject(cast(getActivity().getApplication()).getComponent()); + adUi.onCreate(); + } + + protected void inject(@Nonnull AppComponent component) { + component.inject(this); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { + final View view = inflater.inflate(layout, container, false); + adUi.onCreateView(view); + return view; + } + + @Override + public void onResume() { + super.onResume(); + adUi.onResume(); + } + + @Override + public void onPause() { + adUi.onPause(); + super.onPause(); + } + + @Override + public void onDestroyView() { + adUi.onDestroyView(); + super.onDestroyView(); + } + + @Override + public void onDestroy() { + adUi.onDestroy(); + super.onDestroy(); + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java b/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java index 351c3644..ac0beb33 100644 --- a/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/DisplayFragment.java @@ -26,6 +26,7 @@ import android.app.Activity; import android.content.Context; import android.content.SharedPreferences; import android.os.Bundle; +import android.support.annotation.LayoutRes; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.annotation.StringRes; @@ -93,10 +94,8 @@ public class DisplayFragment extends BaseFragment implements View.OnClickListene @Inject Calculator calculator; - @Nonnull - @Override - protected FragmentUi createUi() { - return new FragmentUi(R.layout.cpp_app_display); + public DisplayFragment() { + super(R.layout.cpp_app_display); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java b/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java index 85bf428c..c18856e0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/EditorFragment.java @@ -50,6 +50,10 @@ public class EditorFragment extends BaseFragment { @Bind(R.id.calculator_editor) EditorView editorView; + public EditorFragment() { + super(R.layout.cpp_app_editor); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -62,12 +66,6 @@ public class EditorFragment extends BaseFragment { component.inject(this); } - @Nonnull - @Override - protected FragmentUi createUi() { - return new FragmentUi(R.layout.cpp_app_editor); - } - @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { final View view = super.onCreateView(inflater, container, savedInstanceState); @@ -79,7 +77,6 @@ public class EditorFragment extends BaseFragment { @Override public void onDestroyView() { editor.clearView(editorView); - ui.onDestroyView(); super.onDestroyView(); } diff --git a/app/src/main/java/org/solovyev/android/calculator/FragmentTab.java b/app/src/main/java/org/solovyev/android/calculator/FragmentTab.java index 962ef30f..891c19c0 100644 --- a/app/src/main/java/org/solovyev/android/calculator/FragmentTab.java +++ b/app/src/main/java/org/solovyev/android/calculator/FragmentTab.java @@ -22,7 +22,6 @@ package org.solovyev.android.calculator; -import android.support.annotation.LayoutRes; import android.support.annotation.StringRes; import android.support.v4.app.Fragment; import org.solovyev.android.calculator.about.AboutFragment; @@ -38,22 +37,17 @@ import javax.annotation.Nonnull; public enum FragmentTab { - editor(EditorFragment.class, R.layout.cpp_app_editor, R.string.editor), - //display(CalculatorHistoryFragment.class, "history", R.layout.fragment_history, R.string.c_history), - //keyboard(CalculatorHistoryFragment.class, "history", R.layout.fragment_history, R.string.c_history), - history(RecentHistoryFragment.class, R.layout.fragment_history, R.string.cpp_history_tab_recent), - saved_history(SavedHistoryFragment.class, R.layout.fragment_history, R.string.cpp_history_tab_saved), - variables(VariablesFragment.class, R.layout.fragment_entities, R.string.c_vars), - functions(FunctionsFragment.class, R.layout.fragment_entities, R.string.c_functions), - operators(OperatorsFragment.class, R.layout.fragment_entities, R.string.c_operators), - about(AboutFragment.class, R.layout.about_fragment, R.string.c_about), + history(RecentHistoryFragment.class, R.string.cpp_history_tab_recent), + saved_history(SavedHistoryFragment.class, R.string.cpp_history_tab_saved), + variables(VariablesFragment.class, R.string.c_vars), + functions(FunctionsFragment.class, R.string.c_functions), + operators(OperatorsFragment.class, R.string.c_operators), + about(AboutFragment.class, R.string.c_about), // todo serso: strings - matrix_edit(EditMatrixFragment.class, R.layout.matrix_edit_fragment, R.string.c_release_notes), - release_notes(ReleaseNotesFragment.class, R.layout.release_notes_fragment, R.string.c_release_notes); + matrix_edit(EditMatrixFragment.class, R.string.c_release_notes), + release_notes(ReleaseNotesFragment.class, R.string.c_release_notes); - @LayoutRes - public final int layout; @Nonnull public final Class type; @StringRes @@ -61,9 +55,8 @@ public enum FragmentTab { @Nonnull public final String tag; - FragmentTab(@Nonnull Class type, int layout, int title) { + FragmentTab(@Nonnull Class type, int title) { this.type = type; - this.layout = layout; this.title = title; this.tag = name(); } diff --git a/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java b/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java deleted file mode 100644 index 9e696e71..00000000 --- a/app/src/main/java/org/solovyev/android/calculator/FragmentUi.java +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright 2013 serso aka se.solovyev - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - * - * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ - * Contact details - * - * Email: se.solovyev@gmail.com - * Site: http://se.solovyev.org - */ - -package org.solovyev.android.calculator; - -import android.support.v4.app.Fragment; -import android.view.LayoutInflater; -import android.view.View; -import android.view.ViewGroup; -import butterknife.Bind; -import butterknife.ButterKnife; -import org.solovyev.android.checkout.CppCheckout; -import org.solovyev.android.checkout.Inventory; -import org.solovyev.android.checkout.ProductTypes; - -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Inject; - -import static org.solovyev.android.calculator.App.cast; - -public class FragmentUi { - private final int layoutId; - @Nullable - private Boolean adFree = null; - @Inject - CppCheckout checkout; - @Nullable - @Bind(R.id.admob) - AdView adView; - - public FragmentUi(int layoutId) { - this.layoutId = layoutId; - } - - public void onCreate(@Nonnull Fragment fragment) { - cast(fragment).getComponent().inject(this); - checkout.start(); - } - - public void onResume() { - if (adView != null) { - adView.resume(); - } - checkout.loadInventory().whenLoaded(new Inventory.Listener() { - @Override - public void onLoaded(@Nonnull Inventory.Products products) { - adFree = products.get(ProductTypes.IN_APP).isPurchased("ad_free"); - updateAdView(); - } - }); - } - - private void updateAdView() { - if (adFree == null || adView == null) { - return; - } - - if (adFree) { - adView.hide(); - } else { - adView.show(); - } - } - - public void onPause() { - adFree = null; - if (adView != null) { - adView.pause(); - } - } - - public void onCreateView(@Nonnull Fragment fragment, @Nonnull View root) { - ButterKnife.bind(this, root); - if (fragment instanceof DisplayFragment || fragment instanceof EditorFragment || fragment instanceof KeyboardFragment) { - // no ads in those fragments - } else if (adView != null) { - updateAdView(); - } - } - - public void onDestroy() { - checkout.stop(); - } - - @Nonnull - public View onCreateView(@Nonnull LayoutInflater inflater, @Nullable ViewGroup container) { - return inflater.inflate(layoutId, container, false); - } - - public void onDestroyView() { - if (adView == null) { - return; - } - adView.destroy(); - adView = null; - } -} diff --git a/app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java b/app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java index 515a7de5..2650c0f2 100644 --- a/app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/KeyboardFragment.java @@ -41,6 +41,10 @@ public class KeyboardFragment extends BaseFragment { @Inject KeyboardUi keyboardUi; + public KeyboardFragment() { + super(R.layout.cpp_app_keyboard); + } + @Override protected void inject(@Nonnull AppComponent component) { super.inject(component); @@ -56,12 +60,6 @@ public class KeyboardFragment extends BaseFragment { return view; } - @Nonnull - @Override - protected FragmentUi createUi() { - return new FragmentUi(R.layout.cpp_app_keyboard); - } - @Override public void onDestroyView() { keyboardUi.onDestroyView(); diff --git a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java index e24ba387..cd1b1c3b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutActivity.java @@ -30,11 +30,6 @@ import org.solovyev.android.calculator.R; import javax.annotation.Nullable; -/** - * User: serso - * Date: 9/16/11 - * Time: 11:52 PM - */ public class AboutActivity extends EmptyActivity { @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java b/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java index ce9d125a..33e4e62b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/AboutFragment.java @@ -33,13 +33,9 @@ import butterknife.Bind; import butterknife.ButterKnife; import org.solovyev.android.calculator.App; import org.solovyev.android.calculator.BaseFragment; -import org.solovyev.android.calculator.FragmentUi; import org.solovyev.android.calculator.R; -import javax.annotation.Nonnull; - import static android.view.View.GONE; -import static org.solovyev.android.calculator.FragmentTab.about; import static org.solovyev.common.text.Strings.isEmpty; public class AboutFragment extends BaseFragment { @@ -53,10 +49,8 @@ public class AboutFragment extends BaseFragment { @Bind(R.id.about_translators) TextView translatorsView; - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(about); + public AboutFragment() { + super(R.layout.about_fragment); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java b/app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java index 345af06e..9cfddf2a 100644 --- a/app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/about/ReleaseNotesFragment.java @@ -32,23 +32,16 @@ import android.widget.TextView; import butterknife.Bind; import butterknife.ButterKnife; import org.solovyev.android.calculator.BaseFragment; -import org.solovyev.android.calculator.FragmentUi; import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.release.ReleaseNotes; -import javax.annotation.Nonnull; - -import static org.solovyev.android.calculator.FragmentTab.release_notes; - public class ReleaseNotesFragment extends BaseFragment { @Bind(R.id.releasenotes_text) TextView text; - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(release_notes); + public ReleaseNotesFragment() { + super(R.layout.release_notes_fragment); } @Override diff --git a/app/src/main/java/org/solovyev/android/calculator/ads/AdUi.java b/app/src/main/java/org/solovyev/android/calculator/ads/AdUi.java new file mode 100644 index 00000000..c364cf24 --- /dev/null +++ b/app/src/main/java/org/solovyev/android/calculator/ads/AdUi.java @@ -0,0 +1,109 @@ +package org.solovyev.android.calculator.ads; + +import android.os.Handler; +import android.os.Looper; +import android.support.annotation.NonNull; +import android.view.View; +import butterknife.Bind; +import butterknife.ButterKnife; +import org.solovyev.android.calculator.AdView; +import org.solovyev.android.calculator.R; +import org.solovyev.android.checkout.CppCheckout; +import org.solovyev.android.checkout.Inventory; + +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; + +import static org.solovyev.android.checkout.ProductTypes.IN_APP; + +public class AdUi { + + @NonNull + private final CppCheckout checkout; + @NonNull + private final Handler handler; + @Nullable + @Bind(R.id.ad) + AdView adView; + @Nullable + private Boolean adFree = null; + + @Inject + public AdUi(@NonNull CppCheckout checkout, @NonNull Handler handler) { + this.checkout = checkout; + this.handler = handler; + } + + public void onCreate() { + checkout.start(); + } + + public void onResume() { + if (adView == null) { + return; + } + adView.resume(); + checkout.loadInventory().whenLoaded(onMainThread(new Inventory.Listener() { + @Override + public void onLoaded(@Nonnull Inventory.Products products) { + adFree = products.get(IN_APP).isPurchased("ad_free"); + updateAdView(); + } + })); + } + + private void updateAdView() { + if (adFree == null || adView == null) { + return; + } + + if (adFree) { + adView.hide(); + } else { + adView.show(); + } + } + + @Nonnull + private Inventory.Listener onMainThread(@Nonnull final Inventory.Listener listener) { + return new Inventory.Listener() { + @Override + public void onLoaded(@Nonnull final Inventory.Products products) { + if (handler.getLooper() == Looper.myLooper()) { + listener.onLoaded(products); + return; + } + handler.post(new Runnable() { + @Override + public void run() { + listener.onLoaded(products); + } + }); + } + }; + } + + public void onCreateView(@NonNull View view) { + ButterKnife.bind(this, view); + } + + public void onPause() { + adFree = null; + if (adView != null) { + adView.pause(); + } + } + + public void onDestroyView() { + if (adView == null) { + return; + } + adView.destroy(); + adView = null; + } + + public void onDestroy() { + checkout.stop(); + } +} diff --git a/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java b/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java index a3efc866..afb28eaf 100644 --- a/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/entities/BaseEntitiesFragment.java @@ -71,6 +71,10 @@ public abstract class BaseEntitiesFragment extends BaseFra @Nullable private String category; + public BaseEntitiesFragment() { + super(R.layout.fragment_entities); + } + @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); @@ -83,7 +87,7 @@ public abstract class BaseEntitiesFragment extends BaseFra @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - final View view = ui.onCreateView(inflater, container); + final View view = super.onCreateView(inflater, container, savedInstanceState); ButterKnife.bind(this, view); final Context context = inflater.getContext(); adapter = new EntitiesAdapter(context, TextUtils.isEmpty(category) ? getEntities() : getEntities(category)); diff --git a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java index 1b3c8767..e4f9b432 100644 --- a/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/functions/FunctionsFragment.java @@ -32,7 +32,9 @@ import com.squareup.otto.Subscribe; import jscl.math.function.Function; import jscl.math.function.IFunction; import org.solovyev.android.Check; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.AppComponent; +import org.solovyev.android.calculator.Calculator; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.calculator.entities.EntityRemovalDialog; @@ -43,8 +45,6 @@ import javax.inject.Inject; import java.util.ArrayList; import java.util.List; -import static org.solovyev.android.calculator.FragmentTab.functions; - public class FunctionsFragment extends BaseEntitiesFragment { @Inject @@ -54,12 +54,6 @@ public class FunctionsFragment extends BaseEntitiesFragment { @Inject Bus bus; - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(functions); - } - @Override protected void inject(@Nonnull AppComponent component) { super.inject(component); diff --git a/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java index 72beef93..f98ee7ed 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/BaseHistoryFragment.java @@ -69,6 +69,7 @@ public abstract class BaseHistoryFragment extends BaseFragment { private HistoryAdapter adapter; protected BaseHistoryFragment(boolean recentHistory) { + super(R.layout.fragment_history); this.recentHistory = recentHistory; } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java index f216e48a..ae56d17b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/RecentHistoryFragment.java @@ -22,20 +22,9 @@ package org.solovyev.android.calculator.history; -import org.solovyev.android.calculator.FragmentTab; -import org.solovyev.android.calculator.FragmentUi; - -import javax.annotation.Nonnull; - public class RecentHistoryFragment extends BaseHistoryFragment { public RecentHistoryFragment() { super(true); } - - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(FragmentTab.history); - } } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java index ca2c3e17..5aea207e 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/SavedHistoryFragment.java @@ -22,21 +22,9 @@ package org.solovyev.android.calculator.history; -import org.solovyev.android.calculator.FragmentUi; - -import javax.annotation.Nonnull; - -import static org.solovyev.android.calculator.FragmentTab.saved_history; - public class SavedHistoryFragment extends BaseHistoryFragment { public SavedHistoryFragment() { super(false); } - - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(saved_history); - } } diff --git a/app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java b/app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java index 2c9528e5..9cc8386b 100644 --- a/app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/matrix/EditMatrixFragment.java @@ -24,16 +24,14 @@ package org.solovyev.android.calculator.matrix; import android.os.Bundle; import android.view.View; - -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.BaseFragment; +import org.solovyev.android.calculator.R; import org.solovyev.android.view.IntegerRange; import org.solovyev.android.view.Picker; import javax.annotation.Nonnull; import javax.annotation.Nullable; -import static org.solovyev.android.calculator.FragmentTab.matrix_edit; - public class EditMatrixFragment extends BaseFragment implements Picker.OnChangedListener { private static final int MAX_COUNT = 10; private static final int MIN_COUNT = 2; @@ -43,15 +41,10 @@ public class EditMatrixFragment extends BaseFragment implements Picker.OnChanged private static final String MATRIX = "matrix"; public EditMatrixFragment() { + super(R.layout.matrix_edit_fragment); setRetainInstance(true); } - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(matrix_edit); - } - @Override public void onViewCreated(View root, @Nullable Bundle in) { super.onViewCreated(root, in); diff --git a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java index 3915a9c6..5b4b6a40 100644 --- a/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/operators/OperatorsFragment.java @@ -26,7 +26,8 @@ import android.support.annotation.NonNull; import android.view.ContextMenu; import android.view.MenuItem; import jscl.math.operator.Operator; -import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.AppComponent; +import org.solovyev.android.calculator.R; import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.entities.Category; import org.solovyev.common.text.Strings; @@ -37,8 +38,6 @@ import javax.inject.Inject; import java.util.ArrayList; import java.util.List; -import static org.solovyev.android.calculator.FragmentTab.operators; - public class OperatorsFragment extends BaseEntitiesFragment { @Inject @@ -46,12 +45,6 @@ public class OperatorsFragment extends BaseEntitiesFragment { @Inject PostfixFunctionsRegistry postfixFunctionsRegistry; - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(operators); - } - @Override protected void inject(@Nonnull AppComponent component) { super.inject(component); diff --git a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java index 83aec8d3..1cce1599 100644 --- a/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/variables/VariablesFragment.java @@ -32,10 +32,10 @@ import com.squareup.otto.Subscribe; import jscl.math.function.IConstant; import org.solovyev.android.Check; import org.solovyev.android.calculator.*; +import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.android.calculator.entities.Category; import org.solovyev.android.calculator.entities.EntityRemovalDialog; import org.solovyev.android.calculator.math.MathType; -import org.solovyev.android.calculator.entities.BaseEntitiesFragment; import org.solovyev.common.JPredicate; import org.solovyev.common.collections.Collections; import org.solovyev.common.text.Strings; @@ -57,12 +57,6 @@ public class VariablesFragment extends BaseEntitiesFragment { @Inject Bus bus; - @Nonnull - @Override - protected FragmentUi createUi() { - return createUi(variables); - } - public static boolean isValidValue(@Nonnull String value) { try { final PreparedExpression pe = ToJsclTextProcessor.getInstance().process(value);