Bug Fixes
This commit is contained in:
@@ -37,6 +37,7 @@ import de.sebse.fuplanner.services.GoogleAuth.Credentials;
|
|||||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
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.KVVListener;
|
import de.sebse.fuplanner.services.KVV.KVVListener;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
@@ -65,7 +66,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
private GoogleAuth mGoogleAuth;
|
private GoogleAuth mGoogleAuth;
|
||||||
private KVV mNewKVV;
|
private KVV mKVV;
|
||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private NavigationView mNavigationView;
|
private NavigationView mNavigationView;
|
||||||
|
|
||||||
@@ -247,10 +248,10 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}*/
|
}*/
|
||||||
|
|
||||||
public KVV getKVV() {
|
public KVV getKVV() {
|
||||||
if (this.mNewKVV == null) {
|
if (this.mKVV == null) {
|
||||||
this.mNewKVV = new KVV(this, this);
|
this.mKVV = new KVV(this, this);
|
||||||
}
|
}
|
||||||
return this.mNewKVV;
|
return this.mKVV;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CanteenBrowser getCanteenBrowser() {
|
public CanteenBrowser getCanteenBrowser() {
|
||||||
@@ -487,22 +488,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
setTitle(titleId);
|
setTitle(titleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*+++@Deprecated
|
|
||||||
@Override
|
|
||||||
public void loginTokenInvalid(boolean doLoginCheck) {
|
|
||||||
if (doLoginCheck) {
|
|
||||||
getKVV().testLogin(isSuccess -> {
|
|
||||||
if (!isSuccess) {
|
|
||||||
getKVV().invalidate();
|
|
||||||
checkAndDoLogin();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
getKVV().invalidate();
|
|
||||||
checkAndDoLogin();
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshCompleted(boolean isFailed) {
|
public void onRefreshCompleted(boolean isFailed) {
|
||||||
setRefreshFailedBanner(isFailed);
|
setRefreshFailedBanner(isFailed);
|
||||||
@@ -549,7 +534,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void handleLogin(de.sebse.fuplanner.services.KVV.types.LoginToken token, boolean enteringOnlineMode) {
|
public void handleLogin(LoginToken token, boolean enteringOnlineMode) {
|
||||||
toLoginState(token.getUsername(), token.getEmail(), getDefaultFragmentAfterLogin(), "", enteringOnlineMode);
|
toLoginState(token.getUsername(), token.getEmail(), getDefaultFragmentAfterLogin(), "", enteringOnlineMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -557,4 +542,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
public void handleLogout() {
|
public void handleLogout() {
|
||||||
toLogoutState();
|
toLogoutState();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onModuleListChange() {
|
||||||
|
updateNavigation();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -47,7 +47,7 @@ public class LoginFragment extends Fragment {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View v = inflater.inflate(R.layout.fragment_login, container, false);
|
View v = inflater.inflate(R.layout.fragment_login, container, false);
|
||||||
if (mActivityListener != null && mActivityListener.getKVV().modules().list().stored()) {
|
if (mActivityListener != null && mActivityListener.getKVV().account().isOfflineStoredAvailable()) {
|
||||||
Button offline_btn = v.findViewById(R.id.btn_offline);
|
Button offline_btn = v.findViewById(R.id.btn_offline);
|
||||||
offline_btn.setVisibility(View.VISIBLE);
|
offline_btn.setVisibility(View.VISIBLE);
|
||||||
offline_btn.setText(v.getResources().getString(R.string.enter_offline_mode, mActivityListener.getKVV().modules().list().getUsername()));
|
offline_btn.setText(v.getResources().getString(R.string.enter_offline_mode, mActivityListener.getKVV().modules().list().getUsername()));
|
||||||
|
|||||||
@@ -23,7 +23,7 @@ public class KVV {
|
|||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public KVVModules modules() {
|
public KVVModules modules() {
|
||||||
return (KVVModules) addAndGet("module", () -> new KVVModules(account(), mContext));
|
return (KVVModules) addAndGet("module", () -> new KVVModules(account(), mListener, mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -11,4 +11,6 @@ public interface KVVListener {
|
|||||||
void handleLogin(LoginToken token, boolean enteringOnlineMode);
|
void handleLogin(LoginToken token, boolean enteringOnlineMode);
|
||||||
|
|
||||||
void handleLogout();
|
void handleLogout();
|
||||||
|
|
||||||
|
void onModuleListChange();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -78,8 +78,8 @@ public class KVVLogin extends HTTPService {
|
|||||||
|
|
||||||
public boolean isOfflineStoredAvailable() {
|
public boolean isOfflineStoredAvailable() {
|
||||||
try {
|
try {
|
||||||
LoginToken.load(getContext());
|
LoginToken load = LoginToken.load(getContext());
|
||||||
return true;
|
return load != null;
|
||||||
} catch (FileNotFoundException ignored) {
|
} catch (FileNotFoundException ignored) {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -171,6 +171,7 @@ public class KVVLogin extends HTTPService {
|
|||||||
private boolean setToken(@Nullable LoginToken token, boolean enteringOnlineMode) {
|
private boolean setToken(@Nullable LoginToken token, boolean enteringOnlineMode) {
|
||||||
if (token == null)
|
if (token == null)
|
||||||
return false;
|
return false;
|
||||||
|
boolean isOnlyRefresh = mToken != null;
|
||||||
mToken = token;
|
mToken = token;
|
||||||
if (enteringOnlineMode) {
|
if (enteringOnlineMode) {
|
||||||
try {
|
try {
|
||||||
@@ -180,7 +181,7 @@ public class KVVLogin extends HTTPService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
mOnlineMode = enteringOnlineMode;
|
mOnlineMode = enteringOnlineMode;
|
||||||
return handleCallbacks();
|
return isOnlyRefresh || handleCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -10,10 +10,12 @@ public class KVVModules {
|
|||||||
private final HashMap<String, Part> mAddons = new HashMap<>();
|
private final HashMap<String, Part> mAddons = new HashMap<>();
|
||||||
private KVVModulesList mList = null;
|
private KVVModulesList mList = null;
|
||||||
private final KVVLogin mLogin;
|
private final KVVLogin mLogin;
|
||||||
|
private KVVListener mListener;
|
||||||
private final Context context;
|
private final Context context;
|
||||||
|
|
||||||
KVVModules(KVVLogin login, Context context) {
|
KVVModules(KVVLogin login, KVVListener listener, Context context) {
|
||||||
this.mLogin = login;
|
this.mLogin = login;
|
||||||
|
this.mListener = listener;
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -53,7 +55,7 @@ public class KVVModules {
|
|||||||
@NotNull
|
@NotNull
|
||||||
public KVVModulesList list() {
|
public KVVModulesList list() {
|
||||||
if (mList == null) {
|
if (mList == null) {
|
||||||
mList = new KVVModulesList(mLogin, context);
|
mList = new KVVModulesList(mLogin, mListener, context);
|
||||||
}
|
}
|
||||||
return mList;
|
return mList;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -25,12 +25,14 @@ import static de.sebse.fuplanner.services.KVV.ModulesPart.RETRY_COUNT;
|
|||||||
|
|
||||||
public class KVVModulesList extends HTTPService {
|
public class KVVModulesList extends HTTPService {
|
||||||
private final KVVLogin mLogin;
|
private final KVVLogin mLogin;
|
||||||
|
private final KVVListener mListener;
|
||||||
@Nullable private Modules mModules;
|
@Nullable private Modules mModules;
|
||||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||||
|
|
||||||
KVVModulesList(KVVLogin login, Context context) {
|
KVVModulesList(KVVLogin login, KVVListener listener, Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
this.mLogin = login;
|
this.mLogin = login;
|
||||||
|
this.mListener = listener;
|
||||||
restore();
|
restore();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,6 +119,7 @@ public class KVVModulesList extends HTTPService {
|
|||||||
this.mModules = success;
|
this.mModules = success;
|
||||||
else
|
else
|
||||||
this.mModules.updateList(success);
|
this.mModules.updateList(success);
|
||||||
|
mListener.onModuleListChange();
|
||||||
store();
|
store();
|
||||||
callback.onResponse(this.mModules);
|
callback.onResponse(this.mModules);
|
||||||
mQueue.next();
|
mQueue.next();
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import androidx.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class LoginToken implements Serializable {
|
public class LoginToken implements Serializable {
|
||||||
private static final String FILE_NAME = "LoginTokenSaveFile";
|
private static final String FILE_NAME = "LoginTokenSaving";
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String shibsessionKey;
|
private final String shibsessionKey;
|
||||||
@@ -43,7 +43,10 @@ public class LoginToken implements Serializable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
ObjectInputStream is = new ObjectInputStream(fis);
|
||||||
LoginToken loginToken = (LoginToken) is.readObject();
|
Object readObject = is.readObject();
|
||||||
|
if (!(readObject instanceof LoginToken))
|
||||||
|
return null;
|
||||||
|
LoginToken loginToken = (LoginToken) readObject;
|
||||||
is.close();
|
is.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
return loginToken;
|
return loginToken;
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
private SortedListModule list;
|
private SortedListModule list;
|
||||||
private final String mUsername;
|
private final String mUsername;
|
||||||
//private transient Logger log = new Logger(this);
|
//private transient Logger log = new Logger(this);
|
||||||
private static final String FILE_NAME = "ModuleListSaveFile";
|
private static final String FILE_NAME = "ModuleListSaving";
|
||||||
|
|
||||||
public Modules(String username) {
|
public Modules(String username) {
|
||||||
this.mUsername = username;
|
this.mUsername = username;
|
||||||
@@ -68,7 +68,10 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
public static Modules load(Context context) throws IOException, ClassNotFoundException {
|
public static Modules 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);
|
||||||
Modules modules = (Modules) is.readObject();
|
Object readObject = is.readObject();
|
||||||
|
if (!(readObject instanceof Modules))
|
||||||
|
return null;
|
||||||
|
Modules modules = (Modules) readObject;
|
||||||
is.close();
|
is.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
return modules;
|
return modules;
|
||||||
|
|||||||
Reference in New Issue
Block a user