Fast Login Successful!
This commit is contained in:
@@ -1,9 +1,9 @@
|
|||||||
package de.sebse.fuplanner;
|
package de.sebse.fuplanner;
|
||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
import android.support.design.widget.NavigationView;
|
import android.support.design.widget.NavigationView;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
import android.support.v4.app.FragmentManager;
|
import android.support.v4.app.FragmentManager;
|
||||||
@@ -19,7 +19,6 @@ import android.view.MenuItem;
|
|||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import de.sebse.fuplanner.fragments.LoginFragment;
|
import de.sebse.fuplanner.fragments.LoginFragment;
|
||||||
@@ -31,15 +30,14 @@ import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
|||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.Conversion;
|
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity
|
public class MainActivity extends AppCompatActivity
|
||||||
implements NavigationView.OnNavigationItemSelectedListener,
|
implements MainAcitivityListener,
|
||||||
|
NavigationView.OnNavigationItemSelectedListener,
|
||||||
LoginFragment.OnLoginFragmentInteractionListener,
|
LoginFragment.OnLoginFragmentInteractionListener,
|
||||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
ModulesFragment.OnModulesFragmentInteractionListener {
|
||||||
ModDetailFragment.OnModuleDetailFragmentInteractionListener,
|
|
||||||
ScheduleFragment.OnScheduleFragmentInteractionListener {
|
|
||||||
|
|
||||||
private static final int FRAGMENT_NONE = -1;
|
private static final int FRAGMENT_NONE = -1;
|
||||||
private static final int FRAGMENT_STARTUP = 0;
|
private static final int FRAGMENT_STARTUP = 0;
|
||||||
@@ -51,7 +49,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
||||||
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
||||||
private static final String ARG_SAVE_DATE = "save_date";
|
|
||||||
|
|
||||||
FragmentManager fragmentManager;
|
FragmentManager fragmentManager;
|
||||||
private GoogleAuth mGoogleAuth;
|
private GoogleAuth mGoogleAuth;
|
||||||
@@ -65,14 +62,14 @@ public class MainActivity extends AppCompatActivity
|
|||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
int newFragmentPage = FRAGMENT_NONE;
|
||||||
|
int newFragmentStatus = 0;
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
fragmentPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
newFragmentPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||||
fragmentStatus = savedInstanceState.getInt(ARG_FRAGMENT_STATUS, fragmentPage);
|
newFragmentStatus = savedInstanceState.getInt(ARG_FRAGMENT_STATUS, fragmentPage);
|
||||||
long saveDate = savedInstanceState.getLong(ARG_SAVE_DATE, 0);
|
|
||||||
|
|
||||||
log.d("fragmentPage", fragmentPage);
|
log.d("fragmentPage", newFragmentPage);
|
||||||
log.d("fragmentStatus", fragmentStatus);
|
log.d("fragmentStatus", newFragmentStatus);
|
||||||
log.d("saveDate", saveDate);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
@@ -87,29 +84,17 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
mNavigationView = findViewById(R.id.nav_view);
|
mNavigationView = findViewById(R.id.nav_view);
|
||||||
mNavigationView.setNavigationItemSelectedListener(this);
|
mNavigationView.setNavigationItemSelectedListener(this);
|
||||||
|
|
||||||
this.getKVV().startUpdate();
|
|
||||||
|
|
||||||
fragmentManager = getSupportFragmentManager();
|
fragmentManager = getSupportFragmentManager();
|
||||||
changeFragment(FRAGMENT_STARTUP);
|
|
||||||
|
|
||||||
this.getGoogleAuth().connect(() -> {
|
if (newFragmentPage != FRAGMENT_LOGIN && newFragmentPage != FRAGMENT_STARTUP && newFragmentPage != FRAGMENT_NONE) {
|
||||||
getGoogleAuth().getLoginState(credentials -> {
|
LoginToken loginToken = getKVV().easyLogin();
|
||||||
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
if (loginToken != null)
|
||||||
this.getKVV().endUpdate();
|
toLoginState(loginToken, newFragmentPage, newFragmentStatus);
|
||||||
toLogoutState();
|
else
|
||||||
return;
|
checkAndDoLogin();
|
||||||
}
|
} else {
|
||||||
this.getKVV().login(credentials.getUsername(), credentials.getPassword(), success -> {
|
checkAndDoLogin();
|
||||||
this.getKVV().endUpdate();
|
}
|
||||||
toLoginState(success);
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
this.getKVV().endUpdate();
|
|
||||||
toLogoutState();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -154,11 +139,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
switch (id) {
|
switch (id) {
|
||||||
case R.id.nav_modules:
|
case R.id.nav_modules:
|
||||||
setTitle(R.string.courses);
|
|
||||||
changeFragment(FRAGMENT_MODULES);
|
changeFragment(FRAGMENT_MODULES);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_schedule:
|
case R.id.nav_schedule:
|
||||||
setTitle(R.string.schedule);
|
|
||||||
changeFragment(FRAGMENT_SCHEDULE);
|
changeFragment(FRAGMENT_SCHEDULE);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_share:
|
case R.id.nav_share:
|
||||||
@@ -198,7 +181,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||||
savedInstanceState.putInt(ARG_FRAGMENT_STATUS, fragmentStatus);
|
savedInstanceState.putInt(ARG_FRAGMENT_STATUS, fragmentStatus);
|
||||||
savedInstanceState.putLong(ARG_SAVE_DATE, System.currentTimeMillis());
|
|
||||||
super.onSaveInstanceState(savedInstanceState);
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -220,33 +202,56 @@ public class MainActivity extends AppCompatActivity
|
|||||||
return this.mKVV;
|
return this.mKVV;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getDefaultFragmentAfterLogin() {
|
||||||
|
return FRAGMENT_MODULES;
|
||||||
|
}
|
||||||
|
|
||||||
private void toLogoutState() {
|
private void toLogoutState() {
|
||||||
setTitle(R.string.log_in);
|
|
||||||
changeFragment(FRAGMENT_LOGIN);
|
changeFragment(FRAGMENT_LOGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toLoginState(LoginToken loginToken) {
|
private void toLoginState(LoginToken loginToken, int newFragment, int newData) {
|
||||||
if (loginToken == null) {
|
if (loginToken == null) {
|
||||||
toLogoutState();
|
toLogoutState();
|
||||||
} else {
|
} else {
|
||||||
toLoginState(loginToken.getFullname(), loginToken.getEmail());
|
toLoginState(loginToken.getFullname(), loginToken.getEmail(), newFragment, newData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toLoginState(String fullname, String email) {
|
private void toLoginState(String fullname, String email, int newFragment, int newData) {
|
||||||
setTitle(R.string.courses);
|
changeFragment(newFragment, newData);
|
||||||
changeFragment(FRAGMENT_MODULES);
|
|
||||||
|
|
||||||
View header = mNavigationView.getHeaderView(0);
|
View header = mNavigationView.getHeaderView(0);
|
||||||
((TextView) header.findViewById(R.id.login_name)).setText(fullname);
|
((TextView) header.findViewById(R.id.login_name)).setText(fullname);
|
||||||
((TextView) header.findViewById(R.id.login_mail)).setText(email);
|
((TextView) header.findViewById(R.id.login_mail)).setText(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void checkAndDoLogin() {
|
||||||
|
changeFragment(FRAGMENT_STARTUP);
|
||||||
|
this.getKVV().startUpdate();
|
||||||
|
this.getGoogleAuth().connect(() -> getGoogleAuth().getLoginState(credentials -> {
|
||||||
|
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
||||||
|
this.getKVV().endUpdate();
|
||||||
|
toLogoutState();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.getKVV().login(credentials.getUsername(), credentials.getPassword(), success -> {
|
||||||
|
this.getKVV().endUpdate();
|
||||||
|
toLoginState(success, getDefaultFragmentAfterLogin(), 0);
|
||||||
|
}, error -> {
|
||||||
|
log.e(error);
|
||||||
|
this.getKVV().endUpdate();
|
||||||
|
toLogoutState();
|
||||||
|
});
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
private void changeFragment(int newFragment) {
|
private void changeFragment(int newFragment) {
|
||||||
changeFragment(newFragment, 0);
|
changeFragment(newFragment, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFragment(int newFragment, int newData) {
|
private void changeFragment(int newFragment, int newData) {
|
||||||
|
onTitleTextChange(R.string.courses);
|
||||||
Fragment fragment;
|
Fragment fragment;
|
||||||
if (newFragment == FRAGMENT_MODULES) {
|
if (newFragment == FRAGMENT_MODULES) {
|
||||||
fragment = ModulesFragment.newInstance();
|
fragment = ModulesFragment.newInstance();
|
||||||
@@ -285,7 +290,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);
|
||||||
} // switch to login
|
} // switch to login
|
||||||
else if ((fragmentPage == FRAGMENT_STARTUP || fragmentPage == FRAGMENT_LOGIN) && (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);
|
||||||
header.findViewById(R.id.imageView).setVisibility(View.VISIBLE);
|
header.findViewById(R.id.imageView).setVisibility(View.VISIBLE);
|
||||||
header.findViewById(R.id.login_name).setVisibility(View.VISIBLE);
|
header.findViewById(R.id.login_name).setVisibility(View.VISIBLE);
|
||||||
@@ -327,25 +332,19 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLoginFragmentInteraction(LoginToken loginToken) {
|
public void onLoginFragmentInteraction(LoginToken loginToken) {
|
||||||
toLoginState(loginToken.getFullname(), loginToken.getEmail());
|
toLoginState(loginToken.getFullname(), loginToken.getEmail(), getDefaultFragmentAfterLogin(), 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onModulesFragmentInteraction(final int itemPosition) {
|
public void onModulesFragmentInteraction(final int itemPosition) {
|
||||||
setTitle(R.string.courses);
|
|
||||||
getKVV().getModuleList(success -> setTitle(success.get(itemPosition).title), error -> log.e(error));
|
|
||||||
changeFragment(FRAGMENT_MODULES_DETAILS, itemPosition);
|
changeFragment(FRAGMENT_MODULES_DETAILS, itemPosition);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onTitleTextChange(String newTitle) {
|
||||||
public void onModuleDetailFragmentInteraction(Uri uri) {
|
setTitle(newTitle);
|
||||||
log.d("Cooles ding");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
public void onTitleTextChange(@StringRes int titleId) {
|
||||||
public void onScheduleFragmentInteraction(Calendar firstVisibleDate, Calendar lastVisibleDay) {
|
setTitle(titleId);
|
||||||
setTitle(getResources().getString(R.string.date_scale, Conversion.getModifiedDate(getApplicationContext(), firstVisibleDate.getTimeInMillis()), Conversion.getModifiedDate(getApplicationContext(), lastVisibleDay.getTimeInMillis())));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,7 @@ import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
|||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -124,6 +125,10 @@ public class LoginFragment extends Fragment {
|
|||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnLoginFragmentInteractionListener");
|
+ " must implement OnLoginFragmentInteractionListener");
|
||||||
}
|
}
|
||||||
|
if (context instanceof MainAcitivityListener)
|
||||||
|
((MainAcitivityListener) context).onTitleTextChange(R.string.courses);
|
||||||
|
else
|
||||||
|
throw new RuntimeException(context.toString() + "must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import android.support.v4.app.Fragment;
|
|||||||
import android.support.v4.widget.SwipeRefreshLayout;
|
import android.support.v4.widget.SwipeRefreshLayout;
|
||||||
import android.support.v7.widget.LinearLayoutManager;
|
import android.support.v7.widget.LinearLayoutManager;
|
||||||
import android.support.v7.widget.RecyclerView;
|
import android.support.v7.widget.RecyclerView;
|
||||||
import android.util.Log;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -15,6 +14,7 @@ import android.view.ViewGroup;
|
|||||||
import de.sebse.fuplanner.MainActivity;
|
import de.sebse.fuplanner.MainActivity;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
|
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -85,7 +85,6 @@ public class ModulesFragment extends Fragment {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
Log.d("ModFrag", "onAttach");
|
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof OnModulesFragmentInteractionListener) {
|
if (context instanceof OnModulesFragmentInteractionListener) {
|
||||||
mListener = (OnModulesFragmentInteractionListener) context;
|
mListener = (OnModulesFragmentInteractionListener) context;
|
||||||
@@ -93,6 +92,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 MainAcitivityListener)
|
||||||
|
((MainAcitivityListener) context).onTitleTextChange(R.string.courses);
|
||||||
|
else
|
||||||
|
throw new RuntimeException(context.toString() + "must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ import de.sebse.fuplanner.R;
|
|||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.Conversion;
|
||||||
|
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.weekview.MonthLoader;
|
import de.sebse.fuplanner.tools.ui.weekview.MonthLoader;
|
||||||
import de.sebse.fuplanner.tools.ui.weekview.WeekView;
|
import de.sebse.fuplanner.tools.ui.weekview.WeekView;
|
||||||
@@ -26,14 +28,14 @@ import de.sebse.fuplanner.tools.ui.weekview.WeekViewEvent;
|
|||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Activities that contain this fragment must implement the
|
* Activities that contain this fragment must implement the
|
||||||
* {@link ScheduleFragment.OnScheduleFragmentInteractionListener} interface
|
* {@link MainAcitivityListener} interface
|
||||||
* to handle interaction events.
|
* to handle interaction events.
|
||||||
* Use the {@link ScheduleFragment#newInstance} factory method to
|
* Use the {@link ScheduleFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class ScheduleFragment extends Fragment implements MonthLoader.MonthChangeListener, WeekView.ScrollListener {
|
public class ScheduleFragment extends Fragment implements MonthLoader.MonthChangeListener, WeekView.ScrollListener {
|
||||||
private OnScheduleFragmentInteractionListener mListener;
|
private MainAcitivityListener mListener;
|
||||||
private WeekView mWeekView;
|
private WeekView mWeekView;
|
||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
private Modules mModules = null;
|
private Modules mModules = null;
|
||||||
@@ -93,12 +95,13 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof OnScheduleFragmentInteractionListener) {
|
if (context instanceof MainAcitivityListener) {
|
||||||
mListener = (OnScheduleFragmentInteractionListener) context;
|
mListener = (MainAcitivityListener) context;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnFragmentInteractionListener");
|
+ " must implement OnFragmentInteractionListener");
|
||||||
}
|
}
|
||||||
|
mListener.onTitleTextChange(R.string.schedule);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -139,10 +142,7 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
|||||||
public void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay) {
|
public void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay) {
|
||||||
Calendar newLastVisibleDay = (Calendar) newFirstVisibleDay.clone();
|
Calendar newLastVisibleDay = (Calendar) newFirstVisibleDay.clone();
|
||||||
newLastVisibleDay.add(Calendar.HOUR, 24*mWeekView.getNumberOfVisibleDays());
|
newLastVisibleDay.add(Calendar.HOUR, 24*mWeekView.getNumberOfVisibleDays());
|
||||||
mListener.onScheduleFragmentInteraction(newFirstVisibleDay, newLastVisibleDay);
|
//mListener.onScheduleFragmentInteraction(newFirstVisibleDay, newLastVisibleDay);
|
||||||
}
|
mListener.onTitleTextChange(getResources().getString(R.string.date_scale, Conversion.getModifiedDate(newFirstVisibleDay.getTimeInMillis()), Conversion.getModifiedDate(newLastVisibleDay.getTimeInMillis())));
|
||||||
|
|
||||||
public interface OnScheduleFragmentInteractionListener {
|
|
||||||
void onScheduleFragmentInteraction(Calendar firstVisibleDate, Calendar lastVisibleDay);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
import android.support.v4.app.Fragment;
|
import android.support.v4.app.Fragment;
|
||||||
@@ -11,11 +10,13 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Activities that contain this fragment must implement the
|
* Activities that contain this fragment must implement the
|
||||||
* {@link OnModuleDetailFragmentInteractionListener} interface
|
* {@link MainAcitivityListener} interface
|
||||||
* to handle interaction events.
|
* to handle interaction events.
|
||||||
* Use the {@link ModDetailFragment#newInstance} factory method to
|
* Use the {@link ModDetailFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
@@ -26,7 +27,8 @@ public class ModDetailFragment extends Fragment {
|
|||||||
// Parameters
|
// Parameters
|
||||||
private int mItemPos;
|
private int mItemPos;
|
||||||
|
|
||||||
private OnModuleDetailFragmentInteractionListener mListener;
|
private MainAcitivityListener mListener;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
|
||||||
public ModDetailFragment() {
|
public ModDetailFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@@ -53,6 +55,10 @@ public class ModDetailFragment extends Fragment {
|
|||||||
if (getArguments() != null) {
|
if (getArguments() != null) {
|
||||||
mItemPos = getArguments().getInt(ARG_POSITION);
|
mItemPos = getArguments().getInt(ARG_POSITION);
|
||||||
}
|
}
|
||||||
|
if (mListener != null) {
|
||||||
|
mListener.onTitleTextChange(R.string.courses);
|
||||||
|
mListener.getKVV().getModuleList(success -> mListener.onTitleTextChange(success.get(mItemPos).title), log::e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -67,21 +73,14 @@ public class ModDetailFragment extends Fragment {
|
|||||||
return v;
|
return v;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: Rename method, update argument and hook method into UI event
|
|
||||||
public void onButtonPressed(Uri uri) {
|
|
||||||
if (mListener != null) {
|
|
||||||
mListener.onModuleDetailFragmentInteraction(uri);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof OnModuleDetailFragmentInteractionListener) {
|
if (context instanceof MainAcitivityListener) {
|
||||||
mListener = (OnModuleDetailFragmentInteractionListener) context;
|
mListener = (MainAcitivityListener) context;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnModuleDetailFragmentInteractionListener");
|
+ " must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,19 +89,4 @@ public class ModDetailFragment extends Fragment {
|
|||||||
super.onDetach();
|
super.onDetach();
|
||||||
mListener = null;
|
mListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface must be implemented by activities that contain this
|
|
||||||
* fragment to allow an interaction in this fragment to be communicated
|
|
||||||
* to the activity and potentially other fragments contained in that
|
|
||||||
* activity.
|
|
||||||
* <p>
|
|
||||||
* See the Android Training lesson <a href=
|
|
||||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
|
||||||
* >Communicating with Other Fragments</a> for more information.
|
|
||||||
*/
|
|
||||||
public interface OnModuleDetailFragmentInteractionListener {
|
|
||||||
// TODO: Update argument type and name
|
|
||||||
void onModuleDetailFragmentInteraction(Uri uri);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,6 +30,12 @@ public class KVV {
|
|||||||
this.updatingList = new ArrayList<>();
|
this.updatingList = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public LoginToken easyLogin() {
|
||||||
|
KVVLogin login = new KVVLogin(this.context);
|
||||||
|
lastToken = login.easyLogin();
|
||||||
|
return lastToken;
|
||||||
|
}
|
||||||
|
|
||||||
public void login(@NonNull String username, @NonNull String password, final NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
public void login(@NonNull String username, @NonNull String password, final NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
||||||
KVVLogin login = new KVVLogin(this.context);
|
KVVLogin login = new KVVLogin(this.context);
|
||||||
login.login(username, password, success -> {
|
login.login(username, password, success -> {
|
||||||
|
|||||||
@@ -34,7 +34,6 @@ class KVVLogin extends HTTPService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public LoginToken easyLogin() {
|
public LoginToken easyLogin() {
|
||||||
return this.loginToken;
|
return this.loginToken;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
@@ -15,13 +16,16 @@ import java.util.HashMap;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class LoginToken implements Serializable {
|
public class LoginToken implements Serializable {
|
||||||
|
private static final long EASY_LOGIN_TIME_MILLIS = 1000 * 60 * 60 * 3;
|
||||||
private static final String FILE_NAME = "LoginTokenSaving";
|
private static final String FILE_NAME = "LoginTokenSaving";
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String shibsessionKey;
|
private final String shibsessionKey;
|
||||||
private final String shibsessionName;
|
private final String shibsessionName;
|
||||||
private String JSESSIONID;
|
private String JSESSIONID;
|
||||||
private String fullname;
|
private String fullname;
|
||||||
private String email;
|
private String email;
|
||||||
|
private long saveDate = 0;
|
||||||
|
|
||||||
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@@ -30,16 +34,19 @@ public class LoginToken implements Serializable {
|
|||||||
this.JSESSIONID = JSESSIONID;
|
this.JSESSIONID = JSESSIONID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static LoginToken load(Context context) throws IOException, ClassNotFoundException {
|
public static LoginToken load(Context context) throws IOException, ClassNotFoundException {
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
ObjectInputStream is = new ObjectInputStream(fis);
|
||||||
LoginToken loginToken = (LoginToken) is.readObject();
|
LoginToken loginToken = (LoginToken) is.readObject();
|
||||||
is.close();
|
is.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
|
loginToken = (loginToken.saveDate > (System.currentTimeMillis() - EASY_LOGIN_TIME_MILLIS)) ? loginToken : null;
|
||||||
return loginToken;
|
return loginToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
public void save(Context context) throws IOException {
|
||||||
|
saveDate = System.currentTimeMillis();
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
ObjectOutputStream os = new ObjectOutputStream(fos);
|
||||||
os.writeObject(this);
|
os.writeObject(this);
|
||||||
|
|||||||
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.services.KVV.types;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.support.annotation.NonNull;
|
import android.support.annotation.NonNull;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
@@ -189,10 +190,10 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
public final String type;
|
public final String type;
|
||||||
public final String description;
|
public final String description;
|
||||||
private final String ID;
|
private final String ID;
|
||||||
public ArrayList<Announcement> announcements;
|
@Nullable public ArrayList<Announcement> announcements;
|
||||||
public AssignmentList assignments;
|
@Nullable public AssignmentList assignments;
|
||||||
public EventList events;
|
@Nullable public EventList events;
|
||||||
public ArrayList<Gradebook> gradebook;
|
@Nullable public ArrayList<Gradebook> gradebook;
|
||||||
|
|
||||||
/*private Module() {
|
/*private Module() {
|
||||||
this(null, null, null, null, null);
|
this(null, null, null, null, null);
|
||||||
@@ -202,10 +203,14 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
public float getGradebookPercent(){
|
public float getGradebookPercent(){
|
||||||
float maxPoint = 0;
|
float maxPoint = 0;
|
||||||
float userPoint = 0;
|
float userPoint = 0;
|
||||||
for (Gradebook g : gradebook){
|
if (gradebook != null) {
|
||||||
maxPoint += g.getMaxPoints();
|
for (Gradebook g : gradebook){
|
||||||
userPoint += g.getPoints();
|
maxPoint += g.getMaxPoints();
|
||||||
|
userPoint += g.getPoints();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
if (maxPoint == 0)
|
||||||
|
return 0;
|
||||||
return userPoint/maxPoint;
|
return userPoint/maxPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
|
import android.support.annotation.Nullable;
|
||||||
import android.text.format.DateFormat;
|
import android.text.format.DateFormat;
|
||||||
|
|
||||||
import com.google.android.gms.common.logging.Logger;
|
import com.google.android.gms.common.logging.Logger;
|
||||||
@@ -33,27 +34,22 @@ public class Conversion {
|
|||||||
return getModifiedDate(context, modified, "hh:mm");
|
return getModifiedDate(context, modified, "hh:mm");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Deprecated
|
|
||||||
public static String getModifiedDate(long modified) {
|
public static String getModifiedDate(long modified) {
|
||||||
return getModifiedDate(null, modified);
|
return getModifiedDate(null, modified, "dd.MM.yy");
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String getModifiedDate(Context context, long modified) {
|
|
||||||
return getModifiedDate(context, modified, "dd.MM.yy");
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String getModifiedDate(Context context, long modified, String skeleton) {
|
|
||||||
|
public static String getModifiedDate(@Nullable Context context, long modified, String skeleton) {
|
||||||
return getModifiedDate(context, Locale.getDefault(), modified, skeleton);
|
return getModifiedDate(context, Locale.getDefault(), modified, skeleton);
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressLint("SimpleDateFormat")
|
@SuppressLint("SimpleDateFormat")
|
||||||
public static String getModifiedDate(Context context, Locale locale, long modified, String skeleton) {
|
private static String getModifiedDate(@Nullable Context context, Locale locale, long modified, String skeleton) {
|
||||||
SimpleDateFormat dateFormat;
|
SimpleDateFormat dateFormat;
|
||||||
|
|
||||||
if (context != null && DateFormat.is24HourFormat(context))
|
if (context != null && DateFormat.is24HourFormat(context))
|
||||||
skeleton = skeleton.replaceAll("h", "H");
|
skeleton = skeleton.replaceAll("h", "H");
|
||||||
else if (context == null)
|
|
||||||
log.w("No context applied for conversion!");
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
dateFormat = new SimpleDateFormat(getDateFormat(locale, skeleton));
|
dateFormat = new SimpleDateFormat(getDateFormat(locale, skeleton));
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -0,0 +1,16 @@
|
|||||||
|
package de.sebse.fuplanner.tools;
|
||||||
|
|
||||||
|
import android.support.annotation.StringRes;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||||
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
|
|
||||||
|
public interface MainAcitivityListener {
|
||||||
|
void onTitleTextChange(String newTitle);
|
||||||
|
|
||||||
|
void onTitleTextChange(@StringRes int titleId);
|
||||||
|
|
||||||
|
KVV getKVV();
|
||||||
|
|
||||||
|
GoogleAuth getGoogleAuth();
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user