56 Commits

Author SHA1 Message Date
Caesar2011
6325f312ea unfinished code 2019-01-07 13:25:24 +01:00
Caesar2011
e0ed23dec5 Still unfinished JSON converter 2019-01-04 15:02:07 +01:00
Caesar2011
bb85911324 Unfinished, unusable code 2019-01-04 00:06:11 +01:00
Sebastian Seedorf
1ed6522ac4 Listener optimization 2019-01-03 12:55:23 +01:00
Sebastian Seedorf
f646dd485d Removed unused imports 2019-01-03 12:44:34 +01:00
Sebastian Seedorf
73f9485394 Removed unused Offline Mode 2019-01-03 11:59:24 +01:00
Sebastian Seedorf
22f7cf3e96 renamed packages 2019-01-03 10:01:47 +01:00
Sebastian Seedorf
4db38ba4fb GoogleAuth removed 2019-01-03 09:55:05 +01:00
Caesar2011
6306cc9c77 Implemented Sync Adapter 2019-01-03 01:02:11 +01:00
Caesar2011
8160ef12b1 Login Bugs removed 2018-12-19 15:46:12 +01:00
Caesar2011
4d22613672 Login Improved; Still Bug when re-login 2018-12-19 01:08:39 +01:00
Caesar2011
fd18e4b61a Login Finished 2018-12-18 23:54:21 +01:00
Caesar2011
cde5fc3582 Login Testing 2018-12-17 16:14:50 +01:00
Caesar2011
c807dda73c Activity Active Bugfix 2018-12-06 13:32:39 +01:00
Joshua
797e848900 Login Authenticator Added 2018-12-03 18:32:06 +01:00
Caesar2011
2dbfd0141a Minor Time and Save Bugfix 2018-11-27 18:11:42 +01:00
Caesar2011
9b39563474 More time to leave 2018-11-27 16:32:34 +01:00
Caesar2011
8791d65d96 Changed Canteen Listener 2018-11-21 22:56:19 +01:00
Caesar2011
6bd99c59a8 Version 16 2018-11-21 17:54:46 +01:00
Caesar2011
6b117997c3 Resized Resource strings 2018-11-21 17:54:20 +01:00
Caesar2011
4c012ed2ba Fixed NullPointerException 2018-11-21 17:53:49 +01:00
Caesar2011
5209491287 Version 15 2018-11-21 13:41:53 +01:00
Caesar2011
4812336cc7 Schedule Left-Right-Bugfix 2018-11-21 13:32:11 +01:00
Caesar2011
4fe6dee4c8 Version 14 2018-11-21 13:14:42 +01:00
Caesar2011
2aad0f19a3 Updated News 2018-11-21 12:26:19 +01:00
Caesar2011
a79f59c66c Improved Schedule Double Tap Listener 2018-11-18 21:51:20 +01:00
Caesar2011
2d160d3b38 Design Update 3 2018-11-18 20:49:28 +01:00
Caesar2011
6acea97458 Merge remote-tracking branch 'origin/master' 2018-11-18 20:34:58 +01:00
Caesar2011
c6f032f92e Design Update 2018-11-18 20:34:35 +01:00
Caesar2011
544162bb47 Design Update 2018-11-18 20:30:23 +01:00
Caesar2011
d5e08ac3c3 Version 13 2018-11-18 19:30:43 +01:00
Caesar2011
671c9bd86a News Show Notification on Sidebar 2018-11-18 19:23:22 +01:00
Caesar2011
35141bc1ec Back Button Implemented! Finally! Finally! Finally! 2018-11-18 16:49:02 +01:00
Caesar2011
d62256f1db Implemented Shortcuts 2018-11-18 14:55:03 +01:00
Caesar2011
0adeca7367 Better NavigationDrawer Item Display 2018-11-18 14:08:06 +01:00
Caesar2011
0b32f8e9f8 News Translatable 2018-11-18 13:56:21 +01:00
Caesar2011
4d9b2200d3 News Data 2018-11-18 12:31:12 +01:00
Caesar2011
50d07193a0 Implemented News with Demo Entries 2018-11-18 11:12:13 +01:00
Caesar2011
8e3360549f DateSortedList Sorting bug fix 2018-11-17 11:52:08 +01:00
Caesar2011
7679135af1 Added News Fragment 2018-11-17 00:40:16 +01:00
Caesar2011
6523d82d6b Code cleanup 2018-11-17 00:08:08 +01:00
Caesar2011
7a7e56bdf5 Resource list icon color adjusted 2018-11-16 23:24:08 +01:00
Caesar2011
14b38f22a3 Fixed Re-login Bug 2018-11-16 23:23:16 +01:00
Caesar2011
1d90b3e9da Merge remote-tracking branch 'origin/master' 2018-11-16 22:13:34 +01:00
Caesar2011
b6deff7b99 Version 12 2018-11-16 22:13:15 +01:00
Caesar2011
dd7e9a910c Removed Debug Resource 2018-11-16 21:51:15 +01:00
Caesar2011
3aa07e0a6d Removed Slashes 2018-11-15 18:36:56 +01:00
Caesar2011
9a1892db0a Update All Parts in Module; Removed Logs 2018-11-15 18:31:37 +01:00
Caesar2011
5ba6c899be Event List Design updated 2018-11-15 18:06:56 +01:00
Caesar2011
547a62d07b Version 11 2018-11-14 01:46:20 +01:00
Caesar2011
d9e2911554 Caption Corrected 2018-11-14 01:46:07 +01:00
Caesar2011
2e96d205d6 Merge branch 'newkvv'
# Conflicts:
#	app/src/main/java/de/sebse/fuplanner/fragments/moddetails/ModDetailAnnounceFragment.java
#	app/src/main/java/de/sebse/fuplanner/fragments/moddetails/ModDetailAssignmentFragment.java
#	app/src/main/java/de/sebse/fuplanner/services/KVV/KVVModuleList.java
2018-11-14 01:27:57 +01:00
Caesar2011
17c093c040 Version 10 - Fixed Download 2018-11-08 21:59:23 +01:00
Caesar2011
a1ce5c644a Download not working 2018-11-08 21:52:47 +01:00
Caesar2011
2d1d8e1e8b Version 10 2018-11-08 20:59:35 +01:00
Joshua
959733a3c9 bug fix beim laden der Module 2018-11-08 18:31:15 +01:00
169 changed files with 3304 additions and 1714 deletions

1
.gitignore vendored
View File

@@ -7,3 +7,4 @@
/build
/captures
.externalNativeBuild
app/release/*

View File

@@ -7,8 +7,8 @@ android {
applicationId "de.sebse.fuplanner"
minSdkVersion 15
targetSdkVersion 28
versionCode 10
versionName "1.2.2"
versionCode 16
versionName "1.3.5"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
buildTypes {

View File

@@ -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>

View File

@@ -1,5 +1,6 @@
package de.sebse.fuplanner;
import android.accounts.AccountManager;
import android.content.Intent;
import android.os.Bundle;
import android.view.Menu;
@@ -11,8 +12,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 +29,33 @@ 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.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.news.NewsManager;
import de.sebse.fuplanner.services.fulogin.AccountGeneral;
import de.sebse.fuplanner.tools.CustomAccountManager;
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 +64,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 +116,91 @@ 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);
}
@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());
}
});
}
isPaused = false;
}
@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 +246,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 +262,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 +277,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 +304,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 +329,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);
@@ -307,18 +371,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 +406,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 +489,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 +509,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 +525,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 +574,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 +600,7 @@ public class MainActivity extends AppCompatActivity
}
@Override
public void onRefreshCompleted(boolean isFailed) {
public void onCanteenRefreshCompleted(boolean isFailed) {
setRefreshFailedBanner(isFailed);
}
@@ -537,20 +633,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 +653,9 @@ public class MainActivity extends AppCompatActivity
public void onKVVNetworkResponse(NetworkResponse error) {
setRefreshFailedBanner(error != null);
}
@Override
public CustomAccountManager getAccountManager() {
return mAccountManager;
}
}

View File

@@ -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> {

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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;

View File

@@ -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);

View File

@@ -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;
}
}

View File

@@ -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);
}
}

View File

@@ -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());
}

View File

@@ -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 {

View File

@@ -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;
}
}
}

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;
/**

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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();
}

View File

@@ -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;

View File

@@ -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("");
}
}

View File

@@ -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;
}
}
}

View File

@@ -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);

View File

@@ -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);

View File

@@ -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() + "'";

View File

@@ -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);

View File

@@ -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 -> {

View File

@@ -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;
}

View File

@@ -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;

View File

@@ -1,9 +0,0 @@
package de.sebse.fuplanner.services.GoogleAuth;
/**
* Created by sebastian on 07.11.17.
*/
public interface ConnectedListener {
void connected();
}

View File

@@ -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;
}
}

View File

@@ -1,9 +0,0 @@
package de.sebse.fuplanner.services.GoogleAuth;
/**
* Created by Sebastian on 06.11.2017.
*/
public interface CredentialsListener {
void onCredentials(Credentials credentials);
}

View File

@@ -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();
}
}

View File

@@ -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;
}

View File

@@ -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);
}

View File

@@ -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);
}
}

View File

@@ -1,170 +0,0 @@
package de.sebse.fuplanner.services.KVV.types;
import android.content.Context;
import org.jetbrains.annotations.NotNull;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
/**
* Created by sebastian on 29.10.17.
*/
public class Modules implements Iterable<Modules.Module>, Serializable {
private SortedListModule list;
private final String mUsername;
//private transient Logger log = new Logger(this);
private static final String FILE_NAME = "ModuleListSaving";
public Modules(String username) {
this.mUsername = username;
this.list = new SortedListModule();
}
public void addModule(@Nullable Semester semester, HashSet<String> lvNumber, String title, LinkedHashSet<Lecturer> lecturer, String type, String description, String ID) {
Module m = new Module(semester, lvNumber, title, lecturer, type, description, ID);
this.list.add(m);
}
@NonNull
@Override
public String toString() {
return this.list.toString();
}
@NonNull
@Override
public Iterator<Module> iterator() {
return this.list.iterator();
}
public Iterator<Module> latestSemesterIterator() {
return this.list.filteredIterator(this.list.getLatestSemester());
}
public int size() {
return this.list.size();
}
public Module get(String id) {
return this.list.getById(id);
}
public Module getByIndex(int index) {
return this.list.get(index);
}
public static Modules load(Context context) throws IOException, ClassNotFoundException {
FileInputStream fis = context.openFileInput(FILE_NAME);
ObjectInputStream is = new ObjectInputStream(fis);
Object readObject = is.readObject();
if (!(readObject instanceof Modules))
return null;
Modules modules = (Modules) readObject;
is.close();
fis.close();
return modules;
}
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 String getUsername() {
return mUsername;
}
public void updateList(Modules modules) {
SortedListModule old = this.list;
this.list = modules.list;
for (Module oldModule : old) {
Module newModule = this.list.getById(oldModule.getID());
if (newModule != null) {
newModule.announcements = oldModule.announcements;
newModule.assignments = oldModule.assignments;
newModule.events = oldModule.events;
newModule.gradebook = oldModule.gradebook;
newModule.resources = oldModule.resources;
}
}
}
public class Module implements Serializable {
@Nullable public final Semester semester;
@NotNull final HashSet<String> lvNumber;
@NotNull public final String title;
@NotNull
public final ArrayList<Lecturer> lecturer;
@Nullable public final String type;
@Nullable public final String description;
@NotNull private final String ID;
@Nullable public ArrayList<Announcement> announcements;
@Nullable public AssignmentList assignments;
@Nullable public EventList events;
@Nullable public ArrayList<Grade> gradebook;
@Nullable public ArrayList<Resource> resources;
public float getGradebookPercent(){
float maxPoint = 0;
float userPoint = 0;
if (gradebook != null) {
for (Grade g : gradebook){
maxPoint += g.getMaxPoints();
userPoint += g.getPoints();
}
}
if (maxPoint == 0)
return 0;
return userPoint/maxPoint;
}
private Module(@Nullable Semester semester, @NotNull HashSet<String> lvNumber, @NotNull String title, @NotNull LinkedHashSet<Lecturer> lecturer, @Nullable String type, @Nullable String description, @NotNull String ID) {
title = title.replaceAll("(.*?) (S[0-9]{2}|W[0-9/]{5})", "$1");
this.semester = semester;
this.lvNumber = lvNumber;
this.title = title;
this.lecturer = new ArrayList<>(lecturer);
this.type = type;
this.description = description;
this.ID = ID;
}
@NonNull
public String getID() {
return ID;
}
@NonNull
@Override
public String toString() {
return "Semester: "+semester+
"\nlvNumber: "+lvNumber.toString()+
"\ntitle: "+title+
"\nlecturer: "+lecturer.toString()+
"\ntype: "+type+
"\nID: "+ID;
}
}
}

View File

@@ -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);
});
}

View File

@@ -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";

View File

@@ -0,0 +1,5 @@
package de.sebse.fuplanner.services.canteen.types;
public interface CanteenListener {
void onCanteenRefreshCompleted(boolean b);
}

View File

@@ -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();

View File

@@ -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";

View File

@@ -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 + ")";

View File

@@ -1,4 +1,4 @@
package de.sebse.fuplanner.services.Canteen.types;
package de.sebse.fuplanner.services.canteen.types;
import de.sebse.fuplanner.tools.SortedList;

View File

@@ -1,4 +1,4 @@
package de.sebse.fuplanner.services.Canteen.types;
package de.sebse.fuplanner.services.canteen.types;
import java.util.Calendar;

View File

@@ -1,4 +1,4 @@
package de.sebse.fuplanner.services.Canteen.types;
package de.sebse.fuplanner.services.canteen.types;
import de.sebse.fuplanner.tools.SortedList;

View File

@@ -0,0 +1,7 @@
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";
}

View File

@@ -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;
}
}

View File

@@ -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();
}
}

View File

@@ -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();
}
}

View File

@@ -0,0 +1,124 @@
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 -> latch.countDown());
}, 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);
}
}

View File

@@ -1,4 +1,4 @@
package de.sebse.fuplanner.services.KVV;
package de.sebse.fuplanner.services.kvv;
import android.content.Context;

View File

@@ -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();
}

View 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);
}
}

View File

@@ -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) {

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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;

View File

@@ -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);
@@ -51,7 +51,7 @@ public class ModulesList extends HTTPService {
}
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 +104,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 +115,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 +139,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 +164,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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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);

View File

@@ -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 {
private static final String PROVIDER_NAME = "de.sebse.fuplanner.contentprovider.kvv.modules";
private static final Uri CONTENT_URI = Uri.parse("content://" + PROVIDER_NAME + "/modules");
private static final 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;
}
}

View File

@@ -0,0 +1,87 @@
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 com.android.volley.NetworkResponse;
import java.util.Iterator;
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.tools.CustomAccountManager;
import de.sebse.fuplanner.tools.logging.Logger;
public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
private KVV mKVV;
private Logger log = new Logger(this);
/**
* 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);
mKVV.account().restoreOnlineLogin(bool -> {});
}
/*
* 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("start syncing");
/*
* Put the data transfer code here.
*/
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);
mKVV.modules().details().recv(module, success1 -> {
if (success1.second)
log.d("Sync Successful for Module '"+module.title+"'!");
}, log::e, true);
}
}, log::e, true);
}
}

View File

@@ -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();
}
}

View File

@@ -1,130 +1,28 @@
package de.sebse.fuplanner.services.KVV;
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.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.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) {
public Login(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) {
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) {
@@ -143,46 +41,6 @@ public class Login extends HTTPService {
}, 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();
}
@@ -193,7 +51,11 @@ public class Login extends HTTPService {
private void doLogin(String username, String password, NetworkCallback<LoginToken> callback, NetworkErrorCallback error) {
public 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 -> {

View File

@@ -1,11 +1,17 @@
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 org.json.JSONException;
import org.json.JSONObject;
public class Announcement implements Serializable {
import java.util.ArrayList;
import java.util.HashSet;
import androidx.annotation.NonNull;
import de.sebse.fuplanner.tools.UtilsJson;
public class Announcement implements UtilsJson.JsonConvertible {
private final String id;
private final String title;
private final String body;
@@ -14,7 +20,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;
@@ -23,6 +28,19 @@ public class Announcement implements Serializable {
this.urls = urls;
}
public Announcement(JSONObject json) throws JSONException {
this.id = json.getString("id");
this.title = json.getString("title");
this.body = json.getString("body");
this.createdBy = json.getString("createdBy");
this.createdOn = json.getLong("createdOn");
ArrayList<String> urls = new ArrayList<>();
for (String url: UtilsJson.jsonArrayToIterableString(json.getJSONArray("urls"))) {
urls.add(url);
}
this.urls = urls;
}
public ArrayList<String> getUrls() {
return urls;
}
@@ -47,6 +65,7 @@ public class Announcement implements Serializable {
return createdOn;
}
@NonNull
@Override
public String toString() {
return "ID: "+getId()+
@@ -61,4 +80,16 @@ public class Announcement implements Serializable {
public int hashCode() {
return Objects.hashCode(getId(), getBody(), getCreatedBy(), getCreatedOn(), getTitle(), getUrls());
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("title", title);
json.put("body", body);
json.put("createdBy", createdBy);
json.put("createdOn", createdOn);
json.put("urls", UtilsJson.collectionToJson(urls));
return json;
}
}

View File

@@ -1,11 +1,16 @@
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 org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
public class Assignment implements Serializable {
import androidx.annotation.NonNull;
import de.sebse.fuplanner.tools.UtilsJson;
public class Assignment implements UtilsJson.JsonConvertible {
private final String id;
private final String title;
private final long dueTime;
@@ -44,6 +49,7 @@ public class Assignment implements Serializable {
return instructions;
}
@NonNull
@Override
public String toString() {
return "ID: "+getId()+
@@ -56,4 +62,15 @@ public class Assignment implements Serializable {
public int hashCode() {
return Objects.hashCode(getId(), getDueDate(), getInstructions(), getTitle(), getUrls());
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("id", id);
json.put("title", title);
json.put("dueTime", dueTime);
json.put("createdBy", UtilsJson.collectionToJson(urls));
json.put("instructions", instructions);
return json;
}
}

View File

@@ -1,4 +1,4 @@
package de.sebse.fuplanner.services.KVV.types;
package de.sebse.fuplanner.services.kvv.types;
import de.sebse.fuplanner.tools.DateSortedList;

View File

@@ -1,15 +1,19 @@
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 org.json.JSONException;
import org.json.JSONObject;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import androidx.annotation.NonNull;
import de.sebse.fuplanner.tools.ColorRGB;
import de.sebse.fuplanner.tools.UtilsJson;
public class Event implements Serializable {
public class Event implements UtilsJson.JsonConvertible {
private final String siteId;
private final String id;
private final String type;
@@ -106,6 +110,7 @@ public class Event implements Serializable {
}
}
@NonNull
@Override
public String toString() {
return "ID: "+getId()+
@@ -118,4 +123,17 @@ public class Event implements Serializable {
public int hashCode() {
return Objects.hashCode(getId(), getType(), getStartDate(), getEndDate(), getTitle(), getLocation());
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("siteId", siteId);
json.put("id", id);
json.put("type", type);
json.put("title", title);
json.put("duration", duration);
json.put("firstTime", firstTime);
json.put("location", location);
return json;
}
}

View File

@@ -1,4 +1,4 @@
package de.sebse.fuplanner.services.KVV.types;
package de.sebse.fuplanner.services.kvv.types;
import de.sebse.fuplanner.tools.DateSortedList;

View File

@@ -1,10 +1,14 @@
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 org.json.JSONException;
import org.json.JSONObject;
public class Grade implements Serializable {
import androidx.annotation.NonNull;
import de.sebse.fuplanner.tools.UtilsJson;
public class Grade implements UtilsJson.JsonConvertible {
private final String itemName;
private final double grade;
private final double maxPoints;
@@ -27,6 +31,7 @@ public class Grade implements Serializable {
return itemName;
}
@NonNull
@Override
public String toString() {
return "Name: "+getItemName()+
@@ -38,4 +43,13 @@ public class Grade implements Serializable {
public int hashCode() {
return Objects.hashCode(getItemName(), getPoints(), getMaxPoints());
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("itemName", itemName);
json.put("grade", grade);
json.put("maxPoints", maxPoints);
return json;
}
}

View File

@@ -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;
}

View File

@@ -1,10 +1,17 @@
package de.sebse.fuplanner.services.KVV.types;
package de.sebse.fuplanner.services.kvv.types;
import com.google.android.gms.common.internal.Objects;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.Serializable;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class Lecturer implements Serializable {
import androidx.annotation.NonNull;
import de.sebse.fuplanner.tools.UtilsJson;
public class Lecturer implements UtilsJson.JsonConvertible {
private final String firstName;
private final String surname;
private final String mail;
@@ -22,6 +29,13 @@ public class Lecturer implements Serializable {
this.isResponsible = matcher.group(4).equals("true");
}
public Lecturer(JSONObject json) throws JSONException {
this.firstName = json.getString("firstName");
this.surname = json.getString("surname");
this.mail = json.getString("mail");
this.isResponsible = json.getBoolean("isResponsible");
}
public String getFirstName() {
return firstName;
}
@@ -46,10 +60,26 @@ public class Lecturer implements Serializable {
return getFirstName().substring(0, 1) + ". " + getSurname();
}
@NonNull
@Override
public String toString() {
return "First name: "+ getFirstName()+
"\nSurname: "+getSurname()+
"\nMail: "+getMail();
}
@Override
public int hashCode() {
return Objects.hashCode(getFirstName(), getSurname(), getMail(), isResponsible());
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("firstName", firstName);
json.put("surname", surname);
json.put("mail", mail);
json.put("isResponsible", isResponsible);
return json;
}
}

View File

@@ -0,0 +1,148 @@
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 {
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);
}
}

View File

@@ -0,0 +1,317 @@
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 org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStreamWriter;
import java.lang.reflect.Array;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashSet;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import de.sebse.fuplanner.tools.UtilsJson;
import static de.sebse.fuplanner.tools.UtilsJson.collectionToJson;
import static de.sebse.fuplanner.tools.UtilsJson.jsonArrayToIterableObject;
/**
* Created by sebastian on 29.10.17.
*/
public class Modules implements Iterable<Modules.Module> {
private SortedListModule list;
private final String mUsername;
private long mLoadTime;
//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;
this.list = new SortedListModule();
}
public void addModule(@Nullable Semester semester, HashSet<String> lvNumber, String title, LinkedHashSet<Lecturer> lecturer, String type, String description, String ID) {
Module m = new Module(semester, lvNumber, title, lecturer, type, description, ID);
this.list.add(m);
}
@NonNull
@Override
public String toString() {
return this.list.toString();
}
@NonNull
@Override
public Iterator<Module> iterator() {
return this.list.iterator();
}
public Iterator<Module> latestSemesterIterator() {
return this.list.filteredIterator(this.list.getLatestSemester());
}
public int size() {
return this.list.size();
}
public Module get(String id) {
return this.list.getById(id);
}
public Module getByIndex(int index) {
return this.list.get(index);
}
public static Modules load(Context context) throws IOException {
String ret = "";
InputStream inputStream = context.openFileInput(FILE_NAME);
if (inputStream != null) {
InputStreamReader inputStreamReader = new InputStreamReader(inputStream);
BufferedReader bufferedReader = new BufferedReader(inputStreamReader);
String receiveString;
StringBuilder stringBuilder = new StringBuilder();
while ((receiveString = bufferedReader.readLine()) != null) {
stringBuilder.append(receiveString);
}
inputStream.close();
ret = stringBuilder.toString();
}
try {
JSONObject json = new JSONObject(ret);
Modules mod = new Modules(json.getString("username"));
JSONArray arr = json.getJSONArray("modules");
for (JSONObject jsonObject: jsonArrayToIterableObject(arr)) {
mod.list.add(new Module(jsonObject));
}
FileInputStream ofi = context.openFileInput(FILE_NAME_TIMESTAMP);
ObjectInputStream inputStream1 = new ObjectInputStream(ofi);
mod.mLoadTime = inputStream1.readLong();
return mod;
} catch (JSONException e) {
e.printStackTrace();
}
return null;
}
public void save(Context context) throws IOException {
JSONObject json = new JSONObject();
try {
json.put("username", mUsername);
json.put("modules", UtilsJson.collectionToJson(list));
OutputStreamWriter osw = new OutputStreamWriter(context.openFileOutput(FILE_NAME, Context.MODE_PRIVATE));
osw.write(json.toString());
osw.close();
} catch (JSONException e) {
e.printStackTrace();
}
mLoadTime = System.currentTimeMillis();
FileOutputStream ofo = context.openFileOutput(FILE_NAME_TIMESTAMP, Context.MODE_PRIVATE);
ObjectOutputStream outputStream = new ObjectOutputStream(ofo);
outputStream.writeLong(mLoadTime);
}
public void delete(Context context) {
context.deleteFile(FILE_NAME);
}
public String getUsername() {
return mUsername;
}
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;
}
}
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 static class Module implements UtilsJson.JsonConvertible {
@Nullable public final Semester semester;
@NotNull final HashSet<String> lvNumber;
@NotNull public final String title;
@NotNull public final ArrayList<Lecturer> lecturer;
@Nullable public final String type;
@Nullable public final String description;
@NotNull private final String ID;
@Nullable public ArrayList<Announcement> announcements;
@Nullable public AssignmentList assignments;
@Nullable public EventList events;
@Nullable public ArrayList<Grade> gradebook;
@Nullable public ArrayList<Resource> resources;
@Override
public int hashCode() {
return Objects.hashCode(semester, lvNumber, title, lecturer, type, description, ID);
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("semester", semester != null ? semester.toJSONObject() : null);
json.put("lvNumber", collectionToJson(lvNumber));
json.put("title", title);
json.put("lecturer", collectionToJson(lecturer));
json.put("type", type);
json.put("description", description);
json.put("ID", ID);
json.put("announcements", collectionToJson(announcements));
json.put("assignments", collectionToJson(assignments));
json.put("events", collectionToJson(events));
json.put("gradebook", collectionToJson(gradebook));
json.put("resources", collectionToJson(resources));
return json;
}
public float getGradebookPercent(){
float maxPoint = 0;
float userPoint = 0;
if (gradebook != null) {
for (Grade g : gradebook){
maxPoint += g.getMaxPoints();
userPoint += g.getPoints();
}
}
if (maxPoint == 0)
return 0;
return userPoint/maxPoint;
}
private Module(@Nullable Semester semester, @NotNull HashSet<String> lvNumber, @NotNull String title, @NotNull LinkedHashSet<Lecturer> lecturer, @Nullable String type, @Nullable String description, @NotNull String ID) {
title = title.replaceAll("(.*?) (S[0-9]{2}|W[0-9/]{5})", "$1");
this.semester = semester;
this.lvNumber = lvNumber;
this.title = title;
this.lecturer = new ArrayList<>(lecturer);
this.type = type;
this.description = description;
this.ID = ID;
}
private Module(@NotNull JSONObject json) throws JSONException {
HashSet<String> lv = new HashSet<>();
for (String number: UtilsJson.jsonArrayToIterableString(json.getJSONArray("lvNumber"))) {
lv.add(number);
}
LinkedHashSet<Lecturer> lecturer = new LinkedHashSet<>();
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(json.getJSONArray("lecturer"))) {
lecturer.add(new Lecturer(l));
}
JSONObject obj = json.optJSONObject("semester");
this.semester = obj != null ? new Semester(obj) : null;
this.lvNumber = lv;
this.title = json.getString("title");
this.lecturer = new ArrayList<>(lecturer);
this.type = json.getString("type");
this.description = json.getString("description");
this.ID = json.getString("ID");
JSONArray arr = json.optJSONArray("announcements");
if (obj != null) {
ArrayList<Announcement> announce = new ArrayList<>();
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
announce.add(new Announcement(l));
}
this.announcements = announce;
}
arr = json.optJSONArray("assignments");
if (obj != null) {
AssignmentList assign = new AssignmentList();
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
assign.add(new Assignment(l));
}
this.assignments = assign;
}
arr = json.optJSONArray("events");
if (obj != null) {
EventList events = new EventList();
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
events.add(new Event(l));
}
this.events = events;
}
arr = json.optJSONArray("gradebook");
if (obj != null) {
ArrayList<Grade> grades = new ArrayList<>();
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
grades.add(new Grade(l));
}
this.gradebook = grades;
}
arr = json.optJSONArray("resources");
if (obj != null) {
ArrayList<Resource> res = new ArrayList<>();
for (JSONObject l: UtilsJson.jsonArrayToIterableObject(arr)) {
if (l.getString("restype").equals("file"))
res.add(new Resource.File(l));
else
res.add(new Resource.Folder(l));
}
this.resources = res;
}
}
@NonNull
public String getID() {
return ID;
}
@NonNull
@Override
public String toString() {
return "Semester: "+semester+
"\nlvNumber: "+lvNumber.toString()+
"\ntitle: "+title+
"\nlecturer: "+lecturer.toString()+
"\ntype: "+type+
"\nID: "+ID;
}
}
}

View File

@@ -1,17 +1,21 @@
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 org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import androidx.annotation.LayoutRes;
import androidx.annotation.NonNull;
import de.sebse.fuplanner.R;
import de.sebse.fuplanner.tools.UtilsJson;
import de.sebse.fuplanner.tools.ui.treeview.LayoutItemType;
import de.sebse.fuplanner.tools.ui.treeview.TreeNode;
public abstract class Resource implements Serializable {
public abstract class Resource implements UtilsJson.JsonConvertible {
final String author;
final long modifiedDate;
@@ -61,6 +65,19 @@ public abstract class Resource implements Serializable {
return Objects.hashCode(getAuthor(), getContainer(), getModifiedDate(), getTitle(), getUrl());
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("author", author);
json.put("modifiedDate", modifiedDate);
json.put("title", title);
json.put("url", url);
json.put("visible", visible);
json.put("container", container);
json.put("restype", "");
return json;
}
public static class File extends Resource implements LayoutItemType {
private final String type;
@@ -69,6 +86,7 @@ public abstract class Resource implements Serializable {
this.type = type;
}
@NonNull
@Override
public String toString() {
return "Resource{" +
@@ -89,6 +107,14 @@ public abstract class Resource implements Serializable {
public @LayoutRes int getLayoutId() {
return R.layout.item_file;
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = super.toJSONObject();
json.put("type", type);
json.put("restype", "file");
return json;
}
}
public static class Folder extends Resource implements LayoutItemType {
@@ -111,6 +137,7 @@ public abstract class Resource implements Serializable {
return children.size();
}
@NonNull
@Override
public String toString() {
return "Resource{" +
@@ -135,6 +162,14 @@ public abstract class Resource implements Serializable {
public @LayoutRes int getLayoutId() {
return R.layout.item_dir;
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = super.toJSONObject();
json.put("children", UtilsJson.collectionToJson(children));
json.put("restype", "dir");
return json;
}
}
}

View File

@@ -1,11 +1,13 @@
package de.sebse.fuplanner.services.KVV.types;
package de.sebse.fuplanner.services.kvv.types;
import java.io.Serializable;
import org.json.JSONException;
import org.json.JSONObject;
import androidx.annotation.Nullable;
import de.sebse.fuplanner.tools.Regex;
import de.sebse.fuplanner.tools.UtilsJson;
public class Semester implements Serializable {
public class Semester implements UtilsJson.JsonConvertible {
public static final int SEM_WS = 1;
public static final int SEM_SS = 2;
private int type;
@@ -17,25 +19,17 @@ public class Semester implements Serializable {
}
public Semester(String semester_string) throws NoSuchFieldException {
/*Semester sem = null;
if (semester != null) {
sem = new Semester(semester)
semester = semester.replace("SS", "S");
semester = semester.replaceAll("[0-9]{2}([0-9]{2})", "$1");
}*/
/*String s1type = Regex.regex("^(S|WS) ", a);
int s1year = Integer.parseInt(Regex.regex("^(S|WS) ([0-9]{2})", a, 2));
String s2type = Regex.regex("^(S|WS) ", b);
int s2year = Integer.parseInt(Regex.regex("^(S|WS) ([0-9]{2})", b, 2));*/
String type = Regex.regex("^(SS|WS) ", semester_string);
String year = Regex.regex("^(SS|WS) ([0-9]{2})", semester_string, 2);
this.type = type.equals("SS") ? SEM_SS : SEM_WS;
this.year = Integer.parseInt(year);
}
public Semester(JSONObject json) throws JSONException {
this.type = json.getInt("type");
this.year = json.getInt("year");
}
public int getType() {
return type;
}
@@ -52,4 +46,12 @@ public class Semester implements Serializable {
}
return false;
}
@Override
public JSONObject toJSONObject() throws JSONException {
JSONObject json = new JSONObject();
json.put("type", type);
json.put("year", year);
return json;
}
}

View File

@@ -1,4 +1,7 @@
package de.sebse.fuplanner.services.KVV.types;
package de.sebse.fuplanner.services.kvv.types;
import org.json.JSONException;
import org.json.JSONObject;
import androidx.annotation.Nullable;
import de.sebse.fuplanner.tools.SortedList;

View File

@@ -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);
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,134 @@
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;
}
@FunctionalInterface
public interface ActivityInterface {
@Nullable
Activity get();
}
public interface StringInterface {
void run(@Nullable String string);
}
}

View File

@@ -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) {

View File

@@ -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);

View File

@@ -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);

View File

@@ -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();
}
}
}

View File

@@ -2,6 +2,7 @@ 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 +10,14 @@ 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();
}
}

View File

@@ -3,12 +3,11 @@ package de.sebse.fuplanner.tools;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
public abstract class SortedList<T, I, F> implements Iterable<T>, Serializable {
public abstract class SortedList<T, I, F> implements Iterable<T> {
private final ArrayList<T> internalList = new ArrayList<>();
@@ -120,6 +119,7 @@ public abstract class SortedList<T, I, F> implements Iterable<T>, Serializable {
};
}
@NonNull
@Override
public String toString() {
return this.internalList.toString();

View File

@@ -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;
}
}

View File

@@ -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;
}
}
}

View File

@@ -0,0 +1,109 @@
package de.sebse.fuplanner.tools;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
import java.util.Iterator;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
public class UtilsJson {
public static JSONArray collectionToJson(@Nullable HashSet<String> coll) {
if (coll == null)
return null;
JSONArray arr = new JSONArray();
for (String e: coll) {
arr.put(e);
}
return arr;
}
public static <E extends JsonConvertible> JSONArray collectionToJson(@Nullable Collection<E> coll) throws JSONException {
if (coll == null)
return null;
JSONArray arr = new JSONArray();
for (E e: coll) {
arr.put(e.toJSONObject());
}
return arr;
}
public static JSONArray collectionToJson(@Nullable ArrayList<String> coll) throws JSONException {
if (coll == null)
return null;
JSONArray arr = new JSONArray();
for (String e: coll) {
arr.put(e);
}
return arr;
}
public static <A extends JsonConvertible> JSONArray collectionToJson(@Nullable SortedList<A, ?, ?> coll) throws JSONException {
if (coll == null)
return null;
JSONArray arr = new JSONArray();
for (A e: coll) {
arr.put(e.toJSONObject());
}
return arr;
}
public static <T> Iterator<T> jsonArrayToIterator(JSONArray array, GetInterface<T> func) {
return new Iterator<T>() {
int size = array == null ? 0 : array.length();
int pos = 0;
@Override
public boolean hasNext() {
return pos < size;
}
@Override
public T next() {
try {
return func.get(array, pos++);
} catch (JSONException e) {
e.printStackTrace();
return null;
}
}
};
}
@FunctionalInterface
private interface GetInterface<T> {
T get(JSONArray array, int index) throws JSONException;
}
public static JsonIterable<JSONObject> jsonArrayToIterableObject(JSONArray array) {
return new JsonIterable<>(array, JSONArray::getJSONObject);
}
public static JsonIterable<String> jsonArrayToIterableString(JSONArray array) {
return new JsonIterable<>(array, JSONArray::getString);
}
public static class JsonIterable<T> implements Iterable<T> {
private JSONArray array;
private GetInterface<T> getInterface;
JsonIterable(JSONArray array, GetInterface<T> getInterface) {
this.array = array;
this.getInterface = getInterface;
}
@NonNull
@Override
public Iterator<T> iterator() {
return UtilsJson.jsonArrayToIterator(array, getInterface);
}
}
public interface JsonConvertible {
JSONObject toJSONObject() throws JSONException;
}
}

View File

@@ -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));

View File

@@ -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));
}

View File

@@ -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();
}

View 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 + '\'' +
'}';
}
}

View File

@@ -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;
}
}

View File

@@ -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