Bug fixed and sync performance improvements
This commit is contained in:
@@ -278,17 +278,12 @@ public class MainActivity extends AppCompatActivity
|
||||
updateNavigation();
|
||||
if (restoreResult == Login.RESTORE_STATUS_SUCCESS && !isLoggedInBeforePause) {
|
||||
changeFragment(getDefaultFragmentAfterLogin());
|
||||
registerSync();
|
||||
} else if (restoreResult == Login.RESTORE_STATUS_INVALID_PASSWORD && isLoggedInBeforePause) {
|
||||
kvv.account().logout(false);
|
||||
changeFragment(getDefaultFragmentAfterLogout());
|
||||
}
|
||||
});
|
||||
kvv.modules().list().reloadIfOutdated();
|
||||
});
|
||||
}
|
||||
isPaused = false;
|
||||
|
||||
if (restoreResult == Login.RESTORE_STATUS_SUCCESS || restoreResult == Login.RELOGIN) {
|
||||
if (!Preferences.getBoolean(this, R.string.pref_set_auto_sync_on_startup) && mAccountManager.hasAccounts(AccountGeneral.ACCOUNT_TYPE)) {
|
||||
registerSync(true);
|
||||
Preferences.setBoolean(this, R.string.pref_set_auto_sync_on_startup, true);
|
||||
@@ -296,6 +291,12 @@ public class MainActivity extends AppCompatActivity
|
||||
registerSync();
|
||||
}
|
||||
}
|
||||
});
|
||||
kvv.modules().list().reloadIfOutdated();
|
||||
});
|
||||
}
|
||||
isPaused = false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBackPressed() {
|
||||
@@ -545,6 +546,13 @@ public class MainActivity extends AppCompatActivity
|
||||
Bundle.EMPTY,
|
||||
Long.parseLong(Preferences.getStringArray(this, R.array.pref_sync_frequency)) * 60 * 60
|
||||
);
|
||||
forceSync();
|
||||
}
|
||||
}
|
||||
|
||||
public void forceSync() {
|
||||
Account accountByType = mAccountManager.getAccountByType(AccountGeneral.ACCOUNT_TYPE);
|
||||
if (accountByType != null && ContentResolver.getMasterSyncAutomatically() && ContentResolver.getSyncAutomatically(accountByType, KVVContentProvider.PROVIDER_NAME)) {
|
||||
ContentResolver.requestSync(accountByType, KVVContentProvider.PROVIDER_NAME, Bundle.EMPTY);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,6 +7,7 @@ import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.appcompat.app.AppCompatDelegate;
|
||||
@@ -32,6 +33,7 @@ import de.sebse.fuplanner.tools.logging.Logger;
|
||||
public class PrefsFragment extends PreferenceFragmentCompat implements SharedPreferences.OnSharedPreferenceChangeListener {
|
||||
|
||||
private MainActivityListener mMainActivityListener;
|
||||
private Logger log = new Logger(this);
|
||||
|
||||
public static PrefsFragment newInstance() {
|
||||
PrefsFragment fragment = new PrefsFragment();
|
||||
@@ -45,7 +47,7 @@ public class PrefsFragment extends PreferenceFragmentCompat implements SharedPre
|
||||
// Load the preferences from an XML resource
|
||||
setPreferencesFromResource(R.xml.preferences, rootKey);
|
||||
for (String s : getPreferenceScreen().getSharedPreferences().getAll().keySet()) {
|
||||
onSharedPreferenceChanged(getPreferenceScreen().getSharedPreferences(), s);
|
||||
updateListPreferenceSummary(s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -63,9 +65,7 @@ public class PrefsFragment extends PreferenceFragmentCompat implements SharedPre
|
||||
|
||||
@Override
|
||||
public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, String s) {
|
||||
Preference preference = getPreferenceScreen().findPreference(s);
|
||||
if (preference instanceof ListPreference)
|
||||
preference.setSummary(((ListPreference) preference).getEntry());
|
||||
updateListPreferenceSummary(s);
|
||||
|
||||
if (s.equals(requireContext().getString(R.string.pref_sync_frequency))) {
|
||||
if (getActivity() != null && getActivity() instanceof MainActivity) {
|
||||
@@ -107,6 +107,16 @@ public class PrefsFragment extends PreferenceFragmentCompat implements SharedPre
|
||||
ActivityCompat.requestPermissions(getActivity(), new String[]{Manifest.permission.WRITE_CALENDAR, Manifest.permission.READ_CALENDAR}, 1);
|
||||
}
|
||||
}
|
||||
if (s.equals(requireContext().getString(R.string.pref_add_calendar)) && mMainActivityListener != null) {
|
||||
log.d("Force sync...");
|
||||
mMainActivityListener.forceSync();
|
||||
}
|
||||
}
|
||||
|
||||
private void updateListPreferenceSummary(String s) {
|
||||
Preference preference = getPreferenceScreen().findPreference(s);
|
||||
if (preference instanceof ListPreference)
|
||||
preference.setSummary(((ListPreference) preference).getEntry());
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -128,6 +128,7 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
mQueue.add(() -> {
|
||||
if (!mKVV.account().isLoggedIn()) {
|
||||
log.w("Not logged in!");
|
||||
mQueue.next();
|
||||
return;
|
||||
}
|
||||
mKVV.modules().list().reloadIfOutdated();
|
||||
@@ -138,6 +139,8 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
latch[0] += 1;
|
||||
iterator.next();
|
||||
}
|
||||
boolean doAddToCalendar = createCalendar(account);
|
||||
log.d("sync calendar", doAddToCalendar);
|
||||
iterator = success.latestSemesterIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Modules.Module module = iterator.next();
|
||||
@@ -167,25 +170,24 @@ public class KVVSyncAdapter extends AbstractThreadedSyncAdapter {
|
||||
sendNotifications(resources, module.resources, module.title, Resource::getTitle, Resource::getUrl,
|
||||
module.getID(), ModulePart.RESOURCES,
|
||||
R.string.resource_updated, R.string.resource_added, R.string.resource_removed);
|
||||
if (--latch[0] == 0) mQueue.next();
|
||||
if (doAddToCalendar) {
|
||||
addToCalendar(module.events, account);
|
||||
}
|
||||
if (--latch[0] == 0) {
|
||||
forceSync();
|
||||
mQueue.next();
|
||||
}
|
||||
}
|
||||
}, error -> {
|
||||
log.e(error);
|
||||
if (--latch[0] == 0) mQueue.next();
|
||||
if (--latch[0] == 0) {
|
||||
forceSync();
|
||||
mQueue.next();
|
||||
}
|
||||
}, true);
|
||||
}
|
||||
|
||||
// Add events to calendar
|
||||
if (createCalendar(account)) {
|
||||
iterator = success.latestSemesterIterator();
|
||||
while (iterator.hasNext()) {
|
||||
Modules.Module module = iterator.next();
|
||||
addToCalendar(module.events, account);
|
||||
}
|
||||
forceSync();
|
||||
}
|
||||
}, msg -> {
|
||||
log.e(msg);
|
||||
}, error -> {
|
||||
log.e(error);
|
||||
mQueue.next();
|
||||
}, true);
|
||||
});
|
||||
|
||||
@@ -2,6 +2,7 @@ package de.sebse.fuplanner.services.kvv.ui;
|
||||
|
||||
import android.Manifest;
|
||||
import android.app.AlertDialog;
|
||||
import android.content.ActivityNotFoundException;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.pm.PackageManager;
|
||||
@@ -243,7 +244,12 @@ public class Download {
|
||||
intent.setDataAndType(uri, "*/*");
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
try {
|
||||
context.startActivity(intent);
|
||||
} catch (ActivityNotFoundException e) {
|
||||
log.e("No matching activity found!");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -24,4 +24,6 @@ public interface MainActivityListener {
|
||||
void addRequestPermissionsResultListener(RequestPermissionsResultListener listener, String id);
|
||||
|
||||
void removeRequestPermissionsResultListener(String id);
|
||||
|
||||
void forceSync();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user