Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class HomePage extends AppCompatActivity {
- private Drawer result = null;
- private Boolean isCoverEdit = false, isProfileEdit = false;
- String username;
- private RelativeLayout splash;
- private Toolbar toolbar;
- private StorageReference mStorage;
- private ProgressDialog progressDialog;
- private ImageView searchBtn;
- private AHBottomNavigationViewPager fragContainer;
- private AHBottomNavigation bottomNavigation;
- private ImageView postBtn;
- private View child;
- private ImageView cover;
- private CircleImageView profilePic;
- private TextView star;
- private TextView id;
- private PopupMenu p;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_home_page);
- if (FirebaseAuth.getInstance().getCurrentUser() == null) {
- Intent i = new Intent(HomePage.this, Login.class);
- startActivity(i);
- finish();
- } else {
- getUsername();
- initiateViews();
- setupOnClickListeners();
- setupBottomNavigation();
- mStorage = FirebaseStorage.getInstance().getReference();
- progressDialog = new ProgressDialog(this);
- }
- }
- private void initiateViews() {
- splash = findViewById(R.id.splash);
- searchBtn = findViewById(R.id.search);
- fragContainer = findViewById(R.id.frame);
- toolbar = findViewById(R.id.toolbar);
- bottomNavigation = findViewById(R.id.bottom_navigation);
- postBtn = findViewById(R.id.post);
- child = getLayoutInflater().inflate(R.layout.header, null);
- profilePic = child.findViewById(R.id.pic);
- id = child.findViewById(R.id.id);
- cover = child.findViewById(R.id.cover);
- star = child.findViewById(R.id.karma);
- }
- private void getUsername() {
- username = new UserData(this).getUsername();
- if (username==null){
- FirebaseDatabase.getInstance().getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("username").addListenerForSingleValueEvent(new ValueEventListener() {
- @Override
- public void onDataChange(DataSnapshot dataSnapshot) {
- username = dataSnapshot.getValue(String.class);
- SharedPreferences settings = getSharedPreferences("AyePref", MODE_PRIVATE);
- SharedPreferences.Editor editor = settings.edit();
- editor.putString("username", username);
- editor.apply();
- setupNavigationDrawer();
- FirebaseDatabase.getInstance().getReference().child("userdata").child(username).child("token").setValue(FirebaseInstanceId.getInstance().getToken());
- }
- @Override
- public void onCancelled(DatabaseError databaseError) {
- }
- });
- }else {
- setupNavigationDrawer();
- FirebaseDatabase.getInstance().getReference().child("userdata").child(username).child("token").setValue(FirebaseInstanceId.getInstance().getToken());
- }
- }
- private void setupNavigationDrawer() {
- result = new DrawerBuilder()
- .withActivity(HomePage.this)
- .withHeader(child)
- .withDisplayBelowStatusBar(false)
- .withTranslucentStatusBar(false)
- .withDrawerLayout(R.layout.material_drawer_fits_not)
- .addDrawerItems(
- new PrimaryDrawerItem().withName("Favourites").withIcon(GoogleMaterial.Icon.gmd_forum),
- new PrimaryDrawerItem().withName("Settings").withIcon(GoogleMaterial.Icon.gmd_settings),
- new PrimaryDrawerItem().withName("Contact").withIcon(GoogleMaterial.Icon.gmd_contact_mail),
- new PrimaryDrawerItem().withName("Commands").withIcon(GoogleMaterial.Icon.gmd_help),
- new PrimaryDrawerItem().withName("Log Out").withIcon(GoogleMaterial.Icon.gmd_security)
- )
- .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
- @Override
- public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
- if (drawerItem instanceof Nameable) {
- FragmentTransaction t = getSupportFragmentManager().beginTransaction();
- switch (position) {
- case 3:
- final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
- emailIntent.setType("plain/text");
- emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ayesupport@yandex.com"});
- startActivity(Intent.createChooser(emailIntent, "Send mail..."));
- break;
- case 5:
- break;
- case 2:
- Intent i= new Intent(HomePage.this, SettingsActivity.class);
- startActivity(i);
- break;
- case 4:
- Intent i2 = new Intent(HomePage.this,CommandsPage.class);
- startActivity(i2);
- break;
- }
- }
- return false;
- }
- }).build();
- FirebaseDatabase.getInstance().getReference().child("userdata").child(username).addListenerForSingleValueEvent(new ValueEventListener() {
- @Override
- public void onDataChange(DataSnapshot dataSnapshot) {
- try {
- Glide.with(HomePage.this).load(dataSnapshot.child("pic").getValue(String.class)).override(100,100).thumbnail(0.5f).into(profilePic);
- //Glide.with(HomePage.this).load(dataSnapshot.child("cover").getValue(String.class)).into(cover);
- } catch (Exception e) {
- e.printStackTrace();
- }
- id.setText(username);
- star.setText("4.7");
- }
- @Override
- public void onCancelled(DatabaseError databaseError) {
- }
- });
- }
- private void setupBottomNavigation() {
- AHBottomNavigationItem item1 = new AHBottomNavigationItem("Topics", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_whatshot));
- AHBottomNavigationItem item2 = new AHBottomNavigationItem("Rooms", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_group_work));
- AHBottomNavigationItem item3 = new AHBottomNavigationItem("Contacts", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_people));
- AHBottomNavigationItem item4 = new AHBottomNavigationItem("Leaderboard", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_star));
- AHBottomNavigationItem item5 = new AHBottomNavigationItem("Stats", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_insert_chart));
- bottomNavigation.addItem(item1);
- bottomNavigation.addItem(item2);
- bottomNavigation.addItem(item3);
- bottomNavigation.addItem(item4);
- bottomNavigation.addItem(item5);
- bottomNavigation.setInactiveColor(R.color.md_grey_800);
- bottomNavigation.setAccentColor(R.color.md_grey_600);
- bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_HIDE);
- fragContainer.setOffscreenPageLimit(4);
- HomePageAdapter adapter = new HomePageAdapter(getSupportFragmentManager());
- setSupportActionBar(toolbar);
- toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
- //fragContainer.setAdapter(adapter);
- bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
- @Override
- public boolean onTabSelected(int position, boolean wasSelected) {
- //fragContainer.setCurrentItem(position);
- return wasSelected;
- }
- });
- }
Add Comment
Please, Sign In to add comment