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