From 3f3fa95d720eb4d43e2a4a493951c6f45f19d1af Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Wed, 22 Aug 2018 10:40:49 +0200 Subject: [PATCH] Added update conversation settings button --- .../ui/fragments/ConversationFragment.java | 29 +++--- .../comunic/client/ui/views/AppBarLayout.java | 89 +++++++++++++++++++ app/src/main/res/drawable/ic_settings.xml | 9 ++ .../main/res/layout/fragment_conversation.xml | 19 ++-- app/src/main/res/layout/view_appbarlayout.xml | 16 ++++ 5 files changed, 133 insertions(+), 29 deletions(-) create mode 100644 app/src/main/java/org/communiquons/android/comunic/client/ui/views/AppBarLayout.java create mode 100644 app/src/main/res/drawable/ic_settings.xml create mode 100644 app/src/main/res/layout/view_appbarlayout.xml diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java index db42690..f6ead57 100644 --- a/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/fragments/ConversationFragment.java @@ -1,10 +1,6 @@ package org.communiquons.android.comunic.client.ui.fragments; import android.app.AlertDialog; -import android.graphics.PorterDuff; -import android.graphics.drawable.Drawable; -import android.support.design.widget.AppBarLayout; -import android.support.v4.app.Fragment; import android.content.DialogInterface; import android.content.Intent; import android.graphics.Bitmap; @@ -12,10 +8,8 @@ import android.os.AsyncTask; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.Nullable; -import android.support.v7.app.ActionBarDrawerToggle; +import android.support.v4.app.Fragment; import android.support.v7.widget.LinearLayoutManager; -import android.support.v7.widget.RecyclerView; -import android.support.v7.widget.Toolbar; import android.util.ArrayMap; import android.util.Log; import android.view.KeyEvent; @@ -44,6 +38,7 @@ import org.communiquons.android.comunic.client.ui.adapters.ConversationMessageAd import org.communiquons.android.comunic.client.ui.listeners.OnScrollChangeDetectListener; import org.communiquons.android.comunic.client.ui.utils.BitmapUtils; import org.communiquons.android.comunic.client.ui.utils.UiUtils; +import org.communiquons.android.comunic.client.ui.views.AppBarLayout; import org.communiquons.android.comunic.client.ui.views.ScrollRecyclerView; import java.io.FileNotFoundException; @@ -107,7 +102,7 @@ public class ConversationFragment extends Fragment /** * Fragment toolbar */ - private Toolbar mToolbar; + private AppBarLayout mAppBar; /** * Fragment main progress bar @@ -239,23 +234,26 @@ public class ConversationFragment extends Fragment //Get views convMessRecyclerView = view.findViewById(R.id.fragment_conversation_messageslist); - mToolbar = view.findViewById(R.id.toolbar); + mAppBar = view.findViewById(R.id.appbar); //Need user ID int userID = new AccountUtils(getActivity()).get_current_user_id(); //Initialize toolbar - Drawable backDrawable = UiUtils.getDrawable(getActivity(), R.drawable.ic_back); - backDrawable.setColorFilter(UiUtils.getColor(getActivity(), android.R.color.white), - PorterDuff.Mode.SRC_IN); - mToolbar.setNavigationIcon(backDrawable); - mToolbar.setNavigationOnClickListener(new View.OnClickListener() { + mAppBar.addBackButton(new View.OnClickListener() { @Override public void onClick(View v) { MainActivity.goBackward(getActivity()); } }); + mAppBar.addButton(R.drawable.ic_settings, new View.OnClickListener() { + @Override + public void onClick(View v) { + ((MainActivity)getActivity()).updateConversation(conversation_id); + } + }); + //Create the adapter convMessAdapter = new ConversationMessageAdapter(getActivity(), @@ -317,6 +315,7 @@ public class ConversationFragment extends Fragment //Set a listener to detect when the user reaches the top of the conversation convMessRecyclerView.setOnScrollChangeDetectListener(this); + } @Override @@ -645,7 +644,7 @@ public class ConversationFragment extends Fragment return; getActivity().setTitle(title); - mToolbar.setTitle(title); + mAppBar.setTitle(title); } /** diff --git a/app/src/main/java/org/communiquons/android/comunic/client/ui/views/AppBarLayout.java b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/AppBarLayout.java new file mode 100644 index 0000000..40ba407 --- /dev/null +++ b/app/src/main/java/org/communiquons/android/comunic/client/ui/views/AppBarLayout.java @@ -0,0 +1,89 @@ +package org.communiquons.android.comunic.client.ui.views; + +import android.content.Context; +import android.graphics.PorterDuff; +import android.graphics.drawable.Drawable; +import android.support.annotation.NonNull; +import android.support.annotation.Nullable; +import android.support.v7.widget.AppCompatImageButton; +import android.support.v7.widget.Toolbar; +import android.util.AttributeSet; +import android.view.View; + +import org.communiquons.android.comunic.client.R; +import org.communiquons.android.comunic.client.ui.utils.UiUtils; + +/** + * Generic AppBarLayout base class for the fragments of this application + */ +public class AppBarLayout extends BaseFrameLayoutView { + + private android.support.design.widget.AppBarLayout mAppBarLayout; + private Toolbar mToolbar; + + public AppBarLayout(@NonNull Context context) { + this(context, null); + } + + public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs) { + this(context, attrs, 0); + } + + public AppBarLayout(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) { + super(context, attrs, defStyleAttr); + + //Set the view + View view = inflate(getContext(), R.layout.view_appbarlayout, this); + mAppBarLayout = view.findViewById(R.id.app_bar_layout); + mToolbar = view.findViewById(R.id.toolbar); + } + + /** + * @return Toolbar view + */ + public Toolbar getToolbar() { + return mToolbar; + } + + /** + * Update the title of the appbar + * + * @param title The new title + */ + public void setTitle(String title){ + mToolbar.setTitle(title); + } + + /** + * Add back button to the view + * + * @param listener The listener to use when the button is clicked + */ + public void addBackButton(View.OnClickListener listener){ + Drawable backDrawable = UiUtils.getDrawable(getActivity(), R.drawable.ic_back); + backDrawable.setColorFilter(UiUtils.getColor(getActivity(), android.R.color.white), + PorterDuff.Mode.SRC_IN); + mToolbar.setNavigationIcon(backDrawable); + mToolbar.setNavigationOnClickListener(listener); + } + + /** + * Add a button to the toolbar + * + * @param icon The icon associated to the button + * @param listener OnClickListener for the button + */ + public void addButton(int icon, @Nullable OnClickListener listener) { + + Drawable drawable = UiUtils.getDrawable(getContext(), icon); + drawable.setColorFilter(UiUtils.getColor(getContext(), android.R.color.white), + PorterDuff.Mode.SRC_IN); + + AppCompatImageButton btn = new AppCompatImageButton(getActivity(), + null, android.support.v7.appcompat.R.attr.toolbarStyle); + btn.setPadding(5, 0, 5, 0); + btn.setImageDrawable(drawable); + btn.setOnClickListener(listener); + getToolbar().addView(btn); + } +} diff --git a/app/src/main/res/drawable/ic_settings.xml b/app/src/main/res/drawable/ic_settings.xml new file mode 100644 index 0000000..d463e92 --- /dev/null +++ b/app/src/main/res/drawable/ic_settings.xml @@ -0,0 +1,9 @@ + + + diff --git a/app/src/main/res/layout/fragment_conversation.xml b/app/src/main/res/layout/fragment_conversation.xml index 68cebeb..14f05b5 100644 --- a/app/src/main/res/layout/fragment_conversation.xml +++ b/app/src/main/res/layout/fragment_conversation.xml @@ -1,8 +1,7 @@ + android:layout_height="match_parent"> - + - - - - + android:layout_height="wrap_content" /> + + + + + \ No newline at end of file