Fast Login Successful!
This commit is contained in:
@@ -1,9 +1,9 @@
|
||||
package de.sebse.fuplanner;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.StringRes;
|
||||
import android.support.design.widget.NavigationView;
|
||||
import android.support.v4.app.Fragment;
|
||||
import android.support.v4.app.FragmentManager;
|
||||
@@ -19,7 +19,6 @@ import android.view.MenuItem;
|
||||
import android.view.View;
|
||||
import android.widget.TextView;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Iterator;
|
||||
|
||||
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.types.LoginToken;
|
||||
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;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements NavigationView.OnNavigationItemSelectedListener,
|
||||
implements MainAcitivityListener,
|
||||
NavigationView.OnNavigationItemSelectedListener,
|
||||
LoginFragment.OnLoginFragmentInteractionListener,
|
||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||
ModDetailFragment.OnModuleDetailFragmentInteractionListener,
|
||||
ScheduleFragment.OnScheduleFragmentInteractionListener {
|
||||
ModulesFragment.OnModulesFragmentInteractionListener {
|
||||
|
||||
private static final int FRAGMENT_NONE = -1;
|
||||
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_STATUS = "fragment_status";
|
||||
private static final String ARG_SAVE_DATE = "save_date";
|
||||
|
||||
FragmentManager fragmentManager;
|
||||
private GoogleAuth mGoogleAuth;
|
||||
@@ -65,14 +62,14 @@ public class MainActivity extends AppCompatActivity
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
int newFragmentPage = FRAGMENT_NONE;
|
||||
int newFragmentStatus = 0;
|
||||
if (savedInstanceState != null) {
|
||||
fragmentPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||
fragmentStatus = savedInstanceState.getInt(ARG_FRAGMENT_STATUS, fragmentPage);
|
||||
long saveDate = savedInstanceState.getLong(ARG_SAVE_DATE, 0);
|
||||
newFragmentPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||
newFragmentStatus = savedInstanceState.getInt(ARG_FRAGMENT_STATUS, fragmentPage);
|
||||
|
||||
log.d("fragmentPage", fragmentPage);
|
||||
log.d("fragmentStatus", fragmentStatus);
|
||||
log.d("saveDate", saveDate);
|
||||
log.d("fragmentPage", newFragmentPage);
|
||||
log.d("fragmentStatus", newFragmentStatus);
|
||||
}
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
@@ -87,29 +84,17 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
mNavigationView = findViewById(R.id.nav_view);
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
|
||||
this.getKVV().startUpdate();
|
||||
|
||||
fragmentManager = getSupportFragmentManager();
|
||||
changeFragment(FRAGMENT_STARTUP);
|
||||
|
||||
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);
|
||||
}, error -> {
|
||||
log.e(error);
|
||||
this.getKVV().endUpdate();
|
||||
toLogoutState();
|
||||
});
|
||||
});
|
||||
});
|
||||
if (newFragmentPage != FRAGMENT_LOGIN && newFragmentPage != FRAGMENT_STARTUP && newFragmentPage != FRAGMENT_NONE) {
|
||||
LoginToken loginToken = getKVV().easyLogin();
|
||||
if (loginToken != null)
|
||||
toLoginState(loginToken, newFragmentPage, newFragmentStatus);
|
||||
else
|
||||
checkAndDoLogin();
|
||||
} else {
|
||||
checkAndDoLogin();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -154,11 +139,9 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
switch (id) {
|
||||
case R.id.nav_modules:
|
||||
setTitle(R.string.courses);
|
||||
changeFragment(FRAGMENT_MODULES);
|
||||
break;
|
||||
case R.id.nav_schedule:
|
||||
setTitle(R.string.schedule);
|
||||
changeFragment(FRAGMENT_SCHEDULE);
|
||||
break;
|
||||
case R.id.nav_share:
|
||||
@@ -198,7 +181,6 @@ public class MainActivity extends AppCompatActivity
|
||||
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||
savedInstanceState.putInt(ARG_FRAGMENT_STATUS, fragmentStatus);
|
||||
savedInstanceState.putLong(ARG_SAVE_DATE, System.currentTimeMillis());
|
||||
super.onSaveInstanceState(savedInstanceState);
|
||||
}
|
||||
|
||||
@@ -220,33 +202,56 @@ public class MainActivity extends AppCompatActivity
|
||||
return this.mKVV;
|
||||
}
|
||||
|
||||
private int getDefaultFragmentAfterLogin() {
|
||||
return FRAGMENT_MODULES;
|
||||
}
|
||||
|
||||
private void toLogoutState() {
|
||||
setTitle(R.string.log_in);
|
||||
changeFragment(FRAGMENT_LOGIN);
|
||||
}
|
||||
|
||||
private void toLoginState(LoginToken loginToken) {
|
||||
private void toLoginState(LoginToken loginToken, int newFragment, int newData) {
|
||||
if (loginToken == null) {
|
||||
toLogoutState();
|
||||
} else {
|
||||
toLoginState(loginToken.getFullname(), loginToken.getEmail());
|
||||
toLoginState(loginToken.getFullname(), loginToken.getEmail(), newFragment, newData);
|
||||
}
|
||||
}
|
||||
|
||||
private void toLoginState(String fullname, String email) {
|
||||
setTitle(R.string.courses);
|
||||
changeFragment(FRAGMENT_MODULES);
|
||||
private void toLoginState(String fullname, String email, int newFragment, int newData) {
|
||||
changeFragment(newFragment, newData);
|
||||
|
||||
View header = mNavigationView.getHeaderView(0);
|
||||
((TextView) header.findViewById(R.id.login_name)).setText(fullname);
|
||||
((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) {
|
||||
changeFragment(newFragment, 0);
|
||||
}
|
||||
|
||||
private void changeFragment(int newFragment, int newData) {
|
||||
onTitleTextChange(R.string.courses);
|
||||
Fragment fragment;
|
||||
if (newFragment == FRAGMENT_MODULES) {
|
||||
fragment = ModulesFragment.newInstance();
|
||||
@@ -285,7 +290,7 @@ public class MainActivity extends AppCompatActivity
|
||||
mNavigationView.getMenu().clear();
|
||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||
} // 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);
|
||||
header.findViewById(R.id.imageView).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) {
|
||||
toLoginState(loginToken.getFullname(), loginToken.getEmail());
|
||||
toLoginState(loginToken.getFullname(), loginToken.getEmail(), getDefaultFragmentAfterLogin(), 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
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);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onModuleDetailFragmentInteraction(Uri uri) {
|
||||
log.d("Cooles ding");
|
||||
public void onTitleTextChange(String newTitle) {
|
||||
setTitle(newTitle);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onScheduleFragmentInteraction(Calendar firstVisibleDate, Calendar lastVisibleDay) {
|
||||
setTitle(getResources().getString(R.string.date_scale, Conversion.getModifiedDate(getApplicationContext(), firstVisibleDate.getTimeInMillis()), Conversion.getModifiedDate(getApplicationContext(), lastVisibleDay.getTimeInMillis())));
|
||||
public void onTitleTextChange(@StringRes int titleId) {
|
||||
setTitle(titleId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
@@ -124,6 +125,10 @@ public class LoginFragment extends Fragment {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnLoginFragmentInteractionListener");
|
||||
}
|
||||
if (context instanceof MainAcitivityListener)
|
||||
((MainAcitivityListener) context).onTitleTextChange(R.string.courses);
|
||||
else
|
||||
throw new RuntimeException(context.toString() + "must implement MainActivityListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -7,7 +7,6 @@ import android.support.v4.app.Fragment;
|
||||
import android.support.v4.widget.SwipeRefreshLayout;
|
||||
import android.support.v7.widget.LinearLayoutManager;
|
||||
import android.support.v7.widget.RecyclerView;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -15,6 +14,7 @@ import android.view.ViewGroup;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
@@ -85,7 +85,6 @@ public class ModulesFragment extends Fragment {
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
Log.d("ModFrag", "onAttach");
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnModulesFragmentInteractionListener) {
|
||||
mListener = (OnModulesFragmentInteractionListener) context;
|
||||
@@ -93,6 +92,10 @@ public class ModulesFragment extends Fragment {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnModulesFragmentInteractionListener");
|
||||
}
|
||||
if (context instanceof MainAcitivityListener)
|
||||
((MainAcitivityListener) context).onTitleTextChange(R.string.courses);
|
||||
else
|
||||
throw new RuntimeException(context.toString() + "must implement MainActivityListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@@ -18,6 +18,8 @@ import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
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.ui.weekview.MonthLoader;
|
||||
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.
|
||||
* Activities that contain this fragment must implement the
|
||||
* {@link ScheduleFragment.OnScheduleFragmentInteractionListener} interface
|
||||
* {@link MainAcitivityListener} interface
|
||||
* to handle interaction events.
|
||||
* Use the {@link ScheduleFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*
|
||||
*/
|
||||
public class ScheduleFragment extends Fragment implements MonthLoader.MonthChangeListener, WeekView.ScrollListener {
|
||||
private OnScheduleFragmentInteractionListener mListener;
|
||||
private MainAcitivityListener mListener;
|
||||
private WeekView mWeekView;
|
||||
private Logger log = new Logger(this);
|
||||
private Modules mModules = null;
|
||||
@@ -93,12 +95,13 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnScheduleFragmentInteractionListener) {
|
||||
mListener = (OnScheduleFragmentInteractionListener) context;
|
||||
if (context instanceof MainAcitivityListener) {
|
||||
mListener = (MainAcitivityListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnFragmentInteractionListener");
|
||||
}
|
||||
mListener.onTitleTextChange(R.string.schedule);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -139,10 +142,7 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
public void onFirstVisibleDayChanged(Calendar newFirstVisibleDay, Calendar oldFirstVisibleDay) {
|
||||
Calendar newLastVisibleDay = (Calendar) newFirstVisibleDay.clone();
|
||||
newLastVisibleDay.add(Calendar.HOUR, 24*mWeekView.getNumberOfVisibleDays());
|
||||
mListener.onScheduleFragmentInteraction(newFirstVisibleDay, newLastVisibleDay);
|
||||
}
|
||||
|
||||
public interface OnScheduleFragmentInteractionListener {
|
||||
void onScheduleFragmentInteraction(Calendar firstVisibleDate, Calendar lastVisibleDay);
|
||||
//mListener.onScheduleFragmentInteraction(newFirstVisibleDay, newLastVisibleDay);
|
||||
mListener.onTitleTextChange(getResources().getString(R.string.date_scale, Conversion.getModifiedDate(newFirstVisibleDay.getTimeInMillis()), Conversion.getModifiedDate(newLastVisibleDay.getTimeInMillis())));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
import android.content.Context;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.v4.app.Fragment;
|
||||
@@ -11,11 +10,13 @@ import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.tools.MainAcitivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Activities that contain this fragment must implement the
|
||||
* {@link OnModuleDetailFragmentInteractionListener} interface
|
||||
* {@link MainAcitivityListener} interface
|
||||
* to handle interaction events.
|
||||
* Use the {@link ModDetailFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
@@ -26,7 +27,8 @@ public class ModDetailFragment extends Fragment {
|
||||
// Parameters
|
||||
private int mItemPos;
|
||||
|
||||
private OnModuleDetailFragmentInteractionListener mListener;
|
||||
private MainAcitivityListener mListener;
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
public ModDetailFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -53,6 +55,10 @@ public class ModDetailFragment extends Fragment {
|
||||
if (getArguments() != null) {
|
||||
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
|
||||
@@ -67,21 +73,14 @@ public class ModDetailFragment extends Fragment {
|
||||
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
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof OnModuleDetailFragmentInteractionListener) {
|
||||
mListener = (OnModuleDetailFragmentInteractionListener) context;
|
||||
if (context instanceof MainAcitivityListener) {
|
||||
mListener = (MainAcitivityListener) context;
|
||||
} else {
|
||||
throw new RuntimeException(context.toString()
|
||||
+ " must implement OnModuleDetailFragmentInteractionListener");
|
||||
+ " must implement MainActivityListener");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -90,19 +89,4 @@ public class ModDetailFragment extends Fragment {
|
||||
super.onDetach();
|
||||
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<>();
|
||||
}
|
||||
|
||||
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) {
|
||||
KVVLogin login = new KVVLogin(this.context);
|
||||
login.login(username, password, success -> {
|
||||
|
||||
@@ -34,7 +34,6 @@ class KVVLogin extends HTTPService {
|
||||
}
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public LoginToken easyLogin() {
|
||||
return this.loginToken;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.Nullable;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
@@ -15,13 +16,16 @@ import java.util.HashMap;
|
||||
*/
|
||||
|
||||
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 final String username;
|
||||
private final String shibsessionKey;
|
||||
private final String shibsessionName;
|
||||
private String JSESSIONID;
|
||||
private String fullname;
|
||||
private String email;
|
||||
private long saveDate = 0;
|
||||
|
||||
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
||||
this.username = username;
|
||||
@@ -30,16 +34,19 @@ public class LoginToken implements Serializable {
|
||||
this.JSESSIONID = JSESSIONID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static LoginToken load(Context context) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||
ObjectInputStream is = new ObjectInputStream(fis);
|
||||
LoginToken loginToken = (LoginToken) is.readObject();
|
||||
is.close();
|
||||
fis.close();
|
||||
loginToken = (loginToken.saveDate > (System.currentTimeMillis() - EASY_LOGIN_TIME_MILLIS)) ? loginToken : null;
|
||||
return loginToken;
|
||||
}
|
||||
|
||||
public void save(Context context) throws IOException {
|
||||
saveDate = System.currentTimeMillis();
|
||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
||||
os.writeObject(this);
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.services.KVV.types;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
@@ -189,10 +190,10 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
public final String type;
|
||||
public final String description;
|
||||
private final String ID;
|
||||
public ArrayList<Announcement> announcements;
|
||||
public AssignmentList assignments;
|
||||
public EventList events;
|
||||
public ArrayList<Gradebook> gradebook;
|
||||
@Nullable public ArrayList<Announcement> announcements;
|
||||
@Nullable public AssignmentList assignments;
|
||||
@Nullable public EventList events;
|
||||
@Nullable public ArrayList<Gradebook> gradebook;
|
||||
|
||||
/*private Module() {
|
||||
this(null, null, null, null, null);
|
||||
@@ -202,10 +203,14 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
public float getGradebookPercent(){
|
||||
float maxPoint = 0;
|
||||
float userPoint = 0;
|
||||
for (Gradebook g : gradebook){
|
||||
maxPoint += g.getMaxPoints();
|
||||
userPoint += g.getPoints();
|
||||
if (gradebook != null) {
|
||||
for (Gradebook g : gradebook){
|
||||
maxPoint += g.getMaxPoints();
|
||||
userPoint += g.getPoints();
|
||||
}
|
||||
}
|
||||
if (maxPoint == 0)
|
||||
return 0;
|
||||
return userPoint/maxPoint;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.annotation.SuppressLint;
|
||||
import android.annotation.TargetApi;
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import com.google.android.gms.common.logging.Logger;
|
||||
@@ -33,27 +34,22 @@ public class Conversion {
|
||||
return getModifiedDate(context, modified, "hh:mm");
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
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);
|
||||
}
|
||||
|
||||
@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;
|
||||
|
||||
if (context != null && DateFormat.is24HourFormat(context))
|
||||
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) {
|
||||
dateFormat = new SimpleDateFormat(getDateFormat(locale, skeleton));
|
||||
} 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