Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,6 @@
import it.niedermann.owncloud.notes.persistence.CapabilitiesWorker;
import it.niedermann.owncloud.notes.persistence.entity.Account;
import it.niedermann.owncloud.notes.persistence.entity.Note;
import it.niedermann.owncloud.notes.share.helper.AvatarLoader;
import it.niedermann.owncloud.notes.shared.model.CategorySortingMethod;
import it.niedermann.owncloud.notes.shared.model.IResponseCallback;
import it.niedermann.owncloud.notes.shared.model.NavigationCategory;
Expand Down Expand Up @@ -286,7 +285,7 @@ protected void onCreate(Bundle savedInstanceState) {
.apply(RequestOptions.circleCropTransform())
.into(activityBinding.launchAccountSwitcher);

mainViewModel.synchronizeNotes(nextAccount, new IResponseCallback<>() {
mainViewModel.synchronizeNotes(this, nextAccount, new IResponseCallback<>() {
@Override
public void onSuccess(Void v) {
Log.d(TAG, "Successfully synchronized notes for " + nextAccount.getAccountName());
Expand Down Expand Up @@ -376,7 +375,7 @@ protected void onResume() {
try {
// It is possible that after the deletion of the last account, this onResponse gets called before the ImportAccountActivity gets started.
if (SingleAccountHelper.getCurrentSingleSignOnAccount(this) != null) {
mainViewModel.synchronizeNotes(currentAccount, new IResponseCallback<>() {
mainViewModel.synchronizeNotes(this, currentAccount, new IResponseCallback<>() {
@Override
public void onSuccess(Void v) {
Log.d(TAG, "Successfully synchronized notes for " + currentAccount.getAccountName());
Expand Down Expand Up @@ -477,7 +476,7 @@ else if (dy < 0)
final var syncLiveData = mainViewModel.getCurrentAccount();
final Observer<Account> syncObserver = currentAccount -> {
syncLiveData.removeObservers(this);
mainViewModel.synchronizeCapabilitiesAndNotes(currentAccount, new IResponseCallback<>() {
mainViewModel.synchronizeCapabilitiesAndNotes(this, currentAccount, new IResponseCallback<>() {
@Override
public void onSuccess(Void v) {
Log.d(TAG, "Successfully synchronized capabilities and notes for " + currentAccount.getAccountName());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByCategory;
import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByInitials;
import static it.niedermann.owncloud.notes.main.slots.SlotterUtil.fillListByTime;
import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_MODIFIED_DESC;
import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_LEXICOGRAPHICAL_DESC;
import static it.niedermann.owncloud.notes.shared.model.CategorySortingMethod.SORT_MODIFIED_DESC;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.DEFAULT_CATEGORY;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.FAVORITES;
import static it.niedermann.owncloud.notes.shared.model.ENavigationCategoryType.RECENT;
Expand Down Expand Up @@ -44,6 +44,7 @@
import com.nextcloud.android.sso.exceptions.NextcloudHttpRequestFailedException;
import com.nextcloud.android.sso.exceptions.UnknownErrorException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.owncloud.android.lib.common.utils.Log_OC;

import java.util.ArrayList;
import java.util.Collection;
Expand Down Expand Up @@ -379,13 +380,13 @@ private static List<NavigationItem> fromCategoriesWithNotesCount(@NonNull Contex
return items;
}

public void synchronizeCapabilitiesAndNotes(@NonNull Account localAccount, @NonNull IResponseCallback<Void> callback) {
public void synchronizeCapabilitiesAndNotes(Context context, @NonNull Account localAccount, @NonNull IResponseCallback<Void> callback) {
Log.i(TAG, "[synchronizeCapabilitiesAndNotes] Synchronize capabilities for " + localAccount.getAccountName());
synchronizeCapabilities(localAccount, new IResponseCallback<>() {
@Override
public void onSuccess(Void v) {
Log.i(TAG, "[synchronizeCapabilitiesAndNotes] Synchronize notes for " + localAccount.getAccountName());
synchronizeNotes(localAccount, callback);
synchronizeNotes(context, localAccount, callback);
}

@Override
Expand Down Expand Up @@ -442,14 +443,22 @@ public void synchronizeCapabilities(@NonNull Account localAccount, @NonNull IRes
/**
* Updates the network status if necessary and pulls the latest notes of the given {@param localAccount}
*/
public void synchronizeNotes(@NonNull Account currentAccount, @NonNull IResponseCallback<Void> callback) {
public void synchronizeNotes(Context context, @NonNull Account currentAccount, @NonNull IResponseCallback<Void> callback) {
executor.submit(() -> {
Log.v(TAG, "[synchronize] - currentAccount: " + currentAccount.getAccountName());
if (!repo.isSyncPossible()) {
repo.updateNetworkStatus();
}
if (repo.isSyncPossible()) {
repo.scheduleSync(currentAccount, false);

try {
final var ssoAccount = AccountImporter.getSingleSignOnAccount(context, currentAccount.getAccountName());
CapabilitiesClient.getCapabilities(context, ssoAccount, null, ApiProvider.getInstance());
} catch (Throwable t) {
Log_OC.e(TAG, t.getMessage());
}

callback.onSuccess(null);
} else { // Sync is not possible
if (repo.isNetworkConnected() && repo.isSyncOnlyOnWifi()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ public static Capabilities getCapabilities(@NonNull Context context, @NonNull Si
} else {
Log.w(TAG, "Response headers of capabilities are null");
}

final var repository = NotesRepository.getInstance(context);
repository.insertCapabilities(capabilities);

return capabilities;
} catch (RuntimeException e) {
final var cause = e.getCause();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,10 @@ public void updateCapabilitiesETag(long id, String capabilitiesETag) {
db.getAccountDao().updateCapabilitiesETag(id, capabilitiesETag);
}

public void insertCapabilities(Capabilities capabilities) {
db.getCapabilitiesDao().insert(capabilities);
}

public void updateModified(long id, long modified) {
db.getAccountDao().updateModified(id, modified);
}
Expand All @@ -339,7 +343,6 @@ public void updateDirectEditingAvailable(final long id, final boolean available)
db.getAccountDao().updateDirectEditingAvailable(id, available);
}


// Notes

public LiveData<Note> getNoteById$(long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ private void initializeArguments() {
binding.loadingLayout.setVisibility(View.GONE);
});
} catch (Exception e) {
throw new RuntimeException(e);
Log_OC.e(TAG, "Exception at NoteShareActivity.init: " + e);
}
});
}
Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:8.11.0'
classpath 'com.android.tools.build:gradle:8.10.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"

// NOTE: Do not place your application dependencies here; they belong
Expand Down
Loading