History changes
This commit is contained in:
parent
e5d0a8d822
commit
77ae5dad9d
@ -26,10 +26,8 @@ import android.content.SharedPreferences;
|
|||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.preference.PreferenceManager;
|
import android.preference.PreferenceManager;
|
||||||
import android.util.Log;
|
import android.util.Log;
|
||||||
|
|
||||||
import com.squareup.leakcanary.LeakCanary;
|
import com.squareup.leakcanary.LeakCanary;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
|
|
||||||
import org.acra.ACRA;
|
import org.acra.ACRA;
|
||||||
import org.acra.ACRAConfiguration;
|
import org.acra.ACRAConfiguration;
|
||||||
import org.acra.sender.HttpSender;
|
import org.acra.sender.HttpSender;
|
||||||
@ -43,15 +41,14 @@ import org.solovyev.android.calculator.plot.AndroidCalculatorPlotter;
|
|||||||
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
|
import org.solovyev.android.calculator.plot.CalculatorPlotterImpl;
|
||||||
import org.solovyev.common.msg.MessageType;
|
import org.solovyev.common.msg.MessageType;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
|
import javax.inject.Inject;
|
||||||
|
import javax.inject.Named;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.concurrent.Executor;
|
import java.util.concurrent.Executor;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
|
||||||
import javax.inject.Inject;
|
|
||||||
import javax.inject.Named;
|
|
||||||
|
|
||||||
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class CalculatorApplication extends android.app.Application implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
@ -107,7 +104,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
|||||||
.build();
|
.build();
|
||||||
component.inject(this);
|
component.inject(this);
|
||||||
history.init(initThread);
|
history.init(initThread);
|
||||||
display.init();
|
|
||||||
|
|
||||||
onPostCreate(preferences, languages);
|
onPostCreate(preferences, languages);
|
||||||
}
|
}
|
||||||
|
@ -30,37 +30,22 @@ import android.os.Bundle;
|
|||||||
import android.support.v4.app.FragmentActivity;
|
import android.support.v4.app.FragmentActivity;
|
||||||
import android.support.v4.app.ListFragment;
|
import android.support.v4.app.ListFragment;
|
||||||
import android.text.ClipboardManager;
|
import android.text.ClipboardManager;
|
||||||
import android.view.ContextMenu;
|
import android.view.*;
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.MenuItem;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.AdapterView;
|
import android.widget.AdapterView;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.Toast;
|
|
||||||
|
|
||||||
import com.melnykov.fab.FloatingActionButton;
|
import com.melnykov.fab.FloatingActionButton;
|
||||||
import com.squareup.otto.Bus;
|
import com.squareup.otto.Bus;
|
||||||
import com.squareup.otto.Subscribe;
|
import com.squareup.otto.Subscribe;
|
||||||
|
import org.solovyev.android.calculator.*;
|
||||||
import org.solovyev.android.calculator.App;
|
|
||||||
import org.solovyev.android.calculator.CalculatorActivity;
|
|
||||||
import org.solovyev.android.calculator.CalculatorApplication;
|
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
|
||||||
import org.solovyev.android.calculator.FragmentUi;
|
|
||||||
import org.solovyev.android.calculator.R;
|
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.common.text.Strings;
|
import org.solovyev.common.text.Strings;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import javax.annotation.Nullable;
|
import javax.annotation.Nullable;
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
import java.util.ArrayList;
|
||||||
import static android.view.Menu.NONE;
|
import java.util.List;
|
||||||
|
|
||||||
public abstract class BaseHistoryFragment extends ListFragment {
|
public abstract class BaseHistoryFragment extends ListFragment {
|
||||||
|
|
||||||
@ -167,73 +152,52 @@ public abstract class BaseHistoryFragment extends ListFragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
public final void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) {
|
||||||
super.onCreateContextMenu(menu, v, menuInfo);
|
super.onCreateContextMenu(menu, v, menuInfo);
|
||||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||||
final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position);
|
final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position);
|
||||||
|
|
||||||
if (!isRecentHistory()) {
|
onCreateContextMenu(menu, state);
|
||||||
menu.add(NONE, R.string.c_use, NONE, R.string.c_use);
|
|
||||||
menu.add(NONE, R.string.c_copy_expression, NONE, R.string.c_copy_expression);
|
|
||||||
if (shouldHaveCopyResult(state)) {
|
|
||||||
menu.add(NONE, R.string.c_copy_result, NONE, R.string.c_copy_result);
|
|
||||||
}
|
|
||||||
menu.add(NONE, R.string.c_edit, NONE, R.string.c_edit);
|
|
||||||
menu.add(NONE, R.string.c_remove, NONE, R.string.c_remove);
|
|
||||||
} else {
|
|
||||||
menu.add(NONE, R.string.c_use, NONE, R.string.c_use);
|
|
||||||
menu.add(NONE, R.string.c_copy_expression, NONE, R.string.c_copy_expression);
|
|
||||||
if (shouldHaveCopyResult(state)) {
|
|
||||||
menu.add(NONE, R.string.c_copy_result, NONE, R.string.c_copy_result);
|
|
||||||
}
|
|
||||||
menu.add(NONE, R.string.c_save, NONE, R.string.c_save);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected abstract void onCreateContextMenu(@Nonnull ContextMenu menu, @Nonnull HistoryState state);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onContextItemSelected(MenuItem item) {
|
public final boolean onContextItemSelected(MenuItem item) {
|
||||||
final Context context = getActivity();
|
|
||||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
||||||
final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position);
|
final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position);
|
||||||
|
|
||||||
switch (item.getItemId()) {
|
if (onContextItemSelected(item, state)) {
|
||||||
case R.string.c_use:
|
|
||||||
useState(state);
|
|
||||||
return true;
|
return true;
|
||||||
case R.string.c_copy_expression:
|
|
||||||
final String editorText = state.editor.getTextString();
|
|
||||||
if (!Strings.isEmpty(editorText)) {
|
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
|
||||||
clipboard.setText(editorText);
|
|
||||||
Toast.makeText(context, context.getText(R.string.c_expression_copied), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case R.string.c_copy_result:
|
|
||||||
final String displayText = state.display.text;
|
|
||||||
if (!Strings.isEmpty(displayText)) {
|
|
||||||
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
|
||||||
clipboard.setText(displayText);
|
|
||||||
Toast.makeText(context, context.getText(R.string.c_result_copied), Toast.LENGTH_SHORT).show();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
case R.string.c_save:
|
|
||||||
EditHistoryFragment.show(state, true, getFragmentManager());
|
|
||||||
return true;
|
|
||||||
case R.string.c_edit:
|
|
||||||
EditHistoryFragment.show(state, false, getFragmentManager());
|
|
||||||
return true;
|
|
||||||
case R.string.c_remove:
|
|
||||||
getAdapter().remove(state);
|
|
||||||
history.removeSaved(state);
|
|
||||||
Toast.makeText(context, context.getText(R.string.c_history_was_removed), Toast.LENGTH_LONG).show();
|
|
||||||
getAdapter().notifyDataSetChanged();
|
|
||||||
return true;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return super.onContextItemSelected(item);
|
return super.onContextItemSelected(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean shouldHaveCopyResult(@Nonnull HistoryState state) {
|
protected abstract boolean onContextItemSelected(@Nonnull MenuItem item, @Nonnull HistoryState state);
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
protected final void copyResult(@Nonnull HistoryState state) {
|
||||||
|
final Context context = getActivity();
|
||||||
|
final String displayText = state.display.text;
|
||||||
|
if (Strings.isEmpty(displayText)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
|
clipboard.setText(displayText);
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
protected final void copyExpression(@Nonnull HistoryState state) {
|
||||||
|
final Context context = getActivity();
|
||||||
|
final String editorText = state.editor.getTextString();
|
||||||
|
if (Strings.isEmpty(editorText)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final ClipboardManager clipboard = (ClipboardManager) context.getSystemService(Activity.CLIPBOARD_SERVICE);
|
||||||
|
clipboard.setText(editorText);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected final boolean shouldHaveCopyResult(@Nonnull HistoryState state) {
|
||||||
return !state.display.valid || !Strings.isEmpty(state.display.text);
|
return !state.display.valid || !Strings.isEmpty(state.display.text);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,16 +12,14 @@ import android.view.LayoutInflater;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
import butterknife.Bind;
|
||||||
|
import butterknife.ButterKnife;
|
||||||
import org.solovyev.android.calculator.AppComponent;
|
import org.solovyev.android.calculator.AppComponent;
|
||||||
import org.solovyev.android.calculator.BaseDialogFragment;
|
import org.solovyev.android.calculator.BaseDialogFragment;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import javax.inject.Inject;
|
import javax.inject.Inject;
|
||||||
|
|
||||||
import butterknife.Bind;
|
|
||||||
import butterknife.ButterKnife;
|
|
||||||
|
|
||||||
public class EditHistoryFragment extends BaseDialogFragment {
|
public class EditHistoryFragment extends BaseDialogFragment {
|
||||||
|
|
||||||
public static final String ARG_STATE = "state";
|
public static final String ARG_STATE = "state";
|
||||||
@ -76,7 +74,6 @@ public class EditHistoryFragment extends BaseDialogFragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPrepareDialog(@NonNull AlertDialog.Builder builder) {
|
protected void onPrepareDialog(@NonNull AlertDialog.Builder builder) {
|
||||||
builder.setTitle(newState ? R.string.c_save_history : R.string.c_edit_history);
|
|
||||||
builder.setNegativeButton(R.string.c_cancel, null);
|
builder.setNegativeButton(R.string.c_cancel, null);
|
||||||
builder.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() {
|
builder.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() {
|
||||||
@Override
|
@Override
|
||||||
|
@ -22,12 +22,16 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.view.Menu.NONE;
|
||||||
|
|
||||||
public class RecentHistoryFragment extends BaseHistoryFragment {
|
public class RecentHistoryFragment extends BaseHistoryFragment {
|
||||||
|
|
||||||
public RecentHistoryFragment() {
|
public RecentHistoryFragment() {
|
||||||
@ -55,4 +59,31 @@ public class RecentHistoryFragment extends BaseHistoryFragment {
|
|||||||
protected boolean isRecentHistory() {
|
protected boolean isRecentHistory() {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onCreateContextMenu(@Nonnull ContextMenu menu, @Nonnull HistoryState state) {
|
||||||
|
menu.add(NONE, R.string.c_use, NONE, R.string.c_use);
|
||||||
|
menu.add(NONE, R.string.c_copy_expression, NONE, R.string.c_copy_expression);
|
||||||
|
if (shouldHaveCopyResult(state)) {
|
||||||
|
menu.add(NONE, R.string.c_copy_result, NONE, R.string.c_copy_result);
|
||||||
|
}
|
||||||
|
menu.add(NONE, R.string.c_save, NONE, R.string.c_save);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onContextItemSelected(@Nonnull MenuItem item, @Nonnull HistoryState state) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.string.c_use:
|
||||||
|
useState(state);
|
||||||
|
return true;
|
||||||
|
case R.string.c_copy_expression:
|
||||||
|
copyExpression(state);
|
||||||
|
return true;
|
||||||
|
case R.string.c_copy_result:
|
||||||
|
copyResult(state);
|
||||||
|
return true;
|
||||||
|
case R.string.c_save:
|
||||||
|
EditHistoryFragment.show(state, true, getFragmentManager());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -22,12 +22,16 @@
|
|||||||
|
|
||||||
package org.solovyev.android.calculator.history;
|
package org.solovyev.android.calculator.history;
|
||||||
|
|
||||||
|
import android.view.ContextMenu;
|
||||||
|
import android.view.MenuItem;
|
||||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||||
import org.solovyev.android.calculator.R;
|
import org.solovyev.android.calculator.R;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import static android.view.Menu.NONE;
|
||||||
|
|
||||||
public class SavedHistoryFragment extends BaseHistoryFragment {
|
public class SavedHistoryFragment extends BaseHistoryFragment {
|
||||||
|
|
||||||
public SavedHistoryFragment() {
|
public SavedHistoryFragment() {
|
||||||
@ -55,4 +59,36 @@ public class SavedHistoryFragment extends BaseHistoryFragment {
|
|||||||
protected boolean isRecentHistory() {
|
protected boolean isRecentHistory() {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void onCreateContextMenu(@Nonnull ContextMenu menu, @Nonnull HistoryState state) {
|
||||||
|
menu.add(NONE, R.string.c_use, NONE, R.string.c_use);
|
||||||
|
menu.add(NONE, R.string.c_copy_expression, NONE, R.string.c_copy_expression);
|
||||||
|
if (shouldHaveCopyResult(state)) {
|
||||||
|
menu.add(NONE, R.string.c_copy_result, NONE, R.string.c_copy_result);
|
||||||
|
}
|
||||||
|
menu.add(NONE, R.string.c_edit, NONE, R.string.c_edit);
|
||||||
|
menu.add(NONE, R.string.c_remove, NONE, R.string.c_remove);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean onContextItemSelected(@Nonnull MenuItem item, @Nonnull HistoryState state) {
|
||||||
|
switch (item.getItemId()) {
|
||||||
|
case R.string.c_use:
|
||||||
|
useState(state);
|
||||||
|
return true;
|
||||||
|
case R.string.c_copy_expression:
|
||||||
|
copyExpression(state);
|
||||||
|
return true;
|
||||||
|
case R.string.c_copy_result:
|
||||||
|
copyResult(state);
|
||||||
|
return true;
|
||||||
|
case R.string.c_edit:
|
||||||
|
EditHistoryFragment.show(state, false, getFragmentManager());
|
||||||
|
return true;
|
||||||
|
case R.string.c_remove:
|
||||||
|
history.removeSaved(state);
|
||||||
|
return true;
|
||||||
|
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -34,13 +34,11 @@
|
|||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
a:id="@+id/history_expression"
|
a:id="@+id/history_expression"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:editable="false"
|
a:editable="false"
|
||||||
a:hint="@string/c_history_expression"
|
a:hint="@string/c_history_expression"
|
||||||
a:inputType="none"
|
a:inputType="none"
|
||||||
a:padding="6dp"
|
|
||||||
a:textStyle="bold"
|
|
||||||
tools:ignore="Deprecated" />
|
tools:ignore="Deprecated" />
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
@ -51,12 +49,10 @@
|
|||||||
|
|
||||||
<EditText
|
<EditText
|
||||||
a:id="@+id/history_comment"
|
a:id="@+id/history_comment"
|
||||||
a:layout_width="fill_parent"
|
a:layout_width="match_parent"
|
||||||
a:layout_height="wrap_content"
|
a:layout_height="wrap_content"
|
||||||
a:hint="@string/c_history_comment"
|
a:hint="@string/c_history_comment"
|
||||||
a:inputType="text"
|
a:inputType="text" />
|
||||||
a:maxLines="4"
|
|
||||||
a:minLines="4" />
|
|
||||||
</android.support.design.widget.TextInputLayout>
|
</android.support.design.widget.TextInputLayout>
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
Loading…
Reference in New Issue
Block a user