Skip to content

#615 Local account #693

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
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 @@ -177,10 +177,14 @@ protected void onResume() {
}

// refresh and sync every time the activity gets
refreshLists();
if (localAccount != null) {
synchronize();
db.getNoteServerSyncHelper().addCallbackPull(ssoAccount, syncCallBack);
refreshLists();
if(localAccount.getId() != 0) {
db.getNoteServerSyncHelper().addCallbackPull(ssoAccount, syncCallBack);
if (db.getNoteServerSyncHelper().isSyncPossible()) {
synchronize();
}
}
}
super.onResume();
}
Expand Down Expand Up @@ -237,13 +241,18 @@ private void setupHeader() {
binding.accountChooser.removeAllViews();
for (LocalAccount localAccount : db.getAccounts()) {
View v = View.inflate(this, R.layout.item_account, null);
((TextView) v.findViewById(R.id.accountItemLabel)).setText(localAccount.getAccountName());
Glide
.with(this)
.load(localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")
.error(R.drawable.ic_account_circle_grey_24dp)
.apply(RequestOptions.circleCropTransform())
.into(((ImageView) v.findViewById(R.id.accountItemAvatar)));
if(localAccount.getId() == 0) {
((TextView) v.findViewById(R.id.accountItemLabel)).setText(R.string.local_account);
v.findViewById(R.id.delete).setVisibility(View.GONE);
} else {
((TextView) v.findViewById(R.id.accountItemLabel)).setText(localAccount.getAccountName());
Glide
.with(this)
.load(localAccount.getUrl() + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")
.error(R.drawable.ic_account_circle_grey_24dp)
.apply(RequestOptions.circleCropTransform())
.into(((ImageView) v.findViewById(R.id.accountItemAvatar)));
}
v.setOnClickListener(clickedView -> {
clickHeader();
binding.drawerLayout.closeDrawer(GravityCompat.START);
Expand Down Expand Up @@ -781,7 +790,9 @@ public void onBackPressed() {
private void synchronize() {
NoteServerSyncHelper syncHelper = db.getNoteServerSyncHelper();
if (syncHelper.isSyncPossible()) {
swipeRefreshLayout.setRefreshing(true);
if(localAccount != null && localAccount.getId() != 0) {
swipeRefreshLayout.setRefreshing(true);
}
syncHelper.addCallbackPull(ssoAccount, syncCallBack);
syncHelper.scheduleSync(ssoAccount, false);
} else { // Sync is not possible
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,42 +67,40 @@ public abstract class BaseNoteFragment extends Fragment implements CategoryDialo
public void onCreate(@Nullable Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
try {
this.ssoAccount = SingleAccountHelper.getCurrentSingleSignOnAccount(requireActivity().getApplicationContext());
this.localAccount = db.getLocalAccountByAccountName(ssoAccount.name);

if (savedInstanceState == null) {
long id = requireArguments().getLong(PARAM_NOTE_ID);
if (id > 0) {
long accountId = requireArguments().getLong(PARAM_ACCOUNT_ID);
if (accountId > 0) {
/* Switch account if account id has been provided */
this.localAccount = db.getAccount(accountId);
SingleAccountHelper.setCurrentAccount(requireActivity().getApplicationContext(), localAccount.getAccountName());
}
isNew = false;
note = originalNote = db.getNote(localAccount.getId(), id);
} else {
CloudNote cloudNote = (CloudNote) requireArguments().getSerializable(PARAM_NEWNOTE);
String content = requireArguments().getString(PARAM_CONTENT);
this.localAccount = db.getLocalAccountByAccountName(SingleAccountHelper.getCurrentSingleSignOnAccount(getActivity().getApplicationContext()).name);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
this.localAccount = db.getAccount(0);
e.printStackTrace();
}
if (savedInstanceState == null) {
long id = requireArguments().getLong(PARAM_NOTE_ID);
if (id > 0) {
long accountId = requireArguments().getLong(PARAM_ACCOUNT_ID);
if (accountId > 0) {
/* Switch account if account id has been provided */
this.localAccount = db.getAccount(accountId);
SingleAccountHelper.setCurrentAccount(requireActivity().getApplicationContext(), localAccount.getAccountName());
}isNew = false;
note = originalNote = db.getNote(localAccount.getId(), id);
} else {
CloudNote cloudNote = (CloudNote) requireArguments().getSerializable(PARAM_NEWNOTE);
String content = requireArguments().getString(PARAM_CONTENT);
if (cloudNote == null) {
if (content == null) {
throw new IllegalArgumentException(PARAM_NOTE_ID + " is not given, argument " + PARAM_NEWNOTE + " is missing and " + PARAM_CONTENT + " is missing.");
if (content ==null) {
throw new IllegalArgumentException(PARAM_NOTE_ID + " is not given , argument " + PARAM_NEWNOTE + " is missing and " + PARAM_CONTENT + " is missing.");
} else {
note = new DBNote(-1, -1, null, NoteUtil.generateNoteTitle(content), content, false, getString(R.string.category_readonly), null, DBStatus.VOID, -1, "");
}
} else {
note = db.getNote(localAccount.getId(), db.addNoteAndSync(ssoAccount, localAccount.getId(), cloudNote));
originalNote = null;
}
}
} else {
note = (DBNote) savedInstanceState.getSerializable(SAVEDKEY_NOTE);
originalNote = (DBNote) savedInstanceState.getSerializable(SAVEDKEY_ORIGINAL_NOTE);
}else {
note = db.getNote(localAccount.getId(), db.addNoteAndSync(ssoAccount, localAccount.getId(), cloudNote));
originalNote = null;}
}
setHasOptionsMenu(true);
} catch (NextcloudFilesAppAccountNotFoundException | NoCurrentAccountSelectedException e) {
e.printStackTrace();
} else {

note = (DBNote) savedInstanceState.getSerializable(SAVEDKEY_NOTE);
originalNote = (DBNote) savedInstanceState.getSerializable(SAVEDKEY_ORIGINAL_NOTE);
}
setHasOptionsMenu(true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ abstract class AbstractNotesDatabase extends SQLiteOpenHelper {

private static final String TAG = AbstractNotesDatabase.class.getSimpleName();

private static final int database_version = 12;
private static final int database_version = 13;
@NonNull
private final Context context;

Expand Down Expand Up @@ -274,6 +274,11 @@ public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
db.execSQL("ALTER TABLE " + table_accounts + " ADD COLUMN " + key_text_color + " VARCHAR(6) NOT NULL DEFAULT '0082C9'");
CapabilitiesWorker.update(context);
}
if (oldVersion < 13) {
ContentValues migratedAccountValues = new ContentValues();
migratedAccountValues.put(key_id, 0);
db.insert(table_accounts, null, migratedAccountValues);
}
}

@Override
Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
<string name="account_already_imported">Account has already been imported</string>
<string name="no_notes_yet">No notes yet</string>
<string name="no_notes_yet_description">Press + button to create a new note</string>
<string name="local_account">Local account</string>
<string name="could_not_load_preview_two_digit_numbered_list">Could not load preview. Please check whether there is a two-digit numbered list item without content.</string>
<string name="simple_more">More</string>
<string name="simple_move">Move</string>
Expand Down