From 231a08c7e7af58e67117999e110b0fdc23b80758 Mon Sep 17 00:00:00 2001 From: Defend Date: Sat, 18 Feb 2017 00:29:10 +0300 Subject: [PATCH] Working with new feature, some code is already adapted for this. --- .../defdevteam/tstu/CabinetActivity.java | 30 +++++++++++++-- .../defdevteam/tstu/FeedController.java | 9 ++--- .../defend/defdevteam/tstu/NewsItemList.java | 38 +++++++++++++++++-- app/src/main/res/layout/cabinet_newsfeed.xml | 20 ++-------- .../layout/cabinet_newsfeed_floatingitem.xml | 37 ++++++++++++++++++ 5 files changed, 105 insertions(+), 29 deletions(-) create mode 100644 app/src/main/res/layout/cabinet_newsfeed_floatingitem.xml 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 43582a0..7ab544e 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java +++ b/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.BitmapFactory; import android.os.AsyncTask; +import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; @@ -31,10 +32,13 @@ import android.widget.ArrayAdapter; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ListView; +import android.widget.PopupWindow; import android.widget.RelativeLayout; +import android.widget.ScrollView; import android.widget.TextView; import java.io.InputStream; +import java.io.StringReader; import java.util.List; @@ -48,7 +52,7 @@ public class CabinetActivity extends AppCompatActivity public String AuthURL; public Boolean authBegin = false; public TextView studentName, studentGroup, studentRate, positionGroup, - positionFaculty, newsTextView; + positionFaculty; public RelativeLayout profileLayout, journalLayout, gRateLayout, fRateLayout, aboutLayout, progressLayout, newsLayout; public Toolbar myToolbar; @@ -198,6 +202,7 @@ public class CabinetActivity extends AppCompatActivity return true; } if (id == R.id.action_reload_newsfeed) { + //Потом уберем :D 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(); LinearLayout newsFeed = (LinearLayout) findViewById(R.id.newsfeed_scroll); - View layout = null; + View layout; if(LastItem) { layout = inflater.inflate(R.layout.cabinet_newsfeed_lastitem, null); } else { layout = inflater.inflate(R.layout.cabinet_newsfeed_item, null); } 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); titleTextView.setText(title); @@ -324,6 +340,14 @@ public class CabinetActivity extends AppCompatActivity new DownloadImageTask((ImageView) layout.findViewById(R.id.newsfeed_item_image)) .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() { 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 5b96e7c..ed88d93 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java +++ b/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++) { - NewsItemList.Group item = newsItemList.get(i); - final String title = item.getTitle(); - final String text = item.getText(); - final String link = item.getLink(); + final NewsItemList.Group item = newsItemList.get(i); if(i < newsItemList.size() - 1) { activity.runOnUiThread(new Runnable() { @Override public void run() { - activity.addNewsItem(title, text, link, false); + activity.addNewsItem(item, false); } }); } else { activity.runOnUiThread(new Runnable() { @Override public void run() { - activity.addNewsItem(title, text, link, true); + activity.addNewsItem(item, true); } }); } diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java b/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java index 635a67d..079a5ca 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java @@ -1,6 +1,11 @@ package ru.defend.defdevteam.tstu; +import android.os.Build; +import android.util.Log; +import android.view.View; + import java.util.ArrayList; +import java.util.HashMap; import java.util.Iterator; import java.util.ListIterator; import java.util.NoSuchElementException; @@ -12,9 +17,11 @@ import java.util.NoSuchElementException; public class NewsItemList { private ArrayList list; + private HashMap hashMap; NewsItemList() { list = new ArrayList<>(); + hashMap = new HashMap<>(); } public int size() { @@ -27,14 +34,21 @@ public class NewsItemList { public void add(Group group) { this.list.add(group); + this.hashMap.put(group.getViewId(), this.list.size()); } - - public void set(int index, Group group) { - this.list.set(index, group); - } +// +// public void set(int index, Group group) { +// this.list.set(index, group); +// this.hashMap.keySet(group.getViewId(), this.list.size()); +// } public void clear() { this.list.clear(); + this.hashMap.clear(); + } + + public Group getGroupByViewId(int viewId) { + return this.list.get(this.hashMap.get(viewId)); } // @Override @@ -71,11 +85,19 @@ public class NewsItemList { private String title; private String text; private String link; + private Integer viewId; + private String fullText; Group(String title, String text, String link) { this.title = title; this.text = text; 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() { @@ -90,6 +112,14 @@ public class NewsItemList { return this.link; } + public int getViewId() { + return this.viewId; + } + + public void setFullText(String fullText) { + this.fullText = fullText; + } + } diff --git a/app/src/main/res/layout/cabinet_newsfeed.xml b/app/src/main/res/layout/cabinet_newsfeed.xml index 7390837..84510e7 100644 --- a/app/src/main/res/layout/cabinet_newsfeed.xml +++ b/app/src/main/res/layout/cabinet_newsfeed.xml @@ -8,7 +8,8 @@ + android:id="@+id/nav_newsfeed" + android:overScrollMode="always"> - -