From 6026a51cc55601a42ea7de3d916adeef4c26c21e Mon Sep 17 00:00:00 2001 From: RadiationG0D Date: Mon, 2 Dec 2013 00:21:10 +0100 Subject: [PATCH] Final updates for release --- Alleinfo/res/layout/detailview.xml | 6 +- Alleinfo/src/com/alleit/alleinfo/Home.java | 124 ++++++++++++------ .../com/alleit/alleinfo/NewsFeedAdapter.java | 12 +- Alleinfo/src/com/alleit/alleinfo/Webber.java | 94 +++++++------ library/bin/library.jar | Bin 49617 -> 49617 bytes 5 files changed, 156 insertions(+), 80 deletions(-) diff --git a/Alleinfo/res/layout/detailview.xml b/Alleinfo/res/layout/detailview.xml index d4b849f..bd79261 100644 --- a/Alleinfo/res/layout/detailview.xml +++ b/Alleinfo/res/layout/detailview.xml @@ -62,12 +62,12 @@ - + android:layout_below="@+id/top" + android:background="#FFFFFF" /> temp = Arrays.asList(Webber.getTinyNewsFeed()); + + if (temp.isEmpty()) { + listData = new NewsInfo[0]; + } else { + int i = 0; + listData = new NewsInfo[temp.size()]; + for (NewsInfo NI : temp) { + listData[i] = NI; + i++; + } + } runOnUiThread(new Runnable() { public void run() { - if(listData.length == 0) - { + if (listData.length == 0) { listData = new NewsInfo[1]; listData[0] = new NewsInfo(); listData[0].headline = "Inga nyheter hittades"; @@ -636,7 +661,7 @@ public void onItemClick(AdapterView parent, View view, if (listData[position].contentType == 1) { makeNews(); } else { - if(listData[position].contentType != -1) + if (listData[position].contentType != -1) ShowSpecNews(listData[position].uniqeIdentifier); } } @@ -648,12 +673,23 @@ public void onItemClick(AdapterView parent, View view, @Override public void run() { - listData = Webber.getNews("", Mode.All); + List temp = Arrays.asList(Webber.getNews("", + Mode.All)); + + if (temp.isEmpty()) { + listData = new NewsInfo[0]; + } else { + int i = 0; + listData = new NewsInfo[temp.size()]; + for (NewsInfo NI : temp) { + listData[i] = NI; + i++; + } + } runOnUiThread(new Runnable() { public void run() { - if(listData.length == 0) - { + if (listData.length == 0) { listData = new NewsInfo[1]; listData[0] = new NewsInfo(); listData[0].headline = "Inga nyheter hittades"; @@ -689,7 +725,19 @@ private void ShowSpecNews(final String uniqeIdentifier) { @Override public void run() { - listData = Webber.getNews(uniqeIdentifier, Mode.Specific); + List temp = Arrays.asList(Webber.getNews( + uniqeIdentifier, Mode.Specific)); + + if (temp.isEmpty()) { + listData = new NewsInfo[0]; + } else { + int i = 0; + listData = new NewsInfo[temp.size()]; + for (NewsInfo NI : temp) { + listData[i] = NI; + i++; + } + } runOnUiThread(new Runnable() { public void run() { @@ -698,7 +746,7 @@ public void run() { } else { Toast.makeText( getApplicationContext(), - Html.fromHtml("Nyheten kunde inte hittas.
Laddar om"), + Html.fromHtml("Nyheten kunde inte hittas."), Toast.LENGTH_SHORT).show(); prepFeed(); } diff --git a/Alleinfo/src/com/alleit/alleinfo/NewsFeedAdapter.java b/Alleinfo/src/com/alleit/alleinfo/NewsFeedAdapter.java index ce8f7b0..79827d4 100644 --- a/Alleinfo/src/com/alleit/alleinfo/NewsFeedAdapter.java +++ b/Alleinfo/src/com/alleit/alleinfo/NewsFeedAdapter.java @@ -41,6 +41,16 @@ public View getView(int position, View convertView, ViewGroup parent) { TextView handler = (TextView) rowView.findViewById(R.id.handler); handler.setText(datas[position].handler); + if (datas[position].handler != null) { + checkColor(handler, position); + } else { + handler.setTextColor(Color.BLACK); + } + + return rowView; + } + + private void checkColor(TextView handler, int position) { if (datas[position].handler.contains(Html.fromHtml(Karlista.Ename) .toString().toUpperCase(Locale.ENGLISH))) { handler.setTextColor(Color.parseColor(Karlista.Ecolor)); @@ -72,7 +82,5 @@ public View getView(int position, View convertView, ViewGroup parent) { } else { handler.setTextColor(Color.BLACK); } - - return rowView; } } \ No newline at end of file diff --git a/Alleinfo/src/com/alleit/alleinfo/Webber.java b/Alleinfo/src/com/alleit/alleinfo/Webber.java index a30d314..d72346b 100644 --- a/Alleinfo/src/com/alleit/alleinfo/Webber.java +++ b/Alleinfo/src/com/alleit/alleinfo/Webber.java @@ -1,6 +1,8 @@ package com.alleit.alleinfo; +import java.util.Arrays; import java.util.Calendar; +import java.util.List; import org.apache.http.HttpEntity; import org.apache.http.HttpHost; @@ -12,6 +14,7 @@ import android.content.Context; import android.graphics.Point; +import android.text.Html; public class Webber { @@ -152,25 +155,32 @@ public static NewsInfo[] getTinyNewsFeed() { // for each new feed update NewsInfo data = null; - feed = new NewsInfo[3]; - NewsInfo[] temp = getNews("", Mode.All); - - if(temp.length == 0) - return new NewsInfo[0]; - - for (int i = 0; i < 2; i++) { - feed[i] = temp[i]; - } + List temp = Arrays.asList(getNews("", Mode.All)); - // news info, show more news - data = new NewsInfo(); - data.headline = "Fler nyheter..."; - data.type = null; - data.handler = null; - data.contentType = 1; - data.uniqeIdentifier = null; - feed[2] = data; + if (temp.isEmpty()) + return new NewsInfo[0]; + if (temp.size() > 2) { + feed = new NewsInfo[3]; + feed[0] = temp.get(0); + feed[1] = temp.get(1); + + // news info, show more news + data = new NewsInfo(); + data.headline = "Fler nyheter..."; + data.type = null; + data.handler = null; + data.contentType = 1; + data.uniqeIdentifier = null; + feed[2] = data; + } else { + int i = 0; + feed = new NewsInfo[temp.size()]; + for (NewsInfo NI : temp) { + feed[i] = NI; + i++; + } + } // return value return feed; } @@ -188,32 +198,35 @@ public static NewsInfo[] getNews(String uniqeIdentifier, Mode returnMode) { HttpEntity entity = response.getEntity(); htmlResponse = EntityUtils.toString(entity); } catch (Exception e) { - e.printStackTrace(); return new NewsInfo[0]; } - if(htmlResponse.contains(",") == false) - { + if (htmlResponse.contains("~") == false) { return new NewsInfo[0]; } - String[] delimitered = htmlResponse.split(","); + String[] delimitered = htmlResponse.split("~"); + if (returnMode == Mode.All) { NewsInfo[] data = new NewsInfo[delimitered.length / 7]; - for (int i = 0, x = 0; i < delimitered.length; i++) { + for (int i = 0, x = 0; i < data.length; i++) { data[i] = new NewsInfo(); - data[i].headline = delimitered[x]; + data[i].headline = String + .valueOf(Html.fromHtml(delimitered[x])); x++; - data[i].description = delimitered[x]; + data[i].description = String.valueOf(Html + .fromHtml(delimitered[x])); x++; - data[i].longDescription = delimitered[x]; + data[i].longDescription = String.valueOf(Html + .fromHtml(delimitered[x])); x++; - data[i].butURL = delimitered[x]; + data[i].butURL = String.valueOf(Html.fromHtml(delimitered[x])); x++; - data[i].type = delimitered[x]; + data[i].type = String.valueOf(Html.fromHtml(delimitered[x])); x++; - data[i].handler = delimitered[x]; + data[i].handler = String.valueOf(Html.fromHtml(delimitered[x])); x++; - data[i].uniqeIdentifier = delimitered[x]; + data[i].uniqeIdentifier = String.valueOf(Html + .fromHtml(delimitered[x])); x++; data[i].contentType = 0; } @@ -226,16 +239,23 @@ public static NewsInfo[] getNews(String uniqeIdentifier, Mode returnMode) { private static NewsInfo[] extractSpecificNews(String uniqeIdentifier, String[] delimitered) { for (int i = 6; i < delimitered.length; i += 7) { - if (delimitered[i].contains("uniqeIdentifier")) { + if (delimitered[i].contains(uniqeIdentifier)) { NewsInfo[] data = new NewsInfo[1]; data[0] = new NewsInfo(); - data[0].headline = delimitered[i - 6]; - data[0].description = delimitered[i - 5]; - data[0].longDescription = delimitered[i - 4]; - data[0].butURL = delimitered[i - 3]; - data[0].type = delimitered[i - 2]; - data[0].handler = delimitered[i - 1]; - data[0].uniqeIdentifier = delimitered[i]; + data[0].headline = String.valueOf(Html + .fromHtml(delimitered[i - 6])); + data[0].description = String.valueOf(Html + .fromHtml(delimitered[i - 5])); + data[0].longDescription = String.valueOf(Html + .fromHtml(delimitered[i - 4])); + data[0].butURL = String.valueOf(Html + .fromHtml(delimitered[i - 3])); + data[0].type = String + .valueOf(Html.fromHtml(delimitered[i - 2])); + data[0].handler = String.valueOf(Html + .fromHtml(delimitered[i - 1])); + data[0].uniqeIdentifier = String.valueOf(Html + .fromHtml(delimitered[i])); data[0].contentType = 0; return data; } diff --git a/library/bin/library.jar b/library/bin/library.jar index 9b9e5241dfedb5b19ef2dac360f5b5b7ea0b3ac3..d51d6d50d3ed6387d61af7d620b45ead926ea58c 100644 GIT binary patch delta 670 zcmY+8OG`pg6ou8RcA+GthZPkyi3SA{*)R%w;y@{C)`N@rC||cC2%^A-fl{Y54Ge;C z5D0bD%vbgUimYKE1>vZHLO-C|`wnvSvDR68ty9=%3j2)0sAr^&B9>)E2C?T*G0FUb z@HQ=R#apj0PsRT=^-8|}8(s88I>l5a)>w75@mkwjWsqW`hK|)6C4Xl$ph`*MUehv8 zgU!d#PBkqD_?&B-M@QYRM`xw;qZclxCp}HL%xTF)s)05yTnT^UMyYJc2CJ0kIGpc} zYKbykN7ZHqV`V=WWYJQBp3tg}EL&v6ov9~b>obh-wjSIMt@h$oK!r7Oy8}P8<+R|^ zJMZp*qgh`;291@-2+;&s>N?rQma_j1kDh|VEJVuw5o)+NhdixB`sL8j9W7#mB&LJd zRLliT3G9ob4hvK!P{GRXg{IXkYc8jeZwXpJ98OL!lNk;szo{68|wS% zvE~5UsiA%wpHq#K=xCcP=-696+Te0{aI+4Vc@r5BYp7=GQu-U;OBFLNSfv8b}PTgp2t#FU^L|f>eBPT-89xPnFY{G8Ps1He4lt&`vo>h B2!j9s