Fix indentation issues when transferring code
This commit is contained in:
parent
4aa0bee20e
commit
e4025420af
|
@ -23,7 +23,6 @@ import android.content.pm.PackageManager.NameNotFoundException;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.Debug;
|
|
||||||
import android.os.Handler;
|
import android.os.Handler;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.text.util.Linkify;
|
import android.text.util.Linkify;
|
||||||
|
@ -42,7 +41,7 @@ import com.reicast.emulator.debug.GitAdapter;
|
||||||
public class AboutFragment extends Fragment {
|
public class AboutFragment extends Fragment {
|
||||||
|
|
||||||
String buildId = "";
|
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;
|
SlidingDrawer slidingGithub;
|
||||||
private ListView list;
|
private ListView list;
|
||||||
private GitAdapter adapter;
|
private GitAdapter adapter;
|
||||||
|
@ -87,11 +86,11 @@ public class AboutFragment extends Fragment {
|
||||||
} catch (NameNotFoundException e) {
|
} catch (NameNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
TextView website = (TextView) getView().findViewById(
|
TextView website = (TextView) getView().findViewById(
|
||||||
R.id.site_text);
|
R.id.site_text);
|
||||||
Linkify.addLinks(website, Linkify.ALL);
|
Linkify.addLinks(website, Linkify.ALL);
|
||||||
|
|
||||||
handler = new Handler();
|
handler = new Handler();
|
||||||
|
|
||||||
slidingGithub = (SlidingDrawer) getView().findViewById(
|
slidingGithub = (SlidingDrawer) getView().findViewById(
|
||||||
|
@ -110,159 +109,159 @@ public class AboutFragment extends Fragment {
|
||||||
});
|
});
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public class retrieveGitTask extends
|
public class retrieveGitTask extends
|
||||||
AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {
|
AsyncTask<String, Integer, ArrayList<HashMap<String, String>>> {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPreExecute() {
|
protected void onPreExecute() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ArrayList<HashMap<String, String>> doInBackground(
|
protected ArrayList<HashMap<String, String>> doInBackground(
|
||||||
String... paths) {
|
String... paths) {
|
||||||
ArrayList<HashMap<String, String>> commitList = new ArrayList<HashMap<String, String>>();
|
ArrayList<HashMap<String, String>> commitList = new ArrayList<HashMap<String, String>>();
|
||||||
try {
|
try {
|
||||||
JSONArray gitObject = getContent(paths[0]);
|
JSONArray gitObject = getContent(paths[0]);
|
||||||
for (int i = 0; i < gitObject.length(); i++) {
|
for (int i = 0; i < gitObject.length(); i++) {
|
||||||
JSONObject jsonObject = gitObject.getJSONObject(i);
|
JSONObject jsonObject = gitObject.getJSONObject(i);
|
||||||
|
|
||||||
JSONObject commitArray = jsonObject.getJSONObject("commit");
|
JSONObject commitArray = jsonObject.getJSONObject("commit");
|
||||||
|
|
||||||
String date = commitArray.getJSONObject("committer")
|
String date = commitArray.getJSONObject("committer")
|
||||||
.getString("date").replace("T", " ")
|
.getString("date").replace("T", " ")
|
||||||
.replace("Z", "");
|
.replace("Z", "");
|
||||||
String author = commitArray.getJSONObject("author")
|
String author = commitArray.getJSONObject("author")
|
||||||
.getString("name");
|
.getString("name");
|
||||||
String committer = commitArray.getJSONObject("committer")
|
String committer = commitArray.getJSONObject("committer")
|
||||||
.getString("name");
|
.getString("name");
|
||||||
|
|
||||||
String avatar = null;
|
String avatar = null;
|
||||||
if (!jsonObject.getString("committer").equals("null")) {
|
if (!jsonObject.getString("committer").equals("null")) {
|
||||||
avatar = jsonObject.getJSONObject("committer")
|
avatar = jsonObject.getJSONObject("committer")
|
||||||
.getString("avatar_url");
|
.getString("avatar_url");
|
||||||
committer = committer
|
committer = committer
|
||||||
+ " ("
|
+ " ("
|
||||||
+ jsonObject.getJSONObject("committer")
|
+ jsonObject.getJSONObject("committer")
|
||||||
.getString("login") + ")";
|
.getString("login") + ")";
|
||||||
if (avatar.equals("null")) {
|
if (avatar.equals("null")) {
|
||||||
avatar = "https://github.com/apple-touch-icon-144.png";
|
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 {
|
} else {
|
||||||
avatar = "https://github.com/apple-touch-icon-144.png";
|
|
||||||
}
|
}
|
||||||
if (!jsonObject.getString("author").equals("null")) {
|
} catch (ClientProtocolException e) {
|
||||||
author = author
|
e.printStackTrace();
|
||||||
+ " ("
|
} catch (IOException e) {
|
||||||
+ jsonObject.getJSONObject("author").getString(
|
e.printStackTrace();
|
||||||
"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);
|
|
||||||
}
|
}
|
||||||
|
return new JSONArray(builder.toString());
|
||||||
} 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 {
|
|
||||||
}
|
|
||||||
} catch (ClientProtocolException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return new JSONArray(builder.toString());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue