Fix indentation issues when transferring code

This commit is contained in:
TwistedUmbrella 2014-11-21 15:03:22 -05:00
parent 4aa0bee20e
commit e4025420af
1 changed files with 144 additions and 145 deletions

View File

@ -23,7 +23,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import android.os.Debug;
import android.os.Handler;
import android.support.v4.app.Fragment;
import android.text.util.Linkify;
@ -42,7 +41,7 @@ import com.reicast.emulator.debug.GitAdapter;
public class AboutFragment extends Fragment {
String buildId = "";
String git_api = "https://api.github.com/repos/reicast/reicast-emulator/commits";
String git_api = "https://api.github.com/repos/reicast/reicast-emulator/commits";
SlidingDrawer slidingGithub;
private ListView list;
private GitAdapter adapter;
@ -87,11 +86,11 @@ public class AboutFragment extends Fragment {
} catch (NameNotFoundException e) {
e.printStackTrace();
}
TextView website = (TextView) getView().findViewById(
R.id.site_text);
Linkify.addLinks(website, Linkify.ALL);
handler = new Handler();
slidingGithub = (SlidingDrawer) getView().findViewById(
@ -110,159 +109,159 @@ public class AboutFragment extends Fragment {
});
}
public class retrieveGitTask extends
AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {
@Override
protected void onPreExecute() {
@Override
protected void onPreExecute() {
}
}
@Override
protected ArrayList<HashMap<String, String>> doInBackground(
String... paths) {
ArrayList<HashMap<String, String>> commitList = new ArrayList<HashMap<String, String>>();
try {
JSONArray gitObject = getContent(paths[0]);
for (int i = 0; i < gitObject.length(); i++) {
JSONObject jsonObject = gitObject.getJSONObject(i);
@Override
protected ArrayList<HashMap<String, String>> doInBackground(
String... paths) {
ArrayList<HashMap<String, String>> commitList = new ArrayList<HashMap<String, String>>();
try {
JSONArray gitObject = getContent(paths[0]);
for (int i = 0; i < gitObject.length(); i++) {
JSONObject jsonObject = gitObject.getJSONObject(i);
JSONObject commitArray = jsonObject.getJSONObject("commit");
JSONObject commitArray = jsonObject.getJSONObject("commit");
String date = commitArray.getJSONObject("committer")
.getString("date").replace("T", " ")
.replace("Z", "");
String author = commitArray.getJSONObject("author")
.getString("name");
String committer = commitArray.getJSONObject("committer")
.getString("name");
String date = commitArray.getJSONObject("committer")
.getString("date").replace("T", " ")
.replace("Z", "");
String author = commitArray.getJSONObject("author")
.getString("name");
String committer = commitArray.getJSONObject("committer")
.getString("name");
String avatar = null;
if (!jsonObject.getString("committer").equals("null")) {
avatar = jsonObject.getJSONObject("committer")
.getString("avatar_url");
committer = committer
+ " ("
+ jsonObject.getJSONObject("committer")
String avatar = null;
if (!jsonObject.getString("committer").equals("null")) {
avatar = jsonObject.getJSONObject("committer")
.getString("avatar_url");
committer = committer
+ " ("
+ jsonObject.getJSONObject("committer")
.getString("login") + ")";
if (avatar.equals("null")) {
avatar = "https://github.com/apple-touch-icon-144.png";
if (avatar.equals("null")) {
avatar = "https://github.com/apple-touch-icon-144.png";
}
} else {
avatar = "https://github.com/apple-touch-icon-144.png";
}
if (!jsonObject.getString("author").equals("null")) {
author = author
+ " ("
+ jsonObject.getJSONObject("author").getString(
"login") + ")";
}
String sha = jsonObject.getString("sha");
String curl = jsonObject
.getString("url")
.replace("https://api.github.com/repos",
"https://github.com")
.replace("commits", "commit");
String title = "No commit heading attached";
String message = "No commit message attached";
if (commitArray.getString("message").contains("\n\n")) {
String fullOutput = commitArray.getString("message");
title = fullOutput.substring(0,
fullOutput.indexOf("\n\n"));
message = fullOutput.substring(
fullOutput.indexOf("\n\n") + 1,
fullOutput.length());
} else {
title = commitArray.getString("message");
}
HashMap<String, String> map = new HashMap<String, String>();
map.put("Date", date);
map.put("Committer", committer);
map.put("Title", title);
map.put("Message", message);
map.put("Sha", sha);
map.put("Url", curl);
map.put("Author", author);
map.put("Avatar", avatar);
map.put("Build", buildId);
commitList.add(map);
}
} catch (JSONException e) {
handler.post(new Runnable() {
public void run() {
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.git_broken),
R.drawable.ic_github);
slidingGithub.close();
}
});
e.printStackTrace();
} catch (Exception e) {
handler.post(new Runnable() {
public void run() {
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.git_broken),
R.drawable.ic_github);
slidingGithub.close();
}
});
e.printStackTrace();
}
return commitList;
}
@Override
protected void onPostExecute(
ArrayList<HashMap<String, String>> commitList) {
if (commitList != null && commitList.size() > 0) {
list = (ListView) getView().findViewById(R.id.list);
list.setSelector(R.drawable.list_selector);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
adapter = new GitAdapter(getActivity(), commitList);
// Set adapter as specified collection
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
}
}
private JSONArray getContent(String urlString) throws IOException,
JSONException {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urlString);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
avatar = "https://github.com/apple-touch-icon-144.png";
}
if (!jsonObject.getString("author").equals("null")) {
author = author
+ " ("
+ jsonObject.getJSONObject("author").getString(
"login") + ")";
}
String sha = jsonObject.getString("sha");
String curl = jsonObject
.getString("url")
.replace("https://api.github.com/repos",
"https://github.com")
.replace("commits", "commit");
String title = "No commit heading attached";
String message = "No commit message attached";
if (commitArray.getString("message").contains("\n\n")) {
String fullOutput = commitArray.getString("message");
title = fullOutput.substring(0,
fullOutput.indexOf("\n\n"));
message = fullOutput.substring(
fullOutput.indexOf("\n\n") + 1,
fullOutput.length());
} else {
title = commitArray.getString("message");
}
HashMap<String, String> map = new HashMap<String, String>();
map.put("Date", date);
map.put("Committer", committer);
map.put("Title", title);
map.put("Message", message);
map.put("Sha", sha);
map.put("Url", curl);
map.put("Author", author);
map.put("Avatar", avatar);
map.put("Build", buildId);
commitList.add(map);
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
} catch (JSONException e) {
handler.post(new Runnable() {
public void run() {
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.git_broken),
R.drawable.ic_github);
slidingGithub.close();
}
});
e.printStackTrace();
} catch (Exception e) {
handler.post(new Runnable() {
public void run() {
MainActivity.showToastMessage(getActivity(),
getActivity().getString(R.string.git_broken),
R.drawable.ic_github);
slidingGithub.close();
}
});
e.printStackTrace();
return new JSONArray(builder.toString());
}
return commitList;
}
@Override
protected void onPostExecute(
ArrayList<HashMap<String, String>> commitList) {
if (commitList != null && commitList.size() > 0) {
list = (ListView) getView().findViewById(R.id.list);
list.setSelector(R.drawable.list_selector);
list.setChoiceMode(ListView.CHOICE_MODE_SINGLE);
adapter = new GitAdapter(getActivity(), commitList);
// Set adapter as specified collection
list.setAdapter(adapter);
list.setOnItemClickListener(new OnItemClickListener() {
public void onItemClick(AdapterView<?> parent, View view,
int position, long id) {
}
});
}
}
}
private JSONArray getContent(String urlString) throws IOException,
JSONException {
StringBuilder builder = new StringBuilder();
HttpClient client = new DefaultHttpClient();
HttpGet httpGet = new HttpGet(urlString);
try {
HttpResponse response = client.execute(httpGet);
StatusLine statusLine = response.getStatusLine();
int statusCode = statusLine.getStatusCode();
if (statusCode == 200) {
HttpEntity entity = response.getEntity();
InputStream content = entity.getContent();
BufferedReader reader = new BufferedReader(
new InputStreamReader(content));
String line;
while ((line = reader.readLine()) != null) {
builder.append(line);
}
} else {
}
} catch (ClientProtocolException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
return new JSONArray(builder.toString());
}
}