Implemented Option Menu
This commit is contained in:
@@ -51,7 +51,7 @@ public class MainActivity extends AppCompatActivity
|
||||
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
||||
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
||||
|
||||
FragmentManager fragmentManager;
|
||||
FragmentManager mFragmentManager;
|
||||
private GoogleAuth mGoogleAuth;
|
||||
private KVV mKVV;
|
||||
private Logger log = new Logger(this);
|
||||
@@ -70,9 +70,6 @@ public class MainActivity extends AppCompatActivity
|
||||
if (savedInstanceState != null) {
|
||||
newFragmentPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||
newFragmentData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, fragmentData);
|
||||
|
||||
log.d("fragmentPage", newFragmentPage);
|
||||
log.d("fragmentData", newFragmentData);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
@@ -87,7 +84,7 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
mNavigationView = findViewById(R.id.nav_view);
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
mFragmentManager = getSupportFragmentManager();
|
||||
|
||||
LoginToken loginToken = getKVV().easyLogin();
|
||||
if (newFragmentPage != FRAGMENT_LOGIN && newFragmentPage != FRAGMENT_STARTUP && newFragmentPage != FRAGMENT_NONE) {
|
||||
@@ -123,9 +120,12 @@ public class MainActivity extends AppCompatActivity
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
getMenuInflater().inflate(R.menu.main, menu);
|
||||
if (fragmentPage == FRAGMENT_SCHEDULE) {
|
||||
getMenuInflater().inflate(R.menu.options_schedule, menu);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onOptionsItemSelected(MenuItem item) {
|
||||
@@ -135,7 +135,17 @@ public class MainActivity extends AppCompatActivity
|
||||
int id = item.getItemId();
|
||||
|
||||
//noinspection SimplifiableIfStatement
|
||||
if (id == R.id.action_settings) {
|
||||
if (id == R.id.refresh) {
|
||||
ScheduleFragment fragment = (ScheduleFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_SCHEDULE));
|
||||
if (fragment != null && fragment.isVisible()) {
|
||||
fragment.invalidate(true);
|
||||
}
|
||||
return true;
|
||||
} else if (id == R.id.go_to_today) {
|
||||
ScheduleFragment fragment = (ScheduleFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_SCHEDULE));
|
||||
if (fragment != null && fragment.isVisible()) {
|
||||
fragment.goToToday();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -145,8 +155,6 @@ public class MainActivity extends AppCompatActivity
|
||||
@SuppressWarnings("StatementWithEmptyBody")
|
||||
@Override
|
||||
public boolean onNavigationItemSelected(@NonNull MenuItem item) {
|
||||
log.d("ITEM SELECTED", item.getTitle());
|
||||
|
||||
// Handle navigation view item clicks here.
|
||||
int id = item.getItemId();
|
||||
|
||||
@@ -287,8 +295,8 @@ public class MainActivity extends AppCompatActivity
|
||||
fragment = StartupFragment.newInstance();
|
||||
}
|
||||
|
||||
FragmentTransaction fragmentTransaction = fragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragcontainer, fragment);
|
||||
FragmentTransaction fragmentTransaction = mFragmentManager.beginTransaction();
|
||||
fragmentTransaction.replace(R.id.fragcontainer, fragment, String.valueOf(newFragment));
|
||||
fragmentTransaction.commit();
|
||||
|
||||
if (newFragment == FRAGMENT_STARTUP) {
|
||||
@@ -349,6 +357,7 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
this.fragmentPage = newFragment;
|
||||
this.fragmentData = newData;
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void setOfflineBanner(boolean onlineMode) {
|
||||
@@ -376,7 +385,6 @@ public class MainActivity extends AppCompatActivity
|
||||
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++;
|
||||
@@ -409,7 +417,6 @@ public class MainActivity extends AppCompatActivity
|
||||
public void loginTokenInvalid(boolean doPrecheck) {
|
||||
getKVV().invalidate();
|
||||
checkAndDoLogin();
|
||||
//log.d("Login token invalid!");
|
||||
}
|
||||
|
||||
public void refreshFailed(boolean isFailed) {
|
||||
|
||||
@@ -60,7 +60,10 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
@Override
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
invalidate(false);
|
||||
}
|
||||
|
||||
public void invalidate(boolean forceRefresh) {
|
||||
if (getActivity() != null) {
|
||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
||||
kvv.getModuleList((Modules success) -> {
|
||||
@@ -75,9 +78,9 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
mWeekView.notifyDatasetChanged();
|
||||
}
|
||||
}
|
||||
}, error1 -> log.e(error1));
|
||||
}, error1 -> log.e(error1), forceRefresh);
|
||||
}
|
||||
}, error -> log.e(error));
|
||||
}, error -> log.e(error), forceRefresh);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,4 +147,8 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
//mListener.onScheduleFragmentInteraction(newFirstVisibleDay, newLastVisibleDay);
|
||||
mListener.onTitleTextChange(getResources().getString(R.string.date_scale, DateUtils.getModifiedDate(newFirstVisibleDay.getTimeInMillis()), DateUtils.getModifiedDate(newLastVisibleDay.getTimeInMillis())));
|
||||
}
|
||||
|
||||
public void goToToday() {
|
||||
mWeekView.goToToday();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -98,7 +98,6 @@ public class ModDetailFragment extends Fragment implements ModDetailListener {
|
||||
|
||||
@Override
|
||||
public void gotoFragmentPart(int part, int index) {
|
||||
log.d("Reference to:", part, index);
|
||||
mViewPager.setCurrentItem(ModulePart.getPageByPart(part), true);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -104,7 +104,6 @@ public class CanteenBrowser extends HTTPService {
|
||||
public void getCanteen(Canteen canteen, final NetworkCallback<Canteen> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||
String hash = "canteen" + canteen.getId();
|
||||
queue.add(hash, () -> {
|
||||
log.d("getCanteen", canteen.size() > 0 && !forceRefresh);
|
||||
if (canteen.size() > 0 && !forceRefresh) {
|
||||
callback.onResponse(canteen);
|
||||
queue.next(hash);
|
||||
|
||||
@@ -86,7 +86,6 @@ class KVVLogin extends HTTPService {
|
||||
getSAMLResponse(identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, ident_idp_session, success1111 -> loginKVV(success1111.get("RelayState"), success1111.get("SAMLResponse"), kvvJSESSIONID, success111112 -> {
|
||||
LoginToken token = new LoginToken(username, success111112.get("shibsessionKey"), success111112.get("shibsessionName"), kvvJSESSIONID);
|
||||
finishKVVlogin(token, success11111 -> {
|
||||
log.d("Login worked!");
|
||||
callback.onResponse(token);
|
||||
}, error);
|
||||
}, error), error);
|
||||
@@ -321,8 +320,8 @@ class KVVLogin extends HTTPService {
|
||||
Pattern pattern = Pattern.compile(name+"=([^;]+);");
|
||||
Matcher matcher = pattern.matcher(cookies);
|
||||
if (!matcher.find()) {
|
||||
log.d("GETcookie failed", name);
|
||||
log.d("GETcookie failed", cookies);
|
||||
log.e("GETcookie failed", name);
|
||||
log.e("GETcookie failed", cookies);
|
||||
throw new NoSuchFieldException();
|
||||
}
|
||||
return matcher.group(1);
|
||||
|
||||
@@ -36,8 +36,6 @@ public class SortedListModule extends SortedList<Modules.Module, String, String>
|
||||
}
|
||||
|
||||
private static int compareSemester(String a, String b) throws NoSuchFieldException {
|
||||
//Logger log = new Logger("SortedListModule");
|
||||
//log.d("compare", a, b);
|
||||
if (a == null && b == null)
|
||||
return EQUAL;
|
||||
if (a == null)
|
||||
|
||||
@@ -2,8 +2,11 @@
|
||||
<menu xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:app="http://schemas.android.com/apk/res-auto">
|
||||
<item
|
||||
android:id="@+id/action_settings"
|
||||
android:orderInCategory="100"
|
||||
android:title="@string/action_settings"
|
||||
android:id="@+id/refresh"
|
||||
android:title="@string/refresh"
|
||||
app:showAsAction="never" />
|
||||
<item
|
||||
android:id="@+id/go_to_today"
|
||||
android:title="@string/go_to_today"
|
||||
app:showAsAction="never" />
|
||||
</menu>
|
||||
@@ -42,4 +42,6 @@
|
||||
<string name="refresh_failed">Refresh failed...</string>
|
||||
<string name="share_intent">Hey check out the new KVV app: %s$s</string>
|
||||
<string name="app_url" translatable="false">https://play.google.com/store/apps/details?id=de.sebse.fuplanner</string>
|
||||
<string name="refresh">Refresh</string>
|
||||
<string name="go_to_today">Go to today</string>
|
||||
</resources>
|
||||
|
||||
Reference in New Issue
Block a user