Compare commits
3 Commits
beta
...
kvvservice
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6325f312ea | ||
|
|
e0ed23dec5 | ||
|
|
bb85911324 |
@@ -7,8 +7,8 @@ android {
|
|||||||
applicationId "de.sebse.fuplanner"
|
applicationId "de.sebse.fuplanner"
|
||||||
minSdkVersion 15
|
minSdkVersion 15
|
||||||
targetSdkVersion 28
|
targetSdkVersion 28
|
||||||
versionCode 21
|
versionCode 16
|
||||||
versionName "1.4.2"
|
versionName "1.3.5"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -34,7 +34,7 @@ dependencies {
|
|||||||
})
|
})
|
||||||
implementation 'androidx.preference:preference:1.0.0'
|
implementation 'androidx.preference:preference:1.0.0'
|
||||||
implementation 'com.google.android.material:material:1.0.0'
|
implementation 'com.google.android.material:material:1.0.0'
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
||||||
implementation 'com.android.volley:volley:1.1.0'
|
implementation 'com.android.volley:volley:1.1.0'
|
||||||
//noinspection GradleDependency
|
//noinspection GradleDependency
|
||||||
implementation 'com.google.android.gms:play-services-auth:15.0.0'
|
implementation 'com.google.android.gms:play-services-auth:15.0.0'
|
||||||
|
|||||||
@@ -18,6 +18,8 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||||
|
|
||||||
<!-- To auto-complete the email text field in the login form with the user's emails -->
|
<!-- To auto-complete the email text field in the login form with the user's emails -->
|
||||||
|
<uses-permission android:name="android.permission.READ_PROFILE" />
|
||||||
|
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package de.sebse.fuplanner;
|
package de.sebse.fuplanner;
|
||||||
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
@@ -41,15 +39,13 @@ import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
|||||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||||
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
|
||||||
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.sync.KVVContentProvider;
|
|
||||||
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.services.news.NewsManager;
|
import de.sebse.fuplanner.services.news.NewsManager;
|
||||||
|
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
import de.sebse.fuplanner.tools.CustomNotificationManager;
|
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
import de.sebse.fuplanner.tools.Preferences;
|
||||||
@@ -140,12 +136,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
changeFragment(getDefaultFragmentAfterLogout());
|
changeFragment(getDefaultFragmentAfterLogout());
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
|
|
||||||
registerSync();
|
|
||||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
|
||||||
}
|
|
||||||
CustomNotificationManager.createNotificationChannel(this);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -168,7 +158,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
changeFragment(getDefaultFragmentAfterLogout());
|
changeFragment(getDefaultFragmentAfterLogout());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
getKVV().modules().list().reloadIfOutdated();
|
|
||||||
}
|
}
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
}
|
}
|
||||||
@@ -361,18 +350,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
changeFragment(newFragment);
|
changeFragment(newFragment);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void registerSync() {
|
|
||||||
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
|
||||||
if (accountByType != null) {
|
|
||||||
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
|
|
||||||
ContentResolver.addPeriodicSync(
|
|
||||||
accountByType,
|
|
||||||
KVVContentProvider.PROVIDER_NAME,
|
|
||||||
Bundle.EMPTY,
|
|
||||||
AccountGeneral.SYNC_INTERVAL);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void changeFragment(int newFragment) {
|
private void changeFragment(int newFragment) {
|
||||||
changeFragment(newFragment, "");
|
changeFragment(newFragment, "");
|
||||||
}
|
}
|
||||||
@@ -658,11 +635,8 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLogin(LoginToken token, boolean isOnlyRefresh) {
|
public void onLogin(LoginToken token) {
|
||||||
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin());
|
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin());
|
||||||
if (!isOnlyRefresh) {
|
|
||||||
registerSync();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -178,7 +178,7 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
end = UtilsDate.getModifiedDate(lastDateTime);
|
end = UtilsDate.getModifiedDate(lastDateTime);
|
||||||
weekday = UtilsDate.getModifiedDate(context, firstDateTime, "E");
|
weekday = UtilsDate.getModifiedDate(context, firstDateTime, "E");
|
||||||
startTime = UtilsDate.getModifiedTime(context, firstDateTime);
|
startTime = UtilsDate.getModifiedTime(context, firstDateTime);
|
||||||
endTime = UtilsDate.getModifiedTime(context, lastDateTime+1);
|
endTime = UtilsDate.getModifiedTime(context, lastDateTime);
|
||||||
for (long skippedDate : group.getSkippedDates()) {
|
for (long skippedDate : group.getSkippedDates()) {
|
||||||
if (excepts == null) {
|
if (excepts == null) {
|
||||||
excepts = new StringBuilder(UtilsDate.getModifiedDate(skippedDate));
|
excepts = new StringBuilder(UtilsDate.getModifiedDate(skippedDate));
|
||||||
@@ -199,9 +199,9 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
else
|
else
|
||||||
start = UtilsDate.getModifiedDateTime(context, event.getStartDate());
|
start = UtilsDate.getModifiedDateTime(context, event.getStartDate());
|
||||||
if (UtilsDate.dateEquals(event.getStartDate(), event.getEndDate()))
|
if (UtilsDate.dateEquals(event.getStartDate(), event.getEndDate()))
|
||||||
end = UtilsDate.getModifiedTime(context, event.getEndDate()+1);
|
end = UtilsDate.getModifiedTime(context, event.getEndDate());
|
||||||
else
|
else
|
||||||
end = UtilsDate.getModifiedDateTime(context, event.getEndDate()+1);
|
end = UtilsDate.getModifiedDateTime(context, event.getEndDate());
|
||||||
date = context.getString(R.string.date_scale, start, end);
|
date = context.getString(R.string.date_scale, start, end);
|
||||||
iu.mTitle.setText(event.getTitle());
|
iu.mTitle.setText(event.getTitle());
|
||||||
iu.mSubLeft.setText(date);
|
iu.mSubLeft.setText(date);
|
||||||
|
|||||||
@@ -193,9 +193,9 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
else
|
else
|
||||||
start = UtilsDate.getModifiedDateTime(i.mView.getContext(), event.getStartDate());
|
start = UtilsDate.getModifiedDateTime(i.mView.getContext(), event.getStartDate());
|
||||||
if (UtilsDate.dateEquals(event.getStartDate(), event.getEndDate()))
|
if (UtilsDate.dateEquals(event.getStartDate(), event.getEndDate()))
|
||||||
end = UtilsDate.getModifiedTime(i.mView.getContext(), event.getEndDate()+1);
|
end = UtilsDate.getModifiedTime(i.mView.getContext(), event.getEndDate());
|
||||||
else
|
else
|
||||||
end = UtilsDate.getModifiedDateTime(i.mView.getContext(), event.getEndDate()+1);
|
end = UtilsDate.getModifiedDateTime(i.mView.getContext(), event.getEndDate());
|
||||||
i.mSubRight.setText(i.mView.getResources().getString(R.string.date_scale,
|
i.mSubRight.setText(i.mView.getResources().getString(R.string.date_scale,
|
||||||
start, end
|
start, end
|
||||||
));
|
));
|
||||||
|
|||||||
@@ -4,5 +4,4 @@ public class AccountGeneral {
|
|||||||
public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth";
|
public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth";
|
||||||
public static final String AUTHTOKEN_TYPE_KVV = "KVV";
|
public static final String AUTHTOKEN_TYPE_KVV = "KVV";
|
||||||
public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard";
|
public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard";
|
||||||
public static final long SYNC_INTERVAL = 6 * 60 * 60; // defined in seconds
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -14,8 +14,8 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.kvv.sync.Login;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
|
import de.sebse.fuplanner.services.kvv.sync.Login;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
|
|
||||||
@@ -62,25 +62,32 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
|||||||
mVolleyLogin.testLoginToken(success, success1 -> {
|
mVolleyLogin.testLoginToken(success, success1 -> {
|
||||||
login.set(success);
|
login.set(success);
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
}, error -> {
|
}, error -> latch.countDown());
|
||||||
log.e(error);
|
}, error -> latch.countDown());
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
try {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
log.d(login.get());
|
||||||
|
|
||||||
if (login.get() == null) {
|
if (login.get() == null) {
|
||||||
return null;
|
return null;
|
||||||
} else {
|
} else {
|
||||||
return login.get().toJsonString();
|
return login.get().toJsonString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*for (String credential : DUMMY_CREDENTIALS) {
|
||||||
|
String[] pieces = credential.split(":");
|
||||||
|
if (pieces[0].equals(mEmail)) {
|
||||||
|
// Account exists, return true if the password matches.
|
||||||
|
return pieces[1].equals(mPassword) ? "auth token here" : null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: register the new account here.
|
||||||
|
return null;*/
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
|||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
|
|
||||||
public interface KVVListener {
|
public interface KVVListener {
|
||||||
default void onLogin(LoginToken token, boolean isOnlyRefresh) {}
|
default void onLogin(LoginToken token) {}
|
||||||
|
|
||||||
default void onLogout() {}
|
default void onLogout() {}
|
||||||
|
|
||||||
|
|||||||
@@ -5,8 +5,8 @@ import android.content.Context;
|
|||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
|
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
import de.sebse.fuplanner.tools.NetworkCallbackCollector;
|
import de.sebse.fuplanner.tools.NetworkCallbackCollector;
|
||||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||||
@@ -34,6 +34,7 @@ public class Login extends HTTPService {
|
|||||||
LoginToken.load(mListener.getAccountManager(), token -> {
|
LoginToken.load(mListener.getAccountManager(), token -> {
|
||||||
boolean result = setToken(token);
|
boolean result = setToken(token);
|
||||||
mLoginPending = false;
|
mLoginPending = false;
|
||||||
|
log.d("loginToken", token != null ? token.toString() : null);
|
||||||
callback.run(result);
|
callback.run(result);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -52,7 +53,7 @@ public class Login extends HTTPService {
|
|||||||
if (delete)
|
if (delete)
|
||||||
mToken.delete(mListener.getAccountManager());
|
mToken.delete(mListener.getAccountManager());
|
||||||
mToken = null;
|
mToken = null;
|
||||||
return handleCallbacks(false);
|
return handleCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoginPending() {
|
public boolean isLoginPending() {
|
||||||
@@ -103,9 +104,9 @@ public class Login extends HTTPService {
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean handleCallbacks(boolean isOnlyRefresh) {
|
private boolean handleCallbacks() {
|
||||||
if (mToken != null) {
|
if (mToken != null) {
|
||||||
mListener.onLogin(mToken, isOnlyRefresh);
|
mListener.onLogin(mToken);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
mListener.onLogout();
|
mListener.onLogout();
|
||||||
@@ -118,7 +119,7 @@ public class Login extends HTTPService {
|
|||||||
return false;
|
return false;
|
||||||
boolean isOnlyRefresh = mToken != null;
|
boolean isOnlyRefresh = mToken != null;
|
||||||
mToken = token;
|
mToken = token;
|
||||||
return isOnlyRefresh || handleCallbacks(isOnlyRefresh);
|
return isOnlyRefresh || handleCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface BooleanInterface {
|
public interface BooleanInterface {
|
||||||
|
|||||||
@@ -46,16 +46,6 @@ public class ModulesList extends HTTPService {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void reloadIfOutdated() {
|
|
||||||
try {
|
|
||||||
if (mModules != null && mModules.isNewerVersionInStorage(getContext())) {
|
|
||||||
restore();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback) {
|
public void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback) {
|
||||||
find(moduleID, moduleNetworkCallback, errorCallback, RETRY_COUNT);
|
find(moduleID, moduleNetworkCallback, errorCallback, RETRY_COUNT);
|
||||||
}
|
}
|
||||||
@@ -125,7 +115,7 @@ public class ModulesList extends HTTPService {
|
|||||||
this.upgrade(success -> {
|
this.upgrade(success -> {
|
||||||
if (this.mModules == null)
|
if (this.mModules == null)
|
||||||
this.mModules = success;
|
this.mModules = success;
|
||||||
else if(this.mModules.updateList(success)) {
|
else if (this.mModules.updateList(success)) {
|
||||||
mListener.onModuleListChange();
|
mListener.onModuleListChange();
|
||||||
store();
|
store();
|
||||||
}
|
}
|
||||||
@@ -149,6 +139,7 @@ public class ModulesList extends HTTPService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void upgrade(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
private void upgrade(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
log.d(mLogin.isInOnlineMode(), mLogin.getLoginToken());
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
errorCallback.onError(new NetworkError(101105, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101105, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
package de.sebse.fuplanner.services.kvv;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
@@ -10,9 +9,6 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLDecoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
@@ -99,18 +95,10 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
} else {
|
} else {
|
||||||
// in sub folder
|
// in sub folder
|
||||||
for (Resource res2: resources) {
|
for (Resource res2: resources) {
|
||||||
try {
|
if (res2.getUrl().endsWith(res.getContainer()) && res2 instanceof Resource.Folder) {
|
||||||
String utf8Name;
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
|
||||||
utf8Name = StandardCharsets.UTF_8.name();
|
|
||||||
else utf8Name = "UTF-8";
|
|
||||||
if (URLDecoder.decode(res2.getUrl(), utf8Name).endsWith(res.getContainer()) && res2 instanceof Resource.Folder) {
|
|
||||||
// Append File/Folder to list
|
// Append File/Folder to list
|
||||||
((Resource.Folder) res2).add(res);
|
((Resource.Folder) res2).add(res);
|
||||||
}
|
}
|
||||||
} catch (UnsupportedEncodingException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
public class KVVContentProvider extends ContentProvider {
|
public class KVVContentProvider extends ContentProvider {
|
||||||
|
|
||||||
public static final String PROVIDER_NAME = "de.sebse.fuplanner.contentprovider.kvv.modules";
|
private static final String PROVIDER_NAME = "de.sebse.fuplanner.contentprovider.kvv.modules";
|
||||||
private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/modules");
|
private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/modules");
|
||||||
private static final int MODULE = 1;
|
private static final int MODULE = 1;
|
||||||
private static final int MODULE_ID = 2;
|
private static final int MODULE_ID = 2;
|
||||||
|
|||||||
@@ -8,30 +8,20 @@ import android.content.Context;
|
|||||||
import android.content.SyncResult;
|
import android.content.SyncResult;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import com.android.volley.NetworkResponse;
|
||||||
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
|
||||||
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.KVVListener;
|
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Assignment;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.AssignmentList;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.EventList;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Grade;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
import de.sebse.fuplanner.tools.CustomNotificationManager;
|
|
||||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
private KVV mKVV;
|
private KVV mKVV;
|
||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set up the sync adapter
|
* Set up the sync adapter
|
||||||
@@ -55,7 +45,6 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
|
|
||||||
private void init(Context context) {
|
private void init(Context context) {
|
||||||
mKVV = new KVV(new KVVListener() {
|
mKVV = new KVV(new KVVListener() {
|
||||||
|
|
||||||
CustomAccountManager accountManager = null;
|
CustomAccountManager accountManager = null;
|
||||||
@Override
|
@Override
|
||||||
public CustomAccountManager getAccountManager() {
|
public CustomAccountManager getAccountManager() {
|
||||||
@@ -64,11 +53,7 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
return accountManager;
|
return accountManager;
|
||||||
}
|
}
|
||||||
}, context);
|
}, context);
|
||||||
mQueue.add(() -> {
|
mKVV.account().restoreOnlineLogin(bool -> {});
|
||||||
mKVV.account().restoreOnlineLogin(bool -> {
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@@ -83,73 +68,20 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|||||||
String authority,
|
String authority,
|
||||||
ContentProviderClient provider,
|
ContentProviderClient provider,
|
||||||
SyncResult syncResult) {
|
SyncResult syncResult) {
|
||||||
mQueue.add(() -> {
|
log.d("start syncing");
|
||||||
|
/*
|
||||||
|
* Put the data transfer code here.
|
||||||
|
*/
|
||||||
mKVV.modules().list().recv(success -> {
|
mKVV.modules().list().recv(success -> {
|
||||||
Iterator<Modules.Module> iterator = success.latestSemesterIterator();
|
Iterator<Modules.Module> iterator = success.latestSemesterIterator();
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
Modules.Module module = iterator.next();
|
Modules.Module module = iterator.next();
|
||||||
final ArrayList<Announcement> announcements = module.announcements;
|
log.d("sync module", module.title);
|
||||||
final AssignmentList assignments = module.assignments;
|
|
||||||
final EventList events = module.events;
|
|
||||||
final ArrayList<Grade> gradebook = module.gradebook;
|
|
||||||
final ArrayList<Resource> resources = module.resources;
|
|
||||||
mKVV.modules().details().recv(module, success1 -> {
|
mKVV.modules().details().recv(module, success1 -> {
|
||||||
if (success1.second) {
|
if (success1.second)
|
||||||
sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
|
log.d("Sync Successful for Module '"+module.title+"'!");
|
||||||
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
|
}, log::e, true);
|
||||||
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
|
|
||||||
R.string.assignment_updated, R.string.assignment_added, R.string.assignment_removed);
|
|
||||||
sendNotifications(events, module.events, module.title, evt -> evt.getTitle()+" - "+UtilsDate.getModifiedDate(evt.getStartDate()), event -> String.valueOf(event.getStartDate()),
|
|
||||||
R.string.event_updated, R.string.event_added, R.string.event_removed);
|
|
||||||
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
|
|
||||||
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
|
|
||||||
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
|
||||||
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
|
||||||
mQueue.next();
|
|
||||||
}
|
}
|
||||||
}, msg -> {
|
}, log::e, true);
|
||||||
log.e(msg);
|
|
||||||
mQueue.next();
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
}, msg -> {
|
|
||||||
log.e(msg);
|
|
||||||
mQueue.next();
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes) {
|
|
||||||
if (oldList == null || newList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<T> obsoletes = new ArrayList<>();
|
|
||||||
for (T old: oldList) {
|
|
||||||
obsoletes.add(old);
|
|
||||||
}
|
|
||||||
for (T newEntry: newList) {
|
|
||||||
boolean found = false;
|
|
||||||
for (T oldEntry: oldList) {
|
|
||||||
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
|
|
||||||
found = true;
|
|
||||||
if (newEntry.hashCode() != oldEntry.hashCode()) {
|
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry));
|
|
||||||
}
|
|
||||||
obsoletes.remove(oldEntry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (T oldEntry: obsoletes) {
|
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
interface StringInterface<T> {
|
|
||||||
String get(T element);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,34 +56,56 @@ public class Login extends HTTPService {
|
|||||||
|
|
||||||
|
|
||||||
public void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
public void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
||||||
step1(success1 -> {
|
startKVVSession(success -> {
|
||||||
String samlLocation = success1.get("Location");
|
String kvvJSESSIONID = success.get("JSESSIONID");
|
||||||
step2(samlLocation, success2 -> {
|
getSAMLRequest(kvvJSESSIONID, success1 -> startIdentSession(success1.get("Location"), success11 -> {
|
||||||
String fuJSESSIONID = success2.get("JSESSIONID");
|
String identJSESSIONID = success11.get("JSESSIONID");
|
||||||
step3(fuJSESSIONID, success3 -> {
|
String ident_idp_authn_lc_key = success11.get("_idp_authn_lc_key");
|
||||||
step4(username, password, fuJSESSIONID, success4 -> {
|
String identROUTEID = success11.get("ROUTEID");
|
||||||
String samlResponse = success4.get("SAMLResponse");
|
loginIdent(true, username, password, identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, success111 -> loginIdent(false, username, password, identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, success11112 -> {
|
||||||
step5(samlResponse, success5 -> {
|
String ident_idp_session = success11112.get("_idp_session");
|
||||||
String shibsessionKey = success5.get("shibsessionKey");
|
getSAMLResponse(identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, ident_idp_session, success1111 -> loginKVV(success1111.get("RelayState"), success1111.get("SAMLResponse"), kvvJSESSIONID, success111112 -> {
|
||||||
String shibsessionName = success5.get("shibsessionName");
|
LoginToken token = new LoginToken(username, success111112.get("shibsessionKey"), success111112.get("shibsessionName"), kvvJSESSIONID);
|
||||||
step6(shibsessionKey, shibsessionName, success6 -> {
|
finishKVVlogin(token, success11111 -> callback.onResponse(token), error);
|
||||||
String kvvJSESSIONID = success6.get("JSESSIONID");
|
}, error), error);
|
||||||
LoginToken token = new LoginToken(username, kvvJSESSIONID);
|
}, error), error);
|
||||||
callback.onResponse(token);
|
}, error), error);
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
}, error);
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
1= GET https://kvv.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub
|
GET https://kvv.imp.fu-berlin.de/portal/login
|
||||||
-> Location-Header: https://identity.fu-berlin.de:9443/idp-fub-qa/profile/SAML2/Redirect/SSO?SAMLResponse=[SAMLResponse]&RelayState=[RelayState]
|
-> JSESSIONID 5c10406f-588c-4c16-96e9-c80d115417de.tomcat1
|
||||||
*/
|
*/
|
||||||
private void step1(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
private void startKVVSession(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
get("https://kvv.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub", null, response -> {
|
get("https://kvv.imp.fu-berlin.de/portal/login", null, response -> {
|
||||||
|
String cookies = response.getHeaders().get("Set-Cookie");
|
||||||
|
if (cookies==null) {
|
||||||
|
errorCallback.onError(new NetworkError(100101, -1, "Error on starting KVV session!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashMap<String, String> object;
|
||||||
|
try {
|
||||||
|
object = getCookie(cookies, new String[]{"JSESSIONID"});
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
errorCallback.onError(new NetworkError(100102, -1, "Error on starting KVV session!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100100, error.networkResponse.statusCode, "Error on starting KVV session!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container
|
||||||
|
<- JSESSIONID
|
||||||
|
-> (Location-Header) https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
|
||||||
|
?SAMLRequest=fZLLb.....Q8yre3X1IHwkJKE0Mnpy/V9TH4A
|
||||||
|
&RelayState=ss:mem:7ea01e29157b8bd906f7002176.....0d1a505f2c8bf
|
||||||
|
*/
|
||||||
|
private void getSAMLRequest(String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("JSESSIONID", JSESSIONID);
|
||||||
|
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", cookies, response -> {
|
||||||
String location = response.getHeaders().get("Location");
|
String location = response.getHeaders().get("Location");
|
||||||
if (location==null) {
|
if (location==null) {
|
||||||
errorCallback.onError(new NetworkError(100111, -1, "Error on getting SAML request!"));
|
errorCallback.onError(new NetworkError(100111, -1, "Error on getting SAML request!"));
|
||||||
@@ -96,98 +118,133 @@ public class Login extends HTTPService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
2= GET [Location-Header 1]
|
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
|
||||||
-> Set-Cookie: JSESSIONID=[JSESSION-FU]
|
?SAMLRequest=fZLLbsIwEEV/JfI+cWJAUIsgpbAoEi2IpF10UznxUKw6dupxaPn7hkdb2LD29bkzRzNGUeuGZ63fmjV8toA++K61QX58SEnrDLcCFXIjakDuK55njwvOopg3znpbWU2CDBGcV9ZMrcG2BpeD26kKnteLlGy9b5BT+rHbRapuok0bluC0MpEEmm9VWVoNfhshWnpgM7pa5gUJZt0wyogD9h+iJBiv/P6aomQTbtqSdhNtlIYzZg1SOag8zfMlCeazlLyNqpHsy1gO2V1fVsNBMuqJoUyAJaxXDUaiiyG2MDfohfEpYXEyDJM4ZKxgCe/FPI5fSbA6L36vjFTm/bal8hRC/lAUq/C02gs4PK7VBchkfHDNj8Xuwv5trPhVTiY3BeOf4DG96DmVNvypA89nK6tVtQ8yre3X1IHwkJKE0Mnpy/V9TH4A
|
||||||
-> Location: /idp-fub-qa/profile/SAML2/Redirect/SSO?execution=e1s1
|
&RelayState=ss:mem:7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
|
||||||
|
-> JSESSIONID C4B6A428BA1F50746235D03F5D107A57
|
||||||
|
-> _idp_authn_lc_key 57a6ae26067f374cc3d0ccfc47e27b04b47752d2a3d4eb2782af0d3994535395
|
||||||
|
-> ROUTEID .1
|
||||||
*/
|
*/
|
||||||
private void step2(String url, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
private void startIdentSession(String url, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
get(url, null, response -> {
|
get(url, null, response -> {
|
||||||
String cookies = response.getHeaders().get("Set-Cookie");
|
String cookies = response.getHeaders().get("Set-Cookie");
|
||||||
if (cookies==null) {
|
if (cookies==null) {
|
||||||
errorCallback.onError(new NetworkError(100121, -1, "Error on starting FU session!"));
|
errorCallback.onError(new NetworkError(100121, -1, "Error on starting Ident session!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashMap<String, String> object;
|
HashMap<String, String> object;
|
||||||
try {
|
try {
|
||||||
object = getCookie(cookies, new String[]{"JSESSIONID"});
|
object = getCookie(cookies, new String[]{"JSESSIONID", "_idp_authn_lc_key", "ROUTEID"});
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
errorCallback.onError(new NetworkError(100122, -1, "Error on starting FU session!"));
|
errorCallback.onError(new NetworkError(100122, -1, "Error on starting Ident session!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
callback.onResponse(object);
|
callback.onResponse(object);
|
||||||
}, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting FU session!")));
|
}, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting Ident session!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
3= GET [Location-Header 2]
|
POST https://identity.fu-berlin.de/idp-fub/Authn/UserPassword
|
||||||
+ Cookie: JSESSIONID=[JSESSION-FU]
|
<- j_username seedorf96
|
||||||
|
<- j_password neinhieristpatrick
|
||||||
|
<- (Header-"Content-Type") application/x-www-form-urlencoded
|
||||||
|
<- JSESSIONID
|
||||||
|
<- _idp_authn_lc_key
|
||||||
|
<- ROUTEID
|
||||||
|
-> _idp_session OTMuMTkzLjg1LjMz|LQ==|OGYxOWI4MjA2NTQ4YWUwYzJkOWM4Mjk4YzcwZDMwZmJiZjBmMTdmMzkyZGU2OWIwY2JkNmZlNjlmNTRmNzBlMQ==|wLlzQal7VqyntmG2vLNn06wt8wQ=
|
||||||
*/
|
*/
|
||||||
private void step3(String JSESSIONID_FU, final NetworkCallback<Boolean> callback, final NetworkErrorCallback errorCallback) {
|
private void loginIdent(final boolean first, String username, String password, String JSESSIONID, String _idp_authn_lc_key, String ROUTEID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
cookies.put("JSESSIONID", JSESSIONID_FU);
|
cookies.put("JSESSIONID", JSESSIONID);
|
||||||
get("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, response -> {
|
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key);
|
||||||
callback.onResponse(true);
|
cookies.put("ROUTEID", ROUTEID);
|
||||||
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error starting login page!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
4= POST [Location-Header 2]
|
|
||||||
+ Body: j_username=[USERNAME]&j_password=[PASSWORD]&_eventId_proceed=
|
|
||||||
+ Header: Content-Type: application/x-www-form-urlencoded
|
|
||||||
+ Header: Referer: [Location-Header 2]
|
|
||||||
+ Cookie: JSESSIONID=[JSESSION-FU]
|
|
||||||
-> Set-Cookie: shib_idp_session=[SHIB-IDP-SESSION]
|
|
||||||
-> Body SAMLResponse-Input-value
|
|
||||||
*/
|
|
||||||
private void step4(String username, String password, String JSESSIONID_FU, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put("JSESSIONID", JSESSIONID_FU);
|
|
||||||
HashMap<String, String> body = new HashMap<>();
|
HashMap<String, String> body = new HashMap<>();
|
||||||
body.put("j_username", username);
|
body.put("j_username", username);
|
||||||
body.put("j_password", password);
|
body.put("j_password", password);
|
||||||
body.put("_eventId_proceed", "");
|
post("https://identity.fu-berlin.de/idp-fub/Authn/UserPassword", cookies, body, response -> {
|
||||||
post("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, body, response -> {
|
if (first) {
|
||||||
|
callback.onResponse(new HashMap<>());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
String cookies1 = response.getHeaders().get("Set-Cookie");
|
String cookies1 = response.getHeaders().get("Set-Cookie");
|
||||||
if (cookies1 ==null) {
|
if (cookies1 ==null) {
|
||||||
errorCallback.onError(new NetworkError(100141, -1, "Error on logging in to FU Identity Server!"));
|
errorCallback.onError(new NetworkError(100131, -1, "Error on logging in to Identity Server!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
HashMap<String, String> object;
|
HashMap<String, String> object;
|
||||||
try {
|
try {
|
||||||
object = getCookie(cookies1, new String[]{"shib_idp_session"});
|
object = getCookie(cookies1, new String[]{"_idp_session"});
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
errorCallback.onError(new NetworkError(100142, -1, "Error on logging in to FU Identity Server!"));
|
errorCallback.onError(new NetworkError(100132, -1, "Error on logging in to Identity Server!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
String content = response.getParsed();
|
|
||||||
if (content == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100143, -1, "Error on getting SAML response!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pattern pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
|
|
||||||
Matcher matcher = pattern.matcher(content);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
errorCallback.onError(new NetworkError(100144, -1, "Error on getting SAML response!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
object.put("SAMLResponse", matcher.group(1));
|
|
||||||
callback.onResponse(object);
|
callback.onResponse(object);
|
||||||
}, error -> errorCallback.onError(new NetworkError(100145, error.networkResponse.statusCode, "Error on logging in to FU Identity Server!")));
|
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error on logging in to Identity Server!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
5= POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
|
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
|
||||||
+ Body: SAMLResponse=[SAML-RESPONSE]
|
<- JSESSIONID
|
||||||
+ Header: Content-Type: application/x-www-form-urlencoded
|
<- _idp_authn_lc_key
|
||||||
-> Set-Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
<- ROUTEID
|
||||||
|
<- _idp_session
|
||||||
|
-> (BODY) RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
|
||||||
|
-> (BODY) SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg==
|
||||||
*/
|
*/
|
||||||
private void step5(String SAMLResponse, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
private void getSAMLResponse(String JSESSIONID, String _idp_authn_lc_key, String ROUTEID, String _idp_session, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("JSESSIONID", JSESSIONID);
|
||||||
|
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key);
|
||||||
|
cookies.put("ROUTEID", ROUTEID);
|
||||||
|
cookies.put("_idp_session", _idp_session);
|
||||||
|
get("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO", cookies, response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(100143, -1, "Error on getting SAML response!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
HashMap<String, String> object = new HashMap<>();
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile("ss:mem:([0-9a-f]+)");
|
||||||
|
Matcher matcher = pattern.matcher(body);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
errorCallback.onError(new NetworkError(100142, -1, "Error on getting SAML response!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
object.put("RelayState", "ss:mem:"+matcher.group(1));
|
||||||
|
|
||||||
|
pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
|
||||||
|
matcher = pattern.matcher(body);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
errorCallback.onError(new NetworkError(100141, -1, "Error on getting SAML response!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
object.put("SAMLResponse", matcher.group(1));
|
||||||
|
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100140, error.networkResponse.statusCode, "Error on getting SAML response!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
|
||||||
|
<- RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
|
||||||
|
<- SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg==
|
||||||
|
<- JSESSIONID
|
||||||
|
-> _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
|
||||||
|
_b1912c5a03d733a80bd3fee772bf68d4
|
||||||
|
*/
|
||||||
|
private void loginKVV(String RelayState, String SAMLResponse, String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("JSESSIONID", JSESSIONID);
|
||||||
HashMap<String, String> body = new HashMap<>();
|
HashMap<String, String> body = new HashMap<>();
|
||||||
|
body.put("RelayState", RelayState);
|
||||||
body.put("SAMLResponse", SAMLResponse);
|
body.put("SAMLResponse", SAMLResponse);
|
||||||
post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", null, body, response -> {
|
post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", cookies, body, response -> {
|
||||||
String cookies = response.getHeaders().get("Set-Cookie");
|
String cookies1 = response.getHeaders().get("Set-Cookie");
|
||||||
if (cookies ==null) {
|
if (cookies1 ==null) {
|
||||||
errorCallback.onError(new NetworkError(100151, -1, "Error on starting KVV session!"));
|
errorCallback.onError(new NetworkError(100151, -1, "Error on starting KVV session!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -195,41 +252,26 @@ public class Login extends HTTPService {
|
|||||||
|
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
|
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
|
||||||
Matcher matcher = pattern.matcher(cookies);
|
Matcher matcher = pattern.matcher(cookies1);
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
errorCallback.onError(new NetworkError(100152, -1, "Error on starting KVV session!"));
|
errorCallback.onError(new NetworkError(100152, -1, "Error on starting Ident session!"));
|
||||||
}
|
}
|
||||||
object.put("shibsessionKey", matcher.group(1));
|
object.put("shibsessionKey", matcher.group(1));
|
||||||
object.put("shibsessionName", matcher.group(2));
|
object.put("shibsessionName", matcher.group(2));
|
||||||
|
|
||||||
callback.onResponse(object);
|
callback.onResponse(object);
|
||||||
}, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting KVV session!")));
|
}, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting Ident session!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
6= https://kvv.imp.fu-berlin.de/sakai-login-tool/container
|
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container
|
||||||
+ Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
<- JSESSIONID
|
||||||
-> Set-Cookie: JSESSIONID: [JSESSION-KVV]
|
<- _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
|
||||||
|
_b1912c5a03d733a80bd3fee772bf68d4
|
||||||
*/
|
*/
|
||||||
private void step6(String shibsessionKey, String shibsessionName, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
private void finishKVVlogin(LoginToken loginToken, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", loginToken.getCookies(), response -> callback.onResponse(new HashMap<>()), error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish login process!")));
|
||||||
cookies.put(shibsessionKey, shibsessionName);
|
|
||||||
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", cookies, response -> {
|
|
||||||
String cookies1 = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookies1 ==null) {
|
|
||||||
errorCallback.onError(new NetworkError(100161, -1, "Cannot finish login process!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
HashMap<String, String> object;
|
|
||||||
try {
|
|
||||||
object = getCookie(cookies1, new String[]{"JSESSIONID"});
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
errorCallback.onError(new NetworkError(100162, -1, "Cannot finish login process!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback.onResponse(object);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish login process!")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,12 +2,16 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Announcement implements Serializable {
|
public class Announcement implements UtilsJson.JsonConvertible {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String title;
|
private final String title;
|
||||||
private final String body;
|
private final String body;
|
||||||
@@ -24,11 +28,24 @@ public class Announcement implements Serializable {
|
|||||||
this.urls = urls;
|
this.urls = urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Announcement(JSONObject json) throws JSONException {
|
||||||
|
this.id = json.getString("id");
|
||||||
|
this.title = json.getString("title");
|
||||||
|
this.body = json.getString("body");
|
||||||
|
this.createdBy = json.getString("createdBy");
|
||||||
|
this.createdOn = json.getLong("createdOn");
|
||||||
|
ArrayList<String> urls = new ArrayList<>();
|
||||||
|
for (String url: UtilsJson.jsonArrayToIterableString(json.getJSONArray("urls"))) {
|
||||||
|
urls.add(url);
|
||||||
|
}
|
||||||
|
this.urls = urls;
|
||||||
|
}
|
||||||
|
|
||||||
public ArrayList<String> getUrls() {
|
public ArrayList<String> getUrls() {
|
||||||
return urls;
|
return urls;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
private String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -63,4 +80,16 @@ public class Announcement implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getId(), getBody(), getCreatedBy(), getCreatedOn(), getTitle(), getUrls());
|
return Objects.hashCode(getId(), getBody(), getCreatedBy(), getCreatedOn(), getTitle(), getUrls());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("id", id);
|
||||||
|
json.put("title", title);
|
||||||
|
json.put("body", body);
|
||||||
|
json.put("createdBy", createdBy);
|
||||||
|
json.put("createdOn", createdOn);
|
||||||
|
json.put("urls", UtilsJson.collectionToJson(urls));
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,12 +2,15 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Assignment implements Serializable {
|
public class Assignment implements UtilsJson.JsonConvertible {
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String title;
|
private final String title;
|
||||||
private final long dueTime;
|
private final long dueTime;
|
||||||
@@ -22,7 +25,7 @@ public class Assignment implements Serializable {
|
|||||||
this.instructions = instructions;
|
this.instructions = instructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId() {
|
private String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,4 +62,15 @@ public class Assignment implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getId(), getDueDate(), getInstructions(), getTitle(), getUrls());
|
return Objects.hashCode(getId(), getDueDate(), getInstructions(), getTitle(), getUrls());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("id", id);
|
||||||
|
json.put("title", title);
|
||||||
|
json.put("dueTime", dueTime);
|
||||||
|
json.put("createdBy", UtilsJson.collectionToJson(urls));
|
||||||
|
json.put("instructions", instructions);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,18 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import de.sebse.fuplanner.tools.ColorRGB;
|
import de.sebse.fuplanner.tools.ColorRGB;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Event implements Serializable {
|
public class Event implements UtilsJson.JsonConvertible {
|
||||||
private final String siteId;
|
private final String siteId;
|
||||||
private final String id;
|
private final String id;
|
||||||
private final String type;
|
private final String type;
|
||||||
@@ -118,6 +121,19 @@ public class Event implements Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getType(), getStartDate(), getEndDate(), getTitle(), getLocation());
|
return Objects.hashCode(getId(), getType(), getStartDate(), getEndDate(), getTitle(), getLocation());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("siteId", siteId);
|
||||||
|
json.put("id", id);
|
||||||
|
json.put("type", type);
|
||||||
|
json.put("title", title);
|
||||||
|
json.put("duration", duration);
|
||||||
|
json.put("firstTime", firstTime);
|
||||||
|
json.put("location", location);
|
||||||
|
return json;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,11 +2,13 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Grade implements Serializable {
|
public class Grade implements UtilsJson.JsonConvertible {
|
||||||
private final String itemName;
|
private final String itemName;
|
||||||
private final double grade;
|
private final double grade;
|
||||||
private final double maxPoints;
|
private final double maxPoints;
|
||||||
@@ -41,4 +43,13 @@ public class Grade implements Serializable {
|
|||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(getItemName(), getPoints(), getMaxPoints());
|
return Objects.hashCode(getItemName(), getPoints(), getMaxPoints());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("itemName", itemName);
|
||||||
|
json.put("grade", grade);
|
||||||
|
json.put("maxPoints", maxPoints);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,12 +1,17 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Lecturer implements Serializable {
|
public class Lecturer implements UtilsJson.JsonConvertible {
|
||||||
private final String firstName;
|
private final String firstName;
|
||||||
private final String surname;
|
private final String surname;
|
||||||
private final String mail;
|
private final String mail;
|
||||||
@@ -24,6 +29,13 @@ public class Lecturer implements Serializable {
|
|||||||
this.isResponsible = matcher.group(4).equals("true");
|
this.isResponsible = matcher.group(4).equals("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Lecturer(JSONObject json) throws JSONException {
|
||||||
|
this.firstName = json.getString("firstName");
|
||||||
|
this.surname = json.getString("surname");
|
||||||
|
this.mail = json.getString("mail");
|
||||||
|
this.isResponsible = json.getBoolean("isResponsible");
|
||||||
|
}
|
||||||
|
|
||||||
public String getFirstName() {
|
public String getFirstName() {
|
||||||
return firstName;
|
return firstName;
|
||||||
}
|
}
|
||||||
@@ -55,4 +67,19 @@ public class Lecturer implements Serializable {
|
|||||||
"\nSurname: "+getSurname()+
|
"\nSurname: "+getSurname()+
|
||||||
"\nMail: "+getMail();
|
"\nMail: "+getMail();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getFirstName(), getSurname(), getMail(), isResponsible());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("firstName", firstName);
|
||||||
|
json.put("surname", surname);
|
||||||
|
json.put("mail", mail);
|
||||||
|
json.put("isResponsible", isResponsible);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,8 +1,12 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.Serializable;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -16,18 +20,21 @@ import de.sebse.fuplanner.tools.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class LoginToken {
|
public class LoginToken {
|
||||||
static Logger log = new Logger("LoginToken");
|
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
|
private final String shibsessionKey;
|
||||||
|
private final String shibsessionName;
|
||||||
private final String JSESSIONID;
|
private final String JSESSIONID;
|
||||||
@Nullable private String fullName;
|
@Nullable private String fullName;
|
||||||
@Nullable private String email;
|
@Nullable private String email;
|
||||||
|
|
||||||
public LoginToken(String username, String JSESSIONID) {
|
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
|
this.shibsessionKey = shibsessionKey;
|
||||||
|
this.shibsessionName = shibsessionName;
|
||||||
this.JSESSIONID = JSESSIONID;
|
this.JSESSIONID = JSESSIONID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
public static void load(CustomAccountManager manager, LoginTokenInterface callback) {
|
public static void load(CustomAccountManager manager, LoginTokenInterface callback) {
|
||||||
if (!manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
if (!manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||||
callback.run(null);
|
callback.run(null);
|
||||||
@@ -55,6 +62,14 @@ public class LoginToken {
|
|||||||
return username;
|
return username;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private String getShibsessionKey() {
|
||||||
|
return shibsessionKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getShibsessionName() {
|
||||||
|
return shibsessionName;
|
||||||
|
}
|
||||||
|
|
||||||
private String getJSESSIONID() {
|
private String getJSESSIONID() {
|
||||||
return JSESSIONID;
|
return JSESSIONID;
|
||||||
}
|
}
|
||||||
@@ -72,6 +87,7 @@ public class LoginToken {
|
|||||||
public HashMap<String, String> getCookies() {
|
public HashMap<String, String> getCookies() {
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
cookies.put("JSESSIONID", getJSESSIONID());
|
cookies.put("JSESSIONID", getJSESSIONID());
|
||||||
|
cookies.put(getShibsessionKey(), getShibsessionName());
|
||||||
cookies.put("pasystem_timezone_ok", "true");
|
cookies.put("pasystem_timezone_ok", "true");
|
||||||
return cookies;
|
return cookies;
|
||||||
}
|
}
|
||||||
@@ -95,6 +111,8 @@ public class LoginToken {
|
|||||||
JSONObject json = new JSONObject();
|
JSONObject json = new JSONObject();
|
||||||
try {
|
try {
|
||||||
json.put("username", username);
|
json.put("username", username);
|
||||||
|
json.put("shibsessionKey", shibsessionKey);
|
||||||
|
json.put("shibsessionName", shibsessionName);
|
||||||
json.put("JSESSIONID", JSESSIONID);
|
json.put("JSESSIONID", JSESSIONID);
|
||||||
json.put("fullName", fullName);
|
json.put("fullName", fullName);
|
||||||
json.put("email", email);
|
json.put("email", email);
|
||||||
@@ -104,11 +122,13 @@ public class LoginToken {
|
|||||||
return json.toString();
|
return json.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
private static LoginToken fromJsonString(String tokenString) {
|
public static LoginToken fromJsonString(String tokenString) {
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(tokenString);
|
JSONObject json = new JSONObject(tokenString);
|
||||||
LoginToken token = new LoginToken(
|
LoginToken token = new LoginToken(
|
||||||
json.getString("username"),
|
json.getString("username"),
|
||||||
|
json.getString("shibsessionName"),
|
||||||
|
json.getString("shibsessionName"),
|
||||||
json.getString("JSESSIONID"));
|
json.getString("JSESSIONID"));
|
||||||
if (!json.isNull("fullName"))
|
if (!json.isNull("fullName"))
|
||||||
token.setAdditionals(
|
token.setAdditionals(
|
||||||
|
|||||||
@@ -5,13 +5,20 @@ import android.content.Context;
|
|||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.BufferedReader;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
import java.io.ObjectOutputStream;
|
import java.io.ObjectOutputStream;
|
||||||
import java.io.Serializable;
|
import java.io.OutputStreamWriter;
|
||||||
|
import java.lang.reflect.Array;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
@@ -19,15 +26,19 @@ import java.util.LinkedHashSet;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
|
import static de.sebse.fuplanner.tools.UtilsJson.collectionToJson;
|
||||||
|
import static de.sebse.fuplanner.tools.UtilsJson.jsonArrayToIterableObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Created by sebastian on 29.10.17.
|
* Created by sebastian on 29.10.17.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public class Modules implements Iterable<Modules.Module>, Serializable {
|
public class Modules implements Iterable<Modules.Module> {
|
||||||
private SortedListModule list;
|
private SortedListModule list;
|
||||||
private final String mUsername;
|
private final String mUsername;
|
||||||
private transient long mLastTimestamp = 0;
|
private long mLoadTime;
|
||||||
//private transient Logger log = new Logger(this);
|
//private transient Logger log = new Logger(this);
|
||||||
private static final String FILE_NAME = "ModuleListSaving";
|
private static final String FILE_NAME = "ModuleListSaving";
|
||||||
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
|
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
|
||||||
@@ -70,47 +81,54 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
return this.list.get(index);
|
return this.list.get(index);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Modules load(Context context) throws IOException, ClassNotFoundException {
|
public static Modules load(Context context) throws IOException {
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
String ret = "";
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
InputStream inputStream = context.openFileInput(FILE_NAME);
|
||||||
Object readObject = is.readObject();
|
if (inputStream != null) {
|
||||||
if (!(readObject instanceof Modules))
|
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
|
||||||
return null;
|
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
|
||||||
Modules modules = (Modules) readObject;
|
String receiveString;
|
||||||
is.close();
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
fis.close();
|
while ((receiveString = bufferedReader.readLine()) != null) {
|
||||||
|
stringBuilder.append(receiveString);
|
||||||
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
}
|
||||||
is = new ObjectInputStream(fis);
|
inputStream.close();
|
||||||
modules.mLastTimestamp = is.readLong();
|
ret = stringBuilder.toString();
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
return modules;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isNewerVersionInStorage(Context context) throws IOException {
|
try {
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
JSONObject json = new JSONObject(ret);
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
Modules mod = new Modules(json.getString("username"));
|
||||||
boolean result = this.mLastTimestamp < is.readLong();
|
JSONArray arr = json.getJSONArray("modules");
|
||||||
is.close();
|
for (JSONObject jsonObject: jsonArrayToIterableObject(arr)) {
|
||||||
fis.close();
|
mod.list.add(new Module(jsonObject));
|
||||||
return result;
|
}
|
||||||
|
FileInputStream ofi = context.openFileInput(FILE_NAME_TIMESTAMP);
|
||||||
|
ObjectInputStream inputStream1 = new ObjectInputStream(ofi);
|
||||||
|
mod.mLoadTime = inputStream1.readLong();
|
||||||
|
return mod;
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
public void save(Context context) throws IOException {
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
JSONObject json = new JSONObject();
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
try {
|
||||||
os.writeObject(this);
|
json.put("username", mUsername);
|
||||||
os.close();
|
json.put("modules", UtilsJson.collectionToJson(list));
|
||||||
fos.close();
|
OutputStreamWriter osw = new OutputStreamWriter(context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE));
|
||||||
|
osw.write(json.toString());
|
||||||
|
osw.close();
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
fos = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
mLoadTime = System.currentTimeMillis();
|
||||||
os = new ObjectOutputStream(fos);
|
FileOutputStream ofo = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
||||||
this.mLastTimestamp = System.currentTimeMillis();
|
ObjectOutputStream outputStream = new ObjectOutputStream(ofo);
|
||||||
os.writeLong(this.mLastTimestamp);
|
outputStream.writeLong(mLoadTime);
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void delete(Context context) {
|
public void delete(Context context) {
|
||||||
@@ -139,8 +157,6 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
isChanged = true;
|
isChanged = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (this.list.size() != old.size())
|
|
||||||
isChanged = true;
|
|
||||||
return isChanged;
|
return isChanged;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -153,12 +169,11 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
return o1.hashCode() == o2.hashCode();
|
return o1.hashCode() == o2.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Module implements Serializable {
|
public static class Module implements UtilsJson.JsonConvertible {
|
||||||
@Nullable public final Semester semester;
|
@Nullable public final Semester semester;
|
||||||
@NotNull final HashSet<String> lvNumber;
|
@NotNull final HashSet<String> lvNumber;
|
||||||
@NotNull public final String title;
|
@NotNull public final String title;
|
||||||
@NotNull
|
@NotNull public final ArrayList<Lecturer> lecturer;
|
||||||
public final ArrayList<Lecturer> lecturer;
|
|
||||||
@Nullable public final String type;
|
@Nullable public final String type;
|
||||||
@Nullable public final String description;
|
@Nullable public final String description;
|
||||||
@NotNull private final String ID;
|
@NotNull private final String ID;
|
||||||
@@ -168,6 +183,29 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
@Nullable public ArrayList<Grade> gradebook;
|
@Nullable public ArrayList<Grade> gradebook;
|
||||||
@Nullable public ArrayList<Resource> resources;
|
@Nullable public ArrayList<Resource> resources;
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("semester", semester != null ? semester.toJSONObject() : null);
|
||||||
|
json.put("lvNumber", collectionToJson(lvNumber));
|
||||||
|
json.put("title", title);
|
||||||
|
json.put("lecturer", collectionToJson(lecturer));
|
||||||
|
json.put("type", type);
|
||||||
|
json.put("description", description);
|
||||||
|
json.put("ID", ID);
|
||||||
|
json.put("announcements", collectionToJson(announcements));
|
||||||
|
json.put("assignments", collectionToJson(assignments));
|
||||||
|
json.put("events", collectionToJson(events));
|
||||||
|
json.put("gradebook", collectionToJson(gradebook));
|
||||||
|
json.put("resources", collectionToJson(resources));
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
public float getGradebookPercent(){
|
public float getGradebookPercent(){
|
||||||
float maxPoint = 0;
|
float maxPoint = 0;
|
||||||
float userPoint = 0;
|
float userPoint = 0;
|
||||||
@@ -195,6 +233,71 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private Module(@NotNull JSONObject json) throws JSONException {
|
||||||
|
HashSet<String> lv = new HashSet<>();
|
||||||
|
for (String number: UtilsJson.jsonArrayToIterableString(json.getJSONArray("lvNumber"))) {
|
||||||
|
lv.add(number);
|
||||||
|
}
|
||||||
|
LinkedHashSet<Lecturer> lecturer = new LinkedHashSet<>();
|
||||||
|
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(json.getJSONArray("lecturer"))) {
|
||||||
|
lecturer.add(new Lecturer(l));
|
||||||
|
}
|
||||||
|
JSONObject obj = json.optJSONObject("semester");
|
||||||
|
|
||||||
|
this.semester = obj != null ? new Semester(obj) : null;
|
||||||
|
this.lvNumber = lv;
|
||||||
|
this.title = json.getString("title");
|
||||||
|
this.lecturer = new ArrayList<>(lecturer);
|
||||||
|
this.type = json.getString("type");
|
||||||
|
this.description = json.getString("description");
|
||||||
|
this.ID = json.getString("ID");
|
||||||
|
|
||||||
|
JSONArray arr = json.optJSONArray("announcements");
|
||||||
|
if (obj != null) {
|
||||||
|
ArrayList<Announcement> announce = new ArrayList<>();
|
||||||
|
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||||
|
announce.add(new Announcement(l));
|
||||||
|
}
|
||||||
|
this.announcements = announce;
|
||||||
|
}
|
||||||
|
arr = json.optJSONArray("assignments");
|
||||||
|
if (obj != null) {
|
||||||
|
AssignmentList assign = new AssignmentList();
|
||||||
|
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||||
|
assign.add(new Assignment(l));
|
||||||
|
}
|
||||||
|
this.assignments = assign;
|
||||||
|
}
|
||||||
|
|
||||||
|
arr = json.optJSONArray("events");
|
||||||
|
if (obj != null) {
|
||||||
|
EventList events = new EventList();
|
||||||
|
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||||
|
events.add(new Event(l));
|
||||||
|
}
|
||||||
|
this.events = events;
|
||||||
|
}
|
||||||
|
arr = json.optJSONArray("gradebook");
|
||||||
|
if (obj != null) {
|
||||||
|
ArrayList<Grade> grades = new ArrayList<>();
|
||||||
|
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||||
|
grades.add(new Grade(l));
|
||||||
|
}
|
||||||
|
this.gradebook = grades;
|
||||||
|
}
|
||||||
|
arr = json.optJSONArray("resources");
|
||||||
|
if (obj != null) {
|
||||||
|
ArrayList<Resource> res = new ArrayList<>();
|
||||||
|
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
|
||||||
|
if (l.getString("restype").equals("file"))
|
||||||
|
res.add(new Resource.File(l));
|
||||||
|
else
|
||||||
|
res.add(new Resource.Folder(l));
|
||||||
|
}
|
||||||
|
this.resources = res;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String getID() {
|
public String getID() {
|
||||||
return ID;
|
return ID;
|
||||||
@@ -210,10 +313,5 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
"\ntype: "+type+
|
"\ntype: "+type+
|
||||||
"\nID: "+ID;
|
"\nID: "+ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,17 +2,20 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.LayoutItemType;
|
import de.sebse.fuplanner.tools.ui.treeview.LayoutItemType;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
||||||
|
|
||||||
|
|
||||||
public abstract class Resource implements Serializable {
|
public abstract class Resource implements UtilsJson.JsonConvertible {
|
||||||
|
|
||||||
final String author;
|
final String author;
|
||||||
final long modifiedDate;
|
final long modifiedDate;
|
||||||
@@ -62,6 +65,19 @@ public abstract class Resource implements Serializable {
|
|||||||
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("author", author);
|
||||||
|
json.put("modifiedDate", modifiedDate);
|
||||||
|
json.put("title", title);
|
||||||
|
json.put("url", url);
|
||||||
|
json.put("visible", visible);
|
||||||
|
json.put("container", container);
|
||||||
|
json.put("restype", "");
|
||||||
|
return json;
|
||||||
|
}
|
||||||
|
|
||||||
public static class File extends Resource implements LayoutItemType {
|
public static class File extends Resource implements LayoutItemType {
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
@@ -91,6 +107,14 @@ public abstract class Resource implements Serializable {
|
|||||||
public @LayoutRes int getLayoutId() {
|
public @LayoutRes int getLayoutId() {
|
||||||
return R.layout.item_file;
|
return R.layout.item_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = super.toJSONObject();
|
||||||
|
json.put("type", type);
|
||||||
|
json.put("restype", "file");
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Folder extends Resource implements LayoutItemType {
|
public static class Folder extends Resource implements LayoutItemType {
|
||||||
@@ -138,6 +162,14 @@ public abstract class Resource implements Serializable {
|
|||||||
public @LayoutRes int getLayoutId() {
|
public @LayoutRes int getLayoutId() {
|
||||||
return R.layout.item_dir;
|
return R.layout.item_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = super.toJSONObject();
|
||||||
|
json.put("children", UtilsJson.collectionToJson(children));
|
||||||
|
json.put("restype", "dir");
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,13 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsJson;
|
||||||
|
|
||||||
public class Semester implements Serializable {
|
public class Semester implements UtilsJson.JsonConvertible {
|
||||||
public static final int SEM_WS = 1;
|
public static final int SEM_WS = 1;
|
||||||
public static final int SEM_SS = 2;
|
public static final int SEM_SS = 2;
|
||||||
private int type;
|
private int type;
|
||||||
@@ -17,25 +19,17 @@ public class Semester implements Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public Semester(String semester_string) throws NoSuchFieldException {
|
public Semester(String semester_string) throws NoSuchFieldException {
|
||||||
/*Semester sem = null;
|
|
||||||
if (semester != null) {
|
|
||||||
sem = new Semester(semester)
|
|
||||||
semester = semester.replace("SS", "S");
|
|
||||||
semester = semester.replaceAll("[0-9]{2}([0-9]{2})", "$1");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
|
|
||||||
/*String s1type = Regex.regex("^(S|WS) ", a);
|
|
||||||
int s1year = Integer.parseInt(Regex.regex("^(S|WS) ([0-9]{2})", a, 2));
|
|
||||||
String s2type = Regex.regex("^(S|WS) ", b);
|
|
||||||
int s2year = Integer.parseInt(Regex.regex("^(S|WS) ([0-9]{2})", b, 2));*/
|
|
||||||
|
|
||||||
String type = Regex.regex("^(SS|WS) ", semester_string);
|
String type = Regex.regex("^(SS|WS) ", semester_string);
|
||||||
String year = Regex.regex("^(SS|WS) ([0-9]{2})", semester_string, 2);
|
String year = Regex.regex("^(SS|WS) ([0-9]{2})", semester_string, 2);
|
||||||
this.type = type.equals("SS") ? SEM_SS : SEM_WS;
|
this.type = type.equals("SS") ? SEM_SS : SEM_WS;
|
||||||
this.year = Integer.parseInt(year);
|
this.year = Integer.parseInt(year);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Semester(JSONObject json) throws JSONException {
|
||||||
|
this.type = json.getInt("type");
|
||||||
|
this.year = json.getInt("year");
|
||||||
|
}
|
||||||
|
|
||||||
public int getType() {
|
public int getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@@ -52,4 +46,12 @@ public class Semester implements Serializable {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JSONObject toJSONObject() throws JSONException {
|
||||||
|
JSONObject json = new JSONObject();
|
||||||
|
json.put("type", type);
|
||||||
|
json.put("year", year);
|
||||||
|
return json;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,8 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.SortedList;
|
import de.sebse.fuplanner.tools.SortedList;
|
||||||
|
|
||||||
|
|||||||
@@ -122,13 +122,6 @@ public class CustomAccountManager {
|
|||||||
return mAccountManager.getAccountsByType(accountType).length != 0;
|
return mAccountManager.getAccountsByType(accountType).length != 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Account getAccountByType(String accountType) {
|
|
||||||
Account[] accountsByType = mAccountManager.getAccountsByType(accountType);
|
|
||||||
if (accountsByType.length > 0)
|
|
||||||
return accountsByType[0];
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
@FunctionalInterface
|
||||||
public interface ActivityInterface {
|
public interface ActivityInterface {
|
||||||
@Nullable
|
@Nullable
|
||||||
|
|||||||
@@ -1,57 +0,0 @@
|
|||||||
package de.sebse.fuplanner.tools;
|
|
||||||
|
|
||||||
import android.app.NotificationChannel;
|
|
||||||
import android.app.NotificationManager;
|
|
||||||
import android.app.PendingIntent;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Build;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import androidx.core.app.NotificationCompat;
|
|
||||||
import androidx.core.app.NotificationManagerCompat;
|
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
|
|
||||||
public class CustomNotificationManager {
|
|
||||||
private static final String CHANNEL_ID = "fuplanner-default";
|
|
||||||
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
|
|
||||||
|
|
||||||
public static void sendNotification(Context context, String textTitle, String textContent) {
|
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
|
||||||
|
|
||||||
|
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
|
|
||||||
.setSmallIcon(R.drawable.ic_notification)
|
|
||||||
.setContentTitle(textTitle)
|
|
||||||
.setContentText(textContent)
|
|
||||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
|
||||||
.setContentIntent(pendingIntent)
|
|
||||||
.setAutoCancel(true);
|
|
||||||
|
|
||||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
|
||||||
int notificationId = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
|
|
||||||
notificationManager.notify(notificationId, mBuilder.build());
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void createNotificationChannel(@NotNull Context context) {
|
|
||||||
// Create the NotificationChannel, but only on API 26+ because
|
|
||||||
// the NotificationChannel class is new and not in the support library
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
|
||||||
CharSequence name = context.getString(R.string.channel_name);
|
|
||||||
String description = context.getString(R.string.channel_description);
|
|
||||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
|
||||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
|
|
||||||
channel.setDescription(description);
|
|
||||||
// Register the channel with the system; you can't change the importance
|
|
||||||
// or other notification behaviors after this
|
|
||||||
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
|
|
||||||
if (notificationManager != null) {
|
|
||||||
notificationManager.createNotificationChannel(channel);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.sebse.fuplanner.tools;
|
package de.sebse.fuplanner.tools;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.ArrayRes;
|
import androidx.annotation.ArrayRes;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
@@ -21,14 +20,4 @@ public class Preferences {
|
|||||||
String string = context.getResources().getString(key);
|
String string = context.getResources().getString(key);
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply();
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean getBoolean(Context context, @StringRes int key) {
|
|
||||||
String string = context.getResources().getString(key);
|
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(string, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setBoolean(Context context, @StringRes int key, boolean value) {
|
|
||||||
String string = context.getResources().getString(key);
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(string, value).apply();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,12 +3,11 @@ package de.sebse.fuplanner.tools;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
public abstract class SortedList<T, I, F> implements Iterable<T>, Serializable {
|
public abstract class SortedList<T, I, F> implements Iterable<T> {
|
||||||
|
|
||||||
private final ArrayList<T> internalList = new ArrayList<>();
|
private final ArrayList<T> internalList = new ArrayList<>();
|
||||||
|
|
||||||
|
|||||||
109
app/src/main/java/de/sebse/fuplanner/tools/UtilsJson.java
Normal file
109
app/src/main/java/de/sebse/fuplanner/tools/UtilsJson.java
Normal file
@@ -0,0 +1,109 @@
|
|||||||
|
package de.sebse.fuplanner.tools;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collection;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
|
||||||
|
public class UtilsJson {
|
||||||
|
public static JSONArray collectionToJson(@Nullable HashSet<String> coll) {
|
||||||
|
if (coll == null)
|
||||||
|
return null;
|
||||||
|
JSONArray arr = new JSONArray();
|
||||||
|
for (String e: coll) {
|
||||||
|
arr.put(e);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <E extends JsonConvertible> JSONArray collectionToJson(@Nullable Collection<E> coll) throws JSONException {
|
||||||
|
if (coll == null)
|
||||||
|
return null;
|
||||||
|
JSONArray arr = new JSONArray();
|
||||||
|
for (E e: coll) {
|
||||||
|
arr.put(e.toJSONObject());
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JSONArray collectionToJson(@Nullable ArrayList<String> coll) throws JSONException {
|
||||||
|
if (coll == null)
|
||||||
|
return null;
|
||||||
|
JSONArray arr = new JSONArray();
|
||||||
|
for (String e: coll) {
|
||||||
|
arr.put(e);
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <A extends JsonConvertible> JSONArray collectionToJson(@Nullable SortedList<A, ?, ?> coll) throws JSONException {
|
||||||
|
if (coll == null)
|
||||||
|
return null;
|
||||||
|
JSONArray arr = new JSONArray();
|
||||||
|
for (A e: coll) {
|
||||||
|
arr.put(e.toJSONObject());
|
||||||
|
}
|
||||||
|
return arr;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static <T> Iterator<T> jsonArrayToIterator(JSONArray array, GetInterface<T> func) {
|
||||||
|
return new Iterator<T>() {
|
||||||
|
int size = array == null ? 0 : array.length();
|
||||||
|
int pos = 0;
|
||||||
|
@Override
|
||||||
|
public boolean hasNext() {
|
||||||
|
return pos < size;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public T next() {
|
||||||
|
try {
|
||||||
|
return func.get(array, pos++);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
private interface GetInterface<T> {
|
||||||
|
T get(JSONArray array, int index) throws JSONException;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonIterable<JSONObject> jsonArrayToIterableObject(JSONArray array) {
|
||||||
|
return new JsonIterable<>(array, JSONArray::getJSONObject);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static JsonIterable<String> jsonArrayToIterableString(JSONArray array) {
|
||||||
|
return new JsonIterable<>(array, JSONArray::getString);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class JsonIterable<T> implements Iterable<T> {
|
||||||
|
private JSONArray array;
|
||||||
|
private GetInterface<T> getInterface;
|
||||||
|
|
||||||
|
JsonIterable(JSONArray array, GetInterface<T> getInterface) {
|
||||||
|
this.array = array;
|
||||||
|
this.getInterface = getInterface;
|
||||||
|
}
|
||||||
|
@NonNull
|
||||||
|
@Override
|
||||||
|
public Iterator<T> iterator() {
|
||||||
|
return UtilsJson.jsonArrayToIterator(array, getInterface);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface JsonConvertible {
|
||||||
|
JSONObject toJSONObject() throws JSONException;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Binary file not shown.
|
Before Width: | Height: | Size: 427 B |
Binary file not shown.
|
Before Width: | Height: | Size: 320 B |
Binary file not shown.
|
Before Width: | Height: | Size: 472 B |
Binary file not shown.
|
Before Width: | Height: | Size: 879 B |
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 KiB |
@@ -7,11 +7,6 @@
|
|||||||
android:icon="@drawable/ic_local_dining"
|
android:icon="@drawable/ic_local_dining"
|
||||||
android:title="@string/canteen_plan"
|
android:title="@string/canteen_plan"
|
||||||
android:orderInCategory="200" />
|
android:orderInCategory="200" />
|
||||||
<item
|
|
||||||
android:id="@+id/nav_settings"
|
|
||||||
android:icon="@drawable/ic_settings"
|
|
||||||
android:title="@string/settings"
|
|
||||||
android:orderInCategory="300"/>
|
|
||||||
<item
|
<item
|
||||||
android:id="@+id/nav_news"
|
android:id="@+id/nav_news"
|
||||||
android:icon="@drawable/ic_chat_bubble_outline"
|
android:icon="@drawable/ic_chat_bubble_outline"
|
||||||
|
|||||||
@@ -92,23 +92,4 @@
|
|||||||
<string name="error_incorrect_password">Das Passwort ist nicht korrekt.</string>
|
<string name="error_incorrect_password">Das Passwort ist nicht korrekt.</string>
|
||||||
<string name="error_field_required">Pflichtfeld</string>
|
<string name="error_field_required">Pflichtfeld</string>
|
||||||
<string name="kvv_sync">KVV-Synchronisation</string>
|
<string name="kvv_sync">KVV-Synchronisation</string>
|
||||||
<string name="channel_name">Neue Daten verfügbar</string>
|
|
||||||
<string name="channel_description">Benachrichtigen, wenn neue Ankündigungen, Aufgaben, Noten oder Ressourcen verfügbar sind</string>
|
|
||||||
<string name="announcement_updated">Ankündigung aktualisiert: %1$s</string>
|
|
||||||
<string name="assignment_updated">Aufgabe aktualisiert: %1$s</string>
|
|
||||||
<string name="event_updated">Event aktualisiert: %1$s</string>
|
|
||||||
<string name="gradebook_updated">Noteneintrag aktualisiert: %1$s</string>
|
|
||||||
<string name="resource_updated">Ressource aktualisiert: %1$s</string>
|
|
||||||
<string name="announcement_added">Neue Ankündigung: %1$s</string>
|
|
||||||
<string name="assignment_added">Neue Aufgabe: %1$s</string>
|
|
||||||
<string name="event_added">Neues Event: %1$s</string>
|
|
||||||
<string name="gradebook_added">Neuer Noteneintrag: %1$s</string>
|
|
||||||
<string name="resource_added">Neue Ressource: %1$s</string>
|
|
||||||
<string name="announcement_removed">Ankündigung entfernt: %1$s</string>
|
|
||||||
<string name="assignment_removed">Aufgabe entfernt: %1$s</string>
|
|
||||||
<string name="event_removed">Event entfernt: %1$s</string>
|
|
||||||
<string name="gradebook_removed">Noteneintrag entfernt: %1$s</string>
|
|
||||||
<string name="resource_removed">Ressource entfernt: %1$s</string>
|
|
||||||
<string name="pref_external_server_title">Effizientes Aktualisieren</string>
|
|
||||||
<string name="pref_external_server_summary">Spart mobile Daten und Akku, verwendet jedoch externen Server zur Sychronisierung.</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -8,14 +8,4 @@
|
|||||||
<string name="pref_price_group_default" translatable="false">all</string>
|
<string name="pref_price_group_default" translatable="false">all</string>
|
||||||
|
|
||||||
<string name="pref_last_visited_news" translatable="false">pref_last_visited_news</string>
|
<string name="pref_last_visited_news" translatable="false">pref_last_visited_news</string>
|
||||||
|
|
||||||
<string name="pref_set_auto_sync_on_startup" translatable="false">pref_set_auto_sync_on_startup</string>
|
|
||||||
|
|
||||||
|
|
||||||
<string-array name="pref_external_server" translatable="false">
|
|
||||||
<item>@string/pref_external_server</item>
|
|
||||||
<item>@string/pref_external_server_default</item>
|
|
||||||
</string-array>
|
|
||||||
<string name="pref_external_server" translatable="false">pref_external_server</string>
|
|
||||||
<string name="pref_external_server_default" translatable="false">all</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
@@ -50,8 +50,6 @@
|
|||||||
<string name="pref_price_group_title">Canteen Price Group</string>
|
<string name="pref_price_group_title">Canteen Price Group</string>
|
||||||
<string name="pref_price_group_summary">Only show specific price category</string>
|
<string name="pref_price_group_summary">Only show specific price category</string>
|
||||||
<string name="pref_price_group_dialog">Price Group Selection</string>
|
<string name="pref_price_group_dialog">Price Group Selection</string>
|
||||||
<string name="pref_external_server_title">More efficient data sync</string>
|
|
||||||
<string name="pref_external_server_summary">Uses more battery and data efficient syncing and refreshing, but use an external server.</string>
|
|
||||||
<string name="meals">Meals</string>
|
<string name="meals">Meals</string>
|
||||||
<string name="special_meals">Special meals</string>
|
<string name="special_meals">Special meals</string>
|
||||||
<string name="side_dishes">Side Dishes</string>
|
<string name="side_dishes">Side Dishes</string>
|
||||||
@@ -102,21 +100,4 @@
|
|||||||
<string name="error_incorrect_password">This password is incorrect</string>
|
<string name="error_incorrect_password">This password is incorrect</string>
|
||||||
<string name="error_field_required">This field is required</string>
|
<string name="error_field_required">This field is required</string>
|
||||||
<string name="kvv_sync">KVV Synchronization</string>
|
<string name="kvv_sync">KVV Synchronization</string>
|
||||||
<string name="channel_name">New data available</string>
|
|
||||||
<string name="channel_description">Notify when new announcements, assignments, grades or resources are available</string>
|
|
||||||
<string name="announcement_updated">Announcement updated: %1$s</string>
|
|
||||||
<string name="announcement_added">New announcement: %1$s</string>
|
|
||||||
<string name="announcement_removed">Announcement removed: %1$s</string>
|
|
||||||
<string name="assignment_updated">Assignment updated: %1$s</string>
|
|
||||||
<string name="assignment_added">New assignment: %1$s</string>
|
|
||||||
<string name="assignment_removed">Assignment removed: %1$s</string>
|
|
||||||
<string name="event_updated">Event updated: %1$s</string>
|
|
||||||
<string name="event_added">New event: %1$s</string>
|
|
||||||
<string name="event_removed">Event removed: %1$s</string>
|
|
||||||
<string name="gradebook_updated">Gradebook entry updated: %1$s</string>
|
|
||||||
<string name="gradebook_added">New gradebook entry: %1$s</string>
|
|
||||||
<string name="gradebook_removed">Gradebook entry removed: %1$s</string>
|
|
||||||
<string name="resource_updated">Resource updated: %1$s</string>
|
|
||||||
<string name="resource_added">New resource: %1$s</string>
|
|
||||||
<string name="resource_removed">Resource removed: %1$s</string>
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -9,11 +9,6 @@
|
|||||||
android:entries="@array/pref_price_group_entries"
|
android:entries="@array/pref_price_group_entries"
|
||||||
android:entryValues="@array/pref_price_group_values"
|
android:entryValues="@array/pref_price_group_values"
|
||||||
android:dialogTitle="@string/pref_price_group_dialog" />
|
android:dialogTitle="@string/pref_price_group_dialog" />
|
||||||
<SwitchPreference
|
|
||||||
android:key="@string/pref_external_server"
|
|
||||||
android:defaultValue="@string/pref_external_server_default"
|
|
||||||
android:title="@string/pref_external_server_title"
|
|
||||||
android:summary="@string/pref_external_server_summary" />
|
|
||||||
<PreferenceScreen
|
<PreferenceScreen
|
||||||
android:title="@string/open_data_policy"
|
android:title="@string/open_data_policy"
|
||||||
android:summary="@string/open_data_policy_summary">
|
android:summary="@string/open_data_policy_summary">
|
||||||
|
|||||||
@@ -9,7 +9,8 @@ buildscript {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
dependencies {
|
dependencies {
|
||||||
classpath 'com.android.tools.build:gradle:3.3.0'
|
classpath 'com.android.tools.build:gradle:3.2.1'
|
||||||
|
classpath 'com.google.gms:google-services:4.0.0'
|
||||||
|
|
||||||
// NOTE: Do not place your application dependencies here; they belong
|
// NOTE: Do not place your application dependencies here; they belong
|
||||||
// in the individual module build.gradle files
|
// in the individual module build.gradle files
|
||||||
|
|||||||
4
gradle/wrapper/gradle-wrapper.properties
vendored
4
gradle/wrapper/gradle-wrapper.properties
vendored
@@ -1,6 +1,6 @@
|
|||||||
#Wed Jan 16 22:29:38 CET 2019
|
#Tue Oct 16 18:11:34 CEST 2018
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
distributionPath=wrapper/dists
|
||||||
zipStoreBase=GRADLE_USER_HOME
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
distributionUrl=https\://services.gradle.org/distributions/gradle-4.10.1-all.zip
|
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-all.zip
|
||||||
|
|||||||
Reference in New Issue
Block a user