Merge branch 'newkvv'
# Conflicts: # app/src/main/java/de/sebse/fuplanner/fragments/moddetails/ModDetailAnnounceFragment.java # app/src/main/java/de/sebse/fuplanner/fragments/moddetails/ModDetailAssignmentFragment.java # app/src/main/java/de/sebse/fuplanner/services/KVV/KVVModuleList.java
This commit is contained in:
@@ -32,7 +32,6 @@ dependencies {
|
|||||||
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-beta02', {
|
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-beta02', {
|
||||||
exclude group: 'com.android.support', module: 'support-annotations'
|
exclude group: 'com.android.support', module: 'support-annotations'
|
||||||
})
|
})
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.0'
|
|
||||||
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-alpha2'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
||||||
@@ -42,7 +41,7 @@ dependencies {
|
|||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation 'androidx.appcompat:appcompat:1.0.0'
|
implementation 'androidx.appcompat:appcompat:1.0.2'
|
||||||
implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
|
implementation 'org.jbundle.util.osgi.wrapped:org.jbundle.util.osgi.wrapped.org.apache.http.client:4.1.2'
|
||||||
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'org.jetbrains:annotations-java5:15.0'
|
implementation 'org.jetbrains:annotations-java5:15.0'
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import android.view.View;
|
|||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
import android.widget.Toast;
|
import android.widget.Toast;
|
||||||
|
|
||||||
|
import com.android.volley.NetworkResponse;
|
||||||
import com.google.android.material.navigation.NavigationView;
|
import com.google.android.material.navigation.NavigationView;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -33,18 +34,23 @@ import de.sebse.fuplanner.fragments.canteen.DaySwitcherFragment;
|
|||||||
import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
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.GoogleAuth.Credentials;
|
||||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.services.KVV.KVV;
|
||||||
|
import de.sebse.fuplanner.services.KVV.KVVListener;
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
|
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||||
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity
|
public class MainActivity extends AppCompatActivity
|
||||||
implements MainActivityListener,
|
implements MainActivityListener, KVVListener,
|
||||||
NavigationView.OnNavigationItemSelectedListener,
|
NavigationView.OnNavigationItemSelectedListener,
|
||||||
LoginFragment.OnLoginFragmentInteractionListener,
|
|
||||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||||
CanteensFragment.OnCanteensFragmentInteractionListener {
|
CanteensFragment.OnCanteensFragmentInteractionListener {
|
||||||
|
|
||||||
@@ -68,21 +74,20 @@ public class MainActivity extends AppCompatActivity
|
|||||||
private NavigationView mNavigationView;
|
private NavigationView mNavigationView;
|
||||||
|
|
||||||
private int fragmentPage = FRAGMENT_NONE;
|
private int fragmentPage = FRAGMENT_NONE;
|
||||||
private int currentPage = FRAGMENT_NONE;
|
|
||||||
private String fragmentData = "";
|
private String fragmentData = "";
|
||||||
private String currentData = "";
|
|
||||||
private CanteenBrowser mCanteenBrowser;
|
private CanteenBrowser mCanteenBrowser;
|
||||||
private boolean mOfflineMode = false;
|
|
||||||
private HashMap<String, RequestPermissionsResultListener> permissionListeners = new HashMap<>();
|
private HashMap<String, RequestPermissionsResultListener> permissionListeners = new HashMap<>();
|
||||||
|
private boolean mOfflineBanner;
|
||||||
|
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
int newFragmentPage = FRAGMENT_NONE;
|
int desiredPage = getDefaultFragmentAfterLogin();
|
||||||
String newFragmentData = "";
|
String desiredData = "";
|
||||||
if (savedInstanceState != null) {
|
if (savedInstanceState != null) {
|
||||||
newFragmentPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
desiredPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, desiredPage);
|
||||||
newFragmentData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, fragmentData);
|
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
setContentView(R.layout.activity_main);
|
||||||
@@ -99,15 +104,12 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mNavigationView.setNavigationItemSelectedListener(this);
|
mNavigationView.setNavigationItemSelectedListener(this);
|
||||||
mFragmentManager = getSupportFragmentManager();
|
mFragmentManager = getSupportFragmentManager();
|
||||||
|
|
||||||
LoginToken loginToken = getKVV().easyLogin();
|
if (!getKVV().account().restoreOnlineLogin()) {
|
||||||
if (loginToken == null) {
|
desiredPage = FRAGMENT_LOGIN;
|
||||||
checkAndDoLogin();
|
desiredData = "";
|
||||||
} else {
|
|
||||||
if (newFragmentPage != FRAGMENT_LOGIN && newFragmentPage != FRAGMENT_STARTUP && newFragmentPage != FRAGMENT_NONE)
|
|
||||||
toLoginState(loginToken, newFragmentPage, newFragmentData);
|
|
||||||
else
|
|
||||||
toLoginState(loginToken, getDefaultFragmentAfterLogin(), "");
|
|
||||||
}
|
}
|
||||||
|
updateNavigation();
|
||||||
|
changeFragment(desiredPage, desiredData);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -123,7 +125,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
@Override
|
@Override
|
||||||
public boolean onCreateOptionsMenu(Menu menu) {
|
public boolean onCreateOptionsMenu(Menu menu) {
|
||||||
// Inflate the menu; this adds items to the action bar if it is present.
|
// Inflate the menu; this adds items to the action bar if it is present.
|
||||||
if (currentPage == FRAGMENT_SCHEDULE) {
|
if (fragmentPage == FRAGMENT_SCHEDULE) {
|
||||||
getMenuInflater().inflate(R.menu.options_schedule, menu);
|
getMenuInflater().inflate(R.menu.options_schedule, menu);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
@@ -180,12 +182,12 @@ public class MainActivity extends AppCompatActivity
|
|||||||
startActivity(sendIntent);
|
startActivity(sendIntent);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_logout:
|
case R.id.nav_logout:
|
||||||
this.getKVV().logout();
|
getKVV().account().logout(true);
|
||||||
|
getKVV().modules().list().delete();
|
||||||
this.getGoogleAuth().getLoginState(credentials -> {
|
this.getGoogleAuth().getLoginState(credentials -> {
|
||||||
if (credentials != null) {
|
if (credentials != null) {
|
||||||
this.getGoogleAuth().deleteLoginState(credentials.getUsername(), credentials.getPassword());
|
this.getGoogleAuth().deleteLoginState(credentials.getUsername(), credentials.getPassword());
|
||||||
}
|
}
|
||||||
this.toLogoutState();
|
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@@ -210,14 +212,15 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
|
if (fragmentPage != FRAGMENT_STARTUP && fragmentPage != FRAGMENT_NONE && fragmentPage != FRAGMENT_LOGIN) {
|
||||||
Fragment fragment = mFragmentManager.findFragmentByTag(String.valueOf(fragmentPage));
|
Fragment fragment = mFragmentManager.findFragmentByTag(String.valueOf(fragmentPage));
|
||||||
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, fragmentData);
|
|
||||||
if (fragment instanceof ModDetailFragment) {
|
if (fragment instanceof ModDetailFragment) {
|
||||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, ((ModDetailFragment) fragment).getData());
|
savedInstanceState.putString(ARG_FRAGMENT_STATUS, ((ModDetailFragment) fragment).getData());
|
||||||
} else {
|
} else {
|
||||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, fragmentData);
|
savedInstanceState.putString(ARG_FRAGMENT_STATUS, fragmentData);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
super.onSaveInstanceState(savedInstanceState);
|
super.onSaveInstanceState(savedInstanceState);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -239,9 +242,17 @@ public class MainActivity extends AppCompatActivity
|
|||||||
return this.mGoogleAuth;
|
return this.mGoogleAuth;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*@Deprecated
|
||||||
|
public de.sebse.fuplanner.services.KVV.KVV getKVV() {
|
||||||
|
if (this.mKVV == null) {
|
||||||
|
this.mKVV = new de.sebse.fuplanner.services.KVV.KVV(this);
|
||||||
|
}
|
||||||
|
return this.mKVV;
|
||||||
|
}*/
|
||||||
|
|
||||||
public KVV getKVV() {
|
public KVV getKVV() {
|
||||||
if (this.mKVV == null) {
|
if (this.mKVV == null) {
|
||||||
this.mKVV = new KVV(this);
|
this.mKVV = new KVV(this, this);
|
||||||
}
|
}
|
||||||
return this.mKVV;
|
return this.mKVV;
|
||||||
}
|
}
|
||||||
@@ -254,59 +265,25 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private int getDefaultFragmentAfterLogin() {
|
private int getDefaultFragmentAfterLogin() {
|
||||||
return getDefaultFragmentAfterLogin(new String[1]);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getDefaultFragmentAfterLogin(String[] id) {
|
|
||||||
if (fragmentPage == FRAGMENT_NONE){
|
|
||||||
id[0] = "";
|
|
||||||
return FRAGMENT_MODULES;
|
return FRAGMENT_MODULES;
|
||||||
}
|
}
|
||||||
else {
|
|
||||||
id[0] = fragmentData;
|
|
||||||
return fragmentPage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toLogoutState() {
|
private void toLogoutState() {
|
||||||
setOfflineBanner(true);
|
setOfflineBanner(false);
|
||||||
setRefreshFailedBanner(false);
|
setRefreshFailedBanner(false);
|
||||||
|
updateNavigation();
|
||||||
changeFragment(FRAGMENT_LOGIN);
|
changeFragment(FRAGMENT_LOGIN);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toLoginState(LoginToken loginToken, int newFragment, String newData) {
|
private void toLoginState(String fullName, String email, int newFragment, boolean onlineMode) {
|
||||||
if (loginToken == null) {
|
setOfflineBanner(!onlineMode);
|
||||||
toLogoutState();
|
updateNavigation();
|
||||||
} else {
|
|
||||||
toLoginState(loginToken.getFullName(), loginToken.getEmail(), newFragment, newData, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void toLoginState(String fullName, String email, int newFragment, String newData, boolean onlineMode) {
|
|
||||||
setOfflineBanner(onlineMode);
|
|
||||||
changeFragment(newFragment, newData);
|
|
||||||
|
|
||||||
View header = mNavigationView.getHeaderView(0);
|
View header = mNavigationView.getHeaderView(0);
|
||||||
((TextView) header.findViewById(R.id.login_name)).setText(fullName);
|
((TextView) header.findViewById(R.id.login_name)).setText(fullName);
|
||||||
((TextView) header.findViewById(R.id.login_mail)).setText(email);
|
((TextView) header.findViewById(R.id.login_mail)).setText(email);
|
||||||
}
|
|
||||||
|
|
||||||
private void checkAndDoLogin() {
|
changeFragment(newFragment);
|
||||||
changeFragment(FRAGMENT_STARTUP);
|
|
||||||
getGoogleAuth().getLoginState(credentials -> {
|
|
||||||
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
|
||||||
toLogoutState();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String[] id = {""};
|
|
||||||
|
|
||||||
int fragment = getDefaultFragmentAfterLogin(id);
|
|
||||||
this.getKVV().login(credentials.getUsername(), credentials.getPassword(), success -> toLoginState(success, fragment , id[0]),
|
|
||||||
error -> {
|
|
||||||
log.e(error);
|
|
||||||
toLogoutState();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void changeFragment(int newFragment) {
|
private void changeFragment(int newFragment) {
|
||||||
@@ -355,56 +332,36 @@ public class MainActivity extends AppCompatActivity
|
|||||||
fragmentTransaction.commit();
|
fragmentTransaction.commit();
|
||||||
|
|
||||||
if (newFragment == FRAGMENT_STARTUP) {
|
if (newFragment == FRAGMENT_STARTUP) {
|
||||||
findViewById(R.id.app_bar_layout).setVisibility(View.GONE);
|
findViewById(R.id.app_bar_include).setVisibility(View.GONE);
|
||||||
} else {
|
} else {
|
||||||
findViewById(R.id.app_bar_layout).setVisibility(View.VISIBLE);
|
findViewById(R.id.app_bar_include).setVisibility(View.VISIBLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean isChangeLoginState =
|
|
||||||
(
|
|
||||||
(newFragment == FRAGMENT_STARTUP || newFragment == FRAGMENT_LOGIN) &&
|
|
||||||
(currentPage != FRAGMENT_STARTUP && currentPage != FRAGMENT_LOGIN)
|
|
||||||
) || (
|
|
||||||
(currentPage == FRAGMENT_STARTUP || currentPage == FRAGMENT_LOGIN || currentPage == FRAGMENT_NONE) &&
|
|
||||||
(newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_LOGIN && (getKVV().isLoggedIn() || mOfflineMode))
|
|
||||||
);
|
|
||||||
|
|
||||||
if (newFragment != FRAGMENT_STARTUP && newFragment != FRAGMENT_NONE && newFragment != FRAGMENT_LOGIN) {
|
|
||||||
this.fragmentPage = newFragment;
|
this.fragmentPage = newFragment;
|
||||||
this.fragmentData = newData;
|
this.fragmentData = newData;
|
||||||
}
|
|
||||||
this.currentPage = newFragment;
|
|
||||||
this.currentData = newData;
|
|
||||||
invalidateOptionsMenu();
|
invalidateOptionsMenu();
|
||||||
if (isChangeLoginState)
|
|
||||||
refreshNavigation();
|
|
||||||
else
|
|
||||||
setNavigationSelection(currentPage, currentData);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setOfflineBanner(boolean onlineMode) {
|
private void setOfflineBanner(boolean visible) {
|
||||||
View offline_header = findViewById(R.id.offline_msg);
|
View offline_header = findViewById(R.id.offline_msg);
|
||||||
if (onlineMode)
|
offline_header.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||||
offline_header.setVisibility(View.GONE);
|
mOfflineBanner = visible;
|
||||||
else
|
|
||||||
offline_header.setVisibility(View.VISIBLE);
|
|
||||||
mOfflineMode = !onlineMode;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setRefreshFailedBanner(boolean refreshFailed) {
|
private void setRefreshFailedBanner(boolean refreshFailed) {
|
||||||
View viewNoConnection = findViewById(R.id.no_connection_msg);
|
View viewNoConnection = findViewById(R.id.no_connection_msg);
|
||||||
if (!mOfflineMode && refreshFailed)
|
if (!mOfflineBanner && refreshFailed)
|
||||||
viewNoConnection.setVisibility(View.VISIBLE);
|
viewNoConnection.setVisibility(View.VISIBLE);
|
||||||
else
|
else
|
||||||
viewNoConnection.setVisibility(View.GONE);
|
viewNoConnection.setVisibility(View.GONE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setNavigationSelection(int fragment, String data) {
|
private void setNavigationSelection() {
|
||||||
MenuItem item;
|
MenuItem item;
|
||||||
switch (fragment) {
|
switch (fragmentPage) {
|
||||||
case FRAGMENT_MODULES_DETAILS:
|
case FRAGMENT_MODULES_DETAILS:
|
||||||
getKVV().getModule(data, success -> {
|
getKVV().modules().list().find(fragmentData, success -> {
|
||||||
int size = mNavigationView.getMenu().size();
|
int size = mNavigationView.getMenu().size();
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
String title = success == null ? null : success.title;
|
String title = success == null ? null : success.title;
|
||||||
@@ -426,7 +383,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
case FRAGMENT_CANTEENS_DETAILS:
|
case FRAGMENT_CANTEENS_DETAILS:
|
||||||
getCanteenBrowser().getCanteens(success -> {
|
getCanteenBrowser().getCanteens(success -> {
|
||||||
int size = mNavigationView.getMenu().size();
|
int size = mNavigationView.getMenu().size();
|
||||||
Canteen canteen = success.getCanteen(Integer.parseInt(data));
|
Canteen canteen = success.getCanteen(Integer.parseInt(fragmentData));
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
String title = canteen == null ? null : canteen.getName();
|
String title = canteen == null ? null : canteen.getName();
|
||||||
for (int k = 0; k < size; k++) {
|
for (int k = 0; k < size; k++) {
|
||||||
@@ -464,9 +421,11 @@ public class MainActivity extends AppCompatActivity
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void afterAnyMenuInflate(boolean isLoggedIn) {
|
private void afterAnyMenuInflate(boolean isLoggedIn, Runnable done) {
|
||||||
|
int MAX_COUNT = isLoggedIn ? 2 : 1;
|
||||||
|
final int[] count = {0};
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
getKVV().getModuleList(success -> {
|
getKVV().modules().list().recv(success -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Iterator<Modules.Module> it = success.latestSemesterIterator(); it.hasNext(); ) {
|
for (Iterator<Modules.Module> it = success.latestSemesterIterator(); it.hasNext(); ) {
|
||||||
Modules.Module module = it.next();
|
Modules.Module module = it.next();
|
||||||
@@ -477,7 +436,11 @@ public class MainActivity extends AppCompatActivity
|
|||||||
});
|
});
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}, log::e);
|
if (++count[0] == MAX_COUNT) done.run();
|
||||||
|
}, msg -> {
|
||||||
|
if (++count[0] == MAX_COUNT) done.run();
|
||||||
|
log.e(msg);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
getCanteenBrowser().getCanteens(success -> {
|
getCanteenBrowser().getCanteens(success -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
@@ -489,7 +452,27 @@ public class MainActivity extends AppCompatActivity
|
|||||||
});
|
});
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}, log::e);
|
if (++count[0] == MAX_COUNT) done.run();
|
||||||
|
}, msg -> {
|
||||||
|
if (++count[0] == MAX_COUNT) done.run();
|
||||||
|
log.e(msg);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updateNavigation() {
|
||||||
|
mQueue.add(() -> {
|
||||||
|
boolean isLoggedIn = getKVV().account().isLoggedIn();
|
||||||
|
setNavigationHeader(isLoggedIn);
|
||||||
|
mNavigationView.getMenu().clear();
|
||||||
|
if (isLoggedIn)
|
||||||
|
mNavigationView.inflateMenu(R.menu.activity_main_drawer_login);
|
||||||
|
else
|
||||||
|
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
||||||
|
afterAnyMenuInflate(isLoggedIn, () -> {
|
||||||
|
setNavigationSelection();
|
||||||
|
mQueue.next();
|
||||||
|
});
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -498,11 +481,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void onLoginFragmentInteraction(LoginToken loginToken, boolean onlineMode) {
|
|
||||||
String[] id = {""};
|
|
||||||
int fragment = getDefaultFragmentAfterLogin(id);
|
|
||||||
toLoginState(loginToken.getFullName(), loginToken.getEmail(), fragment, id[0], onlineMode);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onModulesFragmentInteraction(final String itemID) {
|
public void onModulesFragmentInteraction(final String itemID) {
|
||||||
@@ -524,21 +503,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
setTitle(titleId);
|
setTitle(titleId);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void loginTokenInvalid(boolean doLoginCheck) {
|
|
||||||
if (doLoginCheck) {
|
|
||||||
getKVV().testLogin(isSuccess -> {
|
|
||||||
if (!isSuccess) {
|
|
||||||
getKVV().invalidate();
|
|
||||||
checkAndDoLogin();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
getKVV().invalidate();
|
|
||||||
checkAndDoLogin();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onRefreshCompleted(boolean isFailed) {
|
public void onRefreshCompleted(boolean isFailed) {
|
||||||
setRefreshFailedBanner(isFailed);
|
setRefreshFailedBanner(isFailed);
|
||||||
@@ -564,16 +528,43 @@ public class MainActivity extends AppCompatActivity
|
|||||||
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
Toast.makeText(this, message, Toast.LENGTH_SHORT).show();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void refreshNavigation() {
|
public void getCredentials(NetworkCallback<Credentials> callback, NetworkErrorCallback error) {
|
||||||
boolean isLoggedIn = getKVV().isLoggedIn() || mOfflineMode;
|
getGoogleAuth().getLoginState(credentials -> {
|
||||||
setNavigationHeader(isLoggedIn);
|
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
||||||
mNavigationView.getMenu().clear();
|
error.onError(new NetworkError(200100, 403, "No Google Login available!"));
|
||||||
if (isLoggedIn)
|
} else {
|
||||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer_login);
|
callback.onResponse(credentials);
|
||||||
else
|
}
|
||||||
mNavigationView.inflateMenu(R.menu.activity_main_drawer);
|
});
|
||||||
afterAnyMenuInflate(isLoggedIn);
|
}
|
||||||
setNavigationSelection(currentPage, currentData);
|
|
||||||
|
@Override
|
||||||
|
public void onLogin(LoginToken token, boolean enteringOnlineMode) {
|
||||||
|
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin(), enteringOnlineMode);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLogout() {
|
||||||
|
toLogoutState();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onModuleListChange() {
|
||||||
|
updateNavigation();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onKVVNetworkResponse(NetworkResponse error) {
|
||||||
|
setRefreshFailedBanner(error != null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import de.sebse.fuplanner.R;
|
|||||||
import de.sebse.fuplanner.fragments.CanteensFragment.OnCanteensFragmentInteractionListener;
|
import de.sebse.fuplanner.fragments.CanteensFragment.OnCanteensFragmentInteractionListener;
|
||||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||||
import de.sebse.fuplanner.services.Canteen.types.Canteens;
|
import de.sebse.fuplanner.services.Canteen.types.Canteens;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -70,8 +70,8 @@ public class CanteensFragment extends Fragment {
|
|||||||
CanteenBrowser browser = ((MainActivity) getActivity()).getCanteenBrowser();
|
CanteenBrowser browser = ((MainActivity) getActivity()).getCanteenBrowser();
|
||||||
browser.getCanteens(success -> {
|
browser.getCanteens(success -> {
|
||||||
adapter.setCanteens(success);
|
adapter.setCanteens(success);
|
||||||
if (mMainActivityListener != null)
|
//if (mMainActivityListener != null)
|
||||||
mMainActivityListener.refreshNavigation();
|
// mMainActivityListener.refreshNavigation();
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
log.e(error.toString());
|
log.e(error.toString());
|
||||||
|
|||||||
@@ -9,31 +9,21 @@ import android.view.ViewGroup;
|
|||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.EditText;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* A simple {@link Fragment} subclass.
|
* A simple {@link Fragment} subclass.
|
||||||
* Activities that contain this fragment must implement the
|
|
||||||
* {@link LoginFragment.OnLoginFragmentInteractionListener} interface
|
|
||||||
* to handle interaction events.
|
|
||||||
* Use the {@link LoginFragment#newInstance} factory method to
|
* Use the {@link LoginFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
public class LoginFragment extends Fragment {
|
public class LoginFragment extends Fragment {
|
||||||
private OnLoginFragmentInteractionListener mListener;
|
|
||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private MainActivityListener mActivityListener;
|
@Nullable private MainActivityListener mActivityListener;
|
||||||
|
|
||||||
public LoginFragment() {
|
public LoginFragment() {
|
||||||
// Required empty public constructor
|
// Required empty public constructor
|
||||||
@@ -57,21 +47,11 @@ public class LoginFragment extends Fragment {
|
|||||||
Bundle savedInstanceState) {
|
Bundle savedInstanceState) {
|
||||||
// Inflate the layout for this fragment
|
// Inflate the layout for this fragment
|
||||||
View v = inflater.inflate(R.layout.fragment_login, container, false);
|
View v = inflater.inflate(R.layout.fragment_login, container, false);
|
||||||
try {
|
if (mActivityListener != null && mActivityListener.getKVV().account().isOfflineStoredAvailable()) {
|
||||||
Context context = getContext();
|
|
||||||
if (context != null) {
|
|
||||||
Modules modules = Modules.load(context);
|
|
||||||
if (modules != null) {
|
|
||||||
Button offline_btn = v.findViewById(R.id.btn_offline);
|
Button offline_btn = v.findViewById(R.id.btn_offline);
|
||||||
offline_btn.setVisibility(View.VISIBLE);
|
offline_btn.setVisibility(View.VISIBLE);
|
||||||
offline_btn.setText(v.getResources().getString(R.string.enter_offline_mode, modules.getToken().getUsername()));
|
offline_btn.setText(v.getResources().getString(R.string.enter_offline_mode, mActivityListener.getKVV().modules().list().getUsername()));
|
||||||
offline_btn.setOnClickListener(v1 -> mListener.onLoginFragmentInteraction(modules.getToken(), false));
|
offline_btn.setOnClickListener(v1 -> mActivityListener.getKVV().account().doOfflineLogin());
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
View btn_login = v.findViewById(R.id.btn_login);
|
View btn_login = v.findViewById(R.id.btn_login);
|
||||||
@@ -84,24 +64,15 @@ public class LoginFragment extends Fragment {
|
|||||||
|
|
||||||
EditText input_usr = ((View) view.getParent()).findViewById(R.id.input_username);
|
EditText input_usr = ((View) view.getParent()).findViewById(R.id.input_username);
|
||||||
EditText input_pwd = ((View) view.getParent()).findViewById(R.id.input_password);
|
EditText input_pwd = ((View) view.getParent()).findViewById(R.id.input_password);
|
||||||
if (input_usr != null) {
|
|
||||||
if (input_pwd != null) {
|
|
||||||
if (LoginFragment.this.getActivity() == null) {
|
|
||||||
log.e("Login fragment has no activity!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String username = input_usr.getText().toString();
|
String username = input_usr.getText().toString();
|
||||||
String password = input_pwd.getText().toString();
|
String password = input_pwd.getText().toString();
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
|
||||||
GoogleAuth gauth = ((MainActivity) getActivity()).getGoogleAuth();
|
mActivityListener.getKVV().account().doOnlineLogin(username, password, success -> {
|
||||||
kvv.login(username, password, success -> {
|
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
gauth.setLoginState(username, password);
|
mActivityListener.getGoogleAuth().setLoginState(username, password);
|
||||||
if (mListener != null) {
|
|
||||||
input_usr.setError(null);
|
input_usr.setError(null);
|
||||||
input_pwd.setError(null);
|
input_pwd.setError(null);
|
||||||
mListener.onLoginFragmentInteraction(success, true);
|
|
||||||
}
|
|
||||||
}, error -> {
|
}, error -> {
|
||||||
progressDialog.dismiss();
|
progressDialog.dismiss();
|
||||||
// Invalid password
|
// Invalid password
|
||||||
@@ -116,8 +87,6 @@ public class LoginFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
log.e("Error on KVV login!", error);
|
log.e("Error on KVV login!", error);
|
||||||
});
|
});
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return v;
|
return v;
|
||||||
@@ -128,12 +97,6 @@ public class LoginFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof OnLoginFragmentInteractionListener) {
|
|
||||||
mListener = (OnLoginFragmentInteractionListener) context;
|
|
||||||
} else {
|
|
||||||
throw new RuntimeException(context.toString()
|
|
||||||
+ " must implement OnLoginFragmentInteractionListener");
|
|
||||||
}
|
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
mActivityListener = (MainActivityListener) context;
|
mActivityListener = (MainActivityListener) context;
|
||||||
mActivityListener.onTitleTextChange(R.string.log_in);
|
mActivityListener.onTitleTextChange(R.string.log_in);
|
||||||
@@ -144,20 +107,6 @@ public class LoginFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
mListener = null;
|
mActivityListener = null;
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* This interface must be implemented by activities that contain this
|
|
||||||
* fragment to allow an interaction in this fragment to be communicated
|
|
||||||
* to the activity and potentially other fragments contained in that
|
|
||||||
* activity.
|
|
||||||
* <p>
|
|
||||||
* See the Android Training lesson <a href=
|
|
||||||
* "http://developer.android.com/training/basics/fragments/communicating.html"
|
|
||||||
* >Communicating with Other Fragments</a> for more information.
|
|
||||||
*/
|
|
||||||
public interface OnLoginFragmentInteractionListener {
|
|
||||||
void onLoginFragmentInteraction(LoginToken loginToken, boolean onlineMode);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,66 +1,115 @@
|
|||||||
package de.sebse.fuplanner.fragments;
|
package de.sebse.fuplanner.fragments;
|
||||||
|
|
||||||
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.fragments.ModulesFragment.OnModulesFragmentInteractionListener;
|
import de.sebse.fuplanner.fragments.ModulesFragment.OnModulesFragmentInteractionListener;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Semester;
|
||||||
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||||
|
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link RecyclerView.Adapter} that can display a {@link Modules.Module} and makes a call to the
|
* {@link RecyclerView.Adapter} that can display a {@link Modules.Module} and makes a call to the
|
||||||
* specified {@link OnModulesFragmentInteractionListener}.
|
* specified {@link OnModulesFragmentInteractionListener}.
|
||||||
*/
|
*/
|
||||||
class ModulesAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
class ModulesAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||||
|
|
||||||
|
private static final int TYPE_HEADER = 0;
|
||||||
|
private static final int TYPE_ITEM = 2;
|
||||||
|
|
||||||
private Modules mValues;
|
private Modules mValues;
|
||||||
private final OnModulesFragmentInteractionListener mListener;
|
private final OnModulesFragmentInteractionListener mListener;
|
||||||
|
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
||||||
|
|
||||||
ModulesAdapter(OnModulesFragmentInteractionListener listener) {
|
ModulesAdapter(OnModulesFragmentInteractionListener listener) {
|
||||||
mValues = null;
|
mValues = null;
|
||||||
mListener = listener;
|
mListener = listener;
|
||||||
|
mPositionalData = new ArrayList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setModules(Modules modules) {
|
public void setModules(Modules modules) {
|
||||||
mValues = modules;
|
mValues = modules;
|
||||||
|
mPositionalData.clear();
|
||||||
|
Semester lastSemester = null;
|
||||||
|
for (Modules.Module module : mValues) {
|
||||||
|
Semester semester = module.semester;
|
||||||
|
if (semester == null)
|
||||||
|
continue;
|
||||||
|
if (!semester.equals(lastSemester)) {
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_HEADER, semester));
|
||||||
|
lastSemester = semester;
|
||||||
|
}
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_ITEM, module));
|
||||||
|
}
|
||||||
this.notifyDataSetChanged();
|
this.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getItemViewType(int position) {
|
||||||
|
return mPositionalData.get(position).first;
|
||||||
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
|
if (viewType == TYPE_HEADER) {
|
||||||
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.list_all_caption, parent, false);
|
||||||
|
return new StringViewHolder(view);
|
||||||
|
} else {
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.list_all_items, parent, false);
|
.inflate(R.layout.list_all_items, parent, false);
|
||||||
return new ItemViewHolder(view);
|
return new ItemViewHolder(view);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull CustomViewHolder holder, int position) {
|
||||||
if (mValues == null)
|
Pair<Integer, Object> pair = mPositionalData.get(holder.getAdapterPosition());
|
||||||
return;
|
if (pair.first == TYPE_HEADER) {
|
||||||
Modules.Module module = mValues.getByIndex(holder.getAdapterPosition());
|
StringViewHolder sHolder = (StringViewHolder) holder;
|
||||||
holder.mTitle.setText(module.title);
|
String localizedSemester;
|
||||||
holder.mSubLeft.setText(module.semester);
|
Semester semester = (Semester) pair.second;
|
||||||
holder.mSubRight.setText(module.type);
|
if (semester.getType() == Semester.SEM_WS)
|
||||||
|
localizedSemester = holder.mView.getResources().getString(R.string.winter_semester, semester.getYear(), semester.getYear()+1);
|
||||||
|
else
|
||||||
|
localizedSemester = holder.mView.getResources().getString(R.string.summer_semester, semester.getYear());
|
||||||
|
sHolder.mString.setText(localizedSemester);
|
||||||
|
} else if (pair.first == TYPE_ITEM) {
|
||||||
|
ItemViewHolder iHolder = (ItemViewHolder) holder;
|
||||||
|
Modules.Module module = ((Modules.Module) pair.second);
|
||||||
|
iHolder.mTitle.setText(module.title);
|
||||||
|
StringBuilder lecturers = new StringBuilder();
|
||||||
|
for (Lecturer lecturer: module.lecturer) {
|
||||||
|
if (!lecturer.isResponsible())
|
||||||
|
continue;
|
||||||
|
if (lecturers.length() > 0)
|
||||||
|
lecturers.append(", ");
|
||||||
|
lecturers.append(lecturer.getNameShort());
|
||||||
|
}
|
||||||
|
iHolder.mSubLeft.setText(lecturers);
|
||||||
|
iHolder.mSubRight.setText(module.type);
|
||||||
|
|
||||||
holder.mView.setOnClickListener(v -> {
|
iHolder.mView.setOnClickListener(v -> {
|
||||||
if (null != mListener) {
|
if (mListener != null) {
|
||||||
// Notify the active callbacks interface (the activity, if the
|
|
||||||
// fragment is attached to one) that an item has been selected.
|
|
||||||
mListener.onModulesFragmentInteraction(module.getID());
|
mListener.onModulesFragmentInteraction(module.getID());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (mValues != null) {
|
return mPositionalData.size();
|
||||||
return mValues.size();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,13 +7,12 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
@@ -28,7 +27,7 @@ public class ModulesFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private ModulesAdapter adapter;
|
private ModulesAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private MainActivityListener mMainActivityListener;
|
@Nullable private MainActivityListener mMainActivityListener;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Mandatory empty constructor for the fragment manager to instantiate the
|
* Mandatory empty constructor for the fragment manager to instantiate the
|
||||||
@@ -66,12 +65,11 @@ public class ModulesFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mMainActivityListener != null) {
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
mMainActivityListener.getKVV().modules().list().recv(success -> {
|
||||||
kvv.getModuleList(success -> {
|
|
||||||
adapter.setModules(success);
|
adapter.setModules(success);
|
||||||
if (mMainActivityListener != null)
|
//if (mMainActivityListener != null)
|
||||||
mMainActivityListener.refreshNavigation();
|
// mMainActivityListener.refreshNavigation();
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
log.e(error.toString());
|
log.e(error.toString());
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ import java.util.List;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
@@ -59,13 +58,12 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void invalidate(boolean forceRefresh) {
|
public void invalidate(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener == null) return;
|
||||||
KVV kvv = mListener.getKVV();
|
mListener.getKVV().modules().list().recv(modules -> {
|
||||||
kvv.getModuleList((Modules success) -> {
|
mModules = modules;
|
||||||
mModules = success;
|
|
||||||
final int[] i = {0};
|
final int[] i = {0};
|
||||||
for (Modules.Module module: mModules) {
|
for (Modules.Module module: mModules) {
|
||||||
kvv.getModuleEvents(module, success1 -> {
|
mListener.getKVV().modules().events().recv(module, success1 -> {
|
||||||
i[0]++;
|
i[0]++;
|
||||||
if (i[0] >= mModules.size()) {
|
if (i[0] >= mModules.size()) {
|
||||||
if (mWeekView != null) {
|
if (mWeekView != null) {
|
||||||
@@ -77,7 +75,6 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
|||||||
}
|
}
|
||||||
}, log::e, forceRefresh);
|
}, log::e, forceRefresh);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
|
||||||
@@ -183,10 +180,8 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
|||||||
String moduleId = idParts[0];
|
String moduleId = idParts[0];
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
|
||||||
|
|
||||||
if (mListener != null) {
|
if (mListener == null) return;
|
||||||
KVV kvv = mListener.getKVV();
|
mListener.getKVV().modules().list().find(moduleId, module -> {
|
||||||
kvv.getModuleList((Modules success) -> {
|
|
||||||
Modules.Module module = success.get(moduleId);
|
|
||||||
String moduleName = module.title;
|
String moduleName = module.title;
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
.setTitle(event.getName())
|
.setTitle(event.getName())
|
||||||
@@ -202,5 +197,4 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
|||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
}, log::e);
|
}, log::e);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.Download;
|
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
@@ -76,12 +76,10 @@ class ModDetailAnnounceAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
tag.id = i;
|
tag.id = i;
|
||||||
tag.layoutColor = ContextCompat.getColor(holder.mView.getContext(), R.color.colorFUBlue);
|
tag.layoutColor = ContextCompat.getColor(holder.mView.getContext(), R.color.colorFUBlue);
|
||||||
holder.mTagGroup.addTag(tag);
|
holder.mTagGroup.addTag(tag);
|
||||||
log.d(notes.get(i));
|
|
||||||
}
|
}
|
||||||
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
||||||
String s = notes.get(i);
|
String s = notes.get(i);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
log.d("Download", s);
|
|
||||||
String name = urlToName(s, i, holder.mView.getResources());
|
String name = urlToName(s, i, holder.mView.getResources());
|
||||||
requestInterface.request(name, s);
|
requestInterface.request(name, s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ import android.os.Bundle;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ExpandableListView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
import de.sebse.fuplanner.MainActivity;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.Download;
|
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
@@ -33,7 +32,7 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
|||||||
private ModDetailAnnounceAdapter adapter;
|
private ModDetailAnnounceAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private Download download;
|
private Download download;
|
||||||
private MainActivityListener context;
|
@Nullable private MainActivityListener mListener;
|
||||||
|
|
||||||
|
|
||||||
public ModDetailAnnounceFragment() {
|
public ModDetailAnnounceFragment() {
|
||||||
@@ -83,41 +82,34 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mListener == null)
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
return;
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
mListener.getKVV().modules().announcements().recv(mItemPos, success -> {
|
||||||
adapter.setModule(module);
|
adapter.setModule(success);
|
||||||
kvv.getModuleAnnouncements(module, success1 -> {
|
|
||||||
adapter.setModule();
|
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
}, error -> {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
log.e(error);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void request(String title, String url) {
|
public void request(String title, String url) {
|
||||||
context.getKVV().getModule(mItemPos, (Modules.Module module) -> {
|
if (mListener == null)
|
||||||
if (module == null)
|
|
||||||
return;
|
return;
|
||||||
|
mListener.getKVV().modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||||
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
folderName += "/Assignment";
|
folderName += "/Assignment";
|
||||||
getDownload().openDownloadDialog(title, url, folderName);
|
getDownload().openDownloadDialog(title, url, folderName);
|
||||||
}, log::e, false);
|
}, log::e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.context = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
this.context.addRequestPermissionsResultListener(getDownload().getRequestPermissionsResultListener(), "ModDetailAnnounceFragment");
|
this.mListener.addRequestPermissionsResultListener(getDownload().getRequestPermissionsResultListener(), "ModDetailAnnounceFragment");
|
||||||
} else
|
} else
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
@@ -125,7 +117,10 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
|||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
this.context.removeRequestPermissionsResultListener("ModDetailAnnounceFragment");
|
if (this.mListener != null) {
|
||||||
|
this.mListener.removeRequestPermissionsResultListener("ModDetailAnnounceFragment");
|
||||||
|
this.mListener = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Download getDownload() {
|
Download getDownload() {
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ import androidx.annotation.Nullable;
|
|||||||
import androidx.core.content.ContextCompat;
|
import androidx.core.content.ContextCompat;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.Download;
|
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
@@ -76,12 +76,10 @@ class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder>
|
|||||||
tag.id = i;
|
tag.id = i;
|
||||||
tag.layoutColor = ContextCompat.getColor(holder.mView.getContext(), R.color.colorFUBlue);
|
tag.layoutColor = ContextCompat.getColor(holder.mView.getContext(), R.color.colorFUBlue);
|
||||||
holder.mTagGroup.addTag(tag);
|
holder.mTagGroup.addTag(tag);
|
||||||
log.d(notes.get(i));
|
|
||||||
}
|
}
|
||||||
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
||||||
String s = notes.get(i);
|
String s = notes.get(i);
|
||||||
if (s != null) {
|
if (s != null) {
|
||||||
log.d("Download", s);
|
|
||||||
String name = urlToName(s, i, holder.mView.getResources());
|
String name = urlToName(s, i, holder.mView.getResources());
|
||||||
requestInterface.request(name, s);
|
requestInterface.request(name, s);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,16 +6,15 @@ import android.os.Bundle;
|
|||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
import android.widget.ExpandableListView;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
import de.sebse.fuplanner.MainActivity;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.Download;
|
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
@@ -33,7 +32,7 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
|||||||
private ModDetailAssignmentAdapter adapter;
|
private ModDetailAssignmentAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private Download download;
|
private Download download;
|
||||||
private MainActivityListener context;
|
@Nullable private MainActivityListener mListener;
|
||||||
|
|
||||||
|
|
||||||
public ModDetailAssignmentFragment() {
|
public ModDetailAssignmentFragment() {
|
||||||
@@ -83,41 +82,35 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mListener == null)
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
return;
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
mListener.getKVV().modules().assignments().recv(mItemPos, success -> {
|
||||||
adapter.setModule(module);
|
adapter.setModule(success);
|
||||||
kvv.getModuleAssignments(module, success1 -> {
|
|
||||||
adapter.setModule();
|
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
}, error -> {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
log.e(error);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void request(String title, String url) {
|
public void request(String title, String url) {
|
||||||
context.getKVV().getModule(mItemPos, (Modules.Module module) -> {
|
log.d(title, url, mListener);
|
||||||
if (module == null)
|
if (mListener == null)
|
||||||
return;
|
return;
|
||||||
|
mListener.getKVV().modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||||
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
folderName += "/Assignment";
|
folderName += "/Assignment";
|
||||||
getDownload().openDownloadDialog(title, url, folderName);
|
getDownload().openDownloadDialog(title, url, folderName);
|
||||||
}, log::e, false);
|
}, log::e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.context = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
this.context.addRequestPermissionsResultListener(getDownload().getRequestPermissionsResultListener(), "ModDetailAssignmentFragment");
|
this.mListener.addRequestPermissionsResultListener(getDownload().getRequestPermissionsResultListener(), "ModDetailAssignmentFragment");
|
||||||
} else
|
} else
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
@@ -125,7 +118,10 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
|||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
this.context.removeRequestPermissionsResultListener("ModDetailAssignmentFragment");
|
if (this.mListener != null) {
|
||||||
|
this.mListener.removeRequestPermissionsResultListener("ModDetailAssignmentFragment");
|
||||||
|
this.mListener = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Download getDownload() {
|
Download getDownload() {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.util.Pair;
|
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
@@ -11,7 +10,6 @@ import java.util.LinkedHashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||||
@@ -19,12 +17,9 @@ import de.sebse.fuplanner.services.KVV.types.EventList;
|
|||||||
import de.sebse.fuplanner.services.KVV.types.GroupedEvents;
|
import de.sebse.fuplanner.services.KVV.types.GroupedEvents;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.Triplet;
|
import de.sebse.fuplanner.tools.Triplet;
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
|
||||||
import de.sebse.fuplanner.tools.ui.ListViewHolder;
|
import de.sebse.fuplanner.tools.ui.ListViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
|
||||||
|
|
||||||
class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||||
private static final String VALUE_LECTURE = "Class section - Lecture";
|
private static final String VALUE_LECTURE = "Class section - Lecture";
|
||||||
|
|||||||
@@ -13,11 +13,8 @@ import de.sebse.fuplanner.R;
|
|||||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||||
import de.sebse.fuplanner.services.KVV.types.EventList;
|
import de.sebse.fuplanner.services.KVV.types.EventList;
|
||||||
import de.sebse.fuplanner.services.KVV.types.GroupedEvents;
|
import de.sebse.fuplanner.services.KVV.types.GroupedEvents;
|
||||||
import de.sebse.fuplanner.tools.Triplet;
|
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
|
||||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.ListViewHolder;
|
|
||||||
|
|
||||||
class ModDetailEventAdapterInner extends RecyclerView.Adapter<ItemViewHolder> {
|
class ModDetailEventAdapterInner extends RecyclerView.Adapter<ItemViewHolder> {
|
||||||
private final ArrayList<Entry> mPositionalData;
|
private final ArrayList<Entry> mPositionalData;
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +29,7 @@ public class ModDetailEventFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private ModDetailEventAdapter adapter;
|
private ModDetailEventAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
|
@Nullable private MainActivityListener mListener;
|
||||||
|
|
||||||
|
|
||||||
public ModDetailEventFragment() {
|
public ModDetailEventFragment() {
|
||||||
@@ -81,22 +81,31 @@ public class ModDetailEventFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mListener == null)
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
return;
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
mListener.getKVV().modules().events().recv(mItemPos, success -> {
|
||||||
adapter.setModule(module);
|
adapter.setModule(success);
|
||||||
kvv.getModuleEvents(module, success1 -> {
|
|
||||||
adapter.setModule();
|
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
}, error -> {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
log.e(error);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
if (context instanceof MainActivityListener) {
|
||||||
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
} else
|
||||||
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
if (this.mListener != null) {
|
||||||
|
this.mListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -72,7 +72,7 @@ public class ModDetailFragment extends Fragment implements ModDetailListener {
|
|||||||
}
|
}
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.onTitleTextChange(R.string.courses);
|
mListener.onTitleTextChange(R.string.courses);
|
||||||
mListener.getKVV().getModuleList(success -> {
|
mListener.getKVV().modules().list().recv(success -> {
|
||||||
Modules.Module module = success.get(mItemPos);
|
Modules.Module module = success.get(mItemPos);
|
||||||
if (mListener != null && module != null)
|
if (mListener != null && module != null)
|
||||||
mListener.onTitleTextChange(module.title);
|
mListener.onTitleTextChange(module.title);
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ import java.util.ArrayList;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Gradebook;
|
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.tools.ui.StringViewHolder;
|
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||||
|
|
||||||
@@ -62,7 +62,7 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
case TYPE_GRADE:
|
case TYPE_GRADE:
|
||||||
view = LayoutInflater.from(parent.getContext())
|
view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.list_moddetails_gradebook, parent, false);
|
.inflate(R.layout.list_moddetails_gradebook, parent, false);
|
||||||
return new GradebookViewHolder(view);
|
return new GradeViewHolder(view);
|
||||||
default:
|
default:
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return null;
|
return null;
|
||||||
@@ -90,8 +90,8 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
break;
|
break;
|
||||||
case TYPE_GRADE:
|
case TYPE_GRADE:
|
||||||
int index = data.second / 1024;
|
int index = data.second / 1024;
|
||||||
GradebookViewHolder i = (GradebookViewHolder) holder;
|
GradeViewHolder i = (GradeViewHolder) holder;
|
||||||
Gradebook gradebook = mValue.gradebook.get(index);
|
Grade gradebook = mValue.gradebook.get(index);
|
||||||
|
|
||||||
i.mTitle.setText(gradebook.getItemName());
|
i.mTitle.setText(gradebook.getItemName());
|
||||||
i.mGrade.setText(String.valueOf(gradebook.getPoints()));
|
i.mGrade.setText(String.valueOf(gradebook.getPoints()));
|
||||||
@@ -119,12 +119,12 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
private class GradebookViewHolder extends RecyclerView.ViewHolder {
|
private class GradeViewHolder extends RecyclerView.ViewHolder {
|
||||||
private final TextView mGrade;
|
private final TextView mGrade;
|
||||||
private final TextView mGradeMax;
|
private final TextView mGradeMax;
|
||||||
private final TextView mTitle;
|
private final TextView mTitle;
|
||||||
|
|
||||||
GradebookViewHolder(View view) {
|
GradeViewHolder(View view) {
|
||||||
super(view);
|
super(view);
|
||||||
mTitle = view.findViewById(R.id.title);
|
mTitle = view.findViewById(R.id.title);
|
||||||
mGrade = view.findViewById(R.id.grade);
|
mGrade = view.findViewById(R.id.grade);
|
||||||
|
|||||||
@@ -8,14 +8,13 @@ import android.view.View;
|
|||||||
import android.view.ViewGroup;
|
import android.view.ViewGroup;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -30,6 +29,7 @@ public class ModDetailGradebookFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private ModDetailGradebookAdapter adapter;
|
private ModDetailGradebookAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
|
@Nullable private MainActivityListener mListener;
|
||||||
|
|
||||||
|
|
||||||
public ModDetailGradebookFragment() {
|
public ModDetailGradebookFragment() {
|
||||||
@@ -81,22 +81,31 @@ public class ModDetailGradebookFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mListener == null)
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
return;
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
mListener.getKVV().modules().gradebook().recv(mItemPos, success -> {
|
||||||
adapter.setModule(module);
|
adapter.setModule(success);
|
||||||
kvv.getModuleGradebook(module, success1 -> {
|
|
||||||
adapter.setModule();
|
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
}, error -> {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
log.e(error);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
if (context instanceof MainActivityListener) {
|
||||||
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
} else
|
||||||
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
if (this.mListener != null) {
|
||||||
|
this.mListener = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
|
import android.content.Intent;
|
||||||
|
import android.net.Uri;
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -16,11 +18,13 @@ import de.sebse.fuplanner.R;
|
|||||||
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||||
|
import de.sebse.fuplanner.tools.ui.MailViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||||
|
|
||||||
class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
@@ -30,6 +34,7 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
private static final int TYPE_DESCRIPTION = 1;
|
private static final int TYPE_DESCRIPTION = 1;
|
||||||
private static final int TYPE_ITEM = 2;
|
private static final int TYPE_ITEM = 2;
|
||||||
private static final int TYPE_SHOW_MORE = 3;
|
private static final int TYPE_SHOW_MORE = 3;
|
||||||
|
private static final int TYPE_MAIL = 4;
|
||||||
|
|
||||||
@Nullable private final ModDetailListener mListener;
|
@Nullable private final ModDetailListener mListener;
|
||||||
|
|
||||||
@@ -52,6 +57,10 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
mPositionalData.clear();
|
mPositionalData.clear();
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.DESCRIPTION));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.DESCRIPTION));
|
||||||
mPositionalData.add(new Pair<>(TYPE_DESCRIPTION, null));
|
mPositionalData.add(new Pair<>(TYPE_DESCRIPTION, null));
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.LECTURERS));
|
||||||
|
for (int i = 0; i < mValue.lecturer.size(); i++) {
|
||||||
|
mPositionalData.add(new Pair<>(TYPE_MAIL, ModulePart.LECTURERS+1024*i));
|
||||||
|
}
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.ANNOUNCEMENT));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.ANNOUNCEMENT));
|
||||||
addPositionalListData(getAnnounceCount(), ModulePart.ANNOUNCEMENT);
|
addPositionalListData(getAnnounceCount(), ModulePart.ANNOUNCEMENT);
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.ASSIGNMENT));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.ASSIGNMENT));
|
||||||
@@ -90,6 +99,10 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
view = LayoutInflater.from(parent.getContext())
|
view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.list_all_show_more, parent, false);
|
.inflate(R.layout.list_all_show_more, parent, false);
|
||||||
return new CustomViewHolder(view);
|
return new CustomViewHolder(view);
|
||||||
|
case TYPE_MAIL:
|
||||||
|
view = LayoutInflater.from(parent.getContext())
|
||||||
|
.inflate(R.layout.list_all_mails, parent, false);
|
||||||
|
return new MailViewHolder(view);
|
||||||
default:
|
default:
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return null;
|
return null;
|
||||||
@@ -116,6 +129,9 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
case ModulePart.DESCRIPTION:
|
case ModulePart.DESCRIPTION:
|
||||||
h.mString.setText(R.string.description);
|
h.mString.setText(R.string.description);
|
||||||
break;
|
break;
|
||||||
|
case ModulePart.LECTURERS:
|
||||||
|
h.mString.setText(h.mView.getResources().getString(R.string.lecturers));
|
||||||
|
break;
|
||||||
case ModulePart.ANNOUNCEMENT:
|
case ModulePart.ANNOUNCEMENT:
|
||||||
h.mString.setText(h.mView.getResources().getString(R.string.announcements_count, getAnnounceCount()));
|
h.mString.setText(h.mView.getResources().getString(R.string.announcements_count, getAnnounceCount()));
|
||||||
break;
|
break;
|
||||||
@@ -182,6 +198,26 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case TYPE_MAIL:
|
||||||
|
section = ((Integer) data.second) % 1024;
|
||||||
|
index = ((Integer) data.second) / 1024;
|
||||||
|
MailViewHolder m = (MailViewHolder) holder;
|
||||||
|
switch (section) {
|
||||||
|
case ModulePart.LECTURERS:
|
||||||
|
Lecturer lecturer = mValue.lecturer.get(index);
|
||||||
|
m.mTitle.setText(lecturer.getName());
|
||||||
|
m.mSubLeft.setText(lecturer.getMail());
|
||||||
|
m.mIcon.setOnClickListener(view -> {
|
||||||
|
String defaultText = m.mView.getResources().getString(R.string.mail_default_text,
|
||||||
|
lecturer.getName());
|
||||||
|
Intent emailIntent = new Intent(Intent.ACTION_SENDTO);
|
||||||
|
emailIntent.setData(Uri.parse("mailto:"+lecturer.getMail()));
|
||||||
|
emailIntent.putExtra(Intent.EXTRA_SUBJECT, mValue.title);
|
||||||
|
emailIntent.putExtra(Intent.EXTRA_TEXT, defaultText);
|
||||||
|
m.mView.getContext().startActivity(Intent.createChooser(emailIntent, mValue.title));
|
||||||
|
});
|
||||||
|
break;
|
||||||
|
}
|
||||||
case TYPE_SHOW_MORE:
|
case TYPE_SHOW_MORE:
|
||||||
CustomViewHolder c = (CustomViewHolder) holder;
|
CustomViewHolder c = (CustomViewHolder) holder;
|
||||||
c.mView.setOnClickListener(view -> {
|
c.mView.setOnClickListener(view -> {
|
||||||
@@ -231,6 +267,7 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
mText = view.findViewById(R.id.expand_text_view);//.findViewById(R.id.description);
|
mText = view.findViewById(R.id.expand_text_view);//.findViewById(R.id.description);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return super.toString() + " '" + mText.getText() + "'";
|
return super.toString() + " '" + mText.getText() + "'";
|
||||||
|
|||||||
@@ -13,10 +13,8 @@ import androidx.fragment.app.Fragment;
|
|||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -31,7 +29,8 @@ public class ModDetailOverviewFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private ModDetailOverviewAdapter adapter;
|
private ModDetailOverviewAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
@Nullable private ModDetailListener mListener;
|
@Nullable private ModDetailListener mDetailListener;
|
||||||
|
@Nullable private MainActivityListener mListener;
|
||||||
|
|
||||||
|
|
||||||
public ModDetailOverviewFragment() {
|
public ModDetailOverviewFragment() {
|
||||||
@@ -70,7 +69,7 @@ public class ModDetailOverviewFragment extends Fragment {
|
|||||||
Context context = view.getContext();
|
Context context = view.getContext();
|
||||||
RecyclerView recyclerView = view.findViewById(R.id.list);
|
RecyclerView recyclerView = view.findViewById(R.id.list);
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||||
adapter = new ModDetailOverviewAdapter(mListener);
|
adapter = new ModDetailOverviewAdapter(mDetailListener);
|
||||||
recyclerView.setAdapter(adapter);
|
recyclerView.setAdapter(adapter);
|
||||||
|
|
||||||
// Getting SwipeContainerLayout
|
// Getting SwipeContainerLayout
|
||||||
@@ -82,37 +81,45 @@ public class ModDetailOverviewFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mListener != null) {
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
adapter.setModule(pair.first);
|
||||||
adapter.setModule(module);
|
|
||||||
kvv.getModuleDetails(module, pair -> {
|
|
||||||
adapter.setModule();
|
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
}, error -> {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
log.e(error);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
|
super.onAttach(context);
|
||||||
|
if (context instanceof MainActivityListener) {
|
||||||
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
} else
|
||||||
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
|
|
||||||
|
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
Fragment parentFragment = getParentFragment();
|
Fragment parentFragment = getParentFragment();
|
||||||
if (parentFragment != null) {
|
if (parentFragment != null) {
|
||||||
if (parentFragment instanceof ModDetailListener) {
|
if (parentFragment instanceof ModDetailListener) {
|
||||||
mListener = (ModDetailListener) parentFragment;
|
mDetailListener = (ModDetailListener) parentFragment;
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString() + " must implement ModDetailListener");
|
||||||
+ " must implement ModDetailListener");
|
|
||||||
}
|
}
|
||||||
} else log.w("No parent fragment!");
|
} else log.w("No parent fragment!");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onDetach() {
|
||||||
|
super.onDetach();
|
||||||
|
this.mListener = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,14 @@ import android.widget.ImageView;
|
|||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||||
import de.sebse.fuplanner.MainActivity;
|
import de.sebse.fuplanner.MainActivity;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.KVV.Download;
|
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||||
import de.sebse.fuplanner.services.KVV.KVV;
|
|
||||||
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.services.KVV.types.Resource;
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
@@ -40,8 +40,8 @@ public class ModDetailResourceFragment extends Fragment {
|
|||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private ModDetailResourceAdapter adapter;
|
private ModDetailResourceAdapter adapter;
|
||||||
private SwipeRefreshLayout swipeLayout;
|
private SwipeRefreshLayout swipeLayout;
|
||||||
private MainActivityListener context;
|
|
||||||
private Download download;
|
private Download download;
|
||||||
|
@Nullable private MainActivityListener mListener;
|
||||||
|
|
||||||
|
|
||||||
public ModDetailResourceFragment() {
|
public ModDetailResourceFragment() {
|
||||||
@@ -88,10 +88,8 @@ public class ModDetailResourceFragment extends Fragment {
|
|||||||
if (!node.isLeaf()) {
|
if (!node.isLeaf()) {
|
||||||
// Update and toggle the node.
|
// Update and toggle the node.
|
||||||
onToggle(!node.isExpand(), holder);
|
onToggle(!node.isExpand(), holder);
|
||||||
} else if(node.getContent() instanceof Resource.File) { // if leaf is file
|
} else if (node.getContent() instanceof Resource.File && ModDetailResourceFragment.this.mListener != null) { // if leaf is file
|
||||||
KVV kvv = ModDetailResourceFragment.this.context.getKVV();
|
ModDetailResourceFragment.this.mListener.getKVV().modules().resources().recv(mItemPos, (Modules.Module module) -> {
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
|
||||||
|
|
||||||
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
Resource.File file = (Resource.File) node.getContent();
|
Resource.File file = (Resource.File) node.getContent();
|
||||||
getDownload().openDownloadDialog(file, folderName);
|
getDownload().openDownloadDialog(file, folderName);
|
||||||
@@ -120,14 +118,12 @@ public class ModDetailResourceFragment extends Fragment {
|
|||||||
return view;
|
return view;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.context = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
this.context.addRequestPermissionsResultListener(getDownload().getRequestPermissionsResultListener(), "ModDetailResourceFragment");
|
this.mListener.addRequestPermissionsResultListener(getDownload().getRequestPermissionsResultListener(), "ModDetailResourceFragment");
|
||||||
} else
|
} else
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||||
}
|
}
|
||||||
@@ -135,26 +131,22 @@ public class ModDetailResourceFragment extends Fragment {
|
|||||||
@Override
|
@Override
|
||||||
public void onDetach() {
|
public void onDetach() {
|
||||||
super.onDetach();
|
super.onDetach();
|
||||||
this.context.removeRequestPermissionsResultListener("ModDetailResourceFragment");
|
if (this.mListener != null) {
|
||||||
|
this.mListener.removeRequestPermissionsResultListener("ModDetailResourceFragment");
|
||||||
|
this.mListener = null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (getActivity() != null) {
|
if (mListener == null)
|
||||||
KVV kvv = ((MainActivity) getActivity()).getKVV();
|
return;
|
||||||
kvv.getModule(mItemPos, (Modules.Module module) -> {
|
mListener.getKVV().modules().assignments().recv(mItemPos, success -> {
|
||||||
adapter.setModule(module);
|
adapter.setModule(success);
|
||||||
kvv.getModuleResources(module, success1 -> {
|
|
||||||
adapter.setModule();
|
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
}, error -> {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
log.e(error);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Download getDownload() {
|
Download getDownload() {
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ class ModulePart {
|
|||||||
static final int EVENT = 4;
|
static final int EVENT = 4;
|
||||||
static final int GRADEBOOK = 5;
|
static final int GRADEBOOK = 5;
|
||||||
static final int RESOURCES = 6;
|
static final int RESOURCES = 6;
|
||||||
|
static final int LECTURERS = 7;
|
||||||
private static final int[] pages = new int[]{OVERVIEW, ANNOUNCEMENT, ASSIGNMENT, GRADEBOOK, RESOURCES, EVENT};
|
private static final int[] pages = new int[]{OVERVIEW, ANNOUNCEMENT, ASSIGNMENT, GRADEBOOK, RESOURCES, EVENT};
|
||||||
|
|
||||||
static int getPageCount() {
|
static int getPageCount() {
|
||||||
|
|||||||
@@ -29,6 +29,7 @@ public class GoogleAuth {
|
|||||||
|
|
||||||
private static final String TAG = "GoogleAuth";
|
private static final String TAG = "GoogleAuth";
|
||||||
private final FragmentActivity activity;
|
private final FragmentActivity activity;
|
||||||
|
private static final String FU_PLANNER_PROVIDER = "FUPlanner";
|
||||||
private CredentialsClient mCredentialsClient;
|
private CredentialsClient mCredentialsClient;
|
||||||
private boolean mIsResolving;
|
private boolean mIsResolving;
|
||||||
@Nullable
|
@Nullable
|
||||||
@@ -61,6 +62,7 @@ public class GoogleAuth {
|
|||||||
connect();
|
connect();
|
||||||
CredentialRequest request = new CredentialRequest.Builder()
|
CredentialRequest request = new CredentialRequest.Builder()
|
||||||
.setPasswordLoginSupported(true)
|
.setPasswordLoginSupported(true)
|
||||||
|
.setAccountTypes(FU_PLANNER_PROVIDER)
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,219 +1,47 @@
|
|||||||
package de.sebse.fuplanner.services.KVV;
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 29.10.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class KVV {
|
public class KVV {
|
||||||
private final Context context;
|
|
||||||
private LoginToken lastToken;
|
|
||||||
private boolean isLoginPending = true;
|
|
||||||
private final ArrayList<LastTokenCallback> updatingList;
|
|
||||||
private final HashMap<String, Object> addons = new HashMap<>();
|
private final HashMap<String, Object> addons = new HashMap<>();
|
||||||
private final MainActivityListener mListener;
|
private final KVVListener mListener;
|
||||||
private Logger log = new Logger(this);
|
private final Context mContext;
|
||||||
|
|
||||||
public KVV(Context context) {
|
public KVV(KVVListener listener, Context context) {
|
||||||
mListener = (MainActivityListener) context;
|
this.mListener = listener;
|
||||||
this.context = context;
|
this.mContext = context;
|
||||||
this.updatingList = new ArrayList<>();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoggedIn() {
|
@NotNull
|
||||||
return this.lastToken != null;
|
public Login account() {
|
||||||
|
return (Login) addAndGet("account", () -> new Login(mListener, mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginToken easyLogin() {
|
@NotNull
|
||||||
KVVLogin login = new KVVLogin(this.context);
|
public Modules modules() {
|
||||||
lastToken = login.easyLogin();
|
return (Modules) addAndGet("module", () -> new Modules(account(), mListener, mContext));
|
||||||
this.endUpdate();
|
|
||||||
return lastToken;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void login(@NonNull String username, @NonNull String password, final NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
|
||||||
KVVLogin login = new KVVLogin(this.context);
|
|
||||||
login.login(username, password, success -> {
|
|
||||||
lastToken = success;
|
|
||||||
this.endUpdate();
|
|
||||||
try {
|
|
||||||
login.saveOffline();
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
callback.onResponse(success);
|
|
||||||
}, error1 -> {
|
|
||||||
this.endUpdate();
|
|
||||||
error.onError(error1);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public void logout() {
|
|
||||||
KVVModuleList modules = (KVVModuleList) addons.get("modules");
|
|
||||||
if (modules != null) {
|
|
||||||
modules.deleteModulesOffline(this.context);
|
|
||||||
}
|
|
||||||
invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void invalidate() {
|
|
||||||
if (lastToken != null) {
|
|
||||||
new KVVLogin(context).deleteOffline();
|
|
||||||
lastToken = null;
|
|
||||||
}
|
|
||||||
addons.clear();
|
|
||||||
this.isLoginPending = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModule(String id, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
|
||||||
getModule(id, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModule(String id, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getModule(id, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleList(final NetworkCallback<Modules> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleList(callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleList(final NetworkCallback<Modules> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getModuleList(saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleDetails(Modules.Module module, final NetworkCallback<Pair<Modules.Module, Boolean>> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleDetails(module, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleDetails(Modules.Module module, final NetworkCallback<Pair<Modules.Module, Boolean>> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getModuleDetails(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleAnnouncements(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleAnnouncements(module, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleAnnouncements(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getAnnouncements(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleAssignments(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleAssignments(module, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleAssignments(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getAssignments(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleEvents(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleEvents(module, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleEvents(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getEvents(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleGradebook(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleGradebook(module, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleGradebook(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getGradebook(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleResources(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error) {
|
|
||||||
getModuleResources(module, callback, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getModuleResources(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback error, boolean forceRefresh) {
|
|
||||||
getModulePart(modules -> modules.getResources(module, saveOnCallback(modules, callback, forceRefresh), errorOnCallback(error), forceRefresh));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getResourceFile(final NetworkCallback<String> callback, final NetworkErrorCallback error, String filename, String url, String moduleName, boolean downloadNew){
|
|
||||||
getModulePart(modules -> modules.getResourceFile(callback, errorOnCallback(error),filename, url, moduleName, downloadNew));
|
|
||||||
}
|
|
||||||
|
|
||||||
public void testLogin(BooleanFunction callback) {
|
|
||||||
getLastToken(lastToken -> {
|
|
||||||
TestLogin.testLogin(context, lastToken, success -> callback.apply(true), error -> callback.apply(false));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void getModulePart(ModListFunction func) {
|
|
||||||
this.getLastToken(token -> {
|
@NotNull
|
||||||
KVVModuleList modules = (KVVModuleList) addons.get("modules");
|
private Object addAndGet(@NotNull String addon, @NotNull ModuleCreatorInterface creatorInterface) {
|
||||||
if (modules == null) {
|
Object o = addons.get(addon);
|
||||||
modules = new KVVModuleList(this.context, token);
|
if (o == null) {
|
||||||
addons.put("modules", modules);
|
o = creatorInterface.create();
|
||||||
|
addons.put(addon, o);
|
||||||
}
|
}
|
||||||
func.apply(modules);
|
return o;
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private<T> NetworkCallback<T> saveOnCallback(KVVModuleList modules, NetworkCallback<T> callback, boolean forceRefresh){
|
private interface ModuleCreatorInterface {
|
||||||
return (success -> {
|
@NotNull Object create();
|
||||||
try {
|
|
||||||
modules.saveModulesOffline(this.context);
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (forceRefresh)
|
|
||||||
mListener.onRefreshCompleted(false);
|
|
||||||
callback.onResponse(success);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private NetworkErrorCallback errorOnCallback(NetworkErrorCallback errorCallback){
|
|
||||||
return (error -> {
|
|
||||||
if (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)
|
|
||||||
mListener.loginTokenInvalid(true);
|
|
||||||
else
|
|
||||||
mListener.onRefreshCompleted(true);
|
|
||||||
log.e(error);
|
|
||||||
errorCallback.onError(error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
interface ModListFunction {
|
|
||||||
void apply(KVVModuleList mod);
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
public interface BooleanFunction {
|
|
||||||
void apply(boolean isSuccess);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getLastToken(LastTokenCallback lastTokenCallback) {
|
|
||||||
if (this.isLoginPending) {
|
|
||||||
this.updatingList.add(lastTokenCallback);
|
|
||||||
} else {
|
|
||||||
lastTokenCallback.onReceived(this.lastToken);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void endUpdate() {
|
|
||||||
this.isLoginPending = false;
|
|
||||||
for (LastTokenCallback s: this.updatingList) {
|
|
||||||
s.onReceived(this.lastToken);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import com.android.volley.NetworkResponse;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.GoogleAuth.Credentials;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public interface KVVListener {
|
||||||
|
void getCredentials(NetworkCallback<Credentials> callback, NetworkErrorCallback error);
|
||||||
|
|
||||||
|
void onLogin(LoginToken token, boolean enteringOnlineMode);
|
||||||
|
|
||||||
|
void onLogout();
|
||||||
|
|
||||||
|
void onModuleListChange();
|
||||||
|
|
||||||
|
void onKVVNetworkResponse(NetworkResponse error);
|
||||||
|
}
|
||||||
@@ -1,643 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.KVV;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
|
||||||
import android.text.Html;
|
|
||||||
import android.text.Spanned;
|
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
import java.util.concurrent.atomic.AtomicReference;
|
|
||||||
import java.util.regex.MatchResult;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.AssignmentList;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.EventList;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Gradebook;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.Resource;
|
|
||||||
import de.sebse.fuplanner.tools.AsyncQueue;
|
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
|
||||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
|
||||||
import de.sebse.fuplanner.tools.network.Result;
|
|
||||||
|
|
||||||
import static de.sebse.fuplanner.services.KVV.TestLogin.testLogin;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 29.10.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class KVVModuleList extends HTTPService {
|
|
||||||
private final LoginToken token;
|
|
||||||
private Modules moduleList;
|
|
||||||
private final AsyncQueue queueModuleDetails = new AsyncQueue();
|
|
||||||
|
|
||||||
KVVModuleList(Context context, LoginToken token) {
|
|
||||||
super(context);
|
|
||||||
this.token = token;
|
|
||||||
try {
|
|
||||||
Modules modules = Modules.load(context);
|
|
||||||
if (token == null || token.isSameUser(modules.getToken()))
|
|
||||||
this.moduleList = modules;
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getModuleList(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
queueModuleDetails.add("list", () -> {
|
|
||||||
if (this.moduleList != null && !forceRefresh) {
|
|
||||||
callback.onResponse(this.moduleList);
|
|
||||||
queueModuleDetails.next("list");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.getModuleListUpgrade(success -> {
|
|
||||||
if (this.moduleList == null)
|
|
||||||
this.moduleList = success;
|
|
||||||
else
|
|
||||||
this.moduleList.updateList(success);
|
|
||||||
callback.onResponse(this.moduleList);
|
|
||||||
queueModuleDetails.next("list");
|
|
||||||
}, queueModuleDetails.check("list", errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getModuleListUpgrade(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101105, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get("https://kvv.imp.fu-berlin.de/direct/site.json", token.getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101101, 403, "No module list retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Modules modules = new Modules(token);
|
|
||||||
JSONArray sites;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
sites = json.getJSONArray("site_collection");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101102, 403, "Cannot parse module list!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
try {
|
|
||||||
JSONObject site = sites.getJSONObject(i);
|
|
||||||
String semester = site.getJSONObject("props").getString("term_eid");
|
|
||||||
HashSet<String> lvNumbers = new HashSet<>();
|
|
||||||
for (MatchResult matchResult : Regex.allMatches("[0-9]+", site.getJSONObject("props").getString("kvv_lvnumbers"))) {
|
|
||||||
lvNumbers.add(matchResult.group());
|
|
||||||
}
|
|
||||||
String title = site.getString("entityTitle");
|
|
||||||
HashSet<Lecturer> lecturers = new HashSet<>();
|
|
||||||
for (String lecturer : site.getJSONObject("props").getString("kvv_lecturers").split("#")) {
|
|
||||||
if (lecturer.length() > 2)
|
|
||||||
lecturers.add(new Lecturer(lecturer));
|
|
||||||
}
|
|
||||||
String type = site.getJSONObject("props").getString("kvv_coursetype");
|
|
||||||
String description = site.optString("description", "");
|
|
||||||
description = String.valueOf(fromHtml(description));
|
|
||||||
String id = site.getString("id");
|
|
||||||
modules.addModule(semester, lvNumbers, title, lecturers, type, description, id);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e("Cannot parse module! ID:", i, sites);
|
|
||||||
e.printStackTrace();
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
log.e("Cannot parse module! ID:", i, sites);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Empty module *may be* because token is invalid -> check
|
|
||||||
if (modules.size() == 0)
|
|
||||||
testLogin(getContext(), token, token -> callback.onResponse(modules), errorCallback);
|
|
||||||
else
|
|
||||||
callback.onResponse(modules);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101104, error.networkResponse.statusCode, "Cannot get module list!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
void deleteModulesOffline(Context context) {
|
|
||||||
if (this.moduleList != null)
|
|
||||||
this.moduleList.delete(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
void saveModulesOffline(Context context) throws IOException {
|
|
||||||
if (this.moduleList != null)
|
|
||||||
this.moduleList.save(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
void getModule(String id, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
this.getModuleList(success -> {
|
|
||||||
callback.onResponse(success.get(id));
|
|
||||||
}, errorCallback, forceRefresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getModuleDetails(Modules.Module module, final NetworkCallback<Pair<Modules.Module, Boolean>> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
AtomicInteger returns = new AtomicInteger(0);
|
|
||||||
AtomicReference<NetworkError> lastError = new AtomicReference<>(null);
|
|
||||||
final AtomicInteger items = new AtomicInteger(0);
|
|
||||||
NetworkCallback<Modules.Module> successCb = success -> {
|
|
||||||
returns.getAndIncrement();
|
|
||||||
callback.onResponse(Pair.create(module, false));
|
|
||||||
if (returns.get() == items.get()) {
|
|
||||||
callback.onResponse(Pair.create(module, true));
|
|
||||||
if (lastError.get() != null)
|
|
||||||
errorCallback.onError(lastError.get());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
NetworkErrorCallback errorCb = error -> {
|
|
||||||
lastError.set(error);
|
|
||||||
returns.getAndIncrement();
|
|
||||||
if (returns.get() == items.get()) {
|
|
||||||
callback.onResponse(Pair.create(module, true));
|
|
||||||
if (lastError.get() != null)
|
|
||||||
errorCallback.onError(lastError.get());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
Runnable[] methods = {
|
|
||||||
() -> this.getAssignments(module, successCb, errorCb, forceRefresh),
|
|
||||||
() -> this.getEvents(module, successCb, errorCb, forceRefresh),
|
|
||||||
() -> this.getAnnouncements(module, successCb, errorCb, forceRefresh),
|
|
||||||
() -> this.getGradebook(module, successCb, errorCb, forceRefresh),
|
|
||||||
() -> this.getResources(module, successCb, errorCb, forceRefresh)
|
|
||||||
};
|
|
||||||
items.set(methods.length);
|
|
||||||
for (Runnable method: methods) {
|
|
||||||
method.run();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getAnnouncements(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
queueModuleDetails.add(module.getID(), () -> {
|
|
||||||
if (module.announcements != null && !forceRefresh) {
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getAnnouncementsUpgrade(module.getID(), success -> {
|
|
||||||
module.announcements = success;
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
}, queueModuleDetails.check(module.getID(), errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getAnnouncementsUpgrade(String ID, final NetworkCallback<ArrayList<Announcement>> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101204, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/announcement/site/%s.json?n=999999&d=999999999", ID), token.getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101201, 403, "No announcements retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<Announcement> announcements = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
JSONArray sites = json.getJSONArray("announcement_collection");
|
|
||||||
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
JSONObject site = sites.getJSONObject(i);
|
|
||||||
String id = site.getString("announcementId");
|
|
||||||
String title = site.getString("title");
|
|
||||||
String text = site.getString("body");
|
|
||||||
text = String.valueOf(fromHtml(text));
|
|
||||||
String createdBy = site.getString("createdByDisplayName");
|
|
||||||
long createdOn = site.getLong("createdOn");
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Extract attachment links
|
|
||||||
JSONArray attachments = site.getJSONArray("attachments");
|
|
||||||
ArrayList<String> urls = new ArrayList<>();
|
|
||||||
for (int j =0; j<attachments.length(); j++){
|
|
||||||
urls.add(attachments.getJSONObject(j).optString("url",null));
|
|
||||||
}
|
|
||||||
|
|
||||||
announcements.add(new Announcement(id, title, text, createdBy, createdOn, urls));
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101202, 403, "Cannot parse announcements!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Empty announcements *may be* because token is invalid -> check
|
|
||||||
if (announcements.size() == 0)
|
|
||||||
testLogin(getContext(), token, token -> callback.onResponse(announcements), errorCallback);
|
|
||||||
else
|
|
||||||
callback.onResponse(announcements);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101203, error.networkResponse.statusCode, "Cannot get announcements!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getAssignments(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
queueModuleDetails.add(module.getID(), () -> {
|
|
||||||
if (module.assignments != null && !forceRefresh) {
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getAssignmentsUpgrade(module.getID(), success -> {
|
|
||||||
module.assignments = success;
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
}, queueModuleDetails.check(module.getID(), errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getAssignmentsUpgrade(String ID, final NetworkCallback<AssignmentList> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101304, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/assignment/site/%s.json", ID), token.getCookies(), response ->{
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101301, 403, "No assignments retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
AssignmentList assignments = new AssignmentList();
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
JSONArray sites = json.getJSONArray("assignment_collection");
|
|
||||||
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
JSONObject site = sites.getJSONObject(i);
|
|
||||||
String id = site.getString("id");
|
|
||||||
String title = site.getString("title");
|
|
||||||
String instructions = site.getString("instructions");
|
|
||||||
instructions = String.valueOf(fromHtml(instructions));
|
|
||||||
long dueTime = site.getJSONObject("dueTime").getLong("time");
|
|
||||||
String gradebookItemName = site.optString("gradebookItemName", null);
|
|
||||||
String gradeScale = site.getString("gradeScale");
|
|
||||||
JSONArray attachments = site.getJSONArray("attachments");
|
|
||||||
ArrayList<String> urls = new ArrayList<>();
|
|
||||||
for (int j = 0; j<attachments.length(); j++){
|
|
||||||
urls.add(attachments.getJSONObject(j).getString("url"));
|
|
||||||
}
|
|
||||||
assignments.add(0, new Assignment(id, title, dueTime, gradebookItemName, gradeScale, urls, instructions));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101302, 403, "Cannot parse announcements!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// Empty assignments *may be* because token is invalid -> check
|
|
||||||
if (assignments.size() == 0)
|
|
||||||
testLogin(getContext(), token, token -> callback.onResponse(assignments), errorCallback);
|
|
||||||
else
|
|
||||||
callback.onResponse(assignments);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101303, error.networkResponse.statusCode, "Cannot get assignments!")));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getEvents(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
queueModuleDetails.add(module.getID(), () -> {
|
|
||||||
if (module.events != null && !forceRefresh) {
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getEventsUpgrade(module.getID(), success -> {
|
|
||||||
module.events = success;
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
}, queueModuleDetails.check(module.getID(), errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getEventsUpgrade(String ID, final NetworkCallback<EventList> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101404, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/calendar/site/%s.json?detailed=true", ID), token.getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101401, 403, "No calendar retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EventList events = new EventList();
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
JSONArray sites = json.getJSONArray("calendar_collection");
|
|
||||||
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
JSONObject site = sites.getJSONObject(i);
|
|
||||||
String id = site.getString("eventId");
|
|
||||||
String type = site.getString("type");
|
|
||||||
String title = site.getString("title");
|
|
||||||
String siteId = site.getString("siteId");
|
|
||||||
long duration = site.getLong("duration");
|
|
||||||
long firstTime = site.getJSONObject("firstTime").getLong("time");
|
|
||||||
String location = site.getString("location");
|
|
||||||
events.add(new Event(id, type, title, duration, firstTime, siteId, location));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101402, 403, "Cannot parse calendar entries!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
events.sort();
|
|
||||||
// Empty events *may be* because token is invalid -> check
|
|
||||||
if (events.size() == 0)
|
|
||||||
testLogin(getContext(), token, token -> callback.onResponse(events), errorCallback);
|
|
||||||
else
|
|
||||||
callback.onResponse(events);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101403, error.networkResponse.statusCode, "Cannot get calendar entries!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void getGradebook(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
queueModuleDetails.add(module.getID(), () -> {
|
|
||||||
if (module.gradebook != null && !forceRefresh) {
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getGradebookUpgrade(module.getID(), success -> {
|
|
||||||
module.gradebook = success;
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
}, queueModuleDetails.check(module.getID(), errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getGradebookUpgrade(String ID, final NetworkCallback<ArrayList<Gradebook>> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101504, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/gradebook/site/%s.json", ID ), token.getCookies(), response ->{
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101501, 403, "No assignments retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<Gradebook> gradebook = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
JSONArray sites = json.getJSONArray("assignments");
|
|
||||||
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
JSONObject site = sites.getJSONObject(i);
|
|
||||||
double grade = site.optDouble("grade", 0);
|
|
||||||
String itemName = site.optString("itemName", null);
|
|
||||||
double maxPoints = site.optDouble("points", -1);
|
|
||||||
|
|
||||||
gradebook.add(0, new Gradebook(itemName, grade, maxPoints));
|
|
||||||
}
|
|
||||||
|
|
||||||
}catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101502, 403, "Cannot parse gradebook for announcements!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback.onResponse(gradebook);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101503, error.networkResponse.statusCode, "Cannot get gradebook for assignments!")));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getResources(Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
queueModuleDetails.add(module.getID(), () -> {
|
|
||||||
if (module.resources != null && !forceRefresh) {
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getResourcesUpgrade(module.getID(), success -> {
|
|
||||||
module.resources = success;
|
|
||||||
callback.onResponse(module);
|
|
||||||
queueModuleDetails.next(module.getID());
|
|
||||||
}, queueModuleDetails.check(module.getID(), errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getResourcesUpgrade(String ID, final NetworkCallback<ArrayList<Resource>> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/content/site/%s.json", ID ), token.getCookies(), response ->{
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101601, 403, "No resources retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<Resource> resources = new ArrayList<>();
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
JSONArray sites = json.getJSONArray("content_collection");
|
|
||||||
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
JSONObject site = sites.getJSONObject(i);
|
|
||||||
String author = site.getString("author");
|
|
||||||
String title = site.getString("title");
|
|
||||||
long modifiedDate = site.getLong("modifiedDate");
|
|
||||||
String url = site.getString("url");
|
|
||||||
boolean visible = site.getBoolean("visible");
|
|
||||||
String type = site.getString("type");
|
|
||||||
String container = site.getString("container");
|
|
||||||
if (type.equals("collection")){
|
|
||||||
resources.add(new Resource.Folder(author, title, modifiedDate, url, visible, container));
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
resources.add(new Resource.File(author, title, modifiedDate, url, visible, container, type));
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
ArrayList<Resource> root = new ArrayList<>();
|
|
||||||
// Generate folder structure
|
|
||||||
for (Resource res: resources) {
|
|
||||||
if (!res.getContainer().equals("/content/group/")) {
|
|
||||||
if (res.getContainer().equals("/content/group/"+ID+"/")){
|
|
||||||
// if file in root folder
|
|
||||||
root.add(res);
|
|
||||||
} else {
|
|
||||||
// in sub folder
|
|
||||||
for (Resource res2: resources) {
|
|
||||||
if (res2.getUrl().endsWith(res.getContainer()) && res2 instanceof Resource.Folder) {
|
|
||||||
// Append File/Folder to list
|
|
||||||
((Resource.Folder) res2).add(res);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Empty resources *may be* because token is invalid -> check
|
|
||||||
if (root.size() == 0)
|
|
||||||
testLogin(getContext(), token, token -> callback.onResponse(root), errorCallback);
|
|
||||||
else
|
|
||||||
callback.onResponse(root);
|
|
||||||
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void getResourceFile(final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback, String Filename, String url, String moduleName, boolean downloadNew) {
|
|
||||||
if (isExternalStorageReadable()){
|
|
||||||
File f = new File(Environment.getExternalStoragePublicDirectory(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS)+"/"+moduleName+"/"+Filename);
|
|
||||||
// check if file already downloaded -> do not download again
|
|
||||||
if (f.exists() && !downloadNew) {
|
|
||||||
callback.onResponse(f.getPath());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
getResourceFileUpgrade(Filename, url , moduleName, callback, errorCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getResourceFileUpgrade(String filename, String url , String moduleName, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (token == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101701, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get(url, token.getCookies(), response ->{
|
|
||||||
|
|
||||||
|
|
||||||
if (Regex.has("\\.[Uu][Rr][Ll]$", url)){
|
|
||||||
// Return redirected URL
|
|
||||||
String path = response.getHeaders().get("Location");
|
|
||||||
if (path == null){
|
|
||||||
path = "";
|
|
||||||
}
|
|
||||||
callback.onResponse(path);
|
|
||||||
} else if (response.getBytes()==null){
|
|
||||||
testLogin(getContext(), token, token -> {
|
|
||||||
if (isExternalStorageWritable()) {
|
|
||||||
// try to download file again
|
|
||||||
get(url, token.getCookies(), response2 -> {
|
|
||||||
String path = saveFileInDownloads(filename, response2, moduleName);
|
|
||||||
callback.onResponse(path);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101705, error.networkResponse.statusCode, "Cannot get file!")));
|
|
||||||
} else {
|
|
||||||
errorCallback.onError(new NetworkError(101703, 403, "External storage not writable!"));
|
|
||||||
}
|
|
||||||
}, errorCallback);
|
|
||||||
} else if (isExternalStorageWritable()) {
|
|
||||||
String path = saveFileInDownloads(filename, response, moduleName);
|
|
||||||
callback.onResponse(path);
|
|
||||||
} else {
|
|
||||||
errorCallback.onError(new NetworkError(101704, 403, "External storage not writable!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101702, error.networkResponse.statusCode, "Cannot get file!")));
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/* Checks if external storage is available for read and write */
|
|
||||||
private boolean isExternalStorageWritable() {
|
|
||||||
String state = Environment.getExternalStorageState();
|
|
||||||
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
log.w("File system: Writing not possible!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Checks if external storage is available to at least read */
|
|
||||||
private boolean isExternalStorageReadable() {
|
|
||||||
String state = Environment.getExternalStorageState();
|
|
||||||
if (Environment.MEDIA_MOUNTED.equals(state) ||
|
|
||||||
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
log.w("File system: Reading not possible!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
private String saveFileInDownloads(String filename, Result fileResult, String moduleName) {
|
|
||||||
// Saves file in folder: DOWNLOADS/moduleName
|
|
||||||
File folder = new File(Environment.getExternalStoragePublicDirectory(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
|
||||||
if (!folder.mkdirs()) {
|
|
||||||
log.w( "Directory not created", folder.toString());
|
|
||||||
}
|
|
||||||
String path = "";
|
|
||||||
try {
|
|
||||||
// TODO check if enough storage space is available
|
|
||||||
FileOutputStream out = new FileOutputStream(folder.getPath()+"/"+filename);
|
|
||||||
out.write(fileResult.getBytes());
|
|
||||||
out.close();
|
|
||||||
path = folder.getPath()+"/"+filename;
|
|
||||||
} catch (Exception e) {
|
|
||||||
log.w("File not saved!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
return path;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings("deprecation")
|
|
||||||
public static Spanned fromHtml(String html){
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
|
||||||
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
|
||||||
} else {
|
|
||||||
return Html.fromHtml(html);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.KVV;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 31.01.18.
|
|
||||||
*/
|
|
||||||
|
|
||||||
interface LastTokenCallback {
|
|
||||||
void onReceived(LoginToken token);
|
|
||||||
}
|
|
||||||
@@ -2,69 +2,191 @@ package de.sebse.fuplanner.services.KVV;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
import static de.sebse.fuplanner.services.KVV.TestLogin.testLogin;
|
public class Login extends HTTPService {
|
||||||
|
private KVVListener mListener;
|
||||||
|
@Nullable private LoginToken mToken;
|
||||||
|
private boolean mLoginPending = false;
|
||||||
|
private boolean mOnlineMode = false;
|
||||||
|
|
||||||
/**
|
Login(KVVListener listener, Context context) {
|
||||||
* Created by sebastian on 24.10.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
class KVVLogin extends HTTPService {
|
|
||||||
private LoginToken loginToken;
|
|
||||||
|
|
||||||
KVVLogin(Context context) {
|
|
||||||
super(context);
|
super(context);
|
||||||
|
this.mListener = listener;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doOnlineLogin(@NotNull String username, @NotNull String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback errorCallback) {
|
||||||
|
if (mLoginPending) {
|
||||||
|
errorCallback.onError(new NetworkError(100160, -1, "Login already pending!"));
|
||||||
|
}
|
||||||
|
mLoginPending = true;
|
||||||
|
doLogin(username, password, token -> {
|
||||||
|
testLoginToken(token, token2 -> {
|
||||||
|
setToken(token2, true);
|
||||||
|
mLoginPending = false;
|
||||||
|
callback.onResponse(token2);
|
||||||
|
}, error -> {
|
||||||
|
mLoginPending = false;
|
||||||
|
errorCallback.onError(error);
|
||||||
|
});
|
||||||
|
}, error -> {
|
||||||
|
mLoginPending = false;
|
||||||
|
errorCallback.onError(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean restoreOnlineLogin() {
|
||||||
|
return restoreLogin(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean doOfflineLogin() {
|
||||||
|
return restoreLogin(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean restoreLogin(boolean enteringOnlineMode) {
|
||||||
|
if (mLoginPending || mToken != null)
|
||||||
|
return false;
|
||||||
|
mLoginPending = true;
|
||||||
|
boolean result = false;
|
||||||
try {
|
try {
|
||||||
this.loginToken = LoginToken.load(context);
|
result = setToken(LoginToken.load(getContext()), enteringOnlineMode);
|
||||||
|
} catch (FileNotFoundException ignored) {
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
mLoginPending = false;
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginToken easyLogin() {
|
public boolean isOfflineStoredAvailable() {
|
||||||
return this.loginToken;
|
try {
|
||||||
|
LoginToken load = LoginToken.load(getContext());
|
||||||
|
return load != null;
|
||||||
|
} catch (FileNotFoundException ignored) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
void login(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback errorCallback) {
|
public boolean logout(boolean delete) {
|
||||||
if (this.loginToken != null) {
|
if (mLoginPending)
|
||||||
if (this.loginToken.getUsername().equals(username)) {
|
return false;
|
||||||
testLogin(getContext(), this.loginToken, success -> callback.onResponse(this.loginToken), error -> {
|
if (mToken == null)
|
||||||
this.loginToken = null;
|
return true;
|
||||||
login(username, password, callback, errorCallback);
|
if (delete)
|
||||||
|
mToken.delete(getContext());
|
||||||
|
mToken = null;
|
||||||
|
return handleCallbacks();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLoginPending() {
|
||||||
|
return mLoginPending;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isLoggedIn() {
|
||||||
|
return mToken != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInOfflineMode() {
|
||||||
|
return isLoggedIn() && !mOnlineMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isInOnlineMode() {
|
||||||
|
return isLoggedIn() && mOnlineMode;
|
||||||
|
}
|
||||||
|
|
||||||
|
void testLoginToken(@NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||||
|
if (mToken == null) {
|
||||||
|
errorCallback.onError(new NetworkError(100173, -1, "Not logged in!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
testLoginToken(mToken, callback, errorCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void testLoginToken(@NotNull LoginToken token, @NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||||
|
get(String.format("https://kvv.imp.fu-berlin.de/direct/profile/%s.json", token.getUsername()), token.getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(100172, 403, "Testing login failed!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
String displayName = json.getString("displayName");
|
||||||
|
String email = json.getString("email");
|
||||||
|
token.setAdditionals(displayName, email);
|
||||||
|
callback.onResponse(token);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
errorCallback.onError(new NetworkError(100171, 403, "Cannot parse profile!"));
|
||||||
|
}
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100170, error.networkResponse.statusCode, "Testing login failed!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable public LoginToken getLoginToken() {
|
||||||
|
return mToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
void refreshLogin(NetworkCallback<LoginToken> success, NetworkErrorCallback error) {
|
||||||
|
mListener.getCredentials(credentials -> {
|
||||||
|
doOnlineLogin(credentials.getUsername(), credentials.getPassword(), success, error);
|
||||||
|
}, e -> {
|
||||||
|
logout(false);
|
||||||
|
error.onError(e);
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
this.loginToken = null;
|
|
||||||
login(username, password, callback, errorCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private boolean handleCallbacks() {
|
||||||
|
if (mToken != null) {
|
||||||
|
mListener.onLogin(mToken, mOnlineMode);
|
||||||
|
return true;
|
||||||
} else {
|
} else {
|
||||||
doLogin(username, password, token -> {
|
mListener.onLogout();
|
||||||
this.loginToken = token;
|
return false;
|
||||||
testLogin(getContext(), this.loginToken, success -> callback.onResponse(this.loginToken), errorCallback);
|
|
||||||
}, errorCallback);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void deleteOffline() {
|
private boolean setToken(@Nullable LoginToken token, boolean enteringOnlineMode) {
|
||||||
if (this.loginToken != null)
|
if (token == null)
|
||||||
this.loginToken.delete(getContext());
|
return false;
|
||||||
|
boolean isOnlyRefresh = mToken != null;
|
||||||
|
mToken = token;
|
||||||
|
if (enteringOnlineMode) {
|
||||||
|
try {
|
||||||
|
mToken.save(getContext());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
mOnlineMode = enteringOnlineMode;
|
||||||
|
return isOnlyRefresh || handleCallbacks();
|
||||||
}
|
}
|
||||||
|
|
||||||
void saveOffline() throws IOException {
|
|
||||||
if (this.loginToken != null)
|
|
||||||
this.loginToken.save(getContext());
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -320,5 +442,3 @@ class KVVLogin extends HTTPService {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -0,0 +1,81 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class Modules {
|
||||||
|
private final HashMap<String, Part> mAddons = new HashMap<>();
|
||||||
|
private ModulesList mList = null;
|
||||||
|
private final Login mLogin;
|
||||||
|
private KVVListener mListener;
|
||||||
|
private final Context context;
|
||||||
|
|
||||||
|
Modules(Login login, KVVListener listener, Context context) {
|
||||||
|
this.mLogin = login;
|
||||||
|
this.mListener = listener;
|
||||||
|
this.context = context;
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesDetails details() {
|
||||||
|
return (ModulesDetails) addAndGet("details", () -> {
|
||||||
|
PartModules[] parts = {announcements(), assignments(), events(), gradebook(), resources()};
|
||||||
|
return new ModulesDetails(mLogin, list(), context, parts);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesAnnouncements announcements() {
|
||||||
|
return (ModulesAnnouncements) addAndGet("announcements", () -> new ModulesAnnouncements(mLogin, list(), context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesAssignments assignments() {
|
||||||
|
return (ModulesAssignments) addAndGet("assignments", () -> new ModulesAssignments(mLogin, list(), context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesEvents events() {
|
||||||
|
return (ModulesEvents) addAndGet("events", () -> new ModulesEvents(mLogin, list(), context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesGradebook gradebook() {
|
||||||
|
return (ModulesGradebook) addAndGet("gradebook", () -> new ModulesGradebook(mLogin, list(), context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesResources resources() {
|
||||||
|
return (ModulesResources) addAndGet("resources", () -> new ModulesResources(mLogin, list(), context));
|
||||||
|
}
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
public ModulesList list() {
|
||||||
|
if (mList == null) {
|
||||||
|
mList = new ModulesList(mLogin, mListener, context);
|
||||||
|
mList.addErrorListener("Modules", error -> mListener.onKVVNetworkResponse(error.networkResponse));
|
||||||
|
mList.addSuccessListener("Modules", success -> mListener.onKVVNetworkResponse(null));
|
||||||
|
}
|
||||||
|
return mList;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@NotNull
|
||||||
|
private Part addAndGet(@NotNull String addon, @NotNull ModuleCreatorInterface creatorInterface) {
|
||||||
|
Part o = mAddons.get(addon);
|
||||||
|
if (o == null) {
|
||||||
|
o = creatorInterface.create();
|
||||||
|
o.addErrorListener("Modules", error -> mListener.onKVVNetworkResponse(error.networkResponse));
|
||||||
|
o.addSuccessListener("Modules", success -> mListener.onKVVNetworkResponse(null));
|
||||||
|
mAddons.put(addon, o);
|
||||||
|
}
|
||||||
|
return o;
|
||||||
|
}
|
||||||
|
|
||||||
|
private interface ModuleCreatorInterface {
|
||||||
|
@NotNull Part create();
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,91 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public class ModulesAnnouncements extends PartModules<ArrayList<Announcement>> {
|
||||||
|
|
||||||
|
ModulesAnnouncements(Login login, ModulesList list, Context context) {
|
||||||
|
super(login, list, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ArrayList<Announcement> getPart(Modules.Module module) {
|
||||||
|
return module.announcements;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setPart(Modules.Module module, ArrayList<Announcement> part) {
|
||||||
|
boolean changed = module.announcements == null || module.announcements.hashCode() != part.hashCode();
|
||||||
|
module.announcements = part;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void upgrade(final String ID, final NetworkCallback<ArrayList<Announcement>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101204, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.get(String.format("https://kvv.imp.fu-berlin.de/direct/announcement/site/%s.json?n=999999&d=999999999", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101201, 403, "No announcements retrieved!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ArrayList<Announcement> announcements = new ArrayList<>();
|
||||||
|
JSONArray sites;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
sites = json.getJSONArray("announcement_collection");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorCallback.onError(new NetworkError(101202, 403, "Cannot parse announcements!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
|
try {
|
||||||
|
JSONObject site = sites.getJSONObject(i);
|
||||||
|
String id = site.getString("announcementId");
|
||||||
|
String title = site.getString("title");
|
||||||
|
String text = site.getString("body");
|
||||||
|
text = String.valueOf(fromHtml(text));
|
||||||
|
String createdBy = site.getString("createdByDisplayName");
|
||||||
|
long createdOn = site.getLong("createdOn");
|
||||||
|
|
||||||
|
// Extract attachment links
|
||||||
|
JSONArray attachments = site.getJSONArray("attachments");
|
||||||
|
ArrayList<String> urls = new ArrayList<>();
|
||||||
|
for (int j = 0; j < attachments.length(); j++) {
|
||||||
|
urls.add(attachments.getJSONObject(j).optString("url", null));
|
||||||
|
}
|
||||||
|
|
||||||
|
announcements.add(new Announcement(id, title, text, createdBy, createdOn, urls));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.e(new NetworkError(101205, 403, "Cannot parse announcements!"));
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty announcements *may be* because token is invalid -> check
|
||||||
|
if (announcements.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(announcements), errorCallback);
|
||||||
|
else
|
||||||
|
callback.onResponse(announcements);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101203, error.networkResponse.statusCode, "Cannot get announcements!")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,90 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.AssignmentList;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public class ModulesAssignments extends PartModules<AssignmentList> {
|
||||||
|
|
||||||
|
ModulesAssignments(Login login, ModulesList list, Context context) {
|
||||||
|
super(login, list, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected AssignmentList getPart(Modules.Module module) {
|
||||||
|
return module.assignments;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setPart(Modules.Module module, AssignmentList part) {
|
||||||
|
boolean changed = module.assignments == null || module.assignments.hashCode() != part.hashCode();
|
||||||
|
module.assignments = part;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void upgrade(final String ID, final NetworkCallback<AssignmentList> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101304, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get(String.format("https://kvv.imp.fu-berlin.de/direct/assignment/site/%s.json", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101301, 403, "No assignments retrieved!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
AssignmentList assignments = new AssignmentList();
|
||||||
|
JSONArray sites;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
sites = json.getJSONArray("assignment_collection");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorCallback.onError(new NetworkError(101302, 403, "Cannot parse assignments!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
|
try {
|
||||||
|
JSONObject site = sites.getJSONObject(i);
|
||||||
|
String id = site.getString("id");
|
||||||
|
String title = site.getString("title");
|
||||||
|
String instructions = site.getString("instructions");
|
||||||
|
instructions = String.valueOf(fromHtml(instructions));
|
||||||
|
long dueTime = site.getJSONObject("dueTime").getLong("time");
|
||||||
|
String gradebookItemName = site.optString("gradebookItemName", null);
|
||||||
|
String gradeScale = site.getString("gradeScale");
|
||||||
|
JSONArray attachments = site.getJSONArray("attachments");
|
||||||
|
ArrayList<String> urls = new ArrayList<>();
|
||||||
|
for (int j = 0; j < attachments.length(); j++) {
|
||||||
|
urls.add(attachments.getJSONObject(j).getString("url"));
|
||||||
|
}
|
||||||
|
assignments.add(0, new Assignment(id, title, dueTime, gradebookItemName, gradeScale, urls, instructions));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.e(new NetworkError(101305, 403, "Cannot parse assignments!"));
|
||||||
|
e.printStackTrace();
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty assignments *may be* because token is invalid -> check
|
||||||
|
if (assignments.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(assignments), errorCallback);
|
||||||
|
else
|
||||||
|
callback.onResponse(assignments);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101303, error.networkResponse.statusCode, "Cannot get assignments!")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,47 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.util.Pair;
|
||||||
|
|
||||||
|
import java.util.concurrent.atomic.AtomicReference;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
final public class ModulesDetails extends Part<Pair<Modules.Module, Boolean>> {
|
||||||
|
private final PartModules[] parts;
|
||||||
|
|
||||||
|
ModulesDetails(Login login, ModulesList list, Context context, PartModules[] parts) {
|
||||||
|
super(login, list, context);
|
||||||
|
this.parts = parts;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void recv(final Modules.Module module, final NetworkCallback<Pair<Modules.Module, Boolean>> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh, final int retries) {
|
||||||
|
final int[] returned = {0};
|
||||||
|
AtomicReference<NetworkError> lastError = new AtomicReference<>(null);
|
||||||
|
NetworkCallback<Modules.Module> successCb = success -> {
|
||||||
|
returned[0] += 1;
|
||||||
|
callback.onResponse(Pair.create(module, false));
|
||||||
|
if (returned[0] == parts.length) {
|
||||||
|
callback.onResponse(Pair.create(module, true));
|
||||||
|
if (lastError.get() != null)
|
||||||
|
errorCallback.onError(lastError.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
NetworkErrorCallback errorCb = error -> {
|
||||||
|
lastError.set(error);
|
||||||
|
returned[0] += 1;
|
||||||
|
if (returned[0] == parts.length) {
|
||||||
|
callback.onResponse(Pair.create(module, true));
|
||||||
|
if (lastError.get() != null)
|
||||||
|
errorCallback.onError(lastError.get());
|
||||||
|
}
|
||||||
|
};
|
||||||
|
for (PartModules<?> part: parts) {
|
||||||
|
part.recv(module, successCb, errorCb, forceRefresh, RETRY_COUNT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,83 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.EventList;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public class ModulesEvents extends PartModules<EventList> {
|
||||||
|
|
||||||
|
ModulesEvents(Login login, ModulesList list, Context context) {
|
||||||
|
super(login, list, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EventList getPart(Modules.Module module) {
|
||||||
|
return module.events;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setPart(Modules.Module module, EventList part) {
|
||||||
|
boolean changed = module.events == null || module.events.hashCode() != part.hashCode();
|
||||||
|
module.events = part;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void upgrade(final String ID, final NetworkCallback<EventList> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101404, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get(String.format("https://kvv.imp.fu-berlin.de/direct/calendar/site/%s.json?detailed=true", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101401, 403, "No events retrieved!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
EventList events = new EventList();
|
||||||
|
JSONArray sites;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
sites = json.getJSONArray("calendar_collection");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorCallback.onError(new NetworkError(101402, 403, "Cannot parse events!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
|
try {
|
||||||
|
JSONObject site = sites.getJSONObject(i);
|
||||||
|
String id = site.getString("eventId");
|
||||||
|
String type = site.getString("type");
|
||||||
|
String title = site.getString("title");
|
||||||
|
String siteId = site.getString("siteId");
|
||||||
|
long duration = site.getLong("duration");
|
||||||
|
long firstTime = site.getJSONObject("firstTime").getLong("time");
|
||||||
|
String location = site.getString("location");
|
||||||
|
events.add(new Event(id, type, title, duration, firstTime, siteId, location));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.e(new NetworkError(101405, 403, "Cannot parse events!"));
|
||||||
|
e.printStackTrace();
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty events *may be* because token is invalid -> check
|
||||||
|
if (events.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(events), errorCallback);
|
||||||
|
else
|
||||||
|
callback.onResponse(events);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101403, error.networkResponse.statusCode, "Cannot get events!")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,76 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Grade;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public class ModulesGradebook extends PartModules<ArrayList<Grade>> {
|
||||||
|
|
||||||
|
ModulesGradebook(Login login, ModulesList list, Context context) {
|
||||||
|
super(login, list, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ArrayList<Grade> getPart(Modules.Module module) {
|
||||||
|
return module.gradebook;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setPart(Modules.Module module, ArrayList<Grade> part) {
|
||||||
|
boolean changed = module.gradebook == null || module.gradebook.hashCode() != part.hashCode();
|
||||||
|
module.gradebook = part;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void upgrade(final String ID, final NetworkCallback<ArrayList<Grade>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101504, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
super.get(String.format("https://kvv.imp.fu-berlin.de/direct/gradebook/site/%s.json", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101501, 403, "No gradebook retrieved!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ArrayList<Grade> gradebook = new ArrayList<>();
|
||||||
|
JSONArray sites;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
sites = json.getJSONArray("assignments");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorCallback.onError(new NetworkError(101502, 403, "Cannot parse gradebook!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
|
try {
|
||||||
|
JSONObject site = sites.getJSONObject(i);
|
||||||
|
double grade = site.optDouble("grade", 0);
|
||||||
|
String itemName = site.optString("itemName", null);
|
||||||
|
double maxPoints = site.optDouble("points", -1);
|
||||||
|
|
||||||
|
gradebook.add(0, new Grade(itemName, grade, maxPoints));
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.e(new NetworkError(101505, 403, "Cannot parse gradebook!"));
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
e.printStackTrace();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
callback.onResponse(gradebook);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101503, error.networkResponse.statusCode, "Cannot get gradebook!")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,201 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.Nullable;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.HashSet;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
import java.util.regex.MatchResult;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Semester;
|
||||||
|
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||||
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
import static de.sebse.fuplanner.services.KVV.PartModules.RETRY_COUNT;
|
||||||
|
|
||||||
|
public class ModulesList extends HTTPService {
|
||||||
|
private final Login mLogin;
|
||||||
|
private final KVVListener mListener;
|
||||||
|
@Nullable private Modules mModules;
|
||||||
|
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||||
|
|
||||||
|
ModulesList(Login login, KVVListener listener, Context context) {
|
||||||
|
super(context);
|
||||||
|
this.mLogin = login;
|
||||||
|
this.mListener = listener;
|
||||||
|
restore();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public String getUsername() {
|
||||||
|
if (mModules != null) {
|
||||||
|
return mModules.getUsername();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback) {
|
||||||
|
find(moduleID, moduleNetworkCallback, errorCallback, RETRY_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback, int retries) {
|
||||||
|
if (mModules != null && mLogin.getLoginToken() != null && !mLogin.getLoginToken().isSameUser(mModules.getUsername()))
|
||||||
|
delete();
|
||||||
|
if (retries < 0) {
|
||||||
|
errorCallback.onError(new NetworkError(101107, -1, "Too many retries!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (this.mModules != null) {
|
||||||
|
Modules.Module module = this.mModules.get(moduleID);
|
||||||
|
if (module != null) {
|
||||||
|
moduleNetworkCallback.onResponse(module);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
recv(success -> find(moduleID, moduleNetworkCallback, errorCallback, retries - 1), errorCallback, true, RETRY_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
void store() {
|
||||||
|
if (this.mModules != null) {
|
||||||
|
try {
|
||||||
|
this.mModules.save(getContext());
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void restore() {
|
||||||
|
try {
|
||||||
|
this.mModules = Modules.load(getContext());
|
||||||
|
} catch (FileNotFoundException ignored) {
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void delete() {
|
||||||
|
if (this.mModules != null) {
|
||||||
|
this.mModules.delete(getContext());
|
||||||
|
this.mModules = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recv(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
recv(callback, errorCallback, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recv(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||||
|
recv(callback, errorCallback, forceRefresh, RETRY_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void recv(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, final int retries) {
|
||||||
|
if (mModules != null && mLogin.getLoginToken() != null && !mLogin.getLoginToken().isSameUser(mModules.getUsername()))
|
||||||
|
delete();
|
||||||
|
mQueue.add(() -> {
|
||||||
|
if (this.mModules != null && !forceRefresh) {
|
||||||
|
callback.onResponse(this.mModules);
|
||||||
|
mQueue.next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.upgrade(success -> {
|
||||||
|
if (this.mModules == null)
|
||||||
|
this.mModules = success;
|
||||||
|
else
|
||||||
|
this.mModules.updateList(success);
|
||||||
|
mListener.onModuleListChange();
|
||||||
|
store();
|
||||||
|
callback.onResponse(this.mModules);
|
||||||
|
mQueue.next();
|
||||||
|
}, error -> {
|
||||||
|
if (retries > 0 && (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)) {
|
||||||
|
mLogin.refreshLogin(success -> {
|
||||||
|
recv(callback, errorCallback, forceRefresh, retries-1);
|
||||||
|
mQueue.next();
|
||||||
|
}, error1 -> {
|
||||||
|
errorCallback.onError(error1);
|
||||||
|
mQueue.next();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errorCallback.onError(error);
|
||||||
|
mQueue.next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void upgrade(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101105, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get("https://kvv.imp.fu-berlin.de/direct/site.json", mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101101, 403, "No module list retrieved!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Modules modules = new Modules(mLogin.getLoginToken().getUsername());
|
||||||
|
JSONArray sites;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
sites = json.getJSONArray("site_collection");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorCallback.onError(new NetworkError(101102, 403, "Cannot parse module list!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
|
try {
|
||||||
|
JSONObject site = sites.getJSONObject(i);
|
||||||
|
String semester_string = site.getJSONObject("props").optString("term_eid", null);
|
||||||
|
Semester semester = new Semester(semester_string);
|
||||||
|
HashSet<String> lvNumbers = new HashSet<>();
|
||||||
|
String kvv_lvnumbers = site.getJSONObject("props").optString("kvv_lvnumbers", null);
|
||||||
|
if (kvv_lvnumbers != null) for (MatchResult matchResult : Regex.allMatches("[0-9]+", kvv_lvnumbers)) {
|
||||||
|
lvNumbers.add(matchResult.group());
|
||||||
|
}
|
||||||
|
String title = site.getString("entityTitle");
|
||||||
|
LinkedHashSet<Lecturer> lecturers = new LinkedHashSet<>();
|
||||||
|
String kvv_lecturers = site.getJSONObject("props").optString("kvv_lecturers", null);
|
||||||
|
if (kvv_lecturers != null) for (String lecturer : kvv_lecturers.split("#")) {
|
||||||
|
if (lecturer.length() > 2)
|
||||||
|
lecturers.add(new Lecturer(lecturer));
|
||||||
|
}
|
||||||
|
String type = site.getJSONObject("props").optString("kvv_coursetype", null);
|
||||||
|
String description = site.optString("description", "");
|
||||||
|
description = String.valueOf(PartModules.fromHtml(description));
|
||||||
|
String id = site.getString("id");
|
||||||
|
modules.addModule(semester, lvNumbers, title, lecturers, type, description, id);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.e(new NetworkError(101103, 403, "Cannot parse module list!"));
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
log.e(new NetworkError(101106, 403, "Cannot parse module list!"));
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Empty module *may be* because token is invalid -> check
|
||||||
|
if (modules.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(modules), errorCallback);
|
||||||
|
else
|
||||||
|
callback.onResponse(modules);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101104, error.networkResponse.statusCode, "Cannot get module list!")));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,220 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Environment;
|
||||||
|
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Resource;
|
||||||
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
||||||
|
|
||||||
|
ModulesResources(Login login, ModulesList list, Context context) {
|
||||||
|
super(login, list, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected ArrayList<Resource> getPart(Modules.Module module) {
|
||||||
|
return module.resources;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected boolean setPart(Modules.Module module, ArrayList<Resource> part) {
|
||||||
|
boolean changed = module.resources == null || module.resources.hashCode() != part.hashCode();
|
||||||
|
module.resources = part;
|
||||||
|
return changed;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void upgrade(final String ID, final NetworkCallback<ArrayList<Resource>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get(String.format("https://kvv.imp.fu-berlin.de/direct/content/site/%s.json", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
String body = response.getParsed();
|
||||||
|
if (body == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101601, 403, "No resources retrieved!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ArrayList<Resource> resources = new ArrayList<>();
|
||||||
|
JSONArray sites;
|
||||||
|
try {
|
||||||
|
JSONObject json = new JSONObject(body);
|
||||||
|
sites = json.getJSONArray("content_collection");
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
errorCallback.onError(new NetworkError(101602, 403, "Cannot parse resources!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
|
try {
|
||||||
|
JSONObject site = sites.getJSONObject(i);
|
||||||
|
String author = site.getString("author");
|
||||||
|
String title = site.getString("title");
|
||||||
|
long modifiedDate = site.getLong("modifiedDate");
|
||||||
|
String url = site.getString("url");
|
||||||
|
boolean visible = site.getBoolean("visible");
|
||||||
|
String type = site.getString("type");
|
||||||
|
String container = site.getString("container");
|
||||||
|
if (type.equals("collection")){
|
||||||
|
resources.add(new Resource.Folder(author, title, modifiedDate, url, visible, container));
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
resources.add(new Resource.File(author, title, modifiedDate, url, visible, container, type));
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.e(new NetworkError(101605, 403, "Cannot parse resources!"));
|
||||||
|
e.printStackTrace();
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
ArrayList<Resource> root = new ArrayList<>();
|
||||||
|
// Generate folder structure
|
||||||
|
for (Resource res: resources) {
|
||||||
|
if (!res.getContainer().equals("/content/group/")) {
|
||||||
|
if (res.getContainer().equals("/content/group/"+ID+"/")){
|
||||||
|
// if file in root folder
|
||||||
|
root.add(res);
|
||||||
|
} else {
|
||||||
|
// in sub folder
|
||||||
|
for (Resource res2: resources) {
|
||||||
|
if (res2.getUrl().endsWith(res.getContainer()) && res2 instanceof Resource.Folder) {
|
||||||
|
// Append File/Folder to list
|
||||||
|
((Resource.Folder) res2).add(res);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Empty resources *may be* because token is invalid -> check
|
||||||
|
if (resources.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(root), errorCallback);
|
||||||
|
else
|
||||||
|
callback.onResponse(root);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void file(final String filename, final String url, final String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||||
|
file(filename, url, modulename, callback, errorCallback, forceRefresh, RETRY_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void file(final String filename, final String url, final String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, int retries) {
|
||||||
|
if (isExternalStorageReadable()){
|
||||||
|
File f = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
Environment.DIRECTORY_DOWNLOADS)+"/"+modulename+"/"+filename);
|
||||||
|
// check if file already downloaded -> do not download again
|
||||||
|
if (f.exists() && !forceRefresh) {
|
||||||
|
callback.onResponse(f.getPath());
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fileUpgrade(filename, url , modulename, callback, error -> {
|
||||||
|
if (retries >= 0 && (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)) {
|
||||||
|
mLogin.refreshLogin(success -> {
|
||||||
|
file(filename, url, modulename, callback, errorCallback, forceRefresh, retries-1);
|
||||||
|
}, errorCallback);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errorCallback.onError(error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private void fileUpgrade(String filename, String url, String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
get(url, mLogin.getLoginToken().getCookies(), response -> {
|
||||||
|
if (Regex.has("\\.[Uu][Rr][Ll]$", url)){
|
||||||
|
// Return redirected URL
|
||||||
|
String path = response.getHeaders().get("Location");
|
||||||
|
if (path == null){
|
||||||
|
path = "";
|
||||||
|
}
|
||||||
|
callback.onResponse(path);
|
||||||
|
} else if (response.getBytes() == null) {
|
||||||
|
errorCallback.onError(new NetworkError(101705, 403, "Cannot get file!"));
|
||||||
|
} else if (isExternalStorageWritable()) {
|
||||||
|
String path = saveFileInDownloads(filename, response.getBytes(), modulename);
|
||||||
|
callback.onResponse(path);
|
||||||
|
} else {
|
||||||
|
errorCallback.onError(new NetworkError(101704, 403, "External storage not writable!"));
|
||||||
|
}
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(101702, error.networkResponse.statusCode, "Cannot get file!")));
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/* Checks if external storage is available for read and write */
|
||||||
|
private boolean isExternalStorageWritable() {
|
||||||
|
String state = Environment.getExternalStorageState();
|
||||||
|
if (Environment.MEDIA_MOUNTED.equals(state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
log.w("File system: Writing not possible!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Checks if external storage is available to at least read */
|
||||||
|
private boolean isExternalStorageReadable() {
|
||||||
|
String state = Environment.getExternalStorageState();
|
||||||
|
if (Environment.MEDIA_MOUNTED.equals(state) ||
|
||||||
|
Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
log.w("File system: Reading not possible!");
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
private String saveFileInDownloads(String filename, byte[] data, String moduleName) {
|
||||||
|
// Saves file in folder: DOWNLOADS/moduleName
|
||||||
|
File folder = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
||||||
|
if (!folder.mkdir()) {
|
||||||
|
log.w( "Directory not created");
|
||||||
|
}
|
||||||
|
String path = "";
|
||||||
|
try {
|
||||||
|
// TODO check if enough storage space is available
|
||||||
|
FileOutputStream out = new FileOutputStream(folder.getPath()+"/"+filename);
|
||||||
|
out.write(data);
|
||||||
|
out.close();
|
||||||
|
path = folder.getPath()+"/"+filename;
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.w("File not saved!");
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
}
|
||||||
34
app/src/main/java/de/sebse/fuplanner/services/KVV/Part.java
Normal file
34
app/src/main/java/de/sebse/fuplanner/services/KVV/Part.java
Normal file
@@ -0,0 +1,34 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public abstract class Part<T> extends HTTPService {
|
||||||
|
static final int RETRY_COUNT = 1;
|
||||||
|
protected final Login mLogin;
|
||||||
|
protected final ModulesList mList;
|
||||||
|
|
||||||
|
Part(Login login, ModulesList list, Context context) {
|
||||||
|
super(context);
|
||||||
|
this.mLogin = login;
|
||||||
|
this.mList = list;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recv(final String moduleID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
recv(moduleID, callback, errorCallback, false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recv(final String moduleID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh) {
|
||||||
|
mList.find(moduleID, success -> recv(success, callback, errorCallback, forceRefresh), errorCallback);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void recv(final Modules.Module module, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh) {
|
||||||
|
recv(module, callback, errorCallback, forceRefresh, RETRY_COUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
abstract protected void recv(final Modules.Module module, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh, final int retries);
|
||||||
|
}
|
||||||
@@ -0,0 +1,65 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.os.Build;
|
||||||
|
import android.text.Html;
|
||||||
|
import android.text.Spanned;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||||
|
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
abstract class PartModules<T> extends Part<Modules.Module> {
|
||||||
|
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||||
|
|
||||||
|
PartModules(Login login, ModulesList list, Context context) {
|
||||||
|
super(login, list, context);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void recv(final Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh, final int retries) {
|
||||||
|
mQueue.add(() -> {
|
||||||
|
if (getPart(module) != null && !forceRefresh) {
|
||||||
|
callback.onResponse(module);
|
||||||
|
mQueue.next();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
upgrade(module.getID(), success -> {
|
||||||
|
if (setPart(module, success)) {
|
||||||
|
this.mList.store();
|
||||||
|
}
|
||||||
|
callback.onResponse(module);
|
||||||
|
mQueue.next();
|
||||||
|
}, error -> {
|
||||||
|
if (retries >= 0 && (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)) {
|
||||||
|
mLogin.refreshLogin(success -> {
|
||||||
|
recv(module, callback, errorCallback, forceRefresh, retries-1);
|
||||||
|
mQueue.next();
|
||||||
|
}, error1 -> {
|
||||||
|
errorCallback.onError(error1);
|
||||||
|
mQueue.next();
|
||||||
|
});
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
errorCallback.onError(error);
|
||||||
|
mQueue.next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@SuppressWarnings("deprecation")
|
||||||
|
static Spanned fromHtml(String html){
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
|
||||||
|
return Html.fromHtml(html, Html.FROM_HTML_MODE_LEGACY);
|
||||||
|
} else {
|
||||||
|
return Html.fromHtml(html);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract T getPart(Modules.Module module);
|
||||||
|
|
||||||
|
protected abstract boolean setPart(Modules.Module module, T part);
|
||||||
|
|
||||||
|
protected abstract void upgrade(final String ID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback);
|
||||||
|
}
|
||||||
@@ -1,38 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.KVV;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
|
||||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
|
||||||
|
|
||||||
final class TestLogin extends HTTPService {
|
|
||||||
|
|
||||||
private TestLogin(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
static void testLogin(Context context, LoginToken loginToken, NetworkCallback<LoginToken> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
new TestLogin(context).get(String.format("https://kvv.imp.fu-berlin.de/direct/profile/%s.json", loginToken.getUsername()), loginToken.getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100202, 403, "Testing login failed!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
String displayName = json.getString("displayName");
|
|
||||||
String email = json.getString("email");
|
|
||||||
loginToken.setAdditionals(displayName, email);
|
|
||||||
callback.onResponse(loginToken);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
errorCallback.onError(new NetworkError(100201, 403, "Cannot parse profile!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100200, error.networkResponse.statusCode, "Testing login failed!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -54,4 +56,9 @@ public class Announcement implements Serializable {
|
|||||||
"\nCreated on: "+getCreatedOn()+
|
"\nCreated on: "+getCreatedOn()+
|
||||||
"\nURLs: "+getUrls().toString();
|
"\nURLs: "+getUrls().toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getId(), getBody(), getCreatedBy(), getCreatedOn(), getTitle(), getUrls());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -15,7 +17,6 @@ public class Assignment implements Serializable {
|
|||||||
this.title = title;
|
this.title = title;
|
||||||
this.dueTime = dueTime;
|
this.dueTime = dueTime;
|
||||||
this.urls = urls;
|
this.urls = urls;
|
||||||
//this.grade = grade;
|
|
||||||
this.instructions = instructions;
|
this.instructions = instructions;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,4 +51,9 @@ public class Assignment implements Serializable {
|
|||||||
"\nDue date: "+getDueDate()+
|
"\nDue date: "+getDueDate()+
|
||||||
"\nInstructions: "+getInstructions().substring(0, Math.min(getInstructions().length(), 100));
|
"\nInstructions: "+getInstructions().substring(0, Math.min(getInstructions().length(), 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getId(), getDueDate(), getInstructions(), getTitle(), getUrls());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.nio.charset.StandardCharsets;
|
import java.nio.charset.StandardCharsets;
|
||||||
import java.security.MessageDigest;
|
import java.security.MessageDigest;
|
||||||
@@ -111,4 +113,9 @@ public class Event implements Serializable {
|
|||||||
"\nStart Date: "+getStartDate()+
|
"\nStart Date: "+getStartDate()+
|
||||||
"\nEnd date: "+getEndDate();
|
"\nEnd date: "+getEndDate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getId(), getType(), getStartDate(), getEndDate(), getTitle(), getLocation());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
public class Gradebook implements Serializable {
|
public class Grade implements Serializable {
|
||||||
private final String itemName;
|
private final String itemName;
|
||||||
private final double grade;
|
private final double grade;
|
||||||
private final double maxPoints;
|
private final double maxPoints;
|
||||||
|
|
||||||
public Gradebook(String itemName, double points, double maxPoints) {
|
public Grade(String itemName, double points, double maxPoints) {
|
||||||
this.itemName = itemName;
|
this.itemName = itemName;
|
||||||
this.grade = points;
|
this.grade = points;
|
||||||
this.maxPoints = maxPoints;
|
this.maxPoints = maxPoints;
|
||||||
@@ -31,4 +33,9 @@ public class Gradebook implements Serializable {
|
|||||||
"\nPoints: "+ getPoints()+
|
"\nPoints: "+ getPoints()+
|
||||||
"\nMax points: "+getMaxPoints();
|
"\nMax points: "+getMaxPoints();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getItemName(), getPoints(), getMaxPoints());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -8,9 +8,10 @@ public class Lecturer implements Serializable {
|
|||||||
private final String firstName;
|
private final String firstName;
|
||||||
private final String surname;
|
private final String surname;
|
||||||
private final String mail;
|
private final String mail;
|
||||||
|
private final boolean isResponsible;
|
||||||
|
|
||||||
public Lecturer(String parsableString) throws NoSuchFieldException {
|
public Lecturer(String parsableString) throws NoSuchFieldException {
|
||||||
Pattern pattern = Pattern.compile("([^|]*)\\|([^|]*)\\|([^|]*)\\|\\|", Pattern.DOTALL);
|
Pattern pattern = Pattern.compile("([^|]*)\\|([^|]*)\\|([^|]*)\\|\\|([^|]*)", Pattern.DOTALL);
|
||||||
Matcher matcher = pattern.matcher(parsableString);
|
Matcher matcher = pattern.matcher(parsableString);
|
||||||
if (!matcher.find()) {
|
if (!matcher.find()) {
|
||||||
throw new NoSuchFieldException();
|
throw new NoSuchFieldException();
|
||||||
@@ -18,20 +19,33 @@ public class Lecturer implements Serializable {
|
|||||||
this.firstName = matcher.group(1);
|
this.firstName = matcher.group(1);
|
||||||
this.surname = matcher.group(2);
|
this.surname = matcher.group(2);
|
||||||
this.mail = matcher.group(3);
|
this.mail = matcher.group(3);
|
||||||
|
this.isResponsible = matcher.group(4).equals("true");
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getFirstName() {
|
public String getFirstName() {
|
||||||
return firstName;
|
return firstName;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getSurname() {
|
public String getSurname() {
|
||||||
return surname;
|
return surname;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getMail() {
|
public String getMail() {
|
||||||
return mail;
|
return mail;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isResponsible() {
|
||||||
|
return isResponsible;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return getFirstName() + " " + getSurname();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getNameShort() {
|
||||||
|
return getFirstName().substring(0, 1) + ". " + getSurname();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "First name: "+ getFirstName()+
|
return "First name: "+ getFirstName()+
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package de.sebse.fuplanner.services.KVV.types;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.ObjectInputStream;
|
import java.io.ObjectInputStream;
|
||||||
@@ -17,16 +18,14 @@ import androidx.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class LoginToken implements Serializable {
|
public class LoginToken implements Serializable {
|
||||||
private static final long EASY_LOGIN_TIME_MILLIS = 1000 * 60 * 60 * 300;
|
|
||||||
private static final String FILE_NAME = "LoginTokenSaving";
|
private static final String FILE_NAME = "LoginTokenSaving";
|
||||||
|
|
||||||
private final String username;
|
private final String username;
|
||||||
private final String shibsessionKey;
|
private final String shibsessionKey;
|
||||||
private final String shibsessionName;
|
private final String shibsessionName;
|
||||||
private final String JSESSIONID;
|
private final String JSESSIONID;
|
||||||
private String fullName;
|
@Nullable private String fullName;
|
||||||
private String email;
|
@Nullable private String email;
|
||||||
private long saveDate = 0;
|
|
||||||
|
|
||||||
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
||||||
this.username = username;
|
this.username = username;
|
||||||
@@ -37,17 +36,23 @@ public class LoginToken implements Serializable {
|
|||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
public static LoginToken load(Context context) throws IOException, ClassNotFoundException {
|
public static LoginToken load(Context context) throws IOException, ClassNotFoundException {
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
FileInputStream fis;
|
||||||
|
try {
|
||||||
|
fis = context.openFileInput(FILE_NAME);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
ObjectInputStream is = new ObjectInputStream(fis);
|
||||||
LoginToken loginToken = (LoginToken) is.readObject();
|
Object readObject = is.readObject();
|
||||||
|
if (!(readObject instanceof LoginToken))
|
||||||
|
return null;
|
||||||
|
LoginToken loginToken = (LoginToken) readObject;
|
||||||
is.close();
|
is.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
loginToken = (loginToken.saveDate > (System.currentTimeMillis() - EASY_LOGIN_TIME_MILLIS)) ? loginToken : null;
|
|
||||||
return loginToken;
|
return loginToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
public void save(Context context) throws IOException {
|
||||||
saveDate = System.currentTimeMillis();
|
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
ObjectOutputStream os = new ObjectOutputStream(fos);
|
||||||
os.writeObject(this);
|
os.writeObject(this);
|
||||||
@@ -96,8 +101,8 @@ public class LoginToken implements Serializable {
|
|||||||
return cookies;
|
return cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isSameUser(LoginToken token) {
|
public boolean isSameUser(String username) {
|
||||||
return token != null && this.getUsername().equals(token.getUsername());
|
return this.getUsername().equals(username);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ package de.sebse.fuplanner.services.KVV.types;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.FileOutputStream;
|
import java.io.FileOutputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@@ -11,6 +13,7 @@ import java.io.Serializable;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
import java.util.LinkedHashSet;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -21,16 +24,16 @@ import androidx.annotation.Nullable;
|
|||||||
|
|
||||||
public class Modules implements Iterable<Modules.Module>, Serializable {
|
public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||||
private SortedListModule list;
|
private SortedListModule list;
|
||||||
private final LoginToken token;
|
private final String mUsername;
|
||||||
//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";
|
||||||
|
|
||||||
public Modules(LoginToken loginToken) {
|
public Modules(String username) {
|
||||||
this.token = loginToken;
|
this.mUsername = username;
|
||||||
this.list = new SortedListModule();
|
this.list = new SortedListModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addModule(String semester, HashSet<String> lvNumber, String title, HashSet<Lecturer> lecturer, String type, String description, String ID) {
|
public void addModule(@Nullable Semester semester, HashSet<String> lvNumber, String title, LinkedHashSet<Lecturer> lecturer, String type, String description, String ID) {
|
||||||
Module m = new Module(semester, lvNumber, title, lecturer, type, description, ID);
|
Module m = new Module(semester, lvNumber, title, lecturer, type, description, ID);
|
||||||
this.list.add(m);
|
this.list.add(m);
|
||||||
}
|
}
|
||||||
@@ -66,7 +69,10 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
public static Modules load(Context context) throws IOException, ClassNotFoundException {
|
public static Modules load(Context context) throws IOException, ClassNotFoundException {
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
ObjectInputStream is = new ObjectInputStream(fis);
|
||||||
Modules modules = (Modules) is.readObject();
|
Object readObject = is.readObject();
|
||||||
|
if (!(readObject instanceof Modules))
|
||||||
|
return null;
|
||||||
|
Modules modules = (Modules) readObject;
|
||||||
is.close();
|
is.close();
|
||||||
fis.close();
|
fis.close();
|
||||||
return modules;
|
return modules;
|
||||||
@@ -84,8 +90,8 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
context.deleteFile(FILE_NAME);
|
context.deleteFile(FILE_NAME);
|
||||||
}
|
}
|
||||||
|
|
||||||
public LoginToken getToken() {
|
public String getUsername() {
|
||||||
return token;
|
return mUsername;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateList(Modules modules) {
|
public void updateList(Modules modules) {
|
||||||
@@ -104,29 +110,25 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Module implements Serializable {
|
public class Module implements Serializable {
|
||||||
public final String semester;
|
@Nullable public final Semester semester;
|
||||||
final HashSet<String> lvNumber;
|
@NotNull final HashSet<String> lvNumber;
|
||||||
public final String title;
|
@NotNull public final String title;
|
||||||
final HashSet<Lecturer> lecturer;
|
@NotNull
|
||||||
public final String type;
|
public final ArrayList<Lecturer> lecturer;
|
||||||
public final String description;
|
@Nullable public final String type;
|
||||||
private final String ID;
|
@Nullable public final String description;
|
||||||
|
@NotNull private final String ID;
|
||||||
@Nullable public ArrayList<Announcement> announcements;
|
@Nullable public ArrayList<Announcement> announcements;
|
||||||
@Nullable public AssignmentList assignments;
|
@Nullable public AssignmentList assignments;
|
||||||
@Nullable public EventList events;
|
@Nullable public EventList events;
|
||||||
@Nullable public ArrayList<Gradebook> gradebook;
|
@Nullable public ArrayList<Grade> gradebook;
|
||||||
@Nullable public ArrayList<Resource> resources;
|
@Nullable public ArrayList<Resource> resources;
|
||||||
|
|
||||||
/*private Module() {
|
|
||||||
this(null, null, null, null, null);
|
|
||||||
throw new AssertionError("Do not use this constructor!");
|
|
||||||
}*/
|
|
||||||
|
|
||||||
public float getGradebookPercent(){
|
public float getGradebookPercent(){
|
||||||
float maxPoint = 0;
|
float maxPoint = 0;
|
||||||
float userPoint = 0;
|
float userPoint = 0;
|
||||||
if (gradebook != null) {
|
if (gradebook != null) {
|
||||||
for (Gradebook g : gradebook){
|
for (Grade g : gradebook){
|
||||||
maxPoint += g.getMaxPoints();
|
maxPoint += g.getMaxPoints();
|
||||||
userPoint += g.getPoints();
|
userPoint += g.getPoints();
|
||||||
}
|
}
|
||||||
@@ -136,20 +138,20 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
return userPoint/maxPoint;
|
return userPoint/maxPoint;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Module(String semester, HashSet<String> lvNumber, String title, HashSet<Lecturer> lecturer, String type, String description, String ID) {
|
private Module(@Nullable Semester semester, @NotNull HashSet<String> lvNumber, @NotNull String title, @NotNull LinkedHashSet<Lecturer> lecturer, @Nullable String type, @Nullable String description, @NotNull String ID) {
|
||||||
semester = semester.replace("SS", "S");
|
|
||||||
semester = semester.replaceAll("[0-9]{2}([0-9]{2})", "$1");
|
|
||||||
title = title.replaceAll("(.*?) (S[0-9]{2}|W[0-9/]{5})", "$1");
|
title = title.replaceAll("(.*?) (S[0-9]{2}|W[0-9/]{5})", "$1");
|
||||||
|
|
||||||
this.semester = semester;
|
this.semester = semester;
|
||||||
this.lvNumber = lvNumber;
|
this.lvNumber = lvNumber;
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.lecturer = lecturer;
|
this.lecturer = new ArrayList<>(lecturer);
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
public String getID() {
|
public String getID() {
|
||||||
return ID;
|
return ID;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,7 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
@@ -54,6 +56,11 @@ public abstract class Resource implements Serializable {
|
|||||||
|
|
||||||
public abstract TreeNode getTreeNode();
|
public abstract TreeNode getTreeNode();
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
||||||
|
}
|
||||||
|
|
||||||
public static class File extends Resource implements LayoutItemType {
|
public static class File extends Resource implements LayoutItemType {
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,55 @@
|
|||||||
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
|
||||||
|
public class Semester implements Serializable {
|
||||||
|
public static final int SEM_WS = 1;
|
||||||
|
public static final int SEM_SS = 2;
|
||||||
|
private int type;
|
||||||
|
private int year;
|
||||||
|
|
||||||
|
public Semester(int type, int year) {
|
||||||
|
this.type = type;
|
||||||
|
this.year = year;
|
||||||
|
}
|
||||||
|
|
||||||
|
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 year = Regex.regex("^(SS|WS) ([0-9]{2})", semester_string, 2);
|
||||||
|
this.type = type.equals("SS") ? SEM_SS : SEM_WS;
|
||||||
|
this.year = Integer.parseInt(year);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getYear() {
|
||||||
|
return year;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(@Nullable Object obj) {
|
||||||
|
if (obj instanceof Semester) {
|
||||||
|
Semester other = (Semester) obj;
|
||||||
|
return other.type == type && other.year == year;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,9 +1,9 @@
|
|||||||
package de.sebse.fuplanner.services.KVV.types;
|
package de.sebse.fuplanner.services.KVV.types;
|
||||||
|
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.SortedList;
|
import de.sebse.fuplanner.tools.SortedList;
|
||||||
|
|
||||||
public class SortedListModule extends SortedList<Modules.Module, String, String> {
|
public class SortedListModule extends SortedList<Modules.Module, String, Semester> {
|
||||||
private static final int LARGER = 1;
|
private static final int LARGER = 1;
|
||||||
private static final int EQUAL = 0;
|
private static final int EQUAL = 0;
|
||||||
private static final int SMALLER = -1;
|
private static final int SMALLER = -1;
|
||||||
@@ -27,7 +27,7 @@ public class SortedListModule extends SortedList<Modules.Module, String, String>
|
|||||||
super.add(e);
|
super.add(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLatestSemester() {
|
public Semester getLatestSemester() {
|
||||||
if (size() > 0)
|
if (size() > 0)
|
||||||
//noinspection ConstantConditions
|
//noinspection ConstantConditions
|
||||||
return this.get(0).semester;
|
return this.get(0).semester;
|
||||||
@@ -35,7 +35,7 @@ public class SortedListModule extends SortedList<Modules.Module, String, String>
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static int compareSemester(String a, String b) throws NoSuchFieldException {
|
private static int compareSemester(@Nullable Semester a, @Nullable Semester b) throws NoSuchFieldException {
|
||||||
if (a == null && b == null)
|
if (a == null && b == null)
|
||||||
return EQUAL;
|
return EQUAL;
|
||||||
if (a == null)
|
if (a == null)
|
||||||
@@ -43,17 +43,13 @@ public class SortedListModule extends SortedList<Modules.Module, String, String>
|
|||||||
if (b == null)
|
if (b == null)
|
||||||
return LARGER;
|
return LARGER;
|
||||||
|
|
||||||
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));
|
|
||||||
|
|
||||||
if (s1year == s2year) {
|
if (a.getYear() == b.getYear()) {
|
||||||
if (s1type.equals(s2type))
|
if (a.getType() == b.getType())
|
||||||
return EQUAL;
|
return EQUAL;
|
||||||
return s1type.equals("S") ? SMALLER : LARGER;
|
return a.getType() == Semester.SEM_SS ? SMALLER : LARGER;
|
||||||
}
|
}
|
||||||
return s1year < s2year ? SMALLER : LARGER;
|
return a.getYear() < b.getYear() ? SMALLER : LARGER;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -62,7 +58,7 @@ public class SortedListModule extends SortedList<Modules.Module, String, String>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean hasFilter(Modules.Module o1, String filter) {
|
public boolean hasFilter(Modules.Module o1, Semester filter) {
|
||||||
return o1.semester.equals(filter);
|
return o1.semester != null && o1.semester.equals(filter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
package de.sebse.fuplanner.services.KVV;
|
package de.sebse.fuplanner.services.KVV.ui;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
@@ -24,10 +24,7 @@ import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
|||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
import static android.content.Intent.normalizeMimeType;
|
|
||||||
import static androidx.core.app.ActivityCompat.startActivityForResult;
|
|
||||||
import static androidx.core.content.ContextCompat.checkSelfPermission;
|
import static androidx.core.content.ContextCompat.checkSelfPermission;
|
||||||
import static androidx.core.content.ContextCompat.startActivity;
|
|
||||||
|
|
||||||
public class Download {
|
public class Download {
|
||||||
|
|
||||||
@@ -35,7 +32,6 @@ public class Download {
|
|||||||
private final ActivityInterface activityInterface;
|
private final ActivityInterface activityInterface;
|
||||||
private RequestedDownload requestedDownload;
|
private RequestedDownload requestedDownload;
|
||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
static final int REQUEST_IMAGE_OPEN = 1;
|
|
||||||
|
|
||||||
|
|
||||||
public Download(ContextInterface contextInterface, ActivityInterface activityInterface) {
|
public Download(ContextInterface contextInterface, ActivityInterface activityInterface) {
|
||||||
@@ -48,19 +44,20 @@ public class Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void openDownloadDialog(Resource.File file, String folderName) {
|
public void openDownloadDialog(Resource.File file, String folderName) {
|
||||||
if (contextInterface.get() == null)
|
Context context = contextInterface.get();
|
||||||
|
if (context == null)
|
||||||
return;
|
return;
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(contextInterface.get());
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
||||||
File f = new File(Environment.getExternalStoragePublicDirectory(
|
File f = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
Environment.DIRECTORY_DOWNLOADS)+"/"+folderName+"/"+file.getTitle());
|
Environment.DIRECTORY_DOWNLOADS)+"/"+folderName+"/"+file.getTitle());
|
||||||
Resources resources = contextInterface.get().getResources();
|
Resources resources = context.getResources();
|
||||||
String message = "";
|
String message = "";
|
||||||
if (file.getAuthor() != null && !file.getAuthor().isEmpty())
|
if (file.getAuthor() != null && !file.getAuthor().isEmpty())
|
||||||
message += resources.getString(R.string.creator_name, file.getAuthor());
|
message += resources.getString(R.string.creator_name, file.getAuthor());
|
||||||
if (file.getModifiedDate() != 0) {
|
if (file.getModifiedDate() != 0) {
|
||||||
if (!message.isEmpty())
|
if (!message.isEmpty())
|
||||||
message += "\n";
|
message += "\n";
|
||||||
message += resources.getString(R.string.last_modified_on, UtilsDate.getModifiedDateTime(contextInterface.get(), file.getModifiedDate()));
|
message += resources.getString(R.string.last_modified_on, UtilsDate.getModifiedDateTime(context, file.getModifiedDate()));
|
||||||
}
|
}
|
||||||
|
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
@@ -82,40 +79,46 @@ public class Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void download(Resource.File file, String folderName, boolean downloadNew){
|
private void download(Resource.File file, String folderName, boolean downloadNew){
|
||||||
if (activityInterface.get() == null) {
|
MainActivity activity = activityInterface.get();
|
||||||
|
if (activity == null) {
|
||||||
showDownloadError();
|
showDownloadError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (checkSelfPermission(activityInterface.get(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
if (checkSelfPermission(activity, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED) {
|
||||||
// Access granted
|
// Access granted
|
||||||
downloadOrOpen(file, folderName, downloadNew);
|
downloadOrOpen(file, folderName, downloadNew);
|
||||||
} else {
|
} else {
|
||||||
this.requestedDownload = new RequestedDownload(file, folderName, downloadNew);
|
this.requestedDownload = new RequestedDownload(file, folderName, downloadNew);
|
||||||
ActivityCompat.requestPermissions(activityInterface.get(),
|
ActivityCompat.requestPermissions(activity,
|
||||||
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
new String[]{Manifest.permission.WRITE_EXTERNAL_STORAGE},
|
||||||
1);
|
1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void downloadOrOpen(Resource.File file, String folderName, boolean downloadNew) {
|
private void downloadOrOpen(Resource.File file, String folderName, boolean downloadNew) {
|
||||||
KVV kvv = activityInterface.get().getKVV();
|
if (!isExternalStorageWritable()) {
|
||||||
if(isExternalStorageWritable()){
|
return;
|
||||||
kvv.getResourceFile(success1 -> {
|
}
|
||||||
// Downloading file failed
|
MainActivity activity = activityInterface.get();
|
||||||
if (success1.equals("")){
|
if (activity == null) {
|
||||||
showDownloadError();
|
showDownloadError();
|
||||||
}else {
|
return;
|
||||||
if (Regex.has("^http", success1)){
|
}
|
||||||
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(success1));
|
activity.getKVV().modules().resources().file(file.getTitle(), file.getUrl(), folderName, success -> {
|
||||||
contextInterface.get().startActivity(intent);
|
Context context = contextInterface.get();
|
||||||
|
if (success.equals("")) {
|
||||||
|
showDownloadError();
|
||||||
|
} else {
|
||||||
|
if (Regex.has("^http", success)){
|
||||||
|
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse(success));
|
||||||
|
context.startActivity(intent);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
fileOpen(new File(success1));
|
fileOpen(new File(success));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}, log::e, file.getTitle(), file.getUrl(), folderName, downloadNew);
|
}, log::e, downloadNew);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadError() {
|
private void showDownloadError() {
|
||||||
@@ -186,7 +189,6 @@ public class Download {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fileOpen(File url){
|
private void fileOpen(File url){
|
||||||
|
|
||||||
Uri uri = FileProvider.getUriForFile(contextInterface.get(), contextInterface.get().getApplicationContext().getPackageName() + ".my.provider", url);
|
Uri uri = FileProvider.getUriForFile(contextInterface.get(), contextInterface.get().getApplicationContext().getPackageName() + ".my.provider", url);
|
||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
@@ -235,18 +237,12 @@ public class Download {
|
|||||||
intent.setDataAndType(uri, "video/*");
|
intent.setDataAndType(uri, "video/*");
|
||||||
} else {
|
} else {
|
||||||
//if you want you can also define the intent type for any other file
|
//if you want you can also define the intent type for any other file
|
||||||
|
|
||||||
//additionally use else clause below, to manage other unknown extensions
|
//additionally use else clause below, to manage other unknown extensions
|
||||||
//in this case, Android will show all applications installed on the device
|
//in this case, Android will show all applications installed on the device
|
||||||
//so you can choose which application to use
|
//so you can choose which application to use
|
||||||
intent.setDataAndType(uri, "*/*");
|
intent.setDataAndType(uri, "*/*");
|
||||||
}
|
}
|
||||||
|
|
||||||
//intent.addCategory(Intent.CATEGORY_OPENABLE);
|
|
||||||
// Only the system receives the ACTION_OPEN_DOCUMENT, so no need to test.
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
contextInterface.get().startActivity(intent);
|
contextInterface.get().startActivity(intent);
|
||||||
|
|
||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.sebse.fuplanner.tools;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
public class EventListener<T> {
|
||||||
|
private HashMap<String, EventFunction<T>> list = new HashMap<>();
|
||||||
|
|
||||||
|
public void add(String id,EventFunction<T> listener) {
|
||||||
|
list.put(id, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void remove(String id) {
|
||||||
|
list.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void emit(T value) {
|
||||||
|
for (EventFunction<T> listener : list.values()) {
|
||||||
|
listener.apply(value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
public interface EventFunction<T> {
|
||||||
|
void apply(T value);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -19,15 +19,12 @@ public interface MainActivityListener {
|
|||||||
|
|
||||||
GoogleAuth getGoogleAuth();
|
GoogleAuth getGoogleAuth();
|
||||||
|
|
||||||
void loginTokenInvalid(boolean doLoginCheck);
|
|
||||||
|
|
||||||
void onRefreshCompleted(boolean isFailed);
|
|
||||||
|
|
||||||
CanteenBrowser getCanteenBrowser();
|
CanteenBrowser getCanteenBrowser();
|
||||||
|
|
||||||
|
@Deprecated
|
||||||
|
void onRefreshCompleted(boolean isFailed);
|
||||||
|
|
||||||
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
||||||
|
|
||||||
void removeRequestPermissionsResultListener(String id);
|
void removeRequestPermissionsResultListener(String id);
|
||||||
|
|
||||||
void refreshNavigation();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,58 @@
|
|||||||
|
package de.sebse.fuplanner.tools;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||||
|
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||||
|
|
||||||
|
public class NewAsyncQueue {
|
||||||
|
private final LinkedList<AsyncQueueCallback> mQueue = new LinkedList<>();
|
||||||
|
private boolean mIsRunning = false;
|
||||||
|
|
||||||
|
public void add(AsyncQueueCallback callback) {
|
||||||
|
if (isRunning())
|
||||||
|
getQueue().addLast(callback);
|
||||||
|
else {
|
||||||
|
setRunning(true);
|
||||||
|
callback.run();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void next() {
|
||||||
|
AsyncQueueCallback callback = getQueue().pollFirst();
|
||||||
|
if (callback == null)
|
||||||
|
setRunning(false);
|
||||||
|
else
|
||||||
|
callback.run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public interface AsyncQueueCallback {
|
||||||
|
void run();
|
||||||
|
}
|
||||||
|
|
||||||
|
public NetworkErrorCallback check(NetworkErrorCallback value) {
|
||||||
|
return error -> {
|
||||||
|
value.onError(error);
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public <T> NetworkCallback<T> check(NetworkCallback<T> value) {
|
||||||
|
return success -> {
|
||||||
|
value.onResponse(success);
|
||||||
|
next();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isRunning() {
|
||||||
|
return mIsRunning;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setRunning(boolean value) {
|
||||||
|
mIsRunning = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
private LinkedList<AsyncQueueCallback> getQueue() {
|
||||||
|
return mQueue;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import java.util.HashMap;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
|
import de.sebse.fuplanner.tools.EventListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -27,34 +28,63 @@ public class HTTPService {
|
|||||||
private final RequestQueue requestQueue;
|
private final RequestQueue requestQueue;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
protected Logger log = new Logger(this);
|
protected Logger log = new Logger(this);
|
||||||
|
private EventListener<VolleyError> errorResponseListener = new EventListener<>();
|
||||||
|
private EventListener<Result> successResponseListener = new EventListener<>();
|
||||||
|
|
||||||
protected HTTPService(Context context) {
|
protected HTTPService(Context context) {
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
requestQueue = Volley.newRequestQueue(context, new BetterHurlStack(false));
|
requestQueue = Volley.newRequestQueue(context, new BetterHurlStack(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addErrorListener(String id, EventListener.EventFunction<VolleyError> listener) {
|
||||||
|
errorResponseListener.add(id, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeErrorListener(String id) {
|
||||||
|
errorResponseListener.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addSuccessListener(String id, EventListener.EventFunction<Result> listener) {
|
||||||
|
successResponseListener.add(id, listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeSuccessListener(String id) {
|
||||||
|
successResponseListener.remove(id);
|
||||||
|
}
|
||||||
|
|
||||||
protected void get(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error) {
|
protected void get(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error) {
|
||||||
HttpRequest request = new HttpRequest(Request.Method.GET, url, response, error) {
|
HttpRequest request = new HttpRequest(Request.Method.GET, url, response, error) {
|
||||||
@Override
|
@Override
|
||||||
public void deliverError(VolleyError error) {
|
public void deliverError(VolleyError error) {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
super.deliverError(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
deliver(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
||||||
} else if (error.networkResponse == null) {
|
} else if (error.networkResponse == null) {
|
||||||
int statusCode;
|
int statusCode;
|
||||||
if (error instanceof TimeoutError)
|
if (error instanceof TimeoutError)
|
||||||
statusCode = 408;
|
statusCode = 408;
|
||||||
else
|
else
|
||||||
statusCode = 500;
|
statusCode = 500;
|
||||||
super.deliverError(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
deliver(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
||||||
} else {
|
} else {
|
||||||
final int status = error.networkResponse.statusCode;
|
final int status = error.networkResponse.statusCode;
|
||||||
if (status == 302) {
|
if (status == 302) {
|
||||||
super.deliverResponse(new Result(null, error.networkResponse.headers));
|
deliverResponse(new Result(null, error.networkResponse.headers));
|
||||||
} else {
|
} else {
|
||||||
|
deliver(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void deliverResponse(Result response) {
|
||||||
|
successResponseListener.emit(response);
|
||||||
|
super.deliverResponse(response);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deliver(VolleyError error) {
|
||||||
|
errorResponseListener.emit(error);
|
||||||
super.deliverError(error);
|
super.deliverError(error);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getHeaders() throws AuthFailureError {
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
||||||
Map<String, String> params = super.getHeaders();
|
Map<String, String> params = super.getHeaders();
|
||||||
@@ -109,22 +139,33 @@ public class HTTPService {
|
|||||||
@Override
|
@Override
|
||||||
public void deliverError(VolleyError error) {
|
public void deliverError(VolleyError error) {
|
||||||
if (error == null) {
|
if (error == null) {
|
||||||
super.deliverError(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
deliver(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
||||||
} else if (error.networkResponse == null) {
|
} else if (error.networkResponse == null) {
|
||||||
int statusCode;
|
int statusCode;
|
||||||
if (error instanceof TimeoutError)
|
if (error instanceof TimeoutError)
|
||||||
statusCode = 408;
|
statusCode = 408;
|
||||||
else
|
else
|
||||||
statusCode = 500;
|
statusCode = 500;
|
||||||
super.deliverError(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
deliver(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
||||||
} else {
|
} else {
|
||||||
final int status = error.networkResponse.statusCode;
|
final int status = error.networkResponse.statusCode;
|
||||||
if (status == 302) {
|
if (status == 302) {
|
||||||
super.deliverResponse(new Result(null, error.networkResponse.headers));
|
deliverResponse(new Result(null, error.networkResponse.headers));
|
||||||
} else {
|
} else {
|
||||||
|
deliver(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void deliver(VolleyError error) {
|
||||||
|
errorResponseListener.emit(error);
|
||||||
super.deliverError(error);
|
super.deliverError(error);
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
@Override
|
||||||
|
protected void deliverResponse(Result response) {
|
||||||
|
successResponseListener.emit(response);
|
||||||
|
super.deliverResponse(response);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Map<String, String> getHeaders() throws AuthFailureError {
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
package de.sebse.fuplanner.tools.ui;
|
package de.sebse.fuplanner.tools.ui;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ImageView;
|
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.cunoraz.tagview.TagView;
|
import com.cunoraz.tagview.TagView;
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package de.sebse.fuplanner.tools.ui;
|
package de.sebse.fuplanner.tools.ui;
|
||||||
|
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.widget.ListView;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
|
|||||||
@@ -0,0 +1,26 @@
|
|||||||
|
package de.sebse.fuplanner.tools.ui;
|
||||||
|
|
||||||
|
import android.view.View;
|
||||||
|
import android.widget.ImageView;
|
||||||
|
import android.widget.TextView;
|
||||||
|
|
||||||
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
import de.sebse.fuplanner.R;
|
||||||
|
|
||||||
|
public class MailViewHolder extends StringViewHolder {
|
||||||
|
public final TextView mTitle;
|
||||||
|
public final TextView mSubLeft;
|
||||||
|
public final ImageView mIcon;
|
||||||
|
|
||||||
|
public MailViewHolder(View view) {
|
||||||
|
super(view);
|
||||||
|
mTitle = view.findViewById(R.id.title);
|
||||||
|
mSubLeft = view.findViewById(R.id.sub_left);
|
||||||
|
mIcon = view.findViewById(R.id.icon);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return super.toString() + " '" + mTitle.getText() + "' '" + mSubLeft.getText() + "'";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
|||||||
/**
|
/**
|
||||||
* Created by tlh on 2016/10/1 :)
|
* Created by tlh on 2016/10/1 :)
|
||||||
*/
|
*/
|
||||||
|
@SuppressWarnings("unused")
|
||||||
public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||||
private static final String KEY_IS_EXPAND = "IS_EXPAND";
|
private static final String KEY_IS_EXPAND = "IS_EXPAND";
|
||||||
private final List<? extends TreeViewBinder> viewBinders;
|
private final List<? extends TreeViewBinder> viewBinders;
|
||||||
@@ -42,7 +43,7 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
* @param nodes 基准点
|
* @param nodes 基准点
|
||||||
*/
|
*/
|
||||||
private void findDisplayNodes(List<TreeNode> nodes) {
|
private void findDisplayNodes(List<TreeNode> nodes) {
|
||||||
for (TreeNode node : nodes) {
|
for (TreeNode<?> node : nodes) {
|
||||||
displayNodes.add(node);
|
displayNodes.add(node);
|
||||||
if (!node.isLeaf() && node.isExpand())
|
if (!node.isLeaf() && node.isExpand())
|
||||||
findDisplayNodes(node.getChildList());
|
findDisplayNodes(node.getChildList());
|
||||||
@@ -54,8 +55,9 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
return displayNodes.get(position).getContent().getLayoutId();
|
return displayNodes.get(position).getContent().getLayoutId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
View v = LayoutInflater.from(parent.getContext())
|
View v = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(viewType, parent, false);
|
.inflate(viewType, parent, false);
|
||||||
if (viewBinders.size() == 1)
|
if (viewBinders.size() == 1)
|
||||||
@@ -68,8 +70,8 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(RecyclerView.ViewHolder holder, int position, List<Object> payloads) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position, @NonNull List<Object> payloads) {
|
||||||
if (payloads != null && !payloads.isEmpty()) {
|
if (!payloads.isEmpty()) {
|
||||||
Bundle b = (Bundle) payloads.get(0);
|
Bundle b = (Bundle) payloads.get(0);
|
||||||
for (String key : b.keySet()) {
|
for (String key : b.keySet()) {
|
||||||
switch (key) {
|
switch (key) {
|
||||||
@@ -84,11 +86,9 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(final RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull final RecyclerView.ViewHolder holder, int position) {
|
||||||
holder.itemView.setPadding(displayNodes.get(position).getHeight() * padding, 3, 3, 3);
|
holder.itemView.setPadding(displayNodes.get(position).getHeight() * padding, 3, 3, 3);
|
||||||
holder.itemView.setOnClickListener(new View.OnClickListener() {
|
holder.itemView.setOnClickListener(v -> {
|
||||||
@Override
|
|
||||||
public void onClick(View v) {
|
|
||||||
TreeNode selectedNode = displayNodes.get(holder.getLayoutPosition());
|
TreeNode selectedNode = displayNodes.get(holder.getLayoutPosition());
|
||||||
// Prevent multi-click during the short interval.
|
// Prevent multi-click during the short interval.
|
||||||
try {
|
try {
|
||||||
@@ -113,15 +113,15 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
} else {
|
} else {
|
||||||
notifyItemRangeRemoved(positionStart, removeChildNodes(selectedNode, true));
|
notifyItemRangeRemoved(positionStart, removeChildNodes(selectedNode, true));
|
||||||
}
|
}
|
||||||
}
|
|
||||||
});
|
});
|
||||||
for (TreeViewBinder viewBinder : viewBinders) {
|
for (TreeViewBinder viewBinder : viewBinders) {
|
||||||
if (viewBinder.getLayoutId() == displayNodes.get(position).getContent().getLayoutId())
|
if (viewBinder.getLayoutId() == displayNodes.get(position).getContent().getLayoutId())
|
||||||
|
//noinspection unchecked
|
||||||
viewBinder.bindView(holder, position, displayNodes.get(position));
|
viewBinder.bindView(holder, position, displayNodes.get(position));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int addChildNodes(TreeNode pNode, int startIndex) {
|
private int addChildNodes(TreeNode<?> pNode, int startIndex) {
|
||||||
List<TreeNode> childList = pNode.getChildList();
|
List<TreeNode> childList = pNode.getChildList();
|
||||||
int addChildCount = 0;
|
int addChildCount = 0;
|
||||||
for (TreeNode treeNode : childList) {
|
for (TreeNode treeNode : childList) {
|
||||||
@@ -139,7 +139,7 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
return removeChildNodes(pNode, true);
|
return removeChildNodes(pNode, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
private int removeChildNodes(TreeNode pNode, boolean shouldToggle) {
|
private int removeChildNodes(TreeNode<?> pNode, boolean shouldToggle) {
|
||||||
if (pNode.isLeaf())
|
if (pNode.isLeaf())
|
||||||
return 0;
|
return 0;
|
||||||
List<TreeNode> childList = pNode.getChildList();
|
List<TreeNode> childList = pNode.getChildList();
|
||||||
@@ -287,7 +287,7 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
notifyDiff(temp);
|
notifyDiff(temp);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void collapseBrotherNode(TreeNode pNode) {
|
public void collapseBrotherNode(TreeNode<LayoutItemType> pNode) {
|
||||||
List<TreeNode> temp = backupDisplayNodes();
|
List<TreeNode> temp = backupDisplayNodes();
|
||||||
if (pNode.isRoot()) {
|
if (pNode.isRoot()) {
|
||||||
List<TreeNode> roots = new ArrayList<>();
|
List<TreeNode> roots = new ArrayList<>();
|
||||||
@@ -301,7 +301,7 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
removeChildNodes(root);
|
removeChildNodes(root);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
TreeNode parent = pNode.getParent();
|
TreeNode<?> parent = pNode.getParent();
|
||||||
if (parent == null)
|
if (parent == null)
|
||||||
return;
|
return;
|
||||||
List<TreeNode> childList = parent.getChildList();
|
List<TreeNode> childList = parent.getChildList();
|
||||||
|
|||||||
9
app/src/main/res/drawable/ic_mail.xml
Normal file
9
app/src/main/res/drawable/ic_mail.xml
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
<vector xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
android:width="40dp"
|
||||||
|
android:height="40dp"
|
||||||
|
android:viewportWidth="24.0"
|
||||||
|
android:viewportHeight="24.0">
|
||||||
|
<path
|
||||||
|
android:fillColor="#003366"
|
||||||
|
android:pathData="M20,4L4,4c-1.1,0 -1.99,0.9 -1.99,2L2,18c0,1.1 0.9,2 2,2h16c1.1,0 2,-0.9 2,-2L22,6c0,-1.1 -0.9,-2 -2,-2zM20,8l-8,5 -8,-5L4,6l8,5 8,-5v2z"/>
|
||||||
|
</vector>
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
|
|
||||||
<include
|
<include
|
||||||
layout="@layout/app_bar_main"
|
layout="@layout/app_bar_main"
|
||||||
|
android:id="@+id/app_bar_include"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent" />
|
android:layout_height="match_parent" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,11 +1,15 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="4dp">
|
||||||
|
<RelativeLayout
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:orientation="horizontal"
|
android:orientation="horizontal"
|
||||||
android:padding="5dip" >
|
android:padding="5dip" >
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
@@ -48,4 +52,5 @@
|
|||||||
android:layout_alignParentRight="true"
|
android:layout_alignParentRight="true"
|
||||||
tools:text="Room 105"
|
tools:text="Room 105"
|
||||||
tools:ignore="RelativeOverlap" />
|
tools:ignore="RelativeOverlap" />
|
||||||
</RelativeLayout>
|
</RelativeLayout>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
45
app/src/main/res/layout/list_all_mails.xml
Normal file
45
app/src/main/res/layout/list_all_mails.xml
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
|
||||||
|
<androidx.cardview.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_margin="4dp">
|
||||||
|
<RelativeLayout
|
||||||
|
android:layout_width="match_parent"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:orientation="horizontal"
|
||||||
|
android:padding="5dip" >
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/title"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:textStyle="bold"
|
||||||
|
android:typeface="sans"
|
||||||
|
tools:text="Test this new stuff!" />
|
||||||
|
|
||||||
|
<TextView
|
||||||
|
android:id="@+id/sub_left"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_below="@id/title"
|
||||||
|
android:layout_marginTop="5dip"
|
||||||
|
android:textColor="#343434"
|
||||||
|
android:textSize="12sp"
|
||||||
|
tools:text="Peter Bauer" />
|
||||||
|
|
||||||
|
<ImageView
|
||||||
|
android:id="@+id/icon"
|
||||||
|
android:layout_width="wrap_content"
|
||||||
|
android:layout_height="wrap_content"
|
||||||
|
android:layout_alignTop="@id/title"
|
||||||
|
android:layout_alignBottom="@id/sub_left"
|
||||||
|
android:layout_alignParentEnd="true"
|
||||||
|
android:layout_alignParentRight="true"
|
||||||
|
android:layout_marginRight="10dp"
|
||||||
|
android:contentDescription="@string/mail_icon"
|
||||||
|
android:scaleType="fitCenter"
|
||||||
|
android:src="@drawable/ic_mail"
|
||||||
|
android:layout_marginEnd="10dp" />
|
||||||
|
</RelativeLayout>
|
||||||
|
</androidx.cardview.widget.CardView>
|
||||||
@@ -76,4 +76,9 @@
|
|||||||
<string name="exam">Klausur</string>
|
<string name="exam">Klausur</string>
|
||||||
<string name="other">Andere</string>
|
<string name="other">Andere</string>
|
||||||
<string name="deadline">Abgabe</string>
|
<string name="deadline">Abgabe</string>
|
||||||
|
<string name="winter_semester">Wintersemester %1$d/%2$d</string>
|
||||||
|
<string name="summer_semester">Sommersemester %1$d</string>
|
||||||
|
<string name="lecturers">Dozenten</string>
|
||||||
|
<string name="mail_icon">Mail Icon</string>
|
||||||
|
<string name="mail_default_text">Hallo %1$s, \n\n\n\nMit freundlichen Grüßen\n\n\n\nGesendet von der FUPlanner Android App</string>
|
||||||
</resources>
|
</resources>
|
||||||
@@ -84,4 +84,9 @@
|
|||||||
<string name="exam">Exam</string>
|
<string name="exam">Exam</string>
|
||||||
<string name="other">Other</string>
|
<string name="other">Other</string>
|
||||||
<string name="deadline">Deadline</string>
|
<string name="deadline">Deadline</string>
|
||||||
|
<string name="winter_semester">Winter Semester %1$d/%2$d</string>
|
||||||
|
<string name="summer_semester">Summer Semester %1$d</string>
|
||||||
|
<string name="lecturers">Lecturers</string>
|
||||||
|
<string name="mail_icon">Mail Icon</string>
|
||||||
|
<string name="mail_default_text">Dear %1$s, \n\n\n\nYours sincerely\n\n\n\nSend by FUPlanner Android App</string>
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
Reference in New Issue
Block a user