diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java b/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java index 406465e..1d27485 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java +++ b/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; } diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java b/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java index c815167..5b96e7c 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java +++ b/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 diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java b/app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java index 8a0bed8..0069a1d 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java +++ b/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 = ""; + String b = ""; + 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(); } } diff --git a/app/src/main/res/layout/cabinet_newsfeed.xml b/app/src/main/res/layout/cabinet_newsfeed.xml index bdf3269..7390837 100644 --- a/app/src/main/res/layout/cabinet_newsfeed.xml +++ b/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"/> \ No newline at end of file diff --git a/app/src/main/res/layout/cabinet_newsfeed_item.xml b/app/src/main/res/layout/cabinet_newsfeed_item.xml index ca0a262..6cd7b61 100644 --- a/app/src/main/res/layout/cabinet_newsfeed_item.xml +++ b/app/src/main/res/layout/cabinet_newsfeed_item.xml @@ -1,21 +1,16 @@ @@ -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"/> + android:layout_height="match_parent" + android:adjustViewBounds="true" + android:scaleType="fitXY" + android:id="@+id/newsfeed_item_image" /> diff --git a/app/src/main/res/layout/cabinet_newsfeed_lastitem.xml b/app/src/main/res/layout/cabinet_newsfeed_lastitem.xml index 4ce9dc0..6c60202 100644 --- a/app/src/main/res/layout/cabinet_newsfeed_lastitem.xml +++ b/app/src/main/res/layout/cabinet_newsfeed_lastitem.xml @@ -1,20 +1,16 @@ @@ -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"/> + android:layout_height="match_parent" + android:adjustViewBounds="true" + android:scaleType="fitXY" + android:id="@+id/newsfeed_item_image" />