use of com.polito.mad17.madmax.activities.groups.GroupDetailActivity in project MadMax by deviz92.
the class GroupDetailActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.app_bar_main);
databaseReference = FirebaseDatabase.getInstance().getReference();
Intent intent = getIntent();
groupID = intent.getStringExtra("groupID");
userID = intent.getStringExtra("userID");
Log.d(TAG, "onCreate di GroupDetailActivity. Group: " + groupID);
Bundle bundle = new Bundle();
bundle.putString("groupID", groupID);
bundle.putString("userID", userID);
if (findViewById(R.id.collapsed_content) != null) {
Log.d(TAG, groupID);
barDetailFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.collapsed_content, barDetailFragment).commit();
}
if (findViewById(R.id.main) != null) {
Log.d(TAG, groupID);
DetailFragment detailFragment = new DetailFragment();
detailFragment.setArguments(bundle);
getSupportFragmentManager().beginTransaction().replace(R.id.main, detailFragment).commit();
}
}
use of com.polito.mad17.madmax.activities.groups.GroupDetailActivity in project MadMax by deviz92.
the class FriendsFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
final String activityName = getActivity().getClass().getSimpleName();
Log.d(TAG, "Sono nella activity: " + activityName);
final View view = inflater.inflate(R.layout.skeleton_list, container, false);
databaseReference = FirebaseDatabase.getInstance().getReference();
friends.clear();
setInterface((OnItemClickInterface) getActivity(), (OnItemLongClickInterface) getActivity());
RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(ContextCompat.getColor(getContext(), R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
recyclerView = (RecyclerView) view.findViewById(R.id.rv_skeleton);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(divider);
friendsViewAdapter = new FriendsViewAdapter(this.getContext(), this, this, friends, groupDetail);
recyclerView.setAdapter(friendsViewAdapter);
// Se sono in MainActivity visualizzo lista degli amici
if (activityName.equals("MainActivity")) {
query = databaseReference.child("users").child(MainActivity.getCurrentUID()).child("friends");
} else // Se sono dentro un gruppo, visualizzo lista membri del gruppo
if (activityName.equals("GroupDetailActivity")) {
Bundle b = this.getArguments();
if (b != null) {
groupID = b.getString("groupID");
query = databaseReference.child("groups").child(groupID).child("members");
}
}
Log.d(TAG, "query: " + query);
groupMembersListener = query.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(final DataSnapshot externalDataSnapshot) {
// svuoto la map, così se viene eliminato uno user dal db, non viene tenuto nella map che si ricarica da zero
friends.clear();
for (final DataSnapshot friendSnapshot : externalDataSnapshot.getChildren()) {
// getFriend(friendSnapshot.getKey());
if (activityName.equals("MainActivity")) {
Log.d(TAG, "key: " + friendSnapshot.getKey());
Log.d(TAG, "value: " + friendSnapshot.getValue());
if (!listenedFriends)
listenedFriends = true;
// Log.d(TAG, friendSnapshot.child("deleted").getValue() + " ");
deleted = friendSnapshot.child("deleted").getValue(Boolean.class);
if (deleted == null) {
deleted = true;
}
if (deleted)
Log.d(TAG, friendSnapshot.getKey() + " is cancelled");
} else if (activityName.equals("GroupDetailActivity")) {
deleted = friendSnapshot.child("deleted").getValue(Boolean.class);
if (deleted == null) {
deleted = true;
}
// Se sono negli amici "generali" e non nei membri di un gruppo, non c'è il campo deleted, quindi sarà null
if (!listenedGroups.contains(groupID))
listenedGroups.add(groupID);
}
if (!deleted) {
final String id = friendSnapshot.getKey();
databaseReference.child("users").child(id).addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String name = dataSnapshot.child("name").getValue(String.class);
String surname = dataSnapshot.child("surname").getValue(String.class);
String profileImage = dataSnapshot.child("image").getValue(String.class);
if (activityName.equals("MainActivity")) {
User u = new User();
u.setID(friendSnapshot.getKey());
u.setName(name);
u.setSurname(surname);
u.setProfileImage(profileImage);
if (!deleted)
friends.put(id, u);
else
friends.remove(id);
friendsViewAdapter.update(friends);
friendsViewAdapter.notifyDataSetChanged();
} else if (activityName.equals("GroupDetailActivity")) {
getUserAndGroupBalance(id, name, surname, profileImage, groupID);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
}
friendsViewAdapter.update(friends);
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.w(TAG, databaseError.getMessage());
}
});
Log.d(TAG, "dopo setAdapter");
return view;
}
use of com.polito.mad17.madmax.activities.groups.GroupDetailActivity in project MadMax by deviz92.
the class DetailFragment method onCreateView.
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
// create the view to return
View mainView = null;
// get the bundle
Bundle bundle = this.getArguments();
// the listener will be the GroupDetailActivity or the FriendDetailActivity
setInterface((OnItemClickInterface) getActivity());
databaseReference = FirebaseDatabase.getInstance().getReference();
// when an item in the list will be clicked the onListItemClicked will be called
groupsViewAdapter = new GroupsViewAdapter(this.getContext(), this, groups, DetailFragment.TAG);
if (activityName.equals("FriendDetailActivity")) {
Log.d(TAG, "FriendDetailActivity per RecylerView");
// Inflate the layout for this fragment
mainView = inflater.inflate(R.layout.skeleton_list_friend, container, false);
RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(ContextCompat.getColor(getContext(), R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
recyclerView = (RecyclerView) mainView.findViewById(R.id.rv_skeleton);
layoutManager = new LinearLayoutManager(getActivity(), LinearLayoutManager.VERTICAL, false);
recyclerView.setLayoutManager(layoutManager);
recyclerView.addItemDecoration(divider);
recyclerView.setAdapter(groupsViewAdapter);
// Extract data from bundle
friendID = bundle.getString("friendID");
// Show shared groups
databaseReference.child("users").child(MainActivity.getCurrentUser().getID()).child("friends").child(friendID).child("sharedGroups").addListenerForSingleValueEvent(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot sharedGroupSnapshot : dataSnapshot.getChildren()) {
FirebaseUtils.getInstance().getGroup(sharedGroupSnapshot.getKey(), groups, groupsViewAdapter);
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
} else if (activityName.equals("GroupDetailActivity")) {
groupID = bundle.getString("groupID");
mainView = inflater.inflate(R.layout.fragment_group_detail, container, false);
fab = (FloatingActionButton) getActivity().findViewById(R.id.fab);
fab.setImageResource(android.R.drawable.ic_input_add);
TabLayout tabLayout = (TabLayout) mainView.findViewById(R.id.tab_layout);
tabLayout.addTab(tabLayout.newTab().setText(R.string.expenses));
tabLayout.addTab(tabLayout.newTab().setText(R.string.members));
tabLayout.addTab(tabLayout.newTab().setText(R.string.activities));
tabLayout.setTabGravity(TabLayout.GRAVITY_FILL);
updateFab(0);
final ViewPager viewPager = (ViewPager) mainView.findViewById(R.id.main_view_pager);
final DetailFragment.PagerAdapter adapter = new DetailFragment.PagerAdapter(getActivity().getSupportFragmentManager(), tabLayout.getTabCount());
viewPager.setAdapter(adapter);
viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(tabLayout));
tabLayout.addOnTabSelectedListener(new TabLayout.OnTabSelectedListener() {
@Override
public void onTabSelected(TabLayout.Tab tab) {
Log.d(TAG, "selected tab " + tab.getPosition());
updateFab(tab.getPosition());
viewPager.setCurrentItem(tab.getPosition());
}
@Override
public void onTabUnselected(TabLayout.Tab tab) {
}
@Override
public void onTabReselected(TabLayout.Tab tab) {
}
});
}
return mainView;
}
use of com.polito.mad17.madmax.activities.groups.GroupDetailActivity in project MadMax by deviz92.
the class GroupDetailActivity method onOptionsItemSelected.
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Intent intent;
Log.d(TAG, "Clicked item: " + item.getItemId());
switch(item.getItemId()) {
case R.id.one:
Log.d(TAG, "clicked Modify group");
intent = new Intent(this, GroupEdit.class);
intent.putExtra("groupID", groupID);
startActivity(intent);
finish();
return true;
case R.id.two:
Log.d(TAG, "clicked Remove group");
FirebaseUtils.getInstance().removeGroupFirebase(userID, groupID, getApplicationContext());
finish();
return true;
case android.R.id.home:
Log.d(TAG, "Clicked up button on GroupDetailActivity");
intent = new Intent(this, MainActivity.class);
intent.putExtra("UID", MainActivity.getCurrentUser().getID());
intent.putExtra("currentFragment", 1);
startActivity(intent);
finish();
return (true);
default:
return super.onOptionsItemSelected(item);
}
}
Aggregations