From ef57ba87227a69335bb5e6ae94a3c6d1e199401a Mon Sep 17 00:00:00 2001 From: Defend Date: Sun, 19 Feb 2017 20:49:20 +0300 Subject: [PATCH] Created event when user press back for news fragment. Added full text on news fragment view. Some fixes on news fragment xml. --- .../defdevteam/tstu/CabinetActivity.java | 7 ++- .../defdevteam/tstu/FeedController.java | 8 ++-- .../ru/defend/defdevteam/tstu/FeedParser.java | 8 ++-- .../defend/defdevteam/tstu/NewsFragment.java | 2 +- app/src/main/res/layout/fragment_news.xml | 43 ++++++++++--------- 5 files changed, 37 insertions(+), 31 deletions(-) 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 127dc0f..10cd9cd 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java @@ -62,7 +62,6 @@ public class CabinetActivity extends AppCompatActivity @Override public void onFragmentInteraction(Uri uri) { - } @@ -185,7 +184,10 @@ public class CabinetActivity extends AppCompatActivity @Override public void onBackPressed() { DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout); - if (drawer.isDrawerOpen(GravityCompat.START)) { + int c = getFragmentManager().getBackStackEntryCount(); + if (c > 0) { + getFragmentManager().popBackStack(); + } else if (drawer.isDrawerOpen(GravityCompat.START)) { drawer.closeDrawer(GravityCompat.START); } else { super.onBackPressed(); @@ -350,6 +352,7 @@ public class CabinetActivity extends AppCompatActivity FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); NewsFragment newsFragment = new NewsFragment().newInstance(group); fragmentTransaction.add(R.id.newsfeeder, newsFragment); + fragmentTransaction.addToBackStack(null); fragmentTransaction.commit(); // RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.newsfeeder); // View layout = getLayoutInflater().inflate(R.layout.cabinet_newsfeed_floatingitem, relativeLayout, false); 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 501c631..410874c 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java @@ -56,8 +56,8 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par } } - public void addNewsList(String title, String text, String link) { - newsItemList.add(new NewsItemGroup(title, text, link)); + public void addNewsList(NewsItemGroup group) { + newsItemList.add(group); } @@ -110,8 +110,8 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par } @Override - public void contentDispatcher(String title, String text, String link) { - addNewsList(title, text, link); + public void contentDispatcher(NewsItemGroup group) { + addNewsList(group); } 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 0069a1d..297d4d6 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/FeedParser.java @@ -22,7 +22,7 @@ public class FeedParser { interface ParserCallback { void onSuccessParsing(); void onFailureParsing(); - void contentDispatcher(String title, String text, String link); + void contentDispatcher(NewsItemGroup group); } void registerCallback(ParserCallback callback) { @@ -127,8 +127,10 @@ public class FeedParser { if (qName.equalsIgnoreCase("item") && item) { item = false; String imageLink = getImageLink(descriptionStr); - descriptionStr = getDescriptionShort(descriptionStr); - callback.contentDispatcher(titleStr, descriptionStr, imageLink); + String shortDescriptionStr = getDescriptionShort(descriptionStr); + NewsItemGroup group = new NewsItemGroup(titleStr, shortDescriptionStr, imageLink); + group.setFullText(deleteHtmlTag(descriptionStr, "<", ">")); + callback.contentDispatcher(group); refreshStrings(); } } diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java b/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java index eeaa833..b5d6dd2 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java @@ -41,7 +41,7 @@ public class NewsFragment extends Fragment { NewsFragment newsFragment = new NewsFragment(); Bundle arg = new Bundle(); arg.putString(ARG_PARAM1, group.getTitle()); - arg.putString(ARG_PARAM2, group.getText()); + arg.putString(ARG_PARAM2, group.getFullText()); arg.putString(ARG_PARAM3, group.getLink()); newsFragment.setArguments(arg); return newsFragment; diff --git a/app/src/main/res/layout/fragment_news.xml b/app/src/main/res/layout/fragment_news.xml index 38f7fd0..e5df998 100644 --- a/app/src/main/res/layout/fragment_news.xml +++ b/app/src/main/res/layout/fragment_news.xml @@ -1,34 +1,34 @@ - - - + android:layout_height="match_parent" + android:alpha="0.6" + android:background="@android:color/darker_gray"> - + + + - + android:layout_width="match_parent" + android:layout_height="match_parent" + android:orientation="vertical" + android:alpha="1" + android:background="@android:color/background_light" + android:id="@+id/floatingitem_second"> + android:id="@+id/floatingnews_content" + android:padding="5dp"/> - - - + + +