history changes
This commit is contained in:
parent
df392185f3
commit
09158df194
@ -309,6 +309,7 @@ Check the \'Round result\' preference in application settings - it should be tur
|
|||||||
<string name="c_copy_expression">Copy expression</string>
|
<string name="c_copy_expression">Copy expression</string>
|
||||||
<string name="c_copy_result">Copy result</string>
|
<string name="c_copy_result">Copy result</string>
|
||||||
<string name="c_history_expression">Value</string>
|
<string name="c_history_expression">Value</string>
|
||||||
|
<string name="c_history_item_already_saved">Already saved (see entries above)</string>
|
||||||
<string name="c_history_comment">Comment</string>
|
<string name="c_history_comment">Comment</string>
|
||||||
<string name="c_save_history">Save history</string>
|
<string name="c_save_history">Save history</string>
|
||||||
<string name="c_edit_history">Modify history</string>
|
<string name="c_edit_history">Modify history</string>
|
||||||
|
@ -14,6 +14,7 @@ import android.os.Bundle;
|
|||||||
import android.view.*;
|
import android.view.*;
|
||||||
import android.widget.*;
|
import android.widget.*;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
import org.solovyev.android.calculator.history.*;
|
import org.solovyev.android.calculator.history.*;
|
||||||
import org.solovyev.android.calculator.jscl.JsclOperation;
|
import org.solovyev.android.calculator.jscl.JsclOperation;
|
||||||
import org.solovyev.android.view.AMenu;
|
import org.solovyev.android.view.AMenu;
|
||||||
@ -99,6 +100,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
|||||||
if (isAlreadySaved(historyState)) {
|
if (isAlreadySaved(historyState)) {
|
||||||
menuItems.remove(HistoryItemMenuItem.save);
|
menuItems.remove(HistoryItemMenuItem.save);
|
||||||
}
|
}
|
||||||
|
menuItems.remove(HistoryItemMenuItem.remove);
|
||||||
menuItems.remove(HistoryItemMenuItem.edit);
|
menuItems.remove(HistoryItemMenuItem.edit);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -128,7 +130,15 @@ public class CalculatorHistoryActivity extends ListActivity {
|
|||||||
boolean result = false;
|
boolean result = false;
|
||||||
try {
|
try {
|
||||||
historyState.setSaved(true);
|
historyState.setSaved(true);
|
||||||
if ( CalculatorHistory.instance.getSavedHistory().contains(historyState) ) {
|
if ( CollectionsUtils.contains(historyState, CalculatorHistory.instance.getSavedHistory(), new Equalizer<CalculatorHistoryState>() {
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
||||||
|
return first != null && second != null &&
|
||||||
|
first.getTime().getTime() == second.getTime().getTime() &&
|
||||||
|
first.getDisplayState().equals(second.getDisplayState()) &&
|
||||||
|
first.getEditorState().equals(second.getEditorState());
|
||||||
|
}
|
||||||
|
}) ) {
|
||||||
result = true;
|
result = true;
|
||||||
}
|
}
|
||||||
} finally {
|
} finally {
|
||||||
@ -199,10 +209,14 @@ public class CalculatorHistoryActivity extends ListActivity {
|
|||||||
}
|
}
|
||||||
|
|
||||||
final TextView status = (TextView) result.findViewById(R.id.history_item_status);
|
final TextView status = (TextView) result.findViewById(R.id.history_item_status);
|
||||||
if (state.isSaved() || isAlreadySaved(state)) {
|
if (state.isSaved()) {
|
||||||
status.setText(ResourceCache.instance.getCaption("c_history_item_saved"));
|
status.setText(ResourceCache.instance.getCaption("c_history_item_saved"));
|
||||||
} else {
|
} else {
|
||||||
status.setText(ResourceCache.instance.getCaption("c_history_item_not_saved"));
|
if ( isAlreadySaved(state) ) {
|
||||||
|
status.setText(ResourceCache.instance.getCaption("c_history_item_already_saved"));
|
||||||
|
} else {
|
||||||
|
status.setText(ResourceCache.instance.getCaption("c_history_item_not_saved"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -31,6 +31,17 @@ public class AbstractHistoryState implements Cloneable{
|
|||||||
@Transient
|
@Transient
|
||||||
private boolean saved;
|
private boolean saved;
|
||||||
|
|
||||||
|
@Transient
|
||||||
|
private int id = 0;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Date getTime() {
|
public Date getTime() {
|
||||||
return time;
|
return time;
|
||||||
|
@ -29,6 +29,9 @@ public enum CalculatorHistory implements HistoryHelper<CalculatorHistoryState> {
|
|||||||
|
|
||||||
instance;
|
instance;
|
||||||
|
|
||||||
|
// todo serso: not synchronized
|
||||||
|
private int counter = 0;
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
private final HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
|
private final HistoryHelper<CalculatorHistoryState> history = new SimpleHistoryHelper<CalculatorHistoryState>();
|
||||||
|
|
||||||
@ -97,6 +100,7 @@ public enum CalculatorHistory implements HistoryHelper<CalculatorHistoryState> {
|
|||||||
HistoryUtils.fromXml(value, this.savedHistory);
|
HistoryUtils.fromXml(value, this.savedHistory);
|
||||||
for (CalculatorHistoryState historyState : savedHistory) {
|
for (CalculatorHistoryState historyState : savedHistory) {
|
||||||
historyState.setSaved(true);
|
historyState.setSaved(true);
|
||||||
|
historyState.setId(counter++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -122,6 +126,7 @@ public enum CalculatorHistory implements HistoryHelper<CalculatorHistoryState> {
|
|||||||
} else {
|
} else {
|
||||||
final CalculatorHistoryState savedState = historyState.clone();
|
final CalculatorHistoryState savedState = historyState.clone();
|
||||||
|
|
||||||
|
savedState.setId(counter++);
|
||||||
savedState.setSaved(true);
|
savedState.setSaved(true);
|
||||||
|
|
||||||
savedHistory.add(savedState);
|
savedHistory.add(savedState);
|
||||||
@ -133,8 +138,7 @@ public enum CalculatorHistory implements HistoryHelper<CalculatorHistoryState> {
|
|||||||
|
|
||||||
public void removeSavedHistory(@NotNull CalculatorHistoryState historyState, @NotNull Context context, @NotNull SharedPreferences preferences) {
|
public void removeSavedHistory(@NotNull CalculatorHistoryState historyState, @NotNull Context context, @NotNull SharedPreferences preferences) {
|
||||||
historyState.setSaved(false);
|
historyState.setSaved(false);
|
||||||
|
this.savedHistory.remove(historyState);
|
||||||
save(context);
|
save(context);
|
||||||
this.savedHistory.clear();
|
|
||||||
load(context, preferences);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -77,6 +77,7 @@ public class CalculatorHistoryState extends AbstractHistoryState {
|
|||||||
CalculatorHistoryState that = (CalculatorHistoryState) o;
|
CalculatorHistoryState that = (CalculatorHistoryState) o;
|
||||||
|
|
||||||
if (this.isSaved() != that.isSaved()) return false;
|
if (this.isSaved() != that.isSaved()) return false;
|
||||||
|
if (this.getId() != that.getId()) return false;
|
||||||
if (!displayState.equals(that.displayState)) return false;
|
if (!displayState.equals(that.displayState)) return false;
|
||||||
if (!editorState.equals(that.editorState)) return false;
|
if (!editorState.equals(that.editorState)) return false;
|
||||||
|
|
||||||
@ -86,6 +87,7 @@ public class CalculatorHistoryState extends AbstractHistoryState {
|
|||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = Boolean.valueOf(isSaved()).hashCode();
|
int result = Boolean.valueOf(isSaved()).hashCode();
|
||||||
|
result = 31 * result + getId();
|
||||||
result = 31 * result + editorState.hashCode();
|
result = 31 * result + editorState.hashCode();
|
||||||
result = 31 * result + displayState.hashCode();
|
result = 31 * result + displayState.hashCode();
|
||||||
return result;
|
return result;
|
||||||
|
@ -91,12 +91,12 @@ public enum HistoryItemMenuItem implements AMenuItem<HistoryItemMenuData> {
|
|||||||
@Override
|
@Override
|
||||||
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
public void doAction(@NotNull HistoryItemMenuData data, @NotNull Context context) {
|
||||||
final CalculatorHistoryState historyState = data.getHistoryState();
|
final CalculatorHistoryState historyState = data.getHistoryState();
|
||||||
data.getAdapter().remove(historyState);
|
|
||||||
if (historyState.isSaved()) {
|
if (historyState.isSaved()) {
|
||||||
|
data.getAdapter().remove(historyState);
|
||||||
CalculatorHistory.instance.removeSavedHistory(historyState, context, PreferenceManager.getDefaultSharedPreferences(context));
|
CalculatorHistory.instance.removeSavedHistory(historyState, context, PreferenceManager.getDefaultSharedPreferences(context));
|
||||||
Toast.makeText(context, "History item was removed!", Toast.LENGTH_LONG).show();
|
Toast.makeText(context, "History item was removed!", Toast.LENGTH_LONG).show();
|
||||||
|
data.getAdapter().notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
data.getAdapter().notifyDataSetChanged();
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user