Network and Sync Stabilization
This commit is contained in:
@@ -94,12 +94,12 @@
|
||||
<orderEntry type="library" name="Gradle: androidx.lifecycle:lifecycle-common:2.1.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.arch.core:core-common:2.1.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.annotation:annotation:1.1.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout-solver:2.0.0-beta2@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout-solver:2.0.0-beta3@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: org.jetbrains:annotations-java5:15.0@jar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.preference:preference:1.1.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.google.android.material:material:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.recyclerview:recyclerview:1.0.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout:2.0.0-beta2@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.constraintlayout:constraintlayout:2.0.0-beta3@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.appcompat:appcompat:1.1.0@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: com.ms-square:expandableTextView:0.1.4@aar" level="project" />
|
||||
<orderEntry type="library" name="Gradle: androidx.legacy:legacy-support-core-ui:1.0.0@aar" level="project" />
|
||||
|
||||
@@ -13,8 +13,7 @@ android {
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
minifyEnabled true
|
||||
shrinkResources true
|
||||
minifyEnabled false
|
||||
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
|
||||
}
|
||||
}
|
||||
@@ -31,7 +30,7 @@ dependencies {
|
||||
implementation fileTree(include: ['*.jar'], dir: 'libs')
|
||||
implementation 'androidx.recyclerview:recyclerview:1.0.0'
|
||||
implementation 'androidx.preference:preference:1.1.0'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta2'
|
||||
implementation 'androidx.constraintlayout:constraintlayout:2.0.0-beta3'
|
||||
implementation 'androidx.appcompat:appcompat:1.1.0'
|
||||
implementation 'com.android.volley:volley:1.1.1'
|
||||
implementation 'com.github.Cutta:TagView:1.3'
|
||||
|
||||
@@ -189,7 +189,7 @@ public class MainActivity extends AppCompatActivity
|
||||
if (!mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
desiredPage = getDefaultFragmentAfterLogout();
|
||||
desiredData = "";
|
||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
|
||||
goToLoginScreen();
|
||||
updateNavigation();
|
||||
changeFragment(desiredPage, desiredData);
|
||||
} else {
|
||||
@@ -210,16 +210,10 @@ public class MainActivity extends AppCompatActivity
|
||||
|
||||
if (!mAlreadyCreated) {
|
||||
Intent serviceIntent = new Intent(this, KVV.class);
|
||||
bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
getApplicationContext().bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
mAlreadyCreated = true;
|
||||
|
||||
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup)) {
|
||||
registerSync(true);
|
||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
||||
} else {
|
||||
registerSync(false);
|
||||
}
|
||||
CustomNotificationManager.createNotificationChannel(this);
|
||||
/*getKVV(kvv -> {
|
||||
kvv.modules().list().recv(list -> {
|
||||
@@ -229,12 +223,17 @@ public class MainActivity extends AppCompatActivity
|
||||
});*/
|
||||
}
|
||||
|
||||
private void goToLoginScreen() {
|
||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, false);
|
||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStart() {
|
||||
super.onStart();
|
||||
if (!mAlreadyCreated) {
|
||||
Intent serviceIntent = new Intent(this, KVV.class);
|
||||
bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
getApplicationContext().bindService(serviceIntent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
}
|
||||
mAlreadyCreated = true;
|
||||
}
|
||||
@@ -245,7 +244,7 @@ public class MainActivity extends AppCompatActivity
|
||||
if (mKVV != null)
|
||||
mKVV.removeListener("mainactivity");
|
||||
if (mBound)
|
||||
unbindService(mConnection);
|
||||
getApplicationContext().unbindService(mConnection);
|
||||
mKVV = null;
|
||||
mBound = false;
|
||||
mAlreadyCreated = false;
|
||||
@@ -279,7 +278,7 @@ public class MainActivity extends AppCompatActivity
|
||||
updateNavigation();
|
||||
if (restoreResult == Login.RESTORE_STATUS_SUCCESS && !isLoggedInBeforePause) {
|
||||
changeFragment(getDefaultFragmentAfterLogin());
|
||||
registerSync(true);
|
||||
registerSync();
|
||||
} else if (restoreResult == Login.RESTORE_STATUS_INVALID_PASSWORD && isLoggedInBeforePause) {
|
||||
kvv.account().logout(false);
|
||||
changeFragment(getDefaultFragmentAfterLogout());
|
||||
@@ -289,6 +288,13 @@ public class MainActivity extends AppCompatActivity
|
||||
});
|
||||
}
|
||||
isPaused = false;
|
||||
|
||||
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup) && mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
registerSync(true);
|
||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
||||
} else {
|
||||
registerSync();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -523,16 +529,23 @@ public class MainActivity extends AppCompatActivity
|
||||
changeFragment(newFragment);
|
||||
}
|
||||
|
||||
private void registerSync(boolean onLogin) {
|
||||
private void registerSync() {
|
||||
registerSync(false);
|
||||
}
|
||||
|
||||
private void registerSync(boolean isLogin) {
|
||||
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
||||
if (accountByType != null) {
|
||||
if (onLogin)
|
||||
if (isLogin || (ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME))) {
|
||||
ContentResolver.setSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME, true);
|
||||
}
|
||||
ContentResolver.addPeriodicSync(
|
||||
accountByType,
|
||||
KVVContentProvider.PROVIDER_NAME,
|
||||
Bundle.EMPTY,
|
||||
Long.parseLong(Preferences.getStringArray(this, R.array.pref_sync_frequency))*60*60);
|
||||
Long.parseLong(Preferences.getStringArray(this, R.array.pref_sync_frequency)) * 60 * 60
|
||||
);
|
||||
ContentResolver.requestSync(accountByType, KVVContentProvider.PROVIDER_NAME, Bundle.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -686,7 +699,7 @@ public class MainActivity extends AppCompatActivity
|
||||
if (drawer.isDrawerOpen(GravityCompat.START) && !isDrawerFixed) {
|
||||
drawer.closeDrawer(GravityCompat.START);
|
||||
}
|
||||
mAccountManager.getTokenByType(AccountGeneral.ACCOUNT_TYPE, AccountGeneral.AUTHTOKEN_TYPE_BLACKBOARD, null, null);
|
||||
goToLoginScreen();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -136,9 +136,7 @@ public class CanteenBrowser extends HTTPService {
|
||||
|
||||
// "https://openmensa.org/api/v2/canteens?near[lat]=52.449743&near[lng]=13.282245&near[dist]=50"
|
||||
for (double[] root : canteenRoots) {
|
||||
log.d("invoke", root[0], root[1]);
|
||||
get(String.format("https://openmensa.org/api/v2/canteens?near[lat]=%s&near[lng]=%s&near[dist]=50", root[0], root[1]), null, response -> {
|
||||
log.d("invoke response", root[0], root[1]);
|
||||
String body = response.getParsed();
|
||||
if (body == null) {
|
||||
errorCallback.onError(new NetworkError(201401, 403, "No canteen list retrieved!"));
|
||||
@@ -152,7 +150,6 @@ public class CanteenBrowser extends HTTPService {
|
||||
return;
|
||||
}
|
||||
finishedCount.getAndIncrement();
|
||||
log.d("invoke increment", root[0], root[1], finishedCount.get(), this.canteenRoots.length);
|
||||
if (finishedCount.get() == this.canteenRoots.length) {
|
||||
|
||||
callback.onResponse(canteens);
|
||||
|
||||
@@ -4,6 +4,7 @@ import android.content.Context;
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.ObjectInputStream;
|
||||
@@ -74,7 +75,12 @@ public class Canteens implements Serializable, Iterable<Canteen> {
|
||||
}
|
||||
|
||||
public static Canteens load(Context context) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = context.openFileInput(FILE_NAME);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
ObjectInputStream is = new ObjectInputStream(fis);
|
||||
Canteens modules = (Canteens) is.readObject();
|
||||
is.close();
|
||||
|
||||
@@ -171,7 +171,7 @@ public class FUAuthenticatorActivity extends AccountAuthenticatorActivity {
|
||||
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)) {
|
||||
if (mIsAddingNewAccount) {
|
||||
String authtoken = intent.getStringExtra(AccountManager.KEY_AUTHTOKEN);
|
||||
String authtokenType = mAuthTokenType;
|
||||
|
||||
|
||||
@@ -16,12 +16,11 @@ import de.sebse.fuplanner.services.kvv.types.LoginTokenKVV;
|
||||
import de.sebse.fuplanner.tools.CustomAccountManager;
|
||||
import de.sebse.fuplanner.tools.NetworkCallbackCollector;
|
||||
import de.sebse.fuplanner.tools.Preferences;
|
||||
import de.sebse.fuplanner.tools.network.HTTPService;
|
||||
import de.sebse.fuplanner.tools.network.NetworkCallback;
|
||||
import de.sebse.fuplanner.tools.network.NetworkError;
|
||||
import de.sebse.fuplanner.tools.network.NetworkErrorCallback;
|
||||
|
||||
public class Login extends HTTPService {
|
||||
public class Login {
|
||||
public static final int RESTORE_STATUS_SUCCESS = 1;
|
||||
public static final int RESTORE_STATUS_ERROR = 2;
|
||||
public static final int RESTORE_STATUS_INVALID_PASSWORD = 3;
|
||||
@@ -31,6 +30,7 @@ public class Login extends HTTPService {
|
||||
public static final int RELOGIN = 0;
|
||||
|
||||
private final KVVListener mListener;
|
||||
private Context context;
|
||||
@Nullable private LoginTokenKVV mTokenKVV;
|
||||
@Nullable private LoginTokenBB mTokenBB;
|
||||
private boolean mLoginPending = false;
|
||||
@@ -38,8 +38,13 @@ public class Login extends HTTPService {
|
||||
private final NetworkCallbackCollector<Integer> mRestoreCallbacks = new NetworkCallbackCollector<>();
|
||||
|
||||
Login(KVVListener listener, Context context) {
|
||||
super(context);
|
||||
super();
|
||||
this.mListener = listener;
|
||||
this.context = context;
|
||||
}
|
||||
|
||||
private Context getContext() {
|
||||
return this.context;
|
||||
}
|
||||
|
||||
public void restoreOnlineLogin(IntegerInterface callback) {
|
||||
|
||||
@@ -123,7 +123,6 @@ public class ModulesEvents extends PartModules<EventList> {
|
||||
//String[] tests = {"462854", "465661", "462126", "463782", "437050", "433843", "471614", "464205"};
|
||||
//String[] tests = {"461459", "424564", "459494", "429737", "463765", "476477", "464082", "459577", "459743", "464318", "449358", "454327", "461784", "468081", "485919"};
|
||||
//vvNumber = tests[new Random().nextInt(tests.length)];
|
||||
//log.d("LAAAAAAST", vvNumber);
|
||||
//vvNumber = "462126";
|
||||
super.get(String.format("https://www.fu-berlin.de/vv/de/lv/%s", vvNumber), null, response1 -> {
|
||||
String body = response1.getParsed();
|
||||
|
||||
@@ -27,7 +27,7 @@ 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.Part.RETRY_COUNT;
|
||||
|
||||
public class ModulesList extends HTTPService {
|
||||
private final Login mLogin;
|
||||
|
||||
@@ -100,6 +100,7 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
SyncResult syncResult) {
|
||||
if (!mBound) {
|
||||
Intent intent = new Intent(getContext(), KVV.class);
|
||||
getContext().bindService(intent, mConnection, Context.BIND_AUTO_CREATE);
|
||||
mWaitForBound = true;
|
||||
mQueue.add(() -> {});
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -23,7 +24,12 @@ public class CacheBBCourse implements Serializable {
|
||||
private HashMap<String, Long> mBBCourseListRefresh = new HashMap<>();
|
||||
|
||||
public static CacheBBCourse load(Context context) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = context.openFileInput(FILE_NAME);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
ObjectInputStream is = new ObjectInputStream(fis);
|
||||
Object readObject = is.readObject();
|
||||
if (!(readObject instanceof CacheBBCourse))
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -20,7 +21,12 @@ public class CacheKVVCourse implements Serializable {
|
||||
private HashMap<String, Long> mKVVCourseListRefresh = new HashMap<>();
|
||||
|
||||
public static CacheKVVCourse load(Context context) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = context.openFileInput(FILE_NAME);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
ObjectInputStream is = new ObjectInputStream(fis);
|
||||
Object readObject = is.readObject();
|
||||
if (!(readObject instanceof CacheKVVCourse))
|
||||
|
||||
@@ -3,6 +3,7 @@ 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;
|
||||
@@ -23,7 +24,12 @@ public class CacheLecturer implements Serializable {
|
||||
private HashMap<String, Long> mLecturersRefresh = new HashMap<>();
|
||||
|
||||
public static CacheLecturer load(Context context) throws IOException, ClassNotFoundException {
|
||||
FileInputStream fis = context.openFileInput(FILE_NAME);
|
||||
FileInputStream fis;
|
||||
try {
|
||||
fis = context.openFileInput(FILE_NAME);
|
||||
} catch (FileNotFoundException e) {
|
||||
return null;
|
||||
}
|
||||
ObjectInputStream is = new ObjectInputStream(fis);
|
||||
Object readObject = is.readObject();
|
||||
if (!(readObject instanceof CacheLecturer))
|
||||
|
||||
@@ -44,6 +44,10 @@ public class LoginTokenBB {
|
||||
}, errorCallback);
|
||||
}
|
||||
|
||||
public static boolean hasAccounts(CustomAccountManager manager) {
|
||||
return manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE);
|
||||
}
|
||||
|
||||
public void delete(CustomAccountManager manager) {
|
||||
manager.deleteAccount(AccountGeneral.ACCOUNT_TYPE);
|
||||
}
|
||||
|
||||
@@ -42,6 +42,10 @@ public class LoginTokenKVV {
|
||||
}, errorCallback);
|
||||
}
|
||||
|
||||
public static boolean hasAccounts(CustomAccountManager manager) {
|
||||
return manager.hasAccounts(AccountGeneral.ACCOUNT_TYPE);
|
||||
}
|
||||
|
||||
public void delete(CustomAccountManager manager) {
|
||||
manager.deleteAccount(AccountGeneral.ACCOUNT_TYPE);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user