Skip to content
Browse files

Completely new theme

  • Loading branch information...
1 parent 220df8d commit 91a400e7b5bd121254ab6415c82a2d1f60835b49 @amir amir committed Nov 10, 2010
View
5 AndroidManifest.xml
@@ -1,7 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
- package="com.gluegadget.hndroid" android:versionName="0.1" android:versionCode="1">
- <application android:icon="@drawable/icon" android:label="@string/app_name">
+ package="com.gluegadget.hndroid" android:versionName="0.2" android:versionCode="2">
+ <application android:icon="@drawable/icon" android:label="@string/app_name"
+ android:theme="@android:style/Theme.Light.NoTitleBar">
<activity android:name=".Main" android:label="@string/app_name"
android:configChanges="orientation">
<intent-filter>
View
BIN res/drawable-mdpi/comments.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
42 res/layout/comments_list_item.xml
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="6dip">
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/author"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_below="@+id/title"
+ android:layout_alignLeft="@id/title"
+ android:layout_alignParentBottom="true"
+ android:layout_toLeftOf="@+id/score"
+ android:gravity="bottom"
+ android:textColor="#424142"
+ />
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@id/title"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="top"
+ android:textColor="#424142"
+ android:autoLink="web"
+ android:minHeight="43dip"
+ android:textStyle="bold"
+ android:layout_alignParentTop="true"
+
+ />
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@id/score"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_alignParentRight="true"
+ android:layout_alignBaseline="@id/author"
+ android:textColor="#8C8E8C"
+ />
+
+</RelativeLayout>
View
42 res/layout/main.xml
@@ -4,9 +4,41 @@
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
-<ListView
- android:id="@+id/hnListView"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content"
+
+ <LinearLayout
+ android:id="@+id/hnTop"
+ android:layout_height="60dip"
+ android:layout_width="fill_parent"
+ android:background="#FF6600"
+ android:layout_above="@+id/hnListView"
+ android:orientation="vertical">
+
+ <TextView
+ android:id="@+id/hnTopTitle"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:gravity="center_vertical"
+ android:paddingLeft="10dip"
+ android:paddingTop="10dip"
+ android:textStyle="bold"
+ android:text="Hacker News"
+ />
+
+ <TextView
+ android:id="@+id/hnTopDesc"
+ android:layout_width="fill_parent"
+ android:layout_height="wrap_content"
+ android:paddingLeft="10dip"
+ android:text="News"
+ android:singleLine="true"
+ android:ellipsize="end"
+ />
+
+ </LinearLayout>
+
+ <ListView
+ android:id="@+id/hnListView"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
/>
-</LinearLayout>
+</LinearLayout>
View
56 res/layout/news_list_item.xml
@@ -0,0 +1,56 @@
+<?xml version="1.0" encoding="utf-8"?>
+<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:padding="6dip">
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/comments"
+ android:layout_width="51dip"
+ android:layout_height="48dip"
+ android:background="@drawable/comments"
+ android:layout_alignParentTop="true"
+ android:layout_marginRight="6dip"
+ android:paddingTop="9dip"
+ android:gravity="center_horizontal"
+ android:textStyle="bold"
+ />
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@+id/author"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_below="@+id/title"
+ android:layout_alignLeft="@id/title"
+ android:layout_alignParentBottom="true"
+ android:layout_toLeftOf="@+id/score"
+ android:layout_toRightOf="@+id/comments"
+ android:gravity="bottom"
+ android:textColor="#424142"
+ />
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@id/title"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:textAppearance="?android:attr/textAppearanceMedium"
+ android:gravity="top"
+ android:textColor="#424142"
+ android:autoLink="web"
+ android:minHeight="43dip"
+ android:textStyle="bold"
+ android:layout_toRightOf="@+id/comments"
+ android:layout_alignParentTop="true"
+
+ />
+
+ <TextView xmlns:android="http://schemas.android.com/apk/res/android"
+ android:id="@id/score"
+ android:layout_width="wrap_content"
+ android:layout_height="fill_parent"
+ android:layout_alignParentRight="true"
+ android:layout_alignBaseline="@id/author"
+ android:textColor="#8C8E8C"
+ />
+
+</RelativeLayout>
View
2 src/com/gluegadget/hndroid/Comment.java
@@ -55,6 +55,6 @@ public String getUpVoteUrl() {
@Override
public String toString() {
- return "";
+ return author + ": " + title;
}
}
View
6 src/com/gluegadget/hndroid/Comments.java
@@ -32,6 +32,7 @@
import android.view.ContextMenu.ContextMenuInfo;
import android.view.MenuItem.OnMenuItemClickListener;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
public class Comments extends Activity {
@@ -67,13 +68,14 @@ public void onCreate(Bundle savedInstanceState) {
newsListView = (ListView)this.findViewById(R.id.hnListView);
registerForContextMenu(newsListView);
- int layoutID = R.layout.simple_list_item_1;
+ int layoutID = R.layout.comments_list_item;
aa = new CommentsAdapter(this, layoutID , commentsList);
newsListView.setAdapter(aa);
final Bundle extras = getIntent().getExtras();
extrasCommentsUrl = extras.getString("url");
- setTitle(extras.getString("title"));
+ TextView hnTopDesc = (TextView)this.findViewById(R.id.hnTopDesc);
+ hnTopDesc.setText(extras.getString("title"));
dialog = ProgressDialog.show(Comments.this, "", "Loading. Please wait...", true);
new Thread(new Runnable(){
public void run() {
View
12 src/com/gluegadget/hndroid/Main.java
@@ -67,12 +67,9 @@
static final private int NOTIFY_DATASET_CHANGED = 1;
static final private int LOGIN_FAILED = 2;
static final private int LOGIN_SUCCESSFULL = 3;
-
-
static int DEFAULT_ACTION_PREFERENCES = 0;
-
String loginUrl;
ProgressDialog dialog;
@@ -91,7 +88,7 @@ public void onCreate(Bundle savedInstanceState) {
newsListView = (ListView)this.findViewById(R.id.hnListView);
registerForContextMenu(newsListView);
- int layoutID = R.layout.simple_list_item_1;
+ int layoutID = R.layout.news_list_item;
aa = new NewsAdapter(this, layoutID , news);
newsListView.setAdapter(aa);
newsListView.setOnItemClickListener(clickListener);
@@ -111,6 +108,7 @@ public void handleMessage(Message msg) {
switch(msg.what){
case NOTIFY_DATASET_CHANGED:
aa.notifyDataSetChanged();
+ newsListView.setSelection(0);
break;
case LOGIN_FAILED:
Toast.makeText(Main.this, "Login failed :(", Toast.LENGTH_LONG).show();
@@ -453,6 +451,7 @@ private void refreshNews(String newsUrl) {
Object[] newsTitles = node.evaluateXPath("//td[@class='title']/a[1]");
Object[] scores = node.evaluateXPath("//td[@class='subtext']/span");
Object[] authors = node.evaluateXPath("//td[@class='subtext']/a[1]");
+ Object[] comments = node.evaluateXPath("//td[@class='subtext']/a[2]");
Object[] domains = node.evaluateXPath("//span[@class='comhead']");
Object[] loginFnid = node.evaluateXPath("//span[@class='pagetop']/a");
TagNode loginNode = (TagNode) loginFnid[5];
@@ -467,6 +466,7 @@ private void refreshNews(String newsUrl) {
for (int i = 0; i < newsTitles.length; i++) {
String scoreValue = "";
String authorValue = "";
+ String commentValue = "";
String domainValue = "";
String commentsUrl = "";
String upVoteUrl = "";
@@ -478,6 +478,7 @@ private void refreshNews(String newsUrl) {
if (i < scores.length) {
TagNode score = (TagNode)scores[i];
TagNode author = (TagNode)authors[i];
+ TagNode comment = (TagNode)comments[i];
TagNode userNode = newsTitle.getParent().getParent();
Object[] upVotes = userNode.evaluateXPath("//td/center/a[1]");
if (upVotes.length > 0) {
@@ -491,6 +492,7 @@ private void refreshNews(String newsUrl) {
scoreValue = score.getChildren().iterator().next().toString().trim();
authorValue = author.getChildren().iterator().next().toString().trim();
+ commentValue = comment.getChildren().iterator().next().toString().trim();
if (href.startsWith("http")) {
TagNode domain = (TagNode)domains[j];
@@ -499,7 +501,7 @@ private void refreshNews(String newsUrl) {
}
}
- News newsEntry = new News(title, scoreValue, authorValue, domainValue, href, commentsUrl, upVoteUrl);
+ News newsEntry = new News(title, scoreValue, commentValue, authorValue, domainValue, href, commentsUrl, upVoteUrl);
news.add(newsEntry);
}
}
View
20 src/com/gluegadget/hndroid/News.java
@@ -5,14 +5,16 @@
private String title;
private String author;
private String score;
+ private String comment;
private String url;
private String domain;
private String commentsUrl;
private String upVoteUrl;
- public News(String _title, String _score, String _author, String _domain, String _url, String _commentsUrl, String _upVoteUrl) {
+ public News(String _title, String _score, String _comment, String _author, String _domain, String _url, String _commentsUrl, String _upVoteUrl) {
title = _title;
score = _score;
+ comment = _comment;
author = _author;
url = _url;
if (_commentsUrl.length() > 7)
@@ -32,7 +34,7 @@ public News(String _title, String _score, String _author, String _domain, String
}
public News(String _title) {
- this(_title, "", "", "", "", "", "");
+ this(_title, "", "", "", "", "", "", "");
}
public String getCommentsUrl() {
@@ -47,6 +49,20 @@ public String getScore() {
return score;
}
+ public String getComment() {
+ String returnValue = "";
+ if (comment.contains("discuss")) {
+ returnValue = "0";
+ } else {
+ String tmp = comment.replaceAll("comments?", "");
+ if (tmp.length() == 0)
+ returnValue = "?";
+ else
+ returnValue = tmp;
+ }
+
+ return returnValue;
+ }
public String getAuthor() {
return author;
}
View
3 src/com/gluegadget/hndroid/NewsAdapter.java
@@ -22,6 +22,7 @@ public NewsAdapter(Context _context, int _resource, List<News> _items) {
static class ViewHolder {
TextView title;
TextView score;
+ TextView comment;
TextView author;
}
@@ -36,6 +37,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder = new ViewHolder();
holder.title = (TextView)convertView.findViewById(R.id.title);
holder.score = (TextView)convertView.findViewById(R.id.score);
+ holder.comment = (TextView)convertView.findViewById(R.id.comments);
holder.author = (TextView)convertView.findViewById(R.id.author);
convertView.setTag(holder);
} else {
@@ -44,6 +46,7 @@ public View getView(int position, View convertView, ViewGroup parent) {
holder.title.setText(item.getTitle());
holder.score.setText(item.getScore());
+ holder.comment.setText(item.getComment());
if (item.getAuthor() == "")
holder.author.setText(item.getAuthor());
View
12 src/com/gluegadget/hndroid/Submissions.java
@@ -29,6 +29,7 @@
import android.view.MenuItem.OnMenuItemClickListener;
import android.widget.AdapterView;
import android.widget.ListView;
+import android.widget.TextView;
import android.widget.AdapterView.AdapterContextMenuInfo;
import android.widget.AdapterView.OnItemClickListener;
@@ -58,13 +59,14 @@ public void onCreate(Bundle savedInstanceState) {
newsListView = (ListView)this.findViewById(R.id.hnListView);
registerForContextMenu(newsListView);
- int layoutID = R.layout.simple_list_item_1;
+ int layoutID = R.layout.news_list_item;
aa = new NewsAdapter(this, layoutID , news);
newsListView.setAdapter(aa);
newsListView.setOnItemClickListener(clickListener);
final Bundle extras = getIntent().getExtras();
- setTitle(extras.getString("title"));
+ TextView hnTopDesc = (TextView)this.findViewById(R.id.hnTopDesc);
+ hnTopDesc.setText(extras.getString("title"));
dialog = ProgressDialog.show(Submissions.this, "", "Loading. Please wait...", true);
new Thread(new Runnable(){
public void run() {
@@ -210,6 +212,7 @@ private void refreshNews(String newsUrl) {
Object[] newsTitles = node.evaluateXPath("//td[@class='title']/a");
Object[] scores = node.evaluateXPath("//td[@class='subtext']/span");
Object[] authors = node.evaluateXPath("//td[@class='subtext']/a[1]");
+ Object[] comments = node.evaluateXPath("//td[@class='subtext']/a[2]");
Object[] domains = node.evaluateXPath("//span[@class='comhead']");
Object[] loginFnid = node.evaluateXPath("//span[@class='pagetop']/a");
TagNode loginNode = (TagNode) loginFnid[5];
@@ -220,6 +223,7 @@ private void refreshNews(String newsUrl) {
for (int i = 0; i < newsTitles.length; i++) {
String scoreValue = "";
String authorValue = "";
+ String commentValue = "";
String domainValue = "";
String commentsUrl = "";
String upVoteUrl = "";
@@ -231,6 +235,7 @@ private void refreshNews(String newsUrl) {
if (i < scores.length) {
TagNode score = (TagNode)scores[i];
TagNode author = (TagNode)authors[i];
+ TagNode comment = (TagNode)comments[i];
TagNode userNode = newsTitle.getParent().getParent();
Object[] upVotes = userNode.evaluateXPath("//td/center/a[1]");
if (upVotes.length > 0) {
@@ -244,6 +249,7 @@ private void refreshNews(String newsUrl) {
scoreValue = score.getChildren().iterator().next().toString().trim();
authorValue = author.getChildren().iterator().next().toString().trim();
+ commentValue = comment.getChildren().iterator().next().toString().trim();
if (href.startsWith("http")) {
TagNode domain = (TagNode)domains[j];
@@ -252,7 +258,7 @@ private void refreshNews(String newsUrl) {
}
}
- News newsEntry = new News(title, scoreValue, authorValue, domainValue, href, commentsUrl, upVoteUrl);
+ News newsEntry = new News(title, scoreValue, commentValue, authorValue, domainValue, href, commentsUrl, upVoteUrl);
news.add(newsEntry);
}
}

0 comments on commit 91a400e

Please sign in to comment.
Something went wrong with that request. Please try again.