Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
22470f58da | ||
|
|
697740e20b |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -1,3 +1,4 @@
|
|||||||
|
*.iml
|
||||||
.gradle
|
.gradle
|
||||||
/local.properties
|
/local.properties
|
||||||
/.idea/*
|
/.idea/*
|
||||||
|
|||||||
141
app/app.iml
141
app/app.iml
@@ -1,141 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module external.linked.project.id=":app" external.linked.project.path="$MODULE_DIR$" external.root.project.path="$MODULE_DIR$/.." external.system.id="GRADLE" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="android-gradle" name="Android-Gradle">
|
|
||||||
<configuration>
|
|
||||||
<option name="GRADLE_PROJECT_PATH" value=":app" />
|
|
||||||
<option name="LAST_SUCCESSFUL_SYNC_AGP_VERSION" value="3.5.1" />
|
|
||||||
<option name="LAST_KNOWN_AGP_VERSION" value="3.5.1" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
<facet type="android" name="Android">
|
|
||||||
<configuration>
|
|
||||||
<option name="SELECTED_BUILD_VARIANT" value="debug" />
|
|
||||||
<option name="ASSEMBLE_TASK_NAME" value="assembleDebug" />
|
|
||||||
<option name="COMPILE_JAVA_TASK_NAME" value="compileDebugSources" />
|
|
||||||
<afterSyncTasks>
|
|
||||||
<task>generateDebugSources</task>
|
|
||||||
</afterSyncTasks>
|
|
||||||
<option name="ALLOW_USER_CONFIGURATION" value="false" />
|
|
||||||
<option name="MANIFEST_FILE_RELATIVE_PATH" value="/src/main/AndroidManifest.xml" />
|
|
||||||
<option name="RES_FOLDER_RELATIVE_PATH" value="/src/main/res" />
|
|
||||||
<option name="RES_FOLDERS_RELATIVE_PATH" value="file://$MODULE_DIR$/src/main/res;file://$MODULE_DIR$/build/generated/res/resValues/debug" />
|
|
||||||
<option name="TEST_RES_FOLDERS_RELATIVE_PATH" value="" />
|
|
||||||
<option name="ASSETS_FOLDER_RELATIVE_PATH" value="/src/main/assets" />
|
|
||||||
</configuration>
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/build/intermediates/javac/debug/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/build/intermediates/javac/debugUnitTest/classes" />
|
|
||||||
<exclude-output />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debug/out" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debug/compileDebugAidl/out" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/debug" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debug/compileDebugRenderscript/out" isTestSource="false" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/debug" type="java-resource" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/debug" type="java-resource" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugAndroidTest/out" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/aidl_source_output_dir/debugAndroidTest/compileDebugAndroidTestAidl/out" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/source/buildConfig/androidTest/debug" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/renderscript_source_output_dir/debugAndroidTest/compileDebugAndroidTestRenderscript/out" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/rs/androidTest/debug" type="java-test-resource" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/res/resValues/androidTest/debug" type="java-test-resource" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/build/generated/ap_generated_sources/debugUnitTest/out" isTestSource="true" generated="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/res" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/assets" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/aidl" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/rs" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/debug/shaders" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTestDebug/shaders" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/testDebug/shaders" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/res" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/assets" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/aidl" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/rs" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/shaders" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/androidTest/shaders" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/res" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/assets" type="java-test-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/aidl" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/rs" isTestSource="true" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/shaders" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/build" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="jdk" jdkName="Android API 29 Platform" jdkType="Android SDK" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Gradle: __local_aars__:/media/sebastian/Daten/nextcloud/Documents/Programmierung/Java - Android Studio/fuplanner/app/libs/jericho-html-3.4.jar:unspecified@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.collection:collection:1.1.0@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.1.0@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.1.0@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.1.0@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout-solver:2.0.0-beta3@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: org.jetbrains:annotations-java5:15.0@jar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.preference:preference:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.google.android.material:material:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.recyclerview:recyclerview:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout:2.0.0-beta3@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.ms-square:expandableTextView:0.1.4@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-ui:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-base:17.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-tasks:17.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.google.android.gms:play-services-basement:17.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.fragment:fragment:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat-resources:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.drawerlayout:drawerlayout:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-utils:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.transition:transition:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.viewpager:viewpager:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.coordinatorlayout:coordinatorlayout:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.slidingpanelayout:slidingpanelayout:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.customview:customview:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.swiperefreshlayout:swiperefreshlayout:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.asynclayoutinflater:asynclayoutinflater:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.loader:loader:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.activity:activity:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable-animated:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.vectordrawable:vectordrawable:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.core:core:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.versionedparcelable:versionedparcelable:1.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.cursoradapter:cursoradapter:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.cardview:cardview:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.interpolator:interpolator:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-viewmodel:2.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.documentfile:documentfile:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.localbroadcastmanager:localbroadcastmanager:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.print:print:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-runtime:2.1.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.savedstate:savedstate:1.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata:2.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-livedata-core:2.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: androidx.arch.core:core-runtime:2.0.0@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.android.volley:volley:1.1.1@aar" level="project" />
|
|
||||||
<orderEntry type="library" name="Gradle: com.github.Cutta:TagView:1.3@aar" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
@@ -1,14 +1,14 @@
|
|||||||
apply plugin: 'com.android.application'
|
apply plugin: 'com.android.application'
|
||||||
|
|
||||||
android {
|
android {
|
||||||
compileSdkVersion 29
|
compileSdkVersion 28
|
||||||
buildToolsVersion '28.0.3'
|
buildToolsVersion '28.0.3'
|
||||||
defaultConfig {
|
defaultConfig {
|
||||||
applicationId "de.sebse.fuplanner"
|
applicationId "de.sebse.fuplanner"
|
||||||
minSdkVersion 21
|
minSdkVersion 15
|
||||||
targetSdkVersion 29
|
targetSdkVersion 28
|
||||||
versionCode 43
|
versionCode 21
|
||||||
versionName "1.6.4"
|
versionName "1.4.2"
|
||||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||||
}
|
}
|
||||||
buildTypes {
|
buildTypes {
|
||||||
@@ -27,16 +27,28 @@ android {
|
|||||||
|
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
|
||||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||||
implementation 'androidx.preference:preference:1.1.0'
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
|
androidTestImplementation('androidx.test.espresso:espresso-core:3.1.0-beta02', {
|
||||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
exclude group: 'com.android.support', module: 'support-annotations'
|
||||||
implementation 'com.android.volley:volley:1.1.1'
|
})
|
||||||
implementation 'com.github.Cutta:TagView:1.3'
|
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 'com.google.android.gms:play-services-base:17.1.0'
|
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
||||||
implementation 'com.ms-square:expandableTextView:0.1.4'
|
implementation 'com.android.volley:volley:1.1.0'
|
||||||
|
//noinspection GradleDependency
|
||||||
|
implementation 'com.google.android.gms:play-services-auth:15.0.0'
|
||||||
|
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
|
testImplementation 'junit:junit:4.12'
|
||||||
|
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||||
|
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 'androidx.legacy:legacy-support-v4:1.0.0'
|
||||||
implementation 'org.jetbrains:annotations-java5:15.0'
|
implementation 'org.jetbrains:annotations-java5:15.0'
|
||||||
//implementation 'com.github.quivr:android-week-view:2.0.2'//com.github.alamkanak:android-week-view:1.2.6
|
//implementation 'com.github.quivr:android-week-view:2.0.2'//com.github.alamkanak:android-week-view:1.2.6
|
||||||
|
implementation 'com.ms-square:expandableTextView:0.1.4'
|
||||||
|
// https://github.com/bignerdranch/expandable-recycler-view
|
||||||
|
implementation 'com.bignerdranch.android:expandablerecyclerview:3.0.0-RC1'
|
||||||
|
implementation 'com.github.Cutta:TagView:1.3'
|
||||||
|
implementation files('libs/jericho-html-3.4.jar')
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
package de.sebse.fuplanner;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import androidx.test.InstrumentationRegistry;
|
||||||
|
import androidx.test.runner.AndroidJUnit4;
|
||||||
|
|
||||||
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Instrumentation test, which will execute on an Android device.
|
||||||
|
*
|
||||||
|
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
|
||||||
|
*/
|
||||||
|
@RunWith(AndroidJUnit4.class)
|
||||||
|
public class ExampleInstrumentedTest {
|
||||||
|
@Test
|
||||||
|
public void useAppContext() throws Exception {
|
||||||
|
// Context of the app under test.
|
||||||
|
Context appContext = InstrumentationRegistry.getTargetContext();
|
||||||
|
|
||||||
|
assertEquals("de.sebse.fuplanner", appContext.getPackageName());
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||||
xmlns:tools="http://schemas.android.com/tools"
|
|
||||||
package="de.sebse.fuplanner">
|
package="de.sebse.fuplanner">
|
||||||
|
|
||||||
<uses-permission
|
<uses-permission
|
||||||
@@ -22,10 +21,6 @@
|
|||||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||||
|
|
||||||
<!-- Calendar integration -->
|
|
||||||
<uses-permission android:name="android.permission.READ_CALENDAR" />
|
|
||||||
<uses-permission android:name="android.permission.WRITE_CALENDAR" />
|
|
||||||
|
|
||||||
<application
|
<application
|
||||||
android:allowBackup="true"
|
android:allowBackup="true"
|
||||||
android:fullBackupContent="@xml/backup_descriptor"
|
android:fullBackupContent="@xml/backup_descriptor"
|
||||||
@@ -36,9 +31,7 @@
|
|||||||
android:theme="@style/FUTheme">
|
android:theme="@style/FUTheme">
|
||||||
<activity
|
<activity
|
||||||
android:name=".MainActivity"
|
android:name=".MainActivity"
|
||||||
android:label="@string/app_name"
|
android:label="@string/app_name">
|
||||||
android:clearTaskOnLaunch="true"
|
|
||||||
android:launchMode="singleTop">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.VIEW" />
|
<action android:name="android.intent.action.VIEW" />
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
@@ -63,12 +56,11 @@
|
|||||||
android:syncable="true">
|
android:syncable="true">
|
||||||
|
|
||||||
</provider>
|
</provider>
|
||||||
|
|
||||||
<activity
|
<activity
|
||||||
android:name=".services.fulogin.FUAuthenticatorActivity"
|
android:name=".services.fulogin.FUAuthenticatorActivity"
|
||||||
android:label="@string/title_activity_fuauthenticator" />
|
android:label="@string/title_activity_fuauthenticator" />
|
||||||
<service
|
<service android:name=".services.fulogin.FUAuthenticatorService">
|
||||||
android:name=".services.fulogin.FUAuthenticatorService"
|
|
||||||
android:permission="de.sebse.fuplanner.Account">
|
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.accounts.AccountAuthenticator" />
|
<action android:name="android.accounts.AccountAuthenticator" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
@@ -86,20 +78,6 @@
|
|||||||
android:name="android.content.SyncAdapter"
|
android:name="android.content.SyncAdapter"
|
||||||
android:resource="@xml/syncadapter_kvv" />
|
android:resource="@xml/syncadapter_kvv" />
|
||||||
</service>
|
</service>
|
||||||
<service
|
|
||||||
android:name=".services.kvv.KVV"
|
|
||||||
android:exported="false">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.app.Service" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
<service
|
|
||||||
android:name=".tools.network.HTTPNetwork"
|
|
||||||
android:exported="false">
|
|
||||||
<intent-filter>
|
|
||||||
<action android:name="android.app.Service" />
|
|
||||||
</intent-filter>
|
|
||||||
</service>
|
|
||||||
|
|
||||||
|
|
||||||
</application>
|
</application>
|
||||||
|
|||||||
@@ -2,16 +2,9 @@ package de.sebse.fuplanner;
|
|||||||
|
|
||||||
import android.accounts.Account;
|
import android.accounts.Account;
|
||||||
import android.accounts.AccountManager;
|
import android.accounts.AccountManager;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.ContentResolver;
|
import android.content.ContentResolver;
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.ServiceConnection;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.os.IBinder;
|
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.view.Menu;
|
import android.view.Menu;
|
||||||
import android.view.MenuItem;
|
import android.view.MenuItem;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -23,16 +16,12 @@ import com.google.android.material.navigation.NavigationView;
|
|||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
import androidx.arch.core.util.Function;
|
|
||||||
import androidx.appcompat.app.ActionBarDrawerToggle;
|
import androidx.appcompat.app.ActionBarDrawerToggle;
|
||||||
import androidx.appcompat.app.AppCompatActivity;
|
import androidx.appcompat.app.AppCompatActivity;
|
||||||
import androidx.appcompat.widget.Toolbar;
|
import androidx.appcompat.widget.Toolbar;
|
||||||
@@ -47,7 +36,6 @@ import de.sebse.fuplanner.fragments.NewsFragment;
|
|||||||
import de.sebse.fuplanner.fragments.PrefsFragment;
|
import de.sebse.fuplanner.fragments.PrefsFragment;
|
||||||
import de.sebse.fuplanner.fragments.ScheduleFragment;
|
import de.sebse.fuplanner.fragments.ScheduleFragment;
|
||||||
import de.sebse.fuplanner.fragments.StartupFragment;
|
import de.sebse.fuplanner.fragments.StartupFragment;
|
||||||
import de.sebse.fuplanner.fragments.canteen.CanteensAddFragment;
|
|
||||||
import de.sebse.fuplanner.fragments.canteen.DaySwitcherFragment;
|
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;
|
||||||
@@ -56,10 +44,8 @@ import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
|||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||||
import de.sebse.fuplanner.services.kvv.KVV;
|
import de.sebse.fuplanner.services.kvv.KVV;
|
||||||
import de.sebse.fuplanner.services.kvv.KVVListener;
|
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||||
import de.sebse.fuplanner.services.kvv.Login;
|
|
||||||
import de.sebse.fuplanner.services.kvv.sync.KVVContentProvider;
|
import de.sebse.fuplanner.services.kvv.sync.KVVContentProvider;
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenKVV;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
import de.sebse.fuplanner.services.news.NewsManager;
|
import de.sebse.fuplanner.services.news.NewsManager;
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
@@ -78,59 +64,27 @@ public class MainActivity extends AppCompatActivity
|
|||||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||||
CanteensFragment.OnCanteensFragmentInteractionListener {
|
CanteensFragment.OnCanteensFragmentInteractionListener {
|
||||||
|
|
||||||
public static final int FRAGMENT_NONE = -1;
|
private static final int FRAGMENT_NONE = -1;
|
||||||
public static final int FRAGMENT_STARTUP = 0;
|
private static final int FRAGMENT_STARTUP = 0;
|
||||||
public static final int FRAGMENT_MODULES = 1;
|
private static final int FRAGMENT_MODULES = 1;
|
||||||
public static final int FRAGMENT_MODULES_DETAILS = 2;
|
private static final int FRAGMENT_MODULES_DETAILS = 2;
|
||||||
public static final int FRAGMENT_SCHEDULE = 4;
|
private static final int FRAGMENT_SCHEDULE = 4;
|
||||||
public static final int FRAGMENT_CANTEENS = 5;
|
private static final int FRAGMENT_CANTEENS = 5;
|
||||||
public static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
private static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
||||||
public static final int FRAGMENT_CANTEENS_ADD = 9;
|
private static final int FRAGMENT_PREFERENCES = 7;
|
||||||
public static final int FRAGMENT_PREFERENCES = 7;
|
private static final int FRAGMENT_NEWS = 8;
|
||||||
public static final int FRAGMENT_NEWS = 8;
|
|
||||||
|
|
||||||
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
||||||
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
||||||
private static final int DOUBLE_CLICK_TO_EXIT_MILLIS = 2000;
|
private static final int DOUBLE_CLICK_TO_EXIT_MILLIS = 2000;
|
||||||
|
|
||||||
private FragmentManager mFragmentManager;
|
private FragmentManager mFragmentManager;
|
||||||
|
private KVV mKVV;
|
||||||
private NewsManager mNewsManager;
|
private NewsManager mNewsManager;
|
||||||
private CanteenBrowser mCanteenBrowser;
|
private CanteenBrowser mCanteenBrowser;
|
||||||
private final Logger log = new Logger(this);
|
private final Logger log = new Logger(this);
|
||||||
private NavigationView mNavigationView;
|
private NavigationView mNavigationView;
|
||||||
|
|
||||||
private boolean mAlreadyCreated = false;
|
|
||||||
|
|
||||||
// KVV service
|
|
||||||
private ArrayList<KVVCallback> mCallbacks = new ArrayList<>();
|
|
||||||
@Nullable private KVV mKVV;
|
|
||||||
boolean mBound = false;
|
|
||||||
/** Defines callbacks for service binding, passed to bindService() */
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(ComponentName className,
|
|
||||||
IBinder service) {
|
|
||||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
|
||||||
KVV.LocalBinder binder = (KVV.LocalBinder) service;
|
|
||||||
mKVV = binder.getService();
|
|
||||||
mKVV.addListener("mainactivity", MainActivity.this);
|
|
||||||
for (KVVCallback callback : mCallbacks) {
|
|
||||||
callback.get(mKVV);
|
|
||||||
}
|
|
||||||
mBound = true;
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName arg0) {
|
|
||||||
mKVV.removeListener("mainactivity");
|
|
||||||
mBound = false;
|
|
||||||
mKVV = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private int mFragmentPage = FRAGMENT_NONE;
|
private int mFragmentPage = FRAGMENT_NONE;
|
||||||
@NotNull
|
@NotNull
|
||||||
private String mFragmentData = "";
|
private String mFragmentData = "";
|
||||||
@@ -140,24 +94,14 @@ public class MainActivity extends AppCompatActivity
|
|||||||
private CustomAccountManager mAccountManager;
|
private CustomAccountManager mAccountManager;
|
||||||
private boolean isPaused = false;
|
private boolean isPaused = false;
|
||||||
private boolean isLoggedInBeforePause = false;
|
private boolean isLoggedInBeforePause = false;
|
||||||
private boolean isDrawerFixed = false;
|
|
||||||
private Function<Modules, Void> mMolduleListUpdateFunction;
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
mAccountManager = new CustomAccountManager(AccountManager.get(this), () -> MainActivity.this);
|
mAccountManager = new CustomAccountManager(AccountManager.get(this), () -> MainActivity.this);
|
||||||
isDrawerFixed = getResources().getBoolean(R.bool.isDrawerFixed);
|
|
||||||
int desiredPage = getDefaultFragmentAfterLogin();
|
int desiredPage = getDefaultFragmentAfterLogin();
|
||||||
String desiredData = "";
|
String desiredData = "";
|
||||||
Intent intent = getIntent();
|
if (savedInstanceState != null) {
|
||||||
if (intent != null && CustomNotificationManager.NOTIFICATION_TYPE_NAVIGATE.equals(intent.getStringExtra(CustomNotificationManager.NOTIFICATION_INTENT))) {
|
|
||||||
int page = intent.getIntExtra(CustomNotificationManager.NOTIFICATION_PAGE, 0);
|
|
||||||
if (page == FRAGMENT_STARTUP || page == FRAGMENT_NONE)
|
|
||||||
page = getDefaultFragmentAfterLogin();
|
|
||||||
desiredPage = page;
|
|
||||||
desiredData = intent.getStringExtra(CustomNotificationManager.NOTIFICATION_DATA);
|
|
||||||
} else if (savedInstanceState != null) {
|
|
||||||
desiredPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, desiredPage);
|
desiredPage = savedInstanceState.getInt(ARG_FRAGMENT_PAGE, desiredPage);
|
||||||
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
|
desiredData = savedInstanceState.getString(ARG_FRAGMENT_STATUS, desiredData);
|
||||||
}
|
}
|
||||||
@@ -166,20 +110,11 @@ public class MainActivity extends AppCompatActivity
|
|||||||
Toolbar toolbar = findViewById(R.id.toolbar);
|
Toolbar toolbar = findViewById(R.id.toolbar);
|
||||||
setSupportActionBar(toolbar);
|
setSupportActionBar(toolbar);
|
||||||
|
|
||||||
if (!isDrawerFixed) {
|
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
|
||||||
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
|
||||||
drawer.addDrawerListener(toggle);
|
drawer.addDrawerListener(toggle);
|
||||||
toggle.syncState();
|
toggle.syncState();
|
||||||
}
|
|
||||||
|
|
||||||
String nightMode = Preferences.getStringArray(getApplicationContext(), R.array.pref_night_mode);
|
|
||||||
switch (nightMode) {
|
|
||||||
case "night": AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES); break;
|
|
||||||
case "day": AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO); break;
|
|
||||||
default: AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM); break;
|
|
||||||
}
|
|
||||||
|
|
||||||
mNavigationView = findViewById(R.id.nav_view);
|
mNavigationView = findViewById(R.id.nav_view);
|
||||||
mNavigationView.setNavigationItemSelectedListener(this);
|
mNavigationView.setNavigationItemSelectedListener(this);
|
||||||
@@ -189,7 +124,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
if (!mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
if (!mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||||
desiredPage = getDefaultFragmentAfterLogout();
|
desiredPage = getDefaultFragmentAfterLogout();
|
||||||
desiredData = "";
|
desiredData = "";
|
||||||
goToLoginScreen();
|
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null);
|
||||||
updateNavigation();
|
updateNavigation();
|
||||||
changeFragment(desiredPage, desiredData);
|
changeFragment(desiredPage, desiredData);
|
||||||
} else {
|
} else {
|
||||||
@@ -197,103 +132,43 @@ public class MainActivity extends AppCompatActivity
|
|||||||
changeFragment(FRAGMENT_STARTUP);
|
changeFragment(FRAGMENT_STARTUP);
|
||||||
int targetPage = desiredPage;
|
int targetPage = desiredPage;
|
||||||
String targetData = desiredData;
|
String targetData = desiredData;
|
||||||
getKVV(kvv -> {
|
getKVV().account().restoreOnlineLogin(isRestored -> {
|
||||||
kvv.account().restoreOnlineLogin(restoreResult -> {
|
|
||||||
updateNavigation();
|
updateNavigation();
|
||||||
if (restoreResult != Login.RESTORE_STATUS_INVALID_PASSWORD)
|
if (isRestored)
|
||||||
changeFragment(targetPage, targetData);
|
changeFragment(targetPage, targetData);
|
||||||
else
|
else
|
||||||
changeFragment(getDefaultFragmentAfterLogout());
|
changeFragment(getDefaultFragmentAfterLogout());
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mAlreadyCreated) {
|
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
|
||||||
Intent serviceIntent = new Intent(this, KVV.class);
|
registerSync();
|
||||||
getApplicationContext().bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
|
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
||||||
}
|
}
|
||||||
mAlreadyCreated = true;
|
|
||||||
|
|
||||||
CustomNotificationManager.createNotificationChannel(this);
|
CustomNotificationManager.createNotificationChannel(this);
|
||||||
/*getKVV(kvv -> {
|
|
||||||
kvv.modules().list().recv(list -> {
|
|
||||||
Modules.Module module = list.getByIndex(0);
|
|
||||||
CustomNotificationManager.sendNotification(this, "Test", module.title, FRAGMENT_MODULES_DETAILS, module.getID()+"."+ ModulePart.getPageByPart(ModulePart.EVENT));
|
|
||||||
}, log::e);
|
|
||||||
});*/
|
|
||||||
}
|
|
||||||
|
|
||||||
private void goToLoginScreen() {
|
|
||||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, false);
|
|
||||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStart() {
|
|
||||||
super.onStart();
|
|
||||||
if (!mAlreadyCreated) {
|
|
||||||
Intent serviceIntent = new Intent(this, KVV.class);
|
|
||||||
getApplicationContext().bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
|
|
||||||
}
|
|
||||||
mAlreadyCreated = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onStop() {
|
|
||||||
super.onStop();
|
|
||||||
if (mKVV != null)
|
|
||||||
mKVV.removeListener("mainactivity");
|
|
||||||
if (mBound)
|
|
||||||
getApplicationContext().unbindService(mConnection);
|
|
||||||
mKVV = null;
|
|
||||||
mBound = false;
|
|
||||||
mAlreadyCreated = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onNewIntent(Intent intent) {
|
|
||||||
super.onNewIntent(intent);
|
|
||||||
if (CustomNotificationManager.NOTIFICATION_TYPE_NAVIGATE.equals(intent.getStringExtra(CustomNotificationManager.NOTIFICATION_INTENT))) {
|
|
||||||
int page = intent.getIntExtra(CustomNotificationManager.NOTIFICATION_PAGE, 0);
|
|
||||||
String data = intent.getStringExtra(CustomNotificationManager.NOTIFICATION_DATA);
|
|
||||||
if (page == FRAGMENT_STARTUP || page == FRAGMENT_NONE)
|
|
||||||
page = getDefaultFragmentAfterLogin();
|
|
||||||
changeFragment(page, data);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPause() {
|
protected void onPause() {
|
||||||
super.onPause();
|
super.onPause();
|
||||||
isPaused = true;
|
isPaused = true;
|
||||||
getKVV(kvv -> isLoggedInBeforePause = kvv.account().isLoggedIn());
|
isLoggedInBeforePause = getKVV().account().isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onResume() {
|
protected void onResume() {
|
||||||
super.onResume();
|
super.onResume();
|
||||||
if (isPaused) {
|
if (isPaused) {
|
||||||
getKVV(kvv -> {
|
getKVV().account().restoreOnlineLogin(isRestored -> {
|
||||||
kvv.account().restoreOnlineLogin(restoreResult -> {
|
|
||||||
updateNavigation();
|
updateNavigation();
|
||||||
if (restoreResult == Login.RESTORE_STATUS_SUCCESS && !isLoggedInBeforePause) {
|
if (isRestored && !isLoggedInBeforePause)
|
||||||
changeFragment(getDefaultFragmentAfterLogin());
|
changeFragment(getDefaultFragmentAfterLogin());
|
||||||
} else if (restoreResult == Login.RESTORE_STATUS_INVALID_PASSWORD && isLoggedInBeforePause) {
|
else if (!isRestored && isLoggedInBeforePause) {
|
||||||
kvv.account().logout(false);
|
getKVV().account().logout(false);
|
||||||
changeFragment(getDefaultFragmentAfterLogout());
|
changeFragment(getDefaultFragmentAfterLogout());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (restoreResult == Login.RESTORE_STATUS_SUCCESS || restoreResult == Login.RELOGIN) {
|
|
||||||
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup) && mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
|
||||||
registerSync(true);
|
|
||||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
|
||||||
} else {
|
|
||||||
registerSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
kvv.modules().list().reloadIfOutdated();
|
|
||||||
});
|
});
|
||||||
|
getKVV().modules().list().reloadIfOutdated();
|
||||||
}
|
}
|
||||||
isPaused = false;
|
isPaused = false;
|
||||||
}
|
}
|
||||||
@@ -306,10 +181,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
if (drawer.isDrawerOpen(GravityCompat.START) && !isDrawerFixed) {
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
} else {
|
} else {
|
||||||
getKVV(kvv -> {
|
|
||||||
if (mFragmentPage == FRAGMENT_MODULES_DETAILS) {
|
if (mFragmentPage == FRAGMENT_MODULES_DETAILS) {
|
||||||
ModDetailFragment fragment = (ModDetailFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_MODULES_DETAILS));
|
ModDetailFragment fragment = (ModDetailFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_MODULES_DETAILS));
|
||||||
if (fragment != null && fragment.isVisible() && Regex.has("\\.[1-9][0-9]*", fragment.getData())) {
|
if (fragment != null && fragment.isVisible() && Regex.has("\\.[1-9][0-9]*", fragment.getData())) {
|
||||||
@@ -324,16 +198,13 @@ public class MainActivity extends AppCompatActivity
|
|||||||
} else {
|
} else {
|
||||||
changeFragment(FRAGMENT_CANTEENS);
|
changeFragment(FRAGMENT_CANTEENS);
|
||||||
}
|
}
|
||||||
} else if (mFragmentPage == FRAGMENT_CANTEENS_ADD) {
|
} else if (getKVV().account().isLoggedIn() && mFragmentPage != getDefaultFragmentAfterLogin()) {
|
||||||
changeFragment(FRAGMENT_CANTEENS);
|
|
||||||
} else if (kvv.account().isLoggedIn() && mFragmentPage != getDefaultFragmentAfterLogin()) {
|
|
||||||
changeFragment(getDefaultFragmentAfterLogin());
|
changeFragment(getDefaultFragmentAfterLogin());
|
||||||
} else {
|
} else {
|
||||||
mDoubleBackToExitPressedOnce = System.currentTimeMillis();
|
mDoubleBackToExitPressedOnce = System.currentTimeMillis();
|
||||||
showToast(R.string.back_to_exit);
|
showToast(R.string.back_to_exit);
|
||||||
//getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD);
|
//getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV);
|
||||||
}
|
}
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -343,9 +214,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
if (mFragmentPage == FRAGMENT_SCHEDULE) {
|
if (mFragmentPage == FRAGMENT_SCHEDULE) {
|
||||||
getMenuInflater().inflate(R.menu.options_schedule, menu);
|
getMenuInflater().inflate(R.menu.options_schedule, menu);
|
||||||
return true;
|
return true;
|
||||||
} else if (mFragmentPage == FRAGMENT_CANTEENS) {
|
|
||||||
getMenuInflater().inflate(R.menu.options_canteens, menu);
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -357,7 +225,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
// as you specify a parent activity in AndroidManifest.xml.
|
// as you specify a parent activity in AndroidManifest.xml.
|
||||||
int id = item.getItemId();
|
int id = item.getItemId();
|
||||||
|
|
||||||
if (mFragmentPage == FRAGMENT_SCHEDULE) {
|
//noinspection SimplifiableIfStatement
|
||||||
if (id == R.id.refresh) {
|
if (id == R.id.refresh) {
|
||||||
ScheduleFragment fragment = (ScheduleFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_SCHEDULE));
|
ScheduleFragment fragment = (ScheduleFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_SCHEDULE));
|
||||||
if (fragment != null && fragment.isVisible()) {
|
if (fragment != null && fragment.isVisible()) {
|
||||||
@@ -371,26 +239,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} else if (mFragmentPage == FRAGMENT_CANTEENS) {
|
|
||||||
if (id == R.id.restore) {
|
|
||||||
CanteensFragment fragment = (CanteensFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_CANTEENS));
|
|
||||||
if (fragment != null && fragment.isVisible()) {
|
|
||||||
fragment.restoreDefaults();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (id == R.id.delete) {
|
|
||||||
CanteensFragment fragment = (CanteensFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_CANTEENS));
|
|
||||||
if (fragment != null && fragment.isVisible()) {
|
|
||||||
fragment.startDelete();
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
if (id == R.id.add) {
|
|
||||||
changeFragment(FRAGMENT_CANTEENS_ADD);
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return super.onOptionsItemSelected(item);
|
return super.onOptionsItemSelected(item);
|
||||||
}
|
}
|
||||||
@@ -422,30 +270,14 @@ public class MainActivity extends AppCompatActivity
|
|||||||
sendIntent.setType("text/plain");
|
sendIntent.setType("text/plain");
|
||||||
startActivity(sendIntent);
|
startActivity(sendIntent);
|
||||||
break;
|
break;
|
||||||
case R.id.nav_rate:
|
|
||||||
Uri uri = Uri.parse("market://details?id=" + getApplicationContext().getPackageName());
|
|
||||||
Intent viewIntent = new Intent(Intent.ACTION_VIEW, uri);
|
|
||||||
viewIntent.addFlags(Intent.FLAG_ACTIVITY_NO_HISTORY | Intent.FLAG_ACTIVITY_NEW_DOCUMENT | Intent.FLAG_ACTIVITY_MULTIPLE_TASK);
|
|
||||||
try {
|
|
||||||
startActivity(viewIntent);
|
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
uri = Uri.parse("http://play.google.com/store/apps/details?id=" + getApplicationContext().getPackageName());
|
|
||||||
viewIntent = new Intent(Intent.ACTION_VIEW, uri);
|
|
||||||
startActivity(viewIntent);
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case R.id.nav_logout:
|
case R.id.nav_logout:
|
||||||
getKVV(kvv -> {
|
getKVV().account().logout(true);
|
||||||
kvv.account().logout(true);
|
getKVV().modules().list().delete();
|
||||||
kvv.modules().list().delete();
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
}
|
}
|
||||||
if (!isDrawerFixed) {
|
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
}
|
|
||||||
|
|
||||||
int size = mNavigationView.getMenu().size();
|
int size = mNavigationView.getMenu().size();
|
||||||
for (int k = 0; k < size; k++) {
|
for (int k = 0; k < size; k++) {
|
||||||
@@ -457,7 +289,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onSaveInstanceState(@NonNull Bundle savedInstanceState) {
|
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||||
if (mFragmentPage != FRAGMENT_STARTUP && mFragmentPage != FRAGMENT_NONE) {
|
if (mFragmentPage != FRAGMENT_STARTUP && mFragmentPage != FRAGMENT_NONE) {
|
||||||
Fragment fragment = mFragmentManager.findFragmentByTag(String.valueOf(mFragmentPage));
|
Fragment fragment = mFragmentManager.findFragmentByTag(String.valueOf(mFragmentPage));
|
||||||
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, mFragmentPage);
|
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, mFragmentPage);
|
||||||
@@ -490,12 +322,11 @@ public class MainActivity extends AppCompatActivity
|
|||||||
return this.mNewsManager;
|
return this.mNewsManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getKVV(KVVCallback callback) {
|
public KVV getKVV() {
|
||||||
if (this.mKVV == null) {
|
if (this.mKVV == null) {
|
||||||
mCallbacks.add(callback);
|
this.mKVV = new KVV(this, this);
|
||||||
} else {
|
|
||||||
callback.get(this.mKVV);
|
|
||||||
}
|
}
|
||||||
|
return this.mKVV;
|
||||||
}
|
}
|
||||||
|
|
||||||
public CanteenBrowser getCanteenBrowser() {
|
public CanteenBrowser getCanteenBrowser() {
|
||||||
@@ -517,7 +348,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
setRefreshFailedBanner(false);
|
setRefreshFailedBanner(false);
|
||||||
updateNavigation();
|
updateNavigation();
|
||||||
changeFragment(getDefaultFragmentAfterLogout());
|
changeFragment(getDefaultFragmentAfterLogout());
|
||||||
//mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
|
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void toLoginState(String fullName, String email, int newFragment) {
|
private void toLoginState(String fullName, String email, int newFragment) {
|
||||||
@@ -531,29 +362,14 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void registerSync() {
|
private void registerSync() {
|
||||||
registerSync(false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void registerSync(boolean isLogin) {
|
|
||||||
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
||||||
if (accountByType != null) {
|
if (accountByType != null) {
|
||||||
if (isLogin || (ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME))) {
|
|
||||||
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
|
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
|
||||||
}
|
|
||||||
ContentResolver.addPeriodicSync(
|
ContentResolver.addPeriodicSync(
|
||||||
accountByType,
|
accountByType,
|
||||||
KVVContentProvider.PROVIDER_NAME,
|
KVVContentProvider.PROVIDER_NAME,
|
||||||
Bundle.EMPTY,
|
Bundle.EMPTY,
|
||||||
Long.parseLong(Preferences.getStringArray(this, R.array.pref_sync_frequency)) * 60 * 60
|
AccountGeneral.SYNC_INTERVAL);
|
||||||
);
|
|
||||||
forceSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void forceSync() {
|
|
||||||
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
|
||||||
if (accountByType != null && ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME)) {
|
|
||||||
ContentResolver.requestSync(accountByType, KVVContentProvider.PROVIDER_NAME, Bundle.EMPTY);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -578,15 +394,15 @@ public class MainActivity extends AppCompatActivity
|
|||||||
case FRAGMENT_MODULES:
|
case FRAGMENT_MODULES:
|
||||||
fragment = ModulesFragment.newInstance();
|
fragment = ModulesFragment.newInstance();
|
||||||
break;
|
break;
|
||||||
|
/*case FRAGMENT_LOGIN:
|
||||||
|
fragment = LoginFragment.newInstance();
|
||||||
|
break;*/
|
||||||
case FRAGMENT_SCHEDULE:
|
case FRAGMENT_SCHEDULE:
|
||||||
fragment = ScheduleFragment.newInstance();
|
fragment = ScheduleFragment.newInstance();
|
||||||
break;
|
break;
|
||||||
case FRAGMENT_CANTEENS_DETAILS:
|
case FRAGMENT_CANTEENS_DETAILS:
|
||||||
fragment = DaySwitcherFragment.newInstance(newData);
|
fragment = DaySwitcherFragment.newInstance(newData);
|
||||||
break;
|
break;
|
||||||
case FRAGMENT_CANTEENS_ADD:
|
|
||||||
fragment = CanteensAddFragment.newInstance();
|
|
||||||
break;
|
|
||||||
case FRAGMENT_CANTEENS:
|
case FRAGMENT_CANTEENS:
|
||||||
fragment = CanteensFragment.newInstance();
|
fragment = CanteensFragment.newInstance();
|
||||||
break;
|
break;
|
||||||
@@ -629,15 +445,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private void setNavigationSelection() {
|
private void setNavigationSelection() {
|
||||||
MenuItem item = null;
|
MenuItem item = null;
|
||||||
int dotPos = mFragmentData.indexOf(".");
|
|
||||||
String moduleId = mFragmentData;
|
|
||||||
if (dotPos != -1)
|
|
||||||
moduleId = moduleId.substring(0, dotPos);
|
|
||||||
switch (mFragmentPage) {
|
switch (mFragmentPage) {
|
||||||
case FRAGMENT_MODULES_DETAILS:
|
case FRAGMENT_MODULES_DETAILS:
|
||||||
String finalModuleId = moduleId;
|
getKVV().modules().list().find(mFragmentData, success -> {
|
||||||
getKVV(kvv -> {
|
|
||||||
kvv.modules().list().find(finalModuleId, 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;
|
||||||
@@ -649,7 +459,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
case FRAGMENT_MODULES:
|
case FRAGMENT_MODULES:
|
||||||
item = mNavigationView.getMenu().findItem(R.id.nav_modules);
|
item = mNavigationView.getMenu().findItem(R.id.nav_modules);
|
||||||
@@ -660,8 +469,8 @@ 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();
|
||||||
try {
|
|
||||||
Canteen canteen = success.getCanteen(Integer.parseInt(mFragmentData));
|
Canteen canteen = success.getCanteen(Integer.parseInt(mFragmentData));
|
||||||
|
//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++) {
|
||||||
MenuItem menuItem = mNavigationView.getMenu().getItem(k);
|
MenuItem menuItem = mNavigationView.getMenu().getItem(k);
|
||||||
@@ -670,13 +479,9 @@ public class MainActivity extends AppCompatActivity
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NumberFormatException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, log::e);
|
}, log::e);
|
||||||
return;
|
return;
|
||||||
case FRAGMENT_CANTEENS:
|
case FRAGMENT_CANTEENS:
|
||||||
case FRAGMENT_CANTEENS_ADD:
|
|
||||||
item = mNavigationView.getMenu().findItem(R.id.nav_canteens);
|
item = mNavigationView.getMenu().findItem(R.id.nav_canteens);
|
||||||
break;
|
break;
|
||||||
case FRAGMENT_NEWS:
|
case FRAGMENT_NEWS:
|
||||||
@@ -704,10 +509,10 @@ public class MainActivity extends AppCompatActivity
|
|||||||
if (!viewBtn.hasOnClickListeners())
|
if (!viewBtn.hasOnClickListeners())
|
||||||
viewBtn.setOnClickListener(v -> {
|
viewBtn.setOnClickListener(v -> {
|
||||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||||
if (drawer.isDrawerOpen(GravityCompat.START) && !isDrawerFixed) {
|
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||||
drawer.closeDrawer(GravityCompat.START);
|
drawer.closeDrawer(GravityCompat.START);
|
||||||
}
|
}
|
||||||
goToLoginScreen();
|
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -715,8 +520,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
int MAX_COUNT = isLoggedIn ? 3 : 2;
|
int MAX_COUNT = isLoggedIn ? 3 : 2;
|
||||||
final int[] count = {0};
|
final int[] count = {0};
|
||||||
if (isLoggedIn) {
|
if (isLoggedIn) {
|
||||||
getKVV(kvv -> {
|
getKVV().modules().list().recv(success -> {
|
||||||
kvv.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();
|
||||||
@@ -732,14 +536,13 @@ public class MainActivity extends AppCompatActivity
|
|||||||
if (++count[0] == MAX_COUNT) done.run();
|
if (++count[0] == MAX_COUNT) done.run();
|
||||||
log.e(error);
|
log.e(error);
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
getCanteenBrowser().getCanteens(success -> {
|
getCanteenBrowser().getCanteens(success -> {
|
||||||
int i = 0;
|
int i = 0;
|
||||||
for (Canteen canteen: success) {
|
for (Canteen canteen: success) {
|
||||||
MenuItem menuItem = mNavigationView.getMenu().add(Menu.NONE, Menu.NONE, 201 + i, canteen.getName());
|
MenuItem menuItem = mNavigationView.getMenu().add(Menu.NONE, Menu.NONE, 201 + i, canteen.getName());
|
||||||
menuItem.setOnMenuItemClickListener(item -> {
|
menuItem.setOnMenuItemClickListener(item -> {
|
||||||
this.onCanteensFragmentInteraction(canteen.getId());
|
onCanteensFragmentInteraction(canteen.getId());
|
||||||
return false;
|
return false;
|
||||||
});
|
});
|
||||||
i++;
|
i++;
|
||||||
@@ -772,8 +575,7 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
private void updateNavigation() {
|
private void updateNavigation() {
|
||||||
mQueue.add(() -> {
|
mQueue.add(() -> {
|
||||||
getKVV(kvv -> {
|
boolean isLoggedIn = getKVV().account().isLoggedIn();
|
||||||
boolean isLoggedIn = kvv.account().isLoggedIn();
|
|
||||||
setNavigationHeader(isLoggedIn);
|
setNavigationHeader(isLoggedIn);
|
||||||
mNavigationView.getMenu().clear();
|
mNavigationView.getMenu().clear();
|
||||||
if (isLoggedIn)
|
if (isLoggedIn)
|
||||||
@@ -785,7 +587,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
mQueue.next();
|
mQueue.next();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -805,11 +606,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
setNavigationSelection();
|
setNavigationSelection();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onModulesFragmentListUpdate(Function<Modules, Void> update) {
|
|
||||||
this.mMolduleListUpdateFunction = update;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCanteensFragmentInteraction(final int itemID) {
|
public void onCanteensFragmentInteraction(final int itemID) {
|
||||||
changeFragment(FRAGMENT_CANTEENS_DETAILS, String.valueOf(itemID));
|
changeFragment(FRAGMENT_CANTEENS_DETAILS, String.valueOf(itemID));
|
||||||
@@ -828,8 +624,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCanteenRefreshCompleted(boolean isFailed) {
|
public void onCanteenRefreshCompleted(boolean isFailed) {
|
||||||
if (!isFailed)
|
|
||||||
updateNavigation();
|
|
||||||
setRefreshFailedBanner(isFailed);
|
setRefreshFailedBanner(isFailed);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -864,21 +658,11 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onLogin(LoginTokenKVV tokenKVV, LoginTokenBB tokenBB, boolean isOnlyRefresh) {
|
public void onLogin(LoginToken token, boolean isOnlyRefresh) {
|
||||||
String fullName = "";
|
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin());
|
||||||
if (tokenKVV != null && !TextUtils.isEmpty(tokenKVV.getFullName())) {
|
if (!isOnlyRefresh) {
|
||||||
fullName = tokenKVV.getFullName();
|
registerSync();
|
||||||
} else if (tokenBB != null && !TextUtils.isEmpty(tokenBB.getUsername())) {
|
|
||||||
fullName = tokenBB.getUsername();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String email = "";
|
|
||||||
if (tokenKVV != null && !TextUtils.isEmpty(tokenKVV.getEmail()) && !"null".equals(tokenKVV.getEmail())) {
|
|
||||||
email = tokenKVV.getEmail();
|
|
||||||
} else if (tokenBB != null && !TextUtils.isEmpty(tokenBB.getUsername())) {
|
|
||||||
email = tokenBB.getUsername() + "@zedat.fu-berlin.de";
|
|
||||||
}
|
|
||||||
toLoginState(fullName, email, getDefaultFragmentAfterLogin());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -893,8 +677,6 @@ public class MainActivity extends AppCompatActivity
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onKVVNetworkResponse(NetworkResponse error) {
|
public void onKVVNetworkResponse(NetworkResponse error) {
|
||||||
if (error != null)
|
|
||||||
updateNavigation();
|
|
||||||
setRefreshFailedBanner(error != null);
|
setRefreshFailedBanner(error != null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -902,15 +684,4 @@ public class MainActivity extends AppCompatActivity
|
|||||||
public CustomAccountManager getAccountManager() {
|
public CustomAccountManager getAccountManager() {
|
||||||
return mAccountManager;
|
return mAccountManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface KVVCallback {
|
|
||||||
void get(KVV kvv);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onModuleListPartiallyUpdated(Modules modules) {
|
|
||||||
if (mMolduleListUpdateFunction != null) {
|
|
||||||
mMolduleListUpdateFunction.apply(modules);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,30 +6,20 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
import androidx.recyclerview.widget.RecyclerView;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
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.tools.ui.CanteensViewHolder;
|
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
|
||||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* {@link RecyclerView.Adapter} that can display a {@link Canteen} and makes a call to the
|
* {@link RecyclerView.Adapter} that can display a {@link Canteen} and makes a call to the
|
||||||
* specified {@link OnCanteensFragmentInteractionListener}.
|
* specified {@link OnCanteensFragmentInteractionListener}.
|
||||||
*/
|
*/
|
||||||
class CanteensAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
class CanteensAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
||||||
|
|
||||||
private static final int TYPE_DELETE_BUTTON = 1;
|
|
||||||
private static final int TYPE_ENTRY = 2;
|
|
||||||
private Canteens mValues;
|
private Canteens mValues;
|
||||||
private final OnCanteensFragmentInteractionListener mListener;
|
private final OnCanteensFragmentInteractionListener mListener;
|
||||||
private boolean mIsShowDeletion = false;
|
|
||||||
private ArrayList<Integer> mDeleteCanteenIds = new ArrayList<>();
|
|
||||||
private DeletionListener mDeletionListener;
|
|
||||||
|
|
||||||
CanteensAdapter(OnCanteensFragmentInteractionListener listener) {
|
CanteensAdapter(OnCanteensFragmentInteractionListener listener) {
|
||||||
mValues = null;
|
mValues = null;
|
||||||
@@ -43,50 +33,20 @@ class CanteensAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||||
if (viewType == TYPE_DELETE_BUTTON) {
|
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
View view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.list_canteens_btn_delete, parent, false);
|
.inflate(R.layout.list_all_items, parent, false);
|
||||||
return new StringViewHolder(view);
|
return new ItemViewHolder(view);
|
||||||
}
|
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(R.layout.list_canteens_items, parent, false);
|
|
||||||
return new CanteensViewHolder(view);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull CustomViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
|
||||||
int viewType = getItemViewType(position);
|
|
||||||
if (viewType == TYPE_DELETE_BUTTON) {
|
|
||||||
((StringViewHolder) holder).mString.setOnClickListener(v -> endDeletion());
|
|
||||||
} else {
|
|
||||||
if (mIsShowDeletion) {
|
|
||||||
position--;
|
|
||||||
}
|
|
||||||
if (mValues == null)
|
if (mValues == null)
|
||||||
return;
|
return;
|
||||||
Canteen canteen = mValues.get(position);
|
Canteen canteen = mValues.get(holder.getAdapterPosition());
|
||||||
((CanteensViewHolder) holder).mTitle.setText(canteen.getName());
|
holder.mTitle.setText(canteen.getName());
|
||||||
((CanteensViewHolder) holder).mSubLeft.setText(canteen.getAddress());
|
holder.mSubLeft.setText(canteen.getAddress());
|
||||||
((CanteensViewHolder) holder).mSubRight.setText(canteen.getCity());
|
holder.mSubRight.setText(canteen.getCity());
|
||||||
((CanteensViewHolder) holder).mActionIcon.setVisibility(mIsShowDeletion ? View.VISIBLE : View.GONE);
|
|
||||||
if (mDeleteCanteenIds.contains(canteen.getId())) {
|
|
||||||
((CanteensViewHolder) holder).mActionIcon.setImageDrawable(holder.mView.getResources().getDrawable(R.drawable.ic_remove_circle));
|
|
||||||
} else {
|
|
||||||
((CanteensViewHolder) holder).mActionIcon.setImageDrawable(holder.mView.getResources().getDrawable(R.drawable.ic_remove_circle_outline));
|
|
||||||
}
|
|
||||||
((CanteensViewHolder) holder).mActionIcon.setOnClickListener(v -> {
|
|
||||||
if (mDeleteCanteenIds.contains(canteen.getId())) {
|
|
||||||
// Prevent calling remove with index
|
|
||||||
//noinspection SuspiciousMethodCalls
|
|
||||||
mDeleteCanteenIds.remove((Object) canteen.getId());
|
|
||||||
} else {
|
|
||||||
mDeleteCanteenIds.add(canteen.getId());
|
|
||||||
}
|
|
||||||
notifyDataSetChanged();
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
holder.mView.setOnClickListener(v -> {
|
holder.mView.setOnClickListener(v -> {
|
||||||
if (null != mListener) {
|
if (null != mListener) {
|
||||||
@@ -96,42 +56,12 @@ class CanteensAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
if (mValues != null) {
|
if (mValues != null) {
|
||||||
return mIsShowDeletion ? mValues.size() + 1 : mValues.size();
|
return mValues.size();
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemViewType(int position) {
|
|
||||||
return mIsShowDeletion && position == 0 ? TYPE_DELETE_BUTTON : TYPE_ENTRY;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startDeletion(DeletionListener listener) {
|
|
||||||
mDeletionListener = listener;
|
|
||||||
if (mValues.size() > 0) {
|
|
||||||
mDeleteCanteenIds.clear();
|
|
||||||
mIsShowDeletion = true;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void endDeletion() {
|
|
||||||
int[] canteenIds = new int[mDeleteCanteenIds.size()];
|
|
||||||
for (int i = 0; i < mDeleteCanteenIds.size(); i++) {
|
|
||||||
canteenIds[i] = mDeleteCanteenIds.get(i);
|
|
||||||
}
|
|
||||||
mDeletionListener.onDeletionFinished(canteenIds);
|
|
||||||
mDeleteCanteenIds.clear();
|
|
||||||
mIsShowDeletion = false;
|
|
||||||
notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface DeletionListener {
|
|
||||||
void onDeletionFinished(int[] canteenIds);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,14 +11,10 @@ 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 java.util.ArrayList;
|
|
||||||
|
|
||||||
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.canteen.CanteenBrowser;
|
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -86,7 +82,7 @@ public class CanteensFragment extends Fragment {
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof OnCanteensFragmentInteractionListener) {
|
if (context instanceof OnCanteensFragmentInteractionListener) {
|
||||||
mListener = (OnCanteensFragmentInteractionListener) context;
|
mListener = (OnCanteensFragmentInteractionListener) context;
|
||||||
@@ -108,37 +104,6 @@ public class CanteensFragment extends Fragment {
|
|||||||
mMainActivityListener = null;
|
mMainActivityListener = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void restoreDefaults() {
|
|
||||||
Preferences.setArrayInt(requireContext(), R.string.pref_canteen_selection, null);
|
|
||||||
this.refresh(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void startDelete() {
|
|
||||||
adapter.startDeletion(items -> {
|
|
||||||
int[] canteens = Preferences.getArrayInt(requireContext(), R.string.pref_canteen_selection);
|
|
||||||
if (canteens != null) {
|
|
||||||
ArrayList<Integer> newList = new ArrayList<>();
|
|
||||||
for (int canteen : canteens) {
|
|
||||||
boolean found = false;
|
|
||||||
for (int item : items) {
|
|
||||||
if (item == canteen) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
newList.add(canteen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int[] newCants = new int[newList.size()];
|
|
||||||
for (int i = 0; i < newList.size(); i++)
|
|
||||||
newCants[i] = newList.get(i);
|
|
||||||
Preferences.setArrayInt(requireContext(), R.string.pref_canteen_selection, newCants);
|
|
||||||
}
|
|
||||||
this.refresh(true);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
public interface OnCanteensFragmentInteractionListener {
|
public interface OnCanteensFragmentInteractionListener {
|
||||||
void onCanteensFragmentInteraction(int id);
|
void onCanteensFragmentInteraction(int id);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,10 +40,12 @@ class ModulesAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
public void setModules(Modules modules) {
|
public void setModules(Modules modules) {
|
||||||
mValues = modules;
|
mValues = modules;
|
||||||
mPositionalData.clear();
|
mPositionalData.clear();
|
||||||
Semester lastSemester = new Semester(Semester.SEM_WS, 0);
|
Semester lastSemester = null;
|
||||||
for (Modules.Module module : mValues) {
|
for (Modules.Module module : mValues) {
|
||||||
Semester semester = module.semester;
|
Semester semester = module.semester;
|
||||||
if (semester != null && !semester.equals(lastSemester) || semester == null && lastSemester != null) {
|
if (semester == null)
|
||||||
|
continue;
|
||||||
|
if (!semester.equals(lastSemester)) {
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, semester));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, semester));
|
||||||
lastSemester = semester;
|
lastSemester = semester;
|
||||||
}
|
}
|
||||||
@@ -78,9 +80,7 @@ class ModulesAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
StringViewHolder sHolder = (StringViewHolder) holder;
|
StringViewHolder sHolder = (StringViewHolder) holder;
|
||||||
String localizedSemester;
|
String localizedSemester;
|
||||||
Semester semester = (Semester) pair.second;
|
Semester semester = (Semester) pair.second;
|
||||||
if (semester == null)
|
if (semester.getType() == Semester.SEM_WS)
|
||||||
localizedSemester = holder.mView.getResources().getString(R.string.others);
|
|
||||||
else if (semester.getType() == Semester.SEM_WS)
|
|
||||||
localizedSemester = holder.mView.getResources().getString(R.string.winter_semester, semester.getYear(), semester.getYear()+1);
|
localizedSemester = holder.mView.getResources().getString(R.string.winter_semester, semester.getYear(), semester.getYear()+1);
|
||||||
else
|
else
|
||||||
localizedSemester = holder.mView.getResources().getString(R.string.summer_semester, semester.getYear());
|
localizedSemester = holder.mView.getResources().getString(R.string.summer_semester, semester.getYear());
|
||||||
@@ -98,8 +98,6 @@ class ModulesAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
lecturers.append(lecturer.getNameShort());
|
lecturers.append(lecturer.getNameShort());
|
||||||
}
|
}
|
||||||
iHolder.mSubLeft.setText(lecturers);
|
iHolder.mSubLeft.setText(lecturers);
|
||||||
// {'G', 'V-Ue', 'P', 'S', 'V', 'Ue', 'L'}
|
|
||||||
// {'Vorlesung', 'Übung', 'Praktikum', 'Zentralübung', 'Seminaristische Übung', 'Integrierte Veranstaltung', 'Seminar am PC', 'Praxisseminar', 'Seminar', 'Projektseminar', 'Projekt'}
|
|
||||||
iHolder.mSubRight.setText(module.type);
|
iHolder.mSubRight.setText(module.type);
|
||||||
|
|
||||||
iHolder.mView.setOnClickListener(v -> {
|
iHolder.mView.setOnClickListener(v -> {
|
||||||
|
|||||||
@@ -8,13 +8,11 @@ import android.view.ViewGroup;
|
|||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import androidx.arch.core.util.Function;
|
|
||||||
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.R;
|
import de.sebse.fuplanner.R;
|
||||||
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;
|
||||||
|
|
||||||
@@ -68,28 +66,24 @@ public class ModulesFragment extends Fragment {
|
|||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mMainActivityListener != null) {
|
if (mMainActivityListener != null) {
|
||||||
mMainActivityListener.getKVV(kvv -> {
|
mMainActivityListener.getKVV().modules().list().recv(success -> {
|
||||||
kvv.modules().list().recv(success -> {
|
|
||||||
adapter.setModules(success);
|
adapter.setModules(success);
|
||||||
|
//if (mMainActivityListener != null)
|
||||||
|
// mMainActivityListener.refreshNavigation();
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, error -> {
|
}, error -> {
|
||||||
log.e(error.toString());
|
log.e(error.toString());
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof OnModulesFragmentInteractionListener) {
|
if (context instanceof OnModulesFragmentInteractionListener) {
|
||||||
mListener = (OnModulesFragmentInteractionListener) context;
|
mListener = (OnModulesFragmentInteractionListener) context;
|
||||||
mListener.onModulesFragmentListUpdate(modules -> {
|
|
||||||
if (adapter != null) adapter.setModules(modules);
|
|
||||||
return null;
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
throw new RuntimeException(context.toString()
|
throw new RuntimeException(context.toString()
|
||||||
+ " must implement OnModulesFragmentInteractionListener");
|
+ " must implement OnModulesFragmentInteractionListener");
|
||||||
@@ -111,6 +105,5 @@ public class ModulesFragment extends Fragment {
|
|||||||
|
|
||||||
public interface OnModulesFragmentInteractionListener {
|
public interface OnModulesFragmentInteractionListener {
|
||||||
void onModulesFragmentInteraction(String id);
|
void onModulesFragmentInteraction(String id);
|
||||||
void onModulesFragmentListUpdate(Function<Modules, Void> update);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,11 @@ public class NewsFragment extends Fragment {
|
|||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
private MainActivityListener mListener;
|
private MainActivityListener mListener;
|
||||||
private NewsAdapter mAdapter;
|
private NewsAdapter mAdapter;
|
||||||
|
private NewsList dates = new NewsList();
|
||||||
|
// TODO: Rename parameter arguments, choose names that match
|
||||||
|
// the fragment initialization parameters, e.g. ARG_ITEM_NUMBER
|
||||||
|
|
||||||
|
// TODO: Rename and change types of parameters
|
||||||
|
|
||||||
|
|
||||||
public NewsFragment() {
|
public NewsFragment() {
|
||||||
@@ -48,7 +53,7 @@ public class NewsFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
mListener = (MainActivityListener) context;
|
mListener = (MainActivityListener) context;
|
||||||
|
|||||||
@@ -1,38 +1,16 @@
|
|||||||
package de.sebse.fuplanner.fragments;
|
package de.sebse.fuplanner.fragments;
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.SharedPreferences;
|
import android.content.SharedPreferences;
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.util.Log;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
import androidx.core.app.ActivityCompat;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import androidx.preference.ListPreference;
|
import androidx.preference.ListPreference;
|
||||||
import androidx.preference.Preference;
|
import androidx.preference.Preference;
|
||||||
import androidx.preference.PreferenceFragmentCompat;
|
import androidx.preference.PreferenceFragmentCompat;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
|
||||||
import de.sebse.fuplanner.services.kvv.sync.KVVContentProvider;
|
|
||||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
|
||||||
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
public class PrefsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
public class PrefsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||||
|
|
||||||
private MainActivityListener mMainActivityListener;
|
|
||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
|
|
||||||
public static PrefsFragment newInstance() {
|
public static PrefsFragment newInstance() {
|
||||||
@@ -47,7 +25,7 @@ public class PrefsFragment extends PreferenceFragmentCompat implements SharedPre
|
|||||||
// Load the preferences from an XML resource
|
// Load the preferences from an XML resource
|
||||||
setPreferencesFromResource(R.xml.preferences, rootKey);
|
setPreferencesFromResource(R.xml.preferences, rootKey);
|
||||||
for (String s : getPreferenceScreen().getSharedPreferences().getAll().keySet()) {
|
for (String s : getPreferenceScreen().getSharedPreferences().getAll().keySet()) {
|
||||||
updateListPreferenceSummary(s);
|
onSharedPreferenceChanged(getPreferenceScreen().getSharedPreferences(), s);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -65,87 +43,8 @@ public class PrefsFragment extends PreferenceFragmentCompat implements SharedPre
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||||
updateListPreferenceSummary(s);
|
|
||||||
|
|
||||||
if (s.equals(requireContext().getString(R.string.pref_sync_frequency))) {
|
|
||||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
|
||||||
CustomAccountManager accountManager = ((MainActivity) getActivity()).getAccountManager();
|
|
||||||
if (accountManager != null) {
|
|
||||||
Account accountByType = accountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
|
||||||
if (accountByType != null) {
|
|
||||||
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
|
|
||||||
ContentResolver.addPeriodicSync(
|
|
||||||
accountByType,
|
|
||||||
KVVContentProvider.PROVIDER_NAME,
|
|
||||||
Bundle.EMPTY,
|
|
||||||
Long.parseLong(Preferences.getStringArray(getActivity(), R.array.pref_sync_frequency)));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s.equals(requireContext().getString(R.string.pref_night_mode))) {
|
|
||||||
String nightMode = Preferences.getStringArray(requireContext(), R.array.pref_night_mode);
|
|
||||||
switch (nightMode) {
|
|
||||||
case "night":
|
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
|
|
||||||
break;
|
|
||||||
case "day":
|
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_FOLLOW_SYSTEM);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (s.equals(requireContext().getString(R.string.pref_add_calendar))
|
|
||||||
&& getActivity() != null
|
|
||||||
&& Preferences.getBoolean(getActivity(), R.string.pref_add_calendar)) {
|
|
||||||
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED
|
|
||||||
|| ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_CALENDAR, Manifest.permission.READ_CALENDAR}, 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (s.equals(requireContext().getString(R.string.pref_add_calendar)) && mMainActivityListener != null) {
|
|
||||||
log.d("Force sync...");
|
|
||||||
mMainActivityListener.forceSync();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void updateListPreferenceSummary(String s) {
|
|
||||||
Preference preference = getPreferenceScreen().findPreference(s);
|
Preference preference = getPreferenceScreen().findPreference(s);
|
||||||
if (preference instanceof ListPreference)
|
if (preference instanceof ListPreference)
|
||||||
preference.setSummary(((ListPreference) preference).getEntry());
|
preference.setSummary(((ListPreference) preference).getEntry());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(@NonNull Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
if (context instanceof MainActivityListener) {
|
|
||||||
mMainActivityListener = (MainActivityListener) context;
|
|
||||||
mMainActivityListener.onTitleTextChange(R.string.settings);
|
|
||||||
mMainActivityListener.addRequestPermissionsResultListener(getRequestPermissionsResultListener(), "PrefFragment");
|
|
||||||
} else
|
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetach() {
|
|
||||||
super.onDetach();
|
|
||||||
mMainActivityListener.removeRequestPermissionsResultListener("PrefFragment");
|
|
||||||
mMainActivityListener = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private RequestPermissionsResultListener getRequestPermissionsResultListener() {
|
|
||||||
return (requestCode, permissions, grantResults) -> {
|
|
||||||
if (ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.WRITE_CALENDAR) != PackageManager.PERMISSION_GRANTED
|
|
||||||
|| ContextCompat.checkSelfPermission(requireContext(), Manifest.permission.READ_CALENDAR) != PackageManager.PERMISSION_GRANTED) {
|
|
||||||
Preferences.setBoolean(requireContext(), R.string.pref_add_calendar, false);
|
|
||||||
setPreferenceScreen(null);
|
|
||||||
setPreferencesFromResource(R.xml.preferences, null);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
@@ -18,9 +18,8 @@ import androidx.fragment.app.Fragment;
|
|||||||
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;
|
||||||
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.MainActivityListener;
|
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
|
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.weekview.MonthLoader;
|
import de.sebse.fuplanner.tools.ui.weekview.MonthLoader;
|
||||||
import de.sebse.fuplanner.tools.ui.weekview.WeekView;
|
import de.sebse.fuplanner.tools.ui.weekview.WeekView;
|
||||||
@@ -64,14 +63,11 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
|
|
||||||
public void invalidate(boolean forceRefresh) {
|
public void invalidate(boolean forceRefresh) {
|
||||||
if (mListener == null) return;
|
if (mListener == null) return;
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV().modules().list().recv(modules -> {
|
||||||
kvv.modules().list().recv(modules -> {
|
|
||||||
mModules = modules;
|
mModules = modules;
|
||||||
final int[] i = {0};
|
final int[] i = {0};
|
||||||
Iterator<Modules.Module> iter = mModules.latestSemesterIterator();
|
for (Modules.Module module: mModules) {
|
||||||
while (iter.hasNext()) {
|
mListener.getKVV().modules().events().recv(module, success1 -> {
|
||||||
Modules.Module module = iter.next();
|
|
||||||
kvv.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) {
|
||||||
@@ -82,7 +78,6 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
}, log::e, forceRefresh);
|
}, log::e, forceRefresh);
|
||||||
}
|
}
|
||||||
}, log::e, forceRefresh);
|
}, log::e, forceRefresh);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@@ -103,7 +98,7 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
mListener = (MainActivityListener) context;
|
mListener = (MainActivityListener) context;
|
||||||
@@ -124,11 +119,7 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
|
public List<? extends WeekViewEvent> onMonthChange(int newYear, int newMonth) {
|
||||||
ArrayList<WeekViewEvent> events = new ArrayList<>();
|
ArrayList<WeekViewEvent> events = new ArrayList<>();
|
||||||
if (mModules != null){
|
if (mModules != null){
|
||||||
Semester latestSemester = mModules.getLatestSemester();
|
|
||||||
for (Modules.Module mod: mModules) {
|
for (Modules.Module mod: mModules) {
|
||||||
if (mod.getModuleType() == Modules.TYPE_BB && mod.semester != null && !mod.semester.equals(latestSemester)) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (mod.events != null) {
|
if (mod.events != null) {
|
||||||
Iterator<Event> it_modEvents = mod.events.getEventsOfMonth(newYear, newMonth);
|
Iterator<Event> it_modEvents = mod.events.getEventsOfMonth(newYear, newMonth);
|
||||||
while (it_modEvents.hasNext()) {
|
while (it_modEvents.hasNext()) {
|
||||||
@@ -140,7 +131,7 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
start.setTimeInMillis(e.getStartDate());
|
start.setTimeInMillis(e.getStartDate());
|
||||||
|
|
||||||
WeekViewEvent weekViewEvent = new WeekViewEvent(e.getModuleId()+"/"+e.getId(), e.getTitle(), e.getLocation(), start, end);
|
WeekViewEvent weekViewEvent = new WeekViewEvent(e.getModuleId()+"/"+e.getId(), e.getTitle(), e.getLocation(), start, end);
|
||||||
weekViewEvent.setColor(e.getColor(getContext()));
|
weekViewEvent.setColor(e.getColor());
|
||||||
events.add(weekViewEvent);
|
events.add(weekViewEvent);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -189,8 +180,7 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(getContext());
|
||||||
|
|
||||||
if (mListener == null) return;
|
if (mListener == null) return;
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV().modules().list().find(moduleId, module -> {
|
||||||
kvv.modules().list().find(moduleId, module -> {
|
|
||||||
String moduleName = module.title;
|
String moduleName = module.title;
|
||||||
alertDialogBuilder
|
alertDialogBuilder
|
||||||
.setTitle(event.getName())
|
.setTitle(event.getName())
|
||||||
@@ -205,6 +195,5 @@ public class ScheduleFragment extends Fragment implements
|
|||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
AlertDialog alertDialog = alertDialogBuilder.create();
|
||||||
alertDialog.show();
|
alertDialog.show();
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,108 +0,0 @@
|
|||||||
package de.sebse.fuplanner.fragments.canteen;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
|
||||||
import de.sebse.fuplanner.services.canteen.types.Canteens;
|
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
|
||||||
import de.sebse.fuplanner.tools.ui.CanteensViewHolder;
|
|
||||||
|
|
||||||
class CanteensAddAdapter extends RecyclerView.Adapter<CanteensViewHolder> {
|
|
||||||
private int[] mElements;
|
|
||||||
private Canteens mCanteens = null;
|
|
||||||
@Nullable
|
|
||||||
private CanteenAddedInterface mCanteenAddedInterface;
|
|
||||||
private Canteens mValues = null;
|
|
||||||
private String mFilter = "";
|
|
||||||
private final Context mContext;
|
|
||||||
Logger log = new Logger(this);
|
|
||||||
|
|
||||||
public CanteensAddAdapter(Context context, @Nullable CanteenAddedInterface canteenAddedInterface) {
|
|
||||||
mCanteenAddedInterface = canteenAddedInterface;
|
|
||||||
mContext = context;
|
|
||||||
mElements = Preferences.getArrayInt(mContext, R.string.pref_canteen_selection);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setFilterString(String filter) {
|
|
||||||
mFilter = filter;
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCanteens(Canteens canteens) {
|
|
||||||
mCanteens = canteens;
|
|
||||||
this.update();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void update() {
|
|
||||||
if (mCanteens == null || mFilter == null) {
|
|
||||||
mValues = null;
|
|
||||||
} else {
|
|
||||||
mValues = new Canteens();
|
|
||||||
for (Canteen canteen : mCanteens) {
|
|
||||||
boolean found = false;
|
|
||||||
for (int element : mElements) {
|
|
||||||
if (element == canteen.getId()) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found && canteen.contains(mFilter)) {
|
|
||||||
mValues.addCanteen(canteen);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
this.notifyDataSetChanged();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public CanteensViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
|
||||||
View view = LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(R.layout.list_canteens_items, parent, false);
|
|
||||||
return new CanteensViewHolder(view);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onBindViewHolder(@NonNull CanteensViewHolder holder, int position) {
|
|
||||||
if (mValues == null)
|
|
||||||
return;
|
|
||||||
Canteen canteen = mValues.get(position);
|
|
||||||
holder.mTitle.setText(canteen.getName());
|
|
||||||
holder.mSubLeft.setText(canteen.getAddress());
|
|
||||||
holder.mSubRight.setText(canteen.getCity());
|
|
||||||
holder.mActionIcon.setVisibility(View.VISIBLE);
|
|
||||||
holder.mActionIcon.setImageDrawable(holder.mView.getResources().getDrawable(R.drawable.ic_add_circle_outline));
|
|
||||||
holder.mActionIcon.setOnClickListener(v -> {
|
|
||||||
mElements = Arrays.copyOf(mElements, mElements.length + 1);
|
|
||||||
mElements[mElements.length - 1] = canteen.getId();
|
|
||||||
|
|
||||||
Preferences.setArrayInt(mContext, R.string.pref_canteen_selection, mElements);
|
|
||||||
if (mCanteenAddedInterface != null)
|
|
||||||
mCanteenAddedInterface.onCanteenAdded(canteen.getId());
|
|
||||||
update();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getItemCount() {
|
|
||||||
if (mValues != null) {
|
|
||||||
return mValues.size();
|
|
||||||
}
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
interface CanteenAddedInterface {
|
|
||||||
void onCanteenAdded(int canteenId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,129 +0,0 @@
|
|||||||
package de.sebse.fuplanner.fragments.canteen;
|
|
||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
|
||||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
|
||||||
import androidx.recyclerview.widget.RecyclerView;
|
|
||||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
|
||||||
|
|
||||||
import android.text.Editable;
|
|
||||||
import android.text.TextWatcher;
|
|
||||||
import android.view.LayoutInflater;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.ViewGroup;
|
|
||||||
import android.widget.EditText;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
|
||||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* A simple {@link Fragment} subclass.
|
|
||||||
*/
|
|
||||||
public class CanteensAddFragment extends Fragment implements CanteensAddAdapter.CanteenAddedInterface {
|
|
||||||
private CanteensAddAdapter adapter;
|
|
||||||
private SwipeRefreshLayout swipeLayout;
|
|
||||||
private MainActivityListener mMainActivityListener;
|
|
||||||
private final Logger log = new Logger(this);
|
|
||||||
|
|
||||||
|
|
||||||
public CanteensAddFragment() {
|
|
||||||
// Required empty public constructor
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Use this factory method to create a new instance of
|
|
||||||
* this fragment using the provided parameters.
|
|
||||||
*
|
|
||||||
* @return A new instance of fragment CanteensAddFragment.
|
|
||||||
*/
|
|
||||||
// TODO: Rename and change types and number of parameters
|
|
||||||
public static CanteensAddFragment newInstance() {
|
|
||||||
CanteensAddFragment fragment = new CanteensAddFragment();
|
|
||||||
Bundle args = new Bundle();
|
|
||||||
fragment.setArguments(args);
|
|
||||||
return fragment;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public View onCreateView(LayoutInflater inflater, ViewGroup container,
|
|
||||||
Bundle savedInstanceState) {
|
|
||||||
// Inflate the layout for this fragment
|
|
||||||
View view = inflater.inflate(R.layout.fragment_canteens_add, container, false);
|
|
||||||
|
|
||||||
// Set the adapter
|
|
||||||
Context context = view.getContext();
|
|
||||||
RecyclerView recyclerView = view.findViewById(R.id.list);
|
|
||||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
|
||||||
adapter = new CanteensAddAdapter(context, this);
|
|
||||||
recyclerView.setAdapter(adapter);
|
|
||||||
|
|
||||||
// Getting SwipeContainerLayout
|
|
||||||
swipeLayout = view.findViewById(R.id.swipe_container);
|
|
||||||
// Adding Listener
|
|
||||||
swipeLayout.setOnRefreshListener(() -> refresh(true));
|
|
||||||
refresh(false);
|
|
||||||
EditText searchBox = view.findViewById(R.id.search_box);
|
|
||||||
searchBox.addTextChangedListener(new TextWatcher() {
|
|
||||||
@Override
|
|
||||||
public void beforeTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onTextChanged(CharSequence charSequence, int i, int i1, int i2) {
|
|
||||||
adapter.setFilterString(charSequence.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void afterTextChanged(Editable editable) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return view;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(@NonNull Context context) {
|
|
||||||
super.onAttach(context);
|
|
||||||
if (context instanceof MainActivityListener) {
|
|
||||||
mMainActivityListener = (MainActivityListener) context;
|
|
||||||
mMainActivityListener.onTitleTextChange(R.string.canteens);
|
|
||||||
} else
|
|
||||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDetach() {
|
|
||||||
super.onDetach();
|
|
||||||
mMainActivityListener = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
|
||||||
if (getActivity() != null) {
|
|
||||||
CanteenBrowser browser = ((MainActivity) getActivity()).getCanteenBrowser();
|
|
||||||
browser.getAvailableCanteens(success -> {
|
|
||||||
adapter.setCanteens(success);
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
}, error -> {
|
|
||||||
log.e(error.toString());
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
}, forceRefresh);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCanteenAdded(int canteenId) {
|
|
||||||
if (getActivity() != null) {
|
|
||||||
CanteenBrowser browser = ((MainActivity) getActivity()).getCanteenBrowser();
|
|
||||||
browser.getCanteens(success -> {}, error -> {}, true);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,6 +1,5 @@
|
|||||||
package de.sebse.fuplanner.fragments.canteen;
|
package de.sebse.fuplanner.fragments.canteen;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
@@ -12,15 +11,15 @@ class DaySwitcherAdapter extends FragmentStatePagerAdapter {
|
|||||||
private Canteen mCanteen = null;
|
private Canteen mCanteen = null;
|
||||||
|
|
||||||
DaySwitcherAdapter(FragmentManager fm) {
|
DaySwitcherAdapter(FragmentManager fm) {
|
||||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
super(fm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCanteen(Canteen canteen) {
|
public void setModule(Canteen canteen) {
|
||||||
mCanteen = canteen;
|
mCanteen = canteen;
|
||||||
this.setCanteen();
|
this.setModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCanteen() {
|
public void setModule() {
|
||||||
this.notifyDataSetChanged();
|
this.notifyDataSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -32,7 +31,6 @@ class DaySwitcherAdapter extends FragmentStatePagerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the fragment to display for that page
|
// Returns the fragment to display for that page
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
return MealFragment.newInstance(mCanteen.getId(), position);
|
return MealFragment.newInstance(mCanteen.getId(), position);
|
||||||
|
|||||||
@@ -101,7 +101,7 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
mListener = (MainActivityListener) context;
|
mListener = (MainActivityListener) context;
|
||||||
@@ -127,10 +127,10 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
|||||||
browser.getCanteens(canteens -> {
|
browser.getCanteens(canteens -> {
|
||||||
Canteen canteen = canteens.getCanteen(mCanteenId);
|
Canteen canteen = canteens.getCanteen(mCanteenId);
|
||||||
canteen.cleanUpDays();
|
canteen.cleanUpDays();
|
||||||
adapterViewPager.setCanteen(canteen);
|
adapterViewPager.setModule(canteen);
|
||||||
applyPageRequest();
|
applyPageRequest();
|
||||||
browser.getCanteen(canteen, success -> {
|
browser.getCanteen(canteen, success -> {
|
||||||
adapterViewPager.setCanteen();
|
adapterViewPager.setModule();
|
||||||
applyPageRequest();
|
applyPageRequest();
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.onResponse(success);
|
callback.onResponse(success);
|
||||||
|
|||||||
@@ -27,10 +27,6 @@ class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||||||
private final int CATEGORY_OTHER = R.string.others;
|
private final int CATEGORY_OTHER = R.string.others;
|
||||||
private final ArrayList<Object> matches = new ArrayList<>();
|
private final ArrayList<Object> matches = new ArrayList<>();
|
||||||
|
|
||||||
private static final int TYPE_MEAL = 0;
|
|
||||||
private static final int TYPE_HEADER = 1;
|
|
||||||
private static final int TYPE_LEGEND = 2;
|
|
||||||
|
|
||||||
private Day mDay = null;
|
private Day mDay = null;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
@@ -41,30 +37,26 @@ class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup viewGroup, int viewType) {
|
||||||
if (viewType == TYPE_MEAL) {
|
if (viewType == 0) {
|
||||||
View view = LayoutInflater.from(viewGroup.getContext())
|
View view = LayoutInflater.from(viewGroup.getContext())
|
||||||
.inflate(R.layout.list_canteen_items, viewGroup, false);
|
.inflate(R.layout.list_canteen_items, viewGroup, false);
|
||||||
return new MealViewHolder(view);
|
return new MealViewHolder(view);
|
||||||
} else if (viewType == TYPE_HEADER) {
|
|
||||||
View view = LayoutInflater.from(viewGroup.getContext())
|
|
||||||
.inflate(R.layout.list_all_caption, viewGroup, false);
|
|
||||||
return new StringViewHolder(view);
|
|
||||||
} else {
|
} else {
|
||||||
View view = LayoutInflater.from(viewGroup.getContext())
|
View view = LayoutInflater.from(viewGroup.getContext())
|
||||||
.inflate(R.layout.list_canteen_legend, viewGroup, false);
|
.inflate(R.layout.list_all_caption, viewGroup, false);
|
||||||
return new StringViewHolder(view);
|
return new StringViewHolder(view);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {
|
||||||
if (holder.getItemViewType() == TYPE_MEAL) {
|
if (holder.getItemViewType() == 0) {
|
||||||
MealViewHolder viewHolder = ((MealViewHolder) holder);
|
MealViewHolder viewHolder = ((MealViewHolder) holder);
|
||||||
viewHolder.reset();
|
viewHolder.reset();
|
||||||
Meal meal = getMeal(position);
|
Meal meal = getMeal(position);
|
||||||
viewHolder.mTitle.setText(meal.getName());
|
viewHolder.mTitle.setText(meal.getName());
|
||||||
String value;
|
String value;
|
||||||
switch (Preferences.getStringArray(mContext, R.array.pref_price_group)) {
|
switch (Preferences.getString(mContext, R.array.pref_price_group)) {
|
||||||
case "student":
|
case "student":
|
||||||
if (meal.getPriceStdnt() < 0)
|
if (meal.getPriceStdnt() < 0)
|
||||||
value = mContext.getResources().getString(R.string.no_price_available);
|
value = mContext.getResources().getString(R.string.no_price_available);
|
||||||
@@ -115,7 +107,7 @@ class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||||||
viewHolder.mIconVegetarian.setVisibility(meal.getVegan() == Meal.VEGAN_VEGETARIAN ? View.VISIBLE : View.GONE);
|
viewHolder.mIconVegetarian.setVisibility(meal.getVegan() == Meal.VEGAN_VEGETARIAN ? View.VISIBLE : View.GONE);
|
||||||
viewHolder.mIconBio.setVisibility((meal.getCertificates() & Meal.CERT_BIO) != 0 ? View.VISIBLE : View.GONE);
|
viewHolder.mIconBio.setVisibility((meal.getCertificates() & Meal.CERT_BIO) != 0 ? View.VISIBLE : View.GONE);
|
||||||
viewHolder.mIconMsc.setVisibility((meal.getCertificates() & Meal.CERT_MSC) != 0 ? View.VISIBLE : View.GONE);
|
viewHolder.mIconMsc.setVisibility((meal.getCertificates() & Meal.CERT_MSC) != 0 ? View.VISIBLE : View.GONE);
|
||||||
} else if (holder.getItemViewType() == TYPE_HEADER) {
|
} else {
|
||||||
StringViewHolder viewHolder = ((StringViewHolder) holder);
|
StringViewHolder viewHolder = ((StringViewHolder) holder);
|
||||||
viewHolder.mString.setText(getHeading(position));
|
viewHolder.mString.setText(getHeading(position));
|
||||||
}
|
}
|
||||||
@@ -123,25 +115,23 @@ class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemCount() {
|
public int getItemCount() {
|
||||||
return matches.size() + 1;
|
return matches.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
if (position == 0)
|
return matches.get(position) instanceof String ? 1 : 0;
|
||||||
return TYPE_LEGEND;
|
|
||||||
return matches.get(position - 1) instanceof String ? TYPE_HEADER : TYPE_MEAL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Meal getMeal(int position) {
|
private Meal getMeal(int position) {
|
||||||
if (this.mDay != null)
|
if (this.mDay != null)
|
||||||
return this.mDay.get((Integer) matches.get(position - 1));
|
return this.mDay.get((Integer) matches.get(position));
|
||||||
else
|
else
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getHeading(int position) {
|
private String getHeading(int position) {
|
||||||
return (String) matches.get(position - 1);
|
return (String) matches.get(position);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDay(Day day) {
|
public void setDay(Day day) {
|
||||||
@@ -151,13 +141,8 @@ class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
|||||||
|
|
||||||
public void setDay() {
|
public void setDay() {
|
||||||
HashMap<String, ArrayList<Integer>> map = new HashMap<>();
|
HashMap<String, ArrayList<Integer>> map = new HashMap<>();
|
||||||
String foodLevel = Preferences.getStringArray(mContext, R.array.pref_food_level);
|
|
||||||
for (int i = 0; i < this.mDay.size(); i++) {
|
for (int i = 0; i < this.mDay.size(); i++) {
|
||||||
Meal meal = this.mDay.get(i);
|
String category = this.mDay.get(i).getCategory();
|
||||||
if (!(meal.getVegan() == Meal.VEGAN_VEGAN || ("vegetarian".equals(foodLevel) && meal.getVegan() == Meal.VEGAN_VEGETARIAN) || "all".equals(foodLevel))) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
String category = meal.getCategory();
|
|
||||||
boolean found = false;
|
boolean found = false;
|
||||||
for (String category_key : CATEGORY_KEYS) {
|
for (String category_key : CATEGORY_KEYS) {
|
||||||
if (category_key.equals(category)) {
|
if (category_key.equals(category)) {
|
||||||
|
|||||||
@@ -85,7 +85,7 @@ public class MealFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
Fragment parentFragment = getParentFragment();
|
Fragment parentFragment = getParentFragment();
|
||||||
if (parentFragment != null) {
|
if (parentFragment != null) {
|
||||||
@@ -104,10 +104,6 @@ public class MealFragment extends Fragment {
|
|||||||
browser.getCanteens(canteens -> {
|
browser.getCanteens(canteens -> {
|
||||||
Canteen canteen = canteens.getCanteen(mCanteenId);
|
Canteen canteen = canteens.getCanteen(mCanteenId);
|
||||||
browser.getCanteen(canteen, success -> {
|
browser.getCanteen(canteen, success -> {
|
||||||
if (success.size() <= mDayPosition) {
|
|
||||||
swipeLayout.setRefreshing(false);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Day day = success.get(mDayPosition);
|
Day day = success.get(mDayPosition);
|
||||||
adapter.setDay(day);
|
adapter.setDay(day);
|
||||||
browser.getDay(day, success1 -> {
|
browser.getDay(day, success1 -> {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.fragment.app.Fragment;
|
import androidx.fragment.app.Fragment;
|
||||||
import androidx.fragment.app.FragmentManager;
|
import androidx.fragment.app.FragmentManager;
|
||||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||||
@@ -14,7 +12,7 @@ class ModDetailAdapter extends FragmentStatePagerAdapter {
|
|||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
|
|
||||||
ModDetailAdapter(FragmentManager fm, String itemPosition, Context context) {
|
ModDetailAdapter(FragmentManager fm, String itemPosition, Context context) {
|
||||||
super(fm, BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT);
|
super(fm);
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
this.mItemPos = itemPosition;
|
this.mItemPos = itemPosition;
|
||||||
}
|
}
|
||||||
@@ -27,7 +25,6 @@ class ModDetailAdapter extends FragmentStatePagerAdapter {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Returns the fragment to display for that page
|
// Returns the fragment to display for that page
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public Fragment getItem(int position) {
|
public Fragment getItem(int position) {
|
||||||
switch (ModulePart.getPartByPage(position)) {
|
switch (ModulePart.getPartByPage(position)) {
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ 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;
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.AnnouncementViewHolder;
|
import de.sebse.fuplanner.tools.ui.AnnouncementViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
|
|
||||||
class ModDetailAnnounceAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
class ModDetailAnnounceAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||||
|
|
||||||
@Nullable private Modules.Module mModule = null;
|
@Nullable private Modules.Module mModule = null;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
@NonNull private final Download.OnDownloadRequestInterface requestInterface;
|
@NonNull private final Download.OnDownloadRequestInterface requestInterface;
|
||||||
|
|
||||||
ModDetailAnnounceAdapter(@NonNull Download.OnDownloadRequestInterface requestInterface) {
|
ModDetailAnnounceAdapter(@NonNull Download.OnDownloadRequestInterface requestInterface) {
|
||||||
@@ -93,7 +95,10 @@ class ModDetailAnnounceAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return URLDecoder.decode(Regex.regex("/([^/]*)$", url), "UTF-8");
|
return URLDecoder.decode(Regex.regex("/([^/]*)$", url), "UTF-8");
|
||||||
} catch (NoSuchFieldException | UnsupportedEncodingException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return res.getString(R.string.attachment_nr, index);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.getString(R.string.attachment_nr, index);
|
return res.getString(R.string.attachment_nr, index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -83,9 +82,9 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener == null)
|
||||||
mListener.getKVV(kvv -> {
|
return;
|
||||||
kvv.modules().details().recv(mItemPos, pair -> {
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
adapter.setModule(pair.first);
|
adapter.setModule(pair.first);
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
@@ -93,37 +92,21 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
|||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void request(String title, String url) {
|
public void request(String title, String url) {
|
||||||
if (mListener == null)
|
if (mListener == null)
|
||||||
return;
|
return;
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV().modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||||
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
|
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
String folderName;
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
if (module.semester != null) {
|
|
||||||
folderName = module.semester.toString();
|
|
||||||
} else {
|
|
||||||
folderName = "PROJ";
|
|
||||||
}
|
|
||||||
folderName += "-" + module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
|
||||||
folderName += "/Announcements";
|
|
||||||
} else {
|
|
||||||
folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
|
||||||
folderName += "/Announcement";
|
folderName += "/Announcement";
|
||||||
}
|
|
||||||
|
|
||||||
getDownload().openDownloadDialog(title, url, folderName);
|
getDownload().openDownloadDialog(title, url, folderName);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.mListener = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
|||||||
@@ -21,12 +21,14 @@ 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;
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.ui.AnnouncementViewHolder;
|
import de.sebse.fuplanner.tools.ui.AnnouncementViewHolder;
|
||||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||||
|
|
||||||
class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||||
|
|
||||||
@Nullable private Modules.Module mModule = null;
|
@Nullable private Modules.Module mModule = null;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
@NonNull private final Download.OnDownloadRequestInterface requestInterface;
|
@NonNull private final Download.OnDownloadRequestInterface requestInterface;
|
||||||
|
|
||||||
ModDetailAssignmentAdapter(@NonNull Download.OnDownloadRequestInterface requestInterface) {
|
ModDetailAssignmentAdapter(@NonNull Download.OnDownloadRequestInterface requestInterface) {
|
||||||
@@ -72,7 +74,7 @@ class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder>
|
|||||||
String name = urlToName(notes.get(i), i, holder.mView.getResources());
|
String name = urlToName(notes.get(i), i, holder.mView.getResources());
|
||||||
Tag tag = new Tag(name);
|
Tag tag = new Tag(name);
|
||||||
tag.id = i;
|
tag.id = i;
|
||||||
tag.layoutColor = ContextCompat.getColor(holder.mView.getContext(), R.color.fuAccent);
|
tag.layoutColor = ContextCompat.getColor(holder.mView.getContext(), R.color.colorFUBlue);
|
||||||
holder.mTagGroup.addTag(tag);
|
holder.mTagGroup.addTag(tag);
|
||||||
}
|
}
|
||||||
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
||||||
@@ -93,7 +95,10 @@ class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder>
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
return URLDecoder.decode(Regex.regex("/([^/]*)$", url), "UTF-8");
|
return URLDecoder.decode(Regex.regex("/([^/]*)$", url), "UTF-8");
|
||||||
} catch (NoSuchFieldException | UnsupportedEncodingException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return res.getString(R.string.attachment_nr, index);
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
return res.getString(R.string.attachment_nr, index);
|
return res.getString(R.string.attachment_nr, index);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -83,9 +82,9 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener == null)
|
||||||
mListener.getKVV(kvv -> {
|
return;
|
||||||
kvv.modules().details().recv(mItemPos, pair -> {
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
adapter.setModule(pair.first);
|
adapter.setModule(pair.first);
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
@@ -93,37 +92,21 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
|||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void request(String title, String url) {
|
public void request(String title, String url) {
|
||||||
if (mListener == null)
|
if (mListener == null)
|
||||||
return;
|
return;
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV().modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||||
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
|
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
String folderName;
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
if (module.semester != null) {
|
|
||||||
folderName = module.semester.toString();
|
|
||||||
} else {
|
|
||||||
folderName = "PROJ";
|
|
||||||
}
|
|
||||||
folderName += "-" + module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
|
||||||
folderName += "/Assignments";
|
|
||||||
} else {
|
|
||||||
folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
|
||||||
folderName += "/Assignment";
|
folderName += "/Assignment";
|
||||||
}
|
|
||||||
|
|
||||||
getDownload().openDownloadDialog(title, url, folderName);
|
getDownload().openDownloadDialog(title, url, folderName);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.mListener = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
|||||||
@@ -1,9 +1,7 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
import android.app.AlertDialog;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -21,6 +19,7 @@ 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.UtilsDate;
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
|
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.StringViewHolder;
|
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||||
@@ -42,6 +41,8 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
private Modules.Module mValue;
|
private Modules.Module mValue;
|
||||||
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
||||||
|
|
||||||
|
private final Logger log = new Logger(this);
|
||||||
|
|
||||||
ModDetailEventAdapter() {
|
ModDetailEventAdapter() {
|
||||||
mValue = null;
|
mValue = null;
|
||||||
mPositionalData = new ArrayList<>();
|
mPositionalData = new ArrayList<>();
|
||||||
@@ -80,20 +81,19 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
for (Map.Entry<String, GroupedEvents> value: listsGrouped.entrySet()) {
|
for (Map.Entry<String, GroupedEvents> value: listsGrouped.entrySet()) {
|
||||||
if (value.getValue().getGroups().size() > 0) {
|
if (value.getValue().getGroups().size() > 0) {
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, value.getKey()));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, value.getKey()));
|
||||||
ArrayList<GroupedEvents.Group> ungroupedGroups = new ArrayList<>();
|
|
||||||
for (GroupedEvents.Group group: value.getValue().getGroups()) {
|
|
||||||
boolean showAsGrouped = true;
|
boolean showAsGrouped = true;
|
||||||
if (group.getSkippedDates().size() > 3 || group.size() < 3) {
|
for (GroupedEvents.Group group : value.getValue().getGroups()) {
|
||||||
|
if (group.getSkippedDates().size() > 2) {
|
||||||
showAsGrouped = false;
|
showAsGrouped = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (showAsGrouped) {
|
if (showAsGrouped) {
|
||||||
|
for (GroupedEvents.Group group : value.getValue().getGroups()) {
|
||||||
mPositionalData.add(new Pair<>(TYPE_GROUPED, group));
|
mPositionalData.add(new Pair<>(TYPE_GROUPED, group));
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
ungroupedGroups.add(group);
|
for (Event event : value.getValue()) {
|
||||||
}
|
|
||||||
}
|
|
||||||
for (GroupedEvents.Group ungroupedGroup : ungroupedGroups) {
|
|
||||||
for (Event event: ungroupedGroup) {
|
|
||||||
mPositionalData.add(new Pair<>(TYPE_UNGROUPED, event));
|
mPositionalData.add(new Pair<>(TYPE_UNGROUPED, event));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -186,30 +186,9 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
excepts.append(", ").append(UtilsDate.getModifiedDate(skippedDate));
|
excepts.append(", ").append(UtilsDate.getModifiedDate(skippedDate));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
String groupTitle = context.getString(R.string.event_scale, weekday, startTime, endTime);
|
ig.mTitle.setText(context.getString(R.string.event_scale, weekday, startTime, endTime));
|
||||||
if (!TextUtils.isEmpty(group.getTitle()) && !group.getTitle().equals(mValue.title))
|
|
||||||
groupTitle += " ("+group.getTitle()+")";
|
|
||||||
ig.mTitle.setText(groupTitle);
|
|
||||||
ig.mSubLeft.setText(context.getString(R.string.date_scale, start, end));
|
ig.mSubLeft.setText(context.getString(R.string.date_scale, start, end));
|
||||||
ig.mSubRight.setText(excepts != null ? context.getString(R.string.except_list, excepts.toString()) : "");
|
ig.mSubRight.setText(excepts != null ? context.getString(R.string.except_list, excepts.toString()) : "");
|
||||||
String moduleName = mValue.title;
|
|
||||||
StringBuilder finalExcepts = excepts;
|
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(ig.mView.getContext());
|
|
||||||
ig.mView.setOnClickListener(v -> {
|
|
||||||
alertDialogBuilder
|
|
||||||
.setTitle(R.string.events)
|
|
||||||
.setMessage(
|
|
||||||
ig.mView.getResources().getString(R.string.module_name, moduleName) + "\n" +
|
|
||||||
ig.mView.getResources().getString(R.string.location_name, group.getLocation()) + "\n" +
|
|
||||||
context.getString(R.string.event_scale, weekday, startTime, endTime) + "\n" +
|
|
||||||
context.getString(R.string.date_scale, start, end) + "\n" +
|
|
||||||
(finalExcepts != null ? context.getString(R.string.except_list, finalExcepts.toString()) : "")
|
|
||||||
)
|
|
||||||
.setCancelable(true)
|
|
||||||
.setNeutralButton(R.string.close, (dialog, id) -> dialog.cancel());
|
|
||||||
AlertDialog alertDialog = alertDialogBuilder.create();
|
|
||||||
alertDialog.show();
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
case TYPE_UNGROUPED:
|
case TYPE_UNGROUPED:
|
||||||
ItemViewHolder iu = (ItemViewHolder) holder;
|
ItemViewHolder iu = (ItemViewHolder) holder;
|
||||||
@@ -226,23 +205,7 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
|||||||
date = context.getString(R.string.date_scale, start, end);
|
date = context.getString(R.string.date_scale, start, end);
|
||||||
iu.mTitle.setText(event.getTitle());
|
iu.mTitle.setText(event.getTitle());
|
||||||
iu.mSubLeft.setText(date);
|
iu.mSubLeft.setText(date);
|
||||||
iu.mSubRight.setText(event.getLocation());
|
iu.mSubRight.setText("");
|
||||||
String moduleName1 = mValue.title;
|
|
||||||
AlertDialog.Builder alertDialogBuilder1 = new AlertDialog.Builder(iu.mView.getContext());
|
|
||||||
iu.mView.setOnClickListener(v -> {
|
|
||||||
alertDialogBuilder1
|
|
||||||
.setTitle(moduleName1)
|
|
||||||
.setMessage(
|
|
||||||
iu.mView.getResources().getString(R.string.module_name, moduleName1) + "\n" +
|
|
||||||
iu.mView.getResources().getString(R.string.location_name, event.getLocation()) + "\n" +
|
|
||||||
date
|
|
||||||
)
|
|
||||||
.setCancelable(true)
|
|
||||||
.setNeutralButton(R.string.close, (dialog, id) -> dialog.cancel());
|
|
||||||
|
|
||||||
AlertDialog alertDialog = alertDialogBuilder1.create();
|
|
||||||
alertDialog.show();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ public class ModDetailEventFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener == null)
|
||||||
mListener.getKVV(kvv -> {
|
return;
|
||||||
kvv.modules().details().recv(mItemPos, pair -> {
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
adapter.setModule(pair.first);
|
adapter.setModule(pair.first);
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
@@ -91,12 +91,10 @@ public class ModDetailEventFragment extends Fragment {
|
|||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.mListener = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
|||||||
@@ -72,13 +72,11 @@ 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(kvv -> {
|
mListener.getKVV().modules().list().recv(success -> {
|
||||||
kvv.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);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -97,7 +95,7 @@ public class ModDetailFragment extends Fragment implements ModDetailListener {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
mListener = (MainActivityListener) context;
|
mListener = (MainActivityListener) context;
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ 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.Grade;
|
import de.sebse.fuplanner.services.kvv.types.Grade;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Gradebook;
|
|
||||||
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;
|
||||||
|
|
||||||
@@ -21,12 +20,9 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
private static final int TYPE_TOTAL = 0;
|
private static final int TYPE_TOTAL = 0;
|
||||||
private static final int TYPE_GRADE = 1;
|
private static final int TYPE_GRADE = 1;
|
||||||
|
|
||||||
private static final int SECTION_EXAM = 0;
|
private static final int SECTION_GRADE = 0;
|
||||||
private static final int SECTION_ASSIGNMENT = 1;
|
|
||||||
private static final int SECTION_OTHER = 2;
|
|
||||||
|
|
||||||
private Modules.Module mValue;
|
private Modules.Module mValue;
|
||||||
private Gradebook.CategorizedGrades mGrades;
|
|
||||||
private final ArrayList<Pair<Integer, Integer>> mPositionalData;
|
private final ArrayList<Pair<Integer, Integer>> mPositionalData;
|
||||||
|
|
||||||
ModDetailGradebookAdapter() {
|
ModDetailGradebookAdapter() {
|
||||||
@@ -42,32 +38,9 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
|
|
||||||
private void setModule() {
|
private void setModule() {
|
||||||
mPositionalData.clear();
|
mPositionalData.clear();
|
||||||
if (mValue != null && mValue.gradebook != null) {
|
mPositionalData.add(new Pair<>(TYPE_TOTAL, SECTION_GRADE));
|
||||||
mGrades = mValue.gradebook.getAutoCategorizedGrades();
|
for (int i = 0; i < getGradesCount(); i++) {
|
||||||
int size;
|
mPositionalData.add(new Pair<>(TYPE_GRADE, SECTION_GRADE +1024*i));
|
||||||
size = mGrades.getExams().grades.size();
|
|
||||||
if (size > 0) {
|
|
||||||
mPositionalData.add(new Pair<>(setViewType(TYPE_TOTAL, SECTION_EXAM), 0));
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
mPositionalData.add(new Pair<>(setViewType(TYPE_GRADE, SECTION_EXAM), i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size = mGrades.getAssignments().grades.size();
|
|
||||||
if (size > 0) {
|
|
||||||
mPositionalData.add(new Pair<>(setViewType(TYPE_TOTAL, SECTION_ASSIGNMENT), 0));
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
mPositionalData.add(new Pair<>(setViewType(TYPE_GRADE, SECTION_ASSIGNMENT), i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
size = mGrades.getOthers().grades.size();
|
|
||||||
if (size > 0) {
|
|
||||||
mPositionalData.add(new Pair<>(setViewType(TYPE_TOTAL, SECTION_OTHER), 0));
|
|
||||||
for (int i = 0; i < size; i++) {
|
|
||||||
mPositionalData.add(new Pair<>(setViewType(TYPE_GRADE, SECTION_OTHER), i));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
mGrades = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.notifyDataSetChanged();
|
this.notifyDataSetChanged();
|
||||||
@@ -80,8 +53,8 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
switch (viewType) {
|
switch (viewType) {
|
||||||
case TYPE_TOTAL:
|
case TYPE_TOTAL:
|
||||||
view = LayoutInflater.from(parent.getContext())
|
view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.list_moddetails_gradebook_title, parent, false);
|
.inflate(R.layout.list_all_caption, parent, false);
|
||||||
return new GradeTitleViewHolder(view);
|
return new StringViewHolder(view);
|
||||||
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);
|
||||||
@@ -96,7 +69,7 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
public int getItemViewType(int position) {
|
public int getItemViewType(int position) {
|
||||||
// Note that unlike in ListView adapters, types don't have to be contiguous
|
// Note that unlike in ListView adapters, types don't have to be contiguous
|
||||||
if (position < mPositionalData.size())
|
if (position < mPositionalData.size())
|
||||||
return getViewType(mPositionalData.get(position).first);
|
return mPositionalData.get(position).first;
|
||||||
else return -1;
|
else return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,45 +79,19 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
if (mValue == null || position > mPositionalData.size())
|
if (mValue == null || position > mPositionalData.size())
|
||||||
return;
|
return;
|
||||||
Pair<Integer, Integer> data = mPositionalData.get(position);
|
Pair<Integer, Integer> data = mPositionalData.get(position);
|
||||||
int viewType = getViewType(data.first);
|
switch (data.first) {
|
||||||
int viewSection = getViewSection(data.first);
|
|
||||||
Gradebook.GradebookOutput gradebook = getViewSectionGradebook(viewSection);
|
|
||||||
switch (viewType) {
|
|
||||||
case TYPE_TOTAL:
|
case TYPE_TOTAL:
|
||||||
GradeTitleViewHolder h = (GradeTitleViewHolder) holder;
|
StringViewHolder h = (StringViewHolder) holder;
|
||||||
|
h.mString.setText(h.mView.getResources().getString(R.string.current_percentage, mValue.getGradebookPercent()*100));
|
||||||
if (gradebook != null) {
|
|
||||||
String title = "";
|
|
||||||
switch (viewSection) {
|
|
||||||
case SECTION_EXAM: title = h.mView.getResources().getString(R.string.exam); break;
|
|
||||||
case SECTION_ASSIGNMENT: title = h.mView.getResources().getString(R.string.assignments); break;
|
|
||||||
case SECTION_OTHER: title = h.mView.getResources().getString(R.string.others); break;
|
|
||||||
}
|
|
||||||
h.mTitle.setText(title);
|
|
||||||
Grade bestGrade = gradebook.getBestGrade();
|
|
||||||
h.mString.setText(h.mView.getResources().getString(
|
|
||||||
R.string.current_percentage,
|
|
||||||
gradebook.getUserPointSum(),
|
|
||||||
gradebook.getMaxPointSum(),
|
|
||||||
gradebook.getPercentage() * 100,
|
|
||||||
bestGrade == null ? 0 : bestGrade.getPoints(),
|
|
||||||
bestGrade == null ? 0 : bestGrade.getMaxPoints(),
|
|
||||||
bestGrade == null ? 0 : bestGrade.getPoints() / bestGrade.getMaxPoints() * 100,
|
|
||||||
bestGrade == null ? "" : bestGrade.getItemName()
|
|
||||||
));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
case TYPE_GRADE:
|
case TYPE_GRADE:
|
||||||
int index = data.second;
|
int index = data.second / 1024;
|
||||||
GradeViewHolder i = (GradeViewHolder) holder;
|
GradeViewHolder i = (GradeViewHolder) holder;
|
||||||
|
Grade gradebook = mValue.gradebook.get(index);
|
||||||
|
|
||||||
if (gradebook != null) {
|
i.mTitle.setText(gradebook.getItemName());
|
||||||
Grade grade = gradebook.grades.get(index);
|
i.mGrade.setText(String.valueOf(gradebook.getPoints()));
|
||||||
|
i.mGradeMax.setText(String.valueOf(gradebook.getMaxPoints()));
|
||||||
i.mTitle.setText(grade.getItemName());
|
|
||||||
i.mGrade.setText(String.valueOf(grade.getPoints()));
|
|
||||||
i.mGradeMax.setText(String.valueOf(grade.getMaxPoints()));
|
|
||||||
}
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -154,27 +101,10 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
return mPositionalData.size();
|
return mPositionalData.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
private int setViewType(int type, int section) {
|
private int getGradesCount() {
|
||||||
return type * 1024 + section;
|
if (mValue.gradebook != null)
|
||||||
}
|
return mValue.gradebook.size();
|
||||||
|
return 0;
|
||||||
private int getViewType(int combinedViewType) {
|
|
||||||
return combinedViewType / 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
private int getViewSection(int combinedViewType) {
|
|
||||||
return combinedViewType - getViewType(combinedViewType) * 1024;
|
|
||||||
}
|
|
||||||
|
|
||||||
private Gradebook.GradebookOutput getViewSectionGradebook(int viewSection) {
|
|
||||||
if (mGrades != null) {
|
|
||||||
switch (viewSection) {
|
|
||||||
case SECTION_EXAM: return mGrades.getExams();
|
|
||||||
case SECTION_ASSIGNMENT: return mGrades.getAssignments();
|
|
||||||
case SECTION_OTHER: return mGrades.getOthers();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -203,19 +133,4 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
|||||||
return super.toString() + " '" + mTitle.getText() + " '" + mGrade.getText() + " '" + mGradeMax.getText() + "'";
|
return super.toString() + " '" + mTitle.getText() + " '" + mGrade.getText() + " '" + mGradeMax.getText() + "'";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private class GradeTitleViewHolder extends StringViewHolder {
|
|
||||||
private final TextView mTitle;
|
|
||||||
|
|
||||||
GradeTitleViewHolder(View view) {
|
|
||||||
super(view);
|
|
||||||
mTitle = view.findViewById(R.id.title);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return super.toString() + " '" + mTitle.getText();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -81,9 +81,9 @@ public class ModDetailGradebookFragment extends Fragment {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener == null)
|
||||||
mListener.getKVV(kvv -> {
|
return;
|
||||||
kvv.modules().details().recv(mItemPos, pair -> {
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
adapter.setModule(pair.first);
|
adapter.setModule(pair.first);
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
@@ -91,12 +91,10 @@ public class ModDetailGradebookFragment extends Fragment {
|
|||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.mListener = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.text.TextUtils;
|
|
||||||
import android.util.Pair;
|
import android.util.Pair;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -22,6 +21,7 @@ import de.sebse.fuplanner.services.kvv.types.Event;
|
|||||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
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.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.MailViewHolder;
|
||||||
@@ -37,12 +37,12 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
private static final int TYPE_SHOW_MORE = 3;
|
private static final int TYPE_SHOW_MORE = 3;
|
||||||
private static final int TYPE_MAIL = 4;
|
private static final int TYPE_MAIL = 4;
|
||||||
private static final int TYPE_SHORTCUTS = 5;
|
private static final int TYPE_SHORTCUTS = 5;
|
||||||
private static final int TYPE_NO_ITEMS = 6;
|
|
||||||
|
|
||||||
@Nullable private final ModDetailListener mListener;
|
@Nullable private final ModDetailListener mListener;
|
||||||
|
|
||||||
private Modules.Module mValue;
|
private Modules.Module mValue;
|
||||||
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
|
||||||
ModDetailOverviewAdapter(@Nullable final ModDetailListener listener) {
|
ModDetailOverviewAdapter(@Nullable final ModDetailListener listener) {
|
||||||
mValue = null;
|
mValue = null;
|
||||||
@@ -57,10 +57,8 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
|
|
||||||
private void setModule() {
|
private void setModule() {
|
||||||
mPositionalData.clear();
|
mPositionalData.clear();
|
||||||
if (!TextUtils.isEmpty(mValue.description)) {
|
|
||||||
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_SHORTCUTS, null));
|
mPositionalData.add(new Pair<>(TYPE_SHORTCUTS, null));
|
||||||
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.LECTURERS));
|
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.LECTURERS));
|
||||||
for (int i = 0; i < mValue.lecturer.size(); i++) {
|
for (int i = 0; i < mValue.lecturer.size(); i++) {
|
||||||
@@ -81,9 +79,6 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
}
|
}
|
||||||
if (count > MAX_ITEMS_PER_PREVIEW)
|
if (count > MAX_ITEMS_PER_PREVIEW)
|
||||||
mPositionalData.add(new Pair<>(TYPE_SHOW_MORE, category));
|
mPositionalData.add(new Pair<>(TYPE_SHOW_MORE, category));
|
||||||
if (count == 0) {
|
|
||||||
mPositionalData.add(new Pair<>(TYPE_NO_ITEMS, category));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -107,10 +102,6 @@ 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_NO_ITEMS:
|
|
||||||
view = LayoutInflater.from(parent.getContext())
|
|
||||||
.inflate(R.layout.list_all_no_items, parent, false);
|
|
||||||
return new CustomViewHolder(view);
|
|
||||||
case TYPE_MAIL:
|
case TYPE_MAIL:
|
||||||
view = LayoutInflater.from(parent.getContext())
|
view = LayoutInflater.from(parent.getContext())
|
||||||
.inflate(R.layout.list_all_mails, parent, false);
|
.inflate(R.layout.list_all_mails, parent, false);
|
||||||
@@ -245,7 +236,6 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
|||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
case TYPE_SHOW_MORE:
|
case TYPE_SHOW_MORE:
|
||||||
case TYPE_NO_ITEMS:
|
|
||||||
CustomViewHolder c = (CustomViewHolder) holder;
|
CustomViewHolder c = (CustomViewHolder) holder;
|
||||||
c.mView.setOnClickListener(view -> {
|
c.mView.setOnClickListener(view -> {
|
||||||
if (mListener != null) mListener.gotoFragmentPart((Integer) data.second, -1);
|
if (mListener != null) mListener.gotoFragmentPart((Integer) data.second, -1);
|
||||||
|
|||||||
@@ -86,8 +86,7 @@ public class ModDetailOverviewFragment extends Fragment {
|
|||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener != null) {
|
||||||
mListener.getKVV(kvv -> {
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
kvv.modules().details().recv(mItemPos, pair -> {
|
|
||||||
adapter.setModule(pair.first);
|
adapter.setModule(pair.first);
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
@@ -95,12 +94,11 @@ public class ModDetailOverviewFragment extends Fragment {
|
|||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onAttach(@NonNull Context context) {
|
public void onAttach(Context context) {
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.mListener = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.sebse.fuplanner.fragments.moddetails;
|
|||||||
|
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
import android.view.LayoutInflater;
|
import android.view.LayoutInflater;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
@@ -25,7 +24,6 @@ import de.sebse.fuplanner.services.kvv.types.Resource;
|
|||||||
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;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.DirectoryNodeBinder;
|
import de.sebse.fuplanner.tools.ui.treeview.DirectoryNodeBinder;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.DocumentNodeBinder;
|
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.FileNodeBinder;
|
import de.sebse.fuplanner.tools.ui.treeview.FileNodeBinder;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
||||||
import de.sebse.fuplanner.tools.ui.treeview.TreeViewAdapter;
|
import de.sebse.fuplanner.tools.ui.treeview.TreeViewAdapter;
|
||||||
@@ -35,7 +33,7 @@ import de.sebse.fuplanner.tools.ui.treeview.TreeViewAdapter;
|
|||||||
* Use the {@link ModDetailResourceFragment#newInstance} factory method to
|
* Use the {@link ModDetailResourceFragment#newInstance} factory method to
|
||||||
* create an instance of this fragment.
|
* create an instance of this fragment.
|
||||||
*/
|
*/
|
||||||
public class ModDetailResourceFragment extends Fragment implements Download.OnDownloadRequestInterface {
|
public class ModDetailResourceFragment extends Fragment {
|
||||||
private static final String ARG_POSITION = "itemPosition";
|
private static final String ARG_POSITION = "itemPosition";
|
||||||
|
|
||||||
private String mItemPos;
|
private String mItemPos;
|
||||||
@@ -83,7 +81,7 @@ public class ModDetailResourceFragment extends Fragment implements Download.OnDo
|
|||||||
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 ModDetailResourceAdapter(Arrays.asList(new FileNodeBinder(), new DirectoryNodeBinder(), new DocumentNodeBinder(this)));
|
adapter = new ModDetailResourceAdapter(Arrays.asList(new FileNodeBinder(), new DirectoryNodeBinder()));
|
||||||
adapter.setOnTreeNodeListener(new TreeViewAdapter.OnTreeNodeListener() {
|
adapter.setOnTreeNodeListener(new TreeViewAdapter.OnTreeNodeListener() {
|
||||||
@Override
|
@Override
|
||||||
public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {
|
public boolean onClick(TreeNode node, RecyclerView.ViewHolder holder) {
|
||||||
@@ -91,24 +89,11 @@ public class ModDetailResourceFragment extends Fragment implements Download.OnDo
|
|||||||
// 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 && ModDetailResourceFragment.this.mListener != null) { // if leaf is file
|
} else if (node.getContent() instanceof Resource.File && ModDetailResourceFragment.this.mListener != null) { // if leaf is file
|
||||||
ModDetailResourceFragment.this.mListener.getKVV(kvv -> {
|
ModDetailResourceFragment.this.mListener.getKVV().modules().resources().recv(mItemPos, (Modules.Module module) -> {
|
||||||
kvv.modules().resources().recv(mItemPos, (Modules.Module module) -> {
|
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||||
String folderName;
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
if (module.semester != null) {
|
|
||||||
folderName = module.semester.toString();
|
|
||||||
} else {
|
|
||||||
folderName = "PROJ";
|
|
||||||
}
|
|
||||||
folderName += "-" + module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
|
||||||
folderName += "/Resources";
|
|
||||||
} else {
|
|
||||||
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);
|
||||||
}, log::e);
|
}, log::e);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@@ -134,20 +119,7 @@ public class ModDetailResourceFragment extends Fragment implements Download.OnDo
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void request(String title, String url) {
|
public void onAttach(Context context) {
|
||||||
if (mListener == null)
|
|
||||||
return;
|
|
||||||
mListener.getKVV(kvv -> {
|
|
||||||
kvv.modules().list().find(mItemPos, (Modules.Module module) -> {
|
|
||||||
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
|
||||||
folderName += "/Announcement";
|
|
||||||
getDownload().openDownloadDialog(title, url, folderName);
|
|
||||||
}, log::e);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAttach(@NonNull Context context) {
|
|
||||||
super.onAttach(context);
|
super.onAttach(context);
|
||||||
if (context instanceof MainActivityListener) {
|
if (context instanceof MainActivityListener) {
|
||||||
this.mListener = ((MainActivityListener) context);
|
this.mListener = ((MainActivityListener) context);
|
||||||
@@ -166,9 +138,9 @@ public class ModDetailResourceFragment extends Fragment implements Download.OnDo
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void refresh(boolean forceRefresh) {
|
private void refresh(boolean forceRefresh) {
|
||||||
if (mListener != null) {
|
if (mListener == null)
|
||||||
mListener.getKVV(kvv -> {
|
return;
|
||||||
kvv.modules().details().recv(mItemPos, pair -> {
|
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||||
adapter.setModule(pair.first);
|
adapter.setModule(pair.first);
|
||||||
if (pair.second)
|
if (pair.second)
|
||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
@@ -176,8 +148,6 @@ public class ModDetailResourceFragment extends Fragment implements Download.OnDo
|
|||||||
swipeLayout.setRefreshing(false);
|
swipeLayout.setRefreshing(false);
|
||||||
log.e(error);
|
log.e(error);
|
||||||
}, forceRefresh);
|
}, forceRefresh);
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Download getDownload() {
|
private Download getDownload() {
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
package de.sebse.fuplanner.fragments.moddetails;
|
package de.sebse.fuplanner.fragments.moddetails;
|
||||||
|
|
||||||
public class ModulePart {
|
class ModulePart {
|
||||||
static final int DESCRIPTION = 0;
|
static final int DESCRIPTION = 0;
|
||||||
static final int OVERVIEW = 1;
|
static final int OVERVIEW = 1;
|
||||||
public static final int ANNOUNCEMENT = 2;
|
static final int ANNOUNCEMENT = 2;
|
||||||
public static final int ASSIGNMENT = 3;
|
static final int ASSIGNMENT = 3;
|
||||||
public static final int EVENT = 4;
|
static final int EVENT = 4;
|
||||||
public static final int GRADEBOOK = 5;
|
static final int GRADEBOOK = 5;
|
||||||
public static final int RESOURCES = 6;
|
static final int RESOURCES = 6;
|
||||||
static final int LECTURERS = 7;
|
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};
|
||||||
|
|
||||||
|
|||||||
@@ -2,21 +2,17 @@ package de.sebse.fuplanner.services.canteen;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||||
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
||||||
import de.sebse.fuplanner.services.canteen.types.Canteens;
|
import de.sebse.fuplanner.services.canteen.types.Canteens;
|
||||||
import de.sebse.fuplanner.services.canteen.types.Day;
|
import de.sebse.fuplanner.services.canteen.types.Day;
|
||||||
import de.sebse.fuplanner.tools.AsyncQueue;
|
import de.sebse.fuplanner.tools.AsyncQueue;
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
|
||||||
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;
|
||||||
@@ -24,11 +20,9 @@ import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
|||||||
|
|
||||||
public class CanteenBrowser extends HTTPService {
|
public class CanteenBrowser extends HTTPService {
|
||||||
private Canteens canteens;
|
private Canteens canteens;
|
||||||
private Canteens availableCanteens;
|
|
||||||
private final AsyncQueue queue = new AsyncQueue();
|
private final AsyncQueue queue = new AsyncQueue();
|
||||||
private final Context context;
|
private final Context context;
|
||||||
private CanteenListener mListener;
|
private CanteenListener mListener;
|
||||||
private final double[][] canteenRoots = {{52.5508,13.4014}, {52.4438,13.2771}, {52.3926,13.0611}, {52.4781,13.5286}};
|
|
||||||
|
|
||||||
public CanteenBrowser(Context context) {
|
public CanteenBrowser(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -39,7 +33,9 @@ public class CanteenBrowser extends HTTPService {
|
|||||||
throw new RuntimeException(context.toString() + " must implement CanteenListener");
|
throw new RuntimeException(context.toString() + " must implement CanteenListener");
|
||||||
try {
|
try {
|
||||||
this.canteens = Canteens.load(context);
|
this.canteens = Canteens.load(context);
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,11 +45,12 @@ public class CanteenBrowser extends HTTPService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void getCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
public void getCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||||
|
queue.add("list", () -> {
|
||||||
if (this.canteens != null && !forceRefresh) {
|
if (this.canteens != null && !forceRefresh) {
|
||||||
callback.onResponse(this.canteens);
|
callback.onResponse(this.canteens);
|
||||||
|
queue.next("list");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queue.add("list", () -> {
|
|
||||||
this.upgradeCanteens(success -> {
|
this.upgradeCanteens(success -> {
|
||||||
if (this.canteens == null)
|
if (this.canteens == null)
|
||||||
this.canteens = success;
|
this.canteens = success;
|
||||||
@@ -67,22 +64,7 @@ public class CanteenBrowser extends HTTPService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void upgradeCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback) {
|
private void upgradeCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback) {
|
||||||
int[] visibleCanteens = Preferences.getArrayInt(context, R.string.pref_canteen_selection);
|
get("https://openmensa.org/api/v2/canteens?near[lat]=52.449743&near[lng]=13.282245&near[dist]=7", null, response -> {
|
||||||
if (visibleCanteens == null) {
|
|
||||||
Preferences.setArrayInt(context, R.string.pref_canteen_selection, Canteens.availableCanteens);
|
|
||||||
visibleCanteens = Preferences.getArrayInt(context, R.string.pref_canteen_selection);
|
|
||||||
}
|
|
||||||
if (visibleCanteens == null || visibleCanteens.length == 0) {
|
|
||||||
callback.onResponse(new Canteens());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
StringBuilder ids = new StringBuilder();
|
|
||||||
ids.append(visibleCanteens[0]);
|
|
||||||
for (int i = 1; i < visibleCanteens.length; i++) ids.append(",").append(visibleCanteens[i]);
|
|
||||||
|
|
||||||
// "https://openmensa.org/api/v2/canteens?near[lat]=52.449743&near[lng]=13.282245&near[dist]=7"
|
|
||||||
get("https://openmensa.org/api/v2/canteens?ids=" + ids.toString(), null, response -> {
|
|
||||||
String body = response.getParsed();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(201101, 403, "No canteen list retrieved!"));
|
errorCallback.onError(new NetworkError(201101, 403, "No canteen list retrieved!"));
|
||||||
@@ -90,7 +72,28 @@ public class CanteenBrowser extends HTTPService {
|
|||||||
}
|
}
|
||||||
Canteens canteens = new Canteens();
|
Canteens canteens = new Canteens();
|
||||||
try {
|
try {
|
||||||
parseCanteens(body, canteens);
|
JSONArray json = new JSONArray(body);
|
||||||
|
|
||||||
|
for (int i = 0; i < json.length(); i++) {
|
||||||
|
JSONObject canteen = json.getJSONObject(i);
|
||||||
|
int id = canteen.getInt("id");
|
||||||
|
String name = canteen.getString("name");
|
||||||
|
String city = canteen.getString("city");
|
||||||
|
String address = canteen.getString("address");
|
||||||
|
JSONArray coords = canteen.getJSONArray("coordinates");
|
||||||
|
double lat = 0;
|
||||||
|
double lng = 0;
|
||||||
|
if (coords != null) {
|
||||||
|
lat = coords.getDouble(0);
|
||||||
|
lng = coords.getDouble(1);
|
||||||
|
}
|
||||||
|
for (int cant : Canteens.availableCanteens) {
|
||||||
|
if (cant == id) {
|
||||||
|
canteens.addCanteen(id, name, city, address, lat, lng);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
errorCallback.onError(new NetworkError(201102, 403, "Cannot parse canteen list!"));
|
errorCallback.onError(new NetworkError(201102, 403, "Cannot parse canteen list!"));
|
||||||
@@ -100,95 +103,18 @@ public class CanteenBrowser extends HTTPService {
|
|||||||
}, error -> errorCallback.onError(new NetworkError(201103, error.networkResponse.statusCode, "Cannot get canteen list!")));
|
}, error -> errorCallback.onError(new NetworkError(201103, error.networkResponse.statusCode, "Cannot get canteen list!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public void getAvailableCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
getAvailableCanteens(callback, errorCallback, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getAvailableCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
|
||||||
if (this.availableCanteens != null && !forceRefresh) {
|
|
||||||
callback.onResponse(this.availableCanteens);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
queue.add("available", () -> {
|
|
||||||
this.upgradeAvailableCanteens(success -> {
|
|
||||||
if (this.availableCanteens == null)
|
|
||||||
this.availableCanteens = success;
|
|
||||||
else
|
|
||||||
this.availableCanteens.update(success);
|
|
||||||
callback.onResponse(success);
|
|
||||||
queue.next("available");
|
|
||||||
}, queue.check("available", errorCallback));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
private void upgradeAvailableCanteens(final NetworkCallback<Canteens> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
|
|
||||||
AtomicInteger finishedCount = new AtomicInteger();
|
|
||||||
Canteens canteens = new Canteens();
|
|
||||||
|
|
||||||
|
|
||||||
// "https://openmensa.org/api/v2/canteens?near[lat]=52.449743&near[lng]=13.282245&near[dist]=50"
|
|
||||||
for (double[] root : canteenRoots) {
|
|
||||||
get(String.format("https://openmensa.org/api/v2/canteens?near[lat]=%s&near[lng]=%s&near[dist]=50", root[0], root[1]), null, response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(201401, 403, "No canteen list retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
parseCanteens(body, canteens);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(201402, 403, "Cannot parse canteen list!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
finishedCount.getAndIncrement();
|
|
||||||
if (finishedCount.get() == this.canteenRoots.length) {
|
|
||||||
|
|
||||||
callback.onResponse(canteens);
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(201403, error.networkResponse.statusCode, "Cannot get canteen list!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private void parseCanteens(@NotNull String body, @NotNull Canteens canteens) throws JSONException {
|
|
||||||
JSONArray json = new JSONArray(body);
|
|
||||||
|
|
||||||
for (int i = 0; i < json.length(); i++) {
|
|
||||||
JSONObject canteen = json.getJSONObject(i);
|
|
||||||
int id = canteen.getInt("id");
|
|
||||||
String name = canteen.getString("name");
|
|
||||||
String city = canteen.getString("city");
|
|
||||||
String address = canteen.getString("address");
|
|
||||||
double lat = 0;
|
|
||||||
double lng = 0;
|
|
||||||
if (canteen.has("coordinates")) {
|
|
||||||
JSONArray coords = canteen.getJSONArray("coordinates");
|
|
||||||
lat = coords.getDouble(0);
|
|
||||||
lng = coords.getDouble(1);
|
|
||||||
}
|
|
||||||
canteens.addCanteen(id, name, city, address, lat, lng);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public void getCanteen(Canteen canteen, final NetworkCallback<Canteen> callback, final NetworkErrorCallback errorCallback) {
|
public void getCanteen(Canteen canteen, final NetworkCallback<Canteen> callback, final NetworkErrorCallback errorCallback) {
|
||||||
getCanteen(canteen, callback, errorCallback, false);
|
getCanteen(canteen, callback, errorCallback, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getCanteen(Canteen canteen, final NetworkCallback<Canteen> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
public void getCanteen(Canteen canteen, final NetworkCallback<Canteen> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||||
String hash = "canteen" + canteen.getId();
|
String hash = "canteen" + canteen.getId();
|
||||||
|
queue.add(hash, () -> {
|
||||||
if (canteen.size() > 0 && !forceRefresh) {
|
if (canteen.size() > 0 && !forceRefresh) {
|
||||||
callback.onResponse(canteen);
|
callback.onResponse(canteen);
|
||||||
|
queue.next(hash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queue.add(hash, () -> {
|
|
||||||
this.upgradeCanteen(canteen, success -> {
|
this.upgradeCanteen(canteen, success -> {
|
||||||
canteen.update(success);
|
canteen.update(success);
|
||||||
this.save();
|
this.save();
|
||||||
@@ -230,11 +156,12 @@ public class CanteenBrowser extends HTTPService {
|
|||||||
|
|
||||||
public void getDay(Day day, final NetworkCallback<Day> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
public void getDay(Day day, final NetworkCallback<Day> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh) {
|
||||||
String hash = "day" + day.getCanteenId() + "@@@" + Canteen.calendarToKey(day.getCalendar());
|
String hash = "day" + day.getCanteenId() + "@@@" + Canteen.calendarToKey(day.getCalendar());
|
||||||
|
queue.add(hash, () -> {
|
||||||
if (day.size() > 0 && !forceRefresh) {
|
if (day.size() > 0 && !forceRefresh) {
|
||||||
callback.onResponse(day);
|
callback.onResponse(day);
|
||||||
|
queue.next(hash);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
queue.add(hash, () -> {
|
|
||||||
this.upgradeDay(day, success -> {
|
this.upgradeDay(day, success -> {
|
||||||
day.update(success);
|
day.update(success);
|
||||||
this.save();
|
this.save();
|
||||||
|
|||||||
@@ -126,12 +126,4 @@ public class Canteen implements Serializable, Iterable<Day> {
|
|||||||
public String toString() {
|
public String toString() {
|
||||||
return id+": "+name+"\n"+list.toString()+"\n";
|
return id+": "+name+"\n"+list.toString()+"\n";
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean contains(String searchString) {
|
|
||||||
return containsIgnoreCase(getName(), searchString) || containsIgnoreCase(getAddress(), searchString) || containsIgnoreCase(getCity(), searchString);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static boolean containsIgnoreCase(String str, String subString) {
|
|
||||||
return str.toLowerCase().contains(subString.toLowerCase());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ import android.content.Context;
|
|||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
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;
|
||||||
@@ -26,7 +25,7 @@ public class Canteens implements Serializable, Iterable<Canteen> {
|
|||||||
addCanteen(canteen);
|
addCanteen(canteen);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addCanteen(Canteen canteen) {
|
private void addCanteen(Canteen canteen) {
|
||||||
if (this.list.contains(canteen)) return;
|
if (this.list.contains(canteen)) return;
|
||||||
this.list.add(canteen);
|
this.list.add(canteen);
|
||||||
}
|
}
|
||||||
@@ -75,12 +74,7 @@ public class Canteens implements Serializable, Iterable<Canteen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Canteens load(Context context) throws IOException, ClassNotFoundException {
|
public static Canteens load(Context context) throws IOException, ClassNotFoundException {
|
||||||
FileInputStream fis;
|
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||||
try {
|
|
||||||
fis = context.openFileInput(FILE_NAME);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
ObjectInputStream is = new ObjectInputStream(fis);
|
||||||
Canteens modules = (Canteens) is.readObject();
|
Canteens modules = (Canteens) is.readObject();
|
||||||
is.close();
|
is.close();
|
||||||
|
|||||||
@@ -4,4 +4,5 @@ public class AccountGeneral {
|
|||||||
public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth";
|
public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth";
|
||||||
public static final String AUTHTOKEN_TYPE_KVV = "KVV";
|
public static final String AUTHTOKEN_TYPE_KVV = "KVV";
|
||||||
public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard";
|
public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard";
|
||||||
|
public static final long SYNC_INTERVAL = 6 * 60 * 60; // defined in seconds
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,14 +28,6 @@ public class FUAuthenticator extends AbstractAccountAuthenticator {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
|
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
|
||||||
final AccountManager am = AccountManager.get(mContext);
|
|
||||||
if (am.getAccountsByType(accountType).length > 0) {
|
|
||||||
final Bundle bundle = new Bundle();
|
|
||||||
bundle.putInt(AccountManager.KEY_ERROR_CODE, AccountManager.ERROR_CODE_UNSUPPORTED_OPERATION);
|
|
||||||
bundle.putString(AccountManager.KEY_ERROR_MESSAGE, "Already an account added!");
|
|
||||||
return bundle;
|
|
||||||
}
|
|
||||||
|
|
||||||
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
|
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
|
||||||
intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
|
intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
|
||||||
intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
|
intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
|
||||||
@@ -66,14 +58,9 @@ public class FUAuthenticator extends AbstractAccountAuthenticator {
|
|||||||
if (password != null) {
|
if (password != null) {
|
||||||
try {
|
try {
|
||||||
authToken = new UserLoginTask(account.name, password, authTokenType, mContext).execute((Void) null).get();
|
authToken = new UserLoginTask(account.name, password, authTokenType, mContext).execute((Void) null).get();
|
||||||
// Login when auth/re-auth
|
} catch (InterruptedException e) {
|
||||||
if (!TextUtils.isEmpty(authToken) && authToken.startsWith("Error: ")) {
|
e.printStackTrace();
|
||||||
// if password is not wrong -> Networking error
|
} catch (ExecutionException e) {
|
||||||
if (!authToken.contains("100343"))
|
|
||||||
throw new NetworkErrorException(authToken);
|
|
||||||
else authToken = null;
|
|
||||||
}
|
|
||||||
} catch (InterruptedException | ExecutionException e) {
|
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,19 +6,25 @@ import android.accounts.AccountManager;
|
|||||||
import android.animation.Animator;
|
import android.animation.Animator;
|
||||||
import android.animation.AnimatorListenerAdapter;
|
import android.animation.AnimatorListenerAdapter;
|
||||||
import android.annotation.TargetApi;
|
import android.annotation.TargetApi;
|
||||||
|
import android.app.LoaderManager.LoaderCallbacks;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
import android.content.CursorLoader;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.Loader;
|
||||||
|
import android.content.pm.PackageManager;
|
||||||
|
import android.database.Cursor;
|
||||||
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.provider.ContactsContract;
|
||||||
import android.text.TextUtils;
|
import android.text.TextUtils;
|
||||||
import android.view.View;
|
import android.view.View;
|
||||||
import android.view.inputmethod.EditorInfo;
|
import android.view.inputmethod.EditorInfo;
|
||||||
import android.view.inputmethod.InputMethodManager;
|
import android.view.inputmethod.InputMethodManager;
|
||||||
import android.widget.Button;
|
import android.widget.Button;
|
||||||
import android.widget.TextView;
|
import android.widget.EditText;
|
||||||
|
|
||||||
import com.google.android.material.textfield.TextInputEditText;
|
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
|
|
||||||
import static de.sebse.fuplanner.services.fulogin.UserLoginTask.PARAM_USER_PASS;
|
import static de.sebse.fuplanner.services.fulogin.UserLoginTask.PARAM_USER_PASS;
|
||||||
@@ -26,16 +32,21 @@ import static de.sebse.fuplanner.services.fulogin.UserLoginTask.PARAM_USER_PASS;
|
|||||||
/**
|
/**
|
||||||
* A login screen that offers login via email/password.
|
* A login screen that offers login via email/password.
|
||||||
*/
|
*/
|
||||||
public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
public class FUAuthenticatorActivity extends AccountAuthenticatorActivity implements LoaderCallbacks<Cursor> {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Id to identity READ_CONTACTS permission request.
|
||||||
|
*/
|
||||||
|
private static final int REQUEST_READ_CONTACTS = 0;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Keep track of the login task to ensure we can cancel it if requested.
|
* Keep track of the login task to ensure we can cancel it if requested.
|
||||||
*/
|
*/
|
||||||
UserLoginTask mAuthTask = null;
|
UserLoginTask mAuthTask = null;
|
||||||
|
|
||||||
// UI references.
|
// UI references.
|
||||||
private TextInputEditText mEmailView;
|
private EditText mEmailView;
|
||||||
TextInputEditText mPasswordView;
|
EditText mPasswordView;
|
||||||
TextView mErrorView;
|
|
||||||
private View mProgressView;
|
private View mProgressView;
|
||||||
private View mLoginFormView;
|
private View mLoginFormView;
|
||||||
|
|
||||||
@@ -55,13 +66,12 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
|||||||
|
|
||||||
mAccountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
|
mAccountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
|
||||||
mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE);
|
mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE);
|
||||||
mAuthTokenType = mAuthTokenType != null ? mAuthTokenType : AccountGeneral.AUTHTOKEN_TYPE_KVV;
|
|
||||||
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
|
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
|
||||||
|
|
||||||
setContentView(R.layout.activity_fu_authenticator);
|
setContentView(R.layout.activity_fu_authenticator);
|
||||||
mErrorView = findViewById(R.id.error_textview);
|
|
||||||
// Set up the login form.
|
// Set up the login form.
|
||||||
mEmailView = findViewById(R.id.input_username);
|
mEmailView = findViewById(R.id.input_username);
|
||||||
|
populateAutoComplete();
|
||||||
|
|
||||||
mPasswordView = findViewById(R.id.input_password);
|
mPasswordView = findViewById(R.id.input_password);
|
||||||
mPasswordView.setOnEditorActionListener((textView, id, keyEvent) -> {
|
mPasswordView.setOnEditorActionListener((textView, id, keyEvent) -> {
|
||||||
@@ -79,6 +89,49 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
|||||||
mProgressView = findViewById(R.id.login_progress);
|
mProgressView = findViewById(R.id.login_progress);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void populateAutoComplete() {
|
||||||
|
if (!mayRequestContacts()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
getLoaderManager().initLoader(0, null, this);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean mayRequestContacts() {
|
||||||
|
/*if (Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (checkSelfPermission(READ_CONTACTS) == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (shouldShowRequestPermissionRationale(READ_CONTACTS)) {
|
||||||
|
Snackbar.make(mEmailView, R.string.permission_rationale, Snackbar.LENGTH_INDEFINITE)
|
||||||
|
.setAction(android.R.string.ok, new View.OnClickListener() {
|
||||||
|
@Override
|
||||||
|
@TargetApi(Build.VERSION_CODES.M)
|
||||||
|
public void onClick(View v) {
|
||||||
|
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
requestPermissions(new String[]{READ_CONTACTS}, REQUEST_READ_CONTACTS);
|
||||||
|
}*/
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Callback received when a permissions request has been completed.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions,
|
||||||
|
@NonNull int[] grantResults) {
|
||||||
|
if (requestCode == REQUEST_READ_CONTACTS) {
|
||||||
|
if (grantResults.length == 1 && grantResults[0] == PackageManager.PERMISSION_GRANTED) {
|
||||||
|
populateAutoComplete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Attempts to sign in or register the account specified by the login form.
|
* Attempts to sign in or register the account specified by the login form.
|
||||||
@@ -165,13 +218,50 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Loader<Cursor> onCreateLoader(int i, Bundle bundle) {
|
||||||
|
return new CursorLoader(this,
|
||||||
|
// Retrieve data rows for the device user's 'profile' contact.
|
||||||
|
Uri.withAppendedPath(ContactsContract.Profile.CONTENT_URI,
|
||||||
|
ContactsContract.Contacts.Data.CONTENT_DIRECTORY), ProfileQuery.PROJECTION,
|
||||||
|
|
||||||
|
// Select only email addresses.
|
||||||
|
ContactsContract.Contacts.Data.MIMETYPE +
|
||||||
|
" = ?", new String[]{ContactsContract.CommonDataKinds.Email
|
||||||
|
.CONTENT_ITEM_TYPE},
|
||||||
|
|
||||||
|
// Show primary email addresses first. Note that there won't be
|
||||||
|
// a primary email address if the user hasn't specified one.
|
||||||
|
ContactsContract.Contacts.Data.IS_PRIMARY + " DESC");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoadFinished(Loader<Cursor> cursorLoader, Cursor cursor) {
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void onLoaderReset(Loader<Cursor> cursorLoader) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private interface ProfileQuery {
|
||||||
|
String[] PROJECTION = {
|
||||||
|
ContactsContract.CommonDataKinds.Email.ADDRESS,
|
||||||
|
ContactsContract.CommonDataKinds.Email.IS_PRIMARY,
|
||||||
|
};
|
||||||
|
|
||||||
|
int ADDRESS = 0;
|
||||||
|
int IS_PRIMARY = 1;
|
||||||
|
}
|
||||||
|
|
||||||
void finishLogin(Intent intent) {
|
void finishLogin(Intent intent) {
|
||||||
String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
||||||
String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
|
String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
|
||||||
final Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
|
final Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
|
||||||
final AccountManager mAccountManager = AccountManager.get(this);
|
final AccountManager mAccountManager = AccountManager.get(this);
|
||||||
|
|
||||||
if (mIsAddingNewAccount) {
|
if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) {
|
||||||
String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
|
String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
|
||||||
String authtokenType = mAuthTokenType;
|
String authtokenType = mAuthTokenType;
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.fulogin;
|
|
||||||
|
|
||||||
public class UserLoginResult {
|
|
||||||
}
|
|
||||||
@@ -5,6 +5,7 @@ import android.annotation.SuppressLint;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.os.AsyncTask;
|
import android.os.AsyncTask;
|
||||||
|
import android.os.Build;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
@@ -13,13 +14,9 @@ import java.util.concurrent.atomic.AtomicReference;
|
|||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
import de.sebse.fuplanner.services.kvv.sync.BBLogin;
|
import de.sebse.fuplanner.services.kvv.sync.Login;
|
||||||
import de.sebse.fuplanner.services.kvv.sync.FULogin;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.kvv.sync.KVVLogin;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenKVV;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
|
||||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -37,23 +34,20 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
|||||||
};*/
|
};*/
|
||||||
static final String PARAM_USER_PASS = "PARAM_USER_PASS";
|
static final String PARAM_USER_PASS = "PARAM_USER_PASS";
|
||||||
|
|
||||||
private final String mUsername;
|
private final String mEmail;
|
||||||
private final String mPassword;
|
private final String mPassword;
|
||||||
private final KVVLogin mKVVLogin;
|
private final Login mVolleyLogin;
|
||||||
private final BBLogin mBBLogin;
|
|
||||||
private String mTokenType;
|
private String mTokenType;
|
||||||
private Logger log = new Logger(this);
|
private Logger log = new Logger(this);
|
||||||
@SuppressLint("StaticFieldLeak")
|
@SuppressLint("StaticFieldLeak")
|
||||||
@Nullable
|
@Nullable
|
||||||
private FUAuthenticatorActivity mActivity;
|
private FUAuthenticatorActivity mActivity;
|
||||||
|
|
||||||
UserLoginTask(String username, String password, @NotNull String tokenType, @NotNull Context context) {
|
UserLoginTask(String email, String password, String tokenType, @NotNull Context context) {
|
||||||
mUsername = username;
|
mEmail = email;
|
||||||
mPassword = password;
|
mPassword = password;
|
||||||
mTokenType = tokenType;
|
mTokenType = tokenType;
|
||||||
FULogin mFULogin = new FULogin(context);
|
mVolleyLogin = new Login(context);
|
||||||
mKVVLogin = new KVVLogin(context, mFULogin);
|
|
||||||
mBBLogin = new BBLogin(context, mFULogin);
|
|
||||||
if (context instanceof FUAuthenticatorActivity)
|
if (context instanceof FUAuthenticatorActivity)
|
||||||
mActivity = (FUAuthenticatorActivity) context;
|
mActivity = (FUAuthenticatorActivity) context;
|
||||||
}
|
}
|
||||||
@@ -63,84 +57,51 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
|||||||
// TODO: attempt authentication against a network service.
|
// TODO: attempt authentication against a network service.
|
||||||
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
CountDownLatch latch = new CountDownLatch(1);
|
||||||
AtomicReference<String> login = new AtomicReference<>();
|
AtomicReference<LoginToken> login = new AtomicReference<>();
|
||||||
NetworkErrorCallback errorFunc = error -> {
|
mVolleyLogin.doLogin(mEmail, mPassword, success -> {
|
||||||
|
mVolleyLogin.testLoginToken(success, success1 -> {
|
||||||
|
login.set(success);
|
||||||
|
latch.countDown();
|
||||||
|
}, error -> {
|
||||||
log.e(error);
|
log.e(error);
|
||||||
login.set("Error: "+ error.getCode());
|
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
};
|
|
||||||
switch (mTokenType) {
|
|
||||||
case AccountGeneral.AUTHTOKEN_TYPE_KVV:
|
|
||||||
mKVVLogin.doLogin(mUsername, mPassword, success -> {
|
|
||||||
mKVVLogin.testLoginToken(success, success1 -> {
|
|
||||||
login.set(success1.toJsonString());
|
|
||||||
latch.countDown();
|
|
||||||
}, errorFunc);
|
|
||||||
}, error -> {
|
|
||||||
if (error.getCode() == 100101) {
|
|
||||||
// KVV never used
|
|
||||||
LoginTokenKVV loginTokenKVV = new LoginTokenKVV(mUsername, "");
|
|
||||||
loginTokenKVV.setNotAvailable();
|
|
||||||
login.set(loginTokenKVV.toJsonString());
|
|
||||||
latch.countDown();
|
|
||||||
} else {
|
|
||||||
errorFunc.onError(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
break;
|
|
||||||
case AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD:
|
|
||||||
mBBLogin.doLogin(mUsername, mPassword, success -> {
|
|
||||||
mBBLogin.testLoginToken(success, success1 -> {
|
|
||||||
login.set(success1.toJsonString());
|
|
||||||
latch.countDown();
|
|
||||||
}, error -> {
|
}, error -> {
|
||||||
if (error.getCode() == 100270) {
|
log.e(error);
|
||||||
// Blackboard never used
|
|
||||||
success.setNotAvailable();
|
|
||||||
login.set(success.toJsonString());
|
|
||||||
latch.countDown();
|
latch.countDown();
|
||||||
} else {
|
|
||||||
errorFunc.onError(error);
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
}, errorFunc);
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
errorFunc.onError(new NetworkError(104100, 400, "Invalid auth token type"));
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
try {
|
||||||
latch.await();
|
latch.await();
|
||||||
} catch (InterruptedException e) {
|
} catch (InterruptedException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
|
|
||||||
return login.get();
|
if (login.get() == null) {
|
||||||
|
return null;
|
||||||
|
} else {
|
||||||
|
return login.get().toJsonString();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onPostExecute(final String success) {
|
protected void onPostExecute(final String success) {
|
||||||
if (mActivity == null || mActivity.isFinishing())
|
if (mActivity == null || mActivity.isFinishing())
|
||||||
return;
|
return;
|
||||||
if (mActivity.isDestroyed())
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())
|
||||||
return;
|
return;
|
||||||
mActivity.mAuthTask = null;
|
mActivity.mAuthTask = null;
|
||||||
mActivity.showProgress(false);
|
mActivity.showProgress(false);
|
||||||
|
|
||||||
if (success != null && !success.startsWith("Error: ")) {
|
if (success != null) {
|
||||||
final Intent res = new Intent();
|
final Intent res = new Intent();
|
||||||
res.putExtra(AccountManager.KEY_ACCOUNT_NAME, mUsername);
|
res.putExtra(AccountManager.KEY_ACCOUNT_NAME, mEmail);
|
||||||
res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE);
|
res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE);
|
||||||
res.putExtra(AccountManager.KEY_AUTHTOKEN, success);
|
res.putExtra(AccountManager.KEY_AUTHTOKEN, success);
|
||||||
res.putExtra(PARAM_USER_PASS, mPassword);
|
res.putExtra(PARAM_USER_PASS, mPassword);
|
||||||
mActivity.finishLogin(res);
|
mActivity.finishLogin(res);
|
||||||
} else if (success != null && (success.contains("100343"))) {
|
} else {
|
||||||
mActivity.mPasswordView.setError(mActivity.getString(R.string.error_incorrect_password));
|
mActivity.mPasswordView.setError(mActivity.getString(R.string.error_incorrect_password));
|
||||||
mActivity.mPasswordView.requestFocus();
|
mActivity.mPasswordView.requestFocus();
|
||||||
} else if (success != null) {
|
|
||||||
mActivity.mErrorView.setText(mActivity.getString(R.string.network_error_parameter, success.substring(7)));
|
|
||||||
} else {
|
|
||||||
mActivity.mErrorView.setText(R.string.network_error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -148,7 +109,7 @@ public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
|||||||
protected void onCancelled() {
|
protected void onCancelled() {
|
||||||
if (mActivity == null || mActivity.isFinishing())
|
if (mActivity == null || mActivity.isFinishing())
|
||||||
return;
|
return;
|
||||||
if (mActivity.isDestroyed())
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())
|
||||||
return;
|
return;
|
||||||
mActivity.mAuthTask = null;
|
mActivity.mAuthTask = null;
|
||||||
mActivity.showProgress(false);
|
mActivity.showProgress(false);
|
||||||
|
|||||||
@@ -1,6 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
|
||||||
|
|
||||||
public class Constants {
|
|
||||||
public static final String WB_SERVER_URL = "https://mycampus.imp.fu-berlin.de/";
|
|
||||||
public static final String BB_SERVER_URL = "https://lms.fu-berlin.de/";
|
|
||||||
}
|
|
||||||
@@ -1,104 +1,31 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
package de.sebse.fuplanner.services.kvv;
|
||||||
|
|
||||||
import android.accounts.AccountManager;
|
import android.content.Context;
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Binder;
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
import com.android.volley.NetworkResponse;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
|
public class KVV {
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenWB;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
|
||||||
|
|
||||||
public class KVV extends Service {
|
|
||||||
private final HashMap<String, Object> addons = new HashMap<>();
|
private final HashMap<String, Object> addons = new HashMap<>();
|
||||||
private final HashMap<String, KVVListener> mListeners = new HashMap<>();
|
private final KVVListener mListener;
|
||||||
private final KVVListener mListener = new KVVListener() {
|
private final Context mContext;
|
||||||
CustomAccountManager accountManager = null;
|
|
||||||
|
|
||||||
@Override
|
public KVV(KVVListener listener, Context context) {
|
||||||
public CustomAccountManager getAccountManager() {
|
this.mListener = listener;
|
||||||
if (accountManager == null)
|
this.mContext = context;
|
||||||
accountManager = new CustomAccountManager(AccountManager.get(KVV.this.getApplicationContext()), () -> null);
|
|
||||||
return accountManager;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onKVVNetworkResponse(NetworkResponse error) {
|
|
||||||
for (KVVListener listener : mListeners.values())
|
|
||||||
listener.onKVVNetworkResponse(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogin(LoginTokenWB tokenKVV, LoginTokenBB tokenBB, boolean isOnlyRefresh) {
|
|
||||||
for (KVVListener listener : mListeners.values())
|
|
||||||
listener.onLogin(tokenKVV, tokenBB, isOnlyRefresh);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onLogout() {
|
|
||||||
for (KVVListener listener : mListeners.values())
|
|
||||||
listener.onLogout();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onModuleListChange() {
|
|
||||||
for (KVVListener listener : mListeners.values())
|
|
||||||
listener.onModuleListChange();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onModuleListPartiallyUpdated(de.sebse.fuplanner.services.kvv.types.Modules modules) {
|
|
||||||
for (KVVListener listener : mListeners.values())
|
|
||||||
listener.onModuleListPartiallyUpdated(modules);
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
// Binder given to clients
|
|
||||||
private final IBinder mBinder = new LocalBinder();
|
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Login account() {
|
public Login account() {
|
||||||
return (Login) addAndGet("account", () -> new Login(mListener, getApplicationContext()));
|
return (Login) addAndGet("account", () -> new Login(mListener, mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NotNull
|
||||||
public Modules modules() {
|
public Modules modules() {
|
||||||
return (Modules) addAndGet("module", () -> new Modules(account(), mListener, getApplicationContext()));
|
return (Modules) addAndGet("module", () -> new Modules(account(), mListener, mContext));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(String key, KVVListener listener) {
|
|
||||||
mListeners.put(key, listener);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void removeListener(String key) {
|
|
||||||
mListeners.remove(key);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return mBinder;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class used for the client Binder. Because we know this service always
|
|
||||||
* runs in the same process as its clients, we don't need to deal with IPC.
|
|
||||||
*/
|
|
||||||
public class LocalBinder extends Binder {
|
|
||||||
public KVV getService() {
|
|
||||||
// Return this instance of LocalService so clients can call public methods
|
|
||||||
return KVV.this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -2,20 +2,16 @@ package de.sebse.fuplanner.services.kvv;
|
|||||||
|
|
||||||
import com.android.volley.NetworkResponse;
|
import com.android.volley.NetworkResponse;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenWB;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
|
|
||||||
public interface KVVListener {
|
public interface KVVListener {
|
||||||
default void onLogin(LoginTokenWB tokenKVV, LoginTokenBB tokenBB, boolean isOnlyRefresh) {}
|
default void onLogin(LoginToken token, boolean isOnlyRefresh) {}
|
||||||
|
|
||||||
default void onLogout() {}
|
default void onLogout() {}
|
||||||
|
|
||||||
default void onModuleListChange() {}
|
default void onModuleListChange() {}
|
||||||
|
|
||||||
default void onModuleListPartiallyUpdated(Modules modules) {}
|
|
||||||
|
|
||||||
default void onKVVNetworkResponse(NetworkResponse error) {}
|
default void onKVVNetworkResponse(NetworkResponse error) {}
|
||||||
|
|
||||||
CustomAccountManager getAccountManager();
|
CustomAccountManager getAccountManager();
|
||||||
|
|||||||
@@ -1,93 +1,57 @@
|
|||||||
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 org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||||
import de.sebse.fuplanner.services.kvv.sync.BBLogin;
|
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||||
import de.sebse.fuplanner.services.kvv.sync.FULogin;
|
|
||||||
import de.sebse.fuplanner.services.kvv.sync.WBLogin;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenWB;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
import de.sebse.fuplanner.tools.NetworkCallbackCollector;
|
import de.sebse.fuplanner.tools.NetworkCallbackCollector;
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
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;
|
||||||
|
|
||||||
public class Login {
|
public class Login extends HTTPService {
|
||||||
public static final int RESTORE_STATUS_SUCCESS = 1;
|
|
||||||
public static final int RESTORE_STATUS_ERROR = 2;
|
|
||||||
public static final int RESTORE_STATUS_INVALID_PASSWORD = 3;
|
|
||||||
|
|
||||||
public static final int LOGOUT_KVV = 2;
|
|
||||||
public static final int LOGOUT_BB = 1;
|
|
||||||
public static final int RELOGIN = 0;
|
|
||||||
|
|
||||||
private final KVVListener mListener;
|
private final KVVListener mListener;
|
||||||
private Context context;
|
@Nullable private LoginToken mToken;
|
||||||
@Nullable private LoginTokenWB mTokenKVV;
|
|
||||||
@Nullable private LoginTokenBB mTokenBB;
|
|
||||||
private boolean mLoginPending = false;
|
private boolean mLoginPending = false;
|
||||||
private final NetworkCallbackCollector<Pair<LoginTokenWB, LoginTokenBB>> mRefreshCallbacks = new NetworkCallbackCollector<>();
|
private final NetworkCallbackCollector<LoginToken> mRefreshCallbacks = new NetworkCallbackCollector<>();
|
||||||
private final NetworkCallbackCollector<Integer> mRestoreCallbacks = new NetworkCallbackCollector<>();
|
|
||||||
|
|
||||||
Login(KVVListener listener, Context context) {
|
Login(KVVListener listener, Context context) {
|
||||||
super();
|
super(context);
|
||||||
this.mListener = listener;
|
this.mListener = listener;
|
||||||
this.context = context;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Context getContext() {
|
public void restoreOnlineLogin(BooleanInterface callback) {
|
||||||
return this.context;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void restoreOnlineLogin(IntegerInterface callback) {
|
|
||||||
mRestoreCallbacks.add(new Pair<>(callback::run, null));
|
|
||||||
if (mLoginPending) {
|
if (mLoginPending) {
|
||||||
|
callback.run(false);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mLoginPending = true;
|
mLoginPending = true;
|
||||||
LoginTokenWB.load(mListener.getAccountManager(), tokenKVV -> {
|
LoginToken.load(mListener.getAccountManager(), token -> {
|
||||||
LoginTokenBB.load(mListener.getAccountManager(), tokenBB -> {
|
boolean result = setToken(token);
|
||||||
boolean result = setToken(tokenKVV, tokenBB);
|
|
||||||
mLoginPending = false;
|
mLoginPending = false;
|
||||||
mRestoreCallbacks.responseResponse(result ? RESTORE_STATUS_SUCCESS : RESTORE_STATUS_INVALID_PASSWORD);
|
callback.run(result);
|
||||||
}, e -> {
|
|
||||||
mLoginPending = false;
|
|
||||||
mRestoreCallbacks.responseResponse(RESTORE_STATUS_ERROR);
|
|
||||||
});
|
|
||||||
}, e -> {
|
|
||||||
mLoginPending = false;
|
|
||||||
mRestoreCallbacks.responseResponse(RESTORE_STATUS_ERROR);
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public void isOfflineStoredAvailable(BooleanInterface callback) {
|
public void isOfflineStoredAvailable(BooleanInterface callback) {
|
||||||
LoginTokenWB.load(mListener.getAccountManager(), tokenKVV -> {
|
LoginToken.load(mListener.getAccountManager(), token -> {
|
||||||
LoginTokenBB.load(mListener.getAccountManager(), tokenBB -> {
|
callback.run(token != null);
|
||||||
callback.run(tokenKVV != null && tokenBB != null);
|
});
|
||||||
}, e -> callback.run(false));
|
|
||||||
}, e -> callback.run(false));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean logout(boolean delete) {
|
public boolean logout(boolean delete) {
|
||||||
if (mLoginPending)
|
if (mLoginPending)
|
||||||
return false;
|
return false;
|
||||||
if (mTokenKVV == null || mTokenBB == null)
|
if (mToken == null)
|
||||||
return true;
|
return true;
|
||||||
if (delete) {
|
if (delete)
|
||||||
Preferences.setString(getContext(), R.string.pref_shib_idp_session, "");
|
mToken.delete(mListener.getAccountManager());
|
||||||
mTokenKVV.delete(mListener.getAccountManager());
|
mToken = null;
|
||||||
mTokenBB.delete(mListener.getAccountManager());
|
|
||||||
}
|
|
||||||
mTokenKVV = null;
|
|
||||||
mTokenBB = null;
|
|
||||||
return handleCallbacks(false);
|
return handleCallbacks(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,81 +60,52 @@ public class Login {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public boolean isLoggedIn() {
|
public boolean isLoggedIn() {
|
||||||
return mTokenKVV != null && mTokenBB != null;
|
return mToken != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isInOnlineMode() {
|
public boolean isInOnlineMode() {
|
||||||
return isLoggedIn();
|
return isLoggedIn();
|
||||||
}
|
}
|
||||||
|
|
||||||
void testLoginToken(@NotNull NetworkCallback<Pair<LoginTokenWB, LoginTokenBB>> callback, @NotNull NetworkErrorCallback errorCallback) {
|
void testLoginToken(@NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||||
if (mTokenKVV == null) {
|
if (mToken == null) {
|
||||||
errorCallback.onError(new NetworkError(100173, -1, "Not logged in!"));
|
errorCallback.onError(new NetworkError(100173, -1, "Not logged in!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (mTokenBB == null) {
|
testLoginToken(mToken, callback, errorCallback);
|
||||||
errorCallback.onError(new NetworkError(100174, -1, "Not logged in!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
testLoginToken(mTokenKVV, mTokenBB, callback, errorCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void testLoginToken(@NotNull LoginTokenWB tokenKVV, @NotNull LoginTokenBB tokenBB, @NotNull NetworkCallback<Pair<LoginTokenWB, LoginTokenBB>> callback, @NotNull NetworkErrorCallback errorCallback) {
|
private void testLoginToken(@NotNull LoginToken token, @NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||||
FULogin mFULogin = new FULogin(getContext());
|
new de.sebse.fuplanner.services.kvv.sync.Login(getContext()).testLoginToken(token, callback, errorCallback);
|
||||||
new WBLogin(getContext(), mFULogin).testLoginToken(tokenKVV, tokenKVV1 -> {
|
|
||||||
new BBLogin(getContext(), mFULogin).testLoginToken(tokenBB, tokenBB1 -> {
|
|
||||||
callback.onResponse(new Pair<>(tokenKVV1, tokenBB1));
|
|
||||||
}, errorCallback);
|
|
||||||
}, errorCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public LoginTokenWB getLoginTokenKVV() {
|
@Nullable public LoginToken getLoginToken() {
|
||||||
return mTokenKVV;
|
return mToken;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable public LoginTokenBB getLoginTokenBB() {
|
void refreshLogin(NetworkCallback<LoginToken> success, NetworkErrorCallback error) {
|
||||||
return mTokenBB;
|
|
||||||
}
|
|
||||||
|
|
||||||
void refreshLogin(NetworkCallback<Pair<LoginTokenWB, LoginTokenBB>> success, NetworkErrorCallback error, int flags) {
|
|
||||||
boolean isFirst = mRefreshCallbacks.isEmpty();
|
boolean isFirst = mRefreshCallbacks.isEmpty();
|
||||||
mRefreshCallbacks.add(success, error);
|
mRefreshCallbacks.add(success, error);
|
||||||
if (!isFirst)
|
if (!isFirst)
|
||||||
return;
|
return;
|
||||||
refreshLoginRunner(success, error, flags);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void refreshLoginRunner(NetworkCallback<Pair<LoginTokenWB, LoginTokenBB>> success, NetworkErrorCallback error, int flags) {
|
|
||||||
CustomAccountManager manager = mListener.getAccountManager();
|
CustomAccountManager manager = mListener.getAccountManager();
|
||||||
if ((flags & LOGOUT_KVV) == LOGOUT_KVV) {
|
manager.doInvalidateToken(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, ignored -> {
|
||||||
manager.doInvalidateToken(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_WB, ignored -> {
|
restoreOnlineLogin(isRestored -> {
|
||||||
refreshLoginRunner(success, error, flags & ~LOGOUT_KVV);
|
if (isRestored)
|
||||||
});
|
|
||||||
} else if ((flags & LOGOUT_BB) == LOGOUT_BB) {
|
|
||||||
manager.doInvalidateToken(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, ignored -> {
|
|
||||||
refreshLoginRunner(success, error, flags & ~LOGOUT_BB);
|
|
||||||
});
|
|
||||||
} else if (flags == RELOGIN) {
|
|
||||||
restoreOnlineLogin(restoreResult -> {
|
|
||||||
if (restoreResult == RESTORE_STATUS_SUCCESS)
|
|
||||||
testLoginToken(mRefreshCallbacks::responseResponse, mRefreshCallbacks::responseError);
|
testLoginToken(mRefreshCallbacks::responseResponse, mRefreshCallbacks::responseError);
|
||||||
else if (restoreResult == RESTORE_STATUS_INVALID_PASSWORD) {
|
else {
|
||||||
logout(true);
|
logout(true);
|
||||||
mRefreshCallbacks.responseError(new NetworkError(100180, 403, "Re-login failed (password)!"));
|
mRefreshCallbacks.responseError(new NetworkError(100180, 403, "Re-login failed!"));
|
||||||
} else {
|
|
||||||
mRefreshCallbacks.responseError(new NetworkError(100181, 403, "Re-login failed (error)!"));
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
});
|
||||||
throw new IllegalArgumentException("Invalid flag in refreshLoginRunner: "+flags);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private boolean handleCallbacks(boolean isOnlyRefresh) {
|
private boolean handleCallbacks(boolean isOnlyRefresh) {
|
||||||
if (mTokenKVV != null || mTokenBB != null) {
|
if (mToken != null) {
|
||||||
mListener.onLogin(mTokenKVV, mTokenBB, isOnlyRefresh);
|
mListener.onLogin(mToken, isOnlyRefresh);
|
||||||
return true;
|
return true;
|
||||||
} else {
|
} else {
|
||||||
mListener.onLogout();
|
mListener.onLogout();
|
||||||
@@ -178,20 +113,15 @@ public class Login {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean setToken(@Nullable LoginTokenWB tokenKVV, @Nullable LoginTokenBB tokenBB) {
|
private boolean setToken(@Nullable LoginToken token) {
|
||||||
if (tokenKVV == null || tokenBB == null)
|
if (token == null)
|
||||||
return false;
|
return false;
|
||||||
boolean isOnlyRefresh = mTokenKVV != null;
|
boolean isOnlyRefresh = mToken != null;
|
||||||
mTokenKVV = tokenKVV;
|
mToken = token;
|
||||||
mTokenBB = tokenBB;
|
|
||||||
return isOnlyRefresh || handleCallbacks(isOnlyRefresh);
|
return isOnlyRefresh || handleCallbacks(isOnlyRefresh);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface BooleanInterface {
|
public interface BooleanInterface {
|
||||||
void run(boolean bool);
|
void run(boolean bool);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface IntegerInterface {
|
|
||||||
void run(int integer);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,8 +2,6 @@ package de.sebse.fuplanner.services.kvv;
|
|||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
|
||||||
import com.android.volley.NetworkResponse;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@@ -58,13 +56,7 @@ public class Modules {
|
|||||||
public ModulesList list() {
|
public ModulesList list() {
|
||||||
if (mList == null) {
|
if (mList == null) {
|
||||||
mList = new ModulesList(mLogin, mListener, context);
|
mList = new ModulesList(mLogin, mListener, context);
|
||||||
mList.addErrorListener("Modules", error -> {
|
mList.addErrorListener("Modules", error -> mListener.onKVVNetworkResponse(error.networkResponse));
|
||||||
NetworkResponse networkResponse = error.networkResponse;
|
|
||||||
if ((networkResponse.statusCode == 400 || networkResponse.statusCode == 403) && networkResponse.headers.containsKey("X-Blackboard-product"))
|
|
||||||
mListener.onKVVNetworkResponse(null);
|
|
||||||
else
|
|
||||||
mListener.onKVVNetworkResponse(networkResponse);
|
|
||||||
});
|
|
||||||
mList.addSuccessListener("Modules", success -> mListener.onKVVNetworkResponse(null));
|
mList.addSuccessListener("Modules", success -> mListener.onKVVNetworkResponse(null));
|
||||||
}
|
}
|
||||||
return mList;
|
return mList;
|
||||||
@@ -76,13 +68,7 @@ public class Modules {
|
|||||||
Part o = mAddons.get(addon);
|
Part o = mAddons.get(addon);
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
o = creatorInterface.create();
|
o = creatorInterface.create();
|
||||||
o.addErrorListener("Modules", error -> {
|
o.addErrorListener("Modules", error -> mListener.onKVVNetworkResponse(error.networkResponse));
|
||||||
NetworkResponse networkResponse = error.networkResponse;
|
|
||||||
if ((networkResponse.statusCode == 400 || networkResponse.statusCode == 403) && networkResponse.headers.containsKey("X-Blackboard-product"))
|
|
||||||
mListener.onKVVNetworkResponse(null);
|
|
||||||
else
|
|
||||||
mListener.onKVVNetworkResponse(networkResponse);
|
|
||||||
});
|
|
||||||
o.addSuccessListener("Modules", success -> mListener.onKVVNetworkResponse(null));
|
o.addSuccessListener("Modules", success -> mListener.onKVVNetworkResponse(null));
|
||||||
mAddons.put(addon, o);
|
mAddons.put(addon, o);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ import java.util.ArrayList;
|
|||||||
|
|
||||||
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.UtilsDate;
|
|
||||||
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;
|
||||||
@@ -34,12 +33,12 @@ public class ModulesAnnouncements extends PartModules<ArrayList<Announcement>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void upgradeKVV(final String ID, final NetworkCallback<ArrayList<Announcement>> callback, final NetworkErrorCallback errorCallback) {
|
protected void upgrade(final String ID, final NetworkCallback<ArrayList<Announcement>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
errorCallback.onError(new NetworkError(101204, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101204, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.get(String.format(Constants.WB_SERVER_URL +"direct/announcement/site/%s.json?n=999999&d=999999999&_validateSession=", ID), mLogin.getLoginTokenKVV().getCookies(), response -> {
|
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();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(101201, 403, "No announcements retrieved!"));
|
errorCallback.onError(new NetworkError(101201, 403, "No announcements retrieved!"));
|
||||||
@@ -82,59 +81,11 @@ public class ModulesAnnouncements extends PartModules<ArrayList<Announcement>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty announcements *may be* because token is invalid -> check
|
||||||
|
if (announcements.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(announcements), errorCallback);
|
||||||
|
else
|
||||||
callback.onResponse(announcements);
|
callback.onResponse(announcements);
|
||||||
}, error -> errorCallback.onError(new NetworkError(101203, error.networkResponse.statusCode, "Cannot get announcements!")));
|
}, error -> errorCallback.onError(new NetworkError(101203, error.networkResponse.statusCode, "Cannot get announcements!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void upgradeBB(String ID, NetworkCallback<ArrayList<Announcement>> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(101214, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.get(String.format("https://lms.fu-berlin.de/learn/api/v1/courses/%s/announcements?fields=id,title,body.rawText,startDateRestriction,creatorUserId", ID), mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101211, 403, "No announcements retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<Announcement> announcements = new ArrayList<>();
|
|
||||||
JSONArray sites;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
sites = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101212, 403, "Cannot parse announcements!"));
|
|
||||||
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 text = site.getJSONObject("body").getString("rawText");
|
|
||||||
text = String.valueOf(fromHtml(text));
|
|
||||||
String createdBy = "";//site.getStringArray("createdByDisplayName");
|
|
||||||
long createdOn = UtilsDate.stringToMillis(site.getString("startDateRestriction"), "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
|
||||||
ArrayList<String> urls = new ArrayList<>();
|
|
||||||
|
|
||||||
announcements.add(new Announcement(id, title, text, createdBy, createdOn, urls));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e(new NetworkError(101215, 403, "Cannot parse announcements!"));
|
|
||||||
log.e("ID:", i, "JSON:", sites);
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
callback.onResponse(announcements);
|
|
||||||
}, error -> {
|
|
||||||
if (error.networkResponse.statusCode == 400)
|
|
||||||
callback.onResponse(new ArrayList<>());
|
|
||||||
else
|
|
||||||
errorCallback.onError(new NetworkError(101213, error.networkResponse.statusCode, "Cannot get announcements!"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,12 +34,12 @@ public class ModulesAssignments extends PartModules<AssignmentList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void upgradeKVV(final String ID, final NetworkCallback<AssignmentList> callback, final NetworkErrorCallback errorCallback) {
|
protected void upgrade(final String ID, final NetworkCallback<AssignmentList> callback, final NetworkErrorCallback errorCallback) {
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
errorCallback.onError(new NetworkError(101304, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101304, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get(String.format(Constants.WB_SERVER_URL +"direct/assignment/site/%s.json?_validateSession=", ID), mLogin.getLoginTokenKVV().getCookies(), response -> {
|
get(String.format("https://kvv.imp.fu-berlin.de/direct/assignment/site/%s.json", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
String body = response.getParsed();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(101301, 403, "No assignments retrieved!"));
|
errorCallback.onError(new NetworkError(101301, 403, "No assignments retrieved!"));
|
||||||
@@ -80,12 +80,11 @@ public class ModulesAssignments extends PartModules<AssignmentList> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty assignments *may be* because token is invalid -> check
|
||||||
|
if (assignments.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(assignments), errorCallback);
|
||||||
|
else
|
||||||
callback.onResponse(assignments);
|
callback.onResponse(assignments);
|
||||||
}, error -> errorCallback.onError(new NetworkError(101303, error.networkResponse.statusCode, "Cannot get assignments!")));
|
}, error -> errorCallback.onError(new NetworkError(101303, error.networkResponse.statusCode, "Cannot get assignments!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void upgradeBB(String ID, NetworkCallback<AssignmentList> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
callback.onResponse(new AssignmentList());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,29 +1,20 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
package de.sebse.fuplanner.services.kvv;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.regex.MatchResult;
|
|
||||||
|
|
||||||
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.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Semester;
|
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
|
||||||
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;
|
||||||
|
|
||||||
public class ModulesEvents extends PartModules<EventList> {
|
public class ModulesEvents extends PartModules<EventList> {
|
||||||
|
|
||||||
private ModulesEventsNumber mEventNumbers;
|
|
||||||
|
|
||||||
ModulesEvents(Login login, ModulesList list, Context context) {
|
ModulesEvents(Login login, ModulesList list, Context context) {
|
||||||
super(login, list, context);
|
super(login, list, context);
|
||||||
}
|
}
|
||||||
@@ -41,12 +32,12 @@ public class ModulesEvents extends PartModules<EventList> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void upgradeKVV(final String ID, final NetworkCallback<EventList> callback, final NetworkErrorCallback errorCallback) {
|
protected void upgrade(final String ID, final NetworkCallback<EventList> callback, final NetworkErrorCallback errorCallback) {
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
errorCallback.onError(new NetworkError(101404, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101404, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get(String.format(Constants.WB_SERVER_URL +"direct/calendar/site/%s.json?detailed=true&_validateSession=", ID), mLogin.getLoginTokenKVV().getCookies(), response -> {
|
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();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(101401, 403, "No events retrieved!"));
|
errorCallback.onError(new NetworkError(101401, 403, "No events retrieved!"));
|
||||||
@@ -82,100 +73,11 @@ public class ModulesEvents extends PartModules<EventList> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty events *may be* because token is invalid -> check
|
||||||
|
if (events.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(events), errorCallback);
|
||||||
|
else
|
||||||
callback.onResponse(events);
|
callback.onResponse(events);
|
||||||
}, error -> errorCallback.onError(new NetworkError(101403, error.networkResponse.statusCode, "Cannot get events!")));
|
}, error -> errorCallback.onError(new NetworkError(101403, error.networkResponse.statusCode, "Cannot get events!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void upgradeBB(String ID, NetworkCallback<EventList> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(101414, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
this.mList.recv(modules -> {
|
|
||||||
Modules.Module module = modules.get(ID);
|
|
||||||
if (module == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101416, 400, "Cannot get events!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Semester latestSemester = modules.getLatestSemester();
|
|
||||||
if (module.semester != null && !module.semester.equals(latestSemester)) {
|
|
||||||
if (module.events != null) {
|
|
||||||
callback.onResponse(module.events);
|
|
||||||
} else {
|
|
||||||
callback.onResponse(new EventList());
|
|
||||||
}
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (module.lvNumber.size() == 0) {
|
|
||||||
// Events not available
|
|
||||||
callback.onResponse(new EventList());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
eventNumbers().getVVNumber(module.lvNumber.iterator().next(), vvNumber -> {
|
|
||||||
if (vvNumber.equals("")) {
|
|
||||||
// Events not available
|
|
||||||
callback.onResponse(new EventList());
|
|
||||||
//errorCallback.onError(new NetworkError(101410, 403, "Cannot get events!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
// 462854, 465661, 462126, 463782, 437050, 433843, 471614, 464205
|
|
||||||
//String[] tests = {"462854", "465661", "462126", "463782", "437050", "433843", "471614", "464205"};
|
|
||||||
//String[] tests = {"461459", "424564", "459494", "429737", "463765", "476477", "464082", "459577", "459743", "464318", "449358", "454327", "461784", "468081", "485919"};
|
|
||||||
//vvNumber = tests[new Random().nextInt(tests.length)];
|
|
||||||
//vvNumber = "462126";
|
|
||||||
super.get(String.format("https://www.fu-berlin.de/vv/de/lv/%s", vvNumber), null, response1 -> {
|
|
||||||
String body = response1.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101411, 400, "Cannot get events!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
EventList events = new EventList();
|
|
||||||
for (MatchResult match : Regex.allMatches("<span id=\"link_to_details_[^~]*?</span>", body)) {
|
|
||||||
String entry = match.group(0);
|
|
||||||
String date;
|
|
||||||
String title = "";
|
|
||||||
try {
|
|
||||||
date = Regex.regex("[A-Z][a-z], [0-9]{2}\\.[0-9]{2}\\.[0-9]{4} [0-9]{2}:[0-9]{2} - [0-9]{2}:[0-9]{2}", entry, 0);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
log.e(new NetworkError(101412, 400, "Cannot get events!"));
|
|
||||||
e.printStackTrace();
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
title = Regex.regex("<div class=\"course_title\">([^<]*?)</div>", entry, 1);
|
|
||||||
} catch (NoSuchFieldException ignored) {}
|
|
||||||
if (TextUtils.isEmpty(title))
|
|
||||||
title = module.title;
|
|
||||||
ArrayList<String> docents = new ArrayList<>();
|
|
||||||
ArrayList<String> locations = new ArrayList<>();
|
|
||||||
for (MatchResult match1 : Regex.allMatches("<div class=\"appointment_details_column\">[^~]*?</div>", entry)) {
|
|
||||||
if (match1.group(0).contains("Dozenten:")) {
|
|
||||||
for (MatchResult match2 : Regex.allMatches(">([^>]*?)<small class=\"phone_portal\">", match1.group(0))) {
|
|
||||||
docents.add(match2.group(0).trim());
|
|
||||||
}
|
|
||||||
} else if (match1.group(0).contains("Räume:")) {
|
|
||||||
for (MatchResult match2 : Regex.allMatches("</b>([^~]*?)</p>", match1.group(0))) {
|
|
||||||
locations.add(match2.group(1).trim());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
long start = UtilsDate.stringToMillis(date.substring(4, 20), "dd.MM.yyyy HH:mm");
|
|
||||||
long duration = (Integer.parseInt(date.substring(23, 25))-Integer.parseInt(date.substring(15, 17)))*60
|
|
||||||
+ Integer.parseInt(date.substring(26, 28))-Integer.parseInt(date.substring(18, 20));
|
|
||||||
duration = duration*60*1000-1;
|
|
||||||
String locationString = TextUtils.join(", ", locations);
|
|
||||||
events.add(new Event("", "Class section - Lecture", title, duration, start, ID, locationString));
|
|
||||||
}
|
|
||||||
callback.onResponse(events);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101415, error.networkResponse.statusCode, "Cannot get events!")));
|
|
||||||
}, errorCallback);
|
|
||||||
}, errorCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
private ModulesEventsNumber eventNumbers() {
|
|
||||||
if (mEventNumbers == null)
|
|
||||||
mEventNumbers = new ModulesEventsNumber(getContext());
|
|
||||||
return mEventNumbers;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,62 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.CacheBBEventNumber;
|
|
||||||
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;
|
|
||||||
|
|
||||||
class ModulesEventsNumber extends HTTPService {
|
|
||||||
private final CacheBBEventNumber mStorage;
|
|
||||||
|
|
||||||
ModulesEventsNumber(Context context) {
|
|
||||||
super(context);
|
|
||||||
CacheBBEventNumber storage = null;
|
|
||||||
try {
|
|
||||||
storage = CacheBBEventNumber.load(context);
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (storage == null) {
|
|
||||||
mStorage = new CacheBBEventNumber();
|
|
||||||
} else {
|
|
||||||
mStorage = storage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getVVNumber(String lvNumber, NetworkCallback<String> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
String vvNumber = mStorage.getVVNumber(lvNumber);
|
|
||||||
if (vvNumber != null) {
|
|
||||||
callback.onResponse(vvNumber);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
super.head(String.format("https://www.fu-berlin.de/vv/de/search?utf8=✓&query=%s", lvNumber), null, response -> {
|
|
||||||
String location = response.getHeaders().get("Location");
|
|
||||||
if (location == null) {
|
|
||||||
// Events not available
|
|
||||||
callback.onResponse("");
|
|
||||||
//errorCallback.onError(new NetworkError(101410, 403, "Cannot get events!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
String group = Regex.regex("lv/([0-9]+)\\?", location);
|
|
||||||
mStorage.setVVNumber(lvNumber, group);
|
|
||||||
try {
|
|
||||||
mStorage.save(getContext());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
callback.onResponse(group);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
errorCallback.onError(new NetworkError(102201, 400, "Cannot get events!"));
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(102202, error.networkResponse.statusCode, "Error retrieving lecturer!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,44 +6,45 @@ import org.json.JSONArray;
|
|||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Grade;
|
import de.sebse.fuplanner.services.kvv.types.Grade;
|
||||||
import de.sebse.fuplanner.services.kvv.types.Gradebook;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
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;
|
||||||
|
|
||||||
public class ModulesGradebook extends PartModules<Gradebook> {
|
public class ModulesGradebook extends PartModules<ArrayList<Grade>> {
|
||||||
|
|
||||||
ModulesGradebook(Login login, ModulesList list, Context context) {
|
ModulesGradebook(Login login, ModulesList list, Context context) {
|
||||||
super(login, list, context);
|
super(login, list, context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Gradebook getPart(Modules.Module module) {
|
protected ArrayList<Grade> getPart(Modules.Module module) {
|
||||||
return module.gradebook;
|
return module.gradebook;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected boolean setPart(Modules.Module module, Gradebook part) {
|
protected boolean setPart(Modules.Module module, ArrayList<Grade> part) {
|
||||||
boolean changed = module.gradebook == null || module.gradebook.hashCode() != part.hashCode();
|
boolean changed = module.gradebook == null || module.gradebook.hashCode() != part.hashCode();
|
||||||
module.gradebook = part;
|
module.gradebook = part;
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void upgradeKVV(final String ID, final NetworkCallback<Gradebook> callback, final NetworkErrorCallback errorCallback) {
|
protected void upgrade(final String ID, final NetworkCallback<ArrayList<Grade>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
errorCallback.onError(new NetworkError(101504, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101504, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
super.get(String.format(Constants.WB_SERVER_URL +"direct/gradebook/site/%s.json", ID), mLogin.getLoginTokenKVV().getCookies(), response -> {
|
super.get(String.format("https://kvv.imp.fu-berlin.de/direct/gradebook/site/%s.json", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
String body = response.getParsed();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(101501, 403, "No gradebook retrieved!"));
|
errorCallback.onError(new NetworkError(101501, 403, "No gradebook retrieved!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Gradebook gradebook = new Gradebook();
|
ArrayList<Grade> gradebook = new ArrayList<>();
|
||||||
JSONArray sites;
|
JSONArray sites;
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
@@ -61,7 +62,7 @@ public class ModulesGradebook extends PartModules<Gradebook> {
|
|||||||
String itemName = site.optString("itemName", null);
|
String itemName = site.optString("itemName", null);
|
||||||
double maxPoints = site.optDouble("points", -1);
|
double maxPoints = site.optDouble("points", -1);
|
||||||
|
|
||||||
gradebook.addGrade(new Grade(itemName, grade, maxPoints));
|
gradebook.add(0, new Grade(itemName, grade, maxPoints));
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.e(new NetworkError(101505, 403, "Cannot parse gradebook!"));
|
log.e(new NetworkError(101505, 403, "Cannot parse gradebook!"));
|
||||||
log.e("ID:", i, "JSON:", sites);
|
log.e("ID:", i, "JSON:", sites);
|
||||||
@@ -70,85 +71,6 @@ public class ModulesGradebook extends PartModules<Gradebook> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
callback.onResponse(gradebook);
|
callback.onResponse(gradebook);
|
||||||
}, error -> {
|
}, error -> errorCallback.onError(new NetworkError(101503, error.networkResponse.statusCode, "Cannot get gradebook!")));
|
||||||
if (error.networkResponse.statusCode == 400)
|
|
||||||
callback.onResponse(new Gradebook());
|
|
||||||
else
|
|
||||||
errorCallback.onError(new NetworkError(101503, error.networkResponse.statusCode, "Cannot get gradebook!"));
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void upgradeBB(String ID, NetworkCallback<Gradebook> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(101510, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
super.get(String.format("https://lms.fu-berlin.de/learn/api/public/v2/courses/%s/gradebook/columns", ID), mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101511, 400, "No gradebook columns retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONArray gradeColumns;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
gradeColumns = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101512, 400, "Cannot parse gradebook columns!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get(String.format("https://lms.fu-berlin.de/learn/api/public/v2/courses/%s/gradebook/users/%s", ID, mLogin.getLoginTokenBB().getId()), mLogin.getLoginTokenBB().getCookies(), response1 -> {
|
|
||||||
String body1 = response1.getParsed();
|
|
||||||
if (body1 == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101513, 400, "No gradebook entries retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONArray grades;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body1);
|
|
||||||
grades = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101514, 400, "Cannot parse gradebook entries!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Gradebook result = new Gradebook();
|
|
||||||
for (int i = 0; i < grades.length(); i++) {
|
|
||||||
for (int j = 0; j < gradeColumns.length(); j++) {
|
|
||||||
try {
|
|
||||||
JSONObject grade = grades.getJSONObject(i);
|
|
||||||
JSONObject column = gradeColumns.getJSONObject(j);
|
|
||||||
String grade_id = grade.getString("columnId");
|
|
||||||
String column_id = column.getString("id");
|
|
||||||
if (!grade_id.equals(column_id))
|
|
||||||
continue;
|
|
||||||
String name = column.getString("name");
|
|
||||||
JSONObject displayGrade = grade.optJSONObject("displayGrade");
|
|
||||||
double points = displayGrade != null ? displayGrade.optDouble("score", 0) : 0;
|
|
||||||
JSONObject score = column.optJSONObject("score");
|
|
||||||
double maxPoints = score != null ? score.optDouble("possible", 0) : 0;
|
|
||||||
|
|
||||||
result.addGrade(new Grade(name, points, maxPoints));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e(new NetworkError(101515, 400, "Cannot parse grades!"));
|
|
||||||
log.e("ID:", i, "JSON-grades:", grades);
|
|
||||||
log.e("ID:", j, "JSON-gradeColumns:", gradeColumns);
|
|
||||||
e.printStackTrace();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
callback.onResponse(result);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101516, error.networkResponse.statusCode, "Cannot get gradebook columns!")));
|
|
||||||
}, error -> {
|
|
||||||
if (error.networkResponse.statusCode == 403)
|
|
||||||
callback.onResponse(new Gradebook());
|
|
||||||
else
|
|
||||||
errorCallback.onError(new NetworkError(101517, error.networkResponse.statusCode, "Cannot get gradebook entries!"));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,11 +12,7 @@ import java.io.IOException;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.LinkedHashSet;
|
import java.util.LinkedHashSet;
|
||||||
import java.util.regex.MatchResult;
|
import java.util.regex.MatchResult;
|
||||||
import java.util.regex.Matcher;
|
|
||||||
|
|
||||||
import androidx.arch.core.util.Function;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.CacheBBCourse;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.CacheKVVCourse;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
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.services.kvv.types.Semester;
|
||||||
@@ -27,16 +23,13 @@ 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.Part.RETRY_COUNT;
|
import static de.sebse.fuplanner.services.kvv.PartModules.RETRY_COUNT;
|
||||||
|
|
||||||
public class ModulesList extends HTTPService {
|
public class ModulesList extends HTTPService {
|
||||||
private final Login mLogin;
|
private final Login mLogin;
|
||||||
private final KVVListener mListener;
|
private final KVVListener mListener;
|
||||||
@Nullable private Modules mModules;
|
@Nullable private Modules mModules;
|
||||||
private ModulesListLecturer mLecturer;
|
|
||||||
private CacheBBCourse mBBCache;
|
|
||||||
private final NewAsyncQueue mQueue = new NewAsyncQueue();
|
private final NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||||
private CacheKVVCourse mKVVCache;
|
|
||||||
|
|
||||||
ModulesList(Login login, KVVListener listener, Context context) {
|
ModulesList(Login login, KVVListener listener, Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -68,13 +61,9 @@ public class ModulesList extends HTTPService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback, int retries) {
|
private void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback, int retries) {
|
||||||
if (mModules != null &&
|
if (mModules != null && mLogin.getLoginToken() != null && mLogin.getLoginToken().isOtherUser(mModules.getUsername()))
|
||||||
mLogin.getLoginTokenKVV() != null && mLogin.getLoginTokenKVV().isOtherUser(mModules.getUsername()) &&
|
|
||||||
mLogin.getLoginTokenBB() != null && mLogin.getLoginTokenBB().isOtherUser(mModules.getUsername())
|
|
||||||
)
|
|
||||||
delete();
|
delete();
|
||||||
if (retries < 0) {
|
if (retries < 0) {
|
||||||
log.t("Too many retires", retries);
|
|
||||||
errorCallback.onError(new NetworkError(101107, -1, "Too many retries!"));
|
errorCallback.onError(new NetworkError(101107, -1, "Too many retries!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -102,12 +91,10 @@ public class ModulesList extends HTTPService {
|
|||||||
try {
|
try {
|
||||||
this.mModules = Modules.load(getContext());
|
this.mModules = Modules.load(getContext());
|
||||||
} catch (FileNotFoundException ignored) {
|
} catch (FileNotFoundException ignored) {
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
delete();
|
|
||||||
}
|
|
||||||
if (this.mModules == null) {
|
|
||||||
recv(success -> {}, log::e, true);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -127,41 +114,15 @@ public class ModulesList extends HTTPService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void recv(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, final int retries) {
|
private void recv(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, final int retries) {
|
||||||
if (mModules != null &&
|
if (mModules != null && mLogin.getLoginToken() != null && mLogin.getLoginToken().isOtherUser(mModules.getUsername()))
|
||||||
mLogin.getLoginTokenKVV() != null && mLogin.getLoginTokenKVV().isOtherUser(mModules.getUsername()) &&
|
|
||||||
mLogin.getLoginTokenBB() != null && mLogin.getLoginTokenBB().isOtherUser(mModules.getUsername())
|
|
||||||
)
|
|
||||||
delete();
|
delete();
|
||||||
|
mQueue.add(() -> {
|
||||||
if (this.mModules != null && !forceRefresh) {
|
if (this.mModules != null && !forceRefresh) {
|
||||||
callback.onResponse(this.mModules);
|
callback.onResponse(this.mModules);
|
||||||
|
mQueue.next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mQueue.add(() -> {
|
this.upgrade(success -> {
|
||||||
if (mLogin.isLoginPending()) {
|
|
||||||
mLogin.restoreOnlineLogin(resCode -> {
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
mQueue.next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mQueue.add(() -> {
|
|
||||||
Function<Integer, NetworkErrorCallback> errorFunc = ((Integer errorCode) -> (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();
|
|
||||||
}, errorCode);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
errorCallback.onError(error);
|
|
||||||
mQueue.next();
|
|
||||||
}));
|
|
||||||
this.upgradeKVV(successKVV -> {
|
|
||||||
this.upgradeBB(successKVV, success -> {
|
|
||||||
if (this.mModules == null)
|
if (this.mModules == null)
|
||||||
this.mModules = success;
|
this.mModules = success;
|
||||||
else if(this.mModules.updateList(success)) {
|
else if(this.mModules.updateList(success)) {
|
||||||
@@ -170,81 +131,54 @@ public class ModulesList extends HTTPService {
|
|||||||
}
|
}
|
||||||
callback.onResponse(this.mModules);
|
callback.onResponse(this.mModules);
|
||||||
mQueue.next();
|
mQueue.next();
|
||||||
}, errorFunc.apply(Login.LOGOUT_BB));
|
}, error -> {
|
||||||
}, errorFunc.apply(Login.LOGOUT_KVV));
|
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 upgradeKVV(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
private void upgrade(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
||||||
NetworkCallback<Modules> successCallback = (modules -> {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
try {
|
errorCallback.onError(new NetworkError(101105, 500, "Currently running in offline mode!"));
|
||||||
cacheKVVCourse().save(getContext());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
callback.onResponse(modules);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101110, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
Modules modules = new Modules(mLogin.getLoginTokenKVV().getUsername());
|
get("https://kvv.imp.fu-berlin.de/direct/site.json", mLogin.getLoginToken().getCookies(), response -> {
|
||||||
if (!mLogin.getLoginTokenKVV().isAvailable()) {
|
|
||||||
callback.onResponse(modules);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(Constants.WB_SERVER_URL +"direct/membership.json?_validateSession=", mLogin.getLoginTokenKVV().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(101111, 403, "No membership list retrieved!"));
|
errorCallback.onError(new NetworkError(101101, 403, "No module list retrieved!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
JSONArray memberships;
|
Modules modules = new Modules(mLogin.getLoginToken().getUsername());
|
||||||
|
JSONArray sites;
|
||||||
try {
|
try {
|
||||||
JSONObject json = new JSONObject(body);
|
JSONObject json = new JSONObject(body);
|
||||||
memberships = json.getJSONArray("membership_collection");
|
sites = json.getJSONArray("site_collection");
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
errorCallback.onError(new NetworkError(101112, 403, "Cannot parse membership list!"));
|
errorCallback.onError(new NetworkError(101102, 403, "Cannot parse module list!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
final int[] latch = {memberships.length()};
|
for (int i = 0; i < sites.length(); i++) {
|
||||||
if (latch[0] == 0) {
|
|
||||||
successCallback.onResponse(modules);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < memberships.length(); i++) {
|
|
||||||
try {
|
try {
|
||||||
JSONObject membership = memberships.getJSONObject(i);
|
JSONObject site = sites.getJSONObject(i);
|
||||||
String locationReference = membership.getString("locationReference");
|
|
||||||
String courseId = Regex.regex("/site/([^/]*)", locationReference);
|
|
||||||
Modules.Module kvvCourse = cacheKVVCourse().getKVVCourse(courseId);
|
|
||||||
if (kvvCourse != null) {
|
|
||||||
kvvCourse = kvvCourse.clone();
|
|
||||||
modules.addModule(kvvCourse);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modules);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
get(String.format(Constants.WB_SERVER_URL +"direct/site/%s.json?_validateSession=", courseId), mLogin.getLoginTokenKVV().getCookies(), response1 -> {
|
|
||||||
String body1 = response1.getParsed();
|
|
||||||
if (body1 == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101113, 403, "No site retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject site = new JSONObject(body1);
|
|
||||||
|
|
||||||
String semester_string = site.getJSONObject("props").optString("term_eid", null);
|
String semester_string = site.getJSONObject("props").optString("term_eid", null);
|
||||||
Semester semester;
|
|
||||||
if (semester_string == null)
|
if (semester_string == null)
|
||||||
semester = null;
|
continue;
|
||||||
else
|
Semester semester = new Semester(semester_string);
|
||||||
semester = new Semester(semester_string);
|
|
||||||
HashSet<String> lvNumbers = new HashSet<>();
|
HashSet<String> lvNumbers = new HashSet<>();
|
||||||
String kvv_lvnumbers = site.getJSONObject("props").optString("kvv_lvnumbers", null);
|
String kvv_lvnumbers = site.getJSONObject("props").optString("kvv_lvnumbers", null);
|
||||||
if (kvv_lvnumbers != null)
|
if (kvv_lvnumbers != null) for (MatchResult matchResult : Regex.allMatches("[0-9]+", kvv_lvnumbers)) {
|
||||||
for (MatchResult matchResult : Regex.allMatches("[0-9]+", kvv_lvnumbers)) {
|
|
||||||
lvNumbers.add(matchResult.group());
|
lvNumbers.add(matchResult.group());
|
||||||
}
|
}
|
||||||
String title = site.getString("entityTitle");
|
String title = site.getString("entityTitle");
|
||||||
@@ -254,198 +188,26 @@ public class ModulesList extends HTTPService {
|
|||||||
if (lecturer.length() > 2)
|
if (lecturer.length() > 2)
|
||||||
lecturers.add(new Lecturer(lecturer));
|
lecturers.add(new Lecturer(lecturer));
|
||||||
}
|
}
|
||||||
String type = site.getJSONObject("props").optString("kvv_coursetype", "Projekt");
|
String type = site.getJSONObject("props").optString("kvv_coursetype", null);
|
||||||
String description = site.optString("description", "");
|
String description = site.optString("description", "");
|
||||||
description = String.valueOf(PartModules.fromHtml(description));
|
description = String.valueOf(PartModules.fromHtml(description));
|
||||||
String id = site.getString("id");
|
String id = site.getString("id");
|
||||||
Modules.Module module = modules.addModule(semester, lvNumbers, title, lecturers, type, description, id, Modules.TYPE_KVV);
|
modules.addModule(semester, lvNumbers, title, lecturers, type, description, id);
|
||||||
cacheKVVCourse().setKVVCourse(courseId, module.clone());
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modules);
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
log.e(new NetworkError(101114, 403, "Cannot parse site!"));
|
log.e(new NetworkError(101103, 403, "Cannot parse module list!"));
|
||||||
log.e("JSON:", body1);
|
log.e("ID:", i, "JSON:", sites);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
} catch (NoSuchFieldException e) {
|
} catch (NoSuchFieldException e) {
|
||||||
log.e(new NetworkError(101115, 403, "Cannot parse site!"));
|
log.e(new NetworkError(101106, 403, "Cannot parse module list!"));
|
||||||
|
log.e("ID:", i, "JSON:", sites);
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}, error -> errorCallback.onError(new NetworkError(101116, error.networkResponse.statusCode, "Cannot get parse!")));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e("ID:", i, "JSON:", memberships);
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101117, 403, "Cannot parse membership list!"));
|
|
||||||
return;
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
log.e("ID:", i, "JSON:", memberships);
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101118, 403, "Cannot parse membership list!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101119, error.networkResponse.statusCode, "Cannot get membership list!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void upgradeBB(final Modules modulesKVV, final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
NetworkCallback<Modules> successCallback = (modules -> {
|
|
||||||
try {
|
|
||||||
cacheBBCourse().save(getContext());
|
|
||||||
} catch (IOException e) {
|
|
||||||
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);
|
callback.onResponse(modules);
|
||||||
});
|
}, error -> errorCallback.onError(new NetworkError(101104, error.networkResponse.statusCode, "Cannot get module list!")));
|
||||||
NetworkCallback<Modules> fastCallback = (modules -> {
|
|
||||||
mListener.onModuleListPartiallyUpdated(modules);
|
|
||||||
try {
|
|
||||||
cacheBBCourse().save(getContext());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
mListener.onModuleListPartiallyUpdated(modules);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101120, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
callback.onResponse(modulesKVV);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://lms.fu-berlin.de/learn/api/public/v1/users/%s/courses?fields=courseId,dataSourceId", mLogin.getLoginTokenBB().getId()), mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101121, 403, "No module list retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final JSONArray[] sites = new JSONArray[1];
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
sites[0] = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101122, 403, "Cannot parse module list!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final int[] latch = {sites[0].length()};
|
|
||||||
// fetching lecturers takes a lot of time, send success twice: first without lecturers
|
|
||||||
final int[] latchNoLecturers = {sites[0].length()};
|
|
||||||
if (sites[0].length() == 0) {
|
|
||||||
successCallback.onResponse(modulesKVV);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int i = 0; i < sites[0].length(); i++) {
|
|
||||||
try {
|
|
||||||
JSONObject site = sites[0].getJSONObject(i);
|
|
||||||
String courseId = site.getString("courseId");
|
|
||||||
if (cacheBBCourse().hasKVVCourseID(courseId)) {
|
|
||||||
if (--latchNoLecturers[0] == 0) fastCallback.onResponse(modulesKVV);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modulesKVV);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
Modules.Module bbCourse = cacheBBCourse().getBBCourse(courseId);
|
|
||||||
if (bbCourse != null) {
|
|
||||||
bbCourse = bbCourse.clone();
|
|
||||||
modulesKVV.addModule(bbCourse);
|
|
||||||
if (--latchNoLecturers[0] == 0) fastCallback.onResponse(modulesKVV);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modulesKVV);
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
get(String.format("https://lms.fu-berlin.de/learn/api/v1/courses/%s?fields=name,courseId,description", courseId), mLogin.getLoginTokenBB().getCookies(), response1 -> {
|
|
||||||
String body1 = response1.getParsed();
|
|
||||||
if (body1 == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101124, 403, "No course entry retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body1);
|
|
||||||
String name = json.getString("name");
|
|
||||||
String description = json.optString("description", null);
|
|
||||||
String type, lvNumber, semYear, semType;
|
|
||||||
Semester semester = null;
|
|
||||||
HashSet<String> lvNumberSet = new HashSet<>();
|
|
||||||
boolean found = false;
|
|
||||||
try {
|
|
||||||
Matcher match = Regex.match("[A-Za-z0-9]*_([A-Za-z0-9]*)_([A-Za-z0-9]*)_([0-9]{2,})([WS]+)", json.getString("courseId"));
|
|
||||||
type = match.group(1);
|
|
||||||
lvNumber = match.group(2);
|
|
||||||
semYear = match.group(3);
|
|
||||||
semType = match.group(4);
|
|
||||||
semester = new Semester(semType.equals("W") ? Semester.SEM_WS : Semester.SEM_SS, Integer.valueOf(semYear) % 100);
|
|
||||||
lvNumberSet.add(lvNumber);
|
|
||||||
for (Modules.Module module: modulesKVV) {
|
|
||||||
if (module.lvNumber.contains(lvNumber)) {
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} catch (NoSuchFieldException | NumberFormatException e) {
|
|
||||||
log.e(e);
|
|
||||||
type = "Projekt";
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
Modules.Module module = modulesKVV.addModule(semester, lvNumberSet, name, new LinkedHashSet<>(), type, description, courseId, Modules.TYPE_BB);
|
|
||||||
lecturer().getBBLecturers(courseId, success -> {
|
|
||||||
module.setLecturers(success);
|
|
||||||
cacheBBCourse().setBBCourse(courseId, module.clone());
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modulesKVV);
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modulesKVV);
|
|
||||||
});
|
|
||||||
if (--latchNoLecturers[0] == 0) fastCallback.onResponse(modulesKVV);
|
|
||||||
} else {
|
|
||||||
cacheBBCourse().addKVVCourseID(courseId);
|
|
||||||
if (--latchNoLecturers[0] == 0) fastCallback.onResponse(modulesKVV);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modulesKVV);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
log.e(new NetworkError(101125, 403, "Cannot parse course entry!"));
|
|
||||||
if (--latchNoLecturers[0] == 0) fastCallback.onResponse(modulesKVV);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(modulesKVV);
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101126, error.networkResponse.statusCode, "Cannot get module list!")));
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e(new NetworkError(101123, 403, "Cannot parse course entry"));
|
|
||||||
log.e("ID:", i, "JSON:", sites[0]);
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101125, error.networkResponse.statusCode, "Cannot get module list!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
private ModulesListLecturer lecturer() {
|
|
||||||
if (mLecturer == null)
|
|
||||||
mLecturer = new ModulesListLecturer(getContext(), mLogin);
|
|
||||||
return mLecturer;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CacheBBCourse cacheBBCourse() {
|
|
||||||
if (mBBCache == null) {
|
|
||||||
try {
|
|
||||||
mBBCache = CacheBBCourse.load(getContext());
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mBBCache == null)
|
|
||||||
mBBCache = new CacheBBCourse();
|
|
||||||
return mBBCache;
|
|
||||||
}
|
|
||||||
|
|
||||||
private CacheKVVCourse cacheKVVCourse() {
|
|
||||||
if (mKVVCache == null) {
|
|
||||||
try {
|
|
||||||
mKVVCache = CacheKVVCourse.load(getContext());
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mKVVCache == null)
|
|
||||||
mKVVCache = new CacheKVVCourse();
|
|
||||||
return mKVVCache;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,155 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.LinkedHashSet;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.CacheLecturer;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
|
||||||
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;
|
|
||||||
|
|
||||||
class ModulesListLecturer extends HTTPService {
|
|
||||||
private final Login mLogin;
|
|
||||||
private final CacheLecturer mStorage;
|
|
||||||
|
|
||||||
ModulesListLecturer(Context context, Login login) {
|
|
||||||
super(context);
|
|
||||||
this.mLogin = login;
|
|
||||||
CacheLecturer storage = null;
|
|
||||||
try {
|
|
||||||
storage = CacheLecturer.load(context);
|
|
||||||
} catch (IOException | ClassNotFoundException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (storage == null) {
|
|
||||||
mStorage = new CacheLecturer();
|
|
||||||
} else {
|
|
||||||
mStorage = storage;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void getBBLecturers(String moduleID, NetworkCallback<LinkedHashSet<Lecturer>> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
ArrayList<String> lecturerString = mStorage.getLecturersPerCourse(moduleID);
|
|
||||||
if (lecturerString != null) {
|
|
||||||
final int[] latch = {lecturerString.size()};
|
|
||||||
LinkedHashSet<Lecturer> lecturers = new LinkedHashSet<>();
|
|
||||||
for (String userId : lecturerString) {
|
|
||||||
getBBLecturer(userId, success -> {
|
|
||||||
lecturers.add(success);
|
|
||||||
if (--latch[0] == 0) callback.onResponse(lecturers);
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
if (--latch[0] == 0) callback.onResponse(lecturers);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (lecturerString.size() == 0)
|
|
||||||
callback.onResponse(lecturers);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(102100, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
get(String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/users?fields=userId,courseRoleId", moduleID), mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(102101, 403, "No lecturers retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONArray sites;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
sites = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(102102, 403, "Cannot parse lecturers!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
LinkedHashSet<Lecturer> lecturers = new LinkedHashSet<>();
|
|
||||||
final int[] latch = {sites.length()};
|
|
||||||
ArrayList<String> lecturerString2 = new ArrayList<>();
|
|
||||||
NetworkCallback<LinkedHashSet<Lecturer>> successCallback = l -> {
|
|
||||||
mStorage.setLecturersPerCourse(moduleID, lecturerString2);
|
|
||||||
try {
|
|
||||||
mStorage.save(getContext());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
callback.onResponse(lecturers);
|
|
||||||
};
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
try {
|
|
||||||
JSONObject lecturerJson = sites.getJSONObject(i);
|
|
||||||
String userId = lecturerJson.getString("userId");
|
|
||||||
String role = lecturerJson.getString("courseRoleId");
|
|
||||||
if (!"Student".equals(role)) {
|
|
||||||
lecturerString2.add(userId);
|
|
||||||
getBBLecturer(userId, success -> {
|
|
||||||
lecturers.add(success);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(lecturers);
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(lecturers);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(lecturers);
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e(new NetworkError(102103, 403, "Cannot parse lecturers!"));
|
|
||||||
log.e("ID:", i, "JSON:", sites);
|
|
||||||
e.printStackTrace();
|
|
||||||
if (--latch[0] == 0) successCallback.onResponse(lecturers);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(102104, error.networkResponse.statusCode, "Error retrieving lecturers!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getBBLecturer(String lecturerID, NetworkCallback<Lecturer> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
Lecturer lecturerStore = mStorage.getLecturer(lecturerID);
|
|
||||||
if (lecturerStore != null) {
|
|
||||||
callback.onResponse(lecturerStore);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(102110, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(String.format("https://lms.fu-berlin.de/learn/api/public/v1/users/%s?fields=userName,name", lecturerID), mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(102111, 403, "No lecturer retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
String userName = json.getString("userName");
|
|
||||||
String givenName = json.getJSONObject("name").getString("given");
|
|
||||||
String familyName = json.getJSONObject("name").getString("family");
|
|
||||||
Lecturer lecturer = new Lecturer(givenName, familyName, userName + "@zedat.fu-berlin.de", true);
|
|
||||||
mStorage.setLecturer(lecturerID, lecturer);
|
|
||||||
try {
|
|
||||||
mStorage.save(getContext());
|
|
||||||
} catch (IOException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
callback.onResponse(lecturer);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(102112, 403, "Cannot parse lecturer!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(102113, error.networkResponse.statusCode, "Error retrieving lecturer!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -42,12 +42,12 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void upgradeKVV(final String ID, final NetworkCallback<ArrayList<Resource>> callback, final NetworkErrorCallback errorCallback) {
|
protected void upgrade(final String ID, final NetworkCallback<ArrayList<Resource>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get(String.format(Constants.WB_SERVER_URL +"direct/content/site/%s.json?_validateSession=", ID), mLogin.getLoginTokenKVV().getCookies(), response -> {
|
get(String.format("https://kvv.imp.fu-berlin.de/direct/content/site/%s.json", ID), mLogin.getLoginToken().getCookies(), response -> {
|
||||||
String body = response.getParsed();
|
String body = response.getParsed();
|
||||||
if (body == null) {
|
if (body == null) {
|
||||||
errorCallback.onError(new NetworkError(101601, 403, "No resources retrieved!"));
|
errorCallback.onError(new NetworkError(101601, 403, "No resources retrieved!"));
|
||||||
@@ -101,7 +101,9 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
for (Resource res2: resources) {
|
for (Resource res2: resources) {
|
||||||
try {
|
try {
|
||||||
String utf8Name;
|
String utf8Name;
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT)
|
||||||
utf8Name = StandardCharsets.UTF_8.name();
|
utf8Name = StandardCharsets.UTF_8.name();
|
||||||
|
else utf8Name = "UTF-8";
|
||||||
if (URLDecoder.decode(res2.getUrl(), utf8Name).endsWith(res.getContainer()) && res2 instanceof Resource.Folder) {
|
if (URLDecoder.decode(res2.getUrl(), utf8Name).endsWith(res.getContainer()) && res2 instanceof Resource.Folder) {
|
||||||
// Append File/Folder to list
|
// Append File/Folder to list
|
||||||
((Resource.Folder) res2).add(res);
|
((Resource.Folder) res2).add(res);
|
||||||
@@ -114,124 +116,14 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Empty resources *may be* because token is invalid -> check
|
||||||
|
if (resources.size() == 0)
|
||||||
|
mLogin.testLoginToken(token -> callback.onResponse(root), errorCallback);
|
||||||
|
else
|
||||||
callback.onResponse(root);
|
callback.onResponse(root);
|
||||||
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
|
}, error -> errorCallback.onError(new NetworkError(101603, error.networkResponse.statusCode, "Cannot get resources!")));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void upgradeBB(String ID, NetworkCallback<ArrayList<Resource>> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(101614, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
getRescourceFolder(String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/contents/", ID), ID, false, callback, errorCallback);
|
|
||||||
//callback.onResponse(new ArrayList<>());
|
|
||||||
}
|
|
||||||
|
|
||||||
private void getRescourceFolder(String url, String ID, boolean subRequest, NetworkCallback<ArrayList<Resource>> callback, NetworkErrorCallback errorCallback) {
|
|
||||||
if (mLogin.getLoginTokenBB() == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101610, 500, "Cannot get resources!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(url, mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101611, 403, "No resources retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<Resource> resources = new ArrayList<>();
|
|
||||||
JSONArray sites;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
sites = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101612, 400, "Cannot parse resources!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
final int[] latch = {sites.length()};
|
|
||||||
for (int i = 0; i < sites.length(); i++) {
|
|
||||||
try {
|
|
||||||
JSONObject resource = sites.getJSONObject(i);
|
|
||||||
String resid = resource.getString("id");
|
|
||||||
String title = resource.getString("title");
|
|
||||||
String created = resource.getString("created");
|
|
||||||
String content = resource.getJSONObject("contentHandler").getString("id");
|
|
||||||
long createdDate = UtilsDate.stringToMillis(created, "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'");
|
|
||||||
if (content.equals("resource/x-bb-folder")) {
|
|
||||||
String url2 = String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/contents/%s", ID, resid);
|
|
||||||
Resource.Folder folder = new Resource.Folder("", title, createdDate, url2, true, "");
|
|
||||||
resources.add(folder);
|
|
||||||
getRescourceFolder(String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/contents/%s/children", ID, resid), ID, true, response1 -> {
|
|
||||||
for (Resource resource1 : response1) {
|
|
||||||
folder.add(resource1);
|
|
||||||
}
|
|
||||||
if (--latch[0] == 0) callback.onResponse(resources);
|
|
||||||
}, error -> {
|
|
||||||
if (error.getHttpStatus() == 403) {
|
|
||||||
if (--latch[0] == 0) callback.onResponse(resources);
|
|
||||||
} else {
|
|
||||||
errorCallback.onError(error);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
String bodyText = resource.optString("body", "");
|
|
||||||
bodyText = String.valueOf(PartModules.fromHtml(bodyText));
|
|
||||||
String url2 = String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/contents/%s", ID, resid);
|
|
||||||
Resource.Document document = new Resource.Document("", title, createdDate, url2, true, "", bodyText);
|
|
||||||
resources.add(document);
|
|
||||||
get(String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/contents/%s/attachments", ID, resid), mLogin.getLoginTokenBB().getCookies(), response1 -> {
|
|
||||||
|
|
||||||
String body1 = response1.getParsed();
|
|
||||||
if (body1 == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101617, 403, "No resource attachments retrieved!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
JSONArray attachments;
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body1);
|
|
||||||
attachments = json.getJSONArray("results");
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
errorCallback.onError(new NetworkError(101618, 400, "Cannot parse resource attachments!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
for (int j = 0; j < attachments.length(); j++) {
|
|
||||||
try {
|
|
||||||
JSONObject attachment = attachments.getJSONObject(j);
|
|
||||||
String attachid = attachment.getString("id");
|
|
||||||
String attachname = attachment.getString("fileName");
|
|
||||||
document.addUrl(String.format("https://lms.fu-berlin.de/learn/api/public/v1/courses/%s/contents/%s/attachments/%s/download", ID, resid, attachid), attachname);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e(new NetworkError(101619, 400, "Cannot parse resource attachments!"));
|
|
||||||
e.printStackTrace();
|
|
||||||
log.e("ID:", j, "JSON:", attachments);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (--latch[0] == 0) callback.onResponse(resources);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101616, error.networkResponse.statusCode, "Cannot get resource attachments!")));
|
|
||||||
}
|
|
||||||
} catch (JSONException e) {
|
|
||||||
log.e(new NetworkError(101615, 400, "Cannot parse resources!"));
|
|
||||||
e.printStackTrace();
|
|
||||||
log.e("ID:", i, "JSON:", sites);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, error -> {
|
|
||||||
if (error.networkResponse.statusCode != 403) {
|
|
||||||
errorCallback.onError(new NetworkError(101613, error.networkResponse.statusCode, "Cannot get resources!"));
|
|
||||||
} else {
|
|
||||||
callback.onResponse(new ArrayList<>());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@@ -260,7 +152,7 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
if (retries >= 0 && (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)) {
|
if (retries >= 0 && (error.getHttpStatus() == 401 || error.getHttpStatus() == 403)) {
|
||||||
mLogin.refreshLogin(success -> {
|
mLogin.refreshLogin(success -> {
|
||||||
file(filename, url, modulename, callback, errorCallback, forceRefresh, retries-1);
|
file(filename, url, modulename, callback, errorCallback, forceRefresh, retries-1);
|
||||||
}, errorCallback, url.contains("lms.fu-berlin.de") ? Login.LOGOUT_BB : Login.LOGOUT_KVV);
|
}, errorCallback);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
errorCallback.onError(error);
|
errorCallback.onError(error);
|
||||||
@@ -268,19 +160,11 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private void fileUpgrade(String filename, String url, String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
private void fileUpgrade(String filename, String url, String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
||||||
if (url.contains("lms.fu-berlin.de")) {
|
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||||
fileUpgradeBB(filename, url, modulename, callback, errorCallback);
|
|
||||||
} else {
|
|
||||||
fileUpgradeKVV(filename, url, modulename, callback, errorCallback);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void fileUpgradeKVV(String filename, String url, String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenKVV() == null || !mLogin.getLoginTokenKVV().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
errorCallback.onError(new NetworkError(101604, 500, "Currently running in offline mode!"));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
get(url, mLogin.getLoginTokenKVV().getCookies(), response -> {
|
get(url, mLogin.getLoginToken().getCookies(), response -> {
|
||||||
if (Regex.has("\\.[Uu][Rr][Ll]$", url)){
|
if (Regex.has("\\.[Uu][Rr][Ll]$", url)){
|
||||||
// Return redirected URL
|
// Return redirected URL
|
||||||
String path = response.getHeaders().get("Location");
|
String path = response.getHeaders().get("Location");
|
||||||
@@ -294,50 +178,11 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
String path = saveFileInDownloads(filename, response.getBytes(), modulename);
|
String path = saveFileInDownloads(filename, response.getBytes(), modulename);
|
||||||
callback.onResponse(path);
|
callback.onResponse(path);
|
||||||
} else {
|
} else {
|
||||||
errorCallback.onError(new NetworkError(101704, 400, "External storage not writable!"));
|
errorCallback.onError(new NetworkError(101704, 403, "External storage not writable!"));
|
||||||
}
|
}
|
||||||
}, error -> errorCallback.onError(new NetworkError(101702, error.networkResponse.statusCode, "Cannot get file!")));
|
}, error -> errorCallback.onError(new NetworkError(101702, error.networkResponse.statusCode, "Cannot get file!")));
|
||||||
}
|
|
||||||
|
|
||||||
private void fileUpgradeBB(String filename, String url, String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginTokenBB() == null || !mLogin.getLoginTokenBB().isAvailable()) {
|
|
||||||
errorCallback.onError(new NetworkError(101615, 500, "Currently running in offline mode!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
get(url, mLogin.getLoginTokenBB().getCookies(), response -> {
|
|
||||||
if (response.getHeaders().containsKey("Location")) {
|
|
||||||
// Return redirected URL
|
|
||||||
String redirectUrl = response.getHeaders().get("Location");
|
|
||||||
if (redirectUrl == null){
|
|
||||||
redirectUrl = "";
|
|
||||||
}
|
|
||||||
get(redirectUrl, mLogin.getLoginTokenBB().getCookies(), response1 -> {
|
|
||||||
if (response1.getHeaders().containsKey("Location")) {
|
|
||||||
// Return redirected URL
|
|
||||||
String redirectUrl2 = response1.getHeaders().get("Location");
|
|
||||||
if (redirectUrl2 == null) {
|
|
||||||
redirectUrl2 = "";
|
|
||||||
} else {
|
|
||||||
redirectUrl2 = "https://lms.fu-berlin.de" + redirectUrl2;
|
|
||||||
}
|
|
||||||
get(redirectUrl2, mLogin.getLoginTokenBB().getCookies(), response2 -> {
|
|
||||||
if (response2.getBytes() == null) {
|
|
||||||
errorCallback.onError(new NetworkError(101714, 400, "Cannot get file!"));
|
|
||||||
} else if (isExternalStorageWritable()) {
|
|
||||||
String path = saveFileInDownloads(filename, response2.getBytes(), modulename);
|
|
||||||
callback.onResponse(path);
|
|
||||||
} else {
|
|
||||||
errorCallback.onError(new NetworkError(101713, 400, "External storage not writable!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101717, error.networkResponse.statusCode, "Cannot get file!")));
|
|
||||||
} else {
|
|
||||||
errorCallback.onError(new NetworkError(101716, 400, "External storage not writable!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101712, error.networkResponse.statusCode, "Cannot get file!")));
|
|
||||||
} else {
|
|
||||||
errorCallback.onError(new NetworkError(101711, 400, "External storage not writable!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(101710, error.networkResponse.statusCode, "Cannot get file!")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -368,16 +213,9 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
|||||||
}
|
}
|
||||||
private String saveFileInDownloads(String filename, byte[] data, String moduleName) {
|
private String saveFileInDownloads(String filename, byte[] data, String moduleName) {
|
||||||
// Saves file in folder: DOWNLOADS/moduleName
|
// Saves file in folder: DOWNLOADS/moduleName
|
||||||
File folder;
|
File folder = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
folder = new File(getContext().getExternalFilesDir(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
||||||
} else {
|
if (!folder.mkdir()) {
|
||||||
folder = new File(Environment.getExternalStoragePublicDirectory(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS), moduleName);
|
|
||||||
}
|
|
||||||
if (!folder.mkdirs()) {
|
|
||||||
log.w( "Directory not created");
|
log.w( "Directory not created");
|
||||||
}
|
}
|
||||||
String path = "";
|
String path = "";
|
||||||
|
|||||||
@@ -19,21 +19,13 @@ abstract class PartModules<T> extends Part<Modules.Module> {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void recv(final Modules.Module module, final NetworkCallback<Modules.Module> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh, final int retries) {
|
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) {
|
if (getPart(module) != null && !forceRefresh) {
|
||||||
callback.onResponse(module);
|
callback.onResponse(module);
|
||||||
|
mQueue.next();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
mQueue.add(() -> {
|
upgrade(module.getID(), success -> {
|
||||||
if (mLogin.isLoginPending()) {
|
|
||||||
mLogin.restoreOnlineLogin(resCode -> {
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
mQueue.next();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
mQueue.add(() -> {
|
|
||||||
upgrade(module.getModuleType(), module.getID(), success -> {
|
|
||||||
if (setPart(module, success)) {
|
if (setPart(module, success)) {
|
||||||
this.mList.store();
|
this.mList.store();
|
||||||
}
|
}
|
||||||
@@ -47,7 +39,7 @@ abstract class PartModules<T> extends Part<Modules.Module> {
|
|||||||
}, error1 -> {
|
}, error1 -> {
|
||||||
errorCallback.onError(error1);
|
errorCallback.onError(error1);
|
||||||
mQueue.next();
|
mQueue.next();
|
||||||
}, module.getModuleType() == Modules.TYPE_BB ? Login.LOGOUT_BB : Login.LOGOUT_KVV);
|
});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
errorCallback.onError(error);
|
errorCallback.onError(error);
|
||||||
@@ -69,18 +61,5 @@ abstract class PartModules<T> extends Part<Modules.Module> {
|
|||||||
|
|
||||||
protected abstract boolean setPart(Modules.Module module, T part);
|
protected abstract boolean setPart(Modules.Module module, T part);
|
||||||
|
|
||||||
protected void upgrade(final int moduleType, final String ID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback) {
|
protected abstract void upgrade(final String ID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback);
|
||||||
switch (moduleType) {
|
|
||||||
case Modules.TYPE_KVV:
|
|
||||||
upgradeKVV(ID, callback, errorCallback);
|
|
||||||
break;
|
|
||||||
case Modules.TYPE_BB:
|
|
||||||
upgradeBB(ID, callback, errorCallback);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void upgradeKVV(final String ID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback);
|
|
||||||
|
|
||||||
protected abstract void upgradeBB(final String ID, final NetworkCallback<T> callback, final NetworkErrorCallback errorCallback);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,149 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.sync;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenBB;
|
|
||||||
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.Constants.BB_SERVER_URL;
|
|
||||||
|
|
||||||
public class BBLogin extends LoginRoutine<LoginTokenBB> {
|
|
||||||
private FULogin fuLogin;
|
|
||||||
|
|
||||||
public BBLogin(Context context, FULogin fuLogin) {
|
|
||||||
super(context);
|
|
||||||
this.fuLogin = fuLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doesAccountExists(@NotNull String username, @NotNull NetworkCallback<Boolean> callback, @NotNull NetworkErrorCallback error) {
|
|
||||||
callback.onResponse(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected LoginTokenBB createUnavailableToken() {
|
|
||||||
return new LoginTokenBB();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkToken(@NotNull LoginTokenBB token, @NotNull NetworkCallback<Bundle> bundleCallback, @NotNull NetworkErrorCallback error) {
|
|
||||||
get(String.format(BB_SERVER_URL + "learn/api/public/v1/users/?userName=%s", token.getUsername()), token.getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
error.onError(new NetworkError(100272, 403, "Testing BB login failed!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
json = json.getJSONArray("results").getJSONObject(0);
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("id", json.getString("id"));
|
|
||||||
bundle.putString("studentId", json.getString("studentId"));
|
|
||||||
bundleCallback.onResponse(bundle);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
error.onError(new NetworkError(100271, 403, "Cannot parse BB profile!"));
|
|
||||||
}
|
|
||||||
}, err -> error.onError(new NetworkError(100270, err.networkResponse.statusCode, "Testing BB login failed!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createLoginToken(@NotNull String username, @NotNull String password, @NotNull NetworkCallback<LoginTokenBB> callback, @NotNull NetworkErrorCallback error) {
|
|
||||||
getSAMLLocation(samlLocation -> {
|
|
||||||
fuLogin.fulogin(samlLocation, username, password, samlResponse -> {
|
|
||||||
startShibSession(samlResponse, shibSessionKey -> {
|
|
||||||
String shibsessionKey = shibSessionKey.getString("shibsessionKey");
|
|
||||||
String shibsessionName = shibSessionKey.getString("shibsessionName");
|
|
||||||
startSession(shibsessionKey, shibsessionName, sessionCookies -> {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("username", username);
|
|
||||||
bundle.putAll(sessionCookies);
|
|
||||||
LoginTokenBB tokenBB = new LoginTokenBB(bundle);
|
|
||||||
testToken(tokenBB, callback, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
1= GET https://lms.fu-berlin.de/lms-apps/login/sso/index.php
|
|
||||||
-> Location-Header: https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?SAMLResponse=[SAMLResponse]&RelayState=[RelayState]
|
|
||||||
*/
|
|
||||||
private void getSAMLLocation(final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
get(BB_SERVER_URL + "lms-apps/login/sso/index.php", null, response -> {
|
|
||||||
String location = response.getHeaders().get("Location");
|
|
||||||
if (location == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100211, -1, "Error on getting BB SAML request!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback.onResponse(location);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100210, error.networkResponse.statusCode, "Error on getting BB SAML request!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
5= POST https://lms.fu-berlin.de/Shibboleth.sso/SAML2/POST
|
|
||||||
+ Body: SAMLResponse=[SAML-RESPONSE]
|
|
||||||
+ Header: Content-Type: application/x-www-form-urlencoded
|
|
||||||
-> Set-Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
|
||||||
*/
|
|
||||||
private void startShibSession(String samlResponse, final NetworkCallback<Bundle> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> body = new HashMap<>();
|
|
||||||
body.put("SAMLResponse", samlResponse);
|
|
||||||
post(BB_SERVER_URL + "Shibboleth.sso/SAML2/POST", null, body, response -> {
|
|
||||||
String cookies = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookies ==null) {
|
|
||||||
errorCallback.onError(new NetworkError(100251, -1, "Error on starting BB session!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
|
|
||||||
Matcher matcher = pattern.matcher(cookies);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
errorCallback.onError(new NetworkError(100252, -1, "Error on starting BB session!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("shibsessionKey", matcher.group(1));
|
|
||||||
bundle.putString("shibsessionName", matcher.group(2));
|
|
||||||
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100250, error.networkResponse.statusCode, "Error on starting BB session!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
6= https://lms.fu-berlin.de/webapps/bb-auth-provider-shibboleth-bb_bb60/execute/shibbolethLogin?returnUrl=https://lms.fu-berlin.de/webapps/portal/execute/defaultTab&authProviderId=_3_1
|
|
||||||
+ Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
|
||||||
-> Set-Cookie: JSESSIONID: [JSESSION-KVV]
|
|
||||||
*/
|
|
||||||
private void startSession(String shibsessionKey, String shibsessionName, final NetworkCallback<Bundle> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put(shibsessionKey, shibsessionName);
|
|
||||||
get(BB_SERVER_URL + "webapps/bb-auth-provider-shibboleth-bb_bb60/execute/shibbolethLogin?returnUrl=https://lms.fu-berlin.de/webapps/portal/execute/defaultTab&authProviderId=_3_1", cookies, response -> {
|
|
||||||
String cookiesSet = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookiesSet == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100261, -1, "Cannot finish BB login process!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Bundle bundle = getCookie(cookiesSet, new String[]{"session_id", "s_session_id"});
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
errorCallback.onError(new NetworkError(100262, -1, "Cannot finish BB login process!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100260, error.networkResponse.statusCode, "Cannot finish BB login process!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,145 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.sync;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
|
||||||
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;
|
|
||||||
|
|
||||||
public class FULogin extends HTTPService {
|
|
||||||
public FULogin(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void fulogin(String samlRequestUri, String username, String password, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
String old_shib_idp_session = Preferences.getString(getContext(), R.string.pref_shib_idp_session);
|
|
||||||
startSamlRequest(samlRequestUri, old_shib_idp_session, samlRequest -> {
|
|
||||||
if (samlRequest.containsKey("SAMLResponse")) {
|
|
||||||
callback.onResponse(samlRequest.getString("SAMLResponse", ""));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String JSESSIONID = samlRequest.getString("JSESSIONID");
|
|
||||||
openLoginForm(JSESSIONID, success -> {
|
|
||||||
finishLogin(username, password, JSESSIONID, samlResp -> {
|
|
||||||
String shib_idp_session = samlResp.getString("shib_idp_session");
|
|
||||||
Preferences.setString(getContext(), R.string.pref_shib_idp_session, shib_idp_session);
|
|
||||||
String samlResponse = samlResp.getString("SAMLResponse");
|
|
||||||
if (samlResponse != null)
|
|
||||||
callback.onResponse(samlResponse);
|
|
||||||
else
|
|
||||||
errorCallback.onError(new NetworkError(100300, -1, "Cannot get SAML Response!"));
|
|
||||||
}, errorCallback);
|
|
||||||
}, errorCallback);
|
|
||||||
}, errorCallback);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
2= GET [Location-Header 1]
|
|
||||||
-> Set-Cookie: JSESSIONID=[JSESSION-FU]
|
|
||||||
-> Location: /idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1
|
|
||||||
*/
|
|
||||||
private void startSamlRequest(String samlRequestUri, @Nullable String shib_idp_session, final NetworkCallback<Bundle> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> cookiesReq = null;
|
|
||||||
if (shib_idp_session != null) {
|
|
||||||
cookiesReq = new HashMap<>();
|
|
||||||
cookiesReq.put("shib_idp_session", shib_idp_session);
|
|
||||||
}
|
|
||||||
get(samlRequestUri, cookiesReq, response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body != null) {
|
|
||||||
Pattern pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
|
|
||||||
Matcher matcher = pattern.matcher(body);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
errorCallback.onError(new NetworkError(100344, -1, "Error on getting FU SAML response!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("SAMLResponse", matcher.group(1));
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
String cookies = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookies == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100321, -1, "Error on starting FU session!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Bundle bundle = getCookie(cookies, new String[]{"JSESSIONID"});
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
errorCallback.onError(new NetworkError(100322, -1, "Error on starting FU session!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100320, error.networkResponse.statusCode, "Error on starting FU session!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
3= GET [Location-Header 2]
|
|
||||||
+ Cookie: JSESSIONID=[JSESSION-FU]
|
|
||||||
*/
|
|
||||||
private void openLoginForm(String JSESSIONID_FU, final NetworkCallback<Boolean> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put("JSESSIONID", JSESSIONID_FU);
|
|
||||||
head("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, response -> {
|
|
||||||
callback.onResponse(true);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100330, error.networkResponse.statusCode, "Error starting FU login page!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
4= POST [Location-Header 2]
|
|
||||||
+ Body: j_username=[USERNAME]&j_password=[PASSWORD]&_eventId_proceed=
|
|
||||||
+ Header: Content-Type: application/x-www-form-urlencoded
|
|
||||||
+ Header: Referer: [Location-Header 2]
|
|
||||||
+ Cookie: JSESSIONID=[JSESSION-FU]
|
|
||||||
-> Set-Cookie: shib_idp_session=[SHIB-IDP-SESSION]
|
|
||||||
-> Body SAMLResponse-Input-value
|
|
||||||
*/
|
|
||||||
private void finishLogin(String username, String password, String JSESSIONID_FU, final NetworkCallback<Bundle> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> cookiesReq = new HashMap<>();
|
|
||||||
cookiesReq.put("JSESSIONID", JSESSIONID_FU);
|
|
||||||
HashMap<String, String> body = new HashMap<>();
|
|
||||||
body.put("j_username", username);
|
|
||||||
body.put("j_password", password);
|
|
||||||
body.put("_eventId_proceed", "");
|
|
||||||
post("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookiesReq, body, response -> {
|
|
||||||
String content = response.getParsed();
|
|
||||||
if (content == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100343, -1, "Error on getting FU SAML response!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
String cookies = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookies == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100341, -1, "Error on logging in to FU Identity Server!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Bundle bundle;
|
|
||||||
try {
|
|
||||||
bundle = getCookie(cookies, new String[]{"shib_idp_session"});
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
errorCallback.onError(new NetworkError(100342, -1, "Error on logging in to FU Identity Server!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
Pattern pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
|
|
||||||
Matcher matcher = pattern.matcher(content);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
errorCallback.onError(new NetworkError(100344, -1, "Error on getting SAML response!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
bundle.putString("SAMLResponse", matcher.group(1));
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100345, error.networkResponse.statusCode, "Error on logging in to FU Identity Server!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,155 @@
|
|||||||
|
package de.sebse.fuplanner.services.kvv.sync;
|
||||||
|
|
||||||
|
import android.accounts.Account;
|
||||||
|
import android.accounts.AccountManager;
|
||||||
|
import android.content.AbstractThreadedSyncAdapter;
|
||||||
|
import android.content.ContentProviderClient;
|
||||||
|
import android.content.Context;
|
||||||
|
import android.content.SyncResult;
|
||||||
|
import android.os.Bundle;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Iterator;
|
||||||
|
|
||||||
|
import androidx.annotation.StringRes;
|
||||||
|
import de.sebse.fuplanner.R;
|
||||||
|
import de.sebse.fuplanner.services.kvv.KVV;
|
||||||
|
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||||
|
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.EventList;
|
||||||
|
import de.sebse.fuplanner.services.kvv.types.Grade;
|
||||||
|
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||||
|
import de.sebse.fuplanner.services.kvv.types.Resource;
|
||||||
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
|
import de.sebse.fuplanner.tools.CustomNotificationManager;
|
||||||
|
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||||
|
import de.sebse.fuplanner.tools.UtilsDate;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
|
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||||
|
private KVV mKVV;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set up the sync adapter
|
||||||
|
*/
|
||||||
|
public KVVSyncAdapter(Context context, boolean autoInitialize) {
|
||||||
|
super(context, autoInitialize);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set up the sync adapter. This form of the
|
||||||
|
* constructor maintains compatibility with Android 3.0
|
||||||
|
* and later platform versions
|
||||||
|
*/
|
||||||
|
public KVVSyncAdapter(
|
||||||
|
Context context,
|
||||||
|
boolean autoInitialize,
|
||||||
|
boolean allowParallelSyncs) {
|
||||||
|
super(context, autoInitialize, allowParallelSyncs);
|
||||||
|
init(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void init(Context context) {
|
||||||
|
mKVV = new KVV(new KVVListener() {
|
||||||
|
|
||||||
|
CustomAccountManager accountManager = null;
|
||||||
|
@Override
|
||||||
|
public CustomAccountManager getAccountManager() {
|
||||||
|
if (accountManager == null)
|
||||||
|
accountManager = new CustomAccountManager(AccountManager.get(context), () -> null);
|
||||||
|
return accountManager;
|
||||||
|
}
|
||||||
|
}, context);
|
||||||
|
mQueue.add(() -> {
|
||||||
|
mKVV.account().restoreOnlineLogin(bool -> {
|
||||||
|
mQueue.next();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Specify the code you want to run in the sync adapter. The entire
|
||||||
|
* sync adapter runs in a background thread, so you don't have to set
|
||||||
|
* up your own background processing.
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onPerformSync(
|
||||||
|
Account account,
|
||||||
|
Bundle extras,
|
||||||
|
String authority,
|
||||||
|
ContentProviderClient provider,
|
||||||
|
SyncResult syncResult) {
|
||||||
|
mQueue.add(() -> {
|
||||||
|
mKVV.modules().list().recv(success -> {
|
||||||
|
Iterator<Modules.Module> iterator = success.latestSemesterIterator();
|
||||||
|
while (iterator.hasNext()) {
|
||||||
|
Modules.Module module = iterator.next();
|
||||||
|
final ArrayList<Announcement> announcements = module.announcements;
|
||||||
|
final AssignmentList assignments = module.assignments;
|
||||||
|
final EventList events = module.events;
|
||||||
|
final ArrayList<Grade> gradebook = module.gradebook;
|
||||||
|
final ArrayList<Resource> resources = module.resources;
|
||||||
|
mKVV.modules().details().recv(module, success1 -> {
|
||||||
|
if (success1.second) {
|
||||||
|
sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
|
||||||
|
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
|
||||||
|
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
|
||||||
|
R.string.assignment_updated, R.string.assignment_added, R.string.assignment_removed);
|
||||||
|
sendNotifications(events, module.events, module.title, evt -> evt.getTitle()+" - "+UtilsDate.getModifiedDate(evt.getStartDate()), event -> String.valueOf(event.getStartDate()),
|
||||||
|
R.string.event_updated, R.string.event_added, R.string.event_removed);
|
||||||
|
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
|
||||||
|
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
|
||||||
|
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
||||||
|
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
||||||
|
mQueue.next();
|
||||||
|
}
|
||||||
|
}, msg -> {
|
||||||
|
log.e(msg);
|
||||||
|
mQueue.next();
|
||||||
|
}, true);
|
||||||
|
}
|
||||||
|
}, msg -> {
|
||||||
|
log.e(msg);
|
||||||
|
mQueue.next();
|
||||||
|
}, true);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes) {
|
||||||
|
if (oldList == null || newList == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
ArrayList<T> obsoletes = new ArrayList<>();
|
||||||
|
for (T old: oldList) {
|
||||||
|
obsoletes.add(old);
|
||||||
|
}
|
||||||
|
for (T newEntry: newList) {
|
||||||
|
boolean found = false;
|
||||||
|
for (T oldEntry: oldList) {
|
||||||
|
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
|
||||||
|
found = true;
|
||||||
|
if (newEntry.hashCode() != oldEntry.hashCode()) {
|
||||||
|
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry));
|
||||||
|
}
|
||||||
|
obsoletes.remove(oldEntry);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!found) {
|
||||||
|
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
for (T oldEntry: obsoletes) {
|
||||||
|
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@FunctionalInterface
|
||||||
|
interface StringInterface<T> {
|
||||||
|
String get(T element);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,264 @@
|
|||||||
|
package de.sebse.fuplanner.services.kvv.sync;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
|
||||||
|
import org.jetbrains.annotations.NotNull;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
|
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;
|
||||||
|
|
||||||
|
public class Login extends HTTPService {
|
||||||
|
public Login(Context context) {
|
||||||
|
super(context);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public 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!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
||||||
|
step1(success1 -> {
|
||||||
|
String samlLocation = success1.get("Location");
|
||||||
|
step2(samlLocation, success2 -> {
|
||||||
|
String fuJSESSIONID = success2.get("JSESSIONID");
|
||||||
|
step3(fuJSESSIONID, success3 -> {
|
||||||
|
step4(username, password, fuJSESSIONID, success4 -> {
|
||||||
|
String samlResponse = success4.get("SAMLResponse");
|
||||||
|
step5(samlResponse, success5 -> {
|
||||||
|
String shibsessionKey = success5.get("shibsessionKey");
|
||||||
|
String shibsessionName = success5.get("shibsessionName");
|
||||||
|
step6(shibsessionKey, shibsessionName, success6 -> {
|
||||||
|
String kvvJSESSIONID = success6.get("JSESSIONID");
|
||||||
|
LoginToken token = new LoginToken(username, kvvJSESSIONID);
|
||||||
|
callback.onResponse(token);
|
||||||
|
}, error);
|
||||||
|
}, error);
|
||||||
|
}, error);
|
||||||
|
}, error);
|
||||||
|
}, error);
|
||||||
|
}, error);
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
1= GET https://kvv.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub
|
||||||
|
-> Location-Header: https://identity.fu-berlin.de:9443/idp-fub-qa/profile/SAML2/Redirect/SSO?SAMLResponse=[SAMLResponse]&RelayState=[RelayState]
|
||||||
|
*/
|
||||||
|
private void step1(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
get("https://kvv.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub", null, response -> {
|
||||||
|
String location = response.getHeaders().get("Location");
|
||||||
|
if (location==null) {
|
||||||
|
errorCallback.onError(new NetworkError(100111, -1, "Error on getting SAML request!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashMap<String, String> object = new HashMap<>();
|
||||||
|
object.put("Location", location);
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100110, error.networkResponse.statusCode, "Error on getting SAML request!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
2= GET [Location-Header 1]
|
||||||
|
-> Set-Cookie: JSESSIONID=[JSESSION-FU]
|
||||||
|
-> Location: /idp-fub-qa/profile/SAML2/Redirect/SSO?execution=e1s1
|
||||||
|
*/
|
||||||
|
private void step2(String url, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
get(url, null, response -> {
|
||||||
|
String cookies = response.getHeaders().get("Set-Cookie");
|
||||||
|
if (cookies==null) {
|
||||||
|
errorCallback.onError(new NetworkError(100121, -1, "Error on starting FU session!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashMap<String, String> object;
|
||||||
|
try {
|
||||||
|
object = getCookie(cookies, new String[]{"JSESSIONID"});
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
errorCallback.onError(new NetworkError(100122, -1, "Error on starting FU session!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting FU session!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
3= GET [Location-Header 2]
|
||||||
|
+ Cookie: JSESSIONID=[JSESSION-FU]
|
||||||
|
*/
|
||||||
|
private void step3(String JSESSIONID_FU, final NetworkCallback<Boolean> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("JSESSIONID", JSESSIONID_FU);
|
||||||
|
get("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, response -> {
|
||||||
|
callback.onResponse(true);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error starting login page!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
4= POST [Location-Header 2]
|
||||||
|
+ Body: j_username=[USERNAME]&j_password=[PASSWORD]&_eventId_proceed=
|
||||||
|
+ Header: Content-Type: application/x-www-form-urlencoded
|
||||||
|
+ Header: Referer: [Location-Header 2]
|
||||||
|
+ Cookie: JSESSIONID=[JSESSION-FU]
|
||||||
|
-> Set-Cookie: shib_idp_session=[SHIB-IDP-SESSION]
|
||||||
|
-> Body SAMLResponse-Input-value
|
||||||
|
*/
|
||||||
|
private void step4(String username, String password, String JSESSIONID_FU, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("JSESSIONID", JSESSIONID_FU);
|
||||||
|
HashMap<String, String> body = new HashMap<>();
|
||||||
|
body.put("j_username", username);
|
||||||
|
body.put("j_password", password);
|
||||||
|
body.put("_eventId_proceed", "");
|
||||||
|
post("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?execution=e1s1", cookies, body, response -> {
|
||||||
|
String cookies1 = response.getHeaders().get("Set-Cookie");
|
||||||
|
if (cookies1 ==null) {
|
||||||
|
errorCallback.onError(new NetworkError(100141, -1, "Error on logging in to FU Identity Server!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashMap<String, String> object;
|
||||||
|
try {
|
||||||
|
object = getCookie(cookies1, new String[]{"shib_idp_session"});
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
errorCallback.onError(new NetworkError(100142, -1, "Error on logging in to FU Identity Server!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
String content = response.getParsed();
|
||||||
|
if (content == null) {
|
||||||
|
errorCallback.onError(new NetworkError(100143, -1, "Error on getting SAML response!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Pattern pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
|
||||||
|
Matcher matcher = pattern.matcher(content);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
errorCallback.onError(new NetworkError(100144, -1, "Error on getting SAML response!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
object.put("SAMLResponse", matcher.group(1));
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100145, error.networkResponse.statusCode, "Error on logging in to FU Identity Server!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
5= POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
|
||||||
|
+ Body: SAMLResponse=[SAML-RESPONSE]
|
||||||
|
+ Header: Content-Type: application/x-www-form-urlencoded
|
||||||
|
-> Set-Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
||||||
|
*/
|
||||||
|
private void step5(String SAMLResponse, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> body = new HashMap<>();
|
||||||
|
body.put("SAMLResponse", SAMLResponse);
|
||||||
|
post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", null, body, response -> {
|
||||||
|
String cookies = response.getHeaders().get("Set-Cookie");
|
||||||
|
if (cookies ==null) {
|
||||||
|
errorCallback.onError(new NetworkError(100151, -1, "Error on starting KVV session!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashMap<String, String> object = new HashMap<>();
|
||||||
|
|
||||||
|
|
||||||
|
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
|
||||||
|
Matcher matcher = pattern.matcher(cookies);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
errorCallback.onError(new NetworkError(100152, -1, "Error on starting KVV session!"));
|
||||||
|
}
|
||||||
|
object.put("shibsessionKey", matcher.group(1));
|
||||||
|
object.put("shibsessionName", matcher.group(2));
|
||||||
|
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting KVV session!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*
|
||||||
|
6= https://kvv.imp.fu-berlin.de/sakai-login-tool/container
|
||||||
|
+ Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
||||||
|
-> Set-Cookie: JSESSIONID: [JSESSION-KVV]
|
||||||
|
*/
|
||||||
|
private void step6(String shibsessionKey, String shibsessionName, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||||
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put(shibsessionKey, shibsessionName);
|
||||||
|
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", cookies, response -> {
|
||||||
|
String cookies1 = response.getHeaders().get("Set-Cookie");
|
||||||
|
if (cookies1 ==null) {
|
||||||
|
errorCallback.onError(new NetworkError(100161, -1, "Cannot finish login process!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
HashMap<String, String> object;
|
||||||
|
try {
|
||||||
|
object = getCookie(cookies1, new String[]{"JSESSIONID"});
|
||||||
|
} catch (NoSuchFieldException e) {
|
||||||
|
errorCallback.onError(new NetworkError(100162, -1, "Cannot finish login process!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
callback.onResponse(object);
|
||||||
|
}, error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish login process!")));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
private String getCookie(String cookies, String name) throws NoSuchFieldException {
|
||||||
|
Pattern pattern = Pattern.compile(name+"=([^;]+);");
|
||||||
|
Matcher matcher = pattern.matcher(cookies);
|
||||||
|
if (!matcher.find()) {
|
||||||
|
log.e("GETcookie failed", name);
|
||||||
|
log.e("GETcookie failed", cookies);
|
||||||
|
throw new NoSuchFieldException();
|
||||||
|
}
|
||||||
|
return matcher.group(1);
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, String> getCookie(String cookies, String[] names) throws NoSuchFieldException {
|
||||||
|
HashMap<String, String> result = new HashMap<>();
|
||||||
|
for (String name: names) {
|
||||||
|
result.put(name,this.getCookie(cookies, name));
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,55 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.sync;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
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.NetworkErrorCallback;
|
|
||||||
|
|
||||||
public abstract class LoginRoutine<T extends LoginToken> extends HTTPService {
|
|
||||||
private long lastHash;
|
|
||||||
private long lastSync;
|
|
||||||
private static final long MAX_CACHE_TIME = 1000 * 60; // 1 minute
|
|
||||||
|
|
||||||
public LoginRoutine(Context context) {
|
|
||||||
super(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
public final void testToken(@NotNull T token, @NotNull NetworkCallback<T> callback, @NotNull NetworkErrorCallback error) {
|
|
||||||
if (token.hashCode() == lastHash && lastSync + MAX_CACHE_TIME > System.currentTimeMillis() && token.hasAdditionals()) {
|
|
||||||
callback.onResponse(token);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
checkToken(token, (bundle) -> {
|
|
||||||
token.setAdditionals(bundle);
|
|
||||||
lastSync = System.currentTimeMillis();
|
|
||||||
lastHash = token.hashCode();
|
|
||||||
callback.onResponse(token);
|
|
||||||
}, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public abstract void doesAccountExists(@NotNull String username, @NotNull NetworkCallback<Boolean> callback, @NotNull NetworkErrorCallback error);
|
|
||||||
|
|
||||||
protected abstract void checkToken(@NotNull T token, @NotNull NetworkCallback<Bundle> bundleCallback, @NotNull NetworkErrorCallback error);
|
|
||||||
|
|
||||||
public final void login(@NotNull String username, @NotNull String password, @NotNull NetworkCallback<T> callback, @NotNull NetworkErrorCallback error) {
|
|
||||||
doesAccountExists(username, success -> {
|
|
||||||
if (success) {
|
|
||||||
createLoginToken(username, password, callback, error);
|
|
||||||
return;
|
|
||||||
} else {
|
|
||||||
callback.onResponse(createUnavailableToken());
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void createLoginToken(@NotNull String username, @NotNull String password, @NotNull NetworkCallback<T> callback, @NotNull NetworkErrorCallback error);
|
|
||||||
|
|
||||||
protected abstract T createUnavailableToken();
|
|
||||||
}
|
|
||||||
@@ -1,373 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.sync;
|
|
||||||
|
|
||||||
import android.Manifest;
|
|
||||||
import android.accounts.Account;
|
|
||||||
import android.accounts.AccountManager;
|
|
||||||
import android.content.AbstractThreadedSyncAdapter;
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.ContentProviderClient;
|
|
||||||
import android.content.ContentResolver;
|
|
||||||
import android.content.ContentValues;
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.ServiceConnection;
|
|
||||||
import android.content.SyncResult;
|
|
||||||
import android.content.pm.PackageManager;
|
|
||||||
import android.database.Cursor;
|
|
||||||
import android.net.Uri;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.os.IBinder;
|
|
||||||
import android.provider.CalendarContract.Calendars;
|
|
||||||
import android.provider.CalendarContract.Events;
|
|
||||||
import android.util.Pair;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Calendar;
|
|
||||||
import java.util.Iterator;
|
|
||||||
|
|
||||||
import androidx.annotation.StringRes;
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.fragments.moddetails.ModulePart;
|
|
||||||
import de.sebse.fuplanner.services.kvv.KVV;
|
|
||||||
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.Grade;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Gradebook;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
|
||||||
import de.sebse.fuplanner.tools.CustomNotificationManager;
|
|
||||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
|
||||||
import de.sebse.fuplanner.tools.Preferences;
|
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
|
||||||
|
|
||||||
import static android.provider.CalendarContract.CALLER_IS_SYNCADAPTER;
|
|
||||||
import static de.sebse.fuplanner.MainActivity.FRAGMENT_MODULES_DETAILS;
|
|
||||||
|
|
||||||
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
|
||||||
private KVV mKVV;
|
|
||||||
private Logger log = new Logger(this);
|
|
||||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
|
||||||
|
|
||||||
|
|
||||||
private boolean mBound = false;
|
|
||||||
private boolean mWaitForBound = false;
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
||||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
|
||||||
KVV.LocalBinder binder = (KVV.LocalBinder) service;
|
|
||||||
mKVV = binder.getService();
|
|
||||||
mBound = true;
|
|
||||||
if (mWaitForBound) {
|
|
||||||
mWaitForBound = false;
|
|
||||||
mQueue.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName arg0) {
|
|
||||||
mBound = false;
|
|
||||||
mKVV = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Set up the sync adapter
|
|
||||||
*/
|
|
||||||
KVVSyncAdapter(Context context, boolean autoInitialize) {
|
|
||||||
super(context, autoInitialize);
|
|
||||||
init(context);
|
|
||||||
}
|
|
||||||
/**
|
|
||||||
* Set up the sync adapter. This form of the
|
|
||||||
* constructor maintains compatibility with Android 3.0
|
|
||||||
* and later platform versions
|
|
||||||
*/
|
|
||||||
public KVVSyncAdapter(
|
|
||||||
Context context,
|
|
||||||
boolean autoInitialize,
|
|
||||||
boolean allowParallelSyncs) {
|
|
||||||
super(context, autoInitialize, allowParallelSyncs);
|
|
||||||
init(context);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(Context context) {
|
|
||||||
// Bind to LocalService
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
* Specify the code you want to run in the sync adapter. The entire
|
|
||||||
* sync adapter runs in a background thread, so you don't have to set
|
|
||||||
* up your own background processing.
|
|
||||||
*/
|
|
||||||
@Override
|
|
||||||
public void onPerformSync(
|
|
||||||
Account account,
|
|
||||||
Bundle extras,
|
|
||||||
String authority,
|
|
||||||
ContentProviderClient provider,
|
|
||||||
SyncResult syncResult) {
|
|
||||||
if (!mBound && !mWaitForBound) {
|
|
||||||
Intent intent = new Intent(getContext(), KVV.class);
|
|
||||||
getContext().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
|
||||||
mWaitForBound = true;
|
|
||||||
mQueue.add(() -> {});
|
|
||||||
}
|
|
||||||
mQueue.add(() -> {
|
|
||||||
mKVV.account().restoreOnlineLogin(bool -> {
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
});
|
|
||||||
mQueue.add(() -> {
|
|
||||||
if (!mKVV.account().isLoggedIn()) {
|
|
||||||
log.w("Not logged in!");
|
|
||||||
mQueue.next();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
mKVV.modules().list().reloadIfOutdated();
|
|
||||||
mKVV.modules().list().recv(success -> {
|
|
||||||
final int[] latch = {0};
|
|
||||||
Iterator<Modules.Module> iterator = success.latestSemesterIterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
latch[0] += 1;
|
|
||||||
iterator.next();
|
|
||||||
}
|
|
||||||
boolean doAddToCalendar = createCalendar(account);
|
|
||||||
log.d("sync calendar", doAddToCalendar);
|
|
||||||
iterator = success.latestSemesterIterator();
|
|
||||||
while (iterator.hasNext()) {
|
|
||||||
Modules.Module module = iterator.next();
|
|
||||||
final ArrayList<Announcement> announcements = module.announcements;
|
|
||||||
final AssignmentList assignments = module.assignments;
|
|
||||||
final EventList events = module.events;
|
|
||||||
final Gradebook gradebook = module.gradebook;
|
|
||||||
final ArrayList<Resource> resources = module.resources;
|
|
||||||
mKVV.modules().details().recv(module, success1 -> {
|
|
||||||
if (success1.second) {
|
|
||||||
sendNotifications(announcements, module.announcements, module.title, Announcement::getTitle, Announcement::getId,
|
|
||||||
module.getID(), ModulePart.ANNOUNCEMENT,
|
|
||||||
R.string.announcement_updated, R.string.announcement_added, R.string.announcement_removed);
|
|
||||||
sendNotifications(assignments, module.assignments, module.title, Assignment::getTitle, Assignment::getId,
|
|
||||||
module.getID(), ModulePart.ASSIGNMENT,
|
|
||||||
R.string.assignment_updated, R.string.assignment_added, R.string.assignment_removed);
|
|
||||||
//ArrayList<Event> differencesAdd = new ArrayList<>();
|
|
||||||
//ArrayList<Pair<Event, Event>> differencesUpd = new ArrayList<>();
|
|
||||||
//ArrayList<Event> differencesDel = new ArrayList<>();
|
|
||||||
sendNotifications(events, module.events, module.title, evt -> evt.getTitle()+" - "+UtilsDate.getModifiedDate(evt.getStartDate()), event -> event.getStartDate() +event.getType()+event.getTitle(),
|
|
||||||
module.getID(), ModulePart.EVENT,
|
|
||||||
R.string.event_updated, R.string.event_added, R.string.event_removed/*,
|
|
||||||
differencesAdd, differencesUpd, differencesDel*/);
|
|
||||||
sendNotifications(gradebook, module.gradebook, module.title, Grade::getItemName, Grade::getItemName,
|
|
||||||
module.getID(), ModulePart.GRADEBOOK,
|
|
||||||
R.string.gradebook_updated, R.string.gradebook_added, R.string.gradebook_removed);
|
|
||||||
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
|
||||||
module.getID(), ModulePart.RESOURCES,
|
|
||||||
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
|
||||||
if (doAddToCalendar) {
|
|
||||||
addToCalendar(module.events, account);
|
|
||||||
}
|
|
||||||
if (--latch[0] == 0) {
|
|
||||||
forceSync();
|
|
||||||
mQueue.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
if (--latch[0] == 0) {
|
|
||||||
forceSync();
|
|
||||||
mQueue.next();
|
|
||||||
}
|
|
||||||
}, true);
|
|
||||||
}
|
|
||||||
}, error -> {
|
|
||||||
log.e(error);
|
|
||||||
mQueue.next();
|
|
||||||
}, true);
|
|
||||||
});
|
|
||||||
mQueue.add(() -> {
|
|
||||||
if (mBound) {
|
|
||||||
getContext().unbindService(mConnection);
|
|
||||||
}
|
|
||||||
mBound = false;
|
|
||||||
mKVV = null;
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static Uri asSyncAdapter(Uri uri, String account, String accountType) {
|
|
||||||
return uri.buildUpon()
|
|
||||||
.appendQueryParameter(CALLER_IS_SYNCADAPTER, "true")
|
|
||||||
.appendQueryParameter(Calendars.ACCOUNT_NAME, account)
|
|
||||||
.appendQueryParameter(Calendars.ACCOUNT_TYPE, accountType).build();
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Uri createCalendarWithName(Context ctx, Account account, String calendarName) {
|
|
||||||
String accountName = account.name;
|
|
||||||
String accountType = account.type;
|
|
||||||
Uri target = asSyncAdapter(Calendars.CONTENT_URI, accountName, accountType);
|
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(Calendars._ID, calendarName.hashCode());
|
|
||||||
values.put(Calendars.ACCOUNT_NAME, accountName);
|
|
||||||
values.put(Calendars.ACCOUNT_TYPE, accountType);
|
|
||||||
values.put(Calendars.NAME, calendarName);
|
|
||||||
values.put(Calendars.CALENDAR_DISPLAY_NAME, calendarName);
|
|
||||||
values.put(Calendars.CALENDAR_COLOR, 0x00FF00);
|
|
||||||
values.put(Calendars.CALENDAR_ACCESS_LEVEL, Calendars.CAL_ACCESS_READ);
|
|
||||||
values.put(Calendars.OWNER_ACCOUNT, accountName);
|
|
||||||
values.put(Calendars.VISIBLE, 1);
|
|
||||||
values.put(Calendars.SYNC_EVENTS, 1);
|
|
||||||
values.put(Calendars.CALENDAR_TIME_ZONE, "Europe/Berlin");
|
|
||||||
values.put(Calendars.CAN_PARTIALLY_UPDATE, 1);
|
|
||||||
values.put(Calendars.CAL_SYNC1, System.currentTimeMillis());
|
|
||||||
|
|
||||||
return ctx.getContentResolver().insert(target, values);
|
|
||||||
}
|
|
||||||
|
|
||||||
private int createEvents(Context ctx, Account account, String calendarName, EventList events) {
|
|
||||||
String accountName = account.name;
|
|
||||||
String accountType = account.type;
|
|
||||||
Uri target = asSyncAdapter(Events.CONTENT_URI, accountName, accountType);
|
|
||||||
|
|
||||||
ContentValues[] contentValues = new ContentValues[events.size()];
|
|
||||||
for (int i = 0; i < contentValues.length; i++) {
|
|
||||||
Event event = events.get(i);
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
//values.put(Events._ID, event.hashCode());
|
|
||||||
values.put(Events.TITLE, event.getTitle());
|
|
||||||
values.put(Events.DTSTART, event.getStartDate());
|
|
||||||
values.put(Events.DTEND, event.getEndDate());
|
|
||||||
values.put(Events.CALENDAR_ID, calendarName.hashCode());
|
|
||||||
contentValues[i] = values;
|
|
||||||
//ctx.getContentResolver().insert(target, values);
|
|
||||||
}
|
|
||||||
log.d(contentValues.length);
|
|
||||||
return ctx.getContentResolver().bulkInsert(target, contentValues);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Cursor getCalendars(Context ctx, Account account) {
|
|
||||||
Uri target = asSyncAdapter(Calendars.CONTENT_URI, account.name, account.type);
|
|
||||||
|
|
||||||
return ctx.getContentResolver().query(target, new String[]{Calendars.CALENDAR_DISPLAY_NAME, Calendars.ACCOUNT_NAME}, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static Cursor getEvents(Context ctx, Account account) {
|
|
||||||
Uri target = asSyncAdapter(Events.CONTENT_URI, account.name, account.type);
|
|
||||||
|
|
||||||
return ctx.getContentResolver().query(target, new String[]{Events.TITLE, Events.DTSTART}, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static int deleteCalendars(Context ctx, Account account) {
|
|
||||||
String accountName = account.name;
|
|
||||||
String accountType = account.type;
|
|
||||||
Uri target = asSyncAdapter(Calendars.CONTENT_URI, account.name, account.type);
|
|
||||||
|
|
||||||
ContentValues values = new ContentValues();
|
|
||||||
values.put(Calendars.ACCOUNT_NAME, accountName);
|
|
||||||
values.put(Calendars.ACCOUNT_TYPE, accountType);
|
|
||||||
|
|
||||||
return ctx.getContentResolver().delete(target, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void addToCalendar(EventList events, Account account) {
|
|
||||||
if (events == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED
|
|
||||||
&& ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
boolean integrationEnabled = Preferences.getBoolean(getContext(), R.string.pref_add_calendar);
|
|
||||||
if (integrationEnabled) {
|
|
||||||
createEvents(getContext(), account, getContext().getString(R.string.app_name), events);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean createCalendar(Account account) {
|
|
||||||
if (ContextCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_CALENDAR) == PackageManager.PERMISSION_GRANTED
|
|
||||||
&& ContextCompat.checkSelfPermission(getContext(), Manifest.permission.READ_CALENDAR) == PackageManager.PERMISSION_GRANTED) {
|
|
||||||
boolean integrationEnabled = Preferences.getBoolean(getContext(), R.string.pref_add_calendar);
|
|
||||||
if (integrationEnabled) {
|
|
||||||
//log.w("No calendar found! Add calendar...");
|
|
||||||
deleteCalendars(getContext(), account);
|
|
||||||
createCalendarWithName(getContext(), account, getContext().getString(R.string.app_name));
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
log.w("Calendar found and integration disabled! Delete calendar...");
|
|
||||||
deleteCalendars(getContext(), account);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.w("Permission calendar not granted!");
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void forceSync() {
|
|
||||||
// Force a sync
|
|
||||||
Bundle extras = new Bundle();
|
|
||||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_EXPEDITED, true);
|
|
||||||
extras.putBoolean(ContentResolver.SYNC_EXTRAS_MANUAL, true);
|
|
||||||
AccountManager am = AccountManager.get(getContext());
|
|
||||||
Account[] acc = am.getAccountsByType("com.google");
|
|
||||||
Account account = null;
|
|
||||||
if (acc.length>0) {
|
|
||||||
account = acc[0];
|
|
||||||
ContentResolver.requestSync(account, "com.android.calendar", extras);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, String moduleId, int modulePart, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes) {
|
|
||||||
sendNotifications(oldList, newList, title, titleInterface, idInterface, moduleId, modulePart, updateRes, addRes, removeRes, null, null, null);
|
|
||||||
}
|
|
||||||
|
|
||||||
private <T> void sendNotifications(Iterable<T> oldList, Iterable<T> newList, String title, StringInterface<T> titleInterface, StringInterface<T> idInterface, String moduleId, int modulePart, @StringRes int updateRes, @StringRes int addRes, @StringRes int removeRes, ArrayList<T> changesAdd, ArrayList<Pair<T, T>> changesUpd, ArrayList<T> changesDel) {
|
|
||||||
if (oldList == null || newList == null) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
ArrayList<T> obsoletes = new ArrayList<>();
|
|
||||||
for (T old: oldList) {
|
|
||||||
obsoletes.add(old);
|
|
||||||
}
|
|
||||||
String targetData = moduleId+"."+ModulePart.getPageByPart(modulePart);
|
|
||||||
for (T newEntry: newList) {
|
|
||||||
boolean found = false;
|
|
||||||
for (T oldEntry: oldList) {
|
|
||||||
if (idInterface.get(newEntry).equals(idInterface.get(oldEntry))) {
|
|
||||||
found = true;
|
|
||||||
if (newEntry.hashCode() != oldEntry.hashCode()) {
|
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(updateRes, title), titleInterface.get(newEntry), FRAGMENT_MODULES_DETAILS, targetData);
|
|
||||||
if (changesUpd != null) {
|
|
||||||
changesUpd.add(new Pair<>(oldEntry, newEntry));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
obsoletes.remove(oldEntry);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!found) {
|
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(addRes, title), titleInterface.get(newEntry), FRAGMENT_MODULES_DETAILS, targetData);
|
|
||||||
if (changesAdd != null) {
|
|
||||||
changesAdd.add(newEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
for (T oldEntry: obsoletes) {
|
|
||||||
CustomNotificationManager.sendNotification(getContext(), getContext().getString(removeRes, title), titleInterface.get(oldEntry), FRAGMENT_MODULES_DETAILS, targetData);
|
|
||||||
if (changesDel != null) {
|
|
||||||
changesDel.add(oldEntry);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@FunctionalInterface
|
|
||||||
interface StringInterface<T> {
|
|
||||||
String get(T element);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,158 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.sync;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.regex.Matcher;
|
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.LoginTokenWB;
|
|
||||||
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.Constants.WB_SERVER_URL;
|
|
||||||
|
|
||||||
public class WBLogin extends LoginRoutine<LoginTokenWB> {
|
|
||||||
private final FULogin fuLogin;
|
|
||||||
|
|
||||||
public WBLogin(Context context, FULogin fuLogin) {
|
|
||||||
super(context);
|
|
||||||
this.fuLogin = fuLogin;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void doesAccountExists(@NotNull String username, @NotNull NetworkCallback<Boolean> callback, @NotNull NetworkErrorCallback error) {
|
|
||||||
callback.onResponse(true);
|
|
||||||
get(String.format(WB_SERVER_URL + "direct/profile/%s.json", username), null, response -> {
|
|
||||||
callback.onResponse(true);
|
|
||||||
}, err -> {
|
|
||||||
if (err.networkResponse.statusCode == 403) {
|
|
||||||
callback.onResponse(true);
|
|
||||||
} else {
|
|
||||||
callback.onResponse(false);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected LoginTokenWB createUnavailableToken() {
|
|
||||||
return new LoginTokenWB();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void checkToken(@NotNull LoginTokenWB token, @NotNull NetworkCallback<Bundle> bundleCallback, @NotNull NetworkErrorCallback error) {
|
|
||||||
get(String.format(WB_SERVER_URL + "direct/profile/%s.json", token.getUsername()), token.getCookies(), response -> {
|
|
||||||
String body = response.getParsed();
|
|
||||||
if (body == null) {
|
|
||||||
error.onError(new NetworkError(100172, 403, "Testing WB login failed!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
JSONObject json = new JSONObject(body);
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("fullName", json.getString("displayName"));
|
|
||||||
bundle.putString("email", json.getString("email"));
|
|
||||||
bundleCallback.onResponse(bundle);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
error.onError(new NetworkError(100171, 403, "Cannot parse WB profile!"));
|
|
||||||
}
|
|
||||||
}, err -> error.onError(new NetworkError(100170, err.networkResponse.statusCode, "Testing WB login failed!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void createLoginToken(@NotNull String username, @NotNull String password, @NotNull NetworkCallback<LoginTokenWB> callback, @NotNull NetworkErrorCallback error) {
|
|
||||||
getSAMLLocation(samlLocation -> {
|
|
||||||
fuLogin.fulogin(samlLocation, username, password, samlResponse -> {
|
|
||||||
startShibSession(samlResponse, shibSessionKey -> {
|
|
||||||
String shibsessionKey = shibSessionKey.getString("shibsessionKey");
|
|
||||||
String shibsessionName = shibSessionKey.getString("shibsessionName");
|
|
||||||
startSession(shibsessionKey, shibsessionName, sessionCookies -> {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("username", username);
|
|
||||||
bundle.putAll(sessionCookies);
|
|
||||||
LoginTokenWB tokenWB = new LoginTokenWB(bundle);
|
|
||||||
testToken(tokenWB, callback, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}, error);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
1= GET https://mycampus.imp.fu-berlin.de/Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub
|
|
||||||
-> Location-Header: https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO?SAMLResponse=[SAMLResponse]&RelayState=[RelayState]
|
|
||||||
*/
|
|
||||||
private void getSAMLLocation(final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
get(WB_SERVER_URL + "Shibboleth.sso/Login?entityID=https://identity.fu-berlin.de/idp-fub", null, response -> {
|
|
||||||
String location = response.getHeaders().get("Location");
|
|
||||||
if (location == null) {
|
|
||||||
errorCallback.onError(new NetworkError(100111, -1, "Error on getting WB SAML request!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
callback.onResponse(location);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100110, error.networkResponse.statusCode, "Error on getting WB SAML request!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
5= POST https://mycampus.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
|
|
||||||
+ Body: SAMLResponse=[SAML-RESPONSE]
|
|
||||||
+ Header: Content-Type: application/x-www-form-urlencoded
|
|
||||||
-> Set-Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
|
||||||
*/
|
|
||||||
private void startShibSession(String samlResponse, final NetworkCallback<Bundle> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> body = new HashMap<>();
|
|
||||||
body.put("SAMLResponse", samlResponse);
|
|
||||||
post(WB_SERVER_URL + "Shibboleth.sso/SAML2/POST", null, body, response -> {
|
|
||||||
String cookies = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookies ==null) {
|
|
||||||
errorCallback.onError(new NetworkError(100151, -1, "Error on starting WB session!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Pattern pattern = Pattern.compile("(_shibsession_[0-9a-f]+)=([^;]+);");
|
|
||||||
Matcher matcher = pattern.matcher(cookies);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
errorCallback.onError(new NetworkError(100152, -1, "Error on starting WB session!"));
|
|
||||||
}
|
|
||||||
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("shibsessionKey", matcher.group(1));
|
|
||||||
bundle.putString("shibsessionName", matcher.group(2));
|
|
||||||
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100150, error.networkResponse.statusCode, "Error on starting WB session!")));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/*
|
|
||||||
6= https://mycampus.imp.fu-berlin.de/sakai-login-tool/container
|
|
||||||
+ Cookie: _shibsession_[SESS-NR]: [SESS-VALUE]
|
|
||||||
-> Set-Cookie: JSESSIONID: [JSESSION-KVV]
|
|
||||||
*/
|
|
||||||
private void startSession(String shibsessionKey, String shibsessionName, final NetworkCallback<Bundle> callback, final NetworkErrorCallback errorCallback) {
|
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put(shibsessionKey, shibsessionName);
|
|
||||||
get(WB_SERVER_URL + "sakai-login-tool/container", cookies, response -> {
|
|
||||||
String cookies1 = response.getHeaders().get("Set-Cookie");
|
|
||||||
if (cookies1 ==null) {
|
|
||||||
errorCallback.onError(new NetworkError(100161, -1, "Cannot finish WB login process!"));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
Bundle bundle = getCookie(cookies1, new String[]{"JSESSIONID"});
|
|
||||||
callback.onResponse(bundle);
|
|
||||||
} catch (NoSuchFieldException e) {
|
|
||||||
errorCallback.onError(new NetworkError(100162, -1, "Cannot finish WB login process!"));
|
|
||||||
}
|
|
||||||
}, error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish WB login process!")));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,98 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
|
|
||||||
public class CacheBBCourse implements Serializable {
|
|
||||||
private transient static final long RESAVE_TIMER = 1000L * 60 * 60 * 24 * 30;
|
|
||||||
private static final String FILE_NAME = "BBCourseStorageSaving";
|
|
||||||
private static final String FILE_NAME_TIMESTAMP = "BBCourseStorageSavingTimestamp";
|
|
||||||
private transient long mLastTimestamp = 0;
|
|
||||||
|
|
||||||
private HashSet<String> mKVVCourseList = new HashSet<>();
|
|
||||||
private long mKVVCourseListRefresh = 0;
|
|
||||||
private HashMap<String, Modules.Module> mBBCourseList = new HashMap<>();
|
|
||||||
private HashMap<String, Long> mBBCourseListRefresh = new HashMap<>();
|
|
||||||
|
|
||||||
public static CacheBBCourse load(Context context) throws IOException, ClassNotFoundException {
|
|
||||||
FileInputStream fis;
|
|
||||||
try {
|
|
||||||
fis = context.openFileInput(FILE_NAME);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
Object readObject = is.readObject();
|
|
||||||
if (!(readObject instanceof CacheBBCourse))
|
|
||||||
return null;
|
|
||||||
CacheBBCourse storage = (CacheBBCourse) readObject;
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
is = new ObjectInputStream(fis);
|
|
||||||
storage.mLastTimestamp = is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNewerVersionInStorage(Context context) throws IOException {
|
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
boolean result = this.mLastTimestamp < is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
|
||||||
os.writeObject(this);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
fos = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
|
||||||
os = new ObjectOutputStream(fos);
|
|
||||||
this.mLastTimestamp = System.currentTimeMillis();
|
|
||||||
os.writeLong(this.mLastTimestamp);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addKVVCourseID(String courseID) {
|
|
||||||
mKVVCourseList.add(courseID);
|
|
||||||
mKVVCourseListRefresh = System.currentTimeMillis();
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean hasKVVCourseID(String courseID) {
|
|
||||||
if (mKVVCourseListRefresh + RESAVE_TIMER < System.currentTimeMillis())
|
|
||||||
return false;
|
|
||||||
return mKVVCourseList.contains(courseID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setBBCourse(String courseID, Modules.Module module) {
|
|
||||||
mBBCourseList.put(courseID, module);
|
|
||||||
mBBCourseListRefresh.put(courseID, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Modules.Module getBBCourse(String courseID) {
|
|
||||||
if (!mBBCourseListRefresh.containsKey(courseID))
|
|
||||||
return null;
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (mBBCourseListRefresh.get(courseID) + RESAVE_TIMER < System.currentTimeMillis())
|
|
||||||
return null;
|
|
||||||
return mBBCourseList.get(courseID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,78 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class CacheBBEventNumber implements Serializable {
|
|
||||||
private transient static final long RESAVE_TIMER = 1000L * 60 * 60 * 24 * 30;
|
|
||||||
private static final String FILE_NAME = "BBEventNumberStorageSaving";
|
|
||||||
private static final String FILE_NAME_TIMESTAMP = "BBEventNumberStorageSavingTimestamp";
|
|
||||||
private transient long mLastTimestamp = 0;
|
|
||||||
|
|
||||||
private HashMap<String, String> mBBEventNumbers = new HashMap<>();
|
|
||||||
private HashMap<String, Long> mBBEventNumbersRefresh = new HashMap<>();
|
|
||||||
|
|
||||||
public static CacheBBEventNumber load(Context context) throws IOException, ClassNotFoundException {
|
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
Object readObject = is.readObject();
|
|
||||||
if (!(readObject instanceof CacheBBEventNumber))
|
|
||||||
return null;
|
|
||||||
CacheBBEventNumber storage = (CacheBBEventNumber) readObject;
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
is = new ObjectInputStream(fis);
|
|
||||||
storage.mLastTimestamp = is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNewerVersionInStorage(Context context) throws IOException {
|
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
boolean result = this.mLastTimestamp < is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
|
||||||
os.writeObject(this);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
fos = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
|
||||||
os = new ObjectOutputStream(fos);
|
|
||||||
this.mLastTimestamp = System.currentTimeMillis();
|
|
||||||
os.writeLong(this.mLastTimestamp);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setVVNumber(String lvNumber, String vvNumber) {
|
|
||||||
mBBEventNumbers.put(lvNumber, vvNumber);
|
|
||||||
mBBEventNumbersRefresh.put(lvNumber, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getVVNumber(String lvNumber) {
|
|
||||||
if (!mBBEventNumbersRefresh.containsKey(lvNumber))
|
|
||||||
return null;
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (mBBEventNumbersRefresh.get(lvNumber) + RESAVE_TIMER < System.currentTimeMillis())
|
|
||||||
return null;
|
|
||||||
return mBBEventNumbers.get(lvNumber);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class CacheKVVCourse implements Serializable {
|
|
||||||
private transient static final long RESAVE_TIMER = 1000L * 60 * 60 * 24 * 30;
|
|
||||||
private static final String FILE_NAME = "KVVCourseStorageSaving";
|
|
||||||
private static final String FILE_NAME_TIMESTAMP = "KVVCourseStorageSavingTimestamp";
|
|
||||||
private transient long mLastTimestamp = 0;
|
|
||||||
|
|
||||||
private HashMap<String, Modules.Module> mKVVCourseList = new HashMap<>();
|
|
||||||
private HashMap<String, Long> mKVVCourseListRefresh = new HashMap<>();
|
|
||||||
|
|
||||||
public static CacheKVVCourse load(Context context) throws IOException, ClassNotFoundException {
|
|
||||||
FileInputStream fis;
|
|
||||||
try {
|
|
||||||
fis = context.openFileInput(FILE_NAME);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
Object readObject = is.readObject();
|
|
||||||
if (!(readObject instanceof CacheKVVCourse))
|
|
||||||
return null;
|
|
||||||
CacheKVVCourse storage = (CacheKVVCourse) readObject;
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
is = new ObjectInputStream(fis);
|
|
||||||
storage.mLastTimestamp = is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNewerVersionInStorage(Context context) throws IOException {
|
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
boolean result = this.mLastTimestamp < is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
|
||||||
os.writeObject(this);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
fos = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
|
||||||
os = new ObjectOutputStream(fos);
|
|
||||||
this.mLastTimestamp = System.currentTimeMillis();
|
|
||||||
os.writeLong(this.mLastTimestamp);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setKVVCourse(String courseID, Modules.Module module) {
|
|
||||||
mKVVCourseList.put(courseID, module);
|
|
||||||
mKVVCourseListRefresh.put(courseID, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public Modules.Module getKVVCourse(String courseID) {
|
|
||||||
if (!mKVVCourseListRefresh.containsKey(courseID))
|
|
||||||
return null;
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (mKVVCourseListRefresh.get(courseID) + RESAVE_TIMER < System.currentTimeMillis())
|
|
||||||
return null;
|
|
||||||
return mKVVCourseList.get(courseID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,101 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.FileOutputStream;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.ObjectInputStream;
|
|
||||||
import java.io.ObjectOutputStream;
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
public class CacheLecturer implements Serializable {
|
|
||||||
private transient static final long RESAVE_TIMER = 1000L * 60 * 60 * 24 * 30;
|
|
||||||
private static final String FILE_NAME = "LecturerStorageSaving";
|
|
||||||
private static final String FILE_NAME_TIMESTAMP = "LecturerStorageSavingTimestamp";
|
|
||||||
private transient long mLastTimestamp = 0;
|
|
||||||
|
|
||||||
private HashMap<String, ArrayList<String>> mLecturersPerCourse = new HashMap<>();
|
|
||||||
private HashMap<String, Long> mLecturersPerCourseRefresh = new HashMap<>();
|
|
||||||
private HashMap<String, Lecturer> mLecturers = new HashMap<>();
|
|
||||||
private HashMap<String, Long> mLecturersRefresh = new HashMap<>();
|
|
||||||
|
|
||||||
public static CacheLecturer load(Context context) throws IOException, ClassNotFoundException {
|
|
||||||
FileInputStream fis;
|
|
||||||
try {
|
|
||||||
fis = context.openFileInput(FILE_NAME);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
Object readObject = is.readObject();
|
|
||||||
if (!(readObject instanceof CacheLecturer))
|
|
||||||
return null;
|
|
||||||
CacheLecturer storage = (CacheLecturer) readObject;
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
is = new ObjectInputStream(fis);
|
|
||||||
storage.mLastTimestamp = is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
|
|
||||||
return storage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isNewerVersionInStorage(Context context) throws IOException {
|
|
||||||
FileInputStream fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
|
||||||
ObjectInputStream is = new ObjectInputStream(fis);
|
|
||||||
boolean result = this.mLastTimestamp < is.readLong();
|
|
||||||
is.close();
|
|
||||||
fis.close();
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void save(Context context) throws IOException {
|
|
||||||
FileOutputStream fos = context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE);
|
|
||||||
ObjectOutputStream os = new ObjectOutputStream(fos);
|
|
||||||
os.writeObject(this);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
|
|
||||||
fos = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
|
|
||||||
os = new ObjectOutputStream(fos);
|
|
||||||
this.mLastTimestamp = System.currentTimeMillis();
|
|
||||||
os.writeLong(this.mLastTimestamp);
|
|
||||||
os.close();
|
|
||||||
fos.close();
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLecturersPerCourse(String courseID, ArrayList<String> lecturers) {
|
|
||||||
mLecturersPerCourse.put(courseID, lecturers);
|
|
||||||
mLecturersPerCourseRefresh.put(courseID, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLecturer(String lecturerID, Lecturer lecturer) {
|
|
||||||
mLecturers.put(lecturerID, lecturer);
|
|
||||||
mLecturersRefresh.put(lecturerID, System.currentTimeMillis());
|
|
||||||
}
|
|
||||||
|
|
||||||
public ArrayList<String> getLecturersPerCourse(String courseID) {
|
|
||||||
if (!mLecturersPerCourseRefresh.containsKey(courseID))
|
|
||||||
return null;
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (mLecturersPerCourseRefresh.get(courseID) + RESAVE_TIMER < System.currentTimeMillis())
|
|
||||||
return null;
|
|
||||||
return mLecturersPerCourse.get(courseID);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Lecturer getLecturer(String lecturerID) {
|
|
||||||
if (!mLecturersRefresh.containsKey(lecturerID))
|
|
||||||
return null;
|
|
||||||
//noinspection ConstantConditions
|
|
||||||
if (mLecturersRefresh.get(lecturerID) + RESAVE_TIMER < System.currentTimeMillis())
|
|
||||||
return null;
|
|
||||||
return mLecturers.get(lecturerID);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,8 +1,5 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.Configuration;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
import com.google.android.gms.common.internal.Objects;
|
||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
@@ -11,9 +8,6 @@ import java.security.MessageDigest;
|
|||||||
import java.security.NoSuchAlgorithmException;
|
import java.security.NoSuchAlgorithmException;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import androidx.appcompat.app.AppCompatDelegate;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.tools.ColorRGB;
|
import de.sebse.fuplanner.tools.ColorRGB;
|
||||||
|
|
||||||
public class Event implements Serializable {
|
public class Event implements Serializable {
|
||||||
@@ -66,7 +60,7 @@ public class Event implements Serializable {
|
|||||||
return siteId;
|
return siteId;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ColorRGB getColor(@Nullable Context context) {
|
public ColorRGB getColor() {
|
||||||
MessageDigest digest;
|
MessageDigest digest;
|
||||||
try {
|
try {
|
||||||
digest = MessageDigest.getInstance("SHA-256");
|
digest = MessageDigest.getInstance("SHA-256");
|
||||||
@@ -75,7 +69,11 @@ public class Event implements Serializable {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
byte[] encodedHash;
|
byte[] encodedHash;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
||||||
encodedHash = digest.digest(siteId.getBytes(StandardCharsets.UTF_8));
|
encodedHash = digest.digest(siteId.getBytes(StandardCharsets.UTF_8));
|
||||||
|
} else {
|
||||||
|
encodedHash = digest.digest(siteId.getBytes());
|
||||||
|
}
|
||||||
int h = (0xff & encodedHash[0]) + (0xff & encodedHash[1]) * 255;
|
int h = (0xff & encodedHash[0]) + (0xff & encodedHash[1]) * 255;
|
||||||
h = h * 360 / 0xffff;
|
h = h * 360 / 0xffff;
|
||||||
//int s = 0xff & encodedHash[2];
|
//int s = 0xff & encodedHash[2];
|
||||||
@@ -85,21 +83,8 @@ public class Event implements Serializable {
|
|||||||
|
|
||||||
// range for more beautiful colors
|
// range for more beautiful colors
|
||||||
h = h / 30 * 30;
|
h = h / 30 * 30;
|
||||||
|
|
||||||
boolean nightMode = false;
|
|
||||||
if (context != null) {
|
|
||||||
int currentNightMode = context.getResources().getConfiguration().uiMode
|
|
||||||
& Configuration.UI_MODE_NIGHT_MASK;
|
|
||||||
if (currentNightMode == Configuration.UI_MODE_NIGHT_YES) {
|
|
||||||
nightMode = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
int s = 100;
|
int s = 100;
|
||||||
int v = 80;
|
int v = 80;
|
||||||
if (nightMode) {
|
|
||||||
s = 60;
|
|
||||||
v = 100;
|
|
||||||
}
|
|
||||||
|
|
||||||
return hsvToRgb(h/360.0, s/100.0, v/100.0);
|
return hsvToRgb(h/360.0, s/100.0, v/100.0);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class Gradebook implements Serializable, Iterable<Grade> {
|
|
||||||
private ArrayList<Grade> gradebook = new ArrayList<>();
|
|
||||||
private final static String[] EXAM_KEYWORDS = new String[] {"exam", "klausur", "prüfung"};
|
|
||||||
private final static String[] ASSIGNMENT_KEYWORDS = new String[] {"übung", "assignment", "blatt", "sheet", "exercise"};
|
|
||||||
|
|
||||||
public void addGrade(Grade grade) {
|
|
||||||
gradebook.add(0, grade);
|
|
||||||
}
|
|
||||||
|
|
||||||
public CategorizedGrades getAutoCategorizedGrades() {
|
|
||||||
ArrayList<Grade> exams = new ArrayList<>();
|
|
||||||
ArrayList<Grade> assignments = new ArrayList<>();
|
|
||||||
ArrayList<Grade> others = new ArrayList<>();
|
|
||||||
for (Grade grade : gradebook) {
|
|
||||||
boolean found = false;
|
|
||||||
String name = grade.getItemName().toLowerCase();
|
|
||||||
for (String keyword : EXAM_KEYWORDS) {
|
|
||||||
if (name.contains(keyword)) {
|
|
||||||
exams.add(grade);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) continue;
|
|
||||||
for (String keyword : ASSIGNMENT_KEYWORDS) {
|
|
||||||
if (name.contains(keyword)) {
|
|
||||||
assignments.add(grade);
|
|
||||||
found = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (found) continue;
|
|
||||||
others.add(grade);
|
|
||||||
}
|
|
||||||
return new CategorizedGrades(exams, assignments, others);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GradebookOutput getUncategorizedGrades() {
|
|
||||||
return new GradebookOutput(gradebook);
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Iterator<Grade> iterator() {
|
|
||||||
return gradebook.iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public class CategorizedGrades {
|
|
||||||
private GradebookOutput exams;
|
|
||||||
private GradebookOutput assignments;
|
|
||||||
private GradebookOutput others;
|
|
||||||
|
|
||||||
private CategorizedGrades(List<Grade> exams, List<Grade> assignments, List<Grade> others) {
|
|
||||||
this.exams = new GradebookOutput(exams);
|
|
||||||
this.assignments = new GradebookOutput(assignments);
|
|
||||||
this.others = new GradebookOutput(others);
|
|
||||||
}
|
|
||||||
|
|
||||||
public GradebookOutput getExams() {
|
|
||||||
return exams;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GradebookOutput getAssignments() {
|
|
||||||
return assignments;
|
|
||||||
}
|
|
||||||
|
|
||||||
public GradebookOutput getOthers() {
|
|
||||||
return others;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class GradebookOutput {
|
|
||||||
public List<Grade> grades;
|
|
||||||
|
|
||||||
private GradebookOutput(List<Grade> grades) {
|
|
||||||
this.grades = Collections.unmodifiableList(grades);
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getPercentage() {
|
|
||||||
float maxPoints = 0;
|
|
||||||
float userPoints = 0;
|
|
||||||
if (grades != null) {
|
|
||||||
for (Grade g : grades){
|
|
||||||
maxPoints += g.getMaxPoints();
|
|
||||||
userPoints += g.getPoints();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (maxPoints == 0)
|
|
||||||
return 0;
|
|
||||||
return userPoints / maxPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getMaxPointSum() {
|
|
||||||
float maxPoints = 0;
|
|
||||||
if (grades != null) {
|
|
||||||
for (Grade g : grades){
|
|
||||||
maxPoints += g.getMaxPoints();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return maxPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public float getUserPointSum() {
|
|
||||||
float userPoints = 0;
|
|
||||||
if (grades != null) {
|
|
||||||
for (Grade g : grades){
|
|
||||||
userPoints += g.getPoints();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return userPoints;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Grade getBestGrade() {
|
|
||||||
Grade bestGrade = null;
|
|
||||||
double bestValue = -1;
|
|
||||||
if (grades != null) {
|
|
||||||
for (Grade g : grades){
|
|
||||||
double perc = g.getPoints() / g.getMaxPoints();
|
|
||||||
if (perc > bestValue) {
|
|
||||||
bestValue = perc;
|
|
||||||
bestGrade = g;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return bestGrade;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -6,7 +6,6 @@ import android.annotation.SuppressLint;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
@@ -37,17 +36,14 @@ public class GroupedEvents extends EventList {
|
|||||||
return skippedDayCount;
|
return skippedDayCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public class Group implements Iterable<Event> {
|
public class Group {
|
||||||
private long firstDate;
|
private long firstDate;
|
||||||
private long lastDate;
|
private long lastDate;
|
||||||
private final ArrayList<Long> skippedDates;
|
private final ArrayList<Long> skippedDates;
|
||||||
private final ArrayList<Event> allEvents = new ArrayList<>();
|
|
||||||
|
|
||||||
private final int dayOfWeek;
|
private final int dayOfWeek;
|
||||||
private final long startTime;
|
private final long startTime;
|
||||||
private final long duration;
|
private final long duration;
|
||||||
private final String location;
|
|
||||||
private final String title;
|
|
||||||
|
|
||||||
private Group(Event event) {
|
private Group(Event event) {
|
||||||
Calendar calendar = Calendar.getInstance();
|
Calendar calendar = Calendar.getInstance();
|
||||||
@@ -55,8 +51,6 @@ public class GroupedEvents extends EventList {
|
|||||||
dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
||||||
duration = event.getEndDate()-event.getStartDate();
|
duration = event.getEndDate()-event.getStartDate();
|
||||||
location = event.getLocation();
|
|
||||||
title = event.getTitle();
|
|
||||||
|
|
||||||
skippedDates = new ArrayList<>();
|
skippedDates = new ArrayList<>();
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
@@ -65,7 +59,6 @@ public class GroupedEvents extends EventList {
|
|||||||
calendar.set(Calendar.MILLISECOND, 0);
|
calendar.set(Calendar.MILLISECOND, 0);
|
||||||
firstDate = calendar.getTimeInMillis();
|
firstDate = calendar.getTimeInMillis();
|
||||||
lastDate = firstDate;
|
lastDate = firstDate;
|
||||||
allEvents.add(event);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean add(Event event) {
|
private boolean add(Event event) {
|
||||||
@@ -74,8 +67,7 @@ public class GroupedEvents extends EventList {
|
|||||||
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
||||||
int startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
int startTime = calendar.get(Calendar.HOUR_OF_DAY)*3600000+calendar.get(Calendar.MINUTE)*60000+calendar.get(Calendar.SECOND)*1000+calendar.get(Calendar.MILLISECOND);
|
||||||
long length = event.getEndDate()-event.getStartDate();
|
long length = event.getEndDate()-event.getStartDate();
|
||||||
String location = event.getLocation();
|
if (this.dayOfWeek != dayOfWeek || this.startTime != startTime || this.duration != length)
|
||||||
if (this.dayOfWeek != dayOfWeek || this.startTime != startTime || this.duration != length || !this.location.equals(location))
|
|
||||||
return false;
|
return false;
|
||||||
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
calendar.set(Calendar.HOUR_OF_DAY, 0);
|
||||||
calendar.set(Calendar.MINUTE, 0);
|
calendar.set(Calendar.MINUTE, 0);
|
||||||
@@ -100,7 +92,6 @@ public class GroupedEvents extends EventList {
|
|||||||
skippedDates.remove(date);
|
skippedDates.remove(date);
|
||||||
skippedDayCount -= 1;
|
skippedDayCount -= 1;
|
||||||
}
|
}
|
||||||
allEvents.add(event);
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,29 +126,11 @@ public class GroupedEvents extends EventList {
|
|||||||
return duration;
|
return duration;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getLocation() {
|
|
||||||
return location;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
|
||||||
return title;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressLint("DefaultLocale")
|
@SuppressLint("DefaultLocale")
|
||||||
@NonNull
|
@NonNull
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%d - %d - %d - %s", dayOfWeek, startTime, duration, skippedDates);
|
return String.format("%d - %d - %d - %s", dayOfWeek, startTime, duration, skippedDates);
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public Iterator<Event> iterator() {
|
|
||||||
return Collections.unmodifiableList(allEvents).iterator();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
|
||||||
return allEvents.size();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,13 +12,6 @@ public class Lecturer implements Serializable {
|
|||||||
private final String mail;
|
private final String mail;
|
||||||
private final boolean isResponsible;
|
private final boolean isResponsible;
|
||||||
|
|
||||||
public Lecturer(String firstName, String surname, String mail, boolean isResponsible) {
|
|
||||||
this.firstName = firstName;
|
|
||||||
this.surname = surname;
|
|
||||||
this.mail = mail;
|
|
||||||
this.isResponsible = 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);
|
||||||
|
|||||||
@@ -1,104 +1,88 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
package de.sebse.fuplanner.services.kvv.types;
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.jetbrains.annotations.Nullable;
|
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Objects;
|
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
public abstract class LoginToken {
|
/**
|
||||||
private boolean isExpanded = false;
|
* Created by sebastian on 29.10.17.
|
||||||
private boolean isAvailable = false;
|
*/
|
||||||
|
|
||||||
LoginToken(@NotNull CustomAccountManager manager, @NotNull LoginTokenInterface callback, @NotNull CustomAccountManager.ExceptionInterface errorCallback) {
|
public class LoginToken {
|
||||||
|
static Logger log = new Logger("LoginToken");
|
||||||
|
|
||||||
|
private final String username;
|
||||||
|
private final String JSESSIONID;
|
||||||
|
@Nullable private String fullName;
|
||||||
|
@Nullable private String email;
|
||||||
|
|
||||||
|
public LoginToken(String username, String JSESSIONID) {
|
||||||
|
this.username = username;
|
||||||
|
this.JSESSIONID = JSESSIONID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void load(CustomAccountManager manager, LoginTokenInterface callback) {
|
||||||
if (!manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
if (!manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||||
callback.run(null);
|
callback.run(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
manager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, tokenString -> {
|
manager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, tokenString -> {
|
||||||
if (tokenString == null) {
|
if (tokenString == null) {
|
||||||
callback.run(null);
|
callback.run(null);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
fromString(tokenString);
|
callback.run(LoginToken.fromJsonString(tokenString));
|
||||||
callback.run(this);
|
});
|
||||||
}, errorCallback);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginToken() {
|
public void delete(CustomAccountManager manager) {
|
||||||
super();
|
manager.deleteAccount(AccountGeneral.ACCOUNT_TYPE);
|
||||||
}
|
}
|
||||||
|
|
||||||
LoginToken(Bundle bundle) {
|
public void setAdditionals(String fullName, String email) {
|
||||||
super();
|
this.fullName = fullName;
|
||||||
init(bundle);
|
this.email = email;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected abstract String getAccountType();
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
protected void init(Bundle bundle) {
|
|
||||||
isAvailable = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdditionals(Bundle bundle) {
|
private String getJSESSIONID() {
|
||||||
isExpanded = true;
|
return JSESSIONID;
|
||||||
isAvailable = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean hasAdditionals() {
|
@Nullable
|
||||||
return isExpanded;
|
public String getFullName() {
|
||||||
|
return fullName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUnavailable() {
|
@Nullable
|
||||||
isExpanded = false;
|
public String getEmail() {
|
||||||
isAvailable = false;
|
return email;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void unsetAdditionals() {
|
public HashMap<String, String> getCookies() {
|
||||||
isExpanded = false;
|
HashMap<String, String> cookies = new HashMap<>();
|
||||||
|
cookies.put("JSESSIONID", getJSESSIONID());
|
||||||
|
cookies.put("pasystem_timezone_ok", "true");
|
||||||
|
return cookies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public final void fromString(String jsonString) {
|
public boolean isOtherUser(String username) {
|
||||||
try {
|
return !this.getUsername().equals(username);
|
||||||
JSONObject json = new JSONObject(jsonString);
|
|
||||||
this.isAvailable = json.getBoolean("isAvailable");
|
|
||||||
this.isExpanded = json.getBoolean("isExpanded");
|
|
||||||
jsonToObject(json);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NotNull
|
@NonNull
|
||||||
public final String toString() {
|
@Override
|
||||||
JSONObject json = null;
|
public String toString() {
|
||||||
try {
|
|
||||||
json = objectToJson();
|
|
||||||
json.put("isAvailable", isAvailable);
|
|
||||||
json.put("isExpanded", isExpanded);
|
|
||||||
} catch (JSONException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
if (json != null) {
|
|
||||||
return json.toString();
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
|
|
||||||
protected abstract void jsonToObject(JSONObject json) throws JSONException;
|
|
||||||
|
|
||||||
protected abstract JSONObject objectToJson() throws JSONException;
|
|
||||||
|
|
||||||
public abstract HashMap<String, String> getCookies();
|
|
||||||
|
|
||||||
public final String getCookieString() {
|
|
||||||
StringBuilder result = new StringBuilder();
|
StringBuilder result = new StringBuilder();
|
||||||
HashMap<String, String> cookies = this.getCookies();
|
HashMap<String, String> cookies = this.getCookies();
|
||||||
for (String header: cookies.keySet()) {
|
for (String header: cookies.keySet()) {
|
||||||
@@ -107,17 +91,38 @@ public abstract class LoginToken {
|
|||||||
return result.substring(0, result.length()-1);
|
return result.substring(0, result.length()-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isExpanded() {
|
public String toJsonString() {
|
||||||
return isExpanded;
|
JSONObject json = new JSONObject();
|
||||||
|
try {
|
||||||
|
json.put("username", username);
|
||||||
|
json.put("JSESSIONID", JSESSIONID);
|
||||||
|
json.put("fullName", fullName);
|
||||||
|
json.put("email", email);
|
||||||
|
} catch (JSONException e) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
return json.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
public final boolean isAvailable() {
|
private static LoginToken fromJsonString(String tokenString) {
|
||||||
return isAvailable;
|
try {
|
||||||
|
JSONObject json = new JSONObject(tokenString);
|
||||||
|
LoginToken token = new LoginToken(
|
||||||
|
json.getString("username"),
|
||||||
|
json.getString("JSESSIONID"));
|
||||||
|
if (!json.isNull("fullName"))
|
||||||
|
token.setAdditionals(
|
||||||
|
json.getString("fullName"),
|
||||||
|
json.getString("email")
|
||||||
|
);
|
||||||
|
return token;
|
||||||
|
} catch (JSONException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface LoginTokenInterface {
|
public interface LoginTokenInterface {
|
||||||
void run(LoginToken token);
|
void run(LoginToken token);
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract boolean isOtherUser(String user);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,138 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 29.10.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class LoginTokenBB extends LoginToken {
|
|
||||||
private String s_session_id;
|
|
||||||
private String session_id;
|
|
||||||
private String username;
|
|
||||||
@Nullable private String id;
|
|
||||||
@Nullable private String studentId;
|
|
||||||
|
|
||||||
public LoginTokenBB() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginTokenBB(Bundle bundle) {
|
|
||||||
super(bundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init(Bundle bundle) {
|
|
||||||
super.init(bundle);
|
|
||||||
this.username = bundle.getString("username");
|
|
||||||
this.s_session_id = bundle.getString("s_session_id");
|
|
||||||
this.session_id = bundle.getString("session_id");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getAccountType() {
|
|
||||||
return AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAdditionals(Bundle bundle) {
|
|
||||||
super.setAdditionals(bundle);
|
|
||||||
this.id = bundle.getString("id");
|
|
||||||
this.studentId = bundle.getString("studentId");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUnavailable() {
|
|
||||||
super.setUnavailable();
|
|
||||||
this.id = null;
|
|
||||||
this.studentId = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getSessionId() {
|
|
||||||
return session_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NotNull
|
|
||||||
public String getSSessionId() {
|
|
||||||
return s_session_id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getId() {
|
|
||||||
return id;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getStudentId() {
|
|
||||||
return studentId;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<String, String> getCookies() {
|
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put("session_id", getSessionId());
|
|
||||||
cookies.put("s_session_id", getSSessionId());
|
|
||||||
return cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOtherUser(String username) {
|
|
||||||
return !this.getUsername().equals(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject objectToJson() throws JSONException {
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
if (isAvailable()) {
|
|
||||||
json.put("s_session_id", s_session_id);
|
|
||||||
json.put("session_id", session_id);
|
|
||||||
json.put("username", username);
|
|
||||||
}
|
|
||||||
if (isExpanded()) {
|
|
||||||
json.put("id", id);
|
|
||||||
json.put("studentId", studentId);
|
|
||||||
}
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void jsonToObject(JSONObject json) throws JSONException {
|
|
||||||
if (isAvailable()) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("username", json.getString("username"));
|
|
||||||
bundle.putString("s_session_id", json.getString("s_session_id"));
|
|
||||||
bundle.putString("session_id", json.getString("session_id"));
|
|
||||||
init(bundle);
|
|
||||||
}
|
|
||||||
if (isExpanded()) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("id", json.getString("id"));
|
|
||||||
bundle.putString("studentId", json.getString("studentId"));
|
|
||||||
setAdditionals(bundle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(s_session_id, session_id, username, id, studentId);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,126 +0,0 @@
|
|||||||
package de.sebse.fuplanner.services.kvv.types;
|
|
||||||
|
|
||||||
import android.os.Bundle;
|
|
||||||
|
|
||||||
import com.google.android.gms.common.internal.Objects;
|
|
||||||
|
|
||||||
import org.json.JSONException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
|
||||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 29.10.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class LoginTokenWB extends LoginToken {
|
|
||||||
private String username;
|
|
||||||
private String JSESSIONID;
|
|
||||||
@Nullable private String fullName;
|
|
||||||
@Nullable private String email;
|
|
||||||
|
|
||||||
public LoginTokenWB() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public LoginTokenWB(Bundle bundle) {
|
|
||||||
super(bundle);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void init(Bundle bundle) {
|
|
||||||
super.init(bundle);
|
|
||||||
this.username = bundle.getString("username");
|
|
||||||
this.JSESSIONID = bundle.getString("JSESSIONID");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected String getAccountType() {
|
|
||||||
return AccountGeneral.AUTHTOKEN_TYPE_WB;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setAdditionals(Bundle bundle) {
|
|
||||||
super.setAdditionals(bundle);
|
|
||||||
this.fullName = bundle.getString("fullName");
|
|
||||||
this.email = bundle.getString("email");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void setUnavailable() {
|
|
||||||
super.setUnavailable();
|
|
||||||
this.fullName = null;
|
|
||||||
this.email = null;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getJSESSIONID() {
|
|
||||||
return JSESSIONID;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getFullName() {
|
|
||||||
return fullName;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Nullable
|
|
||||||
public String getEmail() {
|
|
||||||
return email;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public HashMap<String, String> getCookies() {
|
|
||||||
HashMap<String, String> cookies = new HashMap<>();
|
|
||||||
cookies.put("JSESSIONID", getJSESSIONID());
|
|
||||||
cookies.put("pasystem_timezone_ok", "true");
|
|
||||||
return cookies;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean isOtherUser(String username) {
|
|
||||||
return !this.getUsername().equals(username);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected JSONObject objectToJson() throws JSONException {
|
|
||||||
JSONObject json = new JSONObject();
|
|
||||||
if (isAvailable()) {
|
|
||||||
json.put("username", username);
|
|
||||||
json.put("JSESSIONID", JSESSIONID);
|
|
||||||
}
|
|
||||||
if (isExpanded()) {
|
|
||||||
json.put("fullName", fullName);
|
|
||||||
json.put("email", email);
|
|
||||||
}
|
|
||||||
return json;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void jsonToObject(JSONObject json) throws JSONException {
|
|
||||||
if (isAvailable()) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("username", json.getString("username"));
|
|
||||||
bundle.putString("JSESSIONID", json.getString("JSESSIONID"));
|
|
||||||
init(bundle);
|
|
||||||
}
|
|
||||||
if (isExpanded()) {
|
|
||||||
Bundle bundle = new Bundle();
|
|
||||||
bundle.putString("fullName", json.getString("fullName"));
|
|
||||||
bundle.putString("email", json.getString("email"));
|
|
||||||
setAdditionals(bundle);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(username, JSESSIONID, fullName, email);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -25,12 +25,10 @@ import androidx.annotation.Nullable;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class Modules implements Iterable<Modules.Module>, Serializable {
|
public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||||
public static final int TYPE_KVV = 1;
|
|
||||||
public static final int TYPE_BB = 2;
|
|
||||||
|
|
||||||
private SortedListModule list;
|
private SortedListModule list;
|
||||||
private final String mUsername;
|
private final String mUsername;
|
||||||
private transient long mLastTimestamp = 0;
|
private transient long mLastTimestamp = 0;
|
||||||
|
//private transient Logger log = new Logger(this);
|
||||||
private static final String FILE_NAME = "ModuleListSaving";
|
private static final String FILE_NAME = "ModuleListSaving";
|
||||||
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
|
private static final String FILE_NAME_TIMESTAMP = "ModuleListSavingTimestamp";
|
||||||
|
|
||||||
@@ -39,14 +37,9 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
this.list = new SortedListModule();
|
this.list = new SortedListModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
public Module addModule(@Nullable Semester semester, HashSet<String> lvNumber, String title, LinkedHashSet<Lecturer> lecturer, String type, String description, String ID, int moduleType) {
|
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, moduleType);
|
Module m = new Module(semester, lvNumber, title, lecturer, type, description, ID);
|
||||||
this.list.add(m);
|
this.list.add(m);
|
||||||
return m;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addModule(Module module) {
|
|
||||||
this.list.add(module);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -65,10 +58,6 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
return this.list.filteredIterator(this.list.getLatestSemester());
|
return this.list.filteredIterator(this.list.getLatestSemester());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Semester getLatestSemester() {
|
|
||||||
return this.list.getLatestSemester();
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size() {
|
public int size() {
|
||||||
return this.list.size();
|
return this.list.size();
|
||||||
}
|
}
|
||||||
@@ -165,23 +154,35 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public class Module implements Serializable {
|
public class Module implements Serializable {
|
||||||
|
|
||||||
@Nullable public final Semester semester;
|
@Nullable public final Semester semester;
|
||||||
@NotNull public final HashSet<String> lvNumber;
|
@NotNull final HashSet<String> lvNumber;
|
||||||
@NotNull public final String title;
|
@NotNull public final String title;
|
||||||
@NotNull
|
@NotNull
|
||||||
public ArrayList<Lecturer> lecturer;
|
public final ArrayList<Lecturer> lecturer;
|
||||||
@Nullable public final String type;
|
@Nullable public final String type;
|
||||||
@Nullable public final String description;
|
@Nullable public final String description;
|
||||||
@NotNull private final String ID;
|
@NotNull private final String ID;
|
||||||
private final int moduleType;
|
|
||||||
@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 Gradebook gradebook;
|
@Nullable public ArrayList<Grade> gradebook;
|
||||||
@Nullable public ArrayList<Resource> resources;
|
@Nullable public ArrayList<Resource> resources;
|
||||||
|
|
||||||
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, int moduleType) {
|
public float getGradebookPercent(){
|
||||||
|
float maxPoint = 0;
|
||||||
|
float userPoint = 0;
|
||||||
|
if (gradebook != null) {
|
||||||
|
for (Grade g : gradebook){
|
||||||
|
maxPoint += g.getMaxPoints();
|
||||||
|
userPoint += g.getPoints();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (maxPoint == 0)
|
||||||
|
return 0;
|
||||||
|
return userPoint/maxPoint;
|
||||||
|
}
|
||||||
|
|
||||||
|
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) {
|
||||||
|
|
||||||
title = title.replaceAll("(.*?) (S[0-9]{2}|W[0-9/]{5})", "$1");
|
title = title.replaceAll("(.*?) (S[0-9]{2}|W[0-9/]{5})", "$1");
|
||||||
|
|
||||||
@@ -192,11 +193,6 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
this.description = description;
|
this.description = description;
|
||||||
this.ID = ID;
|
this.ID = ID;
|
||||||
this.moduleType = moduleType;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setLecturers(LinkedHashSet<Lecturer> lecturers) {
|
|
||||||
this.lecturer = new ArrayList<>(lecturers);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
@@ -217,16 +213,7 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID, moduleType);
|
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
|
||||||
}
|
|
||||||
|
|
||||||
public int getModuleType() {
|
|
||||||
return moduleType;
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
public Module clone() {
|
|
||||||
return new Module(semester, lvNumber, title, new LinkedHashSet<>(lecturer), type, description, ID, moduleType);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -62,77 +62,6 @@ public abstract class Resource implements Serializable {
|
|||||||
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Document extends Resource implements LayoutItemType {
|
|
||||||
|
|
||||||
private final ArrayList<DownloadFile> urls;
|
|
||||||
private final String body;
|
|
||||||
|
|
||||||
public Document(String author, String title, long modifiedDate, String url, boolean visible, String container, String body) {
|
|
||||||
super(author, title, modifiedDate, url, visible, container);
|
|
||||||
this.body = body;
|
|
||||||
this.urls = new ArrayList<>();
|
|
||||||
}
|
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return "Resource{" +
|
|
||||||
"author='" + author + '\'' +
|
|
||||||
", modifiedDate=" + modifiedDate +
|
|
||||||
", title='" + title + '\'' +
|
|
||||||
", url='" + url + '\'' +
|
|
||||||
", body='" + body + '\'' +
|
|
||||||
", urls='" + urls + '\'' +
|
|
||||||
'}';
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getBody() {
|
|
||||||
return body;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void addUrl(String url, String name){
|
|
||||||
urls.add(new DownloadFile(url, name));
|
|
||||||
}
|
|
||||||
|
|
||||||
public DownloadFile getUrl(int id){
|
|
||||||
return urls.get(id);
|
|
||||||
}
|
|
||||||
|
|
||||||
public int size(){
|
|
||||||
return urls.size();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public TreeNode getTreeNode() {
|
|
||||||
return new TreeNode<>(this);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public @LayoutRes int getLayoutId() {
|
|
||||||
return R.layout.list_announcement_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(super.hashCode(), urls, body, this.getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
|
|
||||||
public class DownloadFile implements Serializable {
|
|
||||||
public final String url;
|
|
||||||
public final String name;
|
|
||||||
|
|
||||||
public DownloadFile(String url, String name) {
|
|
||||||
this.url = url;
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(url, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static class File extends Resource implements LayoutItemType {
|
public static class File extends Resource implements LayoutItemType {
|
||||||
private final String type;
|
private final String type;
|
||||||
|
|
||||||
@@ -162,11 +91,6 @@ public abstract class Resource implements Serializable {
|
|||||||
public @LayoutRes int getLayoutId() {
|
public @LayoutRes int getLayoutId() {
|
||||||
return R.layout.item_file;
|
return R.layout.item_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(super.hashCode(), this.type, this.getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static class Folder extends Resource implements LayoutItemType {
|
public static class Folder extends Resource implements LayoutItemType {
|
||||||
@@ -214,11 +138,6 @@ public abstract class Resource implements Serializable {
|
|||||||
public @LayoutRes int getLayoutId() {
|
public @LayoutRes int getLayoutId() {
|
||||||
return R.layout.item_dir;
|
return R.layout.item_dir;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode() {
|
|
||||||
return Objects.hashCode(super.hashCode(), children, this.getClass().getSimpleName());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,6 @@ package de.sebse.fuplanner.services.kvv.types;
|
|||||||
|
|
||||||
import java.io.Serializable;
|
import java.io.Serializable;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.Regex;
|
import de.sebse.fuplanner.tools.Regex;
|
||||||
|
|
||||||
@@ -53,10 +52,4 @@ public class Semester implements Serializable {
|
|||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
|
||||||
public String toString() {
|
|
||||||
return (type == SEM_SS ? "SS" : "WS") + year;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,16 +2,15 @@ package de.sebse.fuplanner.services.kvv.ui;
|
|||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.app.AlertDialog;
|
import android.app.AlertDialog;
|
||||||
import android.content.ActivityNotFoundException;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
import android.content.pm.PackageManager;
|
import android.content.pm.PackageManager;
|
||||||
import android.content.res.Resources;
|
import android.content.res.Resources;
|
||||||
import android.net.Uri;
|
import android.net.Uri;
|
||||||
import android.os.Build;
|
|
||||||
import android.os.Environment;
|
import android.os.Environment;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -49,14 +48,8 @@ public class Download {
|
|||||||
if (context == null)
|
if (context == null)
|
||||||
return;
|
return;
|
||||||
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);
|
||||||
File f;
|
File f = new File(Environment.getExternalStoragePublicDirectory(
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.Q) {
|
|
||||||
f = new File(context.getExternalFilesDir(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS)+"/"+folderName+"/"+file.getTitle());
|
Environment.DIRECTORY_DOWNLOADS)+"/"+folderName+"/"+file.getTitle());
|
||||||
} else {
|
|
||||||
f = new File(Environment.getExternalStoragePublicDirectory(
|
|
||||||
Environment.DIRECTORY_DOWNLOADS) + "/" + folderName + "/" + file.getTitle());
|
|
||||||
}
|
|
||||||
Resources resources = context.getResources();
|
Resources resources = context.getResources();
|
||||||
String message = "";
|
String message = "";
|
||||||
if (file.getAuthor() != null && !file.getAuthor().isEmpty())
|
if (file.getAuthor() != null && !file.getAuthor().isEmpty())
|
||||||
@@ -111,8 +104,7 @@ public class Download {
|
|||||||
showDownloadError();
|
showDownloadError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
activity.getKVV(kvv -> {
|
activity.getKVV().modules().resources().file(file.getTitle(), file.getUrl(), folderName, success -> {
|
||||||
kvv.modules().resources().file(file.getTitle(), file.getUrl(), folderName, success -> {
|
|
||||||
Context context = contextInterface.get();
|
Context context = contextInterface.get();
|
||||||
if (success.equals("") || context== null) {
|
if (success.equals("") || context== null) {
|
||||||
showDownloadError();
|
showDownloadError();
|
||||||
@@ -126,7 +118,6 @@ public class Download {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, log::e, downloadNew);
|
}, log::e, downloadNew);
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void showDownloadError() {
|
private void showDownloadError() {
|
||||||
@@ -155,6 +146,11 @@ public class Download {
|
|||||||
showDownloadError();
|
showDownloadError();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
ArrayList<Integer> intList = new ArrayList<>();
|
||||||
|
for (int i : grantResults)
|
||||||
|
{
|
||||||
|
intList.add(i);
|
||||||
|
}
|
||||||
int pos = Arrays.asList(permissions).indexOf("android.permission.WRITE_EXTERNAL_STORAGE");
|
int pos = Arrays.asList(permissions).indexOf("android.permission.WRITE_EXTERNAL_STORAGE");
|
||||||
if (pos != -1) {
|
if (pos != -1) {
|
||||||
if (grantResults[pos] != -1) {
|
if (grantResults[pos] != -1) {
|
||||||
@@ -196,7 +192,11 @@ public class Download {
|
|||||||
Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".my.provider", url);
|
Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".my.provider", url);
|
||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
|
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
||||||
intent = new Intent(Intent.ACTION_VIEW);
|
intent = new Intent(Intent.ACTION_VIEW);
|
||||||
|
} else {
|
||||||
|
intent = new Intent();
|
||||||
|
}
|
||||||
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||||
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
intent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
|
||||||
// Check what kind of file you are trying to open, by comparing the url with extensions.
|
// Check what kind of file you are trying to open, by comparing the url with extensions.
|
||||||
@@ -244,12 +244,7 @@ public class Download {
|
|||||||
intent.setDataAndType(uri, "*/*");
|
intent.setDataAndType(uri, "*/*");
|
||||||
}
|
}
|
||||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||||
try {
|
|
||||||
context.startActivity(intent);
|
context.startActivity(intent);
|
||||||
} catch (ActivityNotFoundException e) {
|
|
||||||
log.e("No matching activity found!");
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -8,7 +8,6 @@ import org.json.JSONObject;
|
|||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
import de.sebse.fuplanner.R;
|
||||||
@@ -16,7 +15,6 @@ import de.sebse.fuplanner.tools.UtilsDate;
|
|||||||
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 de.sebse.fuplanner.tools.types.News;
|
|
||||||
import de.sebse.fuplanner.tools.types.NewsList;
|
import de.sebse.fuplanner.tools.types.NewsList;
|
||||||
|
|
||||||
public class NewsManager {
|
public class NewsManager {
|
||||||
@@ -53,28 +51,21 @@ public class NewsManager {
|
|||||||
|
|
||||||
for (int i = news.length() - 1; i >= 0; i--) {
|
for (int i = news.length() - 1; i >= 0; i--) {
|
||||||
try {
|
try {
|
||||||
String title;
|
String title = news.getJSONObject(i).optString("title_" + language, null);
|
||||||
if (news.getJSONObject(i).has("title_" + language)) {
|
if (title == null)
|
||||||
title = news.getJSONObject(i).getString("title_" + language);
|
|
||||||
} else {
|
|
||||||
title = news.getJSONObject(i).getString("title");
|
title = news.getJSONObject(i).getString("title");
|
||||||
}
|
|
||||||
String text;
|
|
||||||
if (news.getJSONObject(i).has("text_" + language)) {
|
|
||||||
text = news.getJSONObject(i).getString("text_" + language);
|
|
||||||
} else {
|
|
||||||
text = news.getJSONObject(i).getString("text");
|
|
||||||
}
|
|
||||||
|
|
||||||
String categoryString = news.getJSONObject(i).getString("category");
|
String categoryString = news.getJSONObject(i).getString("category");
|
||||||
int category;
|
int category;
|
||||||
if (categoryString.equals("CATEGORY_TRICKS"))
|
if (categoryString.equals("CATEGORY_TRICKS"))
|
||||||
category = News.CATEGORY_TRICKS;
|
category = de.sebse.fuplanner.tools.types.News.CATEGORY_TRICKS;
|
||||||
else
|
else
|
||||||
category = News.CATEGORY_UPDATE;
|
category = de.sebse.fuplanner.tools.types.News.CATEGORY_UPDATE;
|
||||||
String dateString = news.getJSONObject(i).getString("date");
|
String dateString = news.getJSONObject(i).getString("date");
|
||||||
long date = UtilsDate.stringToMillis(dateString, "dd.MM.yyyy");
|
long date = UtilsDate.stringToMillis(dateString, "dd.MM.yyyy");
|
||||||
News event = new News(title, category, date, text);
|
String text = news.getJSONObject(i).optString("text_" + language, null);
|
||||||
|
if (text == null)
|
||||||
|
text = news.getJSONObject(i).getString("text");
|
||||||
|
de.sebse.fuplanner.tools.types.News event = new de.sebse.fuplanner.tools.types.News(title, category, date, text);
|
||||||
dates.add(event);
|
dates.add(event);
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
@@ -91,7 +82,7 @@ public class NewsManager {
|
|||||||
byte[] buffer = new byte[size];
|
byte[] buffer = new byte[size];
|
||||||
is.read(buffer);
|
is.read(buffer);
|
||||||
is.close();
|
is.close();
|
||||||
return new String(buffer, StandardCharsets.UTF_8);
|
return new String(buffer, "UTF-8");
|
||||||
} catch (IOException ex) {
|
} catch (IOException ex) {
|
||||||
ex.printStackTrace();
|
ex.printStackTrace();
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -9,16 +9,16 @@ import android.app.Activity;
|
|||||||
import android.os.Build;
|
import android.os.Build;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
|
||||||
import org.jetbrains.annotations.NotNull;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.services.kvv.Login;
|
import de.sebse.fuplanner.services.kvv.Login;
|
||||||
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
public class CustomAccountManager {
|
public class CustomAccountManager {
|
||||||
private final AccountManager mAccountManager;
|
private final AccountManager mAccountManager;
|
||||||
private final ActivityInterface mActivityInterface;
|
private final ActivityInterface mActivityInterface;
|
||||||
|
private Logger log = new Logger(this);
|
||||||
|
|
||||||
public CustomAccountManager(AccountManager manager, ActivityInterface activityInterface) {
|
public CustomAccountManager(AccountManager manager, ActivityInterface activityInterface) {
|
||||||
mAccountManager = manager;
|
mAccountManager = manager;
|
||||||
@@ -34,7 +34,11 @@ public class CustomAccountManager {
|
|||||||
try {
|
try {
|
||||||
String token = mAccountManager.blockingGetAuthToken(account, authTokenType, true);
|
String token = mAccountManager.blockingGetAuthToken(account, authTokenType, true);
|
||||||
mAccountManager.invalidateAuthToken(accountType, token);
|
mAccountManager.invalidateAuthToken(accountType, token);
|
||||||
} catch (AuthenticatorException | OperationCanceledException | IOException e) {
|
} catch (AuthenticatorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -49,7 +53,11 @@ public class CustomAccountManager {
|
|||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.run(true);
|
callback.run(true);
|
||||||
return;
|
return;
|
||||||
} catch (AuthenticatorException | OperationCanceledException | IOException e) {
|
} catch (AuthenticatorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
@@ -59,6 +67,7 @@ public class CustomAccountManager {
|
|||||||
|
|
||||||
public void deleteAccount(String accountType) {
|
public void deleteAccount(String accountType) {
|
||||||
Account[] accounts = mAccountManager.getAccountsByType(accountType);
|
Account[] accounts = mAccountManager.getAccountsByType(accountType);
|
||||||
|
int[] count = {accounts.length};
|
||||||
for (Account account: accounts) {
|
for (Account account: accounts) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||||
mAccountManager.removeAccount(account, null, null, null);
|
mAccountManager.removeAccount(account, null, null, null);
|
||||||
@@ -68,7 +77,7 @@ public class CustomAccountManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void getTokenByType(String accountType, String authTokenType, @Nullable StringInterface callback, @Nullable ExceptionInterface errorCallback) {
|
public void getTokenByType(String accountType, String authTokenType, @Nullable StringInterface callback) {
|
||||||
Activity activity = mActivityInterface.get();
|
Activity activity = mActivityInterface.get();
|
||||||
AccountManagerCallback<Bundle> cb = (accountManagerFuture -> {
|
AccountManagerCallback<Bundle> cb = (accountManagerFuture -> {
|
||||||
try {
|
try {
|
||||||
@@ -76,11 +85,16 @@ public class CustomAccountManager {
|
|||||||
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
|
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
|
||||||
if (callback != null)
|
if (callback != null)
|
||||||
callback.run(authtoken);
|
callback.run(authtoken);
|
||||||
} catch (AuthenticatorException | IOException | OperationCanceledException e) {
|
return;
|
||||||
|
} catch (AuthenticatorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
if (errorCallback != null)
|
|
||||||
errorCallback.run(e);
|
|
||||||
}
|
}
|
||||||
|
if (callback != null)
|
||||||
|
callback.run(null);
|
||||||
});
|
});
|
||||||
if (activity != null) {
|
if (activity != null) {
|
||||||
mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, null, mActivityInterface.get(), null, null, cb, null);
|
mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, null, mActivityInterface.get(), null, null, cb, null);
|
||||||
@@ -94,7 +108,11 @@ public class CustomAccountManager {
|
|||||||
Account account = mAccountManager.getAccountsByType(accountType)[0];
|
Account account = mAccountManager.getAccountsByType(accountType)[0];
|
||||||
try {
|
try {
|
||||||
return mAccountManager.blockingGetAuthToken(account, authTokenType, true);
|
return mAccountManager.blockingGetAuthToken(account, authTokenType, true);
|
||||||
} catch (AuthenticatorException | OperationCanceledException | IOException e) {
|
} catch (AuthenticatorException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
} catch (OperationCanceledException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
@@ -120,8 +138,4 @@ public class CustomAccountManager {
|
|||||||
public interface StringInterface {
|
public interface StringInterface {
|
||||||
void run(@Nullable String string);
|
void run(@Nullable String string);
|
||||||
}
|
}
|
||||||
|
|
||||||
public interface ExceptionInterface {
|
|
||||||
void run(@NotNull Exception string);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,20 +16,12 @@ import de.sebse.fuplanner.R;
|
|||||||
|
|
||||||
public class CustomNotificationManager {
|
public class CustomNotificationManager {
|
||||||
private static final String CHANNEL_ID = "fuplanner-default";
|
private static final String CHANNEL_ID = "fuplanner-default";
|
||||||
public static final String NOTIFICATION_INTENT = "notification-intent";
|
|
||||||
public static final String NOTIFICATION_PAGE = "notification-page";
|
|
||||||
public static final String NOTIFICATION_DATA = "notification-data";
|
|
||||||
public static final String NOTIFICATION_TYPE_NAVIGATE = "navigate";
|
|
||||||
|
|
||||||
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
|
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
|
||||||
|
|
||||||
public static void sendNotification(Context context, String textTitle, String textContent, int page, String data) {
|
public static void sendNotification(Context context, String textTitle, String textContent) {
|
||||||
Intent intent = new Intent(context, MainActivity.class);
|
Intent intent = new Intent(context, MainActivity.class);
|
||||||
intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
|
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||||
intent.putExtra(NOTIFICATION_INTENT, NOTIFICATION_TYPE_NAVIGATE);
|
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
intent.putExtra(NOTIFICATION_PAGE, page);
|
|
||||||
intent.putExtra(NOTIFICATION_DATA, data);
|
|
||||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
|
|
||||||
|
|
||||||
|
|
||||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
|
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||||
|
|||||||
@@ -2,8 +2,8 @@ package de.sebse.fuplanner.tools;
|
|||||||
|
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
|
|
||||||
import de.sebse.fuplanner.MainActivity;
|
|
||||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||||
|
import de.sebse.fuplanner.services.kvv.KVV;
|
||||||
import de.sebse.fuplanner.services.news.NewsManager;
|
import de.sebse.fuplanner.services.news.NewsManager;
|
||||||
|
|
||||||
public interface MainActivityListener {
|
public interface MainActivityListener {
|
||||||
@@ -15,7 +15,7 @@ public interface MainActivityListener {
|
|||||||
|
|
||||||
void showToast(@StringRes int msgStringRes);
|
void showToast(@StringRes int msgStringRes);
|
||||||
|
|
||||||
void getKVV(MainActivity.KVVCallback kvv);
|
KVV getKVV();
|
||||||
|
|
||||||
CanteenBrowser getCanteenBrowser();
|
CanteenBrowser getCanteenBrowser();
|
||||||
|
|
||||||
@@ -24,6 +24,4 @@ public interface MainActivityListener {
|
|||||||
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
||||||
|
|
||||||
void removeRequestPermissionsResultListener(String id);
|
void removeRequestPermissionsResultListener(String id);
|
||||||
|
|
||||||
void forceSync();
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,13 +5,12 @@ import android.util.Pair;
|
|||||||
import java.util.HashSet;
|
import java.util.HashSet;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
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;
|
||||||
|
|
||||||
public class NetworkCallbackCollector<T> extends HashSet<Pair<NetworkCallback<T>, NetworkErrorCallback>> {
|
public class NetworkCallbackCollector<T> extends HashSet<Pair<NetworkCallback<T>, NetworkErrorCallback>> {
|
||||||
public void add(@Nullable NetworkCallback<T> success, @Nullable NetworkErrorCallback error) {
|
public void add(NetworkCallback<T> success, NetworkErrorCallback error) {
|
||||||
add(new Pair<>(success, error));
|
add(new Pair<>(success, error));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -19,7 +18,6 @@ public class NetworkCallbackCollector<T> extends HashSet<Pair<NetworkCallback<T>
|
|||||||
Iterator<Pair<NetworkCallback<T>, NetworkErrorCallback>> i;
|
Iterator<Pair<NetworkCallback<T>, NetworkErrorCallback>> i;
|
||||||
for (i = this.iterator(); i.hasNext();) {
|
for (i = this.iterator(); i.hasNext();) {
|
||||||
Pair<NetworkCallback<T>, NetworkErrorCallback> pair = i.next();
|
Pair<NetworkCallback<T>, NetworkErrorCallback> pair = i.next();
|
||||||
if (pair.second != null)
|
|
||||||
pair.second.onError(error);
|
pair.second.onError(error);
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
@@ -29,7 +27,6 @@ public class NetworkCallbackCollector<T> extends HashSet<Pair<NetworkCallback<T>
|
|||||||
Iterator<Pair<NetworkCallback<T>, NetworkErrorCallback>> i;
|
Iterator<Pair<NetworkCallback<T>, NetworkErrorCallback>> i;
|
||||||
for (i = this.iterator(); i.hasNext();) {
|
for (i = this.iterator(); i.hasNext();) {
|
||||||
Pair<NetworkCallback<T>, NetworkErrorCallback> pair = i.next();
|
Pair<NetworkCallback<T>, NetworkErrorCallback> pair = i.next();
|
||||||
if (pair.first != null)
|
|
||||||
pair.first.onResponse(success);
|
pair.first.onResponse(success);
|
||||||
i.remove();
|
i.remove();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,9 +9,6 @@ public class NewAsyncQueue {
|
|||||||
private final LinkedList<AsyncQueueCallback> mQueue = new LinkedList<>();
|
private final LinkedList<AsyncQueueCallback> mQueue = new LinkedList<>();
|
||||||
private boolean mIsRunning = false;
|
private boolean mIsRunning = false;
|
||||||
|
|
||||||
public NewAsyncQueue() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public void add(AsyncQueueCallback callback) {
|
public void add(AsyncQueueCallback callback) {
|
||||||
if (isRunning())
|
if (isRunning())
|
||||||
getQueue().addLast(callback);
|
getQueue().addLast(callback);
|
||||||
|
|||||||
@@ -1,32 +1,22 @@
|
|||||||
package de.sebse.fuplanner.tools;
|
package de.sebse.fuplanner.tools;
|
||||||
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.SharedPreferences;
|
|
||||||
|
|
||||||
import androidx.annotation.ArrayRes;
|
import androidx.annotation.ArrayRes;
|
||||||
import androidx.annotation.StringRes;
|
import androidx.annotation.StringRes;
|
||||||
import androidx.preference.PreferenceManager;
|
import androidx.preference.PreferenceManager;
|
||||||
|
|
||||||
public class Preferences {
|
public class Preferences {
|
||||||
public static String getStringArray(Context context, @ArrayRes int key) {
|
public static String getString(Context context, @ArrayRes int key) {
|
||||||
String[] strings = context.getResources().getStringArray(key);
|
String[] strings = context.getResources().getStringArray(key);
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context).getString(strings[0], strings[1]);
|
return PreferenceManager.getDefaultSharedPreferences(context).getString(strings[0], strings[1]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static String getString(Context context, @StringRes int key) {
|
|
||||||
String string = context.getResources().getString(key);
|
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context).getString(string, null);
|
|
||||||
}
|
|
||||||
public static void setString(Context context, @StringRes int key, String value) {
|
|
||||||
String string = context.getResources().getString(key);
|
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putString(string, value).apply();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static long getLong(Context context, @StringRes int key) {
|
public static long getLong(Context context, @StringRes int key) {
|
||||||
String string = context.getResources().getString(key);
|
String string = context.getResources().getString(key);
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context).getLong(string, 0);
|
return PreferenceManager.getDefaultSharedPreferences(context).getLong(string, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setLong(Context context, @StringRes int key, long value) {
|
public static void setLong(Context context, @StringRes int key, long value) {
|
||||||
String string = context.getResources().getString(key);
|
String string = context.getResources().getString(key);
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply();
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply();
|
||||||
@@ -36,41 +26,9 @@ public class Preferences {
|
|||||||
String string = context.getResources().getString(key);
|
String string = context.getResources().getString(key);
|
||||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(string, false);
|
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(string, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void setBoolean(Context context, @StringRes int key, boolean value) {
|
public static void setBoolean(Context context, @StringRes int key, boolean value) {
|
||||||
String string = context.getResources().getString(key);
|
String string = context.getResources().getString(key);
|
||||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(string, value).apply();
|
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(string, value).apply();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static int[] getArrayInt(Context context, @StringRes int key) {
|
|
||||||
String string = context.getResources().getString(key);
|
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
if (!prefs.contains(string + "_size")) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
int size = prefs.getInt(string + "_size", 0);
|
|
||||||
int[] array = new int[size];
|
|
||||||
for (int i = 0; i < size; i++)
|
|
||||||
array[i] = prefs.getInt(string + "_" + i, 0);
|
|
||||||
return array;
|
|
||||||
}
|
|
||||||
public static void setArrayInt(Context context, @StringRes int key, int[] value) {
|
|
||||||
String string = context.getResources().getString(key);
|
|
||||||
|
|
||||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
|
||||||
SharedPreferences.Editor editor = prefs.edit();
|
|
||||||
int oldSize = prefs.getInt(string + "_size", 0);
|
|
||||||
int newSize = 0;
|
|
||||||
if (value == null) {
|
|
||||||
editor.remove(string + "_size");
|
|
||||||
} else {
|
|
||||||
newSize = value.length;
|
|
||||||
editor.putInt(string +"_size", newSize);
|
|
||||||
}
|
|
||||||
for (int i = 0; i < newSize; i++)
|
|
||||||
editor.putInt(string + "_" + i, value[i]);
|
|
||||||
for (int i = newSize; i < oldSize; i++)
|
|
||||||
editor.remove(string + "_" + i);
|
|
||||||
editor.apply();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -30,15 +30,6 @@ public class Regex {
|
|||||||
return matcher.group(group);
|
return matcher.group(group);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Matcher match(@Language("Regexp") String regex, String match) throws NoSuchFieldException {
|
|
||||||
Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
|
||||||
Matcher matcher = pattern.matcher(match);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
throw new NoSuchFieldException(String.format("Pattern: %s - String: %s", regex, match));
|
|
||||||
}
|
|
||||||
return matcher;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Iterable<MatchResult> allMatches(@Language("Regexp") String regex, final CharSequence input) {
|
public static Iterable<MatchResult> allMatches(@Language("Regexp") String regex, final CharSequence input) {
|
||||||
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
final Pattern pattern = Pattern.compile(regex, Pattern.DOTALL);
|
||||||
return () -> new Iterator<MatchResult>() {
|
return () -> new Iterator<MatchResult>() {
|
||||||
|
|||||||
@@ -49,7 +49,11 @@ public class UtilsDate {
|
|||||||
skeleton = skeleton.replaceAll("h", "H");
|
skeleton = skeleton.replaceAll("h", "H");
|
||||||
if (context != null && !DateFormat.is24HourFormat(context))
|
if (context != null && !DateFormat.is24HourFormat(context))
|
||||||
skeleton = skeleton.replaceAll("H", "h");
|
skeleton = skeleton.replaceAll("H", "h");
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR2) {
|
||||||
dateFormat = new SimpleDateFormat(getDateFormat(locale, skeleton));
|
dateFormat = new SimpleDateFormat(getDateFormat(locale, skeleton));
|
||||||
|
} else {
|
||||||
|
dateFormat = new SimpleDateFormat(skeleton, locale);
|
||||||
|
}
|
||||||
|
|
||||||
return dateFormat.format(new Date(modified));
|
return dateFormat.format(new Date(modified));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,219 +0,0 @@
|
|||||||
package de.sebse.fuplanner.tools.network;
|
|
||||||
|
|
||||||
import android.app.Service;
|
|
||||||
import android.content.Intent;
|
|
||||||
import android.os.Binder;
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
import com.android.volley.AuthFailureError;
|
|
||||||
import com.android.volley.NetworkResponse;
|
|
||||||
import com.android.volley.Request;
|
|
||||||
import com.android.volley.RequestQueue;
|
|
||||||
import com.android.volley.Response;
|
|
||||||
import com.android.volley.TimeoutError;
|
|
||||||
import com.android.volley.VolleyError;
|
|
||||||
import com.android.volley.toolbox.Volley;
|
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
|
||||||
import de.sebse.fuplanner.tools.EventListener;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by sebastian on 24.10.17.
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class HTTPNetwork extends Service {
|
|
||||||
private RequestQueue requestQueue;
|
|
||||||
protected final Logger log = new Logger(this);
|
|
||||||
private final EventListener<VolleyError> errorResponseListener = new EventListener<>();
|
|
||||||
private final EventListener<Result> successResponseListener = new EventListener<>();
|
|
||||||
// Binder given to clients
|
|
||||||
private final IBinder mBinder = new LocalBinder();
|
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onCreate() {
|
|
||||||
super.onCreate();
|
|
||||||
requestQueue = Volley.newRequestQueue(getApplicationContext(), 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 head(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error) {
|
|
||||||
get(url, cookies, response, error, true);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void get(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error) {
|
|
||||||
get(url, cookies, response, error, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void get(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error, boolean noBody) {
|
|
||||||
int requestMethod = noBody ? Request.Method.HEAD : Request.Method.GET;
|
|
||||||
HttpRequest request = new HttpRequest(requestMethod, url, response, error) {
|
|
||||||
@Override
|
|
||||||
public void deliverError(VolleyError error) {
|
|
||||||
if (error == null) {
|
|
||||||
deliver(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
|
||||||
} else if (error.networkResponse == null) {
|
|
||||||
int statusCode;
|
|
||||||
if (error instanceof TimeoutError)
|
|
||||||
statusCode = 408;
|
|
||||||
else
|
|
||||||
statusCode = 500;
|
|
||||||
deliver(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
|
||||||
} else {
|
|
||||||
final int status = error.networkResponse.statusCode;
|
|
||||||
if (status == 302) {
|
|
||||||
deliverResponse(new Result(null, error.networkResponse.headers));
|
|
||||||
} 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);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getHeaders() throws AuthFailureError {
|
|
||||||
Map<String, String> params = super.getHeaders();
|
|
||||||
if (cookies != null) {
|
|
||||||
if (params==null)
|
|
||||||
params = new HashMap<>();
|
|
||||||
else
|
|
||||||
params = new HashMap<>(params);
|
|
||||||
StringBuilder newStr = new StringBuilder();
|
|
||||||
for (String key : cookies.keySet())
|
|
||||||
newStr.append(key).append("=").append(cookies.get(key)).append(";");
|
|
||||||
newStr = new StringBuilder(newStr.substring(0, newStr.length() - 1));
|
|
||||||
params.put("Cookie", newStr.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
requestQueue.add(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void post(String url, @Nullable final HashMap<String, String> cookies, @Nullable final HashMap<String, String> body, Response.Listener<Result> response, Response.ErrorListener error) {
|
|
||||||
HttpRequest request = new HttpRequest(Request.Method.POST, url, response, error) {
|
|
||||||
@Override
|
|
||||||
public String getBodyContentType() {
|
|
||||||
return "application/x-www-form-urlencoded";
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public byte[] getBody() {
|
|
||||||
if (body==null) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
StringBuilder sb = new StringBuilder();
|
|
||||||
for(HashMap.Entry<String, String> e: body.entrySet()){
|
|
||||||
if(sb.length() > 0){
|
|
||||||
sb.append('&');
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
sb.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=').append(URLEncoder.encode(e.getValue(), "UTF-8"));
|
|
||||||
} catch (UnsupportedEncodingException ignored) {
|
|
||||||
}
|
|
||||||
}
|
|
||||||
String requestBody = sb.toString();
|
|
||||||
return requestBody.getBytes(StandardCharsets.UTF_8);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void deliverError(VolleyError error) {
|
|
||||||
if (error == null) {
|
|
||||||
deliver(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
|
||||||
} else if (error.networkResponse == null) {
|
|
||||||
int statusCode;
|
|
||||||
if (error instanceof TimeoutError)
|
|
||||||
statusCode = 408;
|
|
||||||
else
|
|
||||||
statusCode = 500;
|
|
||||||
deliver(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
|
||||||
} else {
|
|
||||||
final int status = error.networkResponse.statusCode;
|
|
||||||
if (status == 302) {
|
|
||||||
deliverResponse(new Result(null, error.networkResponse.headers));
|
|
||||||
} else {
|
|
||||||
deliver(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void deliver(VolleyError error) {
|
|
||||||
errorResponseListener.emit(error);
|
|
||||||
super.deliverError(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void deliverResponse(Result response) {
|
|
||||||
successResponseListener.emit(response);
|
|
||||||
super.deliverResponse(response);
|
|
||||||
}
|
|
||||||
|
|
||||||
public Map<String, String> getHeaders() throws AuthFailureError {
|
|
||||||
Map<String, String> params = super.getHeaders();
|
|
||||||
if (cookies != null) {
|
|
||||||
if (params==null)
|
|
||||||
params = new HashMap<>();
|
|
||||||
else
|
|
||||||
params = new HashMap<>(params);
|
|
||||||
StringBuilder newStr = new StringBuilder();
|
|
||||||
for (String key : cookies.keySet())
|
|
||||||
newStr.append(key).append("=").append(cookies.get(key)).append(";");
|
|
||||||
newStr = new StringBuilder(newStr.substring(0, newStr.length() - 1));
|
|
||||||
params.put("Cookie", newStr.toString());
|
|
||||||
}
|
|
||||||
|
|
||||||
return params;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
requestQueue.add(request);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public IBinder onBind(Intent intent) {
|
|
||||||
return mBinder;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class used for the client Binder. Because we know this service always
|
|
||||||
* runs in the same process as its clients, we don't need to deal with IPC.
|
|
||||||
*/
|
|
||||||
public class LocalBinder extends Binder {
|
|
||||||
public HTTPNetwork getService() {
|
|
||||||
// Return this instance of LocalService so clients can call public methods
|
|
||||||
return HTTPNetwork.this;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,22 +1,23 @@
|
|||||||
package de.sebse.fuplanner.tools.network;
|
package de.sebse.fuplanner.tools.network;
|
||||||
|
|
||||||
import android.content.ComponentName;
|
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
|
||||||
import android.content.ServiceConnection;
|
|
||||||
import android.os.CountDownTimer;
|
|
||||||
import android.os.IBinder;
|
|
||||||
|
|
||||||
|
import com.android.volley.AuthFailureError;
|
||||||
|
import com.android.volley.NetworkResponse;
|
||||||
|
import com.android.volley.Request;
|
||||||
|
import com.android.volley.RequestQueue;
|
||||||
import com.android.volley.Response;
|
import com.android.volley.Response;
|
||||||
|
import com.android.volley.TimeoutError;
|
||||||
import com.android.volley.VolleyError;
|
import com.android.volley.VolleyError;
|
||||||
|
import com.android.volley.toolbox.Volley;
|
||||||
|
|
||||||
|
import java.io.UnsupportedEncodingException;
|
||||||
|
import java.net.URLEncoder;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.regex.Matcher;
|
import java.util.Map;
|
||||||
import java.util.regex.Pattern;
|
|
||||||
|
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import de.sebse.fuplanner.tools.EventListener;
|
import de.sebse.fuplanner.tools.EventListener;
|
||||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
import de.sebse.fuplanner.tools.logging.Logger;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -24,172 +25,167 @@ import de.sebse.fuplanner.tools.logging.Logger;
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
public class HTTPService {
|
public class HTTPService {
|
||||||
|
private final RequestQueue requestQueue;
|
||||||
private final Context mContext;
|
private final Context mContext;
|
||||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
|
||||||
protected final Logger log = new Logger(this);
|
protected final Logger log = new Logger(this);
|
||||||
|
private final EventListener<VolleyError> errorResponseListener = new EventListener<>();
|
||||||
private int mRequestCount = 0;
|
private final EventListener<Result> successResponseListener = new EventListener<>();
|
||||||
private final HashMap<String, EventListener.EventFunction<VolleyError>> errorListeners = new HashMap<>();
|
|
||||||
private final HashMap<String, EventListener.EventFunction<Result>> successListeners = new HashMap<>();
|
|
||||||
private CountDownTimer mDisconnectTimer = null;
|
|
||||||
private HTTPNetwork mService;
|
|
||||||
private boolean mBound = false;
|
|
||||||
private boolean mWaitForBound = false;
|
|
||||||
private ServiceConnection mConnection = new ServiceConnection() {
|
|
||||||
@Override
|
|
||||||
public void onServiceConnected(ComponentName className, IBinder service) {
|
|
||||||
// We've bound to LocalService, cast the IBinder and get LocalService instance
|
|
||||||
HTTPNetwork.LocalBinder binder = (HTTPNetwork.LocalBinder) service;
|
|
||||||
mService = binder.getService();
|
|
||||||
mBound = true;
|
|
||||||
for (String listenerKey: errorListeners.keySet()) {
|
|
||||||
mService.addErrorListener(listenerKey, errorListeners.get(listenerKey));
|
|
||||||
}
|
|
||||||
for (String listenerKey: successListeners.keySet()) {
|
|
||||||
mService.addSuccessListener(listenerKey, successListeners.get(listenerKey));
|
|
||||||
}
|
|
||||||
if (mWaitForBound) {
|
|
||||||
mWaitForBound = false;
|
|
||||||
mQueue.next();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onServiceDisconnected(ComponentName arg0) {
|
|
||||||
mBound = false;
|
|
||||||
mService = null;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
public HTTPService(Context context) {
|
public HTTPService(Context context) {
|
||||||
this.mContext = context;
|
this.mContext = context;
|
||||||
|
requestQueue = Volley.newRequestQueue(context, new BetterHurlStack(false));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addErrorListener(String id, EventListener.EventFunction<VolleyError> listener) {
|
public void addErrorListener(String id, EventListener.EventFunction<VolleyError> listener) {
|
||||||
errorListeners.put(id, listener);
|
errorResponseListener.add(id, listener);
|
||||||
connect();
|
|
||||||
mQueue.add(() -> {
|
|
||||||
mService.addErrorListener(id, listener);
|
|
||||||
mQueue.next();
|
|
||||||
disconnect();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeErrorListener(String id) {
|
public void removeErrorListener(String id) {
|
||||||
errorListeners.remove(id);
|
errorResponseListener.remove(id);
|
||||||
connect();
|
|
||||||
mQueue.add(() -> {
|
|
||||||
mService.removeErrorListener(id);
|
|
||||||
mQueue.next();
|
|
||||||
disconnect();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSuccessListener(String id, EventListener.EventFunction<Result> listener) {
|
public void addSuccessListener(String id, EventListener.EventFunction<Result> listener) {
|
||||||
successListeners.put(id, listener);
|
successResponseListener.add(id, listener);
|
||||||
connect();
|
|
||||||
mQueue.add(() -> {
|
|
||||||
mService.addSuccessListener(id, listener);
|
|
||||||
mQueue.next();
|
|
||||||
disconnect();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void removeSuccessListener(String id) {
|
public void removeSuccessListener(String id) {
|
||||||
successListeners.remove(id);
|
successResponseListener.remove(id);
|
||||||
connect();
|
|
||||||
mQueue.add(() -> {
|
|
||||||
mService.removeSuccessListener(id);
|
|
||||||
mQueue.next();
|
|
||||||
disconnect();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void head(String url, @Nullable final HashMap<String, String> cookies, Response.Listener<Result> response, Response.ErrorListener error) {
|
|
||||||
connect();
|
|
||||||
mQueue.add(() -> {
|
|
||||||
mService.head(url, cookies, response1 -> {
|
|
||||||
response.onResponse(response1);
|
|
||||||
disconnect();
|
|
||||||
}, error1 -> {
|
|
||||||
error.onErrorResponse(error1);
|
|
||||||
disconnect();
|
|
||||||
});
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
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) {
|
||||||
connect();
|
HttpRequest request = new HttpRequest(Request.Method.GET, url, response, error) {
|
||||||
mQueue.add(() -> {
|
@Override
|
||||||
mService.get(url, cookies, response1 -> {
|
public void deliverError(VolleyError error) {
|
||||||
response.onResponse(response1);
|
if (error == null) {
|
||||||
disconnect();
|
deliver(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
||||||
}, error1 -> {
|
} else if (error.networkResponse == null) {
|
||||||
error.onErrorResponse(error1);
|
int statusCode;
|
||||||
disconnect();
|
if (error instanceof TimeoutError)
|
||||||
});
|
statusCode = 408;
|
||||||
mQueue.next();
|
else
|
||||||
});
|
statusCode = 500;
|
||||||
|
deliver(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
||||||
|
} else {
|
||||||
|
final int status = error.networkResponse.statusCode;
|
||||||
|
if (status == 302) {
|
||||||
|
deliverResponse(new Result(null, error.networkResponse.headers));
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
||||||
|
Map<String, String> params = super.getHeaders();
|
||||||
|
if (cookies != null) {
|
||||||
|
if (params==null)
|
||||||
|
params = new HashMap<>();
|
||||||
|
else
|
||||||
|
params = new HashMap<>(params);
|
||||||
|
StringBuilder newStr = new StringBuilder();
|
||||||
|
for (String key : cookies.keySet())
|
||||||
|
newStr.append(key).append("=").append(cookies.get(key)).append(";");
|
||||||
|
newStr = new StringBuilder(newStr.substring(0, newStr.length() - 1));
|
||||||
|
params.put("Cookie", newStr.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
requestQueue.add(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void post(String url, @Nullable final HashMap<String, String> cookies, @Nullable final HashMap<String, String> body, Response.Listener<Result> response, Response.ErrorListener error) {
|
protected void post(String url, @Nullable final HashMap<String, String> cookies, @Nullable final HashMap<String, String> body, Response.Listener<Result> response, Response.ErrorListener error) {
|
||||||
connect();
|
HttpRequest request = new HttpRequest(Request.Method.POST, url, response, error) {
|
||||||
mQueue.add(() -> {
|
@Override
|
||||||
mService.post(url, cookies, body, response1 -> {
|
public String getBodyContentType() {
|
||||||
response.onResponse(response1);
|
return "application/x-www-form-urlencoded";
|
||||||
disconnect();
|
|
||||||
}, error1 -> {
|
|
||||||
error.onErrorResponse(error1);
|
|
||||||
disconnect();
|
|
||||||
});
|
|
||||||
mQueue.next();
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void connect() {
|
@Override
|
||||||
if (!mBound) {
|
public byte[] getBody() {
|
||||||
Intent intent = new Intent(getContext(), HTTPNetwork.class);
|
if (body==null) {
|
||||||
getContext().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
return null;
|
||||||
if (!mWaitForBound) mQueue.add(() -> {});
|
|
||||||
mWaitForBound = true;
|
|
||||||
}
|
}
|
||||||
if (mDisconnectTimer != null) {
|
StringBuilder sb = new StringBuilder();
|
||||||
mDisconnectTimer.cancel();
|
for(HashMap.Entry<String, String> e: body.entrySet()){
|
||||||
mDisconnectTimer = null;
|
if(sb.length() > 0){
|
||||||
|
sb.append('&');
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
sb.append(URLEncoder.encode(e.getKey(), "UTF-8")).append('=').append(URLEncoder.encode(e.getValue(), "UTF-8"));
|
||||||
|
} catch (UnsupportedEncodingException ignored) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String requestBody = sb.toString();
|
||||||
|
try {
|
||||||
|
return requestBody.getBytes("utf-8");
|
||||||
|
} catch (UnsupportedEncodingException e) {
|
||||||
|
return null;
|
||||||
}
|
}
|
||||||
mRequestCount++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private void disconnect() {
|
@Override
|
||||||
mRequestCount--;
|
public void deliverError(VolleyError error) {
|
||||||
if (mDisconnectTimer == null) {
|
if (error == null) {
|
||||||
if (mBound && mRequestCount == 0) {
|
deliver(new VolleyError(new NetworkResponse(500, null, true, 0, null)));
|
||||||
mBound = false;
|
} else if (error.networkResponse == null) {
|
||||||
mService = null;
|
int statusCode;
|
||||||
getContext().unbindService(mConnection);
|
if (error instanceof TimeoutError)
|
||||||
|
statusCode = 408;
|
||||||
|
else
|
||||||
|
statusCode = 500;
|
||||||
|
deliver(new VolleyError(new NetworkResponse(statusCode, null, true, error.getNetworkTimeMs(), null)));
|
||||||
|
} else {
|
||||||
|
final int status = error.networkResponse.statusCode;
|
||||||
|
if (status == 302) {
|
||||||
|
deliverResponse(new Result(null, error.networkResponse.headers));
|
||||||
|
} else {
|
||||||
|
deliver(error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void deliver(VolleyError error) {
|
||||||
protected String getCookie(String cookies, String name) throws NoSuchFieldException {
|
errorResponseListener.emit(error);
|
||||||
Pattern pattern = Pattern.compile(name+"=([^;]+);");
|
super.deliverError(error);
|
||||||
Matcher matcher = pattern.matcher(cookies);
|
|
||||||
if (!matcher.find()) {
|
|
||||||
log.e("GETcookie failed", name);
|
|
||||||
log.e("GETcookie failed", cookies);
|
|
||||||
throw new NoSuchFieldException();
|
|
||||||
}
|
|
||||||
return matcher.group(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected HashMap<String, String> getCookie(String cookies, String[] names) throws NoSuchFieldException {
|
@Override
|
||||||
HashMap<String, String> result = new HashMap<>();
|
protected void deliverResponse(Result response) {
|
||||||
for (String name: names) {
|
successResponseListener.emit(response);
|
||||||
result.put(name,this.getCookie(cookies, name));
|
super.deliverResponse(response);
|
||||||
}
|
}
|
||||||
return result;
|
|
||||||
|
public Map<String, String> getHeaders() throws AuthFailureError {
|
||||||
|
Map<String, String> params = super.getHeaders();
|
||||||
|
if (cookies != null) {
|
||||||
|
if (params==null)
|
||||||
|
params = new HashMap<>();
|
||||||
|
else
|
||||||
|
params = new HashMap<>(params);
|
||||||
|
StringBuilder newStr = new StringBuilder();
|
||||||
|
for (String key : cookies.keySet())
|
||||||
|
newStr.append(key).append("=").append(cookies.get(key)).append(";");
|
||||||
|
newStr = new StringBuilder(newStr.substring(0, newStr.length() - 1));
|
||||||
|
params.put("Cookie", newStr.toString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return params;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
requestQueue.add(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Context getContext() {
|
protected Context getContext() {
|
||||||
|
|||||||
@@ -31,6 +31,6 @@ public class NetworkError {
|
|||||||
|
|
||||||
@NonNull
|
@NonNull
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return getCode() + " - " + getHttpStatus() + " - " + getMessage();
|
return String.valueOf(getCode()) + " - " + getHttpStatus() + " - " + getMessage();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,5 @@
|
|||||||
package de.sebse.fuplanner.tools.types;
|
package de.sebse.fuplanner.tools.types;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
|
||||||
|
|
||||||
public class News {
|
public class News {
|
||||||
public static final int CATEGORY_TRICKS = 0;
|
public static final int CATEGORY_TRICKS = 0;
|
||||||
public static final int CATEGORY_UPDATE = 1;
|
public static final int CATEGORY_UPDATE = 1;
|
||||||
@@ -34,7 +32,6 @@ public class News {
|
|||||||
return text;
|
return text;
|
||||||
}
|
}
|
||||||
|
|
||||||
@NonNull
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "News{" +
|
return "News{" +
|
||||||
|
|||||||
@@ -1,15 +0,0 @@
|
|||||||
package de.sebse.fuplanner.tools.ui;
|
|
||||||
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.ImageView;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
|
|
||||||
public class CanteensViewHolder extends ItemViewHolder {
|
|
||||||
public final ImageView mActionIcon;
|
|
||||||
|
|
||||||
public CanteensViewHolder(View view) {
|
|
||||||
super(view);
|
|
||||||
mActionIcon = view.findViewById(R.id.remove_icon);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,84 +0,0 @@
|
|||||||
package de.sebse.fuplanner.tools.ui;
|
|
||||||
|
|
||||||
import android.content.Context;
|
|
||||||
import android.content.res.TypedArray;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.graphics.drawable.Drawable;
|
|
||||||
import android.util.AttributeSet;
|
|
||||||
|
|
||||||
import androidx.appcompat.widget.AppCompatTextView;
|
|
||||||
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.tools.logging.Logger;
|
|
||||||
|
|
||||||
public class TextViewDrawableSize extends AppCompatTextView {
|
|
||||||
|
|
||||||
private int mDrawableWidth;
|
|
||||||
private int mDrawableHeight;
|
|
||||||
|
|
||||||
public TextViewDrawableSize(Context context) {
|
|
||||||
super(context);
|
|
||||||
init(context, null, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextViewDrawableSize(Context context, AttributeSet attrs) {
|
|
||||||
super(context, attrs);
|
|
||||||
init(context, attrs, 0);
|
|
||||||
}
|
|
||||||
|
|
||||||
public TextViewDrawableSize(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
super(context, attrs, defStyleAttr);
|
|
||||||
init(context, attrs, defStyleAttr);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void init(Context context, AttributeSet attrs, int defStyleAttr) {
|
|
||||||
TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.TextViewDrawableSize, defStyleAttr, 0);
|
|
||||||
|
|
||||||
try {
|
|
||||||
mDrawableWidth = array.getDimensionPixelSize(R.styleable.TextViewDrawableSize_compoundDrawableWidth, -1);
|
|
||||||
mDrawableHeight = array.getDimensionPixelSize(R.styleable.TextViewDrawableSize_compoundDrawableHeight, -1);
|
|
||||||
} finally {
|
|
||||||
array.recycle();
|
|
||||||
}
|
|
||||||
|
|
||||||
if (mDrawableWidth > 0 || mDrawableHeight > 0) {
|
|
||||||
initCompoundDrawableSize();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private void initCompoundDrawableSize() {
|
|
||||||
Drawable[] drawables = getCompoundDrawablesRelative();
|
|
||||||
for (Drawable drawable : drawables) {
|
|
||||||
if (drawable == null) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
Rect realBounds = drawable.getBounds();
|
|
||||||
float scaleFactor = realBounds.height() / (float) realBounds.width();
|
|
||||||
|
|
||||||
float drawableWidth = realBounds.width();
|
|
||||||
float drawableHeight = realBounds.height();
|
|
||||||
|
|
||||||
if (mDrawableWidth > 0) {
|
|
||||||
// save scale factor of image
|
|
||||||
if (drawableWidth > mDrawableWidth) {
|
|
||||||
drawableWidth = mDrawableWidth;
|
|
||||||
drawableHeight = drawableWidth * scaleFactor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (mDrawableHeight > 0) {
|
|
||||||
// save scale factor of image
|
|
||||||
if (drawableHeight > mDrawableHeight) {
|
|
||||||
drawableHeight = mDrawableHeight;
|
|
||||||
drawableWidth = drawableHeight / scaleFactor;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
realBounds.right = realBounds.left + Math.round(drawableWidth);
|
|
||||||
realBounds.bottom = realBounds.top + Math.round(drawableHeight);
|
|
||||||
|
|
||||||
drawable.setBounds(realBounds);
|
|
||||||
}
|
|
||||||
setCompoundDrawablesRelative(drawables[0], drawables[1], drawables[2], drawables[3]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -11,7 +11,6 @@ import android.view.animation.Animation;
|
|||||||
import android.view.animation.RotateAnimation;
|
import android.view.animation.RotateAnimation;
|
||||||
import android.view.animation.Transformation;
|
import android.view.animation.Transformation;
|
||||||
import android.widget.ImageButton;
|
import android.widget.ImageButton;
|
||||||
import android.widget.RelativeLayout;
|
|
||||||
|
|
||||||
import androidx.annotation.LayoutRes;
|
import androidx.annotation.LayoutRes;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
@@ -50,7 +49,7 @@ public class ExpandableCardView extends CardView {
|
|||||||
private View outerView;
|
private View outerView;
|
||||||
private ImageButton imageButton;
|
private ImageButton imageButton;
|
||||||
|
|
||||||
private static final int DEFAULT_ANIM_DURATION = 300;
|
private static final int DEFAULT_ANIM_DURATION = 350;
|
||||||
private long animDuration = DEFAULT_ANIM_DURATION;
|
private long animDuration = DEFAULT_ANIM_DURATION;
|
||||||
|
|
||||||
private final static int COLLAPSING = 0;
|
private final static int COLLAPSING = 0;
|
||||||
@@ -64,15 +63,13 @@ public class ExpandableCardView extends CardView {
|
|||||||
private int collapsedHeight = 0;
|
private int collapsedHeight = 0;
|
||||||
private int expandedHeight = 0;
|
private int expandedHeight = 0;
|
||||||
|
|
||||||
LayoutParams layoutParamsPreset = new LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
|
|
||||||
|
|
||||||
private OnExpandedListener listener;
|
private OnExpandedListener listener;
|
||||||
private final Logger log = new Logger(this);
|
|
||||||
|
|
||||||
private final OnClickListener defaultClickListener = v -> {
|
private final OnClickListener defaultClickListener = v -> {
|
||||||
if(isExpanded()) collapse();
|
if(isExpanded()) collapse();
|
||||||
else expand();
|
else expand();
|
||||||
};
|
};
|
||||||
|
private final Logger log = new Logger(this);
|
||||||
|
|
||||||
public ExpandableCardView(Context context) {
|
public ExpandableCardView(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
@@ -103,9 +100,11 @@ public class ExpandableCardView extends CardView {
|
|||||||
(int) UtilsUi.convertDpToPixels(getContext(), 10),
|
(int) UtilsUi.convertDpToPixels(getContext(), 10),
|
||||||
(int) UtilsUi.convertDpToPixels(getContext(), 10)
|
(int) UtilsUi.convertDpToPixels(getContext(), 10)
|
||||||
);
|
);
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
|
||||||
TypedValue outValue = new TypedValue();
|
TypedValue outValue = new TypedValue();
|
||||||
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
|
context.getTheme().resolveAttribute(android.R.attr.selectableItemBackground, outValue, true);
|
||||||
imageButton.setBackgroundResource(outValue.resourceId);
|
imageButton.setBackgroundResource(outValue.resourceId);
|
||||||
|
}
|
||||||
isExpanded = startExpanded;
|
isExpanded = startExpanded;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -135,10 +134,6 @@ public class ExpandableCardView extends CardView {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
protected void onLayout(boolean changed, int l, int t, int r, int b) {
|
||||||
if (outerView == null || innerView == null) {
|
|
||||||
log.w("This should not happen (onLayout)! Inner views are null!", innerView, outerView);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
removeAllViews();
|
removeAllViews();
|
||||||
int x = getPaddingLeft();
|
int x = getPaddingLeft();
|
||||||
int y = getPaddingTop();
|
int y = getPaddingTop();
|
||||||
@@ -158,12 +153,7 @@ public class ExpandableCardView extends CardView {
|
|||||||
@Override
|
@Override
|
||||||
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
|
||||||
if (MeasureSpec.getSize(widthMeasureSpec) == 0 && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED || MeasureSpec.getSize(heightMeasureSpec) == 0 && MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.UNSPECIFIED) {
|
if (MeasureSpec.getSize(widthMeasureSpec) == 0 && MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED || MeasureSpec.getSize(heightMeasureSpec) == 0 && MeasureSpec.getMode(heightMeasureSpec) != MeasureSpec.UNSPECIFIED) {
|
||||||
log.w("This should not happen (onMeasure)! Invalid dimension size");
|
log.w("This should not happen! Invalid dimension size");
|
||||||
setMeasuredDimension(reconcileSize(10, widthMeasureSpec), reconcileSize(10, heightMeasureSpec));
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (outerView == null || innerView == null) {
|
|
||||||
log.w("This should not happen (onMeasure)! Inner views are null!", innerView, outerView);
|
|
||||||
setMeasuredDimension(reconcileSize(10, widthMeasureSpec), reconcileSize(10, heightMeasureSpec));
|
setMeasuredDimension(reconcileSize(10, widthMeasureSpec), reconcileSize(10, heightMeasureSpec));
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -177,14 +167,12 @@ public class ExpandableCardView extends CardView {
|
|||||||
|
|
||||||
widthMeasure = atMostExactlySpec(Math.max(0, MeasureSpec.getSize(widthMeasureSpec)-imageButton.getMeasuredWidth()), widthMeasureSpec);
|
widthMeasure = atMostExactlySpec(Math.max(0, MeasureSpec.getSize(widthMeasureSpec)-imageButton.getMeasuredWidth()), widthMeasureSpec);
|
||||||
heightMeasure = atMostSpec(MeasureSpec.getSize(heightMeasureSpec), heightMeasureSpec);
|
heightMeasure = atMostSpec(MeasureSpec.getSize(heightMeasureSpec), heightMeasureSpec);
|
||||||
outerView.setLayoutParams(layoutParamsPreset);
|
|
||||||
outerView.measure(widthMeasure, heightMeasure);
|
outerView.measure(widthMeasure, heightMeasure);
|
||||||
desiredWidth = imageButton.getMeasuredWidth() + outerView.getMeasuredWidth();
|
desiredWidth = imageButton.getMeasuredWidth() + outerView.getMeasuredWidth();
|
||||||
desiredHeight = Math.max(imageButton.getMeasuredHeight(), outerView.getMeasuredHeight());
|
desiredHeight = Math.max(imageButton.getMeasuredHeight(), outerView.getMeasuredHeight());
|
||||||
|
|
||||||
widthMeasure = atMostSpec(MeasureSpec.getSize(widthMeasureSpec), widthMeasureSpec);
|
widthMeasure = atMostSpec(MeasureSpec.getSize(widthMeasureSpec), widthMeasureSpec);
|
||||||
heightMeasure = atMostSpec(Math.max(0, MeasureSpec.getSize(heightMeasureSpec)-desiredHeight), heightMeasureSpec);
|
heightMeasure = atMostSpec(Math.max(0, MeasureSpec.getSize(heightMeasureSpec)-desiredHeight), heightMeasureSpec);
|
||||||
innerView.setLayoutParams(layoutParamsPreset);
|
|
||||||
innerView.measure(widthMeasure, heightMeasure);
|
innerView.measure(widthMeasure, heightMeasure);
|
||||||
desiredWidth = Math.max(desiredWidth, innerView.getMeasuredWidth());
|
desiredWidth = Math.max(desiredWidth, innerView.getMeasuredWidth());
|
||||||
desiredHeight += innerView.getMeasuredHeight();
|
desiredHeight += innerView.getMeasuredHeight();
|
||||||
@@ -260,29 +248,8 @@ public class ExpandableCardView extends CardView {
|
|||||||
new RotateAnimation(180,0,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
new RotateAnimation(180,0,Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF,
|
||||||
0.5f);
|
0.5f);
|
||||||
|
|
||||||
arrowAnimation.setAnimationListener(new Animation.AnimationListener() {
|
arrowAnimation.setFillAfter(true);
|
||||||
@Override
|
|
||||||
public void onAnimationStart(Animation animation) {
|
|
||||||
imageButton.setRotationX(0);
|
|
||||||
imageButton.setRotationY(0);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animation animation) {
|
|
||||||
if (isExpanded) {
|
|
||||||
imageButton.setRotationX(180);
|
|
||||||
imageButton.setRotationY(180);
|
|
||||||
} else {
|
|
||||||
imageButton.setRotationX(0);
|
|
||||||
imageButton.setRotationY(0);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onAnimationRepeat(Animation animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
arrowAnimation.setDuration(animDuration);
|
arrowAnimation.setDuration(animDuration);
|
||||||
expandAnimation.setDuration(animDuration);
|
expandAnimation.setDuration(animDuration);
|
||||||
@@ -399,3 +366,4 @@ public class ExpandableCardView extends CardView {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,81 +0,0 @@
|
|||||||
package de.sebse.fuplanner.tools.ui.treeview;
|
|
||||||
|
|
||||||
import android.view.View;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
import com.cunoraz.tagview.Tag;
|
|
||||||
import com.cunoraz.tagview.TagView;
|
|
||||||
|
|
||||||
import androidx.core.content.ContextCompat;
|
|
||||||
import de.sebse.fuplanner.R;
|
|
||||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
|
||||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
|
||||||
import de.sebse.fuplanner.tools.UtilsDate;
|
|
||||||
import de.sebse.fuplanner.tools.ui.cardview.ExpandableCardView;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Created by tlh on 2016/10/1 :)
|
|
||||||
*/
|
|
||||||
|
|
||||||
public class DocumentNodeBinder extends TreeViewBinder<DocumentNodeBinder.ViewHolder> {
|
|
||||||
|
|
||||||
private Download.OnDownloadRequestInterface requestInterface;
|
|
||||||
|
|
||||||
public DocumentNodeBinder(Download.OnDownloadRequestInterface requestInterface) {
|
|
||||||
super();
|
|
||||||
this.requestInterface = requestInterface;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ViewHolder provideViewHolder(View itemView) {
|
|
||||||
return new ViewHolder(itemView);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void bindView(ViewHolder holder, int position, TreeNode node) {
|
|
||||||
Resource.Document fileNode = (Resource.Document) node.getContent();
|
|
||||||
holder.title.setText(fileNode.getTitle());
|
|
||||||
holder.sub_title.setText(UtilsDate.getModifiedDateTime(holder.itemView.getContext(), fileNode.getModifiedDate()));
|
|
||||||
holder.notes.setText(fileNode.getBody());
|
|
||||||
|
|
||||||
holder.mTagGroup.removeAll();
|
|
||||||
for (int i = 0, notesSize = fileNode.size(); i < notesSize; i++) {
|
|
||||||
String name = fileNode.getUrl(i).name;
|
|
||||||
Tag tag = new Tag(name.substring(0, Math.min(40, name.length())));
|
|
||||||
tag.id = i;
|
|
||||||
tag.layoutColor = ContextCompat.getColor(holder.itemView.getContext(), R.color.colorFUBlue);
|
|
||||||
holder.mTagGroup.addTag(tag);
|
|
||||||
}
|
|
||||||
holder.mTagGroup.setOnTagClickListener((tag, i) -> {
|
|
||||||
String s = fileNode.getUrl(i).url;
|
|
||||||
if (s != null) {
|
|
||||||
String name = fileNode.getUrl(i).name;
|
|
||||||
this.requestInterface.request(name, s);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
holder.itemView.invalidate();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getLayoutId() {
|
|
||||||
return R.layout.list_announcement_items;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ViewHolder extends TreeViewBinder.ViewHolder {
|
|
||||||
final TextView title;
|
|
||||||
final TextView sub_title;
|
|
||||||
final TextView notes;
|
|
||||||
final ExpandableCardView card_view;
|
|
||||||
final TagView mTagGroup;
|
|
||||||
|
|
||||||
ViewHolder(View rootView) {
|
|
||||||
super(rootView);
|
|
||||||
this.card_view = rootView.findViewById(R.id.card_view);
|
|
||||||
this.title = this.card_view.getOuterView().findViewById(R.id.title);
|
|
||||||
this.sub_title = this.card_view.getOuterView().findViewById(R.id.sub_title);
|
|
||||||
this.notes = this.card_view.getInnerView().findViewById(R.id.notes);
|
|
||||||
this.mTagGroup = this.card_view.getInnerView().findViewById(R.id.tag_group);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -140,8 +140,7 @@ public class TreeNode<T extends LayoutItemType> implements Cloneable {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@NonNull
|
@SuppressWarnings("CloneDoesntDeclareCloneNotSupportedException")
|
||||||
@SuppressWarnings({"CloneDoesntDeclareCloneNotSupportedException"})
|
|
||||||
@Override
|
@Override
|
||||||
protected TreeNode<T> clone() {
|
protected TreeNode<T> clone() {
|
||||||
TreeNode<T> clone = new TreeNode<>(this.content);
|
TreeNode<T> clone = new TreeNode<>(this.content);
|
||||||
|
|||||||
@@ -88,7 +88,6 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
@Override
|
@Override
|
||||||
public void onBindViewHolder(@NonNull 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);
|
||||||
if (!holder.itemView.hasOnClickListeners()) {
|
|
||||||
holder.itemView.setOnClickListener(v -> {
|
holder.itemView.setOnClickListener(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.
|
||||||
@@ -115,7 +114,6 @@ public class TreeViewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolde
|
|||||||
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
|
//noinspection unchecked
|
||||||
|
|||||||
@@ -309,7 +309,7 @@ public class WeekView extends View {
|
|||||||
mDoubleTapListener.onDoubleTapListener((Calendar) selectedTime.clone());
|
mDoubleTapListener.onDoubleTapListener((Calendar) selectedTime.clone());
|
||||||
}
|
}
|
||||||
if (mDoubleTapLeftRightListener != null)
|
if (mDoubleTapLeftRightListener != null)
|
||||||
mDoubleTapLeftRightListener.onDoubleTapLeftRightListener(getWidth() / 2.0 < e.getX());
|
mDoubleTapLeftRightListener.onDoubleTapLeftRightListener(getWidth()/2 < e.getX());
|
||||||
return super.onDoubleTap(e);
|
return super.onDoubleTap(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -365,7 +365,7 @@ public class WeekView extends View {
|
|||||||
}
|
}
|
||||||
int nonRoundedMinutes = selectedTime.get(Calendar.MINUTE);
|
int nonRoundedMinutes = selectedTime.get(Calendar.MINUTE);
|
||||||
int mod = nonRoundedMinutes % mNewEventTimeResolutionInMinutes;
|
int mod = nonRoundedMinutes % mNewEventTimeResolutionInMinutes;
|
||||||
selectedTime.add(Calendar.MINUTE, mod < Math.ceil(mNewEventTimeResolutionInMinutes / 2.0) ? -mod : (mNewEventTimeResolutionInMinutes - mod));
|
selectedTime.add(Calendar.MINUTE, mod < Math.ceil(mNewEventTimeResolutionInMinutes / 2) ? -mod : (mNewEventTimeResolutionInMinutes - mod));
|
||||||
|
|
||||||
Calendar endTime = (Calendar) selectedTime.clone();
|
Calendar endTime = (Calendar) selectedTime.clone();
|
||||||
|
|
||||||
@@ -379,8 +379,8 @@ public class WeekView extends View {
|
|||||||
|
|
||||||
WeekViewEvent newEvent = new WeekViewEvent(mNewEventIdentifier, "", null, selectedTime, endTime);
|
WeekViewEvent newEvent = new WeekViewEvent(mNewEventIdentifier, "", null, selectedTime, endTime);
|
||||||
|
|
||||||
float top = mHourHeight * getPassedMinutesInDay(selectedTime) / 60f + getEventsTop();
|
float top = mHourHeight * getPassedMinutesInDay(selectedTime) / 60 + getEventsTop();
|
||||||
float bottom = mHourHeight * getPassedMinutesInDay(endTime) / 60f + getEventsTop();
|
float bottom = mHourHeight * getPassedMinutesInDay(endTime) / 60 + getEventsTop();
|
||||||
|
|
||||||
// Calculate left and right.
|
// Calculate left and right.
|
||||||
float left = mWidthPerDay * daysBetween(getFirstVisibleDay(), selectedTime);
|
float left = mWidthPerDay * daysBetween(getFirstVisibleDay(), selectedTime);
|
||||||
@@ -1117,7 +1117,7 @@ public class WeekView extends View {
|
|||||||
canvas.drawRoundRect(eventRect.rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
|
canvas.drawRoundRect(eventRect.rectF, mEventCornerRadius, mEventCornerRadius, mEventBackgroundPaint);
|
||||||
float topToUse = top;
|
float topToUse = top;
|
||||||
if (eventRect.event.getStartTime().get(Calendar.HOUR_OF_DAY) < mMinTime)
|
if (eventRect.event.getStartTime().get(Calendar.HOUR_OF_DAY) < mMinTime)
|
||||||
topToUse = mHourHeight * getPassedMinutesInDay(mMinTime, 0) / 60f + getEventsTop();
|
topToUse = mHourHeight * getPassedMinutesInDay(mMinTime, 0) / 60 + getEventsTop();
|
||||||
|
|
||||||
if (!mNewEventIdentifier.equals(eventRect.event.getIdentifier()))
|
if (!mNewEventIdentifier.equals(eventRect.event.getIdentifier()))
|
||||||
drawEventTitle(eventRect.event, eventRect.rectF, canvas, topToUse, left);
|
drawEventTitle(eventRect.event, eventRect.rectF, canvas, topToUse, left);
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
<selector xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
<item android:color="@color/fuAccent" android:state_checked="true" />
|
<item android:color="@color/colorFUBlue" android:state_checked="true" />
|
||||||
<item android:color="@color/fuHeaderText1" android:state_checked="false"/>
|
<item android:color="@color/colorFUBlack" android:state_checked="false"/>
|
||||||
</selector>
|
</selector>
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user