Navigation layout refreshment
This commit is contained in:
@@ -165,7 +165,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
case R.id.nav_schedule:
|
case R.id.nav_schedule:
|
||||||
changeFragment(FRAGMENT_SCHEDULE);
|
changeFragment(FRAGMENT_SCHEDULE);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_dining:
|
case R.id.nav_canteens:
|
||||||
changeFragment(FRAGMENT_CANTEENS);
|
changeFragment(FRAGMENT_CANTEENS);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_settings:
|
case R.id.nav_settings:
|
||||||
@@ -360,70 +360,19 @@ public class MainActivity extends AppCompatActivity
|
|||||||
findViewById(R.id.app_bar_layout).setVisibility(View.VISIBLE);
|
findViewById(R.id.app_bar_layout).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
// switch to logout
|
// switch to logout
|
||||||
if ((currentPage != FRAGMENT_STARTUP && currentPage != FRAGMENT_LOGIN) && (newFragment == FRAGMENT_STARTUP || newFragment == FRAGMENT_LOGIN)) {
|
if (
|
||||||
View header = mNavigationView.getHeaderView(0);
|
(newFragment == FRAGMENT_STARTUP || newFragment == FRAGMENT_LOGIN) &&
|
||||||
//header.findViewById(R.id.imageView).setVisibility(View.GONE);
|
(currentPage != FRAGMENT_STARTUP && currentPage != FRAGMENT_LOGIN)
|
||||||
header.findViewById(R.id.login_name).setVisibility(View.GONE);
|
) {
|
||||||
header.findViewById(R.id.login_mail).setVisibility(View.GONE);
|
refreshNavigation();
|
||||||
header.findViewById(R.id.btn_login_page).setVisibility(View.VISIBLE);
|
|
||||||
header.findViewById(R.id.btn_login_page).setOnClickListener(v -> {
|
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
|
||||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
|
||||||
}
|
|
||||||
changeFragment(FRAGMENT_LOGIN);
|
|
||||||
});
|
|
||||||
mNavigationView.getMenu().clear();
|
|
||||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
|
||||||
afterAnyMenuInflate();
|
|
||||||
} // switch to login
|
} // switch to login
|
||||||
else if (
|
else if (
|
||||||
(currentPage == FRAGMENT_STARTUP || currentPage == FRAGMENT_LOGIN || currentPage == FRAGMENT_NONE) &&
|
(currentPage == FRAGMENT_STARTUP || currentPage == FRAGMENT_LOGIN || currentPage == FRAGMENT_NONE) &&
|
||||||
(newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_LOGIN && getKVV().isLoggedIn())
|
(newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_LOGIN && getKVV().isLoggedIn())
|
||||||
) {
|
) {
|
||||||
View header = mNavigationView.getHeaderView(0);
|
refreshNavigation();
|
||||||
//header.findViewById(R.id.imageView).setVisibility(View.VISIBLE);
|
|
||||||
header.findViewById(R.id.login_name).setVisibility(View.VISIBLE);
|
|
||||||
header.findViewById(R.id.login_mail).setVisibility(View.VISIBLE);
|
|
||||||
header.findViewById(R.id.btn_login_page).setVisibility(View.GONE);
|
|
||||||
mNavigationView.getMenu().clear();
|
|
||||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer_login);
|
|
||||||
mNavigationView.setCheckedItem(R.id.nav_modules);
|
|
||||||
afterAnyMenuInflate();
|
|
||||||
getKVV().getModuleList(success -> {
|
|
||||||
int i = 0;
|
|
||||||
for (Iterator<Modules.Module> it = success.latestSemesterIterator(); it.hasNext(); ) {
|
|
||||||
Modules.Module module = it.next();
|
|
||||||
MenuItem menuItem = mNavigationView.getMenu().add(Menu.NONE, Menu.NONE, 101 + i, module.title);
|
|
||||||
menuItem.setOnMenuItemClickListener(item -> {
|
|
||||||
onModulesFragmentInteraction(module.getID());
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}, log::e);
|
|
||||||
}
|
|
||||||
if (newFragment == FRAGMENT_MODULES_DETAILS) {
|
|
||||||
getKVV().getModule(newData, success -> {
|
|
||||||
int size = mNavigationView.getMenu().size();
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
String title = success == null ? null : success.title;
|
|
||||||
for (int k = 0; k < size; k++) {
|
|
||||||
mNavigationView.getMenu().getItem(k).setChecked(mNavigationView.getMenu().getItem(k).getTitle().equals(title));
|
|
||||||
}
|
|
||||||
}, log::e);
|
|
||||||
}
|
|
||||||
if (newFragment == FRAGMENT_CANTEENS_DETAILS) {
|
|
||||||
getCanteenBrowser().getCanteens(success -> {
|
|
||||||
int size = mNavigationView.getMenu().size();
|
|
||||||
Canteen canteen = success.getCanteen(Integer.parseInt(newData));
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
String title = canteen == null ? null : canteen.getName();
|
|
||||||
for (int k = 0; k < size; k++) {
|
|
||||||
mNavigationView.getMenu().getItem(k).setChecked(mNavigationView.getMenu().getItem(k).getTitle().equals(title));
|
|
||||||
}
|
|
||||||
}, log::e);
|
|
||||||
}
|
}
|
||||||
|
setNavigationSelection(newFragment, newData);
|
||||||
|
|
||||||
if (newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_NONE && newFragment != FRAGMENT_LOGIN) {
|
if (newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_NONE && newFragment != FRAGMENT_LOGIN) {
|
||||||
this.fragmentPage = newFragment;
|
this.fragmentPage = newFragment;
|
||||||
@@ -451,8 +400,80 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void setNavigationSelection(int fragment, String data) {
|
||||||
|
switch (fragment) {
|
||||||
|
case FRAGMENT_MODULES_DETAILS:
|
||||||
|
getKVV().getModule(data, success -> {
|
||||||
|
int size = mNavigationView.getMenu().size();
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
String title = success == null ? null : success.title;
|
||||||
|
for (int k = 0; k < size; k++) {
|
||||||
|
mNavigationView.getMenu().getItem(k).setChecked(mNavigationView.getMenu().getItem(k).getTitle().equals(title));
|
||||||
|
}
|
||||||
|
}, log::e);
|
||||||
|
break;
|
||||||
|
case FRAGMENT_MODULES:
|
||||||
|
mNavigationView.setCheckedItem(R.id.nav_modules);
|
||||||
|
break;
|
||||||
|
case FRAGMENT_SCHEDULE:
|
||||||
|
mNavigationView.setCheckedItem(R.id.nav_schedule);
|
||||||
|
break;
|
||||||
|
case FRAGMENT_CANTEENS_DETAILS:
|
||||||
|
getCanteenBrowser().getCanteens(success -> {
|
||||||
|
int size = mNavigationView.getMenu().size();
|
||||||
|
Canteen canteen = success.getCanteen(Integer.parseInt(data));
|
||||||
|
//noinspection ConstantConditions
|
||||||
|
String title = canteen == null ? null : canteen.getName();
|
||||||
|
for (int k = 0; k < size; k++) {
|
||||||
|
mNavigationView.getMenu().getItem(k).setChecked(mNavigationView.getMenu().getItem(k).getTitle().equals(title));
|
||||||
|
}
|
||||||
|
}, log::e);
|
||||||
|
break;
|
||||||
|
case FRAGMENT_CANTEENS:
|
||||||
|
mNavigationView.setCheckedItem(R.id.nav_canteens);
|
||||||
|
break;
|
||||||
|
case FRAGMENT_PREFERENCES:
|
||||||
|
mNavigationView.setCheckedItem(R.id.nav_settings);
|
||||||
|
break;
|
||||||
|
default: // FRAGMENT_STARTUP / FRAGMENT_LOGIN
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void afterAnyMenuInflate() {
|
private void setNavigationHeader(boolean isLoggedIn) {
|
||||||
|
View header = mNavigationView.getHeaderView(0);
|
||||||
|
int login = isLoggedIn ? View.VISIBLE : View.GONE;
|
||||||
|
int btn = !isLoggedIn ? View.VISIBLE : View.GONE;
|
||||||
|
|
||||||
|
header.findViewById(R.id.login_name).setVisibility(login);
|
||||||
|
header.findViewById(R.id.login_mail).setVisibility(login);
|
||||||
|
View viewBtn = header.findViewById(R.id.btn_login_page);
|
||||||
|
viewBtn.setVisibility(btn);
|
||||||
|
if (!viewBtn.hasOnClickListeners())
|
||||||
|
viewBtn.setOnClickListener(v -> {
|
||||||
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||||
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
|
}
|
||||||
|
changeFragment(FRAGMENT_LOGIN);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void afterAnyMenuInflate(boolean isLoggedIn) {
|
||||||
|
if (isLoggedIn) {
|
||||||
|
getKVV().getModuleList(success -> {
|
||||||
|
int i = 0;
|
||||||
|
for (Iterator<Modules.Module> it = success.latestSemesterIterator(); it.hasNext(); ) {
|
||||||
|
Modules.Module module = it.next();
|
||||||
|
MenuItem menuItem = mNavigationView.getMenu().add(Menu.NONE, Menu.NONE, 101 + i, module.title);
|
||||||
|
menuItem.setOnMenuItemClickListener(item -> {
|
||||||
|
onModulesFragmentInteraction(module.getID());
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}, log::e);
|
||||||
|
}
|
||||||
getCanteenBrowser().getCanteens(success -> {
|
getCanteenBrowser().getCanteens(success -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Canteen canteen: success) {
|
for (Canteen canteen: success) {
|
||||||
@@ -537,4 +558,16 @@ public class MainActivity extends AppCompatActivity
|
|||||||
public void showToast(String message) {
|
public void showToast(String message) {
|
||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void refreshNavigation() {
|
||||||
|
boolean loggedIn = getKVV().isLoggedIn();
|
||||||
|
setNavigationHeader(loggedIn);
|
||||||
|
mNavigationView.getMenu().clear();
|
||||||
|
if (loggedIn)
|
||||||
|
mNavigationView.inflateMenu(R.menu.activity_main_drawer_login);
|
||||||
|
else
|
||||||
|
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||||
|
afterAnyMenuInflate(loggedIn);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class CanteensFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private CanteensAdapter adapter;
|
private CanteensAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
|
private MainActivityListener mMainActivityListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||||
@@ -69,6 +70,8 @@ public class CanteensFragment extends Fragment {
|
|||||||
CanteenBrowser browser = ((MainActivity) getActivity()).getCanteenBrowser();
|
CanteenBrowser browser = ((MainActivity) getActivity()).getCanteenBrowser();
|
||||||
browser.getCanteens(success -> {
|
browser.getCanteens(success -> {
|
||||||
adapter.setCanteens(success);
|
adapter.setCanteens(success);
|
||||||
|
if (mMainActivityListener != null)
|
||||||
|
mMainActivityListener.refreshNavigation();
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
log.e(error.toString());
|
log.e(error.toString());
|
||||||
@@ -87,9 +90,10 @@ public class CanteensFragment extends Fragment {
|
|||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnCanteensFragmentInteractionListener");
|
+ " must implement OnCanteensFragmentInteractionListener");
|
||||||
}
|
}
|
||||||
if (context instanceof MainActivityListener)
|
if (context instanceof MainActivityListener) {
|
||||||
((MainActivityListener) context).onTitleTextChange(R.string.canteens);
|
mMainActivityListener = (MainActivityListener) context;
|
||||||
else
|
mMainActivityListener.onTitleTextChange(R.string.canteens);
|
||||||
|
} else
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,6 +101,7 @@ public class CanteensFragment extends Fragment {
|
|||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
mListener = null;
|
mListener = null;
|
||||||
|
mMainActivityListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnCanteensFragmentInteractionListener {
|
public interface OnCanteensFragmentInteractionListener {
|
||||||
|
|||||||
@@ -28,6 +28,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private ModulesAdapter adapter;
|
private ModulesAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
|
private MainActivityListener mMainActivityListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||||
@@ -69,6 +70,8 @@ public class ModulesFragment extends Fragment {
|
|||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
||||||
kvv.getModuleList(success -> {
|
kvv.getModuleList(success -> {
|
||||||
adapter.setModules(success);
|
adapter.setModules(success);
|
||||||
|
if (mMainActivityListener != null)
|
||||||
|
mMainActivityListener.refreshNavigation();
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
log.e(error.toString());
|
log.e(error.toString());
|
||||||
@@ -87,8 +90,10 @@ public class ModulesFragment extends Fragment {
|
|||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnModulesFragmentInteractionListener");
|
+ " must implement OnModulesFragmentInteractionListener");
|
||||||
}
|
}
|
||||||
if (context instanceof MainActivityListener)
|
if (context instanceof MainActivityListener) {
|
||||||
((MainActivityListener) context).onTitleTextChange(R.string.courses);
|
mMainActivityListener = (MainActivityListener) context;
|
||||||
|
mMainActivityListener.onTitleTextChange(R.string.courses);
|
||||||
|
}
|
||||||
else
|
else
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
@@ -97,6 +102,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
mListener = null;
|
mListener = null;
|
||||||
|
mMainActivityListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface OnModulesFragmentInteractionListener {
|
public interface OnModulesFragmentInteractionListener {
|
||||||
|
|||||||
@@ -11,6 +11,10 @@ public interface MainActivityListener {
|
|||||||
|
|
||||||
void onTitleTextChange(@StringRes int titleId);
|
void onTitleTextChange(@StringRes int titleId);
|
||||||
|
|
||||||
|
void showToast(String message);
|
||||||
|
|
||||||
|
void showToast(@StringRes int msgStringRes);
|
||||||
|
|
||||||
KVV getKVV();
|
KVV getKVV();
|
||||||
|
|
||||||
GoogleAuth getGoogleAuth();
|
GoogleAuth getGoogleAuth();
|
||||||
@@ -25,7 +29,5 @@ public interface MainActivityListener {
|
|||||||
|
|
||||||
void removeRequestPermissionsResultListener(String id);
|
void removeRequestPermissionsResultListener(String id);
|
||||||
|
|
||||||
void showToast(@StringRes int msgStringRes);
|
void refreshNavigation();
|
||||||
|
|
||||||
void showToast(String message);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,7 +3,7 @@
|
|||||||
|
|
||||||
<group android:checkableBehavior="single">
|
<group android:checkableBehavior="single">
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_dining"
|
android:id="@+id/nav_canteens"
|
||||||
android:icon="@drawable/ic_local_dining"
|
android:icon="@drawable/ic_local_dining"
|
||||||
android:title="@string/canteen_plan"
|
android:title="@string/canteen_plan"
|
||||||
android:orderInCategory="200" />
|
android:orderInCategory="200" />
|
||||||
|
|||||||
@@ -13,7 +13,7 @@
|
|||||||
android:title="@string/courses"
|
android:title="@string/courses"
|
||||||
android:orderInCategory="100" />
|
android:orderInCategory="100" />
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_dining"
|
android:id="@+id/nav_canteens"
|
||||||
android:icon="@drawable/ic_local_dining"
|
android:icon="@drawable/ic_local_dining"
|
||||||
android:title="@string/canteen_plan"
|
android:title="@string/canteen_plan"
|
||||||
android:orderInCategory="200"/>
|
android:orderInCategory="200"/>
|
||||||
|
|||||||
Reference in New Issue
Block a user