From 623bd4931ba4b098923caaacc46dede185d7056f Mon Sep 17 00:00:00 2001 From: PaulStets Date: Tue, 19 Dec 2017 17:38:08 +0200 Subject: [PATCH] Added recipients table to OsmAnd Live reports --- OsmAnd/res/layout/fragment_reports.xml | 4 +- OsmAnd/res/values/strings.xml | 2 + .../net/osmand/plus/liveupdates/Protocol.java | 13 ++- .../plus/liveupdates/ReportsFragment.java | 18 +++- .../plus/liveupdates/UsersReportFragment.java | 102 ++++++++++++------ 5 files changed, 100 insertions(+), 39 deletions(-) diff --git a/OsmAnd/res/layout/fragment_reports.xml b/OsmAnd/res/layout/fragment_reports.xml index cc94f46c20..b900f162e6 100644 --- a/OsmAnd/res/layout/fragment_reports.xml +++ b/OsmAnd/res/layout/fragment_reports.xml @@ -275,6 +275,9 @@ android:background="?attr/dashboard_divider"/> Donations Number of recipients Edits %1$s, rank %2$s, total edits %3$s + Edits %1$s, sum %2$s mBTC OSM Editors ranking OsmAnd Live subscription Subscribe @@ -2819,4 +2820,5 @@ File %1$s does not contain waypoints, import it as a track? Move Point Add to a GPX track + OSM Recipients diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/Protocol.java b/OsmAnd/src/net/osmand/plus/liveupdates/Protocol.java index f7e41e3f62..5be7ad064d 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/Protocol.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/Protocol.java @@ -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 { @@ -48,5 +51,13 @@ public final class Protocol { public int users; public int changes; } - + + public static class Recipient { + String osmid; + int changes; + String btcaddress; + int rank; + int weight; + float btc; + } } diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java index 049fccb5c0..5207d72332 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/ReportsFragment.java @@ -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); diff --git a/OsmAnd/src/net/osmand/plus/liveupdates/UsersReportFragment.java b/OsmAnd/src/net/osmand/plus/liveupdates/UsersReportFragment.java index b9c19676f1..e78388b44a 100644 --- a/OsmAnd/src/net/osmand/plus/liveupdates/UsersReportFragment.java +++ b/OsmAnd/src/net/osmand/plus/liveupdates/UsersReportFragment.java @@ -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 adapter = new ListAdapter(getListItemIcon()); + final ArrayAdapter 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 task = new GetJsonAsyncTask<>(RankingUserByMonthResponse.class); - task.setOnResponseListener(new OnResponseListener() { + if (getTag().equals(ReportsFragment.EDITS_FRAGMENT)) { + ((TextView)view.findViewById(R.id.titleTextView)).setText(R.string.osm_editors_ranking); + GetJsonAsyncTask task = new GetJsonAsyncTask<>(RankingUserByMonthResponse.class); + task.setOnResponseListener(new OnResponseListener() { - @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 task = new GetJsonAsyncTask<>(Protocol.RecipientsByMonth.class); + task.setOnResponseListener(new OnResponseListener() { + + @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 { + private class ListAdapter extends ArrayAdapter { 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; + } } }