This commit is contained in:
serso 2016-02-21 23:58:32 +01:00
parent b4ca63a39e
commit aa47871f5f
19 changed files with 226 additions and 124 deletions

View File

@ -86,7 +86,6 @@ dependencies {
compile 'com.google.android.gms:play-services-ads:8.4.0'
compile 'com.google.android.gms:play-services-base:8.4.0'
compile 'com.google.android.gms:play-services-analytics:8.4.0'
compile 'com.melnykov:floatingactionbutton:1.1.0'
compile(name: 'plotter', ext: 'aar')
testCompile 'com.squareup.leakcanary:leakcanary-android-no-op:1.3.1'
debugCompile 'com.squareup.leakcanary:leakcanary-android:1.3.1'

View File

@ -31,7 +31,9 @@ import android.graphics.Color;
import android.graphics.Typeface;
import android.os.Bundle;
import android.preference.PreferenceManager;
import android.support.annotation.DrawableRes;
import android.support.annotation.LayoutRes;
import android.support.design.widget.FloatingActionButton;
import android.support.v4.app.Fragment;
import android.support.v7.app.ActionBar;
import android.support.v7.app.AppCompatActivity;
@ -43,6 +45,7 @@ import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.Activities;
import org.solovyev.android.Check;
import org.solovyev.android.Views;
import org.solovyev.android.calculator.history.History;
import org.solovyev.android.calculator.language.Language;
@ -79,6 +82,9 @@ public class ActivityUi {
@Nullable
@Bind(R.id.toolbar)
Toolbar toolbar;
@Nullable
@Bind(R.id.fab)
FloatingActionButton fab;
@Nonnull
private Preferences.Gui.Theme theme = Preferences.Gui.Theme.material_theme;
@Nonnull
@ -337,4 +343,14 @@ public class ActivityUi {
public Tabs getTabs() {
return tabs;
}
public void withFab(@DrawableRes int icon, @Nonnull View.OnClickListener listener) {
if (fab == null) {
Check.shouldNotHappen();
return;
}
fab.setVisibility(View.VISIBLE);
fab.setImageResource(icon);
fab.setOnClickListener(listener);
}
}

View File

@ -8,6 +8,7 @@ import org.solovyev.android.calculator.functions.EditFunctionFragment;
import org.solovyev.android.calculator.functions.FunctionsFragment;
import org.solovyev.android.calculator.history.BaseHistoryFragment;
import org.solovyev.android.calculator.history.EditHistoryFragment;
import org.solovyev.android.calculator.history.HistoryActivity;
import org.solovyev.android.calculator.keyboard.BaseKeyboardUi;
import org.solovyev.android.calculator.floating.FloatingCalculatorView;
import org.solovyev.android.calculator.operators.OperatorsFragment;
@ -49,4 +50,5 @@ public interface AppComponent {
void inject(FloatingCalculatorView view);
void inject(DragButtonWizardStep fragment);
void inject(BaseFragment fragment);
void inject(HistoryActivity activity);
}

View File

@ -44,13 +44,17 @@ public class AdUi {
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();
}
}));
if (adFree != null) {
updateAdView();
} else {
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() {

View File

@ -35,7 +35,6 @@ import android.view.*;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import com.melnykov.fab.FloatingActionButton;
import org.solovyev.android.Check;
import org.solovyev.android.calculator.*;
import org.solovyev.android.views.llm.DividerItemDecoration;
@ -61,8 +60,6 @@ public abstract class BaseEntitiesFragment<E extends MathEntity> extends BaseFra
}
};
@Bind(R.id.entities_fab)
public FloatingActionButton fab;
@Bind(R.id.entities_recyclerview)
public RecyclerView recyclerView;
@Inject

View File

@ -47,7 +47,7 @@ public class FloatingCalculatorActivity extends AppCompatActivity {
final String permission = getString(R.string.cpp_permission_overlay);
builder.setMessage(getString(R.string.cpp_missing_permission_msg, permission));
builder.setTitle(R.string.cpp_missing_permission_title);
builder.setPositiveButton(R.string.ok, this);
builder.setPositiveButton(R.string.ok, null);
}
@Override

View File

@ -23,6 +23,7 @@
package org.solovyev.android.calculator.functions;
import android.os.Bundle;
import android.view.View;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.FragmentTab;
import org.solovyev.android.calculator.R;
@ -46,6 +47,13 @@ public class FunctionsActivity extends BaseActivity {
EditFunctionFragment.show(function, this);
}
}
ui.withFab(R.drawable.ic_add_white_36dp, new View.OnClickListener() {
@Override
public void onClick(View v) {
EditFunctionFragment.show(FunctionsActivity.this);
}
});
}
@Override

View File

@ -64,14 +64,6 @@ public class FunctionsFragment extends BaseEntitiesFragment<Function> {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = super.onCreateView(inflater, container, savedInstanceState);
bus.register(this);
fab.setVisibility(View.VISIBLE);
fab.attachToRecyclerView(recyclerView);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditFunctionFragment.show(getActivity());
}
});
return view;
}

View File

@ -24,11 +24,9 @@ package org.solovyev.android.calculator.history;
import android.app.Activity;
import android.content.Context;
import android.content.DialogInterface;
import android.os.Bundle;
import android.support.annotation.NonNull;
import android.support.v4.app.FragmentActivity;
import android.support.v7.app.AlertDialog;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.ClipboardManager;
@ -37,7 +35,6 @@ import android.view.*;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import com.melnykov.fab.FloatingActionButton;
import com.squareup.otto.Bus;
import com.squareup.otto.Subscribe;
import org.solovyev.android.Check;
@ -64,8 +61,6 @@ public abstract class BaseHistoryFragment extends BaseFragment {
Bus bus;
@Bind(R.id.history_recyclerview)
RecyclerView recyclerView;
@Bind(R.id.history_fab)
FloatingActionButton fab;
private HistoryAdapter adapter;
protected BaseHistoryFragment(boolean recentHistory) {
@ -107,35 +102,9 @@ public abstract class BaseHistoryFragment extends BaseFragment {
recyclerView.setLayoutManager(new LinearLayoutManager(context, LinearLayoutManager.VERTICAL, false));
recyclerView.setAdapter(adapter);
recyclerView.addItemDecoration(new DividerItemDecoration(context, null));
fab.attachToRecyclerView(recyclerView);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
showClearHistoryDialog();
}
});
return view;
}
private void showClearHistoryDialog() {
new AlertDialog.Builder(getActivity(), App.getTheme().alertDialogTheme)
.setTitle(R.string.cpp_clear_history_title)
.setMessage(R.string.cpp_clear_history_message)
.setPositiveButton(R.string.cpp_clear_history, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (recentHistory) {
history.clearRecent();
} else {
history.clearSaved();
}
}
})
.setNegativeButton(R.string.c_cancel, null)
.create()
.show();
}
@SuppressWarnings("deprecation")
protected final void copyResult(@Nonnull HistoryState state) {
final Context context = getActivity();

View File

@ -12,16 +12,14 @@ import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;
import butterknife.Bind;
import butterknife.ButterKnife;
import org.solovyev.android.calculator.AppComponent;
import org.solovyev.android.calculator.BaseDialogFragment;
import org.solovyev.android.calculator.R;
import javax.inject.Inject;
import butterknife.Bind;
import butterknife.ButterKnife;
public class EditHistoryFragment extends BaseDialogFragment {
public static final String ARG_STATE = "state";
@ -74,14 +72,22 @@ public class EditHistoryFragment extends BaseDialogFragment {
@Override
protected void onPrepareDialog(@NonNull AlertDialog.Builder builder) {
builder.setNegativeButton(R.string.c_cancel, null);
builder.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
builder.setPositiveButton(R.string.c_save, null);
}
@Override
public void onClick(DialogInterface dialog, int which) {
switch (which) {
case DialogInterface.BUTTON_POSITIVE:
final HistoryState.Builder b = HistoryState.builder(state, newState)
.withComment(commentView.getText().toString());
history.updateSaved(b.build());
}
});
dismiss();
break;
default:
super.onClick(dialog, which);
break;
}
}
@SuppressLint("InflateParams")

View File

@ -22,23 +22,67 @@
package org.solovyev.android.calculator.history;
import android.content.DialogInterface;
import android.os.Bundle;
import org.solovyev.android.calculator.BaseActivity;
import android.support.v4.app.Fragment;
import android.support.v7.app.AlertDialog;
import android.view.View;
import org.solovyev.android.calculator.*;
import org.solovyev.android.calculator.view.Tabs;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import javax.inject.Inject;
import static org.solovyev.android.calculator.FragmentTab.history;
import static org.solovyev.android.calculator.FragmentTab.saved_history;
public class HistoryActivity extends BaseActivity {
@Inject
History history;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
ui.withFab(R.drawable.ic_delete_white_36dp, new View.OnClickListener() {
@Override
public void onClick(View v) {
final Fragment fragment = ui.getTabs().getCurrentFragment();
showClearHistoryDialog(fragment instanceof RecentHistoryFragment);
}
});
}
@Override
protected void inject(@Nonnull AppComponent component) {
super.inject(component);
component.inject(this);
}
@Override
protected void populateTabs(@Nonnull Tabs tabs) {
super.populateTabs(tabs);
tabs.addTab(history);
tabs.addTab(FragmentTab.history);
tabs.addTab(saved_history);
}
private void showClearHistoryDialog(final boolean recentHistory) {
new AlertDialog.Builder(this, App.getTheme().alertDialogTheme)
.setTitle(R.string.cpp_clear_history_title)
.setMessage(R.string.cpp_clear_history_message)
.setPositiveButton(R.string.cpp_clear_history, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
if (recentHistory) {
history.clearRecent();
} else {
history.clearSaved();
}
}
})
.setNegativeButton(R.string.c_cancel, null)
.create()
.show();
}
}

View File

@ -23,8 +23,10 @@
package org.solovyev.android.calculator.variables;
import android.os.Bundle;
import android.view.View;
import org.solovyev.android.calculator.BaseActivity;
import org.solovyev.android.calculator.FragmentTab;
import org.solovyev.android.calculator.R;
import org.solovyev.android.calculator.view.Tabs;
import javax.annotation.Nonnull;
@ -45,6 +47,13 @@ public class VariablesActivity extends BaseActivity {
EditVariableFragment.showDialog(variable, this);
}
}
ui.withFab(R.drawable.ic_add_white_36dp, new View.OnClickListener() {
@Override
public void onClick(View v) {
EditVariableFragment.showDialog(VariablesActivity.this);
}
});
}
@Override

View File

@ -46,8 +46,6 @@ import javax.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import static org.solovyev.android.calculator.FragmentTab.variables;
public class VariablesFragment extends BaseEntitiesFragment<IConstant> {
@Inject
@ -76,14 +74,6 @@ public class VariablesFragment extends BaseEntitiesFragment<IConstant> {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = super.onCreateView(inflater, container, savedInstanceState);
bus.register(this);
fab.setVisibility(View.VISIBLE);
fab.attachToRecyclerView(recyclerView);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
EditVariableFragment.showDialog(null, getFragmentManager());
}
});
return view;
}

View File

@ -9,6 +9,7 @@ import android.support.v4.app.FragmentPagerAdapter;
import android.support.v4.view.ViewCompat;
import android.support.v4.view.ViewPager;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.view.ViewTreeObserver;
import butterknife.Bind;
import butterknife.ButterKnife;
@ -32,8 +33,8 @@ public class Tabs {
@Bind(R.id.tabs)
TabLayout tabLayout;
@Nullable
@Bind(R.id.viewpager)
ViewPager viewpager;
@Bind(R.id.viewPager)
ViewPager viewPager;
public Tabs(@Nonnull AppCompatActivity activity) {
this.activity = activity;
@ -43,14 +44,21 @@ public class Tabs {
public void onCreate() {
ButterKnife.bind(this, activity);
if (tabLayout == null || viewpager == null) {
if (tabLayout == null || viewPager == null) {
return;
}
viewpager.setAdapter(adapter);
tabLayout.setupWithViewPager(viewpager);
final int tabs = adapter.getCount();
if (tabs == 0) {
tabLayout.setVisibility(View.GONE);
return;
}
viewPager.setAdapter(adapter);
tabLayout.setTabMode(tabs > 3 ? TabLayout.MODE_SCROLLABLE : TabLayout.MODE_FIXED);
tabLayout.setupWithViewPager(viewPager);
if (ViewCompat.isLaidOut(tabLayout)) {
tabLayout.setupWithViewPager(viewpager);
tabLayout.setupWithViewPager(viewPager);
} else {
final ViewTreeObserver treeObserver = Adjuster.getTreeObserver(tabLayout);
if (treeObserver != null) {
@ -62,7 +70,7 @@ public class Tabs {
//noinspection deprecation
anotherTreeObserver.removeGlobalOnLayoutListener(this);
}
tabLayout.setupWithViewPager(viewpager);
tabLayout.setupWithViewPager(viewPager);
}
});
}
@ -87,6 +95,14 @@ public class Tabs {
adapter.add(new TabFragment(fragmentClass, fragmentArgs, title));
}
@Nullable
public Fragment getCurrentFragment() {
if (viewPager == null) {
return null;
}
return adapter.getItem(viewPager.getCurrentItem());
}
private final class TabFragments extends FragmentPagerAdapter {
@Nonnull

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="utf-8"?>
<!--
~ 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
-->
<android.support.design.widget.CoordinatorLayout
android:id="@+id/main"
style="@style/CppMain"
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<android.support.v7.widget.Toolbar
android:id="@+id/toolbar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_scrollFlags="snap">
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:overScrollMode="never"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed" />
</android.support.v7.widget.Toolbar>
</android.support.design.widget.AppBarLayout>
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/CppFab" />
</android.support.design.widget.CoordinatorLayout>

View File

@ -30,6 +30,12 @@
android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v4.view.ViewPager
android:id="@+id/viewPager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.AppBarLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
@ -43,13 +49,16 @@
<android.support.design.widget.TabLayout
android:id="@+id/tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
android:layout_height="wrap_content"
android:overScrollMode="never"
app:tabGravity="fill"
app:tabMaxWidth="0dp"
app:tabMode="fixed" />
</android.support.design.widget.AppBarLayout>
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior" />
<android.support.design.widget.FloatingActionButton
android:id="@+id/fab"
style="@style/CppFab"/>
</android.support.design.widget.CoordinatorLayout>

View File

@ -22,28 +22,16 @@
~ Site: http://se.solovyev.org
-->
<LinearLayout
xmlns:a="http://schemas.android.com/apk/res/android"
a:id="@+id/main_fragment_layout"
<LinearLayout a:id="@+id/main_fragment_layout"
style="@style/CppFragment"
xmlns:a="http://schemas.android.com/apk/res/android"
a:layout_width="match_parent"
a:layout_height="match_parent">
<org.solovyev.android.calculator.AdView style="@style/CppAd" />
<FrameLayout
<android.support.v7.widget.RecyclerView
a:id="@+id/entities_recyclerview"
a:layout_width="match_parent"
a:layout_height="match_parent">
<android.support.v7.widget.RecyclerView
a:id="@+id/entities_recyclerview"
a:layout_width="match_parent"
a:layout_height="match_parent" />
<com.melnykov.fab.FloatingActionButton
a:id="@+id/entities_fab"
style="@style/CppFab"
a:src="@drawable/ic_add_white_36dp"
a:visibility="gone" />
</FrameLayout>
a:layout_height="match_parent" />
</LinearLayout>

View File

@ -31,18 +31,9 @@
<org.solovyev.android.calculator.AdView style="@style/CppAd" />
<FrameLayout
<android.support.v7.widget.RecyclerView
a:id="@+id/history_recyclerview"
a:layout_width="match_parent"
a:layout_height="match_parent">
a:layout_height="match_parent" />
<android.support.v7.widget.RecyclerView
a:id="@+id/history_recyclerview"
a:layout_width="match_parent"
a:layout_height="match_parent" />
<com.melnykov.fab.FloatingActionButton
a:id="@+id/history_fab"
style="@style/CppFab"
a:src="@drawable/ic_delete_white_36dp" />
</FrameLayout>
</LinearLayout>

View File

@ -279,9 +279,8 @@
<item name="android:layout_height">wrap_content</item>
<item name="android:layout_gravity">bottom|end</item>
<item name="android:layout_margin">16dp</item>
<item name="fab_colorNormal">?attr/cpp_fab_bg</item>
<item name="fab_colorPressed">?attr/cpp_fab_bg</item>
<item name="fab_colorRipple">?attr/colorControlHighlight</item>
<item name="android:visibility">gone</item>
<item name="backgroundTint">?attr/cpp_fab_bg</item>
</style>
<style name="CppListItemText">
@ -326,16 +325,14 @@
<item name="android:padding">0dp</item>
</style>
<style name="CppActionBar" parent="@style/Widget.AppCompat.ActionBar">
<style name="CppToolbar" parent="@style/Widget.AppCompat.Toolbar">
<item name="background">@color/cpp_material_actionbar</item>
<item name="android:background">@color/cpp_material_actionbar</item>
<item name="backgroundStacked">@color/cpp_material_actionbar</item>
<item name="backgroundSplit">@color/cpp_material_actionbar</item>
</style>
<style name="CppActionBar.Light" parent="CppActionBar">
<style name="CppToolbar.Light" parent="CppToolbar">
<item name="background">@color/cpp_material_actionbar_light</item>
<item name="android:background">@color/cpp_material_actionbar_light</item>
<item name="backgroundStacked">@color/cpp_material_actionbar_light</item>
<item name="backgroundSplit">@color/cpp_material_actionbar_light</item>
</style>