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());
}
});
}
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());
}
});
}
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;
}
Aggregations