diff --git a/app/build.gradle b/app/build.gradle index b0394592..03487e05 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -101,6 +101,7 @@ dependencies { compile 'commons-cli:commons-cli:1.2' compile 'com.squareup:otto:1.3.8' compile 'com.jakewharton:butterknife:7.0.1' + compile 'org.solovyev.android.views:linear-layout-manager:0.5@aar' compile 'com.google.dagger:dagger:2.0.2' apt "com.google.dagger:dagger-compiler:2.0.2" diff --git a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java index 84176cab..6f5a8eeb 100644 --- a/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java +++ b/app/src/main/java/org/solovyev/android/calculator/CalculatorFragmentType.java @@ -50,8 +50,8 @@ public enum CalculatorFragmentType { editor(CalculatorEditorFragment.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.c_history), - saved_history(SavedHistoryFragment.class, R.layout.fragment_history, R.string.c_saved_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(CalculatorVarsFragment.class, R.layout.vars_fragment, R.string.c_vars), functions(CalculatorFunctionsFragment.class, R.layout.math_entities_fragment, R.string.c_functions), operators(CalculatorOperatorsFragment.class, R.layout.math_entities_fragment, R.string.c_operators), 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 f8e91512..8088d699 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 @@ -26,36 +26,53 @@ import android.app.Activity; import android.content.Context; import android.content.DialogInterface; import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.annotation.StringRes; +import android.support.v4.app.Fragment; import android.support.v4.app.FragmentActivity; -import android.support.v4.app.ListFragment; import android.support.v7.app.AlertDialog; +import android.support.v7.widget.LinearLayoutManager; +import android.support.v7.widget.RecyclerView; import android.text.ClipboardManager; +import android.text.format.DateUtils; import android.view.*; -import android.widget.AdapterView; -import android.widget.ArrayAdapter; -import android.widget.ListView; +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; import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.jscl.JsclOperation; +import org.solovyev.android.views.llm.DividerItemDecoration; import org.solovyev.common.text.Strings; import javax.annotation.Nonnull; +import javax.annotation.Nullable; import javax.inject.Inject; -import java.util.ArrayList; import java.util.List; -public abstract class BaseHistoryFragment extends ListFragment { +import static android.view.Menu.NONE; +import static android.view.View.GONE; +import static android.view.View.VISIBLE; + +public abstract class BaseHistoryFragment extends Fragment { + private final boolean recentHistory; @Inject History history; @Inject Bus bus; - private HistoryArrayAdapter adapter; + @Bind(R.id.history_recyclerview) + RecyclerView recyclerView; + @Bind(R.id.history_fab) + FloatingActionButton fab; @Nonnull private FragmentUi ui; + private HistoryAdapter adapter; protected BaseHistoryFragment(@Nonnull CalculatorFragmentType type) { + recentHistory = type == CalculatorFragmentType.history; ui = new FragmentUi(type.getDefaultLayoutId(), type.getDefaultTitleResId(), false); } @@ -81,46 +98,33 @@ public abstract class BaseHistoryFragment extends ListFragment { public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); ((CalculatorApplication) getActivity().getApplication()).getComponent().inject(this); - bus.register(this); ui.onCreate(this); } @Override public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { - return ui.onCreateView(this, inflater, container); - } - - @Override - public void onViewCreated(View root, Bundle savedInstanceState) { - super.onViewCreated(root, savedInstanceState); - - ui.onViewCreated(this, root); - - adapter = new HistoryArrayAdapter(this.getActivity(), getItemLayoutId(), R.id.history_item, new ArrayList()); - setListAdapter(adapter); - - final ListView lv = getListView(); - lv.setTextFilterEnabled(true); - - final FloatingActionButton fab = (FloatingActionButton) root.findViewById(R.id.fab); - fab.attachToListView(lv); + final View view = ui.onCreateView(this, inflater, container); + ButterKnife.bind(this, view); + final Context context = inflater.getContext(); + adapter = new HistoryAdapter(context); + bus.register(adapter); + 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; + } - lv.setOnItemClickListener(new AdapterView.OnItemClickListener() { - public void onItemClick(final AdapterView parent, - final View view, - final int position, - final long id) { - useState((HistoryState) parent.getItemAtPosition(position)); - } - }); - - registerForContextMenu(lv); + @Override + public void onViewCreated(View root, Bundle savedInstanceState) { + super.onViewCreated(root, savedInstanceState); + ui.onViewCreated(this, root); } private void showClearHistoryDialog() { @@ -130,7 +134,11 @@ public abstract class BaseHistoryFragment extends ListFragment { .setPositiveButton(R.string.cpp_clear_history, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - clearHistory(); + if (recentHistory) { + history.clearRecent(); + } else { + history.clearSaved(); + } } }) .setNegativeButton(R.string.c_cancel, null) @@ -142,33 +150,8 @@ public abstract class BaseHistoryFragment extends ListFragment { public void onResume() { super.onResume(); ui.onResume(this); - updateAdapter(); } - @Override - 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); - - onCreateContextMenu(menu, state); - } - - protected abstract void onCreateContextMenu(@Nonnull ContextMenu menu, @Nonnull HistoryState state); - - @Override - public final boolean onContextItemSelected(MenuItem item) { - final AdapterView.AdapterContextMenuInfo info = (AdapterView.AdapterContextMenuInfo) item.getMenuInfo(); - final HistoryState state = (HistoryState) getListView().getItemAtPosition(info.position); - - if (onContextItemSelected(item, state)) { - return true; - } - return super.onContextItemSelected(item); - } - - protected abstract boolean onContextItemSelected(@Nonnull MenuItem item, @Nonnull HistoryState state); - @SuppressWarnings("deprecation") protected final void copyResult(@Nonnull HistoryState state) { final Context context = getActivity(); @@ -203,53 +186,188 @@ public abstract class BaseHistoryFragment extends ListFragment { @Override public void onDestroyView() { + bus.unregister(adapter); ui.onDestroyView(this); super.onDestroyView(); } @Override public void onDestroy() { - bus.unregister(this); ui.onDestroy(this); super.onDestroy(); } - protected abstract int getItemLayoutId(); + public class HistoryViewHolder extends RecyclerView.ViewHolder implements View.OnCreateContextMenuListener, View.OnClickListener, MenuItem.OnMenuItemClickListener { - private void updateAdapter() { - final List historyList = getHistoryItems(); + private static final int DATETIME_FORMAT = DateUtils.FORMAT_SHOW_TIME | DateUtils.FORMAT_SHOW_DATE | DateUtils.FORMAT_ABBREV_MONTH | DateUtils.FORMAT_ABBREV_TIME; + @Bind(R.id.history_item_value) + TextView valueView; + @Bind(R.id.history_item_comment) + TextView commentView; + @Bind(R.id.history_item_time) + TextView timeView; + @Nullable + private HistoryState state; - final ArrayAdapter adapter = getAdapter(); - try { - adapter.setNotifyOnChange(false); - adapter.clear(); - for (HistoryState historyState : historyList) { - adapter.add(historyState); + public HistoryViewHolder(View view) { + super(view); + ButterKnife.bind(this, view); + view.setOnCreateContextMenuListener(this); + view.setOnClickListener(this); + } + + void bind(@Nonnull HistoryState state) { + this.state = state; + valueView.setText(BaseHistoryFragment.getHistoryText(state)); + timeView.setText(DateUtils.formatDateTime(getContext(), state.getTime(), DATETIME_FORMAT)); + final String comment = state.getComment(); + if (!Strings.isEmpty(comment)) { + commentView.setText(comment); + commentView.setVisibility(VISIBLE); + } else { + commentView.setText(null); + commentView.setVisibility(GONE); } - } finally { - adapter.setNotifyOnChange(true); } - adapter.notifyDataSetChanged(); - } - - @Nonnull - protected abstract List getHistoryItems(); - - protected abstract void clearHistory(); - - @Nonnull - protected HistoryArrayAdapter getAdapter() { - return adapter; - } - - @Subscribe - void onHistoryChanged(@Nonnull History.ChangedEvent e) { - if (e.recent != isRecentHistory()) { - return; + @Override + public void onCreateContextMenu(ContextMenu menu, View v, ContextMenu.ContextMenuInfo menuInfo) { + Check.isNotNull(state); + if (recentHistory) { + addMenu(menu, R.string.c_use); + addMenu(menu, R.string.c_copy_expression); + if (shouldHaveCopyResult(state)) { + addMenu(menu, R.string.c_copy_result); + } + addMenu(menu, R.string.c_save); + } else { + addMenu(menu, R.string.c_use); + addMenu(menu, R.string.c_copy_expression); + if (shouldHaveCopyResult(state)) { + addMenu(menu, R.string.c_copy_result); + } + addMenu(menu, R.string.c_edit); + addMenu(menu, R.string.c_remove); + } + } + + @Nonnull + private MenuItem addMenu(@Nonnull ContextMenu menu, @StringRes int label) { + return menu.add(NONE, label, NONE, label).setOnMenuItemClickListener(this); + } + + @Override + public void onClick(View v) { + Check.isNotNull(state); + useState(state); + } + + @Override + public boolean onMenuItemClick(MenuItem item) { + Check.isNotNull(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_save: + EditHistoryFragment.show(state, true, getFragmentManager()); + return true; + case R.string.c_remove: + history.removeSaved(state); + return true; + } + return false; } - updateAdapter(); } - protected abstract boolean isRecentHistory(); + public class HistoryAdapter extends RecyclerView.Adapter { + + @NonNull + private final LayoutInflater inflater; + + @NonNull + private final List list; + + public HistoryAdapter(@NonNull Context context) { + inflater = LayoutInflater.from(context); + list = loadHistory(); + setHasStableIds(true); + } + + @NonNull + private List loadHistory() { + return recentHistory ? history.getRecent() : history.getSaved(); + } + + @Override + public HistoryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { + return new HistoryViewHolder(inflater.inflate(R.layout.fragment_history_item, parent, false)); + } + + @Override + public void onBindViewHolder(HistoryViewHolder holder, int position) { + holder.bind(list.get(position)); + } + + @Override + public long getItemId(int position) { + return list.get(position).hashCode(); + } + + @Override + public int getItemCount() { + return list.size(); + } + + @Subscribe + public void onHistoryCleared(@Nonnull History.ClearedEvent e) { + if (e.recent != recentHistory) { + return; + } + list.clear(); + notifyDataSetChanged(); + } + + @Subscribe + public void onHistoryAdded(@Nonnull History.AddedEvent e) { + if (e.recent != recentHistory) { + return; + } + list.add(e.state); + notifyItemInserted(0); + } + + @Subscribe + public void onHistoryUpdated(@Nonnull History.UpdatedEvent e) { + if (e.recent != recentHistory) { + return; + } + final int i = list.indexOf(e.state); + if (i >= 0) { + list.set(i, e.state); + notifyItemChanged(i); + } + } + + @Subscribe + public void onHistoryRemoved(@Nonnull History.RemovedEvent e) { + if (e.recent != recentHistory) { + return; + } + final int i = list.indexOf(e.state); + if (i >= 0) { + list.remove(i); + notifyItemRemoved(i); + } + } + } } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/EditHistoryFragment.java b/app/src/main/java/org/solovyev/android/calculator/history/EditHistoryFragment.java index 39fd2f7d..b07f4f75 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/EditHistoryFragment.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/EditHistoryFragment.java @@ -78,11 +78,8 @@ public class EditHistoryFragment extends BaseDialogFragment { builder.setPositiveButton(R.string.c_save, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { - final HistoryState.Builder b = HistoryState.builder(state) + final HistoryState.Builder b = HistoryState.builder(state, newState) .withComment(commentView.getText().toString()); - if (newState) { - b.withNowTime(); - } history.updateSaved(b.build()); } }); diff --git a/app/src/main/java/org/solovyev/android/calculator/history/History.java b/app/src/main/java/org/solovyev/android/calculator/history/History.java index 500bc194..fc6b8a1a 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/History.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/History.java @@ -27,25 +27,22 @@ import android.content.SharedPreferences; import android.os.Handler; import android.support.annotation.NonNull; import android.text.TextUtils; - import com.google.common.base.Strings; import com.squareup.otto.Bus; import com.squareup.otto.Subscribe; - import org.json.JSONArray; import org.json.JSONException; import org.solovyev.android.Check; -import org.solovyev.android.calculator.App; -import org.solovyev.android.calculator.AppModule; -import org.solovyev.android.calculator.Display; -import org.solovyev.android.calculator.DisplayState; -import org.solovyev.android.calculator.Editor; -import org.solovyev.android.calculator.EditorState; -import org.solovyev.android.calculator.ErrorReporter; +import org.solovyev.android.calculator.*; import org.solovyev.android.calculator.model.AndroidCalculatorEngine.Preferences; import org.solovyev.android.io.FileLoader; import org.solovyev.android.io.FileSaver; +import javax.annotation.Nonnull; +import javax.annotation.Nullable; +import javax.inject.Inject; +import javax.inject.Named; +import javax.inject.Singleton; import java.io.File; import java.io.IOException; import java.util.ArrayList; @@ -54,12 +51,6 @@ import java.util.LinkedList; import java.util.List; import java.util.concurrent.Executor; -import javax.annotation.Nonnull; -import javax.annotation.Nullable; -import javax.inject.Inject; -import javax.inject.Named; -import javax.inject.Singleton; - import static android.text.TextUtils.isEmpty; @Singleton @@ -67,8 +58,8 @@ public class History { public static final String TAG = App.subTag("History"); public static final String OLD_HISTORY_PREFS_KEY = "org.solovyev.android.calculator.CalculatorModel_history"; - private static final ChangedEvent CHANGED_EVENT_RECENT = new ChangedEvent(true); - private static final ChangedEvent CHANGED_EVENT_SAVED = new ChangedEvent(false); + private static final ClearedEvent CLEARED_EVENT_RECENT = new ClearedEvent(true); + private static final ClearedEvent CLEARED_EVENT_SAVED = new ClearedEvent(false); private static final int MAX_INTERMEDIATE_STREAK = 5; @NonNull private final Runnable writeRecent = new WriteTask(true); @@ -246,7 +237,7 @@ public class History { public void addRecent(@Nonnull HistoryState state) { Check.isMainThread(); recent.add(state); - onRecentChanged(); + onRecentChanged(new AddedEvent(state, true)); } public void updateSaved(@Nonnull HistoryState state) { @@ -254,22 +245,23 @@ public class History { final int i = saved.indexOf(state); if(i >= 0) { saved.set(i, state); + onSavedChanged(new UpdatedEvent(state, false)); } else { saved.add(state); + onSavedChanged(new AddedEvent(state, false)); } - onSavedChanged(); } - private void onRecentChanged() { + private void onRecentChanged(@Nonnull Object event) { handler.removeCallbacks(writeRecent); handler.postDelayed(writeRecent, 500); - bus.post(CHANGED_EVENT_RECENT); + bus.post(event); } - private void onSavedChanged() { + private void onSavedChanged(@Nonnull Object event) { handler.removeCallbacks(writeSaved); handler.postDelayed(writeSaved, 500); - bus.post(CHANGED_EVENT_SAVED); + bus.post(event); } @Nonnull @@ -314,13 +306,13 @@ public class History { public void clearRecent() { Check.isMainThread(); recent.clear(); - onRecentChanged(); + onRecentChanged(CLEARED_EVENT_RECENT); } public void clearSaved() { Check.isMainThread(); saved.clear(); - onSavedChanged(); + onSavedChanged(CLEARED_EVENT_SAVED); } public void undo() { @@ -347,13 +339,13 @@ public class History { public void removeSaved(@Nonnull HistoryState state) { Check.isMainThread(); saved.remove(state); - onSavedChanged(); + onSavedChanged(new RemovedEvent(state, false)); } public void removeRecent(@Nonnull HistoryState state) { Check.isMainThread(); recent.remove(state); - onRecentChanged(); + onSavedChanged(new RemovedEvent(state, true)); } @Subscribe @@ -366,10 +358,39 @@ public class History { addRecent(HistoryState.builder(editorState, displayState).build()); } - public static class ChangedEvent { + public static class ClearedEvent { public final boolean recent; - public ChangedEvent(boolean recent) { + ClearedEvent(boolean recent) { + this.recent = recent; + } + } + + public static class RemovedEvent extends StateEvent { + RemovedEvent(@Nonnull HistoryState state, boolean recent) { + super(state, recent); + } + } + + public static class AddedEvent extends StateEvent { + AddedEvent(@Nonnull HistoryState state, boolean recent) { + super(state, recent); + } + } + + public static class UpdatedEvent extends StateEvent { + UpdatedEvent(@Nonnull HistoryState state, boolean recent) { + super(state, recent); + } + } + + public abstract static class StateEvent { + @Nonnull + public final HistoryState state; + public final boolean recent; + + protected StateEvent(@Nonnull HistoryState state, boolean recent) { + this.state = state; this.recent = recent; } } diff --git a/app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java b/app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java index 98dbfd00..fee526ae 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/HistoryArrayAdapter.java @@ -51,10 +51,10 @@ public class HistoryArrayAdapter extends ArrayAdapter { final HistoryState state = getItem(position); - final TextView time = (TextView) result.findViewById(R.id.history_time); + final TextView time = (TextView) result.findViewById(R.id.history_item_time); time.setText(DateUtils.formatDateTime(getContext(), state.getTime(), DATETIME_FORMAT)); - final TextView editor = (TextView) result.findViewById(R.id.history_item); + final TextView editor = (TextView) result.findViewById(R.id.history_item_value); editor.setText(BaseHistoryFragment.getHistoryText(state)); final TextView commentView = (TextView) result.findViewById(R.id.history_item_comment); diff --git a/app/src/main/java/org/solovyev/android/calculator/history/HistoryState.java b/app/src/main/java/org/solovyev/android/calculator/history/HistoryState.java index 59022780..57c24f46 100644 --- a/app/src/main/java/org/solovyev/android/calculator/history/HistoryState.java +++ b/app/src/main/java/org/solovyev/android/calculator/history/HistoryState.java @@ -3,7 +3,6 @@ package org.solovyev.android.calculator.history; import android.annotation.SuppressLint; import android.os.Parcel; import android.os.Parcelable; - import org.json.JSONException; import org.json.JSONObject; import org.solovyev.android.Check; @@ -37,7 +36,7 @@ public class HistoryState implements Parcelable { public final EditorState editor; @Nonnull public final DisplayState display; - protected long time; + protected long time = now(); @Nonnull protected String comment = ""; @@ -47,8 +46,8 @@ public class HistoryState implements Parcelable { this.display = display; } - private HistoryState(@Nonnull HistoryState state) { - this.id = state.id; + private HistoryState(@Nonnull HistoryState state, boolean newState) { + this.id = newState ? System.identityHashCode(this) : state.id; this.editor = state.editor; this.display = state.display; this.time = state.time; @@ -75,8 +74,8 @@ public class HistoryState implements Parcelable { } @Nonnull - public static Builder builder(@Nonnull HistoryState state) { - return new Builder(state); + public static Builder builder(@Nonnull HistoryState state, boolean newState) { + return new Builder(state, newState); } @Nonnull @@ -84,6 +83,10 @@ public class HistoryState implements Parcelable { return new HistoryState(json); } + private static long now() { + return System.currentTimeMillis(); + } + @Nonnull public JSONObject toJson() throws JSONException { final JSONObject json = new JSONObject(); @@ -122,7 +125,7 @@ public class HistoryState implements Parcelable { @Override public boolean equals(Object o) { if (this == o) return true; - if (o == null || getClass() != o.getClass()) return false; + if (o == null || !(o instanceof HistoryState)) return false; final HistoryState that = (HistoryState) o; @@ -167,16 +170,13 @@ public class HistoryState implements Parcelable { private Builder(@Nonnull EditorState editor, @Nonnull DisplayState display) { super(editor, display); - withNowTime(); } - private Builder(@Nonnull HistoryState state) { - super(state); - } - - @Nonnull - public Builder withNowTime() { - return withTime(System.currentTimeMillis()); + private Builder(@Nonnull HistoryState state, boolean newState) { + super(state, newState); + if (newState) { + withTime(now()); + } } @Nonnull 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 fb810fdb..b2332fdf 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 @@ -37,53 +37,4 @@ public class RecentHistoryFragment extends BaseHistoryFragment { public RecentHistoryFragment() { super(CalculatorFragmentType.history); } - - @Override - protected int getItemLayoutId() { - return R.layout.fragment_history_item; - } - - @Nonnull - @Override - protected List getHistoryItems() { - return history.getRecent(); - } - - @Override - protected void clearHistory() { - history.clearRecent(); - getAdapter().clear(); - } - - @Override - 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; - } } 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 3b0d761a..9259de17 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,73 +22,11 @@ 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() { super(CalculatorFragmentType.saved_history); } - - @Override - protected int getItemLayoutId() { - return R.layout.saved_history_item; - } - - @Nonnull - @Override - protected List getHistoryItems() { - return history.getSaved(); - } - - @Override - protected void clearHistory() { - history.clearSaved(); - getAdapter().clear(); - } - - @Override - 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; - } } diff --git a/app/src/main/res/layout/fragment_history.xml b/app/src/main/res/layout/fragment_history.xml index f7fab3a0..814ec9cf 100644 --- a/app/src/main/res/layout/fragment_history.xml +++ b/app/src/main/res/layout/fragment_history.xml @@ -23,9 +23,9 @@ --> @@ -41,10 +41,13 @@ a:layout_width="match_parent" a:layout_height="match_parent"> - + diff --git a/app/src/main/res/layout/fragment_history_item.xml b/app/src/main/res/layout/fragment_history_item.xml index 53bcf1a3..24d45a2b 100644 --- a/app/src/main/res/layout/fragment_history_item.xml +++ b/app/src/main/res/layout/fragment_history_item.xml @@ -23,20 +23,29 @@ --> + a:id="@+id/history_item_value" + style="@style/CppListItemText.Primary" + a:layout_width="match_parent" + a:layout_height="wrap_content" + a:ellipsize="end" + a:maxLines="2" /> + a:id="@+id/history_item_comment" + style="@style/CppListItemText.Secondary.OneLine" + a:layout_width="match_parent" + a:layout_height="wrap_content" /> + \ No newline at end of file diff --git a/app/src/main/res/layout/math_entity.xml b/app/src/main/res/layout/math_entity.xml index d1130401..6c5cc287 100644 --- a/app/src/main/res/layout/math_entity.xml +++ b/app/src/main/res/layout/math_entity.xml @@ -24,14 +24,14 @@ diff --git a/app/src/main/res/layout/saved_history_item.xml b/app/src/main/res/layout/saved_history_item.xml deleted file mode 100644 index eb0e74ae..00000000 --- a/app/src/main/res/layout/saved_history_item.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-ar/text_strings.xml b/app/src/main/res/values-ar/text_strings.xml index b6b4c31a..d62d201a 100644 --- a/app/src/main/res/values-ar/text_strings.xml +++ b/app/src/main/res/values-ar/text_strings.xml @@ -104,7 +104,7 @@ سجل المحفوظات سجل التعديلات تعديل - السجل المحفوظ + السجل المحفوظ السجل محفوظ مسبقاً! يجب أن يتم حفظ السجل قبل التعديل! تمت إزالة السجل بنجاح! diff --git a/app/src/main/res/values-cs/text_strings.xml b/app/src/main/res/values-cs/text_strings.xml index 31d5cbbb..5f3e43f1 100644 --- a/app/src/main/res/values-cs/text_strings.xml +++ b/app/src/main/res/values-cs/text_strings.xml @@ -103,7 +103,7 @@ Uložit historii Upravit historii Upravit - Uložená historie + Uložená historie Historie již byla uložena! Historie musí být uložena před úpravou! Historie byla úspěšně odebrána! diff --git a/app/src/main/res/values-de/text_strings.xml b/app/src/main/res/values-de/text_strings.xml index 8d0e39b8..4477bb3d 100644 --- a/app/src/main/res/values-de/text_strings.xml +++ b/app/src/main/res/values-de/text_strings.xml @@ -103,7 +103,7 @@ Verlauf speichern Verlauf ändern Ändern - Gespeicherter Verlauf + Gespeicherter Verlauf Verlauf wurde bereits gespeichert! Verlauf muss vor der Bearbeitung gespeichert werden! Verlauf wurde erfolgreich gelöscht! diff --git a/app/src/main/res/values-es/text_strings.xml b/app/src/main/res/values-es/text_strings.xml index 1f859dac..f14df0ba 100644 --- a/app/src/main/res/values-es/text_strings.xml +++ b/app/src/main/res/values-es/text_strings.xml @@ -106,7 +106,7 @@ Guardar el historial de Modificar la historia modificar - La historia guardada + La historia guardada La historia se salvó ya! La historia debe ser salvado antes de editar! ¡El historial se ha eliminado satisfactoriamente! diff --git a/app/src/main/res/values-fi/text_strings.xml b/app/src/main/res/values-fi/text_strings.xml index 3f0fdbd7..bd181b0d 100644 --- a/app/src/main/res/values-fi/text_strings.xml +++ b/app/src/main/res/values-fi/text_strings.xml @@ -103,7 +103,7 @@ Tallenna historia Muokkaa historia Mukauta - Tallenna historia + Tallenna historia Historia on jo tallennettu! Historia on tallennettava ennen muokkaamista! Historia on poistettu! diff --git a/app/src/main/res/values-fr/text_strings.xml b/app/src/main/res/values-fr/text_strings.xml index 7c7d194f..3bc9cdd7 100644 --- a/app/src/main/res/values-fr/text_strings.xml +++ b/app/src/main/res/values-fr/text_strings.xml @@ -103,7 +103,7 @@ Enregistrer l\'historique Modifier l\'historique Modifier - Historique enregistré + Historique enregistré L\'historique est déjà enregistré ! L\'historique doit être enregistré avant modification ! L\'historique a été supprimé avec succès ! diff --git a/app/src/main/res/values-it/text_strings.xml b/app/src/main/res/values-it/text_strings.xml index c5b5d8d4..1f5fc7a2 100644 --- a/app/src/main/res/values-it/text_strings.xml +++ b/app/src/main/res/values-it/text_strings.xml @@ -110,7 +110,7 @@ Salva storia Modificare la storia Modificare - Storia salvati + Storia salvati La storia era già salvato! La storia deve essere salvato prima di modificare! La cronologia è stata rimossa con successo! diff --git a/app/src/main/res/values-ja/text_strings.xml b/app/src/main/res/values-ja/text_strings.xml index 3f948e10..cd3470c5 100644 --- a/app/src/main/res/values-ja/text_strings.xml +++ b/app/src/main/res/values-ja/text_strings.xml @@ -106,7 +106,7 @@ 履歴を保存 履歴を編集 編集 - 保存された履歴 + 保存された履歴 履歴はすでに保存されています! 履歴を編集する前に保存してください! 履歴は正常に削除されました! diff --git a/app/src/main/res/values-nl/text_strings.xml b/app/src/main/res/values-nl/text_strings.xml index 05ab7d1b..9a991a11 100644 --- a/app/src/main/res/values-nl/text_strings.xml +++ b/app/src/main/res/values-nl/text_strings.xml @@ -103,7 +103,7 @@ Geschiedenis opslaan Geschiedenis wijzigen Wijzigen - Opgeslagen geschiedenis + Opgeslagen geschiedenis Geschiedenis was al opgeslaan! Geschiedenis moet eerst worden opgeslagen om te bewerken! Geschiedenis is succesvol verwijderd! diff --git a/app/src/main/res/values-pl/text_strings.xml b/app/src/main/res/values-pl/text_strings.xml index eacf0526..ead9c2e2 100644 --- a/app/src/main/res/values-pl/text_strings.xml +++ b/app/src/main/res/values-pl/text_strings.xml @@ -103,7 +103,7 @@ Zapisz historię Modyfikuj historię Modyfikuj - Zapisana historia + Zapisana historia Historia została już zachowana! Historia musi być zapisana przed edycją! Historia została pomyślnie usunięta! diff --git a/app/src/main/res/values-pt-rbr/text_strings.xml b/app/src/main/res/values-pt-rbr/text_strings.xml index 5201d580..6848886a 100644 --- a/app/src/main/res/values-pt-rbr/text_strings.xml +++ b/app/src/main/res/values-pt-rbr/text_strings.xml @@ -103,7 +103,7 @@ Salvar histórico Modificar histórico Modificar - Salvar no histórico + Salvar no histórico O histórico já foi salvo! O histórico deve ser salvo antes de ser editado! O histórico foi removido com sucesso! diff --git a/app/src/main/res/values-pt-rpt/text_strings.xml b/app/src/main/res/values-pt-rpt/text_strings.xml index bca8e6cd..a57ca624 100644 --- a/app/src/main/res/values-pt-rpt/text_strings.xml +++ b/app/src/main/res/values-pt-rpt/text_strings.xml @@ -103,7 +103,7 @@ Guardar histórico Modificar histórico Modificar - Histórico guardado + Histórico guardado O histórico já foi guardado! O histórico deve ser guardado antes de ser alterado! O histórico foi removido com sucesso! diff --git a/app/src/main/res/values-ru/text_strings.xml b/app/src/main/res/values-ru/text_strings.xml index 352f51d5..58e44fa9 100644 --- a/app/src/main/res/values-ru/text_strings.xml +++ b/app/src/main/res/values-ru/text_strings.xml @@ -117,7 +117,7 @@ Сохранить Изменить Изменить - Сохранённая история + Сохранённая история История уже была сохранена! История должна быть сохранена перед редактированием! История успешно удалена! diff --git a/app/src/main/res/values-tr/text_strings.xml b/app/src/main/res/values-tr/text_strings.xml index edb3cdff..0dded81c 100644 --- a/app/src/main/res/values-tr/text_strings.xml +++ b/app/src/main/res/values-tr/text_strings.xml @@ -103,7 +103,7 @@ Geçmişi kaydet Geçmişi düzenle Düzenle - Kayıtlı geçmiş + Kayıtlı geçmiş Geçmiş zaten kaydedildi! Geçmiş düzenlenmeden önce kaydedilmelidir! Geçmiş başarıyla silindi! diff --git a/app/src/main/res/values-uk/text_strings.xml b/app/src/main/res/values-uk/text_strings.xml index 338b828e..e5a59d16 100644 --- a/app/src/main/res/values-uk/text_strings.xml +++ b/app/src/main/res/values-uk/text_strings.xml @@ -108,7 +108,7 @@ Зберегти історію Змінити історію Змінити - Збережена історія + Збережена історія Історія вже збережена! Історію необхідно зберегти перед редагуванням! Історія успішно видалена! diff --git a/app/src/main/res/values-vi/text_strings.xml b/app/src/main/res/values-vi/text_strings.xml index d9f6ae4e..ad6feec1 100644 --- a/app/src/main/res/values-vi/text_strings.xml +++ b/app/src/main/res/values-vi/text_strings.xml @@ -103,7 +103,7 @@ Lưu lịch sử Sửa đổi lịch sử Điều chỉnh - Lịch sử đã lưu + Lịch sử đã lưu Lịch sử đã được lưu! Lịch sử phải được lưu trước khi chỉnh sửa! Lịch sử đã được loại bỏ thành công! diff --git a/app/src/main/res/values-zh-rcn/text_strings.xml b/app/src/main/res/values-zh-rcn/text_strings.xml index fbcb216a..e359e7bb 100644 --- a/app/src/main/res/values-zh-rcn/text_strings.xml +++ b/app/src/main/res/values-zh-rcn/text_strings.xml @@ -104,7 +104,7 @@ 保存历史记录 修改历史记录 修改 - 已保存历史记录 + 已保存历史记录 记录已保存! 编辑之前必须先保存! 已成功删除历史记录! diff --git a/app/src/main/res/values-zh-rtw/text_strings.xml b/app/src/main/res/values-zh-rtw/text_strings.xml index 39fce876..ecf026be 100644 --- a/app/src/main/res/values-zh-rtw/text_strings.xml +++ b/app/src/main/res/values-zh-rtw/text_strings.xml @@ -103,7 +103,7 @@ 儲存歷史紀錄 修改歷史紀錄 修改 - 已儲存的歷史紀錄 + 已儲存的歷史紀錄 歷史紀錄已經儲存! 編輯歷史紀錄之前必須先儲存! 成功刪除歷史紀錄! diff --git a/app/src/main/res/values/colors.xml b/app/src/main/res/values/colors.xml index 33f6f9f5..c93a1422 100644 --- a/app/src/main/res/values/colors.xml +++ b/app/src/main/res/values/colors.xml @@ -29,14 +29,14 @@ #ffffffff #ffffff99 #ffffff99 - #101010 + @color/grey_950 #fff6f1ef #424242 #616161 #757575 #ff000000 - @color/cpp_material_grey - @color/cpp_material_grey_light + @color/grey_900 + @color/grey_800 #10648c #ff0d4663 #ff0d668d @@ -53,12 +53,15 @@ #66ffffff #FAFAFA - #212121 - #393939 - @color/cpp_material_grey - @color/cpp_material_grey_light + @color/grey_900 + @color/grey_800 - @color/cpp_material_grey + @color/grey_900 #ffeae5e3 + #212121 + #101010 + #757575 + #424242 + #37474F \ No newline at end of file diff --git a/app/src/main/res/values/styles.xml b/app/src/main/res/values/styles.xml index 83528343..6c560169 100644 --- a/app/src/main/res/values/styles.xml +++ b/app/src/main/res/values/styles.xml @@ -253,15 +253,23 @@ center_horizontal - + + + + - + + + + + + - @@ -321,4 +342,6 @@ @color/cpp_material_actionbar_light + 16sp + 14sp \ No newline at end of file diff --git a/app/src/main/res/values/text_strings.xml b/app/src/main/res/values/text_strings.xml index 83b507ba..b0a78fc9 100644 --- a/app/src/main/res/values/text_strings.xml +++ b/app/src/main/res/values/text_strings.xml @@ -103,7 +103,8 @@ Save history Modify history Modify - Saved history + Saved + Recent History was already saved! History must be saved before editing! History has been successfully removed! diff --git a/app/src/main/res/values/theme.xml b/app/src/main/res/values/theme.xml index d7d76ee6..77fd49ec 100644 --- a/app/src/main/res/values/theme.xml +++ b/app/src/main/res/values/theme.xml @@ -33,9 +33,11 @@ @color/cpp_main_bg @drawable/pane - @color/cpp_material_grey + @color/grey_900 @color/cpp_text @color/cpp_text_error + + @drawable/divider