Refactoring
This commit is contained in:
parent
623bd4931b
commit
dd5e514dd6
2 changed files with 35 additions and 52 deletions
|
@ -131,17 +131,11 @@ public class ReportsFragment extends BaseOsmAndFragment implements CountrySelect
|
|||
String countryUrlString = selectedCountryItem.getDownloadName();
|
||||
if (countryUrlString.length() > 0) {
|
||||
Bundle bl = new Bundle();
|
||||
if (v.getId() == R.id.numberOfRecipientsLayout) {
|
||||
boolean is = v.getId() == R.id.numberOfRecipientsLayout;
|
||||
bl.putString(UsersReportFragment.URL_REQUEST,
|
||||
String.format(RECIPIENTS_BY_MONTH, monthUrlString, countryUrlString));
|
||||
String.format(is ? RECIPIENTS_BY_MONTH : USERS_RANKING_BY_MONTH, monthUrlString, countryUrlString));
|
||||
userReportFragment.setArguments(bl);
|
||||
userReportFragment.show(getChildFragmentManager(), RECIPIENTS_FRAGMENT);
|
||||
} else {
|
||||
bl.putString(UsersReportFragment.URL_REQUEST,
|
||||
String.format(USERS_RANKING_BY_MONTH, monthUrlString, countryUrlString));
|
||||
userReportFragment.setArguments(bl);
|
||||
userReportFragment.show(getChildFragmentManager(), EDITS_FRAGMENT);
|
||||
}
|
||||
userReportFragment.show(getChildFragmentManager(), is ? RECIPIENTS_FRAGMENT : EDITS_FRAGMENT);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
|
|
@ -35,7 +35,7 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
|
|||
//String reg = getArguments().getString(REGION_NAME);
|
||||
view.findViewById(R.id.progress).setVisibility(View.VISIBLE);
|
||||
if (getTag().equals(ReportsFragment.EDITS_FRAGMENT)) {
|
||||
((TextView)view.findViewById(R.id.titleTextView)).setText(R.string.osm_editors_ranking);
|
||||
((TextView) view.findViewById(R.id.titleTextView)).setText(R.string.osm_editors_ranking);
|
||||
GetJsonAsyncTask<RankingUserByMonthResponse> task = new GetJsonAsyncTask<>(RankingUserByMonthResponse.class);
|
||||
task.setOnResponseListener(new OnResponseListener<Protocol.RankingUserByMonthResponse>() {
|
||||
|
||||
|
@ -43,14 +43,15 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
|
|||
public void onResponse(RankingUserByMonthResponse response) {
|
||||
if (response != null && response.rows != null) {
|
||||
for (UserRankingByMonth rankingByMonth : response.rows) {
|
||||
if (rankingByMonth != null) {
|
||||
adapter.add(rankingByMonth);
|
||||
}
|
||||
}
|
||||
}
|
||||
view.findViewById(R.id.progress).setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
|
||||
listView.setAdapter(adapter);
|
||||
} else if (getTag().equals(ReportsFragment.RECIPIENTS_FRAGMENT)) {
|
||||
((TextView)view.findViewById(R.id.titleTextView)).setText(R.string.osm_recipients_label);
|
||||
GetJsonAsyncTask<Protocol.RecipientsByMonth> task = new GetJsonAsyncTask<>(Protocol.RecipientsByMonth.class);
|
||||
|
@ -60,15 +61,17 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
|
|||
public void onResponse(Protocol.RecipientsByMonth response) {
|
||||
if (response != null && response.rows != null) {
|
||||
for (Protocol.Recipient recipient : response.rows) {
|
||||
if (recipient != null) {
|
||||
adapter.add(recipient);
|
||||
}
|
||||
}
|
||||
}
|
||||
view.findViewById(R.id.progress).setVisibility(View.GONE);
|
||||
}
|
||||
});
|
||||
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
|
||||
listView.setAdapter(adapter);
|
||||
}
|
||||
listView.setAdapter(adapter);
|
||||
ImageButton clearButton = (ImageButton) view.findViewById(R.id.closeButton);
|
||||
//setThemedDrawable(clearButton, R.drawable.ic_action_remove_dark);
|
||||
clearButton.setOnClickListener(new View.OnClickListener() {
|
||||
|
@ -109,43 +112,29 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
|
|||
}
|
||||
|
||||
@Override
|
||||
public View getView(int position, View convertView, ViewGroup parent) {
|
||||
if (getItem(position) instanceof UserRankingByMonth) {
|
||||
UserRankingByMonth item = (UserRankingByMonth) getItem(position);
|
||||
View v = convertView;
|
||||
public View getView(int position, View v, ViewGroup parent) {
|
||||
if (v == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
v = inflater.inflate(android.R.layout.simple_list_item_2, parent, false);
|
||||
v = getActivity().getLayoutInflater().inflate(android.R.layout.simple_list_item_2, parent, false);
|
||||
}
|
||||
TextView text1 = (TextView) v.findViewById(android.R.id.text1);
|
||||
TextView text2 = (TextView) v.findViewById(android.R.id.text2);
|
||||
text1.setText(item.user);
|
||||
text1.setTextColor(textColor);
|
||||
text2.setTextColor(textSecondaryColor);
|
||||
text1.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
|
||||
text1.setCompoundDrawablePadding(getResources().getDimensionPixelSize(R.dimen.list_content_padding));
|
||||
Object item = getItem(position);
|
||||
if (item instanceof UserRankingByMonth) {
|
||||
UserRankingByMonth rankingByMonth = (UserRankingByMonth) item;
|
||||
text1.setText(rankingByMonth.user);
|
||||
text2.setText(getString(R.string.osm_user_stat,
|
||||
String.valueOf(item.changes), String.valueOf(item.rank), String.valueOf(item.globalchanges)));
|
||||
text1.setTextColor(textColor);
|
||||
text2.setTextColor(textSecondaryColor);
|
||||
text1.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
|
||||
text1.setCompoundDrawablePadding(getResources().getDimensionPixelSize(R.dimen.list_content_padding));
|
||||
return v;
|
||||
} else {
|
||||
Protocol.Recipient item = (Protocol.Recipient) getItem(position);
|
||||
View v = convertView;
|
||||
if (v == null) {
|
||||
LayoutInflater inflater = getActivity().getLayoutInflater();
|
||||
v = inflater.inflate(android.R.layout.simple_list_item_2, parent, false);
|
||||
}
|
||||
TextView text1 = (TextView) v.findViewById(android.R.id.text1);
|
||||
TextView text2 = (TextView) v.findViewById(android.R.id.text2);
|
||||
text1.setText(item.osmid);
|
||||
String.valueOf(rankingByMonth.changes), String.valueOf(rankingByMonth.rank), String.valueOf(rankingByMonth.globalchanges)));
|
||||
} else if (item instanceof Protocol.Recipient){
|
||||
Protocol.Recipient recipient = (Protocol.Recipient) item;
|
||||
text1.setText(recipient.osmid);
|
||||
text2.setText(getString(R.string.osm_recipient_stat,
|
||||
String.valueOf(item.changes), String.format("%.4f", (item.btc*1000f))));
|
||||
text1.setTextColor(textColor);
|
||||
text2.setTextColor(textSecondaryColor);
|
||||
text1.setCompoundDrawablesWithIntrinsicBounds(drawableLeft, null, null, null);
|
||||
text1.setCompoundDrawablePadding(getResources().getDimensionPixelSize(R.dimen.list_content_padding));
|
||||
return v;
|
||||
String.valueOf(recipient.changes), String.format("%.4f", (recipient.btc*1000f))));
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue