Canteen NAvigation Menu and Google Auth fix
This commit is contained in:
@@ -247,7 +247,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private void checkAndDoLogin() {
|
private void checkAndDoLogin() {
|
||||||
changeFragment(FRAGMENT_STARTUP);
|
changeFragment(FRAGMENT_STARTUP);
|
||||||
this.getGoogleAuth().connect(() -> getGoogleAuth().getLoginState(credentials -> {
|
getGoogleAuth().getLoginState(credentials -> {
|
||||||
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
||||||
toLogoutState();
|
toLogoutState();
|
||||||
return;
|
return;
|
||||||
@@ -258,7 +258,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
log.e(error);
|
log.e(error);
|
||||||
toLogoutState();
|
toLogoutState();
|
||||||
});
|
});
|
||||||
}));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFragment(int newFragment) {
|
private void changeFragment(int newFragment) {
|
||||||
@@ -288,17 +288,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
findViewById(R.id.app_bar_layout).setVisibility(View.GONE);
|
findViewById(R.id.app_bar_layout).setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
findViewById(R.id.app_bar_layout).setVisibility(View.VISIBLE);
|
findViewById(R.id.app_bar_layout).setVisibility(View.VISIBLE);
|
||||||
getCanteenBrowser().getCanteens(success -> {
|
|
||||||
int i = 0;
|
|
||||||
for (Canteen module : success) {
|
|
||||||
MenuItem menuItem = mNavigationView.getMenu().add(Menu.NONE, Menu.NONE, 101 + i, module.getName());
|
|
||||||
menuItem.setOnMenuItemClickListener(item -> {
|
|
||||||
log.d("canteen click", module.getId());
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
}, log::e);
|
|
||||||
}
|
}
|
||||||
// switch to logout
|
// switch to logout
|
||||||
if ((fragmentPage != FRAGMENT_STARTUP && fragmentPage != FRAGMENT_LOGIN) && (newFragment == FRAGMENT_STARTUP || newFragment == FRAGMENT_LOGIN)) {
|
if ((fragmentPage != FRAGMENT_STARTUP && fragmentPage != FRAGMENT_LOGIN) && (newFragment == FRAGMENT_STARTUP || newFragment == FRAGMENT_LOGIN)) {
|
||||||
@@ -315,6 +304,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
});
|
});
|
||||||
mNavigationView.getMenu().clear();
|
mNavigationView.getMenu().clear();
|
||||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||||
|
afterAnyMenuInflate();
|
||||||
} // switch to login
|
} // switch to login
|
||||||
else if ((fragmentPage == FRAGMENT_STARTUP || fragmentPage == FRAGMENT_LOGIN || fragmentPage == FRAGMENT_NONE) && (newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_LOGIN)) {
|
else if ((fragmentPage == FRAGMENT_STARTUP || fragmentPage == FRAGMENT_LOGIN || fragmentPage == FRAGMENT_NONE) && (newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_LOGIN)) {
|
||||||
View header = mNavigationView.getHeaderView(0);
|
View header = mNavigationView.getHeaderView(0);
|
||||||
@@ -325,6 +315,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mNavigationView.getMenu().clear();
|
mNavigationView.getMenu().clear();
|
||||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer_login);
|
mNavigationView.inflateMenu(R.menu.activity_main_drawer_login);
|
||||||
mNavigationView.setCheckedItem(R.id.nav_modules);
|
mNavigationView.setCheckedItem(R.id.nav_modules);
|
||||||
|
afterAnyMenuInflate();
|
||||||
getKVV().getModuleList(success -> {
|
getKVV().getModuleList(success -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Iterator<Modules.Module> it = success.latestSemesterIterator(); it.hasNext(); ) {
|
for (Iterator<Modules.Module> it = success.latestSemesterIterator(); it.hasNext(); ) {
|
||||||
@@ -354,6 +345,20 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void afterAnyMenuInflate() {
|
||||||
|
getCanteenBrowser().getCanteens(success -> {
|
||||||
|
int i = 0;
|
||||||
|
for (Canteen module : success) {
|
||||||
|
MenuItem menuItem = mNavigationView.getMenu().add(Menu.NONE, Menu.NONE, 201 + i, module.getName());
|
||||||
|
menuItem.setOnMenuItemClickListener(item -> {
|
||||||
|
log.d("canteen click", module.getId());
|
||||||
|
return false;
|
||||||
|
});
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
}, log::e);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -32,19 +32,19 @@ public class GoogleAuth {
|
|||||||
private boolean mIsResolving;
|
private boolean mIsResolving;
|
||||||
@Nullable
|
@Nullable
|
||||||
private CredentialsListener mCredentialsListener;
|
private CredentialsListener mCredentialsListener;
|
||||||
|
private boolean isConnected = false;
|
||||||
|
|
||||||
public GoogleAuth(FragmentActivity activity) {
|
public GoogleAuth(FragmentActivity activity) {
|
||||||
this.activity = activity;
|
this.activity = activity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void connect(final ConnectedListener listener) {
|
private void connect() {
|
||||||
if (this.isUnavailable()) {
|
if (this.isUnavailable()) {
|
||||||
Log.d(TAG, "STATUS: Google auth not available!");
|
Log.d(TAG, "STATUS: Google auth not available!");
|
||||||
listener.connected();
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.mCredentialsClient = getClient();
|
this.mCredentialsClient = getClient();
|
||||||
listener.connected();
|
this.isConnected = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -56,6 +56,8 @@ public class GoogleAuth {
|
|||||||
credentialsListener.onCredentials(null);
|
credentialsListener.onCredentials(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this.isConnected)
|
||||||
|
connect();
|
||||||
CredentialRequest request = new CredentialRequest.Builder()
|
CredentialRequest request = new CredentialRequest.Builder()
|
||||||
.setPasswordLoginSupported(true)
|
.setPasswordLoginSupported(true)
|
||||||
.build();
|
.build();
|
||||||
@@ -101,6 +103,8 @@ public class GoogleAuth {
|
|||||||
Toast.makeText(activity, "Google auth not available!", Toast.LENGTH_SHORT).show();
|
Toast.makeText(activity, "Google auth not available!", Toast.LENGTH_SHORT).show();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this.isConnected)
|
||||||
|
connect();
|
||||||
Credential credential = new Credential.Builder(username)
|
Credential credential = new Credential.Builder(username)
|
||||||
.setPassword(password)
|
.setPassword(password)
|
||||||
.build();
|
.build();
|
||||||
@@ -129,6 +133,8 @@ public class GoogleAuth {
|
|||||||
Log.d(TAG, "STATUS: Google auth not available!");
|
Log.d(TAG, "STATUS: Google auth not available!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!this.isConnected)
|
||||||
|
connect();
|
||||||
Credential credential = new Credential.Builder(username)
|
Credential credential = new Credential.Builder(username)
|
||||||
.setPassword(password)
|
.setPassword(password)
|
||||||
.build();
|
.build();
|
||||||
|
|||||||
@@ -5,7 +5,8 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/nav_dining"
|
android:id="@+id/nav_dining"
|
||||||
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" />
|
||||||
</group>
|
</group>
|
||||||
|
|
||||||
<item android:title="@string/options">
|
<item android:title="@string/options">
|
||||||
@@ -13,7 +14,8 @@
|
|||||||
<item
|
<item
|
||||||
android:id="@+id/nav_share"
|
android:id="@+id/nav_share"
|
||||||
android:icon="@drawable/ic_menu_share"
|
android:icon="@drawable/ic_menu_share"
|
||||||
android:title="@string/share"/>
|
android:title="@string/share"
|
||||||
|
android:orderInCategory="600"/>
|
||||||
</menu>
|
</menu>
|
||||||
</item>
|
</item>
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user