Skip to content

Commit

Permalink
use new hidebroken api for attribute lists
Browse files Browse the repository at this point in the history
  • Loading branch information
segler-alex committed Jun 1, 2016
1 parent 15c596e commit 643e475
Show file tree
Hide file tree
Showing 5 changed files with 41 additions and 8 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ android {
minSdkVersion 8
targetSdkVersion 23

versionCode 24
versionName "0.15"
versionCode 25
versionName "0.16"
}

buildTypes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ protected void onCreate(Bundle savedInstanceState) {
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
return Utils.downloadFeed(getApplicationContext(), String.format(Locale.US, "http://www.radio-browser.info/webservice/json/stations/byid/%s", aStationID),true);
return Utils.downloadFeed(getApplicationContext(), String.format(Locale.US, "http://www.radio-browser.info/webservice/json/stations/byid/%s", aStationID),true,null);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@

import android.app.ProgressDialog;
import android.content.Context;
import android.content.SharedPreferences;
import android.os.AsyncTask;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.preference.PreferenceManager;
import android.text.TextUtils;
import android.util.Log;
import android.widget.ListView;
import android.widget.Toast;

import net.programmierecke.radiodroid2.data.DataRadioStation;

import java.util.HashMap;

public class FragmentBase extends Fragment {
private ProgressDialog itsProgressLoading;
private ListView lv;
Expand Down Expand Up @@ -54,6 +58,9 @@ public void DownloadUrl(final boolean forceUpdate) {
}

public void DownloadUrl(final boolean forceUpdate, final boolean displayProgress) {
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getContext());
final boolean show_broken = sharedPref.getBoolean("show_broken", false);

Log.d("DOWN","Download url:"+url);
if (TextUtils.isGraphic(url)) {
if (mycontext != null && displayProgress) {
Expand All @@ -62,7 +69,11 @@ public void DownloadUrl(final boolean forceUpdate, final boolean displayProgress
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
return Utils.downloadFeed(getActivity(), url, forceUpdate);
HashMap<String,String> p = new HashMap<String, String>();
if (!show_broken) {
p.put("hidebroken", "true");
}
return Utils.downloadFeed(getActivity(), url, forceUpdate, p);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ void Download(final boolean forceUpdate){
new AsyncTask<Void, Void, String>() {
@Override
protected String doInBackground(Void... params) {
return Utils.downloadFeed(getActivity(), "http://www.radio-browser.info/webservice/json/stats", forceUpdate);
return Utils.downloadFeed(getActivity(), "http://www.radio-browser.info/webservice/json/stats", forceUpdate, null);
}

@Override
Expand Down
28 changes: 25 additions & 3 deletions app/src/main/java/net/programmierecke/radiodroid2/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,14 @@
import java.io.FileOutputStream;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.Date;
import java.util.Dictionary;
import java.util.Enumeration;
import java.util.Locale;
import java.util.Map;

public class Utils {
public static String getCacheFile(Context ctx, String theURI) {
Expand Down Expand Up @@ -81,7 +85,7 @@ public static void writeFileCache(Context ctx, String theURI, String content){
}
}

public static String downloadFeed(Context ctx, String theURI, boolean forceUpdate) {
public static String downloadFeed(Context ctx, String theURI, boolean forceUpdate, Map<String,String> dictParams) {
if (!forceUpdate) {
String cache = getCacheFile(ctx, theURI);
if (cache != null) {
Expand All @@ -96,10 +100,28 @@ public static String downloadFeed(Context ctx, String theURI, boolean forceUpdat
connection.setConnectTimeout(4000);
connection.setReadTimeout(3000);
connection.setRequestProperty("User-Agent", "RadioDroid2/"+BuildConfig.VERSION_NAME);
connection.setRequestMethod("GET");
connection.setDoInput(true);
if (dictParams != null) {
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/json");
connection.setRequestProperty("Accept", "application/json");
connection.setRequestMethod("POST");
} else {
connection.setRequestMethod("GET");
}
connection.connect();

if (dictParams != null) {
JSONObject jsonParams = new JSONObject();
for (String key: dictParams.keySet()){
jsonParams.put(key, dictParams.get(key));
}

OutputStreamWriter wr = new OutputStreamWriter(connection.getOutputStream());
wr.write(jsonParams.toString());
wr.flush();
}

InputStream inputStream = connection.getInputStream();
BufferedReader rd = new BufferedReader(new InputStreamReader(inputStream));
String line = "";
Expand All @@ -119,7 +141,7 @@ public static String downloadFeed(Context ctx, String theURI, boolean forceUpdat
}

public static String getRealStationLink(Context ctx, String stationId){
String result = Utils.downloadFeed(ctx, "http://www.radio-browser.info/webservice/json/url/" + stationId, true);
String result = Utils.downloadFeed(ctx, "http://www.radio-browser.info/webservice/json/url/" + stationId, true, null);
if (result != null) {
JSONObject jsonObj = null;
JSONArray jsonArr = null;
Expand Down

0 comments on commit 643e475

Please sign in to comment.