Compare commits
60 Commits
newkvv
...
kvvservice
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7d803777f8 | ||
|
|
7cc0709133 | ||
|
|
21d247052d | ||
|
|
57853eccf1 | ||
|
|
ceccd77f18 | ||
|
|
ae53e94108 | ||
|
|
786c001bbd | ||
|
|
1ed6522ac4 | ||
|
|
f646dd485d | ||
|
|
73f9485394 | ||
|
|
22f7cf3e96 | ||
|
|
4db38ba4fb | ||
|
|
6306cc9c77 | ||
|
|
8160ef12b1 | ||
|
|
4d22613672 | ||
|
|
fd18e4b61a | ||
|
|
cde5fc3582 | ||
|
|
c807dda73c | ||
|
|
797e848900 | ||
|
|
2dbfd0141a | ||
|
|
9b39563474 | ||
|
|
8791d65d96 | ||
|
|
6bd99c59a8 | ||
|
|
6b117997c3 | ||
|
|
4c012ed2ba | ||
|
|
5209491287 | ||
|
|
4812336cc7 | ||
|
|
4fe6dee4c8 | ||
|
|
2aad0f19a3 | ||
|
|
a79f59c66c | ||
|
|
2d160d3b38 | ||
|
|
6acea97458 | ||
|
|
c6f032f92e | ||
|
|
544162bb47 | ||
|
|
d5e08ac3c3 | ||
|
|
671c9bd86a | ||
|
|
35141bc1ec | ||
|
|
d62256f1db | ||
|
|
0adeca7367 | ||
|
|
0b32f8e9f8 | ||
|
|
4d9b2200d3 | ||
|
|
50d07193a0 | ||
|
|
8e3360549f | ||
|
|
7679135af1 | ||
|
|
6523d82d6b | ||
|
|
7a7e56bdf5 | ||
|
|
14b38f22a3 | ||
|
|
1d90b3e9da | ||
|
|
b6deff7b99 | ||
|
|
dd7e9a910c | ||
|
|
3aa07e0a6d | ||
|
|
9a1892db0a | ||
|
|
5ba6c899be | ||
|
|
547a62d07b | ||
|
|
d9e2911554 | ||
|
|
2e96d205d6 | ||
|
|
17c093c040 | ||
|
|
a1ce5c644a | ||
|
|
2d1d8e1e8b | ||
|
|
959733a3c9 |
1
.gitignore
vendored
1
.gitignore
vendored
@@ -7,3 +7,4 @@
|
||||
/build
|
||||
/captures
|
||||
.externalNativeBuild
|
||||
app/release/*
|
||||
|
||||
@@ -7,8 +7,8 @@ android {
|
||||
applicationId "de.sebse.fuplanner"
|
||||
minSdkVersion 15
|
||||
targetSdkVersion 28
|
||||
versionCode 10
|
||||
versionName "1.2.2"
|
||||
versionCode 19
|
||||
versionName "1.4"
|
||||
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
|
||||
}
|
||||
buildTypes {
|
||||
@@ -34,7 +34,7 @@ dependencies {
|
||||
})
|
||||
implementation 'androidx.preference:preference:1.0.0'
|
||||
implementation 'com.google.android.material:material:1.0.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-alpha3'
|
||||
implementation 'com.android.volley:volley:1.1.0'
|
||||
//noinspection GradleDependency
|
||||
implementation 'com.google.android.gms:play-services-auth:15.0.0'
|
||||
|
||||
@@ -2,28 +2,46 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
package="de.sebse.fuplanner">
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.AUTHENTICATE_ACCOUNTS"
|
||||
android:maxSdkVersion="22" />
|
||||
<uses-permission
|
||||
android:name="android.permission.GET_ACCOUNTS"
|
||||
android:maxSdkVersion="22" />
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
|
||||
<uses-permission
|
||||
android:name="android.permission.MANAGE_ACCOUNTS"
|
||||
android:maxSdkVersion="22" />
|
||||
<uses-permission
|
||||
android:name="android.permission.USE_CREDENTIALS"
|
||||
android:maxSdkVersion="22" />
|
||||
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
|
||||
|
||||
<!-- To auto-complete the email text field in the login form with the user's emails -->
|
||||
<uses-permission android:name="android.permission.READ_PROFILE" />
|
||||
<uses-permission android:name="android.permission.READ_CONTACTS" />
|
||||
<uses-permission android:name="android.permission.WRITE_SYNC_SETTINGS" />
|
||||
<uses-permission android:name="android.permission.READ_SYNC_SETTINGS" />
|
||||
|
||||
<application
|
||||
android:allowBackup="true"
|
||||
android:fullBackupContent="@xml/backup_descriptor"
|
||||
android:icon="@mipmap/ic_launcher"
|
||||
android:label="@string/app_name"
|
||||
android:roundIcon="@mipmap/ic_launcher_round"
|
||||
android:supportsRtl="true"
|
||||
android:theme="@style/FUTheme"
|
||||
android:fullBackupContent="@xml/backup_descriptor">
|
||||
android:theme="@style/FUTheme">
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name">
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<action android:name="android.intent.action.MAIN" />
|
||||
|
||||
<category android:name="android.intent.category.LAUNCHER" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="${applicationId}.my.provider"
|
||||
@@ -31,8 +49,39 @@
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/provider_paths"/>
|
||||
android:resource="@xml/provider_paths" />
|
||||
</provider>
|
||||
<provider
|
||||
android:authorities="de.sebse.fuplanner.contentprovider.kvv.modules"
|
||||
android:name="de.sebse.fuplanner.services.kvv.sync.KVVContentProvider"
|
||||
android:exported="false"
|
||||
android:syncable="true">
|
||||
|
||||
</provider>
|
||||
|
||||
<activity
|
||||
android:name=".services.fulogin.FUAuthenticatorActivity"
|
||||
android:label="@string/title_activity_fuauthenticator" />
|
||||
<service android:name=".services.fulogin.FUAuthenticatorService">
|
||||
<intent-filter>
|
||||
<action android:name="android.accounts.AccountAuthenticator" />
|
||||
</intent-filter>
|
||||
<meta-data android:name="android.accounts.AccountAuthenticator"
|
||||
android:resource="@xml/authenticator" />
|
||||
</service>
|
||||
<service
|
||||
android:name=".services.kvv.sync.KVVSyncService"
|
||||
android:label="@string/kvv_sync"
|
||||
android:exported="false">
|
||||
<intent-filter>
|
||||
<action android:name="android.content.SyncAdapter" />
|
||||
</intent-filter>
|
||||
<meta-data
|
||||
android:name="android.content.SyncAdapter"
|
||||
android:resource="@xml/syncadapter_kvv" />
|
||||
</service>
|
||||
|
||||
|
||||
</application>
|
||||
|
||||
</manifest>
|
||||
@@ -1,5 +1,8 @@
|
||||
package de.sebse.fuplanner;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.content.ContentResolver;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.view.Menu;
|
||||
@@ -11,8 +14,11 @@ import android.widget.Toast;
|
||||
import com.android.volley.NetworkResponse;
|
||||
import com.google.android.material.navigation.NavigationView;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.Locale;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
@@ -25,31 +31,35 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentTransaction;
|
||||
import de.sebse.fuplanner.fragments.CanteensFragment;
|
||||
import de.sebse.fuplanner.fragments.LoginFragment;
|
||||
import de.sebse.fuplanner.fragments.ModulesFragment;
|
||||
import de.sebse.fuplanner.fragments.NewsFragment;
|
||||
import de.sebse.fuplanner.fragments.PrefsFragment;
|
||||
import de.sebse.fuplanner.fragments.ScheduleFragment;
|
||||
import de.sebse.fuplanner.fragments.StartupFragment;
|
||||
import de.sebse.fuplanner.fragments.canteen.DaySwitcherFragment;
|
||||
import de.sebse.fuplanner.fragments.moddetails.ModDetailFragment;
|
||||
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.GoogleAuth.Credentials;
|
||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.KVV.KVVListener;
|
||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||
import de.sebse.fuplanner.services.kvv.KVV;
|
||||
import de.sebse.fuplanner.services.kvv.KVVListener;
|
||||
import de.sebse.fuplanner.services.kvv.sync.KVVContentProvider;
|
||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.news.NewsManager;
|
||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||
import de.sebse.fuplanner.tools.CustomNotificationManager;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||
import de.sebse.fuplanner.tools.Preferences;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
import de.sebse.fuplanner.tools.types.News;
|
||||
|
||||
public class MainActivity extends AppCompatActivity
|
||||
implements MainActivityListener, KVVListener,
|
||||
implements MainActivityListener, KVVListener, CanteenListener,
|
||||
NavigationView.OnNavigationItemSelectedListener,
|
||||
ModulesFragment.OnModulesFragmentInteractionListener,
|
||||
CanteensFragment.OnCanteensFragmentInteractionListener {
|
||||
@@ -58,31 +68,37 @@ public class MainActivity extends AppCompatActivity
|
||||
private static final int FRAGMENT_STARTUP = 0;
|
||||
private static final int FRAGMENT_MODULES = 1;
|
||||
private static final int FRAGMENT_MODULES_DETAILS = 2;
|
||||
private static final int FRAGMENT_LOGIN = 3;
|
||||
private static final int FRAGMENT_SCHEDULE = 4;
|
||||
private static final int FRAGMENT_CANTEENS = 5;
|
||||
private static final int FRAGMENT_CANTEENS_DETAILS = 6;
|
||||
private static final int FRAGMENT_PREFERENCES = 7;
|
||||
private static final int FRAGMENT_NEWS = 8;
|
||||
|
||||
private static final String ARG_FRAGMENT_PAGE = "fragment_page";
|
||||
private static final String ARG_FRAGMENT_STATUS = "fragment_status";
|
||||
private static final int DOUBLE_CLICK_TO_EXIT_MILLIS = 2000;
|
||||
|
||||
private FragmentManager mFragmentManager;
|
||||
private GoogleAuth mGoogleAuth;
|
||||
private KVV mKVV;
|
||||
private NewsManager mNewsManager;
|
||||
private CanteenBrowser mCanteenBrowser;
|
||||
private final Logger log = new Logger(this);
|
||||
private NavigationView mNavigationView;
|
||||
|
||||
private int fragmentPage = FRAGMENT_NONE;
|
||||
private String fragmentData = "";
|
||||
private CanteenBrowser mCanteenBrowser;
|
||||
private HashMap<String, RequestPermissionsResultListener> permissionListeners = new HashMap<>();
|
||||
private boolean mOfflineBanner;
|
||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||
private int mFragmentPage = FRAGMENT_NONE;
|
||||
@NotNull
|
||||
private String mFragmentData = "";
|
||||
private final HashMap<String, RequestPermissionsResultListener> permissionListeners = new HashMap<>();
|
||||
private final NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||
private long mDoubleBackToExitPressedOnce = 0;
|
||||
private CustomAccountManager mAccountManager;
|
||||
private boolean isPaused = false;
|
||||
private boolean isLoggedInBeforePause = false;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
mAccountManager = new CustomAccountManager(AccountManager.get(this), () -> MainActivity.this);
|
||||
int desiredPage = getDefaultFragmentAfterLogin();
|
||||
String desiredData = "";
|
||||
if (savedInstanceState != null) {
|
||||
@@ -104,28 +120,100 @@ public class MainActivity extends AppCompatActivity
|
||||
mNavigationView.setNavigationItemSelectedListener(this);
|
||||
mFragmentManager = getSupportFragmentManager();
|
||||
|
||||
if (!getKVV().account().restoreOnlineLogin()) {
|
||||
desiredPage = FRAGMENT_LOGIN;
|
||||
//if (mAccountManager.getAccountsByType(AccountGeneral.ACCOUNT_TYPE).length == 0) {
|
||||
if (!mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
desiredPage = getDefaultFragmentAfterLogout();
|
||||
desiredData = "";
|
||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null);
|
||||
updateNavigation();
|
||||
changeFragment(desiredPage, desiredData);
|
||||
} else {
|
||||
updateNavigation();
|
||||
changeFragment(FRAGMENT_STARTUP);
|
||||
int targetPage = desiredPage;
|
||||
String targetData = desiredData;
|
||||
getKVV().account().restoreOnlineLogin(isRestored -> {
|
||||
updateNavigation();
|
||||
if (isRestored)
|
||||
changeFragment(targetPage, targetData);
|
||||
else
|
||||
changeFragment(getDefaultFragmentAfterLogout());
|
||||
});
|
||||
}
|
||||
updateNavigation();
|
||||
changeFragment(desiredPage, desiredData);
|
||||
|
||||
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
|
||||
registerSync();
|
||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
||||
}
|
||||
CustomNotificationManager.createNotificationChannel(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPause() {
|
||||
super.onPause();
|
||||
isPaused = true;
|
||||
isLoggedInBeforePause = getKVV().account().isLoggedIn();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
if (isPaused) {
|
||||
getKVV().account().restoreOnlineLogin(isRestored -> {
|
||||
updateNavigation();
|
||||
if (isRestored && !isLoggedInBeforePause)
|
||||
changeFragment(getDefaultFragmentAfterLogin());
|
||||
else if (!isRestored && isLoggedInBeforePause) {
|
||||
getKVV().account().logout(false);
|
||||
changeFragment(getDefaultFragmentAfterLogout());
|
||||
}
|
||||
});
|
||||
getKVV().modules().list().reloadIfOutdated();
|
||||
}
|
||||
isPaused = false;
|
||||
//log.d("onResume", "send notification!");
|
||||
//CustomNotificationManager.sendNotification(this, "Titel", "Neue Announcements!");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
if (mDoubleBackToExitPressedOnce + DOUBLE_CLICK_TO_EXIT_MILLIS > System.currentTimeMillis()) {
|
||||
super.onBackPressed();
|
||||
return;
|
||||
}
|
||||
|
||||
DrawerLayout drawer = findViewById(R.id.drawer_layout);
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
} else {
|
||||
super.onBackPressed();
|
||||
if (mFragmentPage == 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())) {
|
||||
fragment.gotoFragmentPart(0, -1);
|
||||
} else {
|
||||
changeFragment(FRAGMENT_MODULES);
|
||||
}
|
||||
} else if (mFragmentPage == FRAGMENT_CANTEENS_DETAILS) {
|
||||
DaySwitcherFragment fragment = (DaySwitcherFragment) mFragmentManager.findFragmentByTag(String.valueOf(FRAGMENT_CANTEENS_DETAILS));
|
||||
if (fragment != null && fragment.isVisible() && Regex.has("\\.[1-9][0-9]*", fragment.getData())) {
|
||||
fragment.gotoFragmentPart(0);
|
||||
} else {
|
||||
changeFragment(FRAGMENT_CANTEENS);
|
||||
}
|
||||
} else if (getKVV().account().isLoggedIn() && mFragmentPage != getDefaultFragmentAfterLogin()) {
|
||||
changeFragment(getDefaultFragmentAfterLogin());
|
||||
} else {
|
||||
mDoubleBackToExitPressedOnce = System.currentTimeMillis();
|
||||
showToast(R.string.back_to_exit);
|
||||
//getTokenForAccountCreateIfNeeded(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onCreateOptionsMenu(Menu menu) {
|
||||
// Inflate the menu; this adds items to the action bar if it is present.
|
||||
if (fragmentPage == FRAGMENT_SCHEDULE) {
|
||||
if (mFragmentPage == FRAGMENT_SCHEDULE) {
|
||||
getMenuInflater().inflate(R.menu.options_schedule, menu);
|
||||
return true;
|
||||
}
|
||||
@@ -171,6 +259,9 @@ public class MainActivity extends AppCompatActivity
|
||||
case R.id.nav_canteens:
|
||||
changeFragment(FRAGMENT_CANTEENS);
|
||||
break;
|
||||
case R.id.nav_news:
|
||||
changeFragment(FRAGMENT_NEWS);
|
||||
break;
|
||||
case R.id.nav_settings:
|
||||
changeFragment(FRAGMENT_PREFERENCES);
|
||||
break;
|
||||
@@ -184,11 +275,6 @@ public class MainActivity extends AppCompatActivity
|
||||
case R.id.nav_logout:
|
||||
getKVV().account().logout(true);
|
||||
getKVV().modules().list().delete();
|
||||
this.getGoogleAuth().getLoginState(credentials -> {
|
||||
if (credentials != null) {
|
||||
this.getGoogleAuth().deleteLoginState(credentials.getUsername(), credentials.getPassword());
|
||||
}
|
||||
});
|
||||
break;
|
||||
|
||||
}
|
||||
@@ -204,21 +290,17 @@ public class MainActivity extends AppCompatActivity
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
super.onActivityResult(requestCode, resultCode, data);
|
||||
this.getGoogleAuth().onActivityResult(requestCode, resultCode, data);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onSaveInstanceState(Bundle savedInstanceState) {
|
||||
if (fragmentPage != FRAGMENT_STARTUP && fragmentPage != FRAGMENT_NONE && fragmentPage != FRAGMENT_LOGIN) {
|
||||
Fragment fragment = mFragmentManager.findFragmentByTag(String.valueOf(fragmentPage));
|
||||
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, fragmentPage);
|
||||
if (mFragmentPage != FRAGMENT_STARTUP && mFragmentPage != FRAGMENT_NONE) {
|
||||
Fragment fragment = mFragmentManager.findFragmentByTag(String.valueOf(mFragmentPage));
|
||||
savedInstanceState.putInt(ARG_FRAGMENT_PAGE, mFragmentPage);
|
||||
if (fragment instanceof ModDetailFragment) {
|
||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, ((ModDetailFragment) fragment).getData());
|
||||
} else if (fragment instanceof DaySwitcherFragment) {
|
||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, ((DaySwitcherFragment) fragment).getData());
|
||||
} else {
|
||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, fragmentData);
|
||||
savedInstanceState.putString(ARG_FRAGMENT_STATUS, mFragmentData);
|
||||
}
|
||||
}
|
||||
super.onSaveInstanceState(savedInstanceState);
|
||||
@@ -235,21 +317,13 @@ public class MainActivity extends AppCompatActivity
|
||||
/* --------------------------------------------*/
|
||||
/* --------------------------------------------*/
|
||||
|
||||
public GoogleAuth getGoogleAuth() {
|
||||
if (this.mGoogleAuth == null) {
|
||||
this.mGoogleAuth = new GoogleAuth(this);
|
||||
public NewsManager getNewsManager() {
|
||||
if (this.mNewsManager == null) {
|
||||
this.mNewsManager = new NewsManager(this);
|
||||
}
|
||||
return this.mGoogleAuth;
|
||||
return this.mNewsManager;
|
||||
}
|
||||
|
||||
/*@Deprecated
|
||||
public de.sebse.fuplanner.services.KVV.KVV getKVV() {
|
||||
if (this.mKVV == null) {
|
||||
this.mKVV = new de.sebse.fuplanner.services.KVV.KVV(this);
|
||||
}
|
||||
return this.mKVV;
|
||||
}*/
|
||||
|
||||
public KVV getKVV() {
|
||||
if (this.mKVV == null) {
|
||||
this.mKVV = new KVV(this, this);
|
||||
@@ -268,15 +342,18 @@ public class MainActivity extends AppCompatActivity
|
||||
return FRAGMENT_MODULES;
|
||||
}
|
||||
|
||||
private void toLogoutState() {
|
||||
setOfflineBanner(false);
|
||||
setRefreshFailedBanner(false);
|
||||
updateNavigation();
|
||||
changeFragment(FRAGMENT_LOGIN);
|
||||
private int getDefaultFragmentAfterLogout() {
|
||||
return FRAGMENT_CANTEENS;
|
||||
}
|
||||
|
||||
private void toLoginState(String fullName, String email, int newFragment, boolean onlineMode) {
|
||||
setOfflineBanner(!onlineMode);
|
||||
private void toLogoutState() {
|
||||
setRefreshFailedBanner(false);
|
||||
updateNavigation();
|
||||
changeFragment(getDefaultFragmentAfterLogout());
|
||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null);
|
||||
}
|
||||
|
||||
private void toLoginState(String fullName, String email, int newFragment) {
|
||||
updateNavigation();
|
||||
|
||||
View header = mNavigationView.getHeaderView(0);
|
||||
@@ -284,6 +361,20 @@ public class MainActivity extends AppCompatActivity
|
||||
((TextView) header.findViewById(R.id.login_mail)).setText(email);
|
||||
|
||||
changeFragment(newFragment);
|
||||
registerSync();
|
||||
}
|
||||
|
||||
private void registerSync() {
|
||||
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
||||
log.d("registerSync", accountByType);
|
||||
if (accountByType != null) {
|
||||
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
|
||||
ContentResolver.addPeriodicSync(
|
||||
accountByType,
|
||||
KVVContentProvider.PROVIDER_NAME,
|
||||
Bundle.EMPTY,
|
||||
AccountGeneral.SYNC_INTERVAL);
|
||||
}
|
||||
}
|
||||
|
||||
private void changeFragment(int newFragment) {
|
||||
@@ -307,18 +398,23 @@ public class MainActivity extends AppCompatActivity
|
||||
case FRAGMENT_MODULES:
|
||||
fragment = ModulesFragment.newInstance();
|
||||
break;
|
||||
case FRAGMENT_LOGIN:
|
||||
/*case FRAGMENT_LOGIN:
|
||||
fragment = LoginFragment.newInstance();
|
||||
break;
|
||||
break;*/
|
||||
case FRAGMENT_SCHEDULE:
|
||||
fragment = ScheduleFragment.newInstance();
|
||||
break;
|
||||
case FRAGMENT_CANTEENS_DETAILS:
|
||||
fragment = DaySwitcherFragment.newInstance(Integer.parseInt(newData));
|
||||
fragment = DaySwitcherFragment.newInstance(newData);
|
||||
break;
|
||||
case FRAGMENT_CANTEENS:
|
||||
fragment = CanteensFragment.newInstance();
|
||||
break;
|
||||
case FRAGMENT_NEWS:
|
||||
Preferences.setLong(this, R.string.pref_last_visited_news, System.currentTimeMillis());
|
||||
updateNavigation();
|
||||
fragment = NewsFragment.newInstance();
|
||||
break;
|
||||
case FRAGMENT_PREFERENCES:
|
||||
fragment = PrefsFragment.newInstance();
|
||||
break;
|
||||
@@ -337,69 +433,72 @@ public class MainActivity extends AppCompatActivity
|
||||
findViewById(R.id.app_bar_include).setVisibility(View.VISIBLE);
|
||||
}
|
||||
|
||||
this.fragmentPage = newFragment;
|
||||
this.fragmentData = newData;
|
||||
this.mFragmentPage = newFragment;
|
||||
this.mFragmentData = newData;
|
||||
|
||||
invalidateOptionsMenu();
|
||||
}
|
||||
|
||||
private void setOfflineBanner(boolean visible) {
|
||||
View offline_header = findViewById(R.id.offline_msg);
|
||||
offline_header.setVisibility(visible ? View.VISIBLE : View.GONE);
|
||||
mOfflineBanner = visible;
|
||||
}
|
||||
|
||||
private void setRefreshFailedBanner(boolean refreshFailed) {
|
||||
View viewNoConnection = findViewById(R.id.no_connection_msg);
|
||||
if (!mOfflineBanner && refreshFailed)
|
||||
if (refreshFailed)
|
||||
viewNoConnection.setVisibility(View.VISIBLE);
|
||||
else
|
||||
viewNoConnection.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
private void setNavigationSelection() {
|
||||
MenuItem item;
|
||||
switch (fragmentPage) {
|
||||
MenuItem item = null;
|
||||
switch (mFragmentPage) {
|
||||
case FRAGMENT_MODULES_DETAILS:
|
||||
getKVV().modules().list().find(fragmentData, success -> {
|
||||
getKVV().modules().list().find(mFragmentData, success -> {
|
||||
int size = mNavigationView.getMenu().size();
|
||||
//noinspection ConstantConditions
|
||||
String title = success == null ? null : success.title;
|
||||
for (int k = 0; k < size; k++) {
|
||||
mNavigationView.getMenu().getItem(k).setChecked(mNavigationView.getMenu().getItem(k).getTitle().equals(title));
|
||||
MenuItem menuItem = mNavigationView.getMenu().getItem(k);
|
||||
if (menuItem.getTitle().equals(title)) {
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, log::e);
|
||||
break;
|
||||
return;
|
||||
case FRAGMENT_MODULES:
|
||||
item = mNavigationView.getMenu().findItem(R.id.nav_modules);
|
||||
if (item != null)
|
||||
item.setChecked(true);
|
||||
break;
|
||||
case FRAGMENT_SCHEDULE:
|
||||
item = mNavigationView.getMenu().findItem(R.id.nav_schedule);
|
||||
if (item != null)
|
||||
item.setChecked(true);
|
||||
break;
|
||||
case FRAGMENT_CANTEENS_DETAILS:
|
||||
getCanteenBrowser().getCanteens(success -> {
|
||||
int size = mNavigationView.getMenu().size();
|
||||
Canteen canteen = success.getCanteen(Integer.parseInt(fragmentData));
|
||||
Canteen canteen = success.getCanteen(Integer.parseInt(mFragmentData));
|
||||
//noinspection ConstantConditions
|
||||
String title = canteen == null ? null : canteen.getName();
|
||||
for (int k = 0; k < size; k++) {
|
||||
mNavigationView.getMenu().getItem(k).setChecked(mNavigationView.getMenu().getItem(k).getTitle().equals(title));
|
||||
MenuItem menuItem = mNavigationView.getMenu().getItem(k);
|
||||
if (menuItem.getTitle().equals(title)) {
|
||||
menuItem.setChecked(true);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}, log::e);
|
||||
break;
|
||||
return;
|
||||
case FRAGMENT_CANTEENS:
|
||||
mNavigationView.getMenu().findItem(R.id.nav_canteens).setChecked(true);
|
||||
item = mNavigationView.getMenu().findItem(R.id.nav_canteens);
|
||||
break;
|
||||
case FRAGMENT_NEWS:
|
||||
item = mNavigationView.getMenu().findItem(R.id.nav_news);
|
||||
break;
|
||||
case FRAGMENT_PREFERENCES:
|
||||
mNavigationView.getMenu().findItem(R.id.nav_settings).setChecked(true);
|
||||
item = mNavigationView.getMenu().findItem(R.id.nav_settings);
|
||||
break;
|
||||
default: // FRAGMENT_STARTUP / FRAGMENT_LOGIN
|
||||
break;
|
||||
}
|
||||
if (item != null)
|
||||
item.setChecked(true);
|
||||
}
|
||||
|
||||
private void setNavigationHeader(boolean isLoggedIn) {
|
||||
@@ -417,12 +516,12 @@ public class MainActivity extends AppCompatActivity
|
||||
if (drawer.isDrawerOpen(GravityCompat.START)) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
}
|
||||
changeFragment(FRAGMENT_LOGIN);
|
||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, null);
|
||||
});
|
||||
}
|
||||
|
||||
private void afterAnyMenuInflate(boolean isLoggedIn, Runnable done) {
|
||||
int MAX_COUNT = isLoggedIn ? 2 : 1;
|
||||
int MAX_COUNT = isLoggedIn ? 3 : 2;
|
||||
final int[] count = {0};
|
||||
if (isLoggedIn) {
|
||||
getKVV().modules().list().recv(success -> {
|
||||
@@ -437,9 +536,9 @@ public class MainActivity extends AppCompatActivity
|
||||
i++;
|
||||
}
|
||||
if (++count[0] == MAX_COUNT) done.run();
|
||||
}, msg -> {
|
||||
}, error -> {
|
||||
if (++count[0] == MAX_COUNT) done.run();
|
||||
log.e(msg);
|
||||
log.e(error);
|
||||
});
|
||||
}
|
||||
getCanteenBrowser().getCanteens(success -> {
|
||||
@@ -453,9 +552,28 @@ public class MainActivity extends AppCompatActivity
|
||||
i++;
|
||||
}
|
||||
if (++count[0] == MAX_COUNT) done.run();
|
||||
}, msg -> {
|
||||
}, error -> {
|
||||
if (++count[0] == MAX_COUNT) done.run();
|
||||
log.e(msg);
|
||||
log.e(error);
|
||||
});
|
||||
getNewsManager().recv(success -> {
|
||||
long lastVisited = Preferences.getLong(this, R.string.pref_last_visited_news);
|
||||
int i = 0;
|
||||
for (News news: success) {
|
||||
if (news.getDate() > lastVisited) i++;
|
||||
}
|
||||
if (i > 0) {
|
||||
MenuItem menuItem = mNavigationView.getMenu().findItem(R.id.nav_news);
|
||||
menuItem.setIcon(R.drawable.ic_sms_failed);
|
||||
View view = View.inflate(this, R.layout.action_icon_number, null);
|
||||
TextView v = view.findViewById(R.id.number);
|
||||
v.setText(String.format(Locale.getDefault(), "%d", i));
|
||||
menuItem.setActionView(view);
|
||||
}
|
||||
if (++count[0] == MAX_COUNT) done.run();
|
||||
}, error -> {
|
||||
if (++count[0] == MAX_COUNT) done.run();
|
||||
log.e(error);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -483,14 +601,19 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onModulesFragmentInteraction(final String itemID) {
|
||||
changeFragment(FRAGMENT_MODULES_DETAILS, itemID);
|
||||
setNavigationSelection();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCanteensFragmentInteraction(final int itemID) {
|
||||
changeFragment(FRAGMENT_CANTEENS_DETAILS, String.valueOf(itemID));
|
||||
setNavigationSelection();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -504,7 +627,7 @@ public class MainActivity extends AppCompatActivity
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRefreshCompleted(boolean isFailed) {
|
||||
public void onCanteenRefreshCompleted(boolean isFailed) {
|
||||
setRefreshFailedBanner(isFailed);
|
||||
}
|
||||
|
||||
@@ -537,20 +660,10 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void getCredentials(NetworkCallback<Credentials> callback, NetworkErrorCallback error) {
|
||||
getGoogleAuth().getLoginState(credentials -> {
|
||||
if (credentials == null || credentials.getUsername() == null || credentials.getPassword() == null) {
|
||||
error.onError(new NetworkError(200100, 403, "No Google Login available!"));
|
||||
} else {
|
||||
callback.onResponse(credentials);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onLogin(LoginToken token, boolean enteringOnlineMode) {
|
||||
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin(), enteringOnlineMode);
|
||||
public void onLogin(LoginToken token) {
|
||||
toLoginState(token.getFullName(), token.getEmail(), getDefaultFragmentAfterLogin());
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -567,4 +680,9 @@ public class MainActivity extends AppCompatActivity
|
||||
public void onKVVNetworkResponse(NetworkResponse error) {
|
||||
setRefreshFailedBanner(error != null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public CustomAccountManager getAccountManager() {
|
||||
return mAccountManager;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,12 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.fragments.CanteensFragment.OnCanteensFragmentInteractionListener;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteens;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteens;
|
||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||
|
||||
/**
|
||||
* {@link RecyclerView.Adapter} that can display a {@link Modules.Module} and makes a call to the
|
||||
* {@link RecyclerView.Adapter} that can display a {@link Canteen} and makes a call to the
|
||||
* specified {@link OnCanteensFragmentInteractionListener}.
|
||||
*/
|
||||
class CanteensAdapter extends RecyclerView.Adapter<ItemViewHolder> {
|
||||
|
||||
@@ -13,7 +13,7 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
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.logging.Logger;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class CanteensFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_modules_list, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_recycler_view, container, false);
|
||||
// Set the adapter
|
||||
Context context = view.getContext();
|
||||
RecyclerView recyclerView = view.findViewById(R.id.list);
|
||||
|
||||
@@ -1,112 +0,0 @@
|
||||
package de.sebse.fuplanner.fragments;
|
||||
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link LoginFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class LoginFragment extends Fragment {
|
||||
private final Logger log = new Logger(this);
|
||||
@Nullable private MainActivityListener mActivityListener;
|
||||
|
||||
public LoginFragment() {
|
||||
// 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 LoginFragment.
|
||||
*/
|
||||
public static LoginFragment newInstance() {
|
||||
LoginFragment fragment = new LoginFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
// Inflate the layout for this fragment
|
||||
View v = inflater.inflate(R.layout.fragment_login, container, false);
|
||||
if (mActivityListener != null && mActivityListener.getKVV().account().isOfflineStoredAvailable()) {
|
||||
Button offline_btn = v.findViewById(R.id.btn_offline);
|
||||
offline_btn.setVisibility(View.VISIBLE);
|
||||
offline_btn.setText(v.getResources().getString(R.string.enter_offline_mode, mActivityListener.getKVV().modules().list().getUsername()));
|
||||
offline_btn.setOnClickListener(v1 -> mActivityListener.getKVV().account().doOfflineLogin());
|
||||
}
|
||||
|
||||
View btn_login = v.findViewById(R.id.btn_login);
|
||||
btn_login.setOnClickListener(view -> {
|
||||
final ProgressDialog progressDialog = new ProgressDialog(LoginFragment.this.getContext(),
|
||||
R.style.FUTheme_Dialog);
|
||||
progressDialog.setIndeterminate(true);
|
||||
progressDialog.setMessage("Authenticating...");
|
||||
progressDialog.show();
|
||||
|
||||
EditText input_usr = ((View) view.getParent()).findViewById(R.id.input_username);
|
||||
EditText input_pwd = ((View) view.getParent()).findViewById(R.id.input_password);
|
||||
|
||||
String username = input_usr.getText().toString();
|
||||
String password = input_pwd.getText().toString();
|
||||
|
||||
mActivityListener.getKVV().account().doOnlineLogin(username, password, success -> {
|
||||
progressDialog.dismiss();
|
||||
mActivityListener.getGoogleAuth().setLoginState(username, password);
|
||||
input_usr.setError(null);
|
||||
input_pwd.setError(null);
|
||||
}, error -> {
|
||||
progressDialog.dismiss();
|
||||
// Invalid password
|
||||
if (mActivityListener != null) {
|
||||
if (error.getCode() == 100131) {
|
||||
mActivityListener.showToast(R.string.invalid_credentials);
|
||||
input_usr.setError(input_usr.getResources().getString(R.string.invalid_credentials));
|
||||
input_pwd.setError(input_pwd.getResources().getString(R.string.invalid_credentials));
|
||||
} else {
|
||||
mActivityListener.showToast(v.getResources().getString(R.string.error_occurred_code, error.getCode()));
|
||||
}
|
||||
}
|
||||
log.e("Error on KVV login!", error);
|
||||
});
|
||||
});
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof MainActivityListener) {
|
||||
mActivityListener = (MainActivityListener) context;
|
||||
mActivityListener.onTitleTextChange(R.string.log_in);
|
||||
} else
|
||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mActivityListener = null;
|
||||
}
|
||||
}
|
||||
@@ -11,9 +11,9 @@ import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.fragments.ModulesFragment.OnModulesFragmentInteractionListener;
|
||||
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.KVV.types.Semester;
|
||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Semester;
|
||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||
|
||||
@@ -47,7 +47,7 @@ public class ModulesFragment extends Fragment {
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
|
||||
View view = inflater.inflate(R.layout.fragment_modules_list, container, false);
|
||||
View view = inflater.inflate(R.layout.fragment_recycler_view, container, false);
|
||||
// Set the adapter
|
||||
Context context = view.getContext();
|
||||
RecyclerView recyclerView = view.findViewById(R.id.list);
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
package de.sebse.fuplanner.fragments;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.fragments.ModulesFragment.OnModulesFragmentInteractionListener;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.types.News;
|
||||
import de.sebse.fuplanner.tools.types.NewsList;
|
||||
import de.sebse.fuplanner.tools.ui.NewsViewHolder;
|
||||
|
||||
/**
|
||||
* {@link RecyclerView.Adapter} that can display a {@link Modules.Module} and makes a call to the
|
||||
* specified {@link OnModulesFragmentInteractionListener}.
|
||||
*/
|
||||
class NewsAdapter extends RecyclerView.Adapter<NewsViewHolder> {
|
||||
|
||||
|
||||
private NewsList mValues;
|
||||
|
||||
NewsAdapter() {
|
||||
mValues = null;
|
||||
}
|
||||
|
||||
public void setNews(NewsList news) {
|
||||
mValues = news;
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public NewsViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_news_item, parent, false);
|
||||
return new NewsViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull NewsViewHolder holder, int position) {
|
||||
News news = mValues.getPast(position);
|
||||
holder.mHeader.setText(news.getTitle());
|
||||
switch (news.getCategory()) {
|
||||
case News.CATEGORY_UPDATE:
|
||||
holder.mSubLeft.setText(R.string.update_news);
|
||||
case News.CATEGORY_TRICKS:
|
||||
holder.mSubLeft.setText(R.string.tricks);
|
||||
}
|
||||
holder.mSubRight.setText(UtilsDate.getModifiedDate(news.getDate()));
|
||||
holder.mText.setText(news.getText());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mValues != null ? mValues.sizePast() : 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,97 @@
|
||||
package de.sebse.fuplanner.fragments;
|
||||
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Bundle;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import androidx.recyclerview.widget.LinearLayoutManager;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.types.NewsList;
|
||||
|
||||
/**
|
||||
* A simple {@link Fragment} subclass.
|
||||
* Use the {@link NewsFragment#newInstance} factory method to
|
||||
* create an instance of this fragment.
|
||||
*/
|
||||
public class NewsFragment extends Fragment {
|
||||
private Logger log = new Logger(this);
|
||||
private MainActivityListener mListener;
|
||||
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() {
|
||||
// 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 NewsFragment.
|
||||
*/
|
||||
// TODO: Rename and change types and number of parameters
|
||||
public static NewsFragment newInstance() {
|
||||
NewsFragment fragment = new NewsFragment();
|
||||
Bundle args = new Bundle();
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttach(Context context) {
|
||||
super.onAttach(context);
|
||||
if (context instanceof MainActivityListener) {
|
||||
mListener = (MainActivityListener) context;
|
||||
mListener.onTitleTextChange(R.string.news);
|
||||
}
|
||||
else
|
||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||
refresh(false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDetach() {
|
||||
super.onDetach();
|
||||
mListener = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public View onCreateView(@NonNull LayoutInflater inflater, ViewGroup container,
|
||||
Bundle savedInstanceState) {
|
||||
View view = inflater.inflate(R.layout.fragment_recycler_norefresh, container, false);
|
||||
// Set the adapter
|
||||
Context context = view.getContext();
|
||||
RecyclerView recyclerView = view.findViewById(R.id.list);
|
||||
recyclerView.setLayoutManager(new LinearLayoutManager(context));
|
||||
mAdapter = new NewsAdapter();
|
||||
recyclerView.setAdapter(mAdapter);
|
||||
refresh(false);
|
||||
|
||||
return view;
|
||||
}
|
||||
|
||||
private void refresh(boolean forceRefresh) {
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getNewsManager().recv(success -> {
|
||||
if (mAdapter != null)
|
||||
mAdapter.setNews(success);
|
||||
}, log::e, forceRefresh);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,8 +16,8 @@ import java.util.List;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Event;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
@@ -34,7 +34,11 @@ import de.sebse.fuplanner.tools.ui.weekview.WeekViewEvent;
|
||||
* create an instance of this fragment.
|
||||
*
|
||||
*/
|
||||
public class ScheduleFragment extends Fragment implements MonthLoader.MonthChangeListener, WeekView.ScrollListener, WeekView.DoubleTapListener, WeekView.EventClickListener {
|
||||
public class ScheduleFragment extends Fragment implements
|
||||
MonthLoader.MonthChangeListener,
|
||||
WeekView.ScrollListener,
|
||||
WeekView.DoubleTapLeftRightListener,
|
||||
WeekView.EventClickListener {
|
||||
private MainActivityListener mListener;
|
||||
private WeekView mWeekView;
|
||||
private final Logger log = new Logger(this);
|
||||
@@ -83,7 +87,7 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
mWeekView = v.findViewById(R.id.weekView);
|
||||
mWeekView.setMonthChangeListener(this);
|
||||
mWeekView.setScrollListener(this);
|
||||
mWeekView.setDoubleTapListener(this);
|
||||
mWeekView.setDoubleTapLeftRightListener(this);
|
||||
mWeekView.setOnEventClickListener(this);
|
||||
invalidate(false);
|
||||
return v;
|
||||
@@ -150,26 +154,21 @@ public class ScheduleFragment extends Fragment implements MonthLoader.MonthChang
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDoubleTapListener(Calendar time) {
|
||||
public void onDoubleTapLeftRightListener(boolean isRight) {
|
||||
Calendar firstVisibleDay = mWeekView.getFirstVisibleDay();
|
||||
Calendar c = Calendar.getInstance();
|
||||
c.set(firstVisibleDay.get(Calendar.YEAR), firstVisibleDay.get(Calendar.MONTH), firstVisibleDay.get(Calendar.DAY_OF_MONTH), 0,0 );
|
||||
// Limit when to go a week backwards and when to the next week
|
||||
c.add(Calendar.DATE, 2);
|
||||
|
||||
// skip to next week
|
||||
if (c.getTimeInMillis() > time.getTimeInMillis()){
|
||||
firstVisibleDay.add(Calendar.DATE, -1);
|
||||
while (firstVisibleDay.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
|
||||
firstVisibleDay.add(Calendar.DATE, -1);
|
||||
}
|
||||
}
|
||||
else{
|
||||
if (isRight){
|
||||
firstVisibleDay.add(Calendar.DATE, 1);
|
||||
while (firstVisibleDay.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
|
||||
firstVisibleDay.add(Calendar.DATE, 1);
|
||||
}
|
||||
}
|
||||
else {
|
||||
firstVisibleDay.add(Calendar.DATE, -1);
|
||||
while (firstVisibleDay.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY) {
|
||||
firstVisibleDay.add(Calendar.DATE, -1);
|
||||
}
|
||||
}
|
||||
mWeekView.goToDate(firstVisibleDay);
|
||||
onFirstVisibleDayChanged(firstVisibleDay, mWeekView.getLastVisibleDay());
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentManager;
|
||||
import androidx.fragment.app.FragmentStatePagerAdapter;
|
||||
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
|
||||
class DaySwitcherAdapter extends FragmentStatePagerAdapter {
|
||||
|
||||
@@ -11,8 +11,8 @@ import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
@@ -31,10 +31,12 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
||||
|
||||
// Parameters
|
||||
private int mCanteenId;
|
||||
private String mPageRestoreRequest = null;
|
||||
|
||||
private MainActivityListener mListener;
|
||||
private final Logger log = new Logger(this);
|
||||
private DaySwitcherAdapter adapterViewPager;
|
||||
private ViewPager mViewPager;
|
||||
|
||||
public DaySwitcherFragment() {
|
||||
// Required empty public constructor
|
||||
@@ -47,10 +49,14 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
||||
* @param canteenId Canteen id in canteens list.
|
||||
* @return A new instance of fragment DaySwitcherFragment.
|
||||
*/
|
||||
public static Fragment newInstance(int canteenId) {
|
||||
public static Fragment newInstance(String canteenId) {
|
||||
DaySwitcherFragment fragment = new DaySwitcherFragment();
|
||||
Bundle args = new Bundle();
|
||||
args.putInt(ARG_POSITION, canteenId);
|
||||
if (!canteenId.contains("."))
|
||||
args.putString(ARG_POSITION, canteenId+".0");
|
||||
else
|
||||
args.putString(ARG_POSITION, canteenId);
|
||||
|
||||
fragment.setArguments(args);
|
||||
return fragment;
|
||||
}
|
||||
@@ -59,7 +65,15 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
||||
public void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (getArguments() != null) {
|
||||
mCanteenId = getArguments().getInt(ARG_POSITION);
|
||||
String canteenId = getArguments().getString(ARG_POSITION);
|
||||
if (!canteenId.contains(".")) {
|
||||
mCanteenId = Integer.parseInt(canteenId);
|
||||
mPageRestoreRequest = null;
|
||||
} else {
|
||||
String[] split = canteenId.split("\\.", 2);
|
||||
mCanteenId = Integer.parseInt(split[0]);
|
||||
mPageRestoreRequest = split[1];
|
||||
}
|
||||
}
|
||||
if (mListener != null) {
|
||||
mListener.onTitleTextChange(R.string.canteens);
|
||||
@@ -77,10 +91,10 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
||||
// Inflate the layout for this fragment
|
||||
View v = inflater.inflate(R.layout.fragment_mod_detail, container, false);
|
||||
|
||||
ViewPager mViewPager = v.findViewById(R.id.vpPager);
|
||||
mViewPager = v.findViewById(R.id.vpPager);
|
||||
adapterViewPager = new DaySwitcherAdapter(getChildFragmentManager());
|
||||
mViewPager.setAdapter(adapterViewPager);
|
||||
|
||||
applyPageRequest();
|
||||
refresh();
|
||||
|
||||
return v;
|
||||
@@ -114,8 +128,10 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
||||
Canteen canteen = canteens.getCanteen(mCanteenId);
|
||||
canteen.cleanUpDays();
|
||||
adapterViewPager.setModule(canteen);
|
||||
applyPageRequest();
|
||||
browser.getCanteen(canteen, success -> {
|
||||
adapterViewPager.setModule();
|
||||
applyPageRequest();
|
||||
if (callback != null)
|
||||
callback.onResponse(success);
|
||||
}, error -> {
|
||||
@@ -136,4 +152,20 @@ public class DaySwitcherFragment extends Fragment implements DaySwitcherListener
|
||||
refresh(true, callback, errorCallback);
|
||||
}
|
||||
|
||||
public void gotoFragmentPart(int part) {
|
||||
mViewPager.setCurrentItem(part, true);
|
||||
}
|
||||
|
||||
public String getData() {
|
||||
return mCanteenId+"."+mViewPager.getCurrentItem();
|
||||
}
|
||||
|
||||
private void applyPageRequest() {
|
||||
if (mPageRestoreRequest != null) {
|
||||
int request = Integer.parseInt(mPageRestoreRequest);
|
||||
mViewPager.setCurrentItem(request);
|
||||
if (request == mViewPager.getCurrentItem())
|
||||
mPageRestoreRequest = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
package de.sebse.fuplanner.fragments.canteen;
|
||||
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
|
||||
@@ -13,19 +13,19 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Day;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Meal;
|
||||
import de.sebse.fuplanner.services.canteen.types.Day;
|
||||
import de.sebse.fuplanner.services.canteen.types.Meal;
|
||||
import de.sebse.fuplanner.tools.Preferences;
|
||||
import de.sebse.fuplanner.tools.ui.MealViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||
|
||||
class MealAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
private String[] CATEGORY_KEYS = new String[]{"Essen", "Aktionen", "Beilagen", "Desserts", "Salate", "Suppen", "Vorspeisen"};
|
||||
private final String[] CATEGORY_KEYS = new String[]{"Essen", "Aktionen", "Beilagen", "Desserts", "Salate", "Suppen", "Vorspeisen"};
|
||||
@StringRes
|
||||
private int[] CATEGORY_VALS = new int[]{R.string.meals, R.string.special_meals, R.string.side_dishes, R.string.desserts, R.string.salads, R.string.soups, R.string.starters};
|
||||
private final int[] CATEGORY_VALS = new int[]{R.string.meals, R.string.special_meals, R.string.side_dishes, R.string.desserts, R.string.salads, R.string.soups, R.string.starters};
|
||||
@StringRes
|
||||
private int CATEGORY_OTHER = R.string.others;
|
||||
private ArrayList<Object> matches = new ArrayList<>();
|
||||
private final int CATEGORY_OTHER = R.string.others;
|
||||
private final ArrayList<Object> matches = new ArrayList<>();
|
||||
|
||||
private Day mDay = null;
|
||||
private final Context mContext;
|
||||
|
||||
@@ -13,9 +13,9 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Day;
|
||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.Day;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
|
||||
@@ -16,9 +16,9 @@ import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
||||
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
@@ -29,7 +29,7 @@ class ModDetailAnnounceAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
|
||||
@Nullable private Modules.Module mModule = null;
|
||||
private Logger log = new Logger(this);
|
||||
@NonNull private Download.OnDownloadRequestInterface requestInterface;
|
||||
@NonNull private final Download.OnDownloadRequestInterface requestInterface;
|
||||
|
||||
ModDetailAnnounceAdapter(@NonNull Download.OnDownloadRequestInterface requestInterface) {
|
||||
this.requestInterface = requestInterface;
|
||||
@@ -40,7 +40,7 @@ class ModDetailAnnounceAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
this.setModule();
|
||||
}
|
||||
|
||||
public void setModule() {
|
||||
private void setModule() {
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
@@ -84,9 +84,10 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
||||
private void refresh(boolean forceRefresh) {
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getKVV().modules().announcements().recv(mItemPos, success -> {
|
||||
adapter.setModule(success);
|
||||
swipeLayout.setRefreshing(false);
|
||||
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||
adapter.setModule(pair.first);
|
||||
if (pair.second)
|
||||
swipeLayout.setRefreshing(false);
|
||||
}, error -> {
|
||||
swipeLayout.setRefreshing(false);
|
||||
log.e(error);
|
||||
@@ -99,7 +100,7 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
||||
return;
|
||||
mListener.getKVV().modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||
String folderName = "FU-"+module.title.replaceAll("[:*<>|/\"\\\\]", "-");
|
||||
folderName += "/Assignment";
|
||||
folderName += "/Announcement";
|
||||
getDownload().openDownloadDialog(title, url, folderName);
|
||||
}, log::e);
|
||||
}
|
||||
@@ -123,7 +124,7 @@ public class ModDetailAnnounceFragment extends Fragment implements Download.OnDo
|
||||
}
|
||||
}
|
||||
|
||||
Download getDownload() {
|
||||
private Download getDownload() {
|
||||
if (download == null)
|
||||
download = new Download(this::getContext, () -> (MainActivity) getActivity());
|
||||
return download;
|
||||
|
||||
@@ -16,9 +16,9 @@ import androidx.annotation.Nullable;
|
||||
import androidx.core.content.ContextCompat;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
||||
import de.sebse.fuplanner.services.kvv.types.Assignment;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
@@ -29,7 +29,7 @@ class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder>
|
||||
|
||||
@Nullable private Modules.Module mModule = null;
|
||||
private Logger log = new Logger(this);
|
||||
@NonNull private Download.OnDownloadRequestInterface requestInterface;
|
||||
@NonNull private final Download.OnDownloadRequestInterface requestInterface;
|
||||
|
||||
ModDetailAssignmentAdapter(@NonNull Download.OnDownloadRequestInterface requestInterface) {
|
||||
this.requestInterface = requestInterface;
|
||||
@@ -40,7 +40,7 @@ class ModDetailAssignmentAdapter extends RecyclerView.Adapter<CustomViewHolder>
|
||||
this.setModule();
|
||||
}
|
||||
|
||||
public void setModule() {
|
||||
private void setModule() {
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
|
||||
@@ -14,8 +14,8 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
@@ -84,9 +84,10 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
||||
private void refresh(boolean forceRefresh) {
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getKVV().modules().assignments().recv(mItemPos, success -> {
|
||||
adapter.setModule(success);
|
||||
swipeLayout.setRefreshing(false);
|
||||
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||
adapter.setModule(pair.first);
|
||||
if (pair.second)
|
||||
swipeLayout.setRefreshing(false);
|
||||
}, error -> {
|
||||
swipeLayout.setRefreshing(false);
|
||||
log.e(error);
|
||||
@@ -95,7 +96,6 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
||||
|
||||
@Override
|
||||
public void request(String title, String url) {
|
||||
log.d(title, url, mListener);
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getKVV().modules().list().find(mItemPos, (Modules.Module module) -> {
|
||||
@@ -124,7 +124,7 @@ public class ModDetailAssignmentFragment extends Fragment implements Download.On
|
||||
}
|
||||
}
|
||||
|
||||
Download getDownload() {
|
||||
private Download getDownload() {
|
||||
if (download == null)
|
||||
download = new Download(this::getContext, () -> (MainActivity) getActivity());
|
||||
return download;
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.util.Pair;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
@@ -12,14 +14,15 @@ import java.util.Map;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.services.KVV.types.EventList;
|
||||
import de.sebse.fuplanner.services.KVV.types.GroupedEvents;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.tools.Triplet;
|
||||
import de.sebse.fuplanner.services.kvv.types.Event;
|
||||
import de.sebse.fuplanner.services.kvv.types.EventList;
|
||||
import de.sebse.fuplanner.services.kvv.types.GroupedEvents;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
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.ListViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||
|
||||
class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
private static final String VALUE_LECTURE = "Class section - Lecture";
|
||||
@@ -33,9 +36,10 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
private static final int TYPE_NONE = 0;
|
||||
private static final int TYPE_GROUPED = 1;
|
||||
private static final int TYPE_UNGROUPED = 2;
|
||||
private static final int TYPE_HEADER = 3;
|
||||
|
||||
private Modules.Module mValue;
|
||||
private final ArrayList<Triplet<Integer, String, Object>> mPositionalData;
|
||||
private final ArrayList<Pair<Integer, Object>> mPositionalData;
|
||||
|
||||
private final Logger log = new Logger(this);
|
||||
|
||||
@@ -50,7 +54,7 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
this.setModule();
|
||||
}
|
||||
|
||||
public void setModule() {
|
||||
private void setModule() {
|
||||
LinkedHashMap<String, GroupedEvents> listsGrouped = new LinkedHashMap<>();
|
||||
LinkedHashMap<String, EventList> listsUngrouped = new LinkedHashMap<>();
|
||||
for (String value : VALUES_GROUPED) listsGrouped.put(value, new GroupedEvents());
|
||||
@@ -75,15 +79,36 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
|
||||
mPositionalData.clear();
|
||||
for (Map.Entry<String, GroupedEvents> value: listsGrouped.entrySet()) {
|
||||
if (value.getValue().getGroups().size() > 0)
|
||||
mPositionalData.add(new Triplet<>(TYPE_GROUPED, value.getKey(), value.getValue()));
|
||||
if (value.getValue().getGroups().size() > 0) {
|
||||
mPositionalData.add(new Pair<>(TYPE_HEADER, value.getKey()));
|
||||
boolean showAsGrouped = true;
|
||||
for (GroupedEvents.Group group : value.getValue().getGroups()) {
|
||||
if (group.getSkippedDates().size() > 2) {
|
||||
showAsGrouped = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (showAsGrouped) {
|
||||
for (GroupedEvents.Group group : value.getValue().getGroups()) {
|
||||
mPositionalData.add(new Pair<>(TYPE_GROUPED, group));
|
||||
}
|
||||
} else {
|
||||
for (Event event : value.getValue()) {
|
||||
mPositionalData.add(new Pair<>(TYPE_UNGROUPED, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Map.Entry<String, EventList> value: listsUngrouped.entrySet()) {
|
||||
if (value.getValue().size() > 0)
|
||||
mPositionalData.add(new Triplet<>(TYPE_UNGROUPED, value.getKey(), value.getValue()));
|
||||
if (value.getValue().size() > 0) {
|
||||
mPositionalData.add(new Pair<>(TYPE_HEADER, value.getKey()));
|
||||
for (Event event : value.getValue()) {
|
||||
mPositionalData.add(new Pair<>(TYPE_UNGROUPED, event));
|
||||
}
|
||||
}
|
||||
}
|
||||
if (mPositionalData.size() == 0)
|
||||
mPositionalData.add(new Triplet<>(TYPE_NONE, null, null));
|
||||
mPositionalData.add(new Pair<>(TYPE_NONE, null));
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@@ -92,66 +117,95 @@ class ModDetailEventAdapter extends RecyclerView.Adapter<CustomViewHolder> {
|
||||
public CustomViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
switch (viewType) {
|
||||
case TYPE_NONE:
|
||||
case TYPE_GROUPED:
|
||||
case TYPE_UNGROUPED:
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_all_items, parent, false);
|
||||
return new ItemViewHolder(view);
|
||||
case TYPE_HEADER:
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_all_caption, parent, false);
|
||||
return new StringViewHolder(view);
|
||||
default:
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_all_no_items, parent, false);
|
||||
return new CustomViewHolder(view);
|
||||
default:
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_all_cardview_list, parent, false);
|
||||
return new ListViewHolder(view);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemViewType(int position) {
|
||||
// Note that unlike in ListView adapters, types don't have to be contiguous
|
||||
if (position < mPositionalData.size())
|
||||
return mPositionalData.get(position).first;
|
||||
else return -1;
|
||||
return mPositionalData.get(position).first;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final CustomViewHolder holder, int position) {
|
||||
if (mValue == null || position > mPositionalData.size())
|
||||
return;
|
||||
Triplet<Integer, String, Object> data = mPositionalData.get(position);
|
||||
if (data.first != TYPE_NONE) {
|
||||
ListViewHolder h;
|
||||
ModDetailEventAdapterInner adapter;
|
||||
h = (ListViewHolder) holder;
|
||||
Resources resources = h.mView.getResources();
|
||||
adapter = new ModDetailEventAdapterInner();
|
||||
String title;
|
||||
switch (data.second) {
|
||||
case VALUE_LECTURE:
|
||||
Pair<Integer, Object> data = mPositionalData.get(position);
|
||||
Resources resources = holder.mView.getResources();
|
||||
Context context = holder.mView.getContext();
|
||||
switch (data.first) {
|
||||
case TYPE_HEADER:
|
||||
StringViewHolder s = (StringViewHolder) holder;
|
||||
String title = "";
|
||||
if (VALUE_LECTURE.equals(data.second)) {
|
||||
title = resources.getString(R.string.lecture);
|
||||
break;
|
||||
case VALUE_TUTORIAL:
|
||||
|
||||
} else if (VALUE_TUTORIAL.equals(data.second)) {
|
||||
title = resources.getString(R.string.tutorial);
|
||||
break;
|
||||
case VALUE_EXAM:
|
||||
|
||||
} else if (VALUE_EXAM.equals(data.second)) {
|
||||
title = resources.getString(R.string.exam);
|
||||
break;
|
||||
case VALUE_DEADLINE:
|
||||
|
||||
} else if (VALUE_DEADLINE.equals(data.second)) {
|
||||
title = resources.getString(R.string.deadline);
|
||||
break;
|
||||
case VALUE_OTHER:
|
||||
|
||||
} else if (VALUE_OTHER.equals(data.second)) {
|
||||
title = resources.getString(R.string.others);
|
||||
break;
|
||||
default:
|
||||
title = data.second;
|
||||
}
|
||||
h.mString.setText(title);
|
||||
switch (data.first) {
|
||||
case TYPE_GROUPED:
|
||||
adapter.setData((GroupedEvents) data.third, h.mView.getContext());
|
||||
break;
|
||||
case TYPE_UNGROUPED:
|
||||
adapter.setData((EventList) data.third, h.mView.getContext());
|
||||
break;
|
||||
}
|
||||
h.mList.setAdapter(adapter);
|
||||
}
|
||||
s.mString.setText(title);
|
||||
return;
|
||||
case TYPE_GROUPED:
|
||||
ItemViewHolder ig = (ItemViewHolder) holder;
|
||||
GroupedEvents.Group group = ((GroupedEvents.Group) data.second);
|
||||
long firstDateTime = group.getFirstDate()+group.getStartTime();
|
||||
long lastDateTime = group.getLastDate()+group.getStartTime()+group.getDuration();
|
||||
String start, end, weekday, startTime, endTime;
|
||||
StringBuilder excepts = null;
|
||||
start = UtilsDate.getModifiedDate(firstDateTime);
|
||||
end = UtilsDate.getModifiedDate(lastDateTime);
|
||||
weekday = UtilsDate.getModifiedDate(context, firstDateTime, "E");
|
||||
startTime = UtilsDate.getModifiedTime(context, firstDateTime);
|
||||
endTime = UtilsDate.getModifiedTime(context, lastDateTime);
|
||||
for (long skippedDate : group.getSkippedDates()) {
|
||||
if (excepts == null) {
|
||||
excepts = new StringBuilder(UtilsDate.getModifiedDate(skippedDate));
|
||||
} else {
|
||||
excepts.append(", ").append(UtilsDate.getModifiedDate(skippedDate));
|
||||
}
|
||||
}
|
||||
ig.mTitle.setText(context.getString(R.string.event_scale, weekday, startTime, endTime));
|
||||
ig.mSubLeft.setText(context.getString(R.string.date_scale, start, end));
|
||||
ig.mSubRight.setText(excepts != null ? context.getString(R.string.except_list, excepts.toString()) : "");
|
||||
return;
|
||||
case TYPE_UNGROUPED:
|
||||
ItemViewHolder iu = (ItemViewHolder) holder;
|
||||
Event event = (Event) data.second;
|
||||
String date;
|
||||
if (UtilsDate.dateEquals(event.getStartDate(), System.currentTimeMillis()))
|
||||
start = UtilsDate.getModifiedTime(context, event.getStartDate());
|
||||
else
|
||||
start = UtilsDate.getModifiedDateTime(context, event.getStartDate());
|
||||
if (UtilsDate.dateEquals(event.getStartDate(), event.getEndDate()))
|
||||
end = UtilsDate.getModifiedTime(context, event.getEndDate());
|
||||
else
|
||||
end = UtilsDate.getModifiedDateTime(context, event.getEndDate());
|
||||
date = context.getString(R.string.date_scale, start, end);
|
||||
iu.mTitle.setText(event.getTitle());
|
||||
iu.mSubLeft.setText(date);
|
||||
iu.mSubRight.setText("");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,104 +0,0 @@
|
||||
package de.sebse.fuplanner.fragments.moddetails;
|
||||
|
||||
import android.content.Context;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.services.KVV.types.EventList;
|
||||
import de.sebse.fuplanner.services.KVV.types.GroupedEvents;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||
|
||||
class ModDetailEventAdapterInner extends RecyclerView.Adapter<ItemViewHolder> {
|
||||
private final ArrayList<Entry> mPositionalData;
|
||||
|
||||
ModDetailEventAdapterInner() {
|
||||
mPositionalData = new ArrayList<>();
|
||||
}
|
||||
|
||||
public void setData(GroupedEvents events, final Context context) {
|
||||
mPositionalData.clear();
|
||||
for (GroupedEvents.Group group : events.getGroups()) {
|
||||
long firstDateTime = group.getFirstDate()+group.getStartTime();
|
||||
long lastDateTime = group.getLastDate()+group.getStartTime()+group.getDuration();
|
||||
String start, end, weekday, startTime, endTime;
|
||||
StringBuilder excepts = null;
|
||||
start = UtilsDate.getModifiedDate(firstDateTime);
|
||||
end = UtilsDate.getModifiedDate(lastDateTime);
|
||||
weekday = UtilsDate.getModifiedDate(context, firstDateTime, "E");
|
||||
startTime = UtilsDate.getModifiedTime(context, firstDateTime);
|
||||
endTime = UtilsDate.getModifiedTime(context, lastDateTime);
|
||||
for (long skippedDate : group.getSkippedDates()) {
|
||||
if (excepts == null) {
|
||||
excepts = new StringBuilder(UtilsDate.getModifiedDate(skippedDate));
|
||||
} else {
|
||||
excepts.append(", ").append(UtilsDate.getModifiedDate(skippedDate));
|
||||
}
|
||||
}
|
||||
mPositionalData.add(new Entry(
|
||||
context.getString(R.string.event_scale, weekday, startTime, endTime),
|
||||
context.getString(R.string.date_scale, start, end),
|
||||
excepts != null ? context.getString(R.string.except_list, excepts.toString()) : ""));
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
public void setData(EventList events, final Context context) {
|
||||
mPositionalData.clear();
|
||||
for (Event event : events) {
|
||||
String date;
|
||||
String start, end;
|
||||
if (UtilsDate.dateEquals(event.getStartDate(), System.currentTimeMillis()))
|
||||
start = UtilsDate.getModifiedTime(context, event.getStartDate());
|
||||
else
|
||||
start = UtilsDate.getModifiedDateTime(context, event.getStartDate());
|
||||
if (UtilsDate.dateEquals(event.getStartDate(), event.getEndDate()))
|
||||
end = UtilsDate.getModifiedTime(context, event.getEndDate());
|
||||
else
|
||||
end = UtilsDate.getModifiedDateTime(context, event.getEndDate());
|
||||
date = context.getString(R.string.date_scale, start, end);
|
||||
mPositionalData.add(new Entry(event.getTitle(), date, ""));
|
||||
}
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
View view;
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_all_items, parent, false);
|
||||
return new ItemViewHolder(view);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBindViewHolder(@NonNull final ItemViewHolder holder, int position) {
|
||||
holder.mTitle.setText(mPositionalData.get(position).title);
|
||||
holder.mSubLeft.setText(mPositionalData.get(position).subtitleLeft);
|
||||
holder.mSubRight.setText(mPositionalData.get(position).subtitleRight);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getItemCount() {
|
||||
return mPositionalData.size();
|
||||
}
|
||||
|
||||
private class Entry {
|
||||
private String title;
|
||||
private String subtitleLeft;
|
||||
private String subtitleRight;
|
||||
|
||||
private Entry(String title, String subtitleLeft, String subtitleRight) {
|
||||
this.title = title;
|
||||
this.subtitleLeft = subtitleLeft;
|
||||
this.subtitleRight = subtitleRight;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -83,9 +83,10 @@ public class ModDetailEventFragment extends Fragment {
|
||||
private void refresh(boolean forceRefresh) {
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getKVV().modules().events().recv(mItemPos, success -> {
|
||||
adapter.setModule(success);
|
||||
swipeLayout.setRefreshing(false);
|
||||
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||
adapter.setModule(pair.first);
|
||||
if (pair.second)
|
||||
swipeLayout.setRefreshing(false);
|
||||
}, error -> {
|
||||
swipeLayout.setRefreshing(false);
|
||||
log.e(error);
|
||||
|
||||
@@ -10,7 +10,7 @@ import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
@@ -48,7 +48,7 @@ public class ModDetailFragment extends Fragment implements ModDetailListener {
|
||||
ModDetailFragment fragment = new ModDetailFragment();
|
||||
Bundle args = new Bundle();
|
||||
if (!itemPosition.contains("."))
|
||||
args.putString(ARG_POSITION, itemPosition+"."+0);
|
||||
args.putString(ARG_POSITION, itemPosition+".0");
|
||||
else
|
||||
args.putString(ARG_POSITION, itemPosition);
|
||||
|
||||
|
||||
@@ -12,8 +12,8 @@ import java.util.ArrayList;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Grade;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Grade;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||
|
||||
class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
@@ -36,20 +36,16 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||
this.setModule();
|
||||
}
|
||||
|
||||
public void setModule() {
|
||||
private void setModule() {
|
||||
mPositionalData.clear();
|
||||
mPositionalData.add(new Pair<>(TYPE_TOTAL, SECTION_GRADE));
|
||||
addPositionalListData(getGradesCount(), SECTION_GRADE);
|
||||
for (int i = 0; i < getGradesCount(); i++) {
|
||||
mPositionalData.add(new Pair<>(TYPE_GRADE, SECTION_GRADE +1024*i));
|
||||
}
|
||||
|
||||
this.notifyDataSetChanged();
|
||||
}
|
||||
|
||||
private void addPositionalListData(int count, int category) {
|
||||
for (int i = 0; i < count; i++) {
|
||||
mPositionalData.add(new Pair<>(TYPE_GRADE, category+1024*i));
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
|
||||
@@ -131,6 +127,7 @@ class ModDetailGradebookAdapter extends RecyclerView.Adapter<RecyclerView.ViewHo
|
||||
mGradeMax = view.findViewById(R.id.grade_max);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " '" + mTitle.getText() + " '" + mGrade.getText() + " '" + mGradeMax.getText() + "'";
|
||||
|
||||
@@ -83,9 +83,10 @@ public class ModDetailGradebookFragment extends Fragment {
|
||||
private void refresh(boolean forceRefresh) {
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getKVV().modules().gradebook().recv(mItemPos, success -> {
|
||||
adapter.setModule(success);
|
||||
swipeLayout.setRefreshing(false);
|
||||
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||
adapter.setModule(pair.first);
|
||||
if (pair.second)
|
||||
swipeLayout.setRefreshing(false);
|
||||
}, error -> {
|
||||
swipeLayout.setRefreshing(false);
|
||||
log.e(error);
|
||||
|
||||
@@ -15,16 +15,17 @@ import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.recyclerview.widget.RecyclerView;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
||||
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
||||
import de.sebse.fuplanner.services.kvv.types.Assignment;
|
||||
import de.sebse.fuplanner.services.kvv.types.Event;
|
||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.ui.CustomViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.ItemViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.MailViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.ShortcutViewHolder;
|
||||
import de.sebse.fuplanner.tools.ui.StringViewHolder;
|
||||
|
||||
class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHolder> {
|
||||
@@ -35,6 +36,7 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
private static final int TYPE_ITEM = 2;
|
||||
private static final int TYPE_SHOW_MORE = 3;
|
||||
private static final int TYPE_MAIL = 4;
|
||||
private static final int TYPE_SHORTCUTS = 5;
|
||||
|
||||
@Nullable private final ModDetailListener mListener;
|
||||
|
||||
@@ -53,10 +55,11 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
this.setModule();
|
||||
}
|
||||
|
||||
public void setModule() {
|
||||
private void setModule() {
|
||||
mPositionalData.clear();
|
||||
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.DESCRIPTION));
|
||||
mPositionalData.add(new Pair<>(TYPE_DESCRIPTION, null));
|
||||
mPositionalData.add(new Pair<>(TYPE_SHORTCUTS, null));
|
||||
mPositionalData.add(new Pair<>(TYPE_HEADER, ModulePart.LECTURERS));
|
||||
for (int i = 0; i < mValue.lecturer.size(); i++) {
|
||||
mPositionalData.add(new Pair<>(TYPE_MAIL, ModulePart.LECTURERS+1024*i));
|
||||
@@ -103,6 +106,10 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_all_mails, parent, false);
|
||||
return new MailViewHolder(view);
|
||||
case TYPE_SHORTCUTS:
|
||||
view = LayoutInflater.from(parent.getContext())
|
||||
.inflate(R.layout.list_moddetails_shortcuts, parent, false);
|
||||
return new ShortcutViewHolder(view);
|
||||
default:
|
||||
//noinspection ConstantConditions
|
||||
return null;
|
||||
@@ -214,10 +221,20 @@ class ModDetailOverviewAdapter extends RecyclerView.Adapter<RecyclerView.ViewHol
|
||||
emailIntent.setData(Uri.parse("mailto:"+lecturer.getMail()));
|
||||
emailIntent.putExtra(Intent.EXTRA_SUBJECT, mValue.title);
|
||||
emailIntent.putExtra(Intent.EXTRA_TEXT, defaultText);
|
||||
m.mView.getContext().startActivity(Intent.createChooser(emailIntent, mValue.title));
|
||||
m.mView.getContext().startActivity(emailIntent);
|
||||
});
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case TYPE_SHORTCUTS:
|
||||
ShortcutViewHolder s = (ShortcutViewHolder) holder;
|
||||
s.mLeft.setOnClickListener(view -> {
|
||||
if (mListener != null) mListener.gotoFragmentPart(ModulePart.RESOURCES, -1);
|
||||
});
|
||||
s.mRight.setOnClickListener(view -> {
|
||||
if (mListener != null) mListener.gotoFragmentPart(ModulePart.GRADEBOOK, -1);
|
||||
});
|
||||
break;
|
||||
case TYPE_SHOW_MORE:
|
||||
CustomViewHolder c = (CustomViewHolder) holder;
|
||||
c.mView.setOnClickListener(view -> {
|
||||
|
||||
@@ -3,8 +3,8 @@ package de.sebse.fuplanner.fragments.moddetails;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.KVV.types.Resource;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.TreeViewAdapter;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.TreeViewBinder;
|
||||
@@ -21,7 +21,7 @@ class ModDetailResourceAdapter extends TreeViewAdapter {
|
||||
this.setModule();
|
||||
}
|
||||
|
||||
public void setModule() {
|
||||
private void setModule() {
|
||||
if (mValue == null || mValue.resources == null) {
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -18,9 +18,9 @@ import androidx.recyclerview.widget.RecyclerView;
|
||||
import androidx.swiperefreshlayout.widget.SwipeRefreshLayout;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.ui.Download;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.KVV.types.Resource;
|
||||
import de.sebse.fuplanner.services.kvv.ui.Download;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.DirectoryNodeBinder;
|
||||
@@ -140,16 +140,17 @@ public class ModDetailResourceFragment extends Fragment {
|
||||
private void refresh(boolean forceRefresh) {
|
||||
if (mListener == null)
|
||||
return;
|
||||
mListener.getKVV().modules().assignments().recv(mItemPos, success -> {
|
||||
adapter.setModule(success);
|
||||
swipeLayout.setRefreshing(false);
|
||||
mListener.getKVV().modules().details().recv(mItemPos, pair -> {
|
||||
adapter.setModule(pair.first);
|
||||
if (pair.second)
|
||||
swipeLayout.setRefreshing(false);
|
||||
}, error -> {
|
||||
swipeLayout.setRefreshing(false);
|
||||
log.e(error);
|
||||
}, forceRefresh);
|
||||
}
|
||||
|
||||
Download getDownload() {
|
||||
private Download getDownload() {
|
||||
if (download == null)
|
||||
download = new Download(this::getContext, () -> (MainActivity) getActivity());
|
||||
return download;
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
package de.sebse.fuplanner.services.GoogleAuth;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 07.11.17.
|
||||
*/
|
||||
|
||||
public interface ConnectedListener {
|
||||
void connected();
|
||||
}
|
||||
@@ -1,23 +0,0 @@
|
||||
package de.sebse.fuplanner.services.GoogleAuth;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 06.11.2017.
|
||||
*/
|
||||
|
||||
public class Credentials {
|
||||
private final String username;
|
||||
private final String password;
|
||||
|
||||
public Credentials(String username, String password) {
|
||||
this.username = username;
|
||||
this.password = password;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
public String getPassword() {
|
||||
return password;
|
||||
}
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
package de.sebse.fuplanner.services.GoogleAuth;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 06.11.2017.
|
||||
*/
|
||||
|
||||
public interface CredentialsListener {
|
||||
void onCredentials(Credentials credentials);
|
||||
}
|
||||
@@ -1,224 +0,0 @@
|
||||
package de.sebse.fuplanner.services.GoogleAuth;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.content.IntentSender;
|
||||
import android.util.Log;
|
||||
import android.widget.Toast;
|
||||
|
||||
import com.google.android.gms.auth.api.credentials.Credential;
|
||||
import com.google.android.gms.auth.api.credentials.CredentialRequest;
|
||||
import com.google.android.gms.auth.api.credentials.CredentialsClient;
|
||||
import com.google.android.gms.auth.api.credentials.CredentialsOptions;
|
||||
import com.google.android.gms.common.ConnectionResult;
|
||||
import com.google.android.gms.common.GoogleApiAvailability;
|
||||
import com.google.android.gms.common.api.ApiException;
|
||||
import com.google.android.gms.common.api.CommonStatusCodes;
|
||||
import com.google.android.gms.common.api.ResolvableApiException;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.fragment.app.FragmentActivity;
|
||||
|
||||
import static android.app.Activity.RESULT_OK;
|
||||
|
||||
/**
|
||||
* Created by Sebastian on 06.11.2017.
|
||||
*/
|
||||
|
||||
public class GoogleAuth {
|
||||
// https://developers.google.com/identity/smartlock-passwords/android/retrieve-credentials
|
||||
|
||||
private static final String TAG = "GoogleAuth";
|
||||
private final FragmentActivity activity;
|
||||
private static final String FU_PLANNER_PROVIDER = "FUPlanner";
|
||||
private CredentialsClient mCredentialsClient;
|
||||
private boolean mIsResolving;
|
||||
@Nullable
|
||||
private CredentialsListener mCredentialsListener;
|
||||
private boolean isConnected = false;
|
||||
|
||||
public GoogleAuth(FragmentActivity activity) {
|
||||
this.activity = activity;
|
||||
}
|
||||
|
||||
private void connect() {
|
||||
if (this.isUnavailable()) {
|
||||
Log.d(TAG, "STATUS: Google auth not available!");
|
||||
return;
|
||||
}
|
||||
this.mCredentialsClient = getClient();
|
||||
this.isConnected = true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void getLoginState(final CredentialsListener credentialsListener) {
|
||||
if (this.isUnavailable()) {
|
||||
Log.d(TAG, "STATUS: Google auth not available!");
|
||||
credentialsListener.onCredentials(null);
|
||||
return;
|
||||
}
|
||||
if (!this.isConnected)
|
||||
connect();
|
||||
CredentialRequest request = new CredentialRequest.Builder()
|
||||
.setPasswordLoginSupported(true)
|
||||
.setAccountTypes(FU_PLANNER_PROVIDER)
|
||||
.build();
|
||||
|
||||
|
||||
mCredentialsClient.request(request).addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
// Successfully read the credential without any user interaction, this
|
||||
// means there was only a single credential and the user has auto
|
||||
// sign-in enabled.
|
||||
Credential credential = task.getResult().getCredential();
|
||||
credentialsListener.onCredentials(new Credentials(credential.getId(), credential.getPassword()));
|
||||
return;
|
||||
}
|
||||
|
||||
Exception e = task.getException();
|
||||
if (e instanceof ResolvableApiException) {
|
||||
// This is most likely the case where the user has multiple saved
|
||||
// credentials and needs to pick one. This requires showing UI to
|
||||
// resolve the read request.
|
||||
GoogleAuth.this.mCredentialsListener = credentialsListener;
|
||||
ResolvableApiException rae = (ResolvableApiException) e;
|
||||
resolveResult(rae, RequestCode.RC_READ);
|
||||
return;
|
||||
}
|
||||
|
||||
if (e instanceof ApiException) {
|
||||
ApiException ae = (ApiException) e;
|
||||
if (ae.getStatusCode() == CommonStatusCodes.SIGN_IN_REQUIRED) {
|
||||
// This means only a hint is available, but we are handling that
|
||||
// elsewhere so no need to act here.
|
||||
} else {
|
||||
credentialsListener.onCredentials(null);
|
||||
Log.w(TAG, "Unexpected status code: " + ae.getStatusCode());
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void setLoginState(String username, String password) {
|
||||
if (this.isUnavailable()) {
|
||||
Log.d(TAG, "STATUS: Google auth not available!");
|
||||
Toast.makeText(activity, "Google auth not available!", Toast.LENGTH_SHORT).show();
|
||||
return;
|
||||
}
|
||||
if (!this.isConnected)
|
||||
connect();
|
||||
Credential credential = new Credential.Builder(username)
|
||||
.setPassword(password)
|
||||
.build();
|
||||
mCredentialsClient.save(credential).addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
showToast("Credential saved.");
|
||||
return;
|
||||
}
|
||||
|
||||
Exception e = task.getException();
|
||||
if (e instanceof ResolvableApiException) {
|
||||
// The first time a credential is saved, the user is shown UI
|
||||
// to confirm the action. This requires resolution.
|
||||
ResolvableApiException rae = (ResolvableApiException) e;
|
||||
resolveResult(rae, RequestCode.RC_SAVE);
|
||||
} else {
|
||||
// Save failure cannot be resolved.
|
||||
Log.w(TAG, "Save failed.", e);
|
||||
showToast("Credential Save Failed");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void deleteLoginState(String username, String password) {
|
||||
if (this.isUnavailable()) {
|
||||
Log.d(TAG, "STATUS: Google auth not available!");
|
||||
return;
|
||||
}
|
||||
if (!this.isConnected)
|
||||
connect();
|
||||
Credential credential = new Credential.Builder(username)
|
||||
.setPassword(password)
|
||||
.build();
|
||||
mCredentialsClient.delete(credential).addOnCompleteListener(task -> {
|
||||
if (task.isSuccessful()) {
|
||||
// Credential was deleted successfully
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
private boolean isUnavailable() {
|
||||
return GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(this.activity) != ConnectionResult.SUCCESS;
|
||||
}
|
||||
|
||||
private CredentialsClient getClient() {
|
||||
CredentialsOptions options = new CredentialsOptions.Builder()
|
||||
.forceEnableSaveDialog()
|
||||
.build();
|
||||
return com.google.android.gms.auth.api.credentials.Credentials.getClient(this.activity, options);
|
||||
}
|
||||
|
||||
public void onActivityResult(int requestCode, int resultCode, Intent data) {
|
||||
Log.d(TAG, "onActivityResult:" + requestCode + ":" + resultCode + ":" + data);
|
||||
|
||||
switch (requestCode) {
|
||||
case RequestCode.RC_HINT:
|
||||
// Drop into handling for RC_READ
|
||||
case RequestCode.RC_READ:
|
||||
if (resultCode == RESULT_OK) {
|
||||
boolean isHint = (requestCode == RequestCode.RC_HINT);
|
||||
Credential credential = data.getParcelableExtra(Credential.EXTRA_KEY);
|
||||
if (mCredentialsListener != null)
|
||||
this.mCredentialsListener.onCredentials(new Credentials(credential.getId(), credential.getPassword()));
|
||||
else
|
||||
Log.d(TAG, "No Credentials Listener");
|
||||
} else {
|
||||
if (mCredentialsListener != null)
|
||||
this.mCredentialsListener.onCredentials(null);
|
||||
else
|
||||
Log.d(TAG, "No Credentials Listener");
|
||||
Log.e(TAG, "Credential Read: NOT OK");
|
||||
showToast("Credential Read Failed");
|
||||
}
|
||||
|
||||
mIsResolving = false;
|
||||
break;
|
||||
case RequestCode.RC_SAVE:
|
||||
if (resultCode == RESULT_OK) {
|
||||
Log.d(TAG, "Credential Save: OK");
|
||||
showToast("Credential Save Success");
|
||||
} else {
|
||||
Log.e(TAG, "Credential Save: NOT OK");
|
||||
showToast("Credential Save Failed");
|
||||
}
|
||||
|
||||
mIsResolving = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void resolveResult(ResolvableApiException rae, int requestCode) {
|
||||
// We don't want to fire multiple resolutions at once since that can result
|
||||
// in stacked dialogs after rotation or another similar event.
|
||||
if (mIsResolving) {
|
||||
Log.w(TAG, "resolveResult: already resolving.");
|
||||
return;
|
||||
}
|
||||
|
||||
Log.d(TAG, "Resolving: " + rae);
|
||||
try {
|
||||
rae.startResolutionForResult(this.activity, requestCode);
|
||||
mIsResolving = true;
|
||||
} catch (IntentSender.SendIntentException e) {
|
||||
Log.e(TAG, "STATUS: Failed to send resolution.", e);
|
||||
}
|
||||
}
|
||||
|
||||
/** Display a short Toast message **/
|
||||
private void showToast(String msg) {
|
||||
Toast.makeText(this.activity, msg, Toast.LENGTH_SHORT).show();
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
package de.sebse.fuplanner.services.GoogleAuth;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 07.11.17.
|
||||
*/
|
||||
|
||||
class RequestCode {
|
||||
public static final int RC_SAVE = 1;
|
||||
public static final int RC_HINT = 2;
|
||||
public static final int RC_READ = 3;
|
||||
}
|
||||
@@ -1,20 +0,0 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
|
||||
import com.android.volley.NetworkResponse;
|
||||
|
||||
import de.sebse.fuplanner.services.GoogleAuth.Credentials;
|
||||
import de.sebse.fuplanner.services.KVV.types.LoginToken;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
public interface KVVListener {
|
||||
void getCredentials(NetworkCallback<Credentials> callback, NetworkErrorCallback error);
|
||||
|
||||
void onLogin(LoginToken token, boolean enteringOnlineMode);
|
||||
|
||||
void onLogout();
|
||||
|
||||
void onModuleListChange();
|
||||
|
||||
void onKVVNetworkResponse(NetworkResponse error);
|
||||
}
|
||||
@@ -1,444 +0,0 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
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 {
|
||||
private KVVListener mListener;
|
||||
@Nullable private LoginToken mToken;
|
||||
private boolean mLoginPending = false;
|
||||
private boolean mOnlineMode = false;
|
||||
|
||||
Login(KVVListener listener, Context context) {
|
||||
super(context);
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public void doOnlineLogin(@NotNull String username, @NotNull String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback errorCallback) {
|
||||
if (mLoginPending) {
|
||||
errorCallback.onError(new NetworkError(100160, -1, "Login already pending!"));
|
||||
}
|
||||
mLoginPending = true;
|
||||
doLogin(username, password, token -> {
|
||||
testLoginToken(token, token2 -> {
|
||||
setToken(token2, true);
|
||||
mLoginPending = false;
|
||||
callback.onResponse(token2);
|
||||
}, error -> {
|
||||
mLoginPending = false;
|
||||
errorCallback.onError(error);
|
||||
});
|
||||
}, error -> {
|
||||
mLoginPending = false;
|
||||
errorCallback.onError(error);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean restoreOnlineLogin() {
|
||||
return restoreLogin(true);
|
||||
}
|
||||
|
||||
public boolean doOfflineLogin() {
|
||||
return restoreLogin(false);
|
||||
}
|
||||
|
||||
private boolean restoreLogin(boolean enteringOnlineMode) {
|
||||
if (mLoginPending || mToken != null)
|
||||
return false;
|
||||
mLoginPending = true;
|
||||
boolean result = false;
|
||||
try {
|
||||
result = setToken(LoginToken.load(getContext()), enteringOnlineMode);
|
||||
} catch (FileNotFoundException ignored) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
mLoginPending = false;
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean isOfflineStoredAvailable() {
|
||||
try {
|
||||
LoginToken load = LoginToken.load(getContext());
|
||||
return load != null;
|
||||
} catch (FileNotFoundException ignored) {
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ClassNotFoundException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean logout(boolean delete) {
|
||||
if (mLoginPending)
|
||||
return false;
|
||||
if (mToken == null)
|
||||
return true;
|
||||
if (delete)
|
||||
mToken.delete(getContext());
|
||||
mToken = null;
|
||||
return handleCallbacks();
|
||||
}
|
||||
|
||||
public boolean isLoginPending() {
|
||||
return mLoginPending;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
return mToken != null;
|
||||
}
|
||||
|
||||
public boolean isInOfflineMode() {
|
||||
return isLoggedIn() && !mOnlineMode;
|
||||
}
|
||||
|
||||
public boolean isInOnlineMode() {
|
||||
return isLoggedIn() && mOnlineMode;
|
||||
}
|
||||
|
||||
void testLoginToken(@NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||
if (mToken == null) {
|
||||
errorCallback.onError(new NetworkError(100173, -1, "Not logged in!"));
|
||||
return;
|
||||
}
|
||||
testLoginToken(mToken, callback, errorCallback);
|
||||
}
|
||||
|
||||
private void testLoginToken(@NotNull LoginToken token, @NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||
get(String.format("https://kvv.imp.fu-berlin.de/direct/profile/%s.json", token.getUsername()), token.getCookies(), response -> {
|
||||
String body = response.getParsed();
|
||||
if (body == null) {
|
||||
errorCallback.onError(new NetworkError(100172, 403, "Testing login failed!"));
|
||||
return;
|
||||
}
|
||||
try {
|
||||
JSONObject json = new JSONObject(body);
|
||||
String displayName = json.getString("displayName");
|
||||
String email = json.getString("email");
|
||||
token.setAdditionals(displayName, email);
|
||||
callback.onResponse(token);
|
||||
} catch (JSONException e) {
|
||||
errorCallback.onError(new NetworkError(100171, 403, "Cannot parse profile!"));
|
||||
}
|
||||
}, error -> errorCallback.onError(new NetworkError(100170, error.networkResponse.statusCode, "Testing login failed!")));
|
||||
}
|
||||
|
||||
@Nullable public LoginToken getLoginToken() {
|
||||
return mToken;
|
||||
}
|
||||
|
||||
void refreshLogin(NetworkCallback<LoginToken> success, NetworkErrorCallback error) {
|
||||
mListener.getCredentials(credentials -> {
|
||||
doOnlineLogin(credentials.getUsername(), credentials.getPassword(), success, error);
|
||||
}, e -> {
|
||||
logout(false);
|
||||
error.onError(e);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean handleCallbacks() {
|
||||
if (mToken != null) {
|
||||
mListener.onLogin(mToken, mOnlineMode);
|
||||
return true;
|
||||
} else {
|
||||
mListener.onLogout();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setToken(@Nullable LoginToken token, boolean enteringOnlineMode) {
|
||||
if (token == null)
|
||||
return false;
|
||||
boolean isOnlyRefresh = mToken != null;
|
||||
mToken = token;
|
||||
if (enteringOnlineMode) {
|
||||
try {
|
||||
mToken.save(getContext());
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
mOnlineMode = enteringOnlineMode;
|
||||
return isOnlyRefresh || handleCallbacks();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
private void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
|
||||
startKVVSession(success -> {
|
||||
String kvvJSESSIONID = success.get("JSESSIONID");
|
||||
getSAMLRequest(kvvJSESSIONID, success1 -> startIdentSession(success1.get("Location"), success11 -> {
|
||||
String identJSESSIONID = success11.get("JSESSIONID");
|
||||
String ident_idp_authn_lc_key = success11.get("_idp_authn_lc_key");
|
||||
String identROUTEID = success11.get("ROUTEID");
|
||||
loginIdent(true, username, password, identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, success111 -> loginIdent(false, username, password, identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, success11112 -> {
|
||||
String ident_idp_session = success11112.get("_idp_session");
|
||||
getSAMLResponse(identJSESSIONID, ident_idp_authn_lc_key, identROUTEID, ident_idp_session, success1111 -> loginKVV(success1111.get("RelayState"), success1111.get("SAMLResponse"), kvvJSESSIONID, success111112 -> {
|
||||
LoginToken token = new LoginToken(username, success111112.get("shibsessionKey"), success111112.get("shibsessionName"), kvvJSESSIONID);
|
||||
finishKVVlogin(token, success11111 -> callback.onResponse(token), error);
|
||||
}, error), error);
|
||||
}, error), error);
|
||||
}, error), error);
|
||||
}, error);
|
||||
}
|
||||
|
||||
/*
|
||||
GET https://kvv.imp.fu-berlin.de/portal/login
|
||||
-> JSESSIONID 5c10406f-588c-4c16-96e9-c80d115417de.tomcat1
|
||||
*/
|
||||
private void startKVVSession(final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||
get("https://kvv.imp.fu-berlin.de/portal/login", null, response -> {
|
||||
String cookies = response.getHeaders().get("Set-Cookie");
|
||||
if (cookies==null) {
|
||||
errorCallback.onError(new NetworkError(100101, -1, "Error on starting KVV session!"));
|
||||
return;
|
||||
}
|
||||
HashMap<String, String> object;
|
||||
try {
|
||||
object = getCookie(cookies, new String[]{"JSESSIONID"});
|
||||
} catch (NoSuchFieldException e) {
|
||||
errorCallback.onError(new NetworkError(100102, -1, "Error on starting KVV session!"));
|
||||
return;
|
||||
}
|
||||
callback.onResponse(object);
|
||||
}, error -> errorCallback.onError(new NetworkError(100100, error.networkResponse.statusCode, "Error on starting KVV session!")));
|
||||
}
|
||||
|
||||
/*
|
||||
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container
|
||||
<- JSESSIONID
|
||||
-> (Location-Header) https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
|
||||
?SAMLRequest=fZLLb.....Q8yre3X1IHwkJKE0Mnpy/V9TH4A
|
||||
&RelayState=ss:mem:7ea01e29157b8bd906f7002176.....0d1a505f2c8bf
|
||||
*/
|
||||
private void getSAMLRequest(String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||
HashMap<String, String> cookies = new HashMap<>();
|
||||
cookies.put("JSESSIONID", JSESSIONID);
|
||||
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", cookies, response -> {
|
||||
String location = response.getHeaders().get("Location");
|
||||
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!")));
|
||||
}
|
||||
|
||||
/*
|
||||
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
|
||||
?SAMLRequest=fZLLbsIwEEV/JfI+cWJAUIsgpbAoEi2IpF10UznxUKw6dupxaPn7hkdb2LD29bkzRzNGUeuGZ63fmjV8toA++K61QX58SEnrDLcCFXIjakDuK55njwvOopg3znpbWU2CDBGcV9ZMrcG2BpeD26kKnteLlGy9b5BT+rHbRapuok0bluC0MpEEmm9VWVoNfhshWnpgM7pa5gUJZt0wyogD9h+iJBiv/P6aomQTbtqSdhNtlIYzZg1SOag8zfMlCeazlLyNqpHsy1gO2V1fVsNBMuqJoUyAJaxXDUaiiyG2MDfohfEpYXEyDJM4ZKxgCe/FPI5fSbA6L36vjFTm/bal8hRC/lAUq/C02gs4PK7VBchkfHDNj8Xuwv5trPhVTiY3BeOf4DG96DmVNvypA89nK6tVtQ8yre3X1IHwkJKE0Mnpy/V9TH4A
|
||||
&RelayState=ss:mem:7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
|
||||
-> JSESSIONID C4B6A428BA1F50746235D03F5D107A57
|
||||
-> _idp_authn_lc_key 57a6ae26067f374cc3d0ccfc47e27b04b47752d2a3d4eb2782af0d3994535395
|
||||
-> ROUTEID .1
|
||||
*/
|
||||
private void startIdentSession(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 Ident session!"));
|
||||
return;
|
||||
}
|
||||
HashMap<String, String> object;
|
||||
try {
|
||||
object = getCookie(cookies, new String[]{"JSESSIONID", "_idp_authn_lc_key", "ROUTEID"});
|
||||
} catch (NoSuchFieldException e) {
|
||||
errorCallback.onError(new NetworkError(100122, -1, "Error on starting Ident session!"));
|
||||
return;
|
||||
}
|
||||
callback.onResponse(object);
|
||||
}, error -> errorCallback.onError(new NetworkError(100120, error.networkResponse.statusCode, "Error on starting Ident session!")));
|
||||
}
|
||||
|
||||
/*
|
||||
POST https://identity.fu-berlin.de/idp-fub/Authn/UserPassword
|
||||
<- j_username seedorf96
|
||||
<- j_password neinhieristpatrick
|
||||
<- (Header-"Content-Type") application/x-www-form-urlencoded
|
||||
<- JSESSIONID
|
||||
<- _idp_authn_lc_key
|
||||
<- ROUTEID
|
||||
-> _idp_session OTMuMTkzLjg1LjMz|LQ==|OGYxOWI4MjA2NTQ4YWUwYzJkOWM4Mjk4YzcwZDMwZmJiZjBmMTdmMzkyZGU2OWIwY2JkNmZlNjlmNTRmNzBlMQ==|wLlzQal7VqyntmG2vLNn06wt8wQ=
|
||||
*/
|
||||
private void loginIdent(final boolean first, String username, String password, String JSESSIONID, String _idp_authn_lc_key, String ROUTEID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||
HashMap<String, String> cookies = new HashMap<>();
|
||||
cookies.put("JSESSIONID", JSESSIONID);
|
||||
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key);
|
||||
cookies.put("ROUTEID", ROUTEID);
|
||||
HashMap<String, String> body = new HashMap<>();
|
||||
body.put("j_username", username);
|
||||
body.put("j_password", password);
|
||||
post("https://identity.fu-berlin.de/idp-fub/Authn/UserPassword", cookies, body, response -> {
|
||||
if (first) {
|
||||
callback.onResponse(new HashMap<>());
|
||||
return;
|
||||
}
|
||||
|
||||
String cookies1 = response.getHeaders().get("Set-Cookie");
|
||||
if (cookies1 ==null) {
|
||||
errorCallback.onError(new NetworkError(100131, -1, "Error on logging in to Identity Server!"));
|
||||
return;
|
||||
}
|
||||
HashMap<String, String> object;
|
||||
try {
|
||||
object = getCookie(cookies1, new String[]{"_idp_session"});
|
||||
} catch (NoSuchFieldException e) {
|
||||
errorCallback.onError(new NetworkError(100132, -1, "Error on logging in to Identity Server!"));
|
||||
return;
|
||||
}
|
||||
callback.onResponse(object);
|
||||
}, error -> errorCallback.onError(new NetworkError(100130, error.networkResponse.statusCode, "Error on logging in to Identity Server!")));
|
||||
}
|
||||
|
||||
/*
|
||||
GET https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO
|
||||
<- JSESSIONID
|
||||
<- _idp_authn_lc_key
|
||||
<- ROUTEID
|
||||
<- _idp_session
|
||||
-> (BODY) RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
|
||||
-> (BODY) SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg==
|
||||
*/
|
||||
private void getSAMLResponse(String JSESSIONID, String _idp_authn_lc_key, String ROUTEID, String _idp_session, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||
HashMap<String, String> cookies = new HashMap<>();
|
||||
cookies.put("JSESSIONID", JSESSIONID);
|
||||
cookies.put("_idp_authn_lc_key", _idp_authn_lc_key);
|
||||
cookies.put("ROUTEID", ROUTEID);
|
||||
cookies.put("_idp_session", _idp_session);
|
||||
get("https://identity.fu-berlin.de/idp-fub/profile/SAML2/Redirect/SSO", cookies, response -> {
|
||||
String body = response.getParsed();
|
||||
if (body == null) {
|
||||
errorCallback.onError(new NetworkError(100143, -1, "Error on getting SAML response!"));
|
||||
return;
|
||||
}
|
||||
|
||||
HashMap<String, String> object = new HashMap<>();
|
||||
|
||||
Pattern pattern = Pattern.compile("ss:mem:([0-9a-f]+)");
|
||||
Matcher matcher = pattern.matcher(body);
|
||||
if (!matcher.find()) {
|
||||
errorCallback.onError(new NetworkError(100142, -1, "Error on getting SAML response!"));
|
||||
return;
|
||||
}
|
||||
object.put("RelayState", "ss:mem:"+matcher.group(1));
|
||||
|
||||
pattern = Pattern.compile("name=\"SAMLResponse\" value=\"([0-9a-zA-Z+]+=*)");
|
||||
matcher = pattern.matcher(body);
|
||||
if (!matcher.find()) {
|
||||
errorCallback.onError(new NetworkError(100141, -1, "Error on getting SAML response!"));
|
||||
return;
|
||||
}
|
||||
object.put("SAMLResponse", matcher.group(1));
|
||||
|
||||
callback.onResponse(object);
|
||||
}, error -> errorCallback.onError(new NetworkError(100140, error.networkResponse.statusCode, "Error on getting SAML response!")));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
POST https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST
|
||||
<- RelayState 7ea01e29157b8bd906f7002176213b6db5e1f45ebb88716a9820d1a505f2c8bf
|
||||
<- SAMLResponse PD94bWwgdmVyc2lvbj0...........wvc2FtbDJwOlJlc3BvbnNlPg==
|
||||
<- JSESSIONID
|
||||
-> _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
|
||||
_b1912c5a03d733a80bd3fee772bf68d4
|
||||
*/
|
||||
private void loginKVV(String RelayState, String SAMLResponse, String JSESSIONID, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||
HashMap<String, String> cookies = new HashMap<>();
|
||||
cookies.put("JSESSIONID", JSESSIONID);
|
||||
HashMap<String, String> body = new HashMap<>();
|
||||
body.put("RelayState", RelayState);
|
||||
body.put("SAMLResponse", SAMLResponse);
|
||||
post("https://kvv.imp.fu-berlin.de/Shibboleth.sso/SAML2/POST", cookies, body, response -> {
|
||||
String cookies1 = response.getHeaders().get("Set-Cookie");
|
||||
if (cookies1 ==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(cookies1);
|
||||
if (!matcher.find()) {
|
||||
errorCallback.onError(new NetworkError(100152, -1, "Error on starting Ident 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 Ident session!")));
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
GET https://kvv.imp.fu-berlin.de/sakai-login-tool/container
|
||||
<- JSESSIONID
|
||||
<- _shibsession_64656661756c7468747470733a2f2f6b76762e696d702e66752d6265726c696e2e64652f73686962626f6c657468
|
||||
_b1912c5a03d733a80bd3fee772bf68d4
|
||||
*/
|
||||
private void finishKVVlogin(LoginToken loginToken, final NetworkCallback<HashMap<String, String>> callback, final NetworkErrorCallback errorCallback) {
|
||||
get("https://kvv.imp.fu-berlin.de/sakai-login-tool/container", loginToken.getCookies(), response -> callback.onResponse(new HashMap<>()), error -> errorCallback.onError(new NetworkError(100160, error.networkResponse.statusCode, "Cannot finish login process!")));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
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,117 +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 androidx.annotation.Nullable;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 29.10.17.
|
||||
*/
|
||||
|
||||
public class LoginToken implements Serializable {
|
||||
private static final String FILE_NAME = "LoginTokenSaving";
|
||||
|
||||
private final String username;
|
||||
private final String shibsessionKey;
|
||||
private final String shibsessionName;
|
||||
private final String JSESSIONID;
|
||||
@Nullable private String fullName;
|
||||
@Nullable private String email;
|
||||
|
||||
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
||||
this.username = username;
|
||||
this.shibsessionKey = shibsessionKey;
|
||||
this.shibsessionName = shibsessionName;
|
||||
this.JSESSIONID = JSESSIONID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static LoginToken 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 LoginToken))
|
||||
return null;
|
||||
LoginToken loginToken = (LoginToken) readObject;
|
||||
is.close();
|
||||
fis.close();
|
||||
return loginToken;
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
public void delete(Context context) {
|
||||
context.deleteFile(FILE_NAME);
|
||||
}
|
||||
|
||||
public void setAdditionals(String fullName, String email) {
|
||||
this.fullName = fullName;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
private String getShibsessionKey() {
|
||||
return shibsessionKey;
|
||||
}
|
||||
|
||||
private String getShibsessionName() {
|
||||
return shibsessionName;
|
||||
}
|
||||
|
||||
private String getJSESSIONID() {
|
||||
return JSESSIONID;
|
||||
}
|
||||
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getCookies() {
|
||||
HashMap<String, String> cookies = new HashMap<>();
|
||||
cookies.put("JSESSIONID", getJSESSIONID());
|
||||
cookies.put(getShibsessionKey(), getShibsessionName());
|
||||
cookies.put("pasystem_timezone_ok", "true");
|
||||
return cookies;
|
||||
}
|
||||
|
||||
public boolean isSameUser(String username) {
|
||||
return this.getUsername().equals(username);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
HashMap<String, String> cookies = this.getCookies();
|
||||
for (String header: cookies.keySet()) {
|
||||
result.append(header).append("=").append(cookies.get(header)).append(";");
|
||||
}
|
||||
return result.substring(0, result.length()-1);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen;
|
||||
package de.sebse.fuplanner.services.canteen;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -8,12 +8,11 @@ import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Canteens;
|
||||
import de.sebse.fuplanner.services.Canteen.types.Day;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteen;
|
||||
import de.sebse.fuplanner.services.canteen.types.CanteenListener;
|
||||
import de.sebse.fuplanner.services.canteen.types.Canteens;
|
||||
import de.sebse.fuplanner.services.canteen.types.Day;
|
||||
import de.sebse.fuplanner.tools.AsyncQueue;
|
||||
import de.sebse.fuplanner.tools.MainActivityListener;
|
||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
@@ -23,15 +22,15 @@ public class CanteenBrowser extends HTTPService {
|
||||
private Canteens canteens;
|
||||
private final AsyncQueue queue = new AsyncQueue();
|
||||
private final Context context;
|
||||
private MainActivityListener mListener;
|
||||
private CanteenListener mListener;
|
||||
|
||||
public CanteenBrowser(Context context) {
|
||||
super(context);
|
||||
this.context = context;
|
||||
if (context instanceof MainActivityListener)
|
||||
mListener = (MainActivity) context;
|
||||
if (context instanceof CanteenListener)
|
||||
mListener = (CanteenListener) context;
|
||||
else
|
||||
throw new RuntimeException(context.toString() + " must implement MainActivityListener");
|
||||
throw new RuntimeException(context.toString() + " must implement CanteenListener");
|
||||
try {
|
||||
this.canteens = Canteens.load(context);
|
||||
} catch (IOException e) {
|
||||
@@ -206,7 +205,6 @@ public class CanteenBrowser extends HTTPService {
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
log.d(body);
|
||||
errorCallback.onError(new NetworkError(201302, 403, "Cannot parse meal list!"));
|
||||
return;
|
||||
}
|
||||
@@ -225,14 +223,14 @@ public class CanteenBrowser extends HTTPService {
|
||||
private<T> NetworkCallback<T> saveOnCallback(NetworkCallback<T> callback, boolean forceRefresh){
|
||||
return (success -> {
|
||||
if (forceRefresh)
|
||||
mListener.onRefreshCompleted(false);
|
||||
mListener.onCanteenRefreshCompleted(false);
|
||||
callback.onResponse(success);
|
||||
});
|
||||
}
|
||||
|
||||
private NetworkErrorCallback errorOnCallback(NetworkErrorCallback errorCallback){
|
||||
return (error -> {
|
||||
mListener.onRefreshCompleted(true);
|
||||
mListener.onCanteenRefreshCompleted(true);
|
||||
errorCallback.onError(error);
|
||||
});
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -121,6 +121,7 @@ public class Canteen implements Serializable, Iterable<Day> {
|
||||
return lng;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return id+": "+name+"\n"+list.toString()+"\n";
|
||||
@@ -0,0 +1,5 @@
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
public interface CanteenListener {
|
||||
void onCanteenRefreshCompleted(boolean b);
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
@@ -94,6 +94,7 @@ public class Canteens implements Serializable, Iterable<Canteen> {
|
||||
context.deleteFile(FILE_NAME);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.list.toString();
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
@@ -58,6 +58,7 @@ public class Day implements Serializable, Iterable<Meal> {
|
||||
return canteenId;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return Canteen.calendarToKey(getCalendar())+"\n"+this.list+"\n";
|
||||
@@ -1,10 +1,12 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class Meal implements Serializable {
|
||||
private static final int LIGHT_NONE = 0;
|
||||
private static final int LIGHT_GREEN = 1;
|
||||
@@ -112,6 +114,7 @@ public class Meal implements Serializable {
|
||||
return certificates;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return name + " (" + category + ")";
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import de.sebse.fuplanner.tools.SortedList;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import java.util.Calendar;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.Canteen.types;
|
||||
package de.sebse.fuplanner.services.canteen.types;
|
||||
|
||||
import de.sebse.fuplanner.tools.SortedList;
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.sebse.fuplanner.services.fulogin;
|
||||
|
||||
public class AccountGeneral {
|
||||
public static final String ACCOUNT_TYPE = "de.sebse.fuplanner.fuauth";
|
||||
public static final String AUTHTOKEN_TYPE_KVV = "KVV";
|
||||
public static final String AUTHTOKEN_TYPE_BLACKBOARD = "Blackboard";
|
||||
public static final long SYNC_INTERVAL = 6 * 60 * 60; // defined in seconds
|
||||
}
|
||||
@@ -0,0 +1,104 @@
|
||||
package de.sebse.fuplanner.services.fulogin;
|
||||
|
||||
import android.accounts.AbstractAccountAuthenticator;
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountAuthenticatorResponse;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import java.util.concurrent.ExecutionException;
|
||||
|
||||
public class FUAuthenticator extends AbstractAccountAuthenticator {
|
||||
|
||||
private final Context mContext;
|
||||
|
||||
public FUAuthenticator(Context context) {
|
||||
super(context);
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle editProperties(AccountAuthenticatorResponse accountAuthenticatorResponse, String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle addAccount(AccountAuthenticatorResponse response, String accountType, String authTokenType, String[] requiredFeatures, Bundle options) throws NetworkErrorException {
|
||||
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, accountType);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_IS_ADDING_NEW_ACCOUNT, true);
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle confirmCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, Bundle bundle) throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle getAuthToken(AccountAuthenticatorResponse response, Account account, String authTokenType, Bundle options) throws NetworkErrorException {
|
||||
|
||||
// Extract the username and password from the Account Manager, and ask
|
||||
// the server for an appropriate AuthToken.
|
||||
final AccountManager am = AccountManager.get(mContext);
|
||||
|
||||
String authToken = am.peekAuthToken(account, authTokenType);
|
||||
|
||||
// Lets give another try to authenticate the user
|
||||
if (TextUtils.isEmpty(authToken)) {
|
||||
final String password = am.getPassword(account);
|
||||
if (password != null) {
|
||||
try {
|
||||
authToken = new UserLoginTask(account.name, password, authTokenType, mContext).execute((Void) null).get();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
} catch (ExecutionException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// If we get an authToken - we return it
|
||||
if (!TextUtils.isEmpty(authToken)) {
|
||||
final Bundle result = new Bundle();
|
||||
result.putString(AccountManager.KEY_ACCOUNT_NAME, account.name);
|
||||
result.putString(AccountManager.KEY_ACCOUNT_TYPE, account.type);
|
||||
result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
|
||||
return result;
|
||||
}
|
||||
|
||||
// If we get here, then we couldn't access the user's password - so we
|
||||
// need to re-prompt them for their credentials. We do that by creating
|
||||
// an intent to display our AuthenticatorActivity.
|
||||
final Intent intent = new Intent(mContext, FUAuthenticatorActivity.class);
|
||||
intent.putExtra(AccountManager.KEY_ACCOUNT_AUTHENTICATOR_RESPONSE, response);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_ACCOUNT_TYPE, account.type);
|
||||
intent.putExtra(FUAuthenticatorActivity.ARG_AUTH_TYPE, authTokenType);
|
||||
final Bundle bundle = new Bundle();
|
||||
bundle.putParcelable(AccountManager.KEY_INTENT, intent);
|
||||
return bundle;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getAuthTokenLabel(String s) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle updateCredentials(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String s, Bundle bundle) throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Bundle hasFeatures(AccountAuthenticatorResponse accountAuthenticatorResponse, Account account, String[] strings) throws NetworkErrorException {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,281 @@
|
||||
package de.sebse.fuplanner.services.fulogin;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountAuthenticatorActivity;
|
||||
import android.accounts.AccountManager;
|
||||
import android.animation.Animator;
|
||||
import android.animation.AnimatorListenerAdapter;
|
||||
import android.annotation.TargetApi;
|
||||
import android.app.LoaderManager.LoaderCallbacks;
|
||||
import android.content.Context;
|
||||
import android.content.CursorLoader;
|
||||
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.Bundle;
|
||||
import android.provider.ContactsContract;
|
||||
import android.text.TextUtils;
|
||||
import android.view.View;
|
||||
import android.view.inputmethod.EditorInfo;
|
||||
import android.view.inputmethod.InputMethodManager;
|
||||
import android.widget.Button;
|
||||
import android.widget.EditText;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.R;
|
||||
|
||||
import static de.sebse.fuplanner.services.fulogin.UserLoginTask.PARAM_USER_PASS;
|
||||
|
||||
/**
|
||||
* A login screen that offers login via email/password.
|
||||
*/
|
||||
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.
|
||||
*/
|
||||
UserLoginTask mAuthTask = null;
|
||||
|
||||
// UI references.
|
||||
private EditText mEmailView;
|
||||
EditText mPasswordView;
|
||||
private View mProgressView;
|
||||
private View mLoginFormView;
|
||||
|
||||
|
||||
|
||||
public static final String ARG_ACCOUNT_TYPE = "ARG_ACCOUNT_TYPE";
|
||||
public static final String ARG_AUTH_TYPE = "ARG_AUTH_TYPE";
|
||||
public static final String ARG_IS_ADDING_NEW_ACCOUNT = "ARG_IS_ADDING_NEW_ACCOUNT";
|
||||
private String mAccountType;
|
||||
private String mAuthTokenType;
|
||||
private boolean mIsAddingNewAccount;
|
||||
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
mAccountType = getIntent().getStringExtra(ARG_ACCOUNT_TYPE);
|
||||
mAuthTokenType = getIntent().getStringExtra(ARG_AUTH_TYPE);
|
||||
mIsAddingNewAccount = getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false);
|
||||
|
||||
setContentView(R.layout.activity_fu_authenticator);
|
||||
// Set up the login form.
|
||||
mEmailView = findViewById(R.id.input_username);
|
||||
populateAutoComplete();
|
||||
|
||||
mPasswordView = findViewById(R.id.input_password);
|
||||
mPasswordView.setOnEditorActionListener((textView, id, keyEvent) -> {
|
||||
if (id == EditorInfo.IME_ACTION_DONE || id == EditorInfo.IME_NULL) {
|
||||
attemptLogin();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
Button mEmailSignInButton = findViewById(R.id.btn_login);
|
||||
mEmailSignInButton.setOnClickListener(view -> attemptLogin());
|
||||
|
||||
mLoginFormView = findViewById(R.id.login_form);
|
||||
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.
|
||||
* If there are form errors (invalid email, missing fields, etc.), the
|
||||
* errors are presented and no actual login attempt is made.
|
||||
*/
|
||||
private void attemptLogin() {
|
||||
InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
|
||||
if (inputManager != null && getCurrentFocus() != null)
|
||||
inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
|
||||
if (mAuthTask != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Reset errors.
|
||||
mEmailView.setError(null);
|
||||
mPasswordView.setError(null);
|
||||
|
||||
// Store values at the time of the login attempt.
|
||||
String email = mEmailView.getText().toString();
|
||||
String password = mPasswordView.getText().toString();
|
||||
|
||||
boolean cancel = false;
|
||||
View focusView = null;
|
||||
|
||||
// Check for a valid password, if the user entered one.
|
||||
if (!TextUtils.isEmpty(password) && !isPasswordValid(password)) {
|
||||
mPasswordView.setError(getString(R.string.error_invalid_password));
|
||||
focusView = mPasswordView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
// Check for a valid email address.
|
||||
if (TextUtils.isEmpty(email)) {
|
||||
mEmailView.setError(getString(R.string.error_field_required));
|
||||
focusView = mEmailView;
|
||||
cancel = true;
|
||||
}
|
||||
|
||||
if (cancel) {
|
||||
// There was an error; don't attempt login and focus the first
|
||||
// form field with an error.
|
||||
focusView.requestFocus();
|
||||
} else {
|
||||
// Show a progress spinner, and kick off a background task to
|
||||
// perform the user login attempt.
|
||||
showProgress(true);
|
||||
mAuthTask = new UserLoginTask(email, password, mAuthTokenType, this);
|
||||
mAuthTask.execute((Void) null);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isPasswordValid(String password) {
|
||||
//TODO: Replace this with your own logic
|
||||
return password.length() > 4;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shows the progress UI and hides the login form.
|
||||
*/
|
||||
@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
|
||||
void showProgress(final boolean show) {
|
||||
// On Honeycomb MR2 we have the ViewPropertyAnimator APIs, which allow
|
||||
// for very easy animations. If available, use these APIs to fade-in
|
||||
// the progress spinner.
|
||||
int shortAnimTime = getResources().getInteger(android.R.integer.config_shortAnimTime);
|
||||
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
mLoginFormView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 0 : 1).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mLoginFormView.setVisibility(show ? View.GONE : View.VISIBLE);
|
||||
}
|
||||
});
|
||||
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
mProgressView.animate().setDuration(shortAnimTime).alpha(
|
||||
show ? 1 : 0).setListener(new AnimatorListenerAdapter() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
mProgressView.setVisibility(show ? View.VISIBLE : View.GONE);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@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) {
|
||||
String accountName = intent.getStringExtra(AccountManager.KEY_ACCOUNT_NAME);
|
||||
String accountPassword = intent.getStringExtra(PARAM_USER_PASS);
|
||||
final Account account = new Account(accountName, intent.getStringExtra(AccountManager.KEY_ACCOUNT_TYPE));
|
||||
final AccountManager mAccountManager = AccountManager.get(this);
|
||||
|
||||
if (getIntent().getBooleanExtra(ARG_IS_ADDING_NEW_ACCOUNT, false)) {
|
||||
String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
|
||||
String authtokenType = mAuthTokenType;
|
||||
|
||||
// Creating the account on the device and setting the auth token we got
|
||||
// (Not setting the auth token will cause another call to the server to authenticate the user)
|
||||
mAccountManager.addAccountExplicitly(account, accountPassword, null);
|
||||
mAccountManager.setAuthToken(account, authtokenType, authtoken);
|
||||
} else {
|
||||
mAccountManager.setPassword(account, accountPassword);
|
||||
}
|
||||
|
||||
setAccountAuthenticatorResult(intent.getExtras());
|
||||
setResult(RESULT_OK, intent);
|
||||
finish();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,13 @@
|
||||
package de.sebse.fuplanner.services.fulogin;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class FUAuthenticatorService extends Service {
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
FUAuthenticator authenticator = new FUAuthenticator(this);
|
||||
return authenticator.getIBinder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package de.sebse.fuplanner.services.fulogin;
|
||||
|
||||
import android.accounts.AccountManager;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.AsyncTask;
|
||||
import android.os.Build;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||
import de.sebse.fuplanner.services.kvv.sync.Login;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
|
||||
/**
|
||||
* Represents an asynchronous login/registration task used to authenticate
|
||||
* the user.
|
||||
*/
|
||||
public class UserLoginTask extends AsyncTask<Void, Void, String> {
|
||||
|
||||
/**
|
||||
* A dummy authentication store containing known user names and passwords.
|
||||
* TODO: remove after connecting to a real authentication system.
|
||||
*/
|
||||
/*private static final String[] DUMMY_CREDENTIALS = new String[]{
|
||||
"foo@example.com:hello", "bar@example.com:world"
|
||||
};*/
|
||||
static final String PARAM_USER_PASS = "PARAM_USER_PASS";
|
||||
|
||||
private final String mEmail;
|
||||
private final String mPassword;
|
||||
private final Login mVolleyLogin;
|
||||
private String mTokenType;
|
||||
private Logger log = new Logger(this);
|
||||
@SuppressLint("StaticFieldLeak")
|
||||
@Nullable
|
||||
private FUAuthenticatorActivity mActivity;
|
||||
|
||||
UserLoginTask(String email, String password, String tokenType, @NotNull Context context) {
|
||||
mEmail = email;
|
||||
mPassword = password;
|
||||
mTokenType = tokenType;
|
||||
mVolleyLogin = new Login(context);
|
||||
if (context instanceof FUAuthenticatorActivity)
|
||||
mActivity = (FUAuthenticatorActivity) context;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected String doInBackground(Void... params) {
|
||||
// TODO: attempt authentication against a network service.
|
||||
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
AtomicReference<LoginToken> login = new AtomicReference<>();
|
||||
mVolleyLogin.doLogin(mEmail, mPassword, success -> {
|
||||
mVolleyLogin.testLoginToken(success, success1 -> {
|
||||
login.set(success);
|
||||
latch.countDown();
|
||||
}, error -> {
|
||||
log.e(error);
|
||||
latch.countDown();
|
||||
});
|
||||
}, error -> {
|
||||
log.e(error);
|
||||
latch.countDown();
|
||||
});
|
||||
try {
|
||||
latch.await();
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
log.d(login.get());
|
||||
|
||||
if (login.get() == null) {
|
||||
return null;
|
||||
} else {
|
||||
return login.get().toJsonString();
|
||||
}
|
||||
|
||||
/*for (String credential : DUMMY_CREDENTIALS) {
|
||||
String[] pieces = credential.split(":");
|
||||
if (pieces[0].equals(mEmail)) {
|
||||
// Account exists, return true if the password matches.
|
||||
return pieces[1].equals(mPassword) ? "auth token here" : null;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: register the new account here.
|
||||
return null;*/
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onPostExecute(final String success) {
|
||||
if (mActivity == null || mActivity.isFinishing())
|
||||
return;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())
|
||||
return;
|
||||
mActivity.mAuthTask = null;
|
||||
mActivity.showProgress(false);
|
||||
|
||||
if (success != null) {
|
||||
final Intent res = new Intent();
|
||||
res.putExtra(AccountManager.KEY_ACCOUNT_NAME, mEmail);
|
||||
res.putExtra(AccountManager.KEY_ACCOUNT_TYPE, AccountGeneral.ACCOUNT_TYPE);
|
||||
res.putExtra(AccountManager.KEY_AUTHTOKEN, success);
|
||||
res.putExtra(PARAM_USER_PASS, mPassword);
|
||||
mActivity.finishLogin(res);
|
||||
} else {
|
||||
mActivity.mPasswordView.setError(mActivity.getString(R.string.error_incorrect_password));
|
||||
mActivity.mPasswordView.requestFocus();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onCancelled() {
|
||||
if (mActivity == null || mActivity.isFinishing())
|
||||
return;
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1 && mActivity.isDestroyed())
|
||||
return;
|
||||
mActivity.mAuthTask = null;
|
||||
mActivity.showProgress(false);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import com.android.volley.NetworkResponse;
|
||||
|
||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||
|
||||
public interface KVVListener {
|
||||
default void onLogin(LoginToken token) {}
|
||||
|
||||
default void onLogout() {}
|
||||
|
||||
default void onModuleListChange() {}
|
||||
|
||||
default void onKVVNetworkResponse(NetworkResponse error) {}
|
||||
|
||||
CustomAccountManager getAccountManager();
|
||||
}
|
||||
128
app/src/main/java/de/sebse/fuplanner/services/kvv/Login.java
Normal file
128
app/src/main/java/de/sebse/fuplanner/services/kvv/Login.java
Normal file
@@ -0,0 +1,128 @@
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.services.kvv.types.LoginToken;
|
||||
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
|
||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||
import de.sebse.fuplanner.tools.NetworkCallbackCollector;
|
||||
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 {
|
||||
private final KVVListener mListener;
|
||||
@Nullable private LoginToken mToken;
|
||||
private boolean mLoginPending = false;
|
||||
private final NetworkCallbackCollector<LoginToken> mRefreshCallbacks = new NetworkCallbackCollector<>();
|
||||
|
||||
Login(KVVListener listener, Context context) {
|
||||
super(context);
|
||||
this.mListener = listener;
|
||||
}
|
||||
|
||||
public void restoreOnlineLogin(BooleanInterface callback) {
|
||||
if (mLoginPending) {
|
||||
callback.run(false);
|
||||
return;
|
||||
}
|
||||
mLoginPending = true;
|
||||
LoginToken.load(mListener.getAccountManager(), token -> {
|
||||
boolean result = setToken(token);
|
||||
mLoginPending = false;
|
||||
log.d("loginToken", token != null ? token.toString() : null);
|
||||
callback.run(result);
|
||||
});
|
||||
}
|
||||
|
||||
public void isOfflineStoredAvailable(BooleanInterface callback) {
|
||||
LoginToken.load(mListener.getAccountManager(), token -> {
|
||||
callback.run(token != null);
|
||||
});
|
||||
}
|
||||
|
||||
public boolean logout(boolean delete) {
|
||||
if (mLoginPending)
|
||||
return false;
|
||||
if (mToken == null)
|
||||
return true;
|
||||
if (delete)
|
||||
mToken.delete(mListener.getAccountManager());
|
||||
mToken = null;
|
||||
return handleCallbacks();
|
||||
}
|
||||
|
||||
public boolean isLoginPending() {
|
||||
return mLoginPending;
|
||||
}
|
||||
|
||||
public boolean isLoggedIn() {
|
||||
return mToken != null;
|
||||
}
|
||||
|
||||
public boolean isInOnlineMode() {
|
||||
return isLoggedIn();
|
||||
}
|
||||
|
||||
void testLoginToken(@NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||
if (mToken == null) {
|
||||
errorCallback.onError(new NetworkError(100173, -1, "Not logged in!"));
|
||||
return;
|
||||
}
|
||||
testLoginToken(mToken, callback, errorCallback);
|
||||
}
|
||||
|
||||
private void testLoginToken(@NotNull LoginToken token, @NotNull NetworkCallback<LoginToken> callback, @NotNull NetworkErrorCallback errorCallback) {
|
||||
new de.sebse.fuplanner.services.kvv.sync.Login(getContext()).testLoginToken(token, callback, errorCallback);
|
||||
}
|
||||
|
||||
@Nullable public LoginToken getLoginToken() {
|
||||
return mToken;
|
||||
}
|
||||
|
||||
void refreshLogin(NetworkCallback<LoginToken> success, NetworkErrorCallback error) {
|
||||
boolean isFirst = mRefreshCallbacks.isEmpty();
|
||||
mRefreshCallbacks.add(success, error);
|
||||
if (!isFirst)
|
||||
return;
|
||||
CustomAccountManager manager = mListener.getAccountManager();
|
||||
manager.doInvalidateToken(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, ignored -> {
|
||||
restoreOnlineLogin(isRestored -> {
|
||||
if (isRestored)
|
||||
testLoginToken(mRefreshCallbacks::responseResponse, mRefreshCallbacks::responseError);
|
||||
else {
|
||||
logout(true);
|
||||
mRefreshCallbacks.responseError(new NetworkError(100180, 403, "Re-login failed!"));
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
private boolean handleCallbacks() {
|
||||
if (mToken != null) {
|
||||
mListener.onLogin(mToken);
|
||||
return true;
|
||||
} else {
|
||||
mListener.onLogout();
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean setToken(@Nullable LoginToken token) {
|
||||
if (token == null)
|
||||
return false;
|
||||
boolean isOnlyRefresh = mToken != null;
|
||||
mToken = token;
|
||||
return isOnlyRefresh || handleCallbacks();
|
||||
}
|
||||
|
||||
public interface BooleanInterface {
|
||||
void run(boolean bool);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -10,7 +10,7 @@ public class Modules {
|
||||
private final HashMap<String, Part> mAddons = new HashMap<>();
|
||||
private ModulesList mList = null;
|
||||
private final Login mLogin;
|
||||
private KVVListener mListener;
|
||||
private final KVVListener mListener;
|
||||
private final Context context;
|
||||
|
||||
Modules(Login login, KVVListener listener, Context context) {
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Announcement;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Announcement;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -8,9 +8,9 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Assignment;
|
||||
import de.sebse.fuplanner.services.KVV.types.AssignmentList;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Assignment;
|
||||
import de.sebse.fuplanner.services.kvv.types.AssignmentList;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -1,11 +1,11 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.concurrent.atomic.AtomicReference;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -6,9 +6,9 @@ import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Event;
|
||||
import de.sebse.fuplanner.services.KVV.types.EventList;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Event;
|
||||
import de.sebse.fuplanner.services.kvv.types.EventList;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -8,8 +8,8 @@ import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Grade;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Grade;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
@@ -13,9 +13,9 @@ import java.util.HashSet;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.regex.MatchResult;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Lecturer;
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.KVV.types.Semester;
|
||||
import de.sebse.fuplanner.services.kvv.types.Lecturer;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Semester;
|
||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||
@@ -23,13 +23,13 @@ import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
import static de.sebse.fuplanner.services.KVV.PartModules.RETRY_COUNT;
|
||||
import static de.sebse.fuplanner.services.kvv.PartModules.RETRY_COUNT;
|
||||
|
||||
public class ModulesList extends HTTPService {
|
||||
private final Login mLogin;
|
||||
private final KVVListener mListener;
|
||||
@Nullable private Modules mModules;
|
||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||
private final NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||
|
||||
ModulesList(Login login, KVVListener listener, Context context) {
|
||||
super(context);
|
||||
@@ -46,12 +46,22 @@ public class ModulesList extends HTTPService {
|
||||
return null;
|
||||
}
|
||||
|
||||
public void reloadIfOutdated() {
|
||||
try {
|
||||
if (mModules != null && mModules.isNewerVersionInStorage(getContext())) {
|
||||
restore();
|
||||
}
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback) {
|
||||
find(moduleID, moduleNetworkCallback, errorCallback, RETRY_COUNT);
|
||||
}
|
||||
|
||||
private void find(String moduleID, NetworkCallback<Modules.Module> moduleNetworkCallback, NetworkErrorCallback errorCallback, int retries) {
|
||||
if (mModules != null && mLogin.getLoginToken() != null && !mLogin.getLoginToken().isSameUser(mModules.getUsername()))
|
||||
if (mModules != null && mLogin.getLoginToken() != null && mLogin.getLoginToken().isOtherUser(mModules.getUsername()))
|
||||
delete();
|
||||
if (retries < 0) {
|
||||
errorCallback.onError(new NetworkError(101107, -1, "Too many retries!"));
|
||||
@@ -104,7 +114,7 @@ public class ModulesList extends HTTPService {
|
||||
}
|
||||
|
||||
private void recv(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, final int retries) {
|
||||
if (mModules != null && mLogin.getLoginToken() != null && !mLogin.getLoginToken().isSameUser(mModules.getUsername()))
|
||||
if (mModules != null && mLogin.getLoginToken() != null && mLogin.getLoginToken().isOtherUser(mModules.getUsername()))
|
||||
delete();
|
||||
mQueue.add(() -> {
|
||||
if (this.mModules != null && !forceRefresh) {
|
||||
@@ -115,10 +125,10 @@ public class ModulesList extends HTTPService {
|
||||
this.upgrade(success -> {
|
||||
if (this.mModules == null)
|
||||
this.mModules = success;
|
||||
else
|
||||
this.mModules.updateList(success);
|
||||
mListener.onModuleListChange();
|
||||
store();
|
||||
else if(this.mModules.updateList(success)) {
|
||||
mListener.onModuleListChange();
|
||||
store();
|
||||
}
|
||||
callback.onResponse(this.mModules);
|
||||
mQueue.next();
|
||||
}, error -> {
|
||||
@@ -139,6 +149,7 @@ public class ModulesList extends HTTPService {
|
||||
}
|
||||
|
||||
private void upgrade(final NetworkCallback<Modules> callback, final NetworkErrorCallback errorCallback) {
|
||||
log.d(mLogin.isInOnlineMode(), mLogin.getLoginToken());
|
||||
if (!mLogin.isInOnlineMode() || mLogin.getLoginToken() == null) {
|
||||
errorCallback.onError(new NetworkError(101105, 500, "Currently running in offline mode!"));
|
||||
return;
|
||||
@@ -163,6 +174,8 @@ public class ModulesList extends HTTPService {
|
||||
try {
|
||||
JSONObject site = sites.getJSONObject(i);
|
||||
String semester_string = site.getJSONObject("props").optString("term_eid", null);
|
||||
if (semester_string == null)
|
||||
continue;
|
||||
Semester semester = new Semester(semester_string);
|
||||
HashSet<String> lvNumbers = new HashSet<>();
|
||||
String kvv_lvnumbers = site.getJSONObject("props").optString("kvv_lvnumbers", null);
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Environment;
|
||||
@@ -11,9 +11,10 @@ import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.KVV.types.Resource;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
||||
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.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
@@ -64,7 +65,8 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
||||
JSONObject site = sites.getJSONObject(i);
|
||||
String author = site.getString("author");
|
||||
String title = site.getString("title");
|
||||
long modifiedDate = site.getLong("modifiedDate");
|
||||
//long modifiedDate = site.getLong("modifiedDate");"20181018155405439"
|
||||
long modifiedDate = UtilsDate.stringToMillis(site.getString("modifiedDate"), "yyyyMMddHHmmssSSS");
|
||||
String url = site.getString("url");
|
||||
boolean visible = site.getBoolean("visible");
|
||||
String type = site.getString("type");
|
||||
@@ -124,7 +126,7 @@ public class ModulesResources extends PartModules<ArrayList<Resource>> {
|
||||
file(filename, url, modulename, callback, errorCallback, forceRefresh, RETRY_COUNT);
|
||||
}
|
||||
|
||||
public void file(final String filename, final String url, final String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, int retries) {
|
||||
private void file(final String filename, final String url, final String modulename, final NetworkCallback<String> callback, final NetworkErrorCallback errorCallback, boolean forceRefresh, int retries) {
|
||||
if (isExternalStorageReadable()){
|
||||
File f = new File(Environment.getExternalStoragePublicDirectory(
|
||||
Environment.DIRECTORY_DOWNLOADS)+"/"+modulename+"/"+filename);
|
||||
@@ -1,16 +1,16 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
public abstract class Part<T> extends HTTPService {
|
||||
static final int RETRY_COUNT = 1;
|
||||
protected final Login mLogin;
|
||||
protected final ModulesList mList;
|
||||
final Login mLogin;
|
||||
final ModulesList mList;
|
||||
|
||||
Part(Login login, ModulesList list, Context context) {
|
||||
super(context);
|
||||
@@ -1,17 +1,17 @@
|
||||
package de.sebse.fuplanner.services.KVV;
|
||||
package de.sebse.fuplanner.services.kvv;
|
||||
|
||||
import android.content.Context;
|
||||
import android.os.Build;
|
||||
import android.text.Html;
|
||||
import android.text.Spanned;
|
||||
|
||||
import de.sebse.fuplanner.services.KVV.types.Modules;
|
||||
import de.sebse.fuplanner.services.kvv.types.Modules;
|
||||
import de.sebse.fuplanner.tools.NewAsyncQueue;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
abstract class PartModules<T> extends Part<Modules.Module> {
|
||||
private NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||
private final NewAsyncQueue mQueue = new NewAsyncQueue();
|
||||
|
||||
PartModules(Login login, ModulesList list, Context context) {
|
||||
super(login, list, context);
|
||||
@@ -0,0 +1,67 @@
|
||||
package de.sebse.fuplanner.services.kvv.sync;
|
||||
|
||||
import android.content.ContentProvider;
|
||||
import android.content.ContentValues;
|
||||
import android.content.UriMatcher;
|
||||
import android.database.Cursor;
|
||||
import android.net.Uri;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
public class KVVContentProvider extends ContentProvider {
|
||||
|
||||
public static final String PROVIDER_NAME = "de.sebse.fuplanner.contentprovider.kvv.modules";
|
||||
private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/modules");
|
||||
private static final int MODULE = 1;
|
||||
private static final int MODULE_ID = 2;
|
||||
private static final UriMatcher uriMatcher = getUriMatcher();
|
||||
|
||||
private static UriMatcher getUriMatcher() {
|
||||
UriMatcher uriMatcher = new UriMatcher(UriMatcher.NO_MATCH);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "modules", MODULE);
|
||||
uriMatcher.addURI(PROVIDER_NAME, "modules/#", MODULE_ID);
|
||||
return uriMatcher;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onCreate() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Cursor query(@NonNull Uri uri, @Nullable String[] strings, @Nullable String s, @Nullable String[] strings1, @Nullable String s1) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public String getType(@NonNull Uri uri) {
|
||||
switch (uriMatcher.match(uri)) {
|
||||
case MODULE:
|
||||
return "vnd.android.cursor.dir/vnd.com."+PROVIDER_NAME;
|
||||
case MODULE_ID:
|
||||
return "vnd.android.cursor.item/vnd.com."+PROVIDER_NAME;
|
||||
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
@Override
|
||||
public Uri insert(@NonNull Uri uri, @Nullable ContentValues contentValues) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int delete(@NonNull Uri uri, @Nullable String s, @Nullable String[] strings) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int update(@NonNull Uri uri, @Nullable ContentValues contentValues, @Nullable String s, @Nullable String[] strings) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,161 @@
|
||||
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.Event;
|
||||
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 -> {
|
||||
log.d("login restored");
|
||||
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) {
|
||||
log.d("onPerformSync");
|
||||
mQueue.add(() -> {
|
||||
log.d("start syncing");
|
||||
mKVV.modules().list().recv(success -> {
|
||||
Iterator<Modules.Module> iterator = success.latestSemesterIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Modules.Module module = iterator.next();
|
||||
log.d("sync module", module.title);
|
||||
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) {
|
||||
log.d("Sync Successful for Module '"+module.title+"'!");
|
||||
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::getId,
|
||||
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);
|
||||
log.d("finished");
|
||||
});
|
||||
}
|
||||
|
||||
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<T>();
|
||||
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,24 @@
|
||||
package de.sebse.fuplanner.services.kvv.sync;
|
||||
|
||||
import android.app.Service;
|
||||
import android.content.Intent;
|
||||
import android.os.IBinder;
|
||||
|
||||
public class KVVSyncService extends Service {
|
||||
|
||||
private static final Object sSyncAdapterLock = new Object();
|
||||
private static KVVSyncAdapter sSyncAdapter = null;
|
||||
|
||||
@Override
|
||||
public void onCreate() {
|
||||
synchronized (sSyncAdapterLock) {
|
||||
if (sSyncAdapter == null)
|
||||
sSyncAdapter = new KVVSyncAdapter(getApplicationContext(), true);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBinder onBind(Intent intent) {
|
||||
return sSyncAdapter.getSyncAdapterBinder();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,265 @@
|
||||
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 fuSHIBSession = success4.get("shib_idp_session");
|
||||
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, shibsessionKey, shibsessionName, 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,10 +1,12 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class Announcement implements Serializable {
|
||||
private final String id;
|
||||
private final String title;
|
||||
@@ -14,7 +16,6 @@ public class Announcement implements Serializable {
|
||||
private final ArrayList<String> urls;
|
||||
|
||||
public Announcement(String id, String title, String body, String createdBy, long createdOn, ArrayList<String> urls) {
|
||||
|
||||
this.id = id;
|
||||
this.title = title;
|
||||
this.body = body;
|
||||
@@ -27,7 +28,7 @@ public class Announcement implements Serializable {
|
||||
return urls;
|
||||
}
|
||||
|
||||
private String getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@ public class Announcement implements Serializable {
|
||||
return createdOn;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ID: "+getId()+
|
||||
@@ -1,10 +1,12 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class Assignment implements Serializable {
|
||||
private final String id;
|
||||
private final String title;
|
||||
@@ -20,7 +22,7 @@ public class Assignment implements Serializable {
|
||||
this.instructions = instructions;
|
||||
}
|
||||
|
||||
private String getId() {
|
||||
public String getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@@ -44,6 +46,7 @@ public class Assignment implements Serializable {
|
||||
return instructions;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ID: "+getId()+
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import de.sebse.fuplanner.tools.DateSortedList;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
@@ -7,6 +7,7 @@ import java.nio.charset.StandardCharsets;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.ColorRGB;
|
||||
|
||||
public class Event implements Serializable {
|
||||
@@ -106,6 +107,7 @@ public class Event implements Serializable {
|
||||
}
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "ID: "+getId()+
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import de.sebse.fuplanner.tools.DateSortedList;
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class Grade implements Serializable {
|
||||
private final String itemName;
|
||||
private final double grade;
|
||||
@@ -27,6 +29,7 @@ public class Grade implements Serializable {
|
||||
return itemName;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Name: "+getItemName()+
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
@@ -9,36 +9,41 @@ import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
public class GroupedEvents {
|
||||
private ArrayList<Group> arrayList = new ArrayList<>();
|
||||
private Logger log = new Logger(this);
|
||||
public class GroupedEvents extends EventList {
|
||||
private final ArrayList<Group> arrayList = new ArrayList<>();
|
||||
private int skippedDayCount = 0;
|
||||
|
||||
public void add(Event event) {
|
||||
public boolean add(Event event) {
|
||||
boolean result = super.add(event);
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
calendar.setTimeInMillis(event.getStartDate());
|
||||
long dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);
|
||||
for (Group group : arrayList) {
|
||||
if (group.add(event)) {
|
||||
return;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
arrayList.add(new Group(event));
|
||||
return result;
|
||||
}
|
||||
|
||||
public List<Group> getGroups() {
|
||||
return Collections.unmodifiableList(arrayList);
|
||||
}
|
||||
|
||||
public int getSkippedDayCount() {
|
||||
return skippedDayCount;
|
||||
}
|
||||
|
||||
public class Group {
|
||||
private long firstDate;
|
||||
private long lastDate;
|
||||
private ArrayList<Long> skippedDates;
|
||||
private final ArrayList<Long> skippedDates;
|
||||
|
||||
private int dayOfWeek;
|
||||
private long startTime;
|
||||
private long duration;
|
||||
private final int dayOfWeek;
|
||||
private final long startTime;
|
||||
private final long duration;
|
||||
|
||||
private Group(Event event) {
|
||||
Calendar calendar = Calendar.getInstance();
|
||||
@@ -73,16 +78,19 @@ public class GroupedEvents {
|
||||
firstDate = addDays(firstDate, -7);
|
||||
while (firstDate > date) {
|
||||
skippedDates.add(firstDate);
|
||||
skippedDayCount += 1;
|
||||
firstDate = addDays(firstDate, -7);
|
||||
}
|
||||
} else if (date > lastDate) {
|
||||
lastDate = addDays(lastDate, 7);
|
||||
while (lastDate < date) {
|
||||
skippedDates.add(lastDate);
|
||||
skippedDayCount += 1;
|
||||
lastDate = addDays(lastDate, 7);
|
||||
}
|
||||
} else {
|
||||
skippedDates.remove(date);
|
||||
skippedDayCount -= 1;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
@@ -1,9 +1,11 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.util.regex.Matcher;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
public class Lecturer implements Serializable {
|
||||
private final String firstName;
|
||||
private final String surname;
|
||||
@@ -46,6 +48,7 @@ public class Lecturer implements Serializable {
|
||||
return getFirstName().substring(0, 1) + ". " + getSurname();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "First name: "+ getFirstName()+
|
||||
@@ -0,0 +1,151 @@
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.Serializable;
|
||||
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;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 29.10.17.
|
||||
*/
|
||||
|
||||
public class LoginToken implements Serializable {
|
||||
static Logger log = new Logger("LoginToken");
|
||||
private static final String FILE_NAME = "LoginTokenSaving";
|
||||
|
||||
private final String username;
|
||||
private final String shibsessionKey;
|
||||
private final String shibsessionName;
|
||||
private final String JSESSIONID;
|
||||
@Nullable private String fullName;
|
||||
@Nullable private String email;
|
||||
|
||||
public LoginToken(String username, String shibsessionKey, String shibsessionName, String JSESSIONID) {
|
||||
this.username = username;
|
||||
this.shibsessionKey = shibsessionKey;
|
||||
this.shibsessionName = shibsessionName;
|
||||
this.JSESSIONID = JSESSIONID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static void load(CustomAccountManager manager, LoginTokenInterface callback) {
|
||||
if (!manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
callback.run(null);
|
||||
return;
|
||||
}
|
||||
manager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_KVV, tokenString -> {
|
||||
if (tokenString == null) {
|
||||
callback.run(null);
|
||||
return;
|
||||
}
|
||||
callback.run(LoginToken.fromJsonString(tokenString));
|
||||
});
|
||||
}
|
||||
|
||||
public void delete(CustomAccountManager manager) {
|
||||
manager.deleteAccount(AccountGeneral.ACCOUNT_TYPE);
|
||||
}
|
||||
|
||||
public void setAdditionals(String fullName, String email) {
|
||||
this.fullName = fullName;
|
||||
this.email = email;
|
||||
}
|
||||
|
||||
public String getUsername() {
|
||||
return username;
|
||||
}
|
||||
|
||||
private String getShibsessionKey() {
|
||||
return shibsessionKey;
|
||||
}
|
||||
|
||||
private String getShibsessionName() {
|
||||
return shibsessionName;
|
||||
}
|
||||
|
||||
private String getJSESSIONID() {
|
||||
return JSESSIONID;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getFullName() {
|
||||
return fullName;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public String getEmail() {
|
||||
return email;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getCookies() {
|
||||
HashMap<String, String> cookies = new HashMap<>();
|
||||
cookies.put("JSESSIONID", getJSESSIONID());
|
||||
cookies.put(getShibsessionKey(), getShibsessionName());
|
||||
cookies.put("pasystem_timezone_ok", "true");
|
||||
return cookies;
|
||||
}
|
||||
|
||||
public boolean isOtherUser(String username) {
|
||||
return !this.getUsername().equals(username);
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder result = new StringBuilder();
|
||||
HashMap<String, String> cookies = this.getCookies();
|
||||
for (String header: cookies.keySet()) {
|
||||
result.append(header).append("=").append(cookies.get(header)).append(";");
|
||||
}
|
||||
return result.substring(0, result.length()-1);
|
||||
}
|
||||
|
||||
public String toJsonString() {
|
||||
JSONObject json = new JSONObject();
|
||||
try {
|
||||
json.put("username", username);
|
||||
json.put("shibsessionKey", shibsessionKey);
|
||||
json.put("shibsessionName", shibsessionName);
|
||||
json.put("JSESSIONID", JSESSIONID);
|
||||
json.put("fullName", fullName);
|
||||
json.put("email", email);
|
||||
} catch (JSONException e) {
|
||||
return null;
|
||||
}
|
||||
return json.toString();
|
||||
}
|
||||
|
||||
public static LoginToken fromJsonString(String tokenString) {
|
||||
try {
|
||||
JSONObject json = new JSONObject(tokenString);
|
||||
LoginToken token = new LoginToken(
|
||||
json.getString("username"),
|
||||
json.getString("shibsessionName"),
|
||||
json.getString("shibsessionName"),
|
||||
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 {
|
||||
void run(LoginToken token);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
@@ -25,8 +27,10 @@ import androidx.annotation.Nullable;
|
||||
public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
private SortedListModule list;
|
||||
private final String mUsername;
|
||||
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_TIMESTAMP = "ModuleListSavingTimestamp";
|
||||
|
||||
public Modules(String username) {
|
||||
this.mUsername = username;
|
||||
@@ -75,15 +79,38 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
Modules modules = (Modules) readObject;
|
||||
is.close();
|
||||
fis.close();
|
||||
|
||||
fis = context.openFileInput(FILE_NAME_TIMESTAMP);
|
||||
is = new ObjectInputStream(fis);
|
||||
modules.mLastTimestamp = is.readLong();
|
||||
is.close();
|
||||
fis.close();
|
||||
|
||||
return modules;
|
||||
}
|
||||
|
||||
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 delete(Context context) {
|
||||
@@ -94,19 +121,36 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
return mUsername;
|
||||
}
|
||||
|
||||
public void updateList(Modules modules) {
|
||||
public boolean updateList(Modules modules) {
|
||||
SortedListModule old = this.list;
|
||||
this.list = modules.list;
|
||||
boolean isChanged = false;
|
||||
for (Module oldModule : old) {
|
||||
Module newModule = this.list.getById(oldModule.getID());
|
||||
if (newModule != null) {
|
||||
if (!isChanged && !hashEquals(oldModule, newModule))
|
||||
isChanged = true;
|
||||
newModule.announcements = oldModule.announcements;
|
||||
newModule.assignments = oldModule.assignments;
|
||||
newModule.events = oldModule.events;
|
||||
newModule.gradebook = oldModule.gradebook;
|
||||
newModule.resources = oldModule.resources;
|
||||
} else {
|
||||
isChanged = true;
|
||||
}
|
||||
}
|
||||
if (this.list.size() != old.size())
|
||||
isChanged = true;
|
||||
return isChanged;
|
||||
}
|
||||
|
||||
private boolean hashEquals(Module o1, Module o2) {
|
||||
if (o1 == null && o2 == null)
|
||||
return true;
|
||||
else if (o1 == null || o2 == null)
|
||||
return false;
|
||||
else
|
||||
return o1.hashCode() == o2.hashCode();
|
||||
}
|
||||
|
||||
public class Module implements Serializable {
|
||||
@@ -166,5 +210,10 @@ public class Modules implements Iterable<Modules.Module>, Serializable {
|
||||
"\ntype: "+type+
|
||||
"\nID: "+ID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import com.google.android.gms.common.internal.Objects;
|
||||
|
||||
@@ -6,6 +6,7 @@ import java.io.Serializable;
|
||||
import java.util.ArrayList;
|
||||
|
||||
import androidx.annotation.LayoutRes;
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.LayoutItemType;
|
||||
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
|
||||
@@ -69,6 +70,7 @@ public abstract class Resource implements Serializable {
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Resource{" +
|
||||
@@ -111,6 +113,7 @@ public abstract class Resource implements Serializable {
|
||||
return children.size();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return "Resource{" +
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.types;
|
||||
package de.sebse.fuplanner.services.kvv.types;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.tools.SortedList;
|
||||
@@ -1,4 +1,4 @@
|
||||
package de.sebse.fuplanner.services.KVV.ui;
|
||||
package de.sebse.fuplanner.services.kvv.ui;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
@@ -18,7 +18,7 @@ import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.FileProvider;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.services.KVV.types.Resource;
|
||||
import de.sebse.fuplanner.services.kvv.types.Resource;
|
||||
import de.sebse.fuplanner.tools.Regex;
|
||||
import de.sebse.fuplanner.tools.RequestPermissionsResultListener;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
@@ -31,7 +31,7 @@ public class Download {
|
||||
private final ContextInterface contextInterface;
|
||||
private final ActivityInterface activityInterface;
|
||||
private RequestedDownload requestedDownload;
|
||||
private Logger log = new Logger(this);
|
||||
private final Logger log = new Logger(this);
|
||||
|
||||
|
||||
public Download(ContextInterface contextInterface, ActivityInterface activityInterface) {
|
||||
@@ -106,7 +106,7 @@ public class Download {
|
||||
}
|
||||
activity.getKVV().modules().resources().file(file.getTitle(), file.getUrl(), folderName, success -> {
|
||||
Context context = contextInterface.get();
|
||||
if (success.equals("")) {
|
||||
if (success.equals("") || context== null) {
|
||||
showDownloadError();
|
||||
} else {
|
||||
if (Regex.has("^http", success)){
|
||||
@@ -116,7 +116,6 @@ public class Download {
|
||||
else {
|
||||
fileOpen(new File(success));
|
||||
}
|
||||
|
||||
}
|
||||
}, log::e, downloadNew);
|
||||
}
|
||||
@@ -140,7 +139,7 @@ public class Download {
|
||||
public RequestPermissionsResultListener getRequestPermissionsResultListener() {
|
||||
return (requestCode, permissions, grantResults) -> {
|
||||
if (requestedDownload == null) {
|
||||
log.d("No request");
|
||||
log.e("No request");
|
||||
return;
|
||||
}
|
||||
if (activityInterface.get() == null) {
|
||||
@@ -152,13 +151,11 @@ public class Download {
|
||||
{
|
||||
intList.add(i);
|
||||
}
|
||||
log.d(requestCode, Arrays.asList(permissions), intList);
|
||||
int pos = Arrays.asList(permissions).indexOf("android.permission.WRITE_EXTERNAL_STORAGE");
|
||||
if (pos != -1) {
|
||||
if (grantResults[pos] != -1) {
|
||||
downloadOrOpen(requestedDownload.file, requestedDownload.folderName, requestedDownload.downloadNew);
|
||||
} else {
|
||||
log.d(requestedDownload, pos, grantResults[pos]);
|
||||
showDownloadError();
|
||||
}
|
||||
requestedDownload = null;
|
||||
@@ -167,9 +164,9 @@ public class Download {
|
||||
}
|
||||
|
||||
private class RequestedDownload {
|
||||
Resource.File file;
|
||||
String folderName;
|
||||
boolean downloadNew;
|
||||
final Resource.File file;
|
||||
final String folderName;
|
||||
final boolean downloadNew;
|
||||
|
||||
RequestedDownload(Resource.File file, String folderName, boolean downloadNew) {
|
||||
this.file = file;
|
||||
@@ -189,7 +186,10 @@ public class Download {
|
||||
}
|
||||
|
||||
private void fileOpen(File url){
|
||||
Uri uri = FileProvider.getUriForFile(contextInterface.get(), contextInterface.get().getApplicationContext().getPackageName() + ".my.provider", url);
|
||||
Context context = contextInterface.get();
|
||||
if (context == null)
|
||||
return;
|
||||
Uri uri = FileProvider.getUriForFile(context, context.getApplicationContext().getPackageName() + ".my.provider", url);
|
||||
|
||||
Intent intent;
|
||||
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
|
||||
@@ -244,7 +244,7 @@ public class Download {
|
||||
intent.setDataAndType(uri, "*/*");
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
contextInterface.get().startActivity(intent);
|
||||
context.startActivity(intent);
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,91 @@
|
||||
package de.sebse.fuplanner.services.news;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.Locale;
|
||||
|
||||
import de.sebse.fuplanner.R;
|
||||
import de.sebse.fuplanner.tools.UtilsDate;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
import de.sebse.fuplanner.tools.types.NewsList;
|
||||
|
||||
public class NewsManager {
|
||||
private NewsList mNewsList;
|
||||
private Context mContext;
|
||||
|
||||
public NewsManager(Context context) {
|
||||
this.mContext = context;
|
||||
}
|
||||
|
||||
public void recv(final NetworkCallback<NewsList> callback, final NetworkErrorCallback errorCallback) {
|
||||
recv(callback, errorCallback, false);
|
||||
}
|
||||
|
||||
public void recv(final NetworkCallback<NewsList> callback, final NetworkErrorCallback errorCallback, final boolean forceRefresh) {
|
||||
if (!forceRefresh && mNewsList != null) {
|
||||
callback.onResponse(mNewsList);
|
||||
return;
|
||||
}
|
||||
String fromAsset = loadJSONFromAsset();
|
||||
if (fromAsset == null)
|
||||
return;
|
||||
String language = Locale.getDefault().getLanguage();
|
||||
JSONArray news;
|
||||
NewsList dates = new NewsList();
|
||||
try {
|
||||
JSONObject json = new JSONObject(fromAsset);
|
||||
news = json.getJSONArray("news");
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
errorCallback.onError(new NetworkError(300100, 500, "Parsing news list failed!"));
|
||||
return;
|
||||
}
|
||||
|
||||
for (int i = news.length() - 1; i >= 0; i--) {
|
||||
try {
|
||||
String title = news.getJSONObject(i).optString("title_" + language, null);
|
||||
if (title == null)
|
||||
title = news.getJSONObject(i).getString("title");
|
||||
String categoryString = news.getJSONObject(i).getString("category");
|
||||
int category;
|
||||
if (categoryString.equals("CATEGORY_TRICKS"))
|
||||
category = de.sebse.fuplanner.tools.types.News.CATEGORY_TRICKS;
|
||||
else
|
||||
category = de.sebse.fuplanner.tools.types.News.CATEGORY_UPDATE;
|
||||
String dateString = news.getJSONObject(i).getString("date");
|
||||
long date = UtilsDate.stringToMillis(dateString, "dd.MM.yyyy");
|
||||
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);
|
||||
} catch (JSONException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
mNewsList = dates;
|
||||
callback.onResponse(mNewsList);
|
||||
}
|
||||
|
||||
private String loadJSONFromAsset() {
|
||||
try {
|
||||
InputStream is = mContext.getResources().openRawResource(R.raw.news);
|
||||
int size = is.available();
|
||||
byte[] buffer = new byte[size];
|
||||
is.read(buffer);
|
||||
is.close();
|
||||
return new String(buffer, "UTF-8");
|
||||
} catch (IOException ex) {
|
||||
ex.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,141 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
import android.accounts.Account;
|
||||
import android.accounts.AccountManager;
|
||||
import android.accounts.AccountManagerCallback;
|
||||
import android.accounts.AuthenticatorException;
|
||||
import android.accounts.OperationCanceledException;
|
||||
import android.app.Activity;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import androidx.annotation.Nullable;
|
||||
import de.sebse.fuplanner.services.kvv.Login;
|
||||
import de.sebse.fuplanner.tools.logging.Logger;
|
||||
|
||||
public class CustomAccountManager {
|
||||
private final AccountManager mAccountManager;
|
||||
private final ActivityInterface mActivityInterface;
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
public CustomAccountManager(AccountManager manager, ActivityInterface activityInterface) {
|
||||
mAccountManager = manager;
|
||||
this.mActivityInterface = activityInterface;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
public void doInvalidateTokenSync(String accountType, String authTokenType) {
|
||||
Account account = mAccountManager.getAccountsByType(accountType)[0];
|
||||
try {
|
||||
String token = mAccountManager.blockingGetAuthToken(account, authTokenType, true);
|
||||
mAccountManager.invalidateAuthToken(accountType, token);
|
||||
} catch (AuthenticatorException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void doInvalidateToken(String accountType, String authTokenType, Login.BooleanInterface callback) {
|
||||
Account account = mAccountManager.getAccountsByType(accountType)[0];
|
||||
mAccountManager.getAuthToken(account, authTokenType, null, true, accountManagerFuture -> {
|
||||
try {
|
||||
Bundle bnd = accountManagerFuture.getResult();
|
||||
String token = bnd.getString(AccountManager.KEY_AUTHTOKEN);
|
||||
mAccountManager.invalidateAuthToken(accountType, token);
|
||||
if (callback != null)
|
||||
callback.run(true);
|
||||
return;
|
||||
} catch (AuthenticatorException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (callback != null)
|
||||
callback.run(false);
|
||||
}, null);
|
||||
}
|
||||
|
||||
public void deleteAccount(String accountType) {
|
||||
Account[] accounts = mAccountManager.getAccountsByType(accountType);
|
||||
int[] count = {accounts.length};
|
||||
for (Account account: accounts) {
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP_MR1) {
|
||||
mAccountManager.removeAccount(account, null, null, null);
|
||||
} else {
|
||||
mAccountManager.removeAccount(account, null, null);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void getTokenByType(String accountType, String authTokenType, @Nullable StringInterface callback) {
|
||||
Activity activity = mActivityInterface.get();
|
||||
AccountManagerCallback<Bundle> cb = (accountManagerFuture -> {
|
||||
try {
|
||||
Bundle bnd = accountManagerFuture.getResult();
|
||||
final String authtoken = bnd.getString(AccountManager.KEY_AUTHTOKEN);
|
||||
if (callback != null)
|
||||
callback.run(authtoken);
|
||||
return;
|
||||
} catch (AuthenticatorException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
if (callback != null)
|
||||
callback.run(null);
|
||||
});
|
||||
if (activity != null) {
|
||||
mAccountManager.getAuthTokenByFeatures(accountType, authTokenType, null, mActivityInterface.get(), null, null, cb, null);
|
||||
} else {
|
||||
Account account = mAccountManager.getAccountsByType(accountType)[0];
|
||||
mAccountManager.getAuthToken(account, authTokenType, null, true, cb, null);
|
||||
}
|
||||
}
|
||||
|
||||
public String getTokenByTypeSync(String accountType, String authTokenType) {
|
||||
Account account = mAccountManager.getAccountsByType(accountType)[0];
|
||||
try {
|
||||
return mAccountManager.blockingGetAuthToken(account, authTokenType, true);
|
||||
} catch (AuthenticatorException e) {
|
||||
e.printStackTrace();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
} catch (OperationCanceledException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public boolean hasAccounts(String accountType) {
|
||||
return mAccountManager.getAccountsByType(accountType).length != 0;
|
||||
}
|
||||
|
||||
public Account getAccountByType(String accountType) {
|
||||
Account[] accountsByType = mAccountManager.getAccountsByType(accountType);
|
||||
if (accountsByType.length > 0)
|
||||
return accountsByType[0];
|
||||
return null;
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
public interface ActivityInterface {
|
||||
@Nullable
|
||||
Activity get();
|
||||
}
|
||||
|
||||
public interface StringInterface {
|
||||
void run(@Nullable String string);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,57 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.PendingIntent;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
import androidx.core.app.NotificationCompat;
|
||||
import androidx.core.app.NotificationManagerCompat;
|
||||
import de.sebse.fuplanner.MainActivity;
|
||||
import de.sebse.fuplanner.R;
|
||||
|
||||
public class CustomNotificationManager {
|
||||
private static final String CHANNEL_ID = "fuplanner-default";
|
||||
//public static ArrayList<Integer> passedNotifications = new ArrayList<>();
|
||||
|
||||
public static void sendNotification(Context context, String textTitle, String textContent) {
|
||||
Intent intent = new Intent(context, MainActivity.class);
|
||||
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK);
|
||||
PendingIntent pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
|
||||
|
||||
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(context, CHANNEL_ID)
|
||||
.setSmallIcon(R.drawable.ic_notification)
|
||||
.setContentTitle(textTitle)
|
||||
.setContentText(textContent)
|
||||
.setPriority(NotificationCompat.PRIORITY_DEFAULT)
|
||||
.setContentIntent(pendingIntent)
|
||||
.setAutoCancel(true);
|
||||
|
||||
NotificationManagerCompat notificationManager = NotificationManagerCompat.from(context);
|
||||
int notificationId = (int) (System.currentTimeMillis() % Integer.MAX_VALUE);
|
||||
notificationManager.notify(notificationId, mBuilder.build());
|
||||
}
|
||||
|
||||
public static void createNotificationChannel(@NotNull Context context) {
|
||||
// Create the NotificationChannel, but only on API 26+ because
|
||||
// the NotificationChannel class is new and not in the support library
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O) {
|
||||
CharSequence name = context.getString(R.string.channel_name);
|
||||
String description = context.getString(R.string.channel_description);
|
||||
int importance = NotificationManager.IMPORTANCE_DEFAULT;
|
||||
NotificationChannel channel = new NotificationChannel(CHANNEL_ID, name, importance);
|
||||
channel.setDescription(description);
|
||||
// Register the channel with the system; you can't change the importance
|
||||
// or other notification behaviors after this
|
||||
NotificationManager notificationManager = context.getSystemService(NotificationManager.class);
|
||||
if (notificationManager != null) {
|
||||
notificationManager.createNotificationChannel(channel);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import java.util.Iterator;
|
||||
|
||||
public abstract class DateSortedList<T> extends ArrayList<T> {
|
||||
private int split = -1;
|
||||
private boolean mSorting = false;
|
||||
|
||||
public T getPast(int index) {
|
||||
if (split < 0)
|
||||
@@ -30,6 +31,7 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
|
||||
|
||||
@Override
|
||||
public T get(int index) {
|
||||
if (mSorting) return super.get(index);
|
||||
if (split < 0)
|
||||
sort();
|
||||
if (reversed())
|
||||
@@ -55,6 +57,7 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
|
||||
}
|
||||
|
||||
public void sort() {
|
||||
mSorting = true;
|
||||
Collections.sort(this, ((e1, e2) -> Long.compare(getDateByItem(e1), getDateByItem(e2))));
|
||||
long now = System.currentTimeMillis();
|
||||
split = 0;
|
||||
@@ -64,6 +67,7 @@ public abstract class DateSortedList<T> extends ArrayList<T> {
|
||||
else
|
||||
break;
|
||||
}
|
||||
mSorting = false;
|
||||
}
|
||||
|
||||
public Iterator<T> getEventsOfMonth(int year, int month) {
|
||||
|
||||
@@ -3,7 +3,7 @@ package de.sebse.fuplanner.tools;
|
||||
import java.util.HashMap;
|
||||
|
||||
public class EventListener<T> {
|
||||
private HashMap<String, EventFunction<T>> list = new HashMap<>();
|
||||
private final HashMap<String, EventFunction<T>> list = new HashMap<>();
|
||||
|
||||
public void add(String id,EventFunction<T> listener) {
|
||||
list.put(id, listener);
|
||||
|
||||
@@ -2,9 +2,9 @@ package de.sebse.fuplanner.tools;
|
||||
|
||||
import androidx.annotation.StringRes;
|
||||
|
||||
import de.sebse.fuplanner.services.Canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.GoogleAuth.GoogleAuth;
|
||||
import de.sebse.fuplanner.services.KVV.KVV;
|
||||
import de.sebse.fuplanner.services.canteen.CanteenBrowser;
|
||||
import de.sebse.fuplanner.services.kvv.KVV;
|
||||
import de.sebse.fuplanner.services.news.NewsManager;
|
||||
|
||||
public interface MainActivityListener {
|
||||
void onTitleTextChange(String newTitle);
|
||||
@@ -17,12 +17,9 @@ public interface MainActivityListener {
|
||||
|
||||
KVV getKVV();
|
||||
|
||||
GoogleAuth getGoogleAuth();
|
||||
|
||||
CanteenBrowser getCanteenBrowser();
|
||||
|
||||
@Deprecated
|
||||
void onRefreshCompleted(boolean isFailed);
|
||||
NewsManager getNewsManager();
|
||||
|
||||
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
||||
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
import android.util.Pair;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
public class NetworkCallbackCollector<T> extends HashSet<Pair<NetworkCallback<T>, NetworkErrorCallback>> {
|
||||
public void add(NetworkCallback<T> success, NetworkErrorCallback error) {
|
||||
add(new Pair<>(success, error));
|
||||
}
|
||||
|
||||
public void responseError(NetworkError error) {
|
||||
Iterator<Pair<NetworkCallback<T>, NetworkErrorCallback>> i;
|
||||
for (i = this.iterator(); i.hasNext();) {
|
||||
Pair<NetworkCallback<T>, NetworkErrorCallback> pair = i.next();
|
||||
pair.second.onError(error);
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
|
||||
public void responseResponse(T success) {
|
||||
Iterator<Pair<NetworkCallback<T>, NetworkErrorCallback>> i;
|
||||
for (i = this.iterator(); i.hasNext();) {
|
||||
Pair<NetworkCallback<T>, NetworkErrorCallback> pair = i.next();
|
||||
pair.first.onResponse(success);
|
||||
i.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,9 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import androidx.annotation.ArrayRes;
|
||||
import androidx.annotation.StringRes;
|
||||
import androidx.preference.PreferenceManager;
|
||||
|
||||
public class Preferences {
|
||||
@@ -9,4 +11,24 @@ public class Preferences {
|
||||
String[] strings = context.getResources().getStringArray(key);
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getString(strings[0], strings[1]);
|
||||
}
|
||||
|
||||
public static long getLong(Context context, @StringRes int key) {
|
||||
String string = context.getResources().getString(key);
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getLong(string, 0);
|
||||
}
|
||||
|
||||
public static void setLong(Context context, @StringRes int key, long value) {
|
||||
String string = context.getResources().getString(key);
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putLong(string, value).apply();
|
||||
}
|
||||
|
||||
public static boolean getBoolean(Context context, @StringRes int key) {
|
||||
String string = context.getResources().getString(key);
|
||||
return PreferenceManager.getDefaultSharedPreferences(context).getBoolean(string, false);
|
||||
}
|
||||
|
||||
public static void setBoolean(Context context, @StringRes int key, boolean value) {
|
||||
String string = context.getResources().getString(key);
|
||||
PreferenceManager.getDefaultSharedPreferences(context).edit().putBoolean(string, value).apply();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ public abstract class SortedList<T, I, F> implements Iterable<T>, Serializable {
|
||||
};
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return this.internalList.toString();
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
package de.sebse.fuplanner.tools;
|
||||
|
||||
public class Triplet<T, U, V> {
|
||||
|
||||
public final T first;
|
||||
public final U second;
|
||||
public final V third;
|
||||
|
||||
public Triplet(T first, U second, V third) {
|
||||
this.first = first;
|
||||
this.second = second;
|
||||
this.third = third;
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import android.os.Build;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.format.DateFormat;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
@@ -65,4 +66,17 @@ public class UtilsDate {
|
||||
public static boolean dateEquals(long a, long b) {
|
||||
return a / 86400000 == b / 86400000;
|
||||
}
|
||||
|
||||
public static long stringToMillis(String dateString, String format) {
|
||||
try {
|
||||
@SuppressLint("SimpleDateFormat") SimpleDateFormat sdf = new SimpleDateFormat(format);
|
||||
Date date = sdf.parse(dateString);
|
||||
|
||||
return date.getTime();
|
||||
|
||||
} catch (ParseException e) {
|
||||
e.printStackTrace();
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,6 +32,11 @@ public class Logger {
|
||||
longLog(concat(msg), Log::e);
|
||||
}
|
||||
|
||||
public void t(Object... msg) {
|
||||
longLog(concat(msg), Log::e);
|
||||
new Error().printStackTrace();
|
||||
}
|
||||
|
||||
private void longLog(String content, LogInterface logInterface) {
|
||||
if (content.length() > 4000) {
|
||||
logInterface.run(tag, content.substring(0, 4000));
|
||||
|
||||
@@ -27,11 +27,11 @@ import de.sebse.fuplanner.tools.logging.Logger;
|
||||
public class HTTPService {
|
||||
private final RequestQueue requestQueue;
|
||||
private final Context mContext;
|
||||
protected Logger log = new Logger(this);
|
||||
private EventListener<VolleyError> errorResponseListener = new EventListener<>();
|
||||
private EventListener<Result> successResponseListener = new EventListener<>();
|
||||
protected final Logger log = new Logger(this);
|
||||
private final EventListener<VolleyError> errorResponseListener = new EventListener<>();
|
||||
private final EventListener<Result> successResponseListener = new EventListener<>();
|
||||
|
||||
protected HTTPService(Context context) {
|
||||
public HTTPService(Context context) {
|
||||
this.mContext = context;
|
||||
requestQueue = Volley.newRequestQueue(context, new BetterHurlStack(false));
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package de.sebse.fuplanner.tools.network;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
/**
|
||||
* Created by sebastian on 24.10.17.
|
||||
*/
|
||||
@@ -27,6 +29,7 @@ public class NetworkError {
|
||||
return message;
|
||||
}
|
||||
|
||||
@NonNull
|
||||
public String toString() {
|
||||
return String.valueOf(getCode()) + " - " + getHttpStatus() + " - " + getMessage();
|
||||
}
|
||||
|
||||
46
app/src/main/java/de/sebse/fuplanner/tools/types/News.java
Normal file
46
app/src/main/java/de/sebse/fuplanner/tools/types/News.java
Normal file
@@ -0,0 +1,46 @@
|
||||
package de.sebse.fuplanner.tools.types;
|
||||
|
||||
public class News {
|
||||
public static final int CATEGORY_TRICKS = 0;
|
||||
public static final int CATEGORY_UPDATE = 1;
|
||||
|
||||
private String title;
|
||||
private int category;
|
||||
private long date;
|
||||
private String text;
|
||||
|
||||
public News(String title, int category, long date, String text) {
|
||||
this.title = title;
|
||||
this.category = category;
|
||||
this.date = date;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getTitle() {
|
||||
return title;
|
||||
}
|
||||
|
||||
public int getCategory() {
|
||||
return category;
|
||||
}
|
||||
|
||||
public long getDate() {
|
||||
return date;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return text;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "News{" +
|
||||
"title='" + title + '\'' +
|
||||
", category=" + category +
|
||||
", date=" + date +
|
||||
", text='" + text + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
package de.sebse.fuplanner.tools.types;
|
||||
|
||||
import de.sebse.fuplanner.tools.DateSortedList;
|
||||
|
||||
public class NewsList extends DateSortedList<News> {
|
||||
@Override
|
||||
protected long getDateByItem(News item) {
|
||||
return item.getDate();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean reversed() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import android.widget.TextView;
|
||||
|
||||
import com.cunoraz.tagview.TagView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import de.sebse.fuplanner.R;
|
||||
|
||||
public class AnnouncementViewHolder extends ExpandableCardViewHolder {
|
||||
@@ -25,6 +26,7 @@ public class AnnouncementViewHolder extends ExpandableCardViewHolder {
|
||||
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String toString() {
|
||||
return super.toString() + " '" + mTitle.getText() + "' '" + mSubTitle.getText() + "'";
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user