Search in sources :

Example 1 with GroupDetailActivity

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();
    }
}
Also used : Bundle(android.os.Bundle) Intent(android.content.Intent) DetailFragment(com.polito.mad17.madmax.activities.DetailFragment) BarDetailFragment(com.polito.mad17.madmax.activities.BarDetailFragment)

Example 2 with GroupDetailActivity

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;
}
Also used : User(com.polito.mad17.madmax.entities.User) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) DatabaseError(com.google.firebase.database.DatabaseError) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 3 with GroupDetailActivity

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;
}
Also used : GroupsViewAdapter(com.polito.mad17.madmax.activities.groups.GroupsViewAdapter) Bundle(android.os.Bundle) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ViewPager(android.support.v4.view.ViewPager) FragmentPagerAdapter(android.support.v4.app.FragmentPagerAdapter) DatabaseError(com.google.firebase.database.DatabaseError) TabLayout(android.support.design.widget.TabLayout) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener)

Example 4 with GroupDetailActivity

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);
    }
}
Also used : Intent(android.content.Intent) MainActivity(com.polito.mad17.madmax.activities.MainActivity)

Aggregations

Bundle (android.os.Bundle)3 Intent (android.content.Intent)2 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)2 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 DataSnapshot (com.google.firebase.database.DataSnapshot)2 DatabaseError (com.google.firebase.database.DatabaseError)2 ValueEventListener (com.google.firebase.database.ValueEventListener)2 FloatingActionButton (android.support.design.widget.FloatingActionButton)1 TabLayout (android.support.design.widget.TabLayout)1 FragmentPagerAdapter (android.support.v4.app.FragmentPagerAdapter)1 ViewPager (android.support.v4.view.ViewPager)1 BarDetailFragment (com.polito.mad17.madmax.activities.BarDetailFragment)1 DetailFragment (com.polito.mad17.madmax.activities.DetailFragment)1 MainActivity (com.polito.mad17.madmax.activities.MainActivity)1 GroupsViewAdapter (com.polito.mad17.madmax.activities.groups.GroupsViewAdapter)1 User (com.polito.mad17.madmax.entities.User)1