mirror of
https://github.com/nextcloud/notes-android.git
synced 2024-11-21 20:35:58 +03:00
- Fix #1475 Detect missing Notes app on server when importing an account
Signed-off-by: Stefan Niedermann <info@niedermann.it>
This commit is contained in:
parent
5b06023a51
commit
828ba1c2ee
4 changed files with 60 additions and 42 deletions
|
@ -73,11 +73,7 @@ public class TipsAdapter extends RecyclerView.Adapter<TipsViewHolder> {
|
|||
} else if (throwable instanceof NextcloudFilesAppNotSupportedException) {
|
||||
add(R.string.error_dialog_tip_files_outdated);
|
||||
} else if (throwable instanceof NextcloudApiNotRespondingException) {
|
||||
if (VERSION.SDK_INT >= VERSION_CODES.M) {
|
||||
add(R.string.error_dialog_tip_disable_battery_optimizations, new Intent().setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS).putExtra(INTENT_EXTRA_BUTTON_TEXT, R.string.error_action_open_battery_settings));
|
||||
} else {
|
||||
add(R.string.error_dialog_tip_disable_battery_optimizations);
|
||||
}
|
||||
add(R.string.error_dialog_tip_files_force_stop);
|
||||
add(R.string.error_dialog_tip_files_delete_storage);
|
||||
final var intent = new Intent(ACTION_APPLICATION_DETAILS_SETTINGS)
|
||||
|
|
|
@ -118,7 +118,7 @@ public class ImportAccountActivity extends AppCompatActivity {
|
|||
@Override
|
||||
public void onError(@NonNull Throwable t) {
|
||||
runOnUiThread(() -> {
|
||||
binding.addButton.setEnabled(true);
|
||||
restoreCleanState();
|
||||
ExceptionDialogFragment.newInstance(t).show(getSupportFragmentManager(), ExceptionDialogFragment.class.getSimpleName());
|
||||
});
|
||||
}
|
||||
|
|
|
@ -53,6 +53,7 @@ public class NotesImportTask {
|
|||
executor.submit(() -> {
|
||||
Log.i(TAG, "… Fetching notes IDs");
|
||||
final var status = new ImportStatus();
|
||||
try {
|
||||
final var remoteIds = notesAPI.getNotesIDs().blockingSingle();
|
||||
status.total = remoteIds.size();
|
||||
status$.postValue(status);
|
||||
|
@ -78,6 +79,16 @@ public class NotesImportTask {
|
|||
} catch (InterruptedException e) {
|
||||
callback.onError(e);
|
||||
}
|
||||
} catch (Throwable t) {
|
||||
final Throwable cause = t.getCause();
|
||||
if (t.getClass() == RuntimeException.class && cause != null) {
|
||||
Log.e(TAG, "Could not fetch list of note IDs: " + cause.getMessage());
|
||||
callback.onError(cause);
|
||||
} else {
|
||||
Log.e(TAG, "Could not fetch list of note IDs: " + t.getMessage());
|
||||
callback.onError(t);
|
||||
}
|
||||
}
|
||||
});
|
||||
return status$;
|
||||
}
|
||||
|
|
|
@ -1,5 +1,15 @@
|
|||
package it.niedermann.owncloud.notes.persistence;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.O;
|
||||
import static androidx.lifecycle.Transformations.distinctUntilChanged;
|
||||
import static androidx.lifecycle.Transformations.map;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
import static it.niedermann.owncloud.notes.edit.EditNoteActivity.ACTION_SHORTCUT;
|
||||
import static it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt;
|
||||
import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets;
|
||||
import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.updateSingleNoteWidgets;
|
||||
|
||||
import android.accounts.NetworkErrorException;
|
||||
import android.content.BroadcastReceiver;
|
||||
import android.content.Context;
|
||||
|
@ -31,7 +41,6 @@ import com.nextcloud.android.sso.model.SingleSignOnAccount;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
@ -66,16 +75,6 @@ import it.niedermann.owncloud.notes.shared.util.NoteUtil;
|
|||
import it.niedermann.owncloud.notes.shared.util.SSOUtil;
|
||||
import retrofit2.Call;
|
||||
|
||||
import static android.os.Build.VERSION.SDK_INT;
|
||||
import static android.os.Build.VERSION_CODES.O;
|
||||
import static androidx.lifecycle.Transformations.distinctUntilChanged;
|
||||
import static androidx.lifecycle.Transformations.map;
|
||||
import static it.niedermann.owncloud.notes.edit.EditNoteActivity.ACTION_SHORTCUT;
|
||||
import static it.niedermann.owncloud.notes.shared.util.NoteUtil.generateNoteExcerpt;
|
||||
import static it.niedermann.owncloud.notes.widget.notelist.NoteListWidget.updateNoteListWidgets;
|
||||
import static it.niedermann.owncloud.notes.widget.singlenote.SingleNoteWidget.updateSingleNoteWidgets;
|
||||
import static java.util.stream.Collectors.toMap;
|
||||
|
||||
@SuppressWarnings("UnusedReturnValue")
|
||||
public class NotesRepository {
|
||||
|
||||
|
@ -186,15 +185,27 @@ public class NotesRepository {
|
|||
|
||||
@Override
|
||||
public void onError(@NonNull Throwable t) {
|
||||
Log.e(TAG, "… Error while importing " + account.getAccountName() + ": " + t.getMessage());
|
||||
deleteAccount(account);
|
||||
SingleAccountHelper.setCurrentAccount(context, null);
|
||||
callback.onError(t);
|
||||
}
|
||||
});
|
||||
} catch (NextcloudFilesAppAccountNotFoundException e) {
|
||||
Log.e(TAG, "… Could not find " + SingleSignOnAccount.class.getSimpleName() + " for account name " + account.getAccountName());
|
||||
importExecutor.submit(() -> {
|
||||
deleteAccount(account);
|
||||
SingleAccountHelper.setCurrentAccount(context, null);
|
||||
callback.onError(e);
|
||||
});
|
||||
}
|
||||
} else {
|
||||
Log.e(TAG, "… No network connection available to import " + account.getAccountName());
|
||||
importExecutor.submit(() -> {
|
||||
deleteAccount(account);
|
||||
SingleAccountHelper.setCurrentAccount(context, null);
|
||||
callback.onError(new NetworkErrorException());
|
||||
});
|
||||
}
|
||||
}
|
||||
return new MutableLiveData<>(new ImportStatus());
|
||||
|
|
Loading…
Reference in a new issue