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