From 926a8c1fc20d143f1d7fe17ec213fdd1ed84f751 Mon Sep 17 00:00:00 2001 From: Apostolof Date: Wed, 4 Jul 2018 00:12:12 +0300 Subject: [PATCH] Enhance bookmarks activity UI --- app/build.gradle | 3 +- app/src/main/AndroidManifest.xml | 2 +- .../mthmmy/activities/BookmarkActivity.java | 198 ------------------ .../bookmarks/BoardBookmarksFragment.java | 130 ++++++++++++ .../bookmarks/BookmarkActivity.java | 143 +++++++++++++ .../bookmarks/TopicBookmarksFragment.java | 163 ++++++++++++++ .../gr/thmmy/mthmmy/base/BaseActivity.java | 2 +- app/src/main/res/layout/activity_bookmark.xml | 27 +-- .../main/res/layout/fragment_bookmarks.xml | 22 ++ app/src/main/res/values/strings.xml | 7 +- 10 files changed, 481 insertions(+), 216 deletions(-) delete mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/BookmarkActivity.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java create mode 100644 app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java create mode 100644 app/src/main/res/layout/fragment_bookmarks.xml diff --git a/app/build.gradle b/app/build.gradle index 3b463434..4d8ca81d 100644 --- a/app/build.gradle +++ b/app/build.gradle @@ -49,7 +49,8 @@ dependencies { implementation 'com.mikepenz:fontawesome-typeface:4.7.0.0@aar' implementation 'com.mikepenz:google-material-typeface:3.0.1.2.original@aar' implementation 'pl.droidsonroids.gif:android-gif-drawable:1.2.12' - implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1' //TODO: needs replacement + implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1' + //TODO: needs replacement implementation 'me.zhanghai.android.materialprogressbar:library:1.4.2' implementation 'com.jakewharton.timber:timber:4.7.0' } diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index c9bfa2af..7417185a 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -98,7 +98,7 @@ android:value=".activities.main.MainActivity" /> = Build.VERSION_CODES.LOLLIPOP) { - notificationsEnabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_on, null); - } else { - notificationsEnabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_on, null); - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - notificationsDisabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_off, null); - } else { - notificationsDisabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_off, null); - } - - LinearLayout bookmarksLinearView = findViewById(R.id.bookmarks_container); - LayoutInflater layoutInflater = getLayoutInflater(); - - if(!getBoardsBookmarked().isEmpty()) { - boardsTitle = new TextView(this); - boardsTitle.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT - , LinearLayout.LayoutParams.WRAP_CONTENT)); - boardsTitle.setText(getString(R.string.board_bookmarks_title)); - boardsTitle.setTypeface(boardsTitle.getTypeface(), Typeface.BOLD); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - boardsTitle.setTextColor(getColor(R.color.primary_text)); - } else { - //noinspection deprecation - boardsTitle.setTextColor(getResources().getColor(R.color.primary_text)); - } - boardsTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - boardsTitle.setTextSize(20f); - bookmarksLinearView.addView(boardsTitle); - - for (final Bookmark bookmarkedBoard : getBoardsBookmarked()) { - if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) { - final LinearLayout row = (LinearLayout) layoutInflater.inflate( - R.layout.activity_bookmark_board_row, bookmarksLinearView, false); - row.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board=" - + bookmarkedBoard.getId() + ".0"); - extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle()); - intent.putExtras(extras); - startActivity(intent); - finish(); - } - }); - ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedBoard.getTitle()); - (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - removeBookmark(bookmarkedBoard); - row.setVisibility(View.GONE); - updateTitles(); - } - }); - bookmarksLinearView.addView(row); - } - } - } - - - if(!getTopicsBookmarked().isEmpty()) { - topicsTitle = new TextView(this); - topicsTitle.setLayoutParams(new LinearLayout.LayoutParams( - LinearLayout.LayoutParams.MATCH_PARENT - , LinearLayout.LayoutParams.WRAP_CONTENT)); - topicsTitle.setText(getString(R.string.topic_bookmarks_title)); - topicsTitle.setTypeface(topicsTitle.getTypeface(), Typeface.BOLD); - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { - topicsTitle.setTextColor(getColor(R.color.primary_text)); - } else { - //noinspection deprecation - topicsTitle.setTextColor(getResources().getColor(R.color.primary_text)); - } - topicsTitle.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); - topicsTitle.setTextSize(20f); - bookmarksLinearView.addView(topicsTitle); - - for (final Bookmark bookmarkedTopic : getTopicsBookmarked()) { - if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) { - final LinearLayout row = (LinearLayout) layoutInflater.inflate( - R.layout.activity_bookmark_topic_row, bookmarksLinearView, false); - row.setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class); - Bundle extras = new Bundle(); - extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic=" - + bookmarkedTopic.getId() + "." + 2147483647); - extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle()); - intent.putExtras(extras); - startActivity(intent); - finish(); - } - }); - ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle()); - - final ImageButton notificationsEnabledButton = row.findViewById(R.id.toggle_notification); - if (!bookmarkedTopic.isNotificationsEnabled()){ - notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); - } - - notificationsEnabledButton.setOnClickListener(new View.OnClickListener() { - - @Override - public void onClick(View view) { - if(toggleNotification(bookmarkedTopic)){ - notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage); - } else { - notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); - } - } - }); - (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() { - @Override - public void onClick(View view) { - removeBookmark(bookmarkedTopic); - row.setVisibility(View.GONE); - Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); - updateTitles(); - } - }); - bookmarksLinearView.addView(row); - } - } - } - } - - @Override - protected void onResume() { - drawer.setSelection(BOOKMARKS_ID); - super.onResume(); - } - - private void updateTitles() - { - if(getBoardsBookmarked().isEmpty()&&boardsTitle!=null) - boardsTitle.setVisibility(View.GONE); - if(getTopicsBookmarked().isEmpty()&&topicsTitle!=null) - topicsTitle.setVisibility(View.GONE); - } -} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java new file mode 100644 index 00000000..3f93ddc4 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BoardBookmarksFragment.java @@ -0,0 +1,130 @@ +package gr.thmmy.mthmmy.activities.bookmarks; + +import android.app.Activity; +import android.graphics.Typeface; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.ArrayList; + +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.model.Bookmark; + +/** + * A {@link Fragment} subclass. + * Use the {@link BoardBookmarksFragment#newInstance} factory method to + * create an instance of this fragment. + */ +public class BoardBookmarksFragment extends Fragment { + protected static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; + protected static final String ARG_BOARD_BOOKMARKS = "BOARD_BOOKMARKS"; + + public static final String INTERACTION_CLICK_BOARD_BOOKMARK = "CLICK_BOARD_BOOKMARK"; + public static final String INTERACTION_REMOVE_BOARD_BOOKMARK= "REMOVE_BOARD_BOOKMARK"; + + ArrayList boardBookmarks = null; + + // Required empty public constructor + public BoardBookmarksFragment() { + } + + /** + * Use ONLY this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @return A new instance of fragment Forum. + */ + public static BoardBookmarksFragment newInstance(int sectionNumber, String boardBookmarks) { + BoardBookmarksFragment fragment = new BoardBookmarksFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + args.putString(ARG_BOARD_BOOKMARKS, boardBookmarks); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + String bundledBoardBookmarks = getArguments().getString(ARG_BOARD_BOOKMARKS); + if (bundledBoardBookmarks != null) { + boardBookmarks = Bookmark.arrayFromString(bundledBoardBookmarks); + } + } + } + + @Override + public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflates the layout for this fragment + final View rootView = layoutInflater.inflate(R.layout.fragment_bookmarks, container, false); + //bookmarks_board_container + final LinearLayout bookmarksLinearView = rootView.findViewById(R.id.bookmarks_container); + + if(this.boardBookmarks != null && !this.boardBookmarks.isEmpty()) { + for (final Bookmark bookmarkedBoard : boardBookmarks) { + if (bookmarkedBoard != null && bookmarkedBoard.getTitle() != null) { + final LinearLayout row = (LinearLayout) layoutInflater.inflate( + R.layout.activity_bookmark_board_row, bookmarksLinearView, false); + row.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Activity activity = getActivity(); + if (activity instanceof BookmarkActivity){ + ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_CLICK_BOARD_BOOKMARK, bookmarkedBoard); + } + } + }); + ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedBoard.getTitle()); + (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Activity activity = getActivity(); + if (activity instanceof BookmarkActivity){ + ((BookmarkActivity) activity).onBoardInteractionListener(INTERACTION_REMOVE_BOARD_BOOKMARK, bookmarkedBoard); + boardBookmarks.remove(bookmarkedBoard); + } + row.setVisibility(View.GONE); + + if (boardBookmarks.isEmpty()){ + bookmarksLinearView.addView(bookmarksListEmptyMessage()); + } + } + }); + bookmarksLinearView.addView(row); + } + } + } else { + + bookmarksLinearView.addView(bookmarksListEmptyMessage()); + } + + return rootView; + } + + private TextView bookmarksListEmptyMessage() { + TextView emptyBookmarksCategory = new TextView(this.getContext()); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); + params.setMargins(0, 12, 0, 0); + emptyBookmarksCategory.setLayoutParams(params); + emptyBookmarksCategory.setText(getString(R.string.empty_board_bookmarks)); + emptyBookmarksCategory.setTypeface(emptyBookmarksCategory.getTypeface(), Typeface.BOLD); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + emptyBookmarksCategory.setTextColor(this.getContext().getColor(R.color.primary_text)); + } else { + //noinspection deprecation + emptyBookmarksCategory.setTextColor(this.getContext().getResources().getColor(R.color.primary_text)); + } + emptyBookmarksCategory.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); + return emptyBookmarksCategory; + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java new file mode 100644 index 00000000..0408db44 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/BookmarkActivity.java @@ -0,0 +1,143 @@ +package gr.thmmy.mthmmy.activities.bookmarks; + +import android.content.Intent; +import android.graphics.drawable.Drawable; +import android.os.Bundle; +import android.support.design.widget.TabLayout; +import android.support.v4.app.Fragment; +import android.support.v4.app.FragmentManager; +import android.support.v4.app.FragmentPagerAdapter; +import android.support.v4.view.ViewPager; +import android.widget.Toast; + +import java.util.ArrayList; +import java.util.List; + +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.activities.board.BoardActivity; +import gr.thmmy.mthmmy.activities.topic.TopicActivity; +import gr.thmmy.mthmmy.base.BaseActivity; +import gr.thmmy.mthmmy.model.Bookmark; + +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_TITLE; +import static gr.thmmy.mthmmy.activities.board.BoardActivity.BUNDLE_BOARD_URL; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_TITLE; +import static gr.thmmy.mthmmy.activities.topic.TopicActivity.BUNDLE_TOPIC_URL; + +//TODO proper handling with adapter etc. +//TODO after clicking bookmark and then back button should return to this activity +public class BookmarkActivity extends BaseActivity { + @Override + protected void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + setContentView(R.layout.activity_bookmark); + + //Initialize toolbar + toolbar = findViewById(R.id.toolbar); + toolbar.setTitle("Bookmarks"); + setSupportActionBar(toolbar); + if (getSupportActionBar() != null) { + getSupportActionBar().setDisplayHomeAsUpEnabled(true); + getSupportActionBar().setDisplayShowHomeEnabled(true); + } + + createDrawer(); + drawer.setSelection(BOOKMARKS_ID); + + //Creates the adapter that will return a fragment for each section of the activity + SectionsPagerAdapter sectionsPagerAdapter = new SectionsPagerAdapter(getSupportFragmentManager()); + sectionsPagerAdapter.addFragment(TopicBookmarksFragment.newInstance(1, Bookmark.arrayToString(getTopicsBookmarked())), "Topics"); + sectionsPagerAdapter.addFragment(BoardBookmarksFragment.newInstance(2, Bookmark.arrayToString(getBoardsBookmarked())), "Boards"); + + //Sets up the ViewPager with the sections adapter. + ViewPager viewPager = findViewById(R.id.bookmarks_container); + viewPager.setAdapter(sectionsPagerAdapter); + + TabLayout tabLayout = findViewById(R.id.bookmark_tabs); + tabLayout.setupWithViewPager(viewPager); + } + + @Override + protected void onResume() { + drawer.setSelection(BOOKMARKS_ID); + super.onResume(); + } + + public boolean onTopicInteractionListener(String interactionType, Bookmark bookmarkedTopic){ + if (interactionType.equals(TopicBookmarksFragment.INTERACTION_CLICK_TOPIC_BOOKMARK)){ + Intent intent = new Intent(BookmarkActivity.this, TopicActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_TOPIC_URL, "https://www.thmmy.gr/smf/index.php?topic=" + + bookmarkedTopic.getId() + "." + 2147483647); + extras.putString(BUNDLE_TOPIC_TITLE, bookmarkedTopic.getTitle()); + intent.putExtras(extras); + startActivity(intent); + finish(); + } else if (interactionType.equals(TopicBookmarksFragment.INTERACTION_TOGGLE_TOPIC_NOTIFICATION)) { + return toggleNotification(bookmarkedTopic); + } else if (interactionType.equals(TopicBookmarksFragment.INTERACTION_REMOVE_TOPIC_BOOKMARK)){ + removeBookmark(bookmarkedTopic); + Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + } + return true; + } + + public void onBoardInteractionListener(String interactionType, Bookmark bookmarkedBoard){ + if (interactionType.equals(BoardBookmarksFragment.INTERACTION_CLICK_BOARD_BOOKMARK)){ + Intent intent = new Intent(BookmarkActivity.this, BoardActivity.class); + Bundle extras = new Bundle(); + extras.putString(BUNDLE_BOARD_URL, "https://www.thmmy.gr/smf/index.php?board=" + + bookmarkedBoard.getId() + ".0"); + extras.putString(BUNDLE_BOARD_TITLE, bookmarkedBoard.getTitle()); + intent.putExtras(extras); + startActivity(intent); + finish(); + } else if (interactionType.equals(BoardBookmarksFragment.INTERACTION_REMOVE_BOARD_BOOKMARK)){ + removeBookmark(bookmarkedBoard); + Toast.makeText(BookmarkActivity.this, "Bookmark removed", Toast.LENGTH_SHORT).show(); + } + } + + /** + * A {@link FragmentPagerAdapter} that returns a fragment corresponding to + * one of the sections/tabs/pages. If it becomes too memory intensive, + * it may be best to switch to a + * {@link android.support.v4.app.FragmentStatePagerAdapter}. + */ + private class SectionsPagerAdapter extends FragmentPagerAdapter { + private final List fragmentList = new ArrayList<>(); + private final List fragmentTitleList = new ArrayList<>(); + + SectionsPagerAdapter(FragmentManager fm) { + super(fm); + } + + void addFragment(Fragment fragment, String title) { + fragmentList.add(fragment); + fragmentTitleList.add(title); + notifyDataSetChanged(); + } + + @Override + public Fragment getItem(int position) { + return fragmentList.get(position); + } + + @Override + public int getCount() { + return fragmentList.size(); + } + + @Override + public CharSequence getPageTitle(int position) { + return fragmentTitleList.get(position); + } + + @Override + public int getItemPosition(Object object) { + @SuppressWarnings("RedundantCast") + int position = fragmentList.indexOf((Fragment) object); + return position == -1 ? POSITION_NONE : position; + } + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java new file mode 100644 index 00000000..d2b982f0 --- /dev/null +++ b/app/src/main/java/gr/thmmy/mthmmy/activities/bookmarks/TopicBookmarksFragment.java @@ -0,0 +1,163 @@ +package gr.thmmy.mthmmy.activities.bookmarks; + +import android.app.Activity; +import android.graphics.Typeface; +import android.graphics.drawable.Drawable; +import android.os.Build; +import android.os.Bundle; +import android.support.annotation.NonNull; +import android.support.graphics.drawable.VectorDrawableCompat; +import android.support.v4.app.Fragment; +import android.view.LayoutInflater; +import android.view.View; +import android.view.ViewGroup; +import android.widget.ImageButton; +import android.widget.LinearLayout; +import android.widget.TextView; + +import java.util.ArrayList; + +import gr.thmmy.mthmmy.R; +import gr.thmmy.mthmmy.model.Bookmark; + +public class TopicBookmarksFragment extends Fragment { + protected static final String ARG_SECTION_NUMBER = "SECTION_NUMBER"; + protected static final String ARG_TOPIC_BOOKMARKS = "BOARD_BOOKMARKS"; + + public static final String INTERACTION_CLICK_TOPIC_BOOKMARK = "CLICK_BOARD_BOOKMARK"; + public static final String INTERACTION_TOGGLE_TOPIC_NOTIFICATION = "TOGGLE_TOPIC_NOTIFICATION"; + public static final String INTERACTION_REMOVE_TOPIC_BOOKMARK = "REMOVE_BOARD_BOOKMARK"; + + ArrayList topicBookmarks = null; + + private static Drawable notificationsEnabledButtonImage; + private static Drawable notificationsDisabledButtonImage; + + // Required empty public constructor + public TopicBookmarksFragment() { + } + + /** + * Use ONLY this factory method to create a new instance of + * this fragment using the provided parameters. + * + * @return A new instance of fragment Forum. + */ + public static TopicBookmarksFragment newInstance(int sectionNumber, String boardBookmarks) { + TopicBookmarksFragment fragment = new TopicBookmarksFragment(); + Bundle args = new Bundle(); + args.putInt(ARG_SECTION_NUMBER, sectionNumber); + args.putString(ARG_TOPIC_BOOKMARKS, boardBookmarks); + fragment.setArguments(args); + return fragment; + } + + @Override + public void onCreate(Bundle savedInstanceState) { + super.onCreate(savedInstanceState); + if (getArguments() != null) { + String bundledBoardBookmarks = getArguments().getString(ARG_TOPIC_BOOKMARKS); + if (bundledBoardBookmarks != null) { + topicBookmarks = Bookmark.arrayFromString(bundledBoardBookmarks); + } + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + notificationsEnabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_on, null); + } else { + notificationsEnabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_on, null); + } + + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + notificationsDisabledButtonImage = getResources().getDrawable(R.drawable.ic_notification_off, null); + } else { + notificationsDisabledButtonImage = VectorDrawableCompat.create(getResources(), R.drawable.ic_notification_off, null); + } + } + + @Override + public View onCreateView(@NonNull LayoutInflater layoutInflater, ViewGroup container, + Bundle savedInstanceState) { + // Inflates the layout for this fragment + final View rootView = layoutInflater.inflate(R.layout.fragment_bookmarks, container, false); + //bookmarks_board_container + final LinearLayout bookmarksLinearView = rootView.findViewById(R.id.bookmarks_container); + + if(this.topicBookmarks != null && !this.topicBookmarks.isEmpty()) { + for (final Bookmark bookmarkedTopic : topicBookmarks) { + if (bookmarkedTopic != null && bookmarkedTopic.getTitle() != null) { + final LinearLayout row = (LinearLayout) layoutInflater.inflate( + R.layout.activity_bookmark_topic_row, bookmarksLinearView, false); + row.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Activity activity = getActivity(); + if (activity instanceof BookmarkActivity) { + ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_CLICK_TOPIC_BOOKMARK, bookmarkedTopic); + } + } + }); + ((TextView) row.findViewById(R.id.bookmark_title)).setText(bookmarkedTopic.getTitle()); + + final ImageButton notificationsEnabledButton = row.findViewById(R.id.toggle_notification); + if (!bookmarkedTopic.isNotificationsEnabled()) { + notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); + } + + notificationsEnabledButton.setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Activity activity = getActivity(); + if (activity instanceof BookmarkActivity) { + if (((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_TOGGLE_TOPIC_NOTIFICATION, bookmarkedTopic)) { + notificationsEnabledButton.setImageDrawable(notificationsEnabledButtonImage); + } else { + notificationsEnabledButton.setImageDrawable(notificationsDisabledButtonImage); + } + } + } + }); + (row.findViewById(R.id.remove_bookmark)).setOnClickListener(new View.OnClickListener() { + @Override + public void onClick(View view) { + Activity activity = getActivity(); + if (activity instanceof BookmarkActivity) { + ((BookmarkActivity) activity).onTopicInteractionListener(INTERACTION_REMOVE_TOPIC_BOOKMARK, bookmarkedTopic); + topicBookmarks.remove(bookmarkedTopic); + } + row.setVisibility(View.GONE); + + if (topicBookmarks.isEmpty()){ + bookmarksLinearView.addView(bookmarksListEmptyMessage()); + } + } + }); + bookmarksLinearView.addView(row); + } + } + } else { + bookmarksLinearView.addView(bookmarksListEmptyMessage()); + } + + + return rootView; + } + + private TextView bookmarksListEmptyMessage() { + TextView emptyBookmarksCategory = new TextView(this.getContext()); + LinearLayout.LayoutParams params = new LinearLayout.LayoutParams( + LinearLayout.LayoutParams.MATCH_PARENT, LinearLayout.LayoutParams.WRAP_CONTENT); + params.setMargins(0, 12, 0, 0); + emptyBookmarksCategory.setLayoutParams(params); + emptyBookmarksCategory.setText(getString(R.string.empty_topic_bookmarks)); + emptyBookmarksCategory.setTypeface(emptyBookmarksCategory.getTypeface(), Typeface.BOLD); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) { + emptyBookmarksCategory.setTextColor(this.getContext().getColor(R.color.primary_text)); + } else { + //noinspection deprecation + emptyBookmarksCategory.setTextColor(this.getContext().getResources().getColor(R.color.primary_text)); + } + emptyBookmarksCategory.setTextAlignment(View.TEXT_ALIGNMENT_CENTER); + return emptyBookmarksCategory; + } +} diff --git a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java index 5a98d618..9150065d 100644 --- a/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java +++ b/app/src/main/java/gr/thmmy/mthmmy/base/BaseActivity.java @@ -42,7 +42,7 @@ import java.util.ArrayList; import gr.thmmy.mthmmy.R; import gr.thmmy.mthmmy.activities.AboutActivity; -import gr.thmmy.mthmmy.activities.BookmarkActivity; +import gr.thmmy.mthmmy.activities.bookmarks.BookmarkActivity; import gr.thmmy.mthmmy.activities.LoginActivity; import gr.thmmy.mthmmy.activities.downloads.DownloadsActivity; import gr.thmmy.mthmmy.activities.main.MainActivity; diff --git a/app/src/main/res/layout/activity_bookmark.xml b/app/src/main/res/layout/activity_bookmark.xml index a12e5e68..03bee885 100644 --- a/app/src/main/res/layout/activity_bookmark.xml +++ b/app/src/main/res/layout/activity_bookmark.xml @@ -21,25 +21,26 @@ android:layout_width="match_parent" android:layout_height="?attr/actionBarSize" android:background="?attr/colorPrimary" + android:gravity="center" app:popupTheme="@style/ToolbarTheme"> + + - - - - + app:layout_behavior="@string/appbar_scrolling_view_behavior"/> + + + + + + + \ No newline at end of file diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index a4543e86..f95c254d 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -72,8 +72,8 @@ Remove - Boards - Topics + You have no bookmarked boards + You have no bookmarked topics @@ -100,4 +100,7 @@ Cancel Open Download + + + Hello blank fragment