From 957b4ec5b7831cbba7897499d1a1b2f428c998a3 Mon Sep 17 00:00:00 2001 From: Defend Date: Sun, 19 Feb 2017 19:26:34 +0300 Subject: [PATCH] A lot of refactoring. Was created and then was changed layout draw method for full news view. NewsItemList divided in two new class - NewsItemList and NewsItemGroup. --- .../animated_vector_drawable_23_4_0.xml | 12 -- .idea/libraries/appcompat_v7_23_4_0.xml | 15 --- .idea/libraries/design_23_4_0.xml | 15 --- .idea/libraries/recyclerview_v7_23_4_0.xml | 15 --- .../libraries/support_annotations_23_4_0.xml | 11 -- .idea/libraries/support_v4_23_4_0.xml | 16 --- .../support_vector_drawable_23_4_0.xml | 12 -- app/app.iml | 54 +++++--- app/build.gradle | 5 +- .../defdevteam/tstu/CabinetActivity.java | 65 ++++++--- .../defdevteam/tstu/FeedController.java | 11 +- .../defend/defdevteam/tstu/NewsFragment.java | 94 +++++++++++++ .../defend/defdevteam/tstu/NewsItemGroup.java | 48 +++++++ .../defend/defdevteam/tstu/NewsItemList.java | 125 ++++-------------- .../layout/cabinet_newsfeed_floatingitem.xml | 39 ++---- app/src/main/res/layout/fragment_news.xml | 61 +++++++++ 16 files changed, 334 insertions(+), 264 deletions(-) delete mode 100644 .idea/libraries/animated_vector_drawable_23_4_0.xml delete mode 100644 .idea/libraries/appcompat_v7_23_4_0.xml delete mode 100644 .idea/libraries/design_23_4_0.xml delete mode 100644 .idea/libraries/recyclerview_v7_23_4_0.xml delete mode 100644 .idea/libraries/support_annotations_23_4_0.xml delete mode 100644 .idea/libraries/support_v4_23_4_0.xml delete mode 100644 .idea/libraries/support_vector_drawable_23_4_0.xml create mode 100644 app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java create mode 100644 app/src/main/java/ru/defend/defdevteam/tstu/NewsItemGroup.java create mode 100644 app/src/main/res/layout/fragment_news.xml diff --git a/.idea/libraries/animated_vector_drawable_23_4_0.xml b/.idea/libraries/animated_vector_drawable_23_4_0.xml deleted file mode 100644 index b2ce40a..0000000 --- a/.idea/libraries/animated_vector_drawable_23_4_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/appcompat_v7_23_4_0.xml b/.idea/libraries/appcompat_v7_23_4_0.xml deleted file mode 100644 index af57544..0000000 --- a/.idea/libraries/appcompat_v7_23_4_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/design_23_4_0.xml b/.idea/libraries/design_23_4_0.xml deleted file mode 100644 index fef7eb9..0000000 --- a/.idea/libraries/design_23_4_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/recyclerview_v7_23_4_0.xml b/.idea/libraries/recyclerview_v7_23_4_0.xml deleted file mode 100644 index e06fd5f..0000000 --- a/.idea/libraries/recyclerview_v7_23_4_0.xml +++ /dev/null @@ -1,15 +0,0 @@ - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_annotations_23_4_0.xml b/.idea/libraries/support_annotations_23_4_0.xml deleted file mode 100644 index 87c058c..0000000 --- a/.idea/libraries/support_annotations_23_4_0.xml +++ /dev/null @@ -1,11 +0,0 @@ - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_v4_23_4_0.xml b/.idea/libraries/support_v4_23_4_0.xml deleted file mode 100644 index 4626a33..0000000 --- a/.idea/libraries/support_v4_23_4_0.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - - - - - - - - - - - - - - \ No newline at end of file diff --git a/.idea/libraries/support_vector_drawable_23_4_0.xml b/.idea/libraries/support_vector_drawable_23_4_0.xml deleted file mode 100644 index a54a2e5..0000000 --- a/.idea/libraries/support_vector_drawable_23_4_0.xml +++ /dev/null @@ -1,12 +0,0 @@ - - - - - - - - - - - - \ No newline at end of file diff --git a/app/app.iml b/app/app.iml index a16956c..ecc689c 100644 --- a/app/app.iml +++ b/app/app.iml @@ -66,14 +66,6 @@ - - - - - - - - @@ -82,17 +74,31 @@ + + + + + + + + - - - - - - + + + + + + + + + + + + @@ -114,15 +120,21 @@ - - - + + + + + + + - - + + - - + + + + \ No newline at end of file diff --git a/app/build.gradle b/app/build.gradle index 3f70650..e420b01 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -21,7 +21,8 @@ android { dependencies { compile fileTree(include: ['*.jar'], dir: 'libs') + compile 'com.android.support:appcompat-v7:25.1.0' + compile 'com.android.support:design:25.1.0' + compile 'com.android.support:support-v4:25.1.0' testCompile 'junit:junit:4.12' - compile 'com.android.support:appcompat-v7:23.4.0' - compile 'com.android.support:design:23.4.0' } 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 2d4a9a7..127dc0f 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/CabinetActivity.java @@ -5,13 +5,14 @@ import android.content.Context; import android.content.Intent; import android.graphics.Bitmap; import android.graphics.BitmapFactory; +import android.net.Uri; import android.os.AsyncTask; -import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.design.widget.FloatingActionButton; import android.support.design.widget.Snackbar; -import android.support.v7.view.menu.MenuView; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentTransaction; import android.util.Log; import android.view.LayoutInflater; import android.view.View; @@ -29,21 +30,20 @@ import android.webkit.WebSettings; import android.webkit.WebView; import android.webkit.WebViewClient; import android.widget.ArrayAdapter; +import android.widget.FrameLayout; 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; public class CabinetActivity extends AppCompatActivity - implements NavigationView.OnNavigationItemSelectedListener { + implements NavigationView.OnNavigationItemSelectedListener, NewsFragment.OnFragmentInteractionListener { static public List group, faculty, subs; @@ -60,6 +60,10 @@ public class CabinetActivity extends AppCompatActivity FeedController feedController; OldCabinetController cabinetController; + @Override + public void onFragmentInteraction(Uri uri) { + + } public class groupAdapter extends ArrayAdapter { @@ -218,12 +222,8 @@ public class CabinetActivity extends AppCompatActivity gRateLayout.setVisibility(View.INVISIBLE); fRateLayout.setVisibility(View.INVISIBLE); aboutLayout.setVisibility(View.INVISIBLE); -// if(!taskFinished) { -// progressLayout.setVisibility(View.VISIBLE); -// } switch (id) { case R.id.nav_newsfeed: - progressLayout.setVisibility(View.INVISIBLE); newsLayout.setVisibility(View.VISIBLE); myToolbar.setTitle(R.string.title_newsfeed); break; @@ -244,7 +244,6 @@ public class CabinetActivity extends AppCompatActivity myToolbar.setTitle(R.string.title_globalrate); break; case R.id.nav_aboutapp: - progressLayout.setVisibility(View.INVISIBLE); aboutLayout.setVisibility(View.VISIBLE); myToolbar.setTitle(R.string.title_about_dev); break; @@ -309,11 +308,11 @@ public class CabinetActivity extends AppCompatActivity } } - public int addNewsItem(NewsItemList.Group group, Boolean LastItem) { + public int addNewsItem(NewsItemGroup group, Boolean LastItem) { String title = group.getTitle(); String text = group.getText(); String link = group.getLink(); - int viewId = group.getViewId(); + int viewId = group.getViewID(); LayoutInflater inflater = getLayoutInflater(); LinearLayout newsFeed = (LinearLayout) findViewById(R.id.newsfeed_scroll); View layout; @@ -344,10 +343,42 @@ public class CabinetActivity extends AppCompatActivity } 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); + NewsItemList newsItemList = feedController.newsItemList; + NewsItemGroup group = newsItemList.getGroupByViewId(v.getId()); + Log.i("ERROR DEBUG", "" +v.getId()); + FragmentManager fragmentManager = getSupportFragmentManager(); + FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction(); + NewsFragment newsFragment = new NewsFragment().newInstance(group); + fragmentTransaction.add(R.id.newsfeeder, newsFragment); + fragmentTransaction.commit(); +// RelativeLayout relativeLayout = (RelativeLayout) findViewById(R.id.newsfeeder); +// View layout = getLayoutInflater().inflate(R.layout.cabinet_newsfeed_floatingitem, relativeLayout, false); +// relativeLayout.addView(layout); +// + +// try { +// Log.i("ERROR DEBUG", "CLICK CLACK"); +// TextView textView = (TextView) layout.findViewById(R.id.floatingnews_title); +// NewsItemList newsItemList = feedController.newsItemList; +// textView.setText(newsItemList.getGroupByViewId(v.getId()).getTitle()); +// TextView textView1 = (TextView) layout.findViewById(R.id.floatingnews_content); +// textView1.setText(newsItemList.getGroupByViewId(v.getId()).getText()); +// +// FrameLayout frameLayout = (FrameLayout) findViewById(R.id.floatingitem_first); +// LinearLayout linearLayout = (LinearLayout) findViewById(R.id.floatingitem_second); +// View.OnClickListener regionOnClickListner = new View.OnClickListener() { +// @Override +// public void onClick(View v) { +// v.setVisibility(View.GONE); +// LinearLayout linearLayout = (LinearLayout) findViewById(R.id.floatingitem_instance); +// linearLayout.setVisibility(View.GONE); +// } +// }; +// linearLayout.setOnClickListener(regionOnClickListner); +// frameLayout.setOnClickListener(regionOnClickListner); +// } catch (Exception e) { +// e.printStackTrace(); +// } } 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 ed88d93..501c631 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/FeedController.java @@ -57,11 +57,7 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par } public void addNewsList(String title, String text, String link) { - newsItemList.add(new NewsItemList().new Group( - title, - text, - link - )); + newsItemList.add(new NewsItemGroup(title, text, link)); } @@ -72,8 +68,9 @@ public class FeedController implements FeedReader.ReaderCallback, FeedParser.Par activity.clearNewsFeed(); } }); - for (int i = 0; i < newsItemList.size(); i++) { - final NewsItemList.Group item = newsItemList.get(i); + NewsItemGroup array[] = newsItemList.toArray(); + for (int i = 0; i < array.length; i++) { + final NewsItemGroup item = array[i]; if(i < newsItemList.size() - 1) { activity.runOnUiThread(new Runnable() { @Override diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java b/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java new file mode 100644 index 0000000..eeaa833 --- /dev/null +++ b/app/src/main/java/ru/defend/defdevteam/tstu/NewsFragment.java @@ -0,0 +1,94 @@ +package ru.defend.defdevteam.tstu; + +import android.content.Context; +import android.net.Uri; +import android.os.Bundle; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.TextView; + +import org.w3c.dom.Text; + +public class NewsFragment extends Fragment { + private static final String ARG_PARAM1 = "title"; + private static final String ARG_PARAM2 = "text"; + private static final String ARG_PARAM3 = "link"; + private String mTitle; + private String mImgLink; + private String mText; + + + + private OnFragmentInteractionListener mListener; + + public NewsFragment() { + } + + @Override + public void onResume() { + super.onResume(); + if (getArguments() != null) { + mTitle = getArguments().getString(ARG_PARAM1); + mText = getArguments().getString(ARG_PARAM2); + mImgLink = getArguments().getString(ARG_PARAM3); + updateNewsFragment(); + } + } + + public static NewsFragment newInstance(NewsItemGroup group) { + NewsFragment newsFragment = new NewsFragment(); + Bundle arg = new Bundle(); + arg.putString(ARG_PARAM1, group.getTitle()); + arg.putString(ARG_PARAM2, group.getText()); + arg.putString(ARG_PARAM3, group.getLink()); + newsFragment.setArguments(arg); + return newsFragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + } + + public void updateNewsFragment() { + TextView titleTextView = (TextView) getActivity().findViewById(R.id.floatingnews_title); + TextView textView = (TextView) getActivity().findViewById(R.id.floatingnews_content); + titleTextView.setText(mTitle); + textView.setText(mText); + } + + @Override + public View onCreateView(LayoutInflater inflater, ViewGroup container, + Bundle savedInstanceState) { + return inflater.inflate(R.layout.fragment_news, container, false); + } + + public void onButtonPressed(Uri uri) { + if (mListener != null) { + mListener.onFragmentInteraction(uri); + } + } + + @Override + public void onAttach(Context context) { + super.onAttach(context); + if (context instanceof OnFragmentInteractionListener) { + mListener = (OnFragmentInteractionListener) context; + } else { + throw new RuntimeException(context.toString() + + " must implement OnFragmentInteractionListener"); + } + } + + @Override + public void onDetach() { + super.onDetach(); + mListener = null; + } + + public interface OnFragmentInteractionListener { + void onFragmentInteraction(Uri uri); + } +} diff --git a/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemGroup.java b/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemGroup.java new file mode 100644 index 0000000..9e8b532 --- /dev/null +++ b/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemGroup.java @@ -0,0 +1,48 @@ +package ru.defend.defdevteam.tstu; + +/** + * Created by itsmy on 19.02.2017. + */ +public class NewsItemGroup { + protected String title; + protected String text; + protected String link; + protected String fullText; + protected int viewID; + + public NewsItemGroup(String title, String text, String link) { + this.fullText = ""; + this.text = text; + this.title = title; + this.link = link; + this.viewID = -1; + } + + public String getTitle() { + return this.title; + } + + public String getText() { + return this.text; + } + + public String getLink() { + return this.link; + } + + public void setFullText(String fullText) { + this.fullText = fullText; + } + + public String getFullText() { + return this.fullText; + } + + public int getViewID() { + return viewID; + } + + public void setViewID(int viewID) { + this.viewID = viewID; + } +} 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 079a5ca..530bd1c 100644 --- a/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java +++ b/app/src/main/java/ru/defend/defdevteam/tstu/NewsItemList.java @@ -6,122 +6,55 @@ import android.view.View; import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; -import java.util.ListIterator; -import java.util.NoSuchElementException; +import java.util.Map; /** * Created by itsmy on 13.02.2017. */ -public class NewsItemList { - - private ArrayList list; - private HashMap hashMap; +public class NewsItemList { + private HashMap hashMap; NewsItemList() { - list = new ArrayList<>(); hashMap = new HashMap<>(); } + public NewsItemGroup[] toArray() { + int counter = 0; + NewsItemGroup[] array = new NewsItemGroup[size()]; + for (Map.Entry entry: hashMap.entrySet()) { + array[counter] = entry.getValue(); + counter++; + } + return array; + } + public int size() { - return list.size(); + return hashMap.size(); } - public Group get(int index) { - return list.get(index); + public void add(NewsItemGroup group) { + int viewId = getViewId(); + group.setViewID(viewId); + this.hashMap.put(viewId, group); } - public void add(Group group) { - this.list.add(group); - this.hashMap.put(group.getViewId(), this.list.size()); + public int getViewId() { + int viewId; + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) { + viewId = View.generateViewId(); + Log.i("Generated view id", Integer.toString(viewId)); + } else { + viewId = -1; + } + return viewId; } -// -// 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)); + public NewsItemGroup getGroupByViewId(int viewId) { + return this.hashMap.get(viewId); } - -// @Override -// public Iterator iterator() { -// return new NewsIterator(); -// } - -// private class NewsIterator implements Iterator { -// private int cursor; -// -// public NewsIterator() { -// this.cursor = 0; -// } -// -// public boolean hasNext() { -// return this.cursor < size(); -// } -// -// public Group next() { -// if(this.hasNext()) { -// Group current = get(cursor); -// cursor ++; -// return current; -// } -// throw new NoSuchElementException(); -// } -// -// public void remove() { -// throw new UnsupportedOperationException(); -// } -// } - - public class Group { - 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() { - return this.title; - } - - public String getText() { - return this.text; - } - - public String getLink() { - 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_floatingitem.xml b/app/src/main/res/layout/cabinet_newsfeed_floatingitem.xml index 398fe84..fa5da38 100644 --- a/app/src/main/res/layout/cabinet_newsfeed_floatingitem.xml +++ b/app/src/main/res/layout/cabinet_newsfeed_floatingitem.xml @@ -1,37 +1,26 @@ + android:layout_height="match_parent" + android:id="@+id/floatingitem_instance" + android:clickable="true"> + + android:layout_height="match_parent"> - - - - + android:alpha="0.6" + android:background="@android:color/darker_gray" + android:id="@+id/floatingitem_first"> + + + + + \ No newline at end of file diff --git a/app/src/main/res/layout/fragment_news.xml b/app/src/main/res/layout/fragment_news.xml new file mode 100644 index 0000000..38f7fd0 --- /dev/null +++ b/app/src/main/res/layout/fragment_news.xml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + + + + + + +