Browse Source

Working with new feature, some code is already adapted for this.

master
Defend 7 years ago
parent
commit
231a08c7e7
  1. 30
      app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java
  2. 9
      app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java
  3. 38
      app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java
  4. 20
      app/src/main/res/layout/cabinet_newsfeed.xml
  5. 37
      app/src/main/res/layout/cabinet_newsfeed_floatingitem.xml

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

@ -6,6 +6,7 @@ import android.content.Intent;
import android.graphics.Bitmap; import android.graphics.Bitmap;
import android.graphics.BitmapFactory; import android.graphics.BitmapFactory;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle; import android.os.Bundle;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.design.widget.FloatingActionButton; import android.support.design.widget.FloatingActionButton;
@ -31,10 +32,13 @@ import android.widget.ArrayAdapter;
import android.widget.ImageView; import android.widget.ImageView;
import android.widget.LinearLayout; import android.widget.LinearLayout;
import android.widget.ListView; import android.widget.ListView;
import android.widget.PopupWindow;
import android.widget.RelativeLayout; import android.widget.RelativeLayout;
import android.widget.ScrollView;
import android.widget.TextView; import android.widget.TextView;
import java.io.InputStream; import java.io.InputStream;
import java.io.StringReader;
import java.util.List; import java.util.List;
@ -48,7 +52,7 @@ public class CabinetActivity extends AppCompatActivity
public String AuthURL; public String AuthURL;
public Boolean authBegin = false; public Boolean authBegin = false;
public TextView studentName, studentGroup, studentRate, positionGroup, public TextView studentName, studentGroup, studentRate, positionGroup,
positionFaculty, newsTextView; positionFaculty;
public RelativeLayout profileLayout, journalLayout, gRateLayout, public RelativeLayout profileLayout, journalLayout, gRateLayout,
fRateLayout, aboutLayout, progressLayout, newsLayout; fRateLayout, aboutLayout, progressLayout, newsLayout;
public Toolbar myToolbar; public Toolbar myToolbar;
@ -198,6 +202,7 @@ public class CabinetActivity extends AppCompatActivity
return true; return true;
} }
if (id == R.id.action_reload_newsfeed) { if (id == R.id.action_reload_newsfeed) {
//Потом уберем :D
feedController.drawNewsList(feedController.newsItemList); feedController.drawNewsList(feedController.newsItemList);
} }
@ -304,16 +309,27 @@ public class CabinetActivity extends AppCompatActivity
} }
} }
public void addNewsItem(String title, String text, String link, Boolean LastItem) { public int addNewsItem(NewsItemList.Group group, Boolean LastItem) {
String title = group.getTitle();
String text = group.getText();
String link = group.getLink();
int viewId = group.getViewId();
LayoutInflater inflater = getLayoutInflater(); LayoutInflater inflater = getLayoutInflater();
LinearLayout newsFeed = (LinearLayout) findViewById(R.id.newsfeed_scroll); LinearLayout newsFeed = (LinearLayout) findViewById(R.id.newsfeed_scroll);
View layout = null; View layout;
if(LastItem) { if(LastItem) {
layout = inflater.inflate(R.layout.cabinet_newsfeed_lastitem, null); layout = inflater.inflate(R.layout.cabinet_newsfeed_lastitem, null);
} else { } else {
layout = inflater.inflate(R.layout.cabinet_newsfeed_item, null); layout = inflater.inflate(R.layout.cabinet_newsfeed_item, null);
} }
newsFeed.addView(layout); newsFeed.addView(layout);
layout.setId(viewId);
layout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
OnNewsItemClick(v);
}
});
TextView titleTextView = (TextView) layout.findViewById(R.id.newsfeed_item_title); TextView titleTextView = (TextView) layout.findViewById(R.id.newsfeed_item_title);
titleTextView.setText(title); titleTextView.setText(title);
@ -324,6 +340,14 @@ public class CabinetActivity extends AppCompatActivity
new DownloadImageTask((ImageView) layout.findViewById(R.id.newsfeed_item_image)) new DownloadImageTask((ImageView) layout.findViewById(R.id.newsfeed_item_image))
.execute(link); .execute(link);
} }
return layout.getId();
}
public void OnNewsItemClick(View v) {
Log.i("View Id", Integer.toString(v.getId()));
// RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.newsfeeder);
// View layout = getLayoutInflater().inflate(R.layout.cabinet_newsfeed_floatingitem, relativeLayout, false);
// relativeLayout.addView(layout);
} }
public void clearNewsFeed() { public void clearNewsFeed() {

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

@ -73,22 +73,19 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par
} }
}); });
for (int i = 0; i < newsItemList.size(); i++) { for (int i = 0; i < newsItemList.size(); i++) {
NewsItemList.Group item = newsItemList.get(i); final NewsItemList.Group item = newsItemList.get(i);
final String title = item.getTitle();
final String text = item.getText();
final String link = item.getLink();
if(i < newsItemList.size() - 1) { if(i < newsItemList.size() - 1) {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
activity.addNewsItem(title, text, link, false); activity.addNewsItem(item, false);
} }
}); });
} else { } else {
activity.runOnUiThread(new Runnable() { activity.runOnUiThread(new Runnable() {
@Override @Override
public void run() { public void run() {
activity.addNewsItem(title, text, link, true); activity.addNewsItem(item, true);
} }
}); });
} }

38
app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java

@ -1,6 +1,11 @@
package ru.defend.defdevteam.tstu; package ru.defend.defdevteam.tstu;
import android.os.Build;
import android.util.Log;
import android.view.View;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.ListIterator; import java.util.ListIterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
@ -12,9 +17,11 @@ import java.util.NoSuchElementException;
public class NewsItemList { public class NewsItemList {
private ArrayList<Group> list; private ArrayList<Group> list;
private HashMap<Integer, Integer> hashMap;
NewsItemList() { NewsItemList() {
list = new ArrayList<>(); list = new ArrayList<>();
hashMap = new HashMap<>();
} }
public int size() { public int size() {
@ -27,14 +34,21 @@ public class NewsItemList {
public void add(Group group) { public void add(Group group) {
this.list.add(group); this.list.add(group);
this.hashMap.put(group.getViewId(), this.list.size());
} }
//
public void set(int index, Group group) { // public void set(int index, Group group) {
this.list.set(index, group); // this.list.set(index, group);
} // this.hashMap.keySet(group.getViewId(), this.list.size());
// }
public void clear() { public void clear() {
this.list.clear(); this.list.clear();
this.hashMap.clear();
}
public Group getGroupByViewId(int viewId) {
return this.list.get(this.hashMap.get(viewId));
} }
// @Override // @Override
@ -71,11 +85,19 @@ public class NewsItemList {
private String title; private String title;
private String text; private String text;
private String link; private String link;
private Integer viewId;
private String fullText;
Group(String title, String text, String link) { Group(String title, String text, String link) {
this.title = title; this.title = title;
this.text = text; this.text = text;
this.link = link; this.link = link;
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
this.viewId = View.generateViewId();
Log.i("Generated view id", Integer.toString(viewId));
} else {
this.viewId = -1;
}
} }
public String getTitle() { public String getTitle() {
@ -90,6 +112,14 @@ public class NewsItemList {
return this.link; return this.link;
} }
public int getViewId() {
return this.viewId;
}
public void setFullText(String fullText) {
this.fullText = fullText;
}
} }

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

@ -8,7 +8,8 @@
<ScrollView <ScrollView
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:id="@+id/nav_newsfeed"> android:id="@+id/nav_newsfeed"
android:overScrollMode="always">
<LinearLayout <LinearLayout
android:orientation="vertical" android:orientation="vertical"
@ -22,21 +23,8 @@
<RelativeLayout <RelativeLayout
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent"> android:layout_height="match_parent"
android:id="@+id/newsfeeder">
<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"
android:visibility="invisible"/>
</RelativeLayout> </RelativeLayout>
</RelativeLayout> </RelativeLayout>

37
app/src/main/res/layout/cabinet_newsfeed_floatingitem.xml

@ -0,0 +1,37 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:alpha="0.4"
android:background="@android:color/darker_gray">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/background_light"
android:layout_margin="25dp"
android:alpha="1">
<TextView
android:text="TextView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:textAppearance="@style/TextAppearance.AppCompat.Headline"
android:paddingBottom="10dp"
android:paddingTop="10dp"
android:gravity="center_horizontal"
android:alpha="1"
android:background="@android:color/background_light" />
</RelativeLayout>
</FrameLayout>
</LinearLayout>
Loading…
Cancel
Save