Browse Source

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

master
Defend 7 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) { protected Bitmap doInBackground(String... urls) {
String urldisplay = urls[0]; String urldisplay = urls[0];
Log.i("DownloadImageTask", urldisplay);
Bitmap mIcon11 = null; Bitmap mIcon11 = null;
try { try {
InputStream in = new java.net.URL(urldisplay).openStream(); InputStream in = new java.net.URL(urldisplay).openStream();
@ -289,6 +290,14 @@ public class CabinetActivity extends AppCompatActivity
Log.e("Error", e.getMessage()); Log.e("Error", e.getMessage());
e.printStackTrace(); e.printStackTrace();
} }
if(mIcon11.getWidth() > 4096 || mIcon11.getHeight() > 4096) {
mIcon11 = Bitmap.createScaledBitmap(
mIcon11,
mIcon11.getWidth()/2,
mIcon11.getHeight()/2,
false
);
}
return mIcon11; 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{ public class FeedController implements FeedReader.ReaderCallback, FeedParser.ParserCallback{
private FeedReader feedReader; private FeedReader feedReader;
private FeedParser parser;
private FeedUpdater feedUpdater; private FeedUpdater feedUpdater;
NewsItemList newsItemList; NewsItemList newsItemList;
private int updateRate; //in minutes private int updateRate; //in minutes
@ -18,12 +19,14 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
} }
FeedController(CabinetActivity activity, int updateRate, String rssUrl) { FeedController(CabinetActivity activity, int updateRate, String rssUrl) {
this.activity = activity;
this.updateRate = updateRate;
feedReader = new FeedReader(this, rssUrl); feedReader = new FeedReader(this, rssUrl);
feedReader.registerCallback(this);
newsItemList = new NewsItemList(); newsItemList = new NewsItemList();
feedUpdater = new FeedUpdater(); feedUpdater = new FeedUpdater();
this.activity = activity; parser = new FeedParser();
this.updateRate = updateRate; feedReader.registerCallback(this);
parser.registerCallback(this);
feedUpdater.start(); 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 { private class FeedUpdater extends Thread {
@Override @Override
public void run() { public void run() {
@ -105,9 +97,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
@Override @Override
public void onSuccess(final String result){ public void onSuccess(final String result){
FeedParser parser = new FeedParser(result); parser.parseXML(result);
parser.registerCallback(this);
parser.parseXML();
} }
@Override @Override
@ -122,7 +112,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
@Override @Override
public void onFailureParsing() { public void onFailureParsing() {
//Ill add this code later!
} }
@Override @Override

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

@ -29,18 +29,12 @@ public class FeedParser {
this.callback = callback; this.callback = callback;
} }
FeedParser(String inputXML) { FeedParser() {}
this.inputXML = inputXML;
}
// 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 { try {
this.inputXML = inputXML;
SAXParserFactory factory = SAXParserFactory.newInstance(); SAXParserFactory factory = SAXParserFactory.newInstance();
SAXParser parser = factory.newSAXParser(); SAXParser parser = factory.newSAXParser();
ExtendedHandler handler = new ExtendedHandler(); ExtendedHandler handler = new ExtendedHandler();
@ -64,6 +58,22 @@ public class FeedParser {
return Line; 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 { public class ExtendedHandler extends DefaultHandler {
boolean item = false; boolean item = false;
@ -116,8 +126,9 @@ public class FeedParser {
public void endElement(String uri, String localName, String qName) throws SAXException { public void endElement(String uri, String localName, String qName) throws SAXException {
if (qName.equalsIgnoreCase("item") && item) { if (qName.equalsIgnoreCase("item") && item) {
item = false; item = false;
descriptionStr = deleteHtmlTag(descriptionStr, "<", ">"); String imageLink = getImageLink(descriptionStr);
callback.contentDispatcher(titleStr, descriptionStr, ""); descriptionStr = getDescriptionShort(descriptionStr);
callback.contentDispatcher(titleStr, descriptionStr, imageLink);
refreshStrings(); refreshStrings();
} }
} }

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

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

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

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

Loading…
Cancel
Save