Skip to content
This repository was archived by the owner on Jun 27, 2020. It is now read-only.

Commit b07bbdc

Browse files
author
Evgenii Kanivets
committed
#40[30m]. Reverse order for records, exchange rates.
1 parent 65e0b6c commit b07bbdc

File tree

2 files changed

+13
-7
lines changed

2 files changed

+13
-7
lines changed

app/src/main/java/com/blogspot/e_kanivets/moneytracker/fragment/ExchangeRatesFragment.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@
2222
import com.blogspot.e_kanivets.moneytracker.activity.NavDrawerActivity;
2323
import com.blogspot.e_kanivets.moneytracker.adapter.ExchangeRateAdapter;
2424
import com.blogspot.e_kanivets.moneytracker.controller.ExchangeRateController;
25+
import com.blogspot.e_kanivets.moneytracker.entity.ExchangeRate;
2526
import com.blogspot.e_kanivets.moneytracker.repo.ExchangeRateRepo;
2627

28+
import java.util.Collections;
29+
import java.util.List;
30+
2731
import butterknife.Bind;
2832
import butterknife.ButterKnife;
2933
import butterknife.OnClick;
@@ -116,17 +120,19 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
116120
}
117121

118122
private void update() {
119-
listView.setAdapter(new ExchangeRateAdapter(getActivity(), rateController.readAll()));
123+
List<ExchangeRate> exchangeRateList = rateController.readAll();
124+
Collections.reverse(exchangeRateList);
125+
126+
listView.setAdapter(new ExchangeRateAdapter(getActivity(), exchangeRateList));
120127
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
121128
}
122129

123130
private void initViews(View rootView) {
124131
if (rootView != null) {
125132
ButterKnife.bind(this, rootView);
126133

127-
listView.setAdapter(new ExchangeRateAdapter(getActivity(), rateController.readAll()));
128-
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
129134
registerForContextMenu(listView);
135+
update();
130136

131137
((NavDrawerActivity) getActivity()).onSectionAttached(TAG);
132138
}

app/src/main/java/com/blogspot/e_kanivets/moneytracker/fragment/RecordsFragment.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444

4545
import java.util.ArrayList;
4646
import java.util.Calendar;
47+
import java.util.Collections;
4748
import java.util.Date;
4849
import java.util.List;
4950

@@ -209,6 +210,8 @@ public void onActivityResult(int requestCode, int resultCode, Intent data) {
209210

210211
private void update() {
211212
recordList = recordController.getRecordsForPeriod(periodController.getPeriod());
213+
Collections.reverse(recordList);
214+
212215
listView.setAdapter(new RecordAdapter(getActivity(), recordList));
213216
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
214217
}
@@ -221,10 +224,7 @@ private void initViews(View rootView) {
221224
tvFromDate.setText(periodController.getFirstDay());
222225
tvToDate.setText(periodController.getLastDay());
223226

224-
recordList = recordController.getRecordsForPeriod(periodController.getPeriod());
225-
226-
listView.setAdapter(new RecordAdapter(getActivity(), recordList));
227-
((BaseAdapter) listView.getAdapter()).notifyDataSetChanged();
227+
update();
228228

229229
/* Scroll list to bottom only once at start */
230230
listView.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {

0 commit comments

Comments
 (0)