Added recipients table to OsmAnd Live reports

This commit is contained in:
PaulStets 2017-12-19 17:38:08 +02:00
parent 67f668bf0c
commit 623bd4931b
5 changed files with 100 additions and 39 deletions

View file

@ -275,6 +275,9 @@
android:background="?attr/dashboard_divider"/>
<LinearLayout
android:id="@+id/numberOfRecipientsLayout"
android:background="?attr/selectableItemBackground"
android:clickable="true"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
@ -289,7 +292,6 @@
android:src="@drawable/ic_group"/>
<LinearLayout
android:id="@+id/numberOfRecipientsLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginRight="16dp"

View file

@ -554,6 +554,7 @@
<string name="donations">Donations</string>
<string name="number_of_recipients">Number of recipients</string>
<string name="osm_user_stat">Edits %1$s, rank %2$s, total edits %3$s</string>
<string name="osm_recipient_stat">Edits %1$s, sum %2$s mBTC</string>
<string name="osm_editors_ranking">OSM Editors ranking</string>
<string name="osm_live_subscription">OsmAnd Live subscription</string>
<string name="osm_live_subscribe_btn">Subscribe</string>
@ -2819,4 +2820,5 @@
<string name="import_track_desc">File %1$s does not contain waypoints, import it as a track?</string>
<string name="move_point">Move Point</string>
<string name="add_segment_to_the_track">Add to a GPX track</string>
<string name="osm_recipients_label">OSM Recipients</string>
</resources>

View file

@ -23,6 +23,9 @@ public final class Protocol {
public int regionCount;
public float regionPercentage;
public float btc;
public float eur;
public float eurRate;
public Recipient[] rows;
}
public static class UserRankingByMonth {
@ -49,4 +52,12 @@ public final class Protocol {
public int changes;
}
public static class Recipient {
String osmid;
int changes;
String btcaddress;
int rank;
int weight;
float btc;
}
}

View file

@ -52,6 +52,8 @@ public class ReportsFragment extends BaseOsmAndFragment implements CountrySelect
private static final Log LOG = PlatformUtil.getLog(ReportsFragment.class);
public static final String OSM_LIVE_URL = "https://osmand.net/osm_live";
public static final String EDITS_FRAGMENT = "NumberOfEditsFragment";
public static final String RECIPIENTS_FRAGMENT = "RecipientsFragment";
private TextView contributorsTextView;
private TextView editsTextView;
@ -129,15 +131,23 @@ public class ReportsFragment extends BaseOsmAndFragment implements CountrySelect
String countryUrlString = selectedCountryItem.getDownloadName();
if (countryUrlString.length() > 0) {
Bundle bl = new Bundle();
bl.putString(UsersReportFragment.URL_REQUEST,
String.format(USERS_RANKING_BY_MONTH, monthUrlString, countryUrlString));
userReportFragment.setArguments(bl);
userReportFragment.show(getChildFragmentManager(), "NumberOfEditsFramgnet");
if (v.getId() == R.id.numberOfRecipientsLayout) {
bl.putString(UsersReportFragment.URL_REQUEST,
String.format(RECIPIENTS_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);
}
}
}
};
view.findViewById(R.id.numberOfContributorsLayout).setOnClickListener(listener);
view.findViewById(R.id.numberOfEditsLayout).setOnClickListener(listener);
view.findViewById(R.id.numberOfRecipientsLayout).setOnClickListener(listener);
countrySelectionFragment.initCountries(getMyApplication());
selectedCountryItem = countrySelectionFragment.getCountryItems().get(0);

View file

@ -1,7 +1,5 @@
package net.osmand.plus.liveupdates;
import java.util.Arrays;
import net.osmand.plus.R;
import net.osmand.plus.base.BaseOsmAndDialogFragment;
import net.osmand.plus.liveupdates.Protocol.RankingUserByMonthResponse;
@ -32,27 +30,45 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final View view = inflater.inflate(R.layout.fragment_simple_list, container, false);
ListView listView = (ListView) view.findViewById(android.R.id.list);
final ArrayAdapter<UserRankingByMonth> adapter = new ListAdapter(getListItemIcon());
final ArrayAdapter<Object> adapter = new ListAdapter(getListItemIcon());
String url = getArguments().getString(URL_REQUEST);
//String reg = getArguments().getString(REGION_NAME);
view.findViewById(R.id.progress).setVisibility(View.VISIBLE);
((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>() {
if (getTag().equals(ReportsFragment.EDITS_FRAGMENT)) {
((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>() {
@Override
public void onResponse(RankingUserByMonthResponse response) {
if (response != null && response.rows != null) {
for (UserRankingByMonth rankingByMonth : response.rows) {
adapter.add(rankingByMonth);
@Override
public void onResponse(RankingUserByMonthResponse response) {
if (response != null && response.rows != null) {
for (UserRankingByMonth rankingByMonth : response.rows) {
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);
listView.setAdapter(adapter);
});
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);
task.setOnResponseListener(new OnResponseListener<Protocol.RecipientsByMonth>() {
@Override
public void onResponse(Protocol.RecipientsByMonth response) {
if (response != null && response.rows != null) {
for (Protocol.Recipient recipient : response.rows) {
adapter.add(recipient);
}
}
view.findViewById(R.id.progress).setVisibility(View.GONE);
}
});
task.executeOnExecutor(AsyncTask.THREAD_POOL_EXECUTOR, url);
listView.setAdapter(adapter);
}
ImageButton clearButton = (ImageButton) view.findViewById(R.id.closeButton);
//setThemedDrawable(clearButton, R.drawable.ic_action_remove_dark);
clearButton.setOnClickListener(new View.OnClickListener() {
@ -74,7 +90,7 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
super.onDetach();
}
private class ListAdapter extends ArrayAdapter<UserRankingByMonth> {
private class ListAdapter extends ArrayAdapter<Object> {
private final Drawable drawableLeft;
@ColorInt
private final int textColor;
@ -94,22 +110,42 @@ public class UsersReportFragment extends BaseOsmAndDialogFragment {
@Override
public View getView(int position, View convertView, ViewGroup parent) {
UserRankingByMonth item = getItem(position);
View v = convertView;
if (v == null) {
LayoutInflater inflater = getActivity().getLayoutInflater();
v = inflater.inflate(android.R.layout.simple_list_item_2, parent, false);
if (getItem(position) instanceof UserRankingByMonth) {
UserRankingByMonth item = (UserRankingByMonth) 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.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);
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;
}
TextView text1 = (TextView) v.findViewById(android.R.id.text1);
TextView text2 = (TextView) v.findViewById(android.R.id.text2);
text1.setText(item.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;
}
}
}