Browse Source

Finally added images on news feed. Little view fixes for news feed.

master
Defend 8 years ago
parent
commit
40a2930689
  1. 9
      app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java
  2. 26
      app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java
  3. 33
      app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java
  4. 3
      app/src/main/res/layout/cabinet_newsfeed.xml
  5. 22
      app/src/main/res/layout/cabinet_newsfeed_item.xml
  6. 22
      app/src/main/res/layout/cabinet_newsfeed_lastitem.xml

9
app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java

@ -281,6 +281,7 @@ public class CabinetActivity extends AppCompatActivity
protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0];
Log.i("DownloadImageTask", urldisplay);
Bitmap mIcon11 = null;
try {
InputStream in = new java.net.URL(urldisplay).openStream();
@ -289,6 +290,14 @@ public class CabinetActivity extends AppCompatActivity
Log.e("Error", e.getMessage());
e.printStackTrace();
}
if(mIcon11.getWidth() > 4096 || mIcon11.getHeight() > 4096) {
mIcon11 = Bitmap.createScaledBitmap(
mIcon11,
mIcon11.getWidth()/2,
mIcon11.getHeight()/2,
false
);
}
return mIcon11;
}

26
app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java

@ -8,6 +8,7 @@ package ru.defend.defdevteam.tstu;
public class FeedController implements FeedReader.ReaderCallback, FeedParser.ParserCallback{
private FeedReader feedReader;
private FeedParser parser;
private FeedUpdater feedUpdater;
NewsItemList newsItemList;
private int updateRate; //in minutes
@ -18,12 +19,14 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
}
FeedController(CabinetActivity activity, int updateRate, String rssUrl) {
this.activity = activity;
this.updateRate = updateRate;
feedReader = new FeedReader(this, rssUrl);
feedReader.registerCallback(this);
newsItemList = new NewsItemList();
feedUpdater = new FeedUpdater();
this.activity = activity;
this.updateRate = updateRate;
parser = new FeedParser();
feedReader.registerCallback(this);
parser.registerCallback(this);
feedUpdater.start();
}
@ -38,17 +41,6 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
}
}
private boolean checkFeedReader() throws Exception{
switch (feedReader.getThreadState()) {
case THREAD_COMPLETE:
return true;
case THREAD_NULL:
return false;
default:
throw new Exception("Failed to get rss source string from FeedReader class");
}
}
private class FeedUpdater extends Thread {
@Override
public void run() {
@ -105,9 +97,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
@Override
public void onSuccess(final String result){
FeedParser parser = new FeedParser(result);
parser.registerCallback(this);
parser.parseXML();
parser.parseXML(result);
}
@Override
@ -122,7 +112,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
@Override
public void onFailureParsing() {
//Ill add this code later!
}
@Override

33
app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java

@ -29,18 +29,12 @@ public class FeedParser {
this.callback = callback;
}
FeedParser(String inputXML) {
this.inputXML = inputXML;
}
FeedParser() {}
// static NewsItemList.Group parsedItem;
// static void getParsedItem(String title, String description, String link, String date) {
// parsedItem = new NewsItemList().new Group(title, description, date);
// this.callback.contentDispatcher();
// }
void parseXML() {
void parseXML(String inputXML) {
try {
this.inputXML = inputXML;
SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser();
ExtendedHandler handler = new ExtendedHandler();
@ -64,6 +58,22 @@ public class FeedParser {
return Line;
}
public String getImageLink(String Line){
String a = "<img src=\"";
String b = "\" border=\"0\"";
Line = Line.substring(Line.indexOf(a)+ a.length());
Line = Line.substring(0, Line.indexOf(b));
return Line;
}
public String getDescriptionShort(String Line){
String a = "<div class=\"K2FeedIntroText\">";
String b = "</div>";
Line = Line.substring(Line.indexOf(a)+ a.length());
Line = Line.substring(0, Line.indexOf(b));
return deleteHtmlTag(Line, "<", ">");
}
public class ExtendedHandler extends DefaultHandler {
boolean item = false;
@ -116,8 +126,9 @@ public class FeedParser {
public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("item") && item) {
item = false;
descriptionStr = deleteHtmlTag(descriptionStr, "<", ">");
callback.contentDispatcher(titleStr, descriptionStr, "");
String imageLink = getImageLink(descriptionStr);
descriptionStr = getDescriptionShort(descriptionStr);
callback.contentDispatcher(titleStr, descriptionStr, imageLink);
refreshStrings();
}
}

3
app/src/main/res/layout/cabinet_newsfeed.xml

@ -35,7 +35,8 @@
android:layout_marginEnd="21dp"
android:layout_marginBottom="16dp"
android:id="@+id/updateBtnNewsFeed"
android:onClick="onClickButtonNewsFeed" />
android:onClick="onClickButtonNewsFeed"
android:visibility="invisible"/>
</RelativeLayout>
</RelativeLayout>

22
app/src/main/res/layout/cabinet_newsfeed_item.xml

@ -1,21 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/cabinet_newsfeed"
android:background="@android:color/darker_gray">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:layout_marginBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
@ -23,19 +18,26 @@
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:layout_marginLeft="5dp"
android:textAppearance="@style/TextAppearance.AppCompat.SearchResult.Title"
android:paddingLeft="25dp"
android:paddingRight="20dp"
android:layout_marginBottom="15dp"
android:id="@+id/newsfeed_item_title"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newsfeed_item_image"/>
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:id="@+id/newsfeed_item_image" />
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginTop="20dp"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:id="@+id/newsfeed_item_text" />

22
app/src/main/res/layout/cabinet_newsfeed_lastitem.xml

@ -1,20 +1,16 @@
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:showIn="@layout/cabinet_newsfeed"
android:background="@android:color/darker_gray">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_height="wrap_content"
android:background="@android:color/background_light"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginBottom="10dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
@ -22,19 +18,25 @@
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:layout_marginLeft="5dp"
android:textAppearance="@style/TextAppearance.AppCompat.SearchResult.Title"
android:paddingLeft="25dp"
android:paddingRight="20dp"
android:id="@+id/newsfeed_item_title"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newsfeed_item_image"/>
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:id="@+id/newsfeed_item_image" />
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:layout_marginTop="20dp"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:id="@+id/newsfeed_item_text" />

Loading…
Cancel
Save