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