Browse Source

Added clearNewsFeed method for clearing layout of news feed every update.

Added ...lastitem.xml - now on the end news feed looking better.
Some other visual fixes with xml's.
Rewrited drawNewsList for visual fixes.
Added refresh news feed button.
master
Defend 8 years ago
parent
commit
f04ebcb02f
  1. 1
      app/app.iml
  2. 23
      app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java
  3. 56
      app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java
  4. 18
      app/src/main/res/layout/cabinet_newsfeed.xml
  5. 3
      app/src/main/res/layout/cabinet_newsfeed_item.xml
  6. 44
      app/src/main/res/layout/cabinet_newsfeed_lastitem.xml

1
app/app.iml

@ -102,6 +102,7 @@
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/instant-run-support" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/jniLibs" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/manifests" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/pre-dexed" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/reload-dex" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/res" />
<excludeFolder url="file://$MODULE_DIR$/build/intermediates/restart-dex" />

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

@ -29,6 +29,7 @@ import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ArrayAdapter;
import android.widget.Button;
import android.widget.Chronometer;
import android.widget.ImageView;
import android.widget.LinearLayout;
@ -304,10 +305,15 @@ public class CabinetActivity extends AppCompatActivity
}
}
public void addNewsItem (String title, String text, String link) {
public void addNewsItem(String title, String text, String link, Boolean LastItem) {
LayoutInflater inflater = getLayoutInflater();
LinearLayout newsFeed = (LinearLayout) findViewById(R.id.newsfeed_scroll);
View layout = inflater.inflate(R.layout.cabinet_newsfeed_item, null);
View layout = null;
if(LastItem) {
layout = inflater.inflate(R.layout.cabinet_newsfeed_lastitem, null);
} else {
layout = inflater.inflate(R.layout.cabinet_newsfeed_item, null);
}
newsFeed.addView(layout);
TextView titleTextView = (TextView) layout.findViewById(R.id.newsfeed_item_title);
@ -320,6 +326,15 @@ public class CabinetActivity extends AppCompatActivity
.execute(link);
}
public void clearNewsFeed() {
LinearLayout newsFeedPage = (LinearLayout) findViewById(R.id.newsfeed_scroll);
try {
newsFeedPage.removeAllViews();
} catch (Exception e) {
}
}
public void loadSite (String url) {
browser.loadUrl(url);
}
@ -364,6 +379,10 @@ public class CabinetActivity extends AppCompatActivity
facultyList.setAdapter(facultyL);
}
public void onClickButtonNewsFeed(View view) {
feedController.drawNewsList(feedController.newsItemList);
}
@TargetApi(19)
public void getHTML(){
browser.evaluateJavascript("javascript:document.documentElement.outerHTML;", new ValueCallback<String>() {

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

@ -8,18 +8,17 @@ import android.util.Log;
public class FeedController implements FeedReader.ReaderCallback, FeedParser.ParserCallback{
FeedReader feedReader;
FeedUpdater feedUpdater;
String newsFeed;
private FeedReader feedReader;
private FeedUpdater feedUpdater;
NewsItemList newsItemList;
int updateRate; //in minutes
private int updateRate; //in minutes
private CabinetActivity activity;
public FeedController(CabinetActivity activity, int updateRate) {
FeedController(CabinetActivity activity, int updateRate) {
this(activity, updateRate, "http://press.tstu.ru/?format=feed");
}
public FeedController(CabinetActivity activity, int updateRate, String rssUrl) {
FeedController(CabinetActivity activity, int updateRate, String rssUrl) {
feedReader = new FeedReader(this, rssUrl);
feedReader.registerCallback(this);
newsItemList = new NewsItemList();
@ -65,7 +64,6 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
public void run() {
startFeedReader();
try {
//TODO: вернуть к норме updateRate*60*1000
sleep(updateRate*60*1000);
} catch (InterruptedException e) {
e.printStackTrace();
@ -73,18 +71,9 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
}
public FeedUpdater() {
//this.start();
}
}
// public String getRssString() throws Exception{
// if(checkFeedReader()) {
// newsFeed = feedReader.getResult();
// return newsFeed;
// }
// throw new Exception("Feed Reader returned empty string");
// }
public void addNewsList(String title, String text, String link) {
newsItemList.add(new NewsItemList().new Group(
title,
@ -93,17 +82,34 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
));
}
public void drawNewsList(NewsItemList newsItemList) {
for (NewsItemList.Group item: newsItemList) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.clearNewsFeed();
}
});
for (int i = 0; i < newsItemList.size(); i++) {
NewsItemList.Group item = newsItemList.get(i);
final String title = item.getTitle();
final String text = item.getText();
final String link = item.getLink();
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.addNewsItem(title, text, link);
}
});
if(i < newsItemList.size() - 1) {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.addNewsItem(title, text, link, false);
}
});
} else {
activity.runOnUiThread(new Runnable() {
@Override
public void run() {
activity.addNewsItem(title, text, link, true);
}
});
}
}
}
@ -119,8 +125,9 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
@Override
public void onSuccess(final String result){
this.newsFeed = result;
addNewsList("Callback Reader Test", result, "");
addNewsList("Multiple Items Test 1", result, "");
addNewsList("Multiple Items Test 2", result, "");
FeedParser parser = new FeedParser(result);
parser.registerCallback(this);
parser.parseXML();
@ -134,6 +141,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
@Override
public void onSuccessParsing() {
drawNewsList(this.newsItemList);
drawNewsList(this.newsItemList);
}
@Override

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

@ -20,4 +20,22 @@
</ScrollView>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:text="Обновить"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_marginRight="21dp"
android:layout_marginEnd="21dp"
android:layout_marginBottom="16dp"
android:id="@+id/updateBtnNewsFeed"
android:onClick="onClickButtonNewsFeed" />
</RelativeLayout>
</RelativeLayout>

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

@ -16,7 +16,8 @@
android:layout_marginBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp">
android:paddingTop="10dp"
android:paddingBottom="10dp">
<TextView
android:text=""

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

@ -0,0 +1,44 @@
<?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:background="@android:color/background_light"
android:paddingLeft="20dp"
android:paddingRight="20dp"
android:paddingTop="10dp"
android:paddingBottom="10dp">
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:layout_marginLeft="5dp"
android:id="@+id/newsfeed_item_title"/>
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/newsfeed_item_image"/>
<TextView
android:text=""
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAppearance="@android:style/TextAppearance.DeviceDefault"
android:id="@+id/newsfeed_item_text" />
</LinearLayout>
</RelativeLayout>
Loading…
Cancel
Save