Search in sources :

Example 1 with GroupsViewAdapter

use of com.polito.mad17.madmax.activities.groups.GroupsViewAdapter in project MadMax by deviz92.

the class ChooseGroupActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    Log.d(TAG, "onCreate");
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_choose_group);
    RecyclerView.ItemDecoration divider = new InsetDivider.Builder(this).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(getResources().getColor(R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
    recyclerView = (RecyclerView) findViewById(R.id.rv_skeleton);
    layoutManager = new LinearLayoutManager(this, LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(divider);
    groupsViewAdapter = new GroupsViewAdapter(getBaseContext(), this, groups, ChooseGroupActivity.TAG);
    recyclerView.setAdapter(groupsViewAdapter);
    //Ascolto i gruppi dello user
    databaseReference.child("users").child(MainActivity.getCurrentUser().getID()).child("groups").addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            //Per ogni gruppo dello user
            for (DataSnapshot groupSnapshot : dataSnapshot.getChildren()) {
                //Se il gruppo è true, ossia è ancora tra quelli dello user
                if (groupSnapshot.getValue(Boolean.class))
                    FirebaseUtils.getInstance().getGroup(groupSnapshot.getKey(), groups, groupsViewAdapter);
                else {
                    //tolgo il gruppo da quelli che verranno stampati, così lo vedo sparire realtime
                    groups.remove(groupSnapshot.getKey());
                    groupsViewAdapter.update(groups);
                    groupsViewAdapter.notifyDataSetChanged();
                }
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
            Log.w(TAG, databaseError.toException());
        }
    });
}
Also used : GroupsViewAdapter(com.polito.mad17.madmax.activities.groups.GroupsViewAdapter) DatabaseError(com.google.firebase.database.DatabaseError) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot)

Example 2 with GroupsViewAdapter

use of com.polito.mad17.madmax.activities.groups.GroupsViewAdapter in project MadMax by deviz92.

the class FriendDetailActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_friend_detail);
    Log.d(TAG, "onCreate di FriendDetailActivity");
    //ID dell'amico di cui sto guardando il dettaglio
    Intent intent = getIntent();
    friendID = intent.getStringExtra("friendID");
    userID = intent.getStringExtra("userID");
    toolbar = (Toolbar) findViewById(R.id.fd_toolbar);
    setSupportActionBar(toolbar);
    toolbar.setBackgroundColor(0x0000FF00);
    // Get a support ActionBar corresponding to this toolbar
    ActionBar ab = getSupportActionBar();
    // Enable the Up button
    ab.setDisplayHomeAsUpEnabled(true);
    //Set data of upper part of Activity
    imageView = (ImageView) findViewById(R.id.img_photo);
    nameTextView = (TextView) findViewById(R.id.tv_friend_name);
    balanceTextView = (TextView) findViewById(R.id.tv_balance);
    balanceTextTextView = (TextView) findViewById(R.id.tv_balance_text);
    RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getApplicationContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(ContextCompat.getColor(getApplicationContext(), R.color.colorDivider)).insets(getResources().getDimensionPixelSize(R.dimen.divider_inset), 0).overlay(true).build();
    recyclerView = (RecyclerView) findViewById(R.id.rv_skeleton);
    layoutManager = new LinearLayoutManager(getApplicationContext(), LinearLayoutManager.VERTICAL, false);
    recyclerView.setLayoutManager(layoutManager);
    recyclerView.addItemDecoration(divider);
    groupsViewAdapter = new GroupsViewAdapter(getApplicationContext(), this, this, groups, FriendDetailActivity.TAG);
    recyclerView.setAdapter(groupsViewAdapter);
    //Show data of friend
    databaseReference.child("users").child(friendID).addListenerForSingleValueEvent(new ValueEventListener() {

        @Override
        public void onDataChange(DataSnapshot dataSnapshot) {
            String name = dataSnapshot.child("name").getValue(String.class);
            String surname = dataSnapshot.child("surname").getValue(String.class);
            nameTextView.setText(name + " " + surname);
            if (!dataSnapshot.child("image").getValue(String.class).equals("")) {
            //                    imageView.setImageURI(dataSnapshot.child("image").getValue(String.class));
            }
        }

        @Override
        public void onCancelled(DatabaseError databaseError) {
        }
    });
    Log.d(TAG, "Populated all the above data");
    if (findViewById(R.id.collapsed_content) != null) {
        Bundle bundle = new Bundle();
        bundle.putString("friendID", friendID);
        Log.d(TAG, friendID);
        BarDetailFragment barDetailFragment = new BarDetailFragment();
        barDetailFragment.setArguments(bundle);
        getSupportFragmentManager().beginTransaction().replace(R.id.collapsed_content, barDetailFragment).commit();
        DetailFragment detailFragment = new DetailFragment();
        detailFragment.setArguments(bundle);
        getSupportFragmentManager().beginTransaction().replace(R.id.main, detailFragment).commit();
    }
    //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) {
            Log.w(TAG, databaseError.toException());
        }
    });
}
Also used : GroupsViewAdapter(com.polito.mad17.madmax.activities.groups.GroupsViewAdapter) Bundle(android.os.Bundle) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) DataSnapshot(com.google.firebase.database.DataSnapshot) DatabaseError(com.google.firebase.database.DatabaseError) BarDetailFragment(com.polito.mad17.madmax.activities.BarDetailFragment) RecyclerView(android.support.v7.widget.RecyclerView) ValueEventListener(com.google.firebase.database.ValueEventListener) DetailFragment(com.polito.mad17.madmax.activities.DetailFragment) BarDetailFragment(com.polito.mad17.madmax.activities.BarDetailFragment) ActionBar(android.support.v7.app.ActionBar)

Example 3 with GroupsViewAdapter

use of com.polito.mad17.madmax.activities.groups.GroupsViewAdapter 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")) {
        // Inflate the layout for this fragment
        mainView = inflater.inflate(R.layout.shared_groups_list, container, false);
        RecyclerView.ItemDecoration divider = new InsetDivider.Builder(getContext()).orientation(InsetDivider.VERTICAL_LIST).dividerHeight(getResources().getDimensionPixelSize(R.dimen.divider_height)).color(getResources().getColor(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)

Aggregations

LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)3 RecyclerView (android.support.v7.widget.RecyclerView)3 DataSnapshot (com.google.firebase.database.DataSnapshot)3 DatabaseError (com.google.firebase.database.DatabaseError)3 ValueEventListener (com.google.firebase.database.ValueEventListener)3 GroupsViewAdapter (com.polito.mad17.madmax.activities.groups.GroupsViewAdapter)3 Bundle (android.os.Bundle)2 Intent (android.content.Intent)1 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 ActionBar (android.support.v7.app.ActionBar)1 View (android.view.View)1 BarDetailFragment (com.polito.mad17.madmax.activities.BarDetailFragment)1 DetailFragment (com.polito.mad17.madmax.activities.DetailFragment)1