Guest User

Untitled

a guest
Jan 20th, 2018
338
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 8.21 KB | None | 0 0
  1. public class HomePage extends AppCompatActivity {
  2. private Drawer result = null;
  3. private Boolean isCoverEdit = false, isProfileEdit = false;
  4. String username;
  5. private RelativeLayout splash;
  6. private Toolbar toolbar;
  7. private StorageReference mStorage;
  8. private ProgressDialog progressDialog;
  9. private ImageView searchBtn;
  10. private AHBottomNavigationViewPager fragContainer;
  11. private AHBottomNavigation bottomNavigation;
  12. private ImageView postBtn;
  13. private View child;
  14. private ImageView cover;
  15. private CircleImageView profilePic;
  16. private TextView star;
  17. private TextView id;
  18. private PopupMenu p;
  19.  
  20.  
  21. @Override
  22. protected void onCreate(Bundle savedInstanceState) {
  23. super.onCreate(savedInstanceState);
  24. setContentView(R.layout.activity_home_page);
  25. if (FirebaseAuth.getInstance().getCurrentUser() == null) {
  26. Intent i = new Intent(HomePage.this, Login.class);
  27. startActivity(i);
  28. finish();
  29. } else {
  30. getUsername();
  31. initiateViews();
  32. setupOnClickListeners();
  33. setupBottomNavigation();
  34.  
  35. mStorage = FirebaseStorage.getInstance().getReference();
  36. progressDialog = new ProgressDialog(this);
  37.  
  38. }
  39.  
  40.  
  41. }
  42.  
  43. private void initiateViews() {
  44. splash = findViewById(R.id.splash);
  45. searchBtn = findViewById(R.id.search);
  46. fragContainer = findViewById(R.id.frame);
  47. toolbar = findViewById(R.id.toolbar);
  48. bottomNavigation = findViewById(R.id.bottom_navigation);
  49. postBtn = findViewById(R.id.post);
  50. child = getLayoutInflater().inflate(R.layout.header, null);
  51. profilePic = child.findViewById(R.id.pic);
  52. id = child.findViewById(R.id.id);
  53. cover = child.findViewById(R.id.cover);
  54. star = child.findViewById(R.id.karma);
  55. }
  56.  
  57. private void getUsername() {
  58. username = new UserData(this).getUsername();
  59.  
  60. if (username==null){
  61. FirebaseDatabase.getInstance().getReference().child("users").child(FirebaseAuth.getInstance().getCurrentUser().getUid()).child("username").addListenerForSingleValueEvent(new ValueEventListener() {
  62. @Override
  63. public void onDataChange(DataSnapshot dataSnapshot) {
  64. username = dataSnapshot.getValue(String.class);
  65. SharedPreferences settings = getSharedPreferences("AyePref", MODE_PRIVATE);
  66. SharedPreferences.Editor editor = settings.edit();
  67. editor.putString("username", username);
  68. editor.apply();
  69. setupNavigationDrawer();
  70. FirebaseDatabase.getInstance().getReference().child("userdata").child(username).child("token").setValue(FirebaseInstanceId.getInstance().getToken());
  71.  
  72. }
  73.  
  74. @Override
  75. public void onCancelled(DatabaseError databaseError) {
  76.  
  77. }
  78. });
  79. }else {
  80. setupNavigationDrawer();
  81. FirebaseDatabase.getInstance().getReference().child("userdata").child(username).child("token").setValue(FirebaseInstanceId.getInstance().getToken());
  82. }
  83. }
  84.  
  85. private void setupNavigationDrawer() {
  86. result = new DrawerBuilder()
  87. .withActivity(HomePage.this)
  88. .withHeader(child)
  89. .withDisplayBelowStatusBar(false)
  90. .withTranslucentStatusBar(false)
  91. .withDrawerLayout(R.layout.material_drawer_fits_not)
  92. .addDrawerItems(
  93. new PrimaryDrawerItem().withName("Favourites").withIcon(GoogleMaterial.Icon.gmd_forum),
  94. new PrimaryDrawerItem().withName("Settings").withIcon(GoogleMaterial.Icon.gmd_settings),
  95. new PrimaryDrawerItem().withName("Contact").withIcon(GoogleMaterial.Icon.gmd_contact_mail),
  96. new PrimaryDrawerItem().withName("Commands").withIcon(GoogleMaterial.Icon.gmd_help),
  97. new PrimaryDrawerItem().withName("Log Out").withIcon(GoogleMaterial.Icon.gmd_security)
  98. )
  99.  
  100. .withOnDrawerItemClickListener(new Drawer.OnDrawerItemClickListener() {
  101. @Override
  102. public boolean onItemClick(View view, int position, IDrawerItem drawerItem) {
  103. if (drawerItem instanceof Nameable) {
  104. FragmentTransaction t = getSupportFragmentManager().beginTransaction();
  105. switch (position) {
  106. case 3:
  107. final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
  108. emailIntent.setType("plain/text");
  109. emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[]{"ayesupport@yandex.com"});
  110. startActivity(Intent.createChooser(emailIntent, "Send mail..."));
  111. break;
  112. case 5:
  113.  
  114. break;
  115. case 2:
  116. Intent i= new Intent(HomePage.this, SettingsActivity.class);
  117. startActivity(i);
  118. break;
  119. case 4:
  120. Intent i2 = new Intent(HomePage.this,CommandsPage.class);
  121. startActivity(i2);
  122. break;
  123.  
  124. }
  125.  
  126.  
  127. }
  128.  
  129. return false;
  130. }
  131. }).build();
  132.  
  133. FirebaseDatabase.getInstance().getReference().child("userdata").child(username).addListenerForSingleValueEvent(new ValueEventListener() {
  134. @Override
  135. public void onDataChange(DataSnapshot dataSnapshot) {
  136. try {
  137. Glide.with(HomePage.this).load(dataSnapshot.child("pic").getValue(String.class)).override(100,100).thumbnail(0.5f).into(profilePic);
  138. //Glide.with(HomePage.this).load(dataSnapshot.child("cover").getValue(String.class)).into(cover);
  139.  
  140. } catch (Exception e) {
  141. e.printStackTrace();
  142. }
  143. id.setText(username);
  144. star.setText("4.7");
  145.  
  146. }
  147.  
  148. @Override
  149. public void onCancelled(DatabaseError databaseError) {
  150.  
  151. }
  152. });
  153. }
  154.  
  155. private void setupBottomNavigation() {
  156. AHBottomNavigationItem item1 = new AHBottomNavigationItem("Topics", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_whatshot));
  157. AHBottomNavigationItem item2 = new AHBottomNavigationItem("Rooms", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_group_work));
  158. AHBottomNavigationItem item3 = new AHBottomNavigationItem("Contacts", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_people));
  159. AHBottomNavigationItem item4 = new AHBottomNavigationItem("Leaderboard", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_star));
  160. AHBottomNavigationItem item5 = new AHBottomNavigationItem("Stats", new IconicsDrawable(this, GoogleMaterial.Icon.gmd_insert_chart));
  161. bottomNavigation.addItem(item1);
  162. bottomNavigation.addItem(item2);
  163. bottomNavigation.addItem(item3);
  164. bottomNavigation.addItem(item4);
  165. bottomNavigation.addItem(item5);
  166. bottomNavigation.setInactiveColor(R.color.md_grey_800);
  167. bottomNavigation.setAccentColor(R.color.md_grey_600);
  168. bottomNavigation.setTitleState(AHBottomNavigation.TitleState.ALWAYS_HIDE);
  169. fragContainer.setOffscreenPageLimit(4);
  170. HomePageAdapter adapter = new HomePageAdapter(getSupportFragmentManager());
  171. setSupportActionBar(toolbar);
  172. toolbar.setNavigationIcon(R.drawable.ic_menu_white_24dp);
  173. //fragContainer.setAdapter(adapter);
  174. bottomNavigation.setOnTabSelectedListener(new AHBottomNavigation.OnTabSelectedListener() {
  175. @Override
  176. public boolean onTabSelected(int position, boolean wasSelected) {
  177. //fragContainer.setCurrentItem(position);
  178. return wasSelected;
  179.  
  180. }
  181. });
  182. }
Add Comment
Please, Sign In to add comment