Reports fragment. Json parsing GSON implementation.
This commit is contained in:
parent
e663dd72d8
commit
b9368dedd7
6 changed files with 105 additions and 29 deletions
|
@ -353,15 +353,7 @@ dependencies {
|
||||||
compile project(':eclipse-compile:design')
|
compile project(':eclipse-compile:design')
|
||||||
compile project(':eclipse-compile:cardview')
|
compile project(':eclipse-compile:cardview')
|
||||||
// compile project(":eclipse-compile:recyclerview")
|
// compile project(":eclipse-compile:recyclerview")
|
||||||
compile fileTree(
|
compile fileTree(include: ['*.jar'], exclude: ['QtAndroid-bundled.jar', 'QtAndroidAccessibility-bundled.jar', 'OsmAndCore_android.jar', 'OsmAndCore_wrapper.jar', 'android-support-multidex.jar'], dir: 'libs')
|
||||||
dir: "libs",
|
|
||||||
include: ["*.jar"],
|
|
||||||
exclude: [
|
|
||||||
"QtAndroid-bundled.jar",
|
|
||||||
"QtAndroidAccessibility-bundled.jar",
|
|
||||||
"OsmAndCore_android.jar",
|
|
||||||
"OsmAndCore_wrapper.jar",
|
|
||||||
"android-support-multidex.jar"])
|
|
||||||
// compile "com.github.ksoichiro:android-observablescrollview:1.5.0"
|
// compile "com.github.ksoichiro:android-observablescrollview:1.5.0"
|
||||||
// compile "com.android.support:appcompat-v7:22.2.1"
|
// compile "com.android.support:appcompat-v7:22.2.1"
|
||||||
// compile "com.github.shell-software:fab:1.0.5"
|
// compile "com.github.shell-software:fab:1.0.5"
|
||||||
|
@ -371,4 +363,5 @@ dependencies {
|
||||||
qtcoredebugCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar"
|
qtcoredebugCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar"
|
||||||
qtcoreCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar"
|
qtcoreCompile "net.osmand:OsmAndCore_androidNativeRelease:0.1-SNAPSHOT@aar"
|
||||||
qtcoreCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar"
|
qtcoreCompile "net.osmand:OsmAndCore_android:0.1-SNAPSHOT@aar"
|
||||||
|
compile files('libs/gson-2.5.jar')
|
||||||
}
|
}
|
||||||
|
|
BIN
OsmAnd/libs/gson-2.5.jar
Normal file
BIN
OsmAnd/libs/gson-2.5.jar
Normal file
Binary file not shown.
|
@ -51,6 +51,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:text="Number of contributors"/>
|
android:text="Number of contributors"/>
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/contributorsTextView"
|
||||||
android:text="65"/>
|
android:text="65"/>
|
||||||
<View
|
<View
|
||||||
android:layout_column="1"
|
android:layout_column="1"
|
||||||
|
@ -64,6 +65,7 @@
|
||||||
<TextView
|
<TextView
|
||||||
android:text="Number of edits"/>
|
android:text="Number of edits"/>
|
||||||
<TextView
|
<TextView
|
||||||
|
android:id="@+id/editsTextView"
|
||||||
android:text="1125"/>
|
android:text="1125"/>
|
||||||
</GridLayout>
|
</GridLayout>
|
||||||
|
|
||||||
|
|
|
@ -9,10 +9,13 @@ import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ArrayAdapter;
|
import android.widget.ArrayAdapter;
|
||||||
import android.widget.Spinner;
|
import android.widget.Spinner;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
import net.osmand.plus.IconsCache;
|
import net.osmand.plus.IconsCache;
|
||||||
import net.osmand.plus.R;
|
import net.osmand.plus.R;
|
||||||
import net.osmand.plus.base.BaseOsmAndFragment;
|
import net.osmand.plus.base.BaseOsmAndFragment;
|
||||||
|
import net.osmand.plus.liveupdates.network.GetJsonAsyncTask;
|
||||||
|
import net.osmand.plus.liveupdates.network.Protocol;
|
||||||
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
@ -29,6 +32,7 @@ import java.util.Locale;
|
||||||
*/
|
*/
|
||||||
public class ReportsFragment extends BaseOsmAndFragment {
|
public class ReportsFragment extends BaseOsmAndFragment {
|
||||||
public static final String TITLE = "Report";
|
public static final String TITLE = "Report";
|
||||||
|
public static final String TOTAL_CHANGES_BY_MONTH_URL = "http://builder.osmand.net/reports/total_changes_by_month.php?month=";
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
||||||
|
@ -41,7 +45,7 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
||||||
Spinner regionReportsSpinner = (Spinner) view.findViewById(R.id.regionReportsSpinner);
|
Spinner regionReportsSpinner = (Spinner) view.findViewById(R.id.regionReportsSpinner);
|
||||||
ArrayAdapter<String> regionsForReportsAdapter =
|
ArrayAdapter<String> regionsForReportsAdapter =
|
||||||
new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
|
new ArrayAdapter<String>(getActivity(), android.R.layout.simple_spinner_item,
|
||||||
new String[] {"Worldwide"});
|
new String[]{"Worldwide"});
|
||||||
regionsForReportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
regionsForReportsAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
|
||||||
regionReportsSpinner.setAdapter(regionsForReportsAdapter);
|
regionReportsSpinner.setAdapter(regionsForReportsAdapter);
|
||||||
|
|
||||||
|
@ -50,6 +54,23 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
||||||
setThemedDrawable(view, R.id.regionIconImageView, R.drawable.ic_world_globe_dark);
|
setThemedDrawable(view, R.id.regionIconImageView, R.drawable.ic_world_globe_dark);
|
||||||
setThemedDrawable(view, R.id.numberOfContributorsIcon, R.drawable.ic_group);
|
setThemedDrawable(view, R.id.numberOfContributorsIcon, R.drawable.ic_group);
|
||||||
setThemedDrawable(view, R.id.numberOfEditsIcon, R.drawable.ic_group);
|
setThemedDrawable(view, R.id.numberOfEditsIcon, R.drawable.ic_group);
|
||||||
|
|
||||||
|
final TextView contributorsTextView = (TextView) view.findViewById(R.id.contributorsTextView);
|
||||||
|
final TextView editsTextView = (TextView) view.findViewById(R.id.editsTextView);
|
||||||
|
|
||||||
|
GetJsonAsyncTask<Protocol.TotalChangesByMonthResponse> totalChangesByMontAsyncTask =
|
||||||
|
new GetJsonAsyncTask<>(Protocol.TotalChangesByMonthResponse.class);
|
||||||
|
totalChangesByMontAsyncTask.setOnResponseListener(
|
||||||
|
new GetJsonAsyncTask.OnResponseListener<Protocol.TotalChangesByMonthResponse>() {
|
||||||
|
@Override
|
||||||
|
public void onResponse(Protocol.TotalChangesByMonthResponse response) {
|
||||||
|
contributorsTextView.setText(String.valueOf(response.users));
|
||||||
|
editsTextView.setText(String.valueOf(response.changes));
|
||||||
|
}
|
||||||
|
});
|
||||||
|
int monthItemPosition = montReportsSpinner.getSelectedItemPosition();
|
||||||
|
String monthUrlString = monthsForReportsAdapter.getQueryString(monthItemPosition);
|
||||||
|
totalChangesByMontAsyncTask.execute(TOTAL_CHANGES_BY_MONTH_URL + monthUrlString);
|
||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -81,23 +102,4 @@ public class ReportsFragment extends BaseOsmAndFragment {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// public static class GetJsonAsyncTask<Protocol> extends AsyncTask<String, Void, Protocol> {
|
|
||||||
// private static final Log LOG = PlatformUtil.getLog(GetJsonAsyncTask.class);
|
|
||||||
// private final Class<Protocol> protocolClass;
|
|
||||||
//
|
|
||||||
// public GetJsonAsyncTask(Class<Protocol> protocolClass) {
|
|
||||||
// this.protocolClass = protocolClass;
|
|
||||||
// }
|
|
||||||
//
|
|
||||||
// @Override
|
|
||||||
// protected Protocol doInBackground(String... params) {
|
|
||||||
// StringBuilder response = new StringBuilder();
|
|
||||||
// String error = NetworkUtils.sendGetRequest(params[0], null, response);
|
|
||||||
// if (error != null) {
|
|
||||||
// return
|
|
||||||
// }
|
|
||||||
// LOG.error(error);
|
|
||||||
// return null;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,50 @@
|
||||||
|
package net.osmand.plus.liveupdates.network;
|
||||||
|
|
||||||
|
import android.os.AsyncTask;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
|
||||||
|
import net.osmand.PlatformUtil;
|
||||||
|
import net.osmand.osm.io.NetworkUtils;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by GaidamakUA on 1/12/16.
|
||||||
|
*/
|
||||||
|
public class GetJsonAsyncTask<Protocol> extends AsyncTask<String, Void, Protocol> {
|
||||||
|
private static final Log LOG = PlatformUtil.getLog(GetJsonAsyncTask.class);
|
||||||
|
private final Class<Protocol> protocolClass;
|
||||||
|
private final Gson gson = new Gson();
|
||||||
|
private OnResponseListener<Protocol> onResponseListener;
|
||||||
|
|
||||||
|
public GetJsonAsyncTask(Class<Protocol> protocolClass) {
|
||||||
|
this.protocolClass = protocolClass;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected Protocol doInBackground(String... params) {
|
||||||
|
StringBuilder response = new StringBuilder();
|
||||||
|
String error = NetworkUtils.sendGetRequest(params[0], null, response);
|
||||||
|
if (error == null) {
|
||||||
|
return gson.fromJson(response.toString(), protocolClass);
|
||||||
|
}
|
||||||
|
LOG.error(error);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onPostExecute(Protocol protocol) {
|
||||||
|
if (onResponseListener != null) {
|
||||||
|
onResponseListener.onResponse(protocol);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOnResponseListener(OnResponseListener<Protocol> onResponseListener) {
|
||||||
|
this.onResponseListener = onResponseListener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface OnResponseListener<Protocol> {
|
||||||
|
void onResponse(Protocol response);
|
||||||
|
}
|
||||||
|
}
|
29
OsmAnd/src/net/osmand/plus/liveupdates/network/Protocol.java
Normal file
29
OsmAnd/src/net/osmand/plus/liveupdates/network/Protocol.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package net.osmand.plus.liveupdates.network;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Created by GaidamakUA on 1/12/16.
|
||||||
|
*/
|
||||||
|
public final class Protocol {
|
||||||
|
private Protocol(){}
|
||||||
|
|
||||||
|
public static class RankingByMonthResponse {
|
||||||
|
public String month;
|
||||||
|
public RankingByMonth[] rows;
|
||||||
|
}
|
||||||
|
|
||||||
|
// {"rank":"8","countUsers":"713","minChanges":"14","maxChanges":"18","avgChanges":"15.9845722300140252"}
|
||||||
|
public static class RankingByMonth {
|
||||||
|
public int rank;
|
||||||
|
public int countUsers;
|
||||||
|
public int minChanges;
|
||||||
|
public int maxChanges;
|
||||||
|
public float avgChanges;
|
||||||
|
}
|
||||||
|
|
||||||
|
// {"month":"2015-11","users":"28363","changes":"673830"}
|
||||||
|
public static class TotalChangesByMonthResponse {
|
||||||
|
public String month;
|
||||||
|
public int users;
|
||||||
|
public int changes;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue