Android - People - Sliding panel (for users actions)

This commit is contained in:
Cristian Luis Duarte 2018-08-13 20:32:45 -03:00
parent b381a182bd
commit 1bfd6fe97d
7 changed files with 93 additions and 13 deletions

View file

@ -144,5 +144,7 @@ dependencies {
compile 'com.squareup.retrofit2:converter-gson:2.4.0' compile 'com.squareup.retrofit2:converter-gson:2.4.0'
implementation 'com.squareup.picasso:picasso:2.71828' implementation 'com.squareup.picasso:picasso:2.71828'
compile 'com.sothree.slidinguppanel:library:3.4.0'
implementation fileTree(include: ['*.jar'], dir: 'libs') implementation fileTree(include: ['*.jar'], dir: 'libs')
} }

View file

@ -150,7 +150,8 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
private void loadFragment(Fragment fragment, String title, boolean addToBackStack) { private void loadFragment(Fragment fragment, String title, boolean addToBackStack) {
FragmentManager fragmentManager = getFragmentManager(); FragmentManager fragmentManager = getFragmentManager();
FragmentTransaction ft = fragmentManager.beginTransaction(); FragmentTransaction ft = fragmentManager.beginTransaction();
ft.replace(R.id.content_frame, fragment); ft.replace(R.id.content_frame, fragment, getString(R.string.tagFragmentPeople));
if (addToBackStack) { if (addToBackStack) {
ft.addToBackStack(title); ft.addToBackStack(title);
} }
@ -297,6 +298,15 @@ public class MainActivity extends AppCompatActivity implements NavigationView.On
@Override @Override
public void onBackPressed() { public void onBackPressed() {
// if a fragment needs to internally manage back presses..
FragmentManager fm = getFragmentManager();
Fragment friendsFragment = fm.findFragmentByTag(getString(R.string.tagFragmentPeople));
if (friendsFragment != null && friendsFragment instanceof FriendsFragment) {
if (((FriendsFragment) friendsFragment).onBackPressed()) {
return;
}
}
int index = getFragmentManager().getBackStackEntryCount() - 1; int index = getFragmentManager().getBackStackEntryCount() - 1;
if (index > 0) { if (index > 0) {
super.onBackPressed(); super.onBackPressed();

View file

@ -10,6 +10,8 @@ import android.view.LayoutInflater;
import android.view.View; import android.view.View;
import android.view.ViewGroup; import android.view.ViewGroup;
import com.sothree.slidinguppanel.SlidingUpPanelLayout;
import io.highfidelity.hifiinterface.R; import io.highfidelity.hifiinterface.R;
import io.highfidelity.hifiinterface.view.UserListAdapter; import io.highfidelity.hifiinterface.view.UserListAdapter;
@ -20,7 +22,9 @@ public class FriendsFragment extends Fragment {
public native String nativeGetAccessToken(); public native String nativeGetAccessToken();
private RecyclerView mUsersView; private RecyclerView mUsersView;
private View mUserActions;
private UserListAdapter mUsersAdapter; private UserListAdapter mUsersAdapter;
private SlidingUpPanelLayout mSlidingUpPanelLayout;
public FriendsFragment() { public FriendsFragment() {
// Required empty public constructor // Required empty public constructor
@ -45,9 +49,44 @@ public class FriendsFragment extends Fragment {
GridLayoutManager gridLayoutMgr = new GridLayoutManager(getContext(), numberOfColumns); GridLayoutManager gridLayoutMgr = new GridLayoutManager(getContext(), numberOfColumns);
mUsersView.setLayoutManager(gridLayoutMgr); mUsersView.setLayoutManager(gridLayoutMgr);
mUsersAdapter = new UserListAdapter(getContext(), accessToken); mUsersAdapter = new UserListAdapter(getContext(), accessToken);
mUserActions = rootView.findViewById(R.id.userActionsLayout);
mSlidingUpPanelLayout = rootView.findViewById(R.id.sliding_layout);
mSlidingUpPanelLayout.setPanelHeight(0);
mUsersAdapter.setClickListener(new UserListAdapter.ItemClickListener() {
@Override
public void onItemClick(View view, int position, UserListAdapter.User user) {
// 1. 'select' user
// ..
// 2. adapt options
// ..
// 3. show
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.EXPANDED);
}
});
mUsersView.setAdapter(mUsersAdapter); mUsersView.setAdapter(mUsersAdapter);
mSlidingUpPanelLayout.setFadeOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
}
});
return rootView; return rootView;
} }
/**
* Processes the back pressed event and returns true if it was managed by this Fragment
* @return
*/
public boolean onBackPressed() {
if (mSlidingUpPanelLayout.getPanelState().equals(SlidingUpPanelLayout.PanelState.EXPANDED)) {
mSlidingUpPanelLayout.setPanelState(SlidingUpPanelLayout.PanelState.COLLAPSED);
return true;
} else {
return false;
}
}
} }

View file

@ -34,6 +34,7 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.ViewHo
private LayoutInflater mInflater; private LayoutInflater mInflater;
private Context mContext; private Context mContext;
private List<User> mUsers = new ArrayList<>(); private List<User> mUsers = new ArrayList<>();
private ItemClickListener mClickListener;
public UserListAdapter(Context c, String accessToken) { public UserListAdapter(Context c, String accessToken) {
mContext = c; mContext = c;
@ -99,7 +100,7 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.ViewHo
return mUsers.size(); return mUsers.size();
} }
public class ViewHolder extends RecyclerView.ViewHolder { public class ViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
TextView mUsername; TextView mUsername;
TextView mOnline; TextView mOnline;
@ -114,7 +115,23 @@ public class UserListAdapter extends RecyclerView.Adapter<UserListAdapter.ViewHo
mImage = itemView.findViewById(R.id.userImage); mImage = itemView.findViewById(R.id.userImage);
mOnlineInfo = itemView.findViewById(R.id.userOnlineInfo); mOnlineInfo = itemView.findViewById(R.id.userOnlineInfo);
mLocation = itemView.findViewById(R.id.userLocation); mLocation = itemView.findViewById(R.id.userLocation);
itemView.setOnClickListener(this);
} }
@Override
public void onClick(View view) {
int position = getAdapterPosition();
if (mClickListener != null) mClickListener.onItemClick(view, position, mUsers.get(position));
}
}
// allows clicks events to be caught
public void setClickListener(ItemClickListener itemClickListener) {
this.mClickListener = itemClickListener;
}
public interface ItemClickListener {
void onItemClick(View view, int position, User user);
} }
public static class User { public static class User {

View file

@ -1,21 +1,29 @@
<?xml version="1.0" encoding="utf-8"?> <?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android" <com.sothree.slidinguppanel.SlidingUpPanelLayout xmlns:sothree="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:id="@+id/sliding_layout"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent"
android:background="@color/backgroundLight"> android:gravity="bottom"
sothree:umanoShadowHeight="4dp"
android:background="@color/backgroundLight">
<!--sothree:umanoPanelHeight="68dp"-->
<android.support.v7.widget.RecyclerView <android.support.v7.widget.RecyclerView
android:id="@+id/rvUsers" android:id="@+id/rvUsers"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
android:paddingTop="@dimen/list_vertical_padding" android:paddingTop="@dimen/list_vertical_padding"
android:paddingBottom="@dimen/list_vertical_padding" android:paddingBottom="@dimen/list_vertical_padding"
android:clipToPadding="false" android:clipToPadding="false"
android:layout_width="0dp" android:layout_width="match_parent"
android:layout_height="0dp" /> android:layout_height="match_parent" />
</android.support.constraint.ConstraintLayout> <LinearLayout
android:id="@+id/userActionsLayout"
android:layout_width="match_parent"
android:layout_height="270dp"
android:orientation="vertical"
android:background="@color/backgroundDark"
>
</LinearLayout>
</com.sothree.slidinguppanel.SlidingUpPanelLayout>

View file

@ -24,4 +24,7 @@
<string name="privacyPolicy">Privacy Policy</string> <string name="privacyPolicy">Privacy Policy</string>
<string name="your_last_location">Your Last Location</string> <string name="your_last_location">Your Last Location</string>
<string name="online">Online</string> <string name="online">Online</string>
<!-- tags -->
<string name="tagFragmentPeople">tagFragmentPeople</string>
</resources> </resources>

View file

@ -28,6 +28,7 @@ allprojects {
repositories { repositories {
jcenter() jcenter()
google() google()
mavenCentral()
} }
} }