Commit 7c990455 authored by Lennart Bader's avatar Lennart Bader
Browse files

Added Authentication Check to Navigation

parent ae4d4ed4
......@@ -18,6 +18,7 @@ import java.util.Set;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.fragments.AboutFragment;
import de.mytfg.apps.vplan.fragments.AuthenticationFragment;
import de.mytfg.apps.vplan.fragments.LinksFragment;
import de.mytfg.apps.vplan.fragments.SettingsFragment;
import de.mytfg.apps.vplan.fragments.LoginFragment;
......@@ -68,13 +69,8 @@ public class MainActivity extends AppCompatActivity {
navi.navigate(new StartFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_plan:
// Login required to see VPlan
navi.clear();
if (!api.isLoggedIn()) {
navi.navigate(new LoginFragment(), R.id.fragment_container);
} else {
navi.navigate(new PlanFragment(), R.id.fragment_container);
}
navi.navigate(new PlanFragment(), R.id.fragment_container);
return true;
case R.id.mainmenu_vrr:
navi.clear();
......@@ -107,7 +103,7 @@ public class MainActivity extends AppCompatActivity {
});
Fragment fragment;
AuthenticationFragment fragment;
Settings settings = new Settings(context);
MyTFGApi api = new MyTFGApi(context);
......@@ -116,7 +112,7 @@ public class MainActivity extends AppCompatActivity {
fragment = new LoginFragment();
} else {
if (savedInstanceState != null) {
fragment = getSupportFragmentManager().getFragment(savedInstanceState,
fragment = (AuthenticationFragment)getSupportFragmentManager().getFragment(savedInstanceState,
"fragmentInstanceSaved");
} else {
// Read Landing Page from settings
......@@ -124,7 +120,7 @@ public class MainActivity extends AppCompatActivity {
try {
fragName = "de.mytfg.apps.vplan.fragments." + fragName;
Class c = Class.forName(fragName);
fragment = (Fragment)c.newInstance();
fragment = (AuthenticationFragment)c.newInstance();
} catch (Exception ex) {
fragment = new StartFragment();
}
......
......@@ -16,7 +16,7 @@ import android.widget.ImageView;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.activities.MainActivity;
public class AboutFragment extends Fragment {
public class AboutFragment extends AuthenticationFragment {
private final String githubUrl = "https://github.com/MyTFG/mytfg-vplan-app";
......
package de.mytfg.apps.vplan.fragments;
import android.support.v4.app.Fragment;
/**
* Adds a method for authentication check to the Fragment
*/
public abstract class AuthenticationFragment extends Fragment {
public boolean needsAuthentication() {
return false;
};
}
......@@ -16,7 +16,7 @@ import android.widget.ImageView;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.activities.MainActivity;
public class LinksFragment extends Fragment {
public class LinksFragment extends AuthenticationFragment {
private final String mytfgUrl = "https://mytfg.de";
private final String moodleUrl = "https://tfgym-duesseldorf.lms.schulon.org/";
private final String tfgUrl = "http://tfg-duesseldorf.de";
......
......@@ -32,7 +32,7 @@ import de.mytfg.apps.vplan.api.ApiParams;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.objects.User;
public class LoginFragment extends Fragment {
public class LoginFragment extends AuthenticationFragment {
private View view;
......
......@@ -35,7 +35,7 @@ import de.mytfg.apps.vplan.toolbar.ToolbarManager;
import de.mytfg.apps.vplan.tools.CustomViewTarget;
import de.mytfg.apps.vplan.tools.ShowCaseManager;
public class PlanFragment extends Fragment {
public class PlanFragment extends AuthenticationFragment {
private View view;
private PlanLogic today;
private PlanLogic tomorrow;
......@@ -46,7 +46,10 @@ public class PlanFragment extends Fragment {
public PlanFragment() {
}
@Override
public boolean needsAuthentication() {
return true;
}
@Nullable
@Override
......
......@@ -43,7 +43,7 @@ import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.objects.User;
import de.mytfg.apps.vplan.tools.Settings;
public class SettingsFragment extends Fragment {
public class SettingsFragment extends AuthenticationFragment {
private View view;
private MainActivity context;
......@@ -74,6 +74,7 @@ public class SettingsFragment extends Fragment {
CardView additional = (CardView) view.findViewById(R.id.account_additional_card);
MyTFGApi api = new MyTFGApi(context);
Log.d("LoggedIn", "" + api.isLoggedIn());
if (api.isLoggedIn()) {
login.setVisibility(View.GONE);
details.setVisibility(View.VISIBLE);
......
......@@ -39,7 +39,7 @@ import de.mytfg.apps.vplan.tools.CustomViewTarget;
import de.mytfg.apps.vplan.tools.ItemOffsetDecoration;
import de.mytfg.apps.vplan.tools.ShowCaseManager;
public class StartFragment extends Fragment {
public class StartFragment extends AuthenticationFragment {
private View view;
private RecylcerNewsAdapter adapter;
private RecyclerView recyclerView;
......
......@@ -33,7 +33,7 @@ import de.mytfg.apps.vplan.tools.CustomViewTarget;
import de.mytfg.apps.vplan.tools.ItemOffsetDecoration;
import de.mytfg.apps.vplan.tools.ShowCaseManager;
public class VrrFragment extends Fragment {
public class VrrFragment extends AuthenticationFragment {
private View view;
private RecylcerVrrAdapter adapter;
private RecyclerView recyclerView;
......
......@@ -29,6 +29,9 @@ import java.util.HashMap;
import de.mytfg.apps.vplan.R;
import de.mytfg.apps.vplan.activities.MainActivity;
import de.mytfg.apps.vplan.adapters.FragmentHolder;
import de.mytfg.apps.vplan.api.MyTFGApi;
import de.mytfg.apps.vplan.fragments.AuthenticationFragment;
import de.mytfg.apps.vplan.fragments.LoginFragment;
import de.mytfg.apps.vplan.tools.CopyDrawableImageTransform;
public class Navigation {
......@@ -39,13 +42,19 @@ public class Navigation {
}
public void navigate(Fragment fragment, int container, HashMap<String, Pair<String, View>> sharedElements) {
public void navigate(AuthenticationFragment fragment, int container, HashMap<String, Pair<String, View>> sharedElements) {
// Need to accept Terms of Use first
/*if (!MainActivity.sharedPreferences.getBoolean("tou_accepted", false) && !(fragment instanceof AboutFragment)) {
navigate(new AboutFragment(), container);
return;
}*/
MyTFGApi api = new MyTFGApi(context);
if (fragment.needsAuthentication() && !api.isLoggedIn()) {
navigate(new LoginFragment(), container);
return;
}
this.hideKeyboard();
/*if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
......@@ -100,7 +109,7 @@ public class Navigation {
((MainActivity)context).getDrawerLayout().closeDrawers();
}
public void navigate(Fragment fragment, int container) {
public void navigate(AuthenticationFragment fragment, int container) {
this.navigate(fragment, container, new HashMap<String, Pair<String, View>>());
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment