import java.net.HttpURLConnection; //导入方法依赖的package包/类
@Override
public void run() {
try {
HttpURLConnection request = (HttpURLConnection) new URL("https://api.github.com/repos/TheAndroidMaster/MediaNotification/contributors").openConnection();
request.connect();
JsonReader reader = new JsonReader(new InputStreamReader((InputStream) request.getContent()));
reader.setLenient(true);
reader.beginArray();
reader.skipValue();
while (reader.hasNext()) {
reader.beginObject();
String name = null, imageUrl = null, url = null;
while (reader.hasNext()) {
switch (reader.nextName()) {
case "login":
name = reader.nextString();
break;
case "avatar_url":
imageUrl = reader.nextString();
break;
case "html_url":
url = reader.nextString();
break;
default:
reader.skipValue();
}
}
contributors.add(new ContributorData(name, imageUrl, url));
reader.endObject();
}
reader.endArray();
} catch (Exception ignored) {
}
new Handler(Looper.getMainLooper()).post(new Runnable() {
@Override
public void run() {
AboutDialog dialog = dialogReference.get();
if (dialog != null) {
dialog.contributorView.getAdapter().notifyDataSetChanged();
for (final ContributorData contributor : contributors) {
new ContributorThread(dialog, contributor).start();
}
}
}
});
}