history changes

This commit is contained in:
Sergey Solovyev 2011-12-18 17:44:59 +04:00
parent 09158df194
commit c4ecdbf8d3
4 changed files with 18 additions and 22 deletions

View File

@ -25,10 +25,7 @@ import org.solovyev.common.utils.*;
import org.solovyev.common.utils.Filter;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.*;
/**
* User: serso
@ -41,7 +38,8 @@ public class CalculatorHistoryActivity extends ListActivity {
@Override
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
if (state1.isSaved() == state2.isSaved()) {
return state2.getTime().compareTo(state1.getTime());
long l = state2.getTime() - state1.getTime();
return l > 0l ? 1 : (l < 0l ? -1 : 0);
} else if (state1.isSaved()) {
return -1;
} else if (state2.isSaved()) {
@ -134,7 +132,7 @@ public class CalculatorHistoryActivity extends ListActivity {
@Override
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
return first != null && second != null &&
first.getTime().getTime() == second.getTime().getTime() &&
first.getTime() == second.getTime() &&
first.getDisplayState().equals(second.getDisplayState()) &&
first.getEditorState().equals(second.getEditorState());
}
@ -195,7 +193,7 @@ public class CalculatorHistoryActivity extends ListActivity {
final CalculatorHistoryState state = getItem(position);
final TextView time = (TextView) result.findViewById(R.id.history_time);
time.setText(new SimpleDateFormat().format(state.getTime()));
time.setText(new SimpleDateFormat().format(new Date(state.getTime())));
final TextView editor = (TextView) result.findViewById(R.id.history_item);
editor.setText(getHistoryText(state));

View File

@ -21,8 +21,7 @@ import java.util.Date;
public class AbstractHistoryState implements Cloneable{
@Element
@NotNull
private Date time = new Date();
private long time = new Date().getTime();
@Element(required = false)
@Nullable
@ -42,12 +41,11 @@ public class AbstractHistoryState implements Cloneable{
this.id = id;
}
@NotNull
public Date getTime() {
public long getTime() {
return time;
}
public void setTime(@NotNull Date time) {
public void setTime(long time) {
this.time = time;
}
@ -74,7 +72,6 @@ public class AbstractHistoryState implements Cloneable{
try {
clone = (AbstractHistoryState)super.clone();
clone.time = new Date(this.time.getTime());
} catch (CloneNotSupportedException e) {
throw new UnsupportedOperationException(e);
}

View File

@ -97,6 +97,7 @@ public enum CalculatorHistory implements HistoryHelper<CalculatorHistoryState> {
public void load(@Nullable Context context, @Nullable SharedPreferences preferences) {
if (context != null && preferences != null) {
final String value = preferences.getString(context.getString(R.string.p_calc_history), null);
this.savedHistory.clear();
HistoryUtils.fromXml(value, this.savedHistory);
for (CalculatorHistoryState historyState : savedHistory) {
historyState.setSaved(true);

View File

@ -41,7 +41,7 @@ public class HistoryUtilsTest {
private static final String toXml1 = "<history>\n" +
" <historyItems class=\"java.util.ArrayList\">\n" +
" <calculatorHistoryState>\n" +
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
" <time>100000000</time>\n" +
" <editorState>\n" +
" <cursorPosition>3</cursorPosition>\n" +
" <text>1+1</text>\n" +
@ -60,7 +60,7 @@ public class HistoryUtilsTest {
private static final String toXml2 = "<history>\n" +
" <historyItems class=\"java.util.ArrayList\">\n" +
" <calculatorHistoryState>\n" +
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
" <time>100000000</time>\n" +
" <editorState>\n" +
" <cursorPosition>3</cursorPosition>\n" +
" <text>1+1</text>\n" +
@ -74,7 +74,7 @@ public class HistoryUtilsTest {
" </displayState>\n" +
" </calculatorHistoryState>\n" +
" <calculatorHistoryState>\n" +
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
" <time>100000000</time>\n" +
" <editorState>\n" +
" <cursorPosition>2</cursorPosition>\n" +
" <text>5/6</text>\n" +
@ -88,7 +88,7 @@ public class HistoryUtilsTest {
" </displayState>\n" +
" </calculatorHistoryState>\n" +
" <calculatorHistoryState>\n" +
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
" <time>100000000</time>\n" +
" <editorState>\n" +
" <cursorPosition>1</cursorPosition>\n" +
" <text>null</text>\n" +
@ -102,7 +102,7 @@ public class HistoryUtilsTest {
" </displayState>\n" +
" </calculatorHistoryState>\n" +
" <calculatorHistoryState>\n" +
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
" <time>100000000</time>\n" +
" <editorState>\n" +
" <cursorPosition>0</cursorPosition>\n" +
" <text>4+5/35sin(41)+dfdsfsdfs</text>\n" +
@ -135,7 +135,7 @@ public class HistoryUtilsTest {
calculatorEditor.setText("1+1");
CalculatorHistoryState state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
state.setTime(date);
state.setTime(date.getTime());
history.addState(state);
Assert.assertEquals(emptyHistory, HistoryUtils.toXml(history.getStates()));
@ -157,7 +157,7 @@ public class HistoryUtilsTest {
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
state.setSaved(true);
state.setTime(date);
state.setTime(date.getTime());
history.addState(state);
calculatorDisplay = new TestCalculatorDisplay();
@ -172,7 +172,7 @@ public class HistoryUtilsTest {
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
state.setSaved(true);
state.setTime(date);
state.setTime(date.getTime());
history.addState(state);
calculatorDisplay = new TestCalculatorDisplay();
@ -187,7 +187,7 @@ public class HistoryUtilsTest {
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
state.setSaved(true);
state.setTime(date);
state.setTime(date.getTime());
history.addState(state);
String xml = HistoryUtils.toXml(history.getStates());