history changes
This commit is contained in:
parent
09158df194
commit
c4ecdbf8d3
@ -25,10 +25,7 @@ import org.solovyev.common.utils.*;
|
|||||||
import org.solovyev.common.utils.Filter;
|
import org.solovyev.common.utils.Filter;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.*;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* User: serso
|
* User: serso
|
||||||
@ -41,7 +38,8 @@ public class CalculatorHistoryActivity extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
public int compare(CalculatorHistoryState state1, CalculatorHistoryState state2) {
|
||||||
if (state1.isSaved() == state2.isSaved()) {
|
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()) {
|
} else if (state1.isSaved()) {
|
||||||
return -1;
|
return -1;
|
||||||
} else if (state2.isSaved()) {
|
} else if (state2.isSaved()) {
|
||||||
@ -134,7 +132,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
|||||||
@Override
|
@Override
|
||||||
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
public boolean equals(@Nullable CalculatorHistoryState first, @Nullable CalculatorHistoryState second) {
|
||||||
return first != null && second != null &&
|
return first != null && second != null &&
|
||||||
first.getTime().getTime() == second.getTime().getTime() &&
|
first.getTime() == second.getTime() &&
|
||||||
first.getDisplayState().equals(second.getDisplayState()) &&
|
first.getDisplayState().equals(second.getDisplayState()) &&
|
||||||
first.getEditorState().equals(second.getEditorState());
|
first.getEditorState().equals(second.getEditorState());
|
||||||
}
|
}
|
||||||
@ -195,7 +193,7 @@ public class CalculatorHistoryActivity extends ListActivity {
|
|||||||
final CalculatorHistoryState state = getItem(position);
|
final CalculatorHistoryState state = getItem(position);
|
||||||
|
|
||||||
final TextView time = (TextView) result.findViewById(R.id.history_time);
|
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);
|
final TextView editor = (TextView) result.findViewById(R.id.history_item);
|
||||||
editor.setText(getHistoryText(state));
|
editor.setText(getHistoryText(state));
|
||||||
|
@ -21,8 +21,7 @@ import java.util.Date;
|
|||||||
public class AbstractHistoryState implements Cloneable{
|
public class AbstractHistoryState implements Cloneable{
|
||||||
|
|
||||||
@Element
|
@Element
|
||||||
@NotNull
|
private long time = new Date().getTime();
|
||||||
private Date time = new Date();
|
|
||||||
|
|
||||||
@Element(required = false)
|
@Element(required = false)
|
||||||
@Nullable
|
@Nullable
|
||||||
@ -42,12 +41,11 @@ public class AbstractHistoryState implements Cloneable{
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
public long getTime() {
|
||||||
public Date getTime() {
|
|
||||||
return time;
|
return time;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTime(@NotNull Date time) {
|
public void setTime(long time) {
|
||||||
this.time = time;
|
this.time = time;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,7 +72,6 @@ public class AbstractHistoryState implements Cloneable{
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
clone = (AbstractHistoryState)super.clone();
|
clone = (AbstractHistoryState)super.clone();
|
||||||
clone.time = new Date(this.time.getTime());
|
|
||||||
} catch (CloneNotSupportedException e) {
|
} catch (CloneNotSupportedException e) {
|
||||||
throw new UnsupportedOperationException(e);
|
throw new UnsupportedOperationException(e);
|
||||||
}
|
}
|
||||||
|
@ -97,6 +97,7 @@ public enum CalculatorHistory implements HistoryHelper<CalculatorHistoryState> {
|
|||||||
public void load(@Nullable Context context, @Nullable SharedPreferences preferences) {
|
public void load(@Nullable Context context, @Nullable SharedPreferences preferences) {
|
||||||
if (context != null && preferences != null) {
|
if (context != null && preferences != null) {
|
||||||
final String value = preferences.getString(context.getString(R.string.p_calc_history), null);
|
final String value = preferences.getString(context.getString(R.string.p_calc_history), null);
|
||||||
|
this.savedHistory.clear();
|
||||||
HistoryUtils.fromXml(value, this.savedHistory);
|
HistoryUtils.fromXml(value, this.savedHistory);
|
||||||
for (CalculatorHistoryState historyState : savedHistory) {
|
for (CalculatorHistoryState historyState : savedHistory) {
|
||||||
historyState.setSaved(true);
|
historyState.setSaved(true);
|
||||||
|
@ -41,7 +41,7 @@ public class HistoryUtilsTest {
|
|||||||
private static final String toXml1 = "<history>\n" +
|
private static final String toXml1 = "<history>\n" +
|
||||||
" <historyItems class=\"java.util.ArrayList\">\n" +
|
" <historyItems class=\"java.util.ArrayList\">\n" +
|
||||||
" <calculatorHistoryState>\n" +
|
" <calculatorHistoryState>\n" +
|
||||||
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
|
" <time>100000000</time>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>3</cursorPosition>\n" +
|
" <cursorPosition>3</cursorPosition>\n" +
|
||||||
" <text>1+1</text>\n" +
|
" <text>1+1</text>\n" +
|
||||||
@ -60,7 +60,7 @@ public class HistoryUtilsTest {
|
|||||||
private static final String toXml2 = "<history>\n" +
|
private static final String toXml2 = "<history>\n" +
|
||||||
" <historyItems class=\"java.util.ArrayList\">\n" +
|
" <historyItems class=\"java.util.ArrayList\">\n" +
|
||||||
" <calculatorHistoryState>\n" +
|
" <calculatorHistoryState>\n" +
|
||||||
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
|
" <time>100000000</time>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>3</cursorPosition>\n" +
|
" <cursorPosition>3</cursorPosition>\n" +
|
||||||
" <text>1+1</text>\n" +
|
" <text>1+1</text>\n" +
|
||||||
@ -74,7 +74,7 @@ public class HistoryUtilsTest {
|
|||||||
" </displayState>\n" +
|
" </displayState>\n" +
|
||||||
" </calculatorHistoryState>\n" +
|
" </calculatorHistoryState>\n" +
|
||||||
" <calculatorHistoryState>\n" +
|
" <calculatorHistoryState>\n" +
|
||||||
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
|
" <time>100000000</time>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>2</cursorPosition>\n" +
|
" <cursorPosition>2</cursorPosition>\n" +
|
||||||
" <text>5/6</text>\n" +
|
" <text>5/6</text>\n" +
|
||||||
@ -88,7 +88,7 @@ public class HistoryUtilsTest {
|
|||||||
" </displayState>\n" +
|
" </displayState>\n" +
|
||||||
" </calculatorHistoryState>\n" +
|
" </calculatorHistoryState>\n" +
|
||||||
" <calculatorHistoryState>\n" +
|
" <calculatorHistoryState>\n" +
|
||||||
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
|
" <time>100000000</time>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>1</cursorPosition>\n" +
|
" <cursorPosition>1</cursorPosition>\n" +
|
||||||
" <text>null</text>\n" +
|
" <text>null</text>\n" +
|
||||||
@ -102,7 +102,7 @@ public class HistoryUtilsTest {
|
|||||||
" </displayState>\n" +
|
" </displayState>\n" +
|
||||||
" </calculatorHistoryState>\n" +
|
" </calculatorHistoryState>\n" +
|
||||||
" <calculatorHistoryState>\n" +
|
" <calculatorHistoryState>\n" +
|
||||||
" <time>1970-01-02 06:46:40.0 MSK</time>\n" +
|
" <time>100000000</time>\n" +
|
||||||
" <editorState>\n" +
|
" <editorState>\n" +
|
||||||
" <cursorPosition>0</cursorPosition>\n" +
|
" <cursorPosition>0</cursorPosition>\n" +
|
||||||
" <text>4+5/35sin(41)+dfdsfsdfs</text>\n" +
|
" <text>4+5/35sin(41)+dfdsfsdfs</text>\n" +
|
||||||
@ -135,7 +135,7 @@ public class HistoryUtilsTest {
|
|||||||
calculatorEditor.setText("1+1");
|
calculatorEditor.setText("1+1");
|
||||||
|
|
||||||
CalculatorHistoryState state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
CalculatorHistoryState state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setTime(date);
|
state.setTime(date.getTime());
|
||||||
history.addState(state);
|
history.addState(state);
|
||||||
|
|
||||||
Assert.assertEquals(emptyHistory, HistoryUtils.toXml(history.getStates()));
|
Assert.assertEquals(emptyHistory, HistoryUtils.toXml(history.getStates()));
|
||||||
@ -157,7 +157,7 @@ public class HistoryUtilsTest {
|
|||||||
|
|
||||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setSaved(true);
|
state.setSaved(true);
|
||||||
state.setTime(date);
|
state.setTime(date.getTime());
|
||||||
history.addState(state);
|
history.addState(state);
|
||||||
|
|
||||||
calculatorDisplay = new TestCalculatorDisplay();
|
calculatorDisplay = new TestCalculatorDisplay();
|
||||||
@ -172,7 +172,7 @@ public class HistoryUtilsTest {
|
|||||||
|
|
||||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setSaved(true);
|
state.setSaved(true);
|
||||||
state.setTime(date);
|
state.setTime(date.getTime());
|
||||||
history.addState(state);
|
history.addState(state);
|
||||||
|
|
||||||
calculatorDisplay = new TestCalculatorDisplay();
|
calculatorDisplay = new TestCalculatorDisplay();
|
||||||
@ -187,7 +187,7 @@ public class HistoryUtilsTest {
|
|||||||
|
|
||||||
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
state = CalculatorHistoryState.newInstance(calculatorEditor, calculatorDisplay);
|
||||||
state.setSaved(true);
|
state.setSaved(true);
|
||||||
state.setTime(date);
|
state.setTime(date.getTime());
|
||||||
history.addState(state);
|
history.addState(state);
|
||||||
|
|
||||||
String xml = HistoryUtils.toXml(history.getStates());
|
String xml = HistoryUtils.toXml(history.getStates());
|
||||||
|
Loading…
Reference in New Issue
Block a user