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.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
|
||||
import com.squareup.leakcanary.LeakCanary;
|
||||
import com.squareup.otto.Bus;
|
||||
|
||||
import org.acra.ACRA;
|
||||
import org.acra.ACRAConfiguration;
|
||||
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.common.msg.MessageType;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Named;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
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 {
|
||||
|
||||
@Inject
|
||||
@ -107,7 +104,6 @@ public class CalculatorApplication extends android.app.Application implements Sh
|
||||
.build();
|
||||
component.inject(this);
|
||||
history.init(initThread);
|
||||
display.init();
|
||||
|
||||
onPostCreate(preferences, languages);
|
||||
}
|
||||
|
@ -30,37 +30,22 @@ import android.os.Bundle;
|
||||
import android.support.v4.app.FragmentActivity;
|
||||
import android.support.v4.app.ListFragment;
|
||||
import android.text.ClipboardManager;
|
||||
import android.view.ContextMenu;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.*;
|
||||
import android.widget.AdapterView;
|
||||
import android.widget.ArrayAdapter;
|
||||
import android.widget.ListView;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.melnykov.fab.FloatingActionButton;
|
||||
import com.squareup.otto.Bus;
|
||||
import com.squareup.otto.Subscribe;
|
||||
|
||||
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.*;
|
||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||
import org.solovyev.common.text.Strings;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
import javax.inject.Inject;
|
||||
|
||||
import static android.view.Menu.NONE;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public abstract class BaseHistoryFragment extends ListFragment {
|
||||
|
||||
@ -167,73 +152,52 @@ public abstract class BaseHistoryFragment extends ListFragment {
|
||||
}
|
||||
|
||||
@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);
|
||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) menuInfo;
|
||||
final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position);
|
||||
|
||||
if (!isRecentHistory()) {
|
||||
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);
|
||||
}
|
||||
onCreateContextMenu(menu, state);
|
||||
}
|
||||
|
||||
protected abstract void onCreateContextMenu(@Nonnull ContextMenu menu, @Nonnull HistoryState state);
|
||||
|
||||
@Override
|
||||
public boolean onContextItemSelected(MenuItem item) {
|
||||
final Context context = getActivity();
|
||||
public final boolean onContextItemSelected(MenuItem item) {
|
||||
final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo();
|
||||
final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position);
|
||||
|
||||
switch (item.getItemId()) {
|
||||
case R.string.c_use:
|
||||
useState(state);
|
||||
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;
|
||||
|
||||
if (onContextItemSelected(item, state)) {
|
||||
return true;
|
||||
}
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -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";
|
||||
@ -76,7 +74,6 @@ public class EditHistoryFragment extends BaseDialogFragment {
|
||||
|
||||
@Override
|
||||
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.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() {
|
||||
@Override
|
||||
|
@ -22,12 +22,16 @@
|
||||
|
||||
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.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import static android.view.Menu.NONE;
|
||||
|
||||
public class RecentHistoryFragment extends BaseHistoryFragment {
|
||||
|
||||
public RecentHistoryFragment() {
|
||||
@ -55,4 +59,31 @@ public class RecentHistoryFragment extends BaseHistoryFragment {
|
||||
protected boolean isRecentHistory() {
|
||||
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;
|
||||
|
||||
import android.view.ContextMenu;
|
||||
import android.view.MenuItem;
|
||||
import org.solovyev.android.calculator.CalculatorFragmentType;
|
||||
import org.solovyev.android.calculator.R;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
import java.util.List;
|
||||
|
||||
import static android.view.Menu.NONE;
|
||||
|
||||
public class SavedHistoryFragment extends BaseHistoryFragment {
|
||||
|
||||
public SavedHistoryFragment() {
|
||||
@ -55,4 +59,36 @@ public class SavedHistoryFragment extends BaseHistoryFragment {
|
||||
protected boolean isRecentHistory() {
|
||||
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
|
||||
a:id="@+id/history_expression"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:editable="false"
|
||||
a:hint="@string/c_history_expression"
|
||||
a:inputType="none"
|
||||
a:padding="6dp"
|
||||
a:textStyle="bold"
|
||||
tools:ignore="Deprecated" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
@ -51,12 +49,10 @@
|
||||
|
||||
<EditText
|
||||
a:id="@+id/history_comment"
|
||||
a:layout_width="fill_parent"
|
||||
a:layout_width="match_parent"
|
||||
a:layout_height="wrap_content"
|
||||
a:hint="@string/c_history_comment"
|
||||
a:inputType="text"
|
||||
a:maxLines="4"
|
||||
a:minLines="4" />
|
||||
a:inputType="text" />
|
||||
</android.support.design.widget.TextInputLayout>
|
||||
|
||||
</LinearLayout>
|
||||
|
Loading…
Reference in New Issue
Block a user