forked from Electrostat-Lab/DBTraining
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Navigation.java
65 lines (60 loc) · 2.61 KB
/
Navigation.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.scrappers.dbtraining.navigation;
import android.view.MenuItem;
import android.view.View;
import android.widget.ImageButton;
import android.widget.ImageView;
import com.google.android.material.navigation.NavigationView;
import com.scrappers.dbtraining.R;
import com.scrappers.dbtraining.mainScreens.aboutScreen.AboutScreen;
import com.scrappers.dbtraining.mainScreens.ioBufferScreen.IOBufferScreen;
import com.scrappers.dbtraining.mainScreens.ioStreamScreen.IOStreamScreen;
import com.scrappers.dbtraining.mainScreens.prefaceScreen.PrefaceScreen;
import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentTransaction;
public class Navigation {
private final AppCompatActivity context;
public static DrawerLayout drawerLayout;
private NavigationView navigationView;
public Navigation(@NonNull AppCompatActivity context) {
this.context=context;
}
public void start(){
drawerLayout=context.findViewById(R.id.drawer);
navigationView=context.findViewById(R.id.navigation);
ImageButton aboutProfile=navigationView.getHeaderView(0).findViewById(R.id.aboutProfile);
aboutProfile.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
drawerLayout.closeDrawer(GravityCompat.START);
displayWindow(new AboutScreen());
}
});
ImageButton jmePreface=navigationView.getHeaderView(0).findViewById(R.id.jmePreface);
jmePreface.setOnClickListener(v -> {
drawerLayout.closeDrawer(GravityCompat.START);
displayWindow(new PrefaceScreen());
});
navigationView.bringToFront();
navigationView.setNavigationItemSelectedListener(item -> {
switch (item.getItemId()){
case (R.id.streams):
drawerLayout.closeDrawer(GravityCompat.START);
displayWindow(new IOStreamScreen());
break;
case (R.id.buffers):
drawerLayout.closeDrawer(GravityCompat.START);
displayWindow(new IOBufferScreen());
}
return true;
});
}
public void displayWindow(@NonNull Fragment fragment){
FragmentTransaction fragmentTransaction= context.getSupportFragmentManager().beginTransaction();
fragmentTransaction.replace(R.id.content,fragment);
fragmentTransaction.commit();
}
}