Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Unverified Commit 7e82e3da authored by Daniel Bailey's avatar Daniel Bailey
Browse files

Merge branch 'multi-account' of github.com:stefan-niedermann/nextcloud-notes...


Merge branch 'multi-account' of github.com:stefan-niedermann/nextcloud-notes into multi-account.rebase-test.test.2

Signed-off-by: default avatarDaniel Bailey <daniel.bailey@grappleIT.co.uk>
parents f40eab40 16b98435
Loading
Loading
Loading
Loading
+5 −2
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.android;

import android.content.Context;
import androidx.appcompat.widget.AppCompatAutoCompleteTextView;
import android.util.AttributeSet;
import android.util.Log;
import android.view.WindowManager;

import androidx.appcompat.widget.AppCompatAutoCompleteTextView;

/**
 * Extension of the {@link AppCompatAutoCompleteTextView}, but this one is always open, i.e. you can see the list of suggestions even the TextView is empty.
 */
public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView {

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

    private int myThreshold;

    public AlwaysAutoCompleteTextView(Context context) {
@@ -50,7 +53,7 @@ public class AlwaysAutoCompleteTextView extends AppCompatAutoCompleteTextView {
        } catch (WindowManager.BadTokenException e) {
            // https://github.com/stefan-niedermann/nextcloud-notes/issues/366
            e.printStackTrace();
            Log.e(AlwaysAutoCompleteTextView.class.getSimpleName(), "Exception", e);
            Log.e(TAG, "Exception", e);
        }
    }
}
 No newline at end of file
+5 −7
Original line number Diff line number Diff line
@@ -2,6 +2,7 @@ package it.niedermann.owncloud.notes.android.activity;

import android.os.Bundle;

import androidx.annotation.NonNull;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentManager;
@@ -37,26 +38,23 @@ public class AboutActivity extends AppCompatActivity {
    }

    private class TabsPagerAdapter extends FragmentPagerAdapter {
        private final int PAGE_COUNT = 3;

        public TabsPagerAdapter(FragmentManager fragmentManager) {
        TabsPagerAdapter(FragmentManager fragmentManager) {
            super(fragmentManager);
        }

        @Override
        public int getCount() {
            return PAGE_COUNT;
            return 3;
        }

        /**
         * return the right fragment for the given position
         */
        @NonNull
        @Override
        public Fragment getItem(int position) {
            switch (position) {
                case 0:
                    return new AboutFragmentCreditsTab();

                case 1:
                    return new AboutFragmentContributingTab();

@@ -64,7 +62,7 @@ public class AboutActivity extends AppCompatActivity {
                    return new AboutFragmentLicenseTab();

                default:
                    return null;
                    return new AboutFragmentCreditsTab();
            }
        }

+11 −3
Original line number Diff line number Diff line
@@ -13,6 +13,7 @@ import androidx.appcompat.app.ActionBar;
import androidx.appcompat.app.AppCompatActivity;

import java.util.Calendar;
import java.util.Objects;

import it.niedermann.owncloud.notes.R;
import it.niedermann.owncloud.notes.android.fragment.BaseNoteFragment;
@@ -26,6 +27,8 @@ import it.niedermann.owncloud.notes.util.NoteUtil;

public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragment.NoteFragmentListener {

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

    public static final String ACTION_SHORTCUT = "it.niedermann.owncloud.notes.shortcut";
    private static final String INTENT_GOOGLE_ASSISTANT = "com.google.android.gm.action.AUTO_SEND";
    private static final String MIMETYPE_TEXT_PLAIN = "text/plain";
@@ -54,7 +57,7 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm
    @Override
    protected void onNewIntent(Intent intent) {
        super.onNewIntent(intent);
        Log.d(getClass().getSimpleName(), "onNewIntent: " + intent.getLongExtra(PARAM_NOTE_ID, 0));
        Log.d(TAG, "onNewIntent: " + intent.getLongExtra(PARAM_NOTE_ID, 0));
        setIntent(intent);
        if (fragment != null) {
            getFragmentManager().beginTransaction().detach(fragment).commit();
@@ -211,12 +214,17 @@ public class EditNoteActivity extends AppCompatActivity implements BaseNoteFragm

    @Override
    public void onNoteUpdated(DBNote note) {
        ActionBar actionBar = getSupportActionBar();
        if (actionBar != null) {
        ActionBar actionBar = Objects.requireNonNull(getSupportActionBar());
        if (note != null) {
            actionBar.setTitle(note.getTitle());
            if (!note.getCategory().isEmpty()) {
                actionBar.setSubtitle(NoteUtil.extendCategory(note.getCategory()));
            }
        } else {
            // Maybe account is not authenticated -> note == null
            Log.e(TAG, "note is null, start NotesListViewActivity");
            startActivity(new Intent(this, NotesListViewActivity.class));
            finish();
        }
    }
}
 No newline at end of file
+2 −0
Original line number Diff line number Diff line
package it.niedermann.owncloud.notes.android.activity;

import android.annotation.SuppressLint;
import android.content.ClipData;
import android.content.ClipboardManager;
import android.os.Bundle;
@@ -30,6 +31,7 @@ public class ExceptionActivity extends AppCompatActivity {

    public static final String KEY_THROWABLE = "T";

    @SuppressLint("SetTextI18n") // only used for logging
    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        setContentView(R.layout.activity_exception);
+53 −48
Original line number Diff line number Diff line
@@ -5,6 +5,7 @@ import android.content.Intent;
import android.content.pm.ShortcutInfo;
import android.content.pm.ShortcutManager;
import android.content.res.Configuration;
import android.database.sqlite.SQLiteConstraintException;
import android.graphics.Canvas;
import android.graphics.drawable.Icon;
import android.net.Uri;
@@ -30,6 +31,7 @@ import androidx.appcompat.view.ActionMode;
import androidx.appcompat.widget.AppCompatImageView;
import androidx.appcompat.widget.SearchView;
import androidx.appcompat.widget.Toolbar;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
import androidx.core.view.GravityCompat;
import androidx.drawerlayout.widget.DrawerLayout;
import androidx.recyclerview.widget.ItemTouchHelper;
@@ -48,8 +50,6 @@ import com.nextcloud.android.sso.exceptions.NoCurrentAccountSelectedException;
import com.nextcloud.android.sso.helper.SingleAccountHelper;
import com.nextcloud.android.sso.model.SingleSignOnAccount;

import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
@@ -69,12 +69,15 @@ import it.niedermann.owncloud.notes.util.ExceptionHandler;
import it.niedermann.owncloud.notes.util.ICallback;
import it.niedermann.owncloud.notes.util.NoteUtil;
import it.niedermann.owncloud.notes.util.NotesClientUtil;
import it.niedermann.owncloud.notes.util.SSOUtil;

import static it.niedermann.owncloud.notes.android.activity.EditNoteActivity.ACTION_SHORTCUT;
import static it.niedermann.owncloud.notes.util.SSOUtil.askForNewAccount;

public class NotesListViewActivity extends AppCompatActivity implements ItemAdapter.NoteClickListener {

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

    public static final String CREATED_NOTE = "it.niedermann.owncloud.notes.created_notes";
    public static final String ADAPTER_KEY_RECENT = "recent";
    public static final String ADAPTER_KEY_STARRED = "starred";
@@ -92,6 +95,8 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap

    private LocalAccount localAccount;

    @BindView(R.id.coordinatorLayout)
    CoordinatorLayout coordinatorLayout;
    @BindView(R.id.accountNavigation)
    LinearLayout accountNavigation;
    @BindView(R.id.accountChooser)
@@ -152,7 +157,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                                    .setIntent(intent)
                                    .build());
                        }
                        Log.d(getClass().getSimpleName(), "Update dynamic shortcuts");
                        Log.d(TAG, "Update dynamic shortcuts");
                        shortcutManager.removeAllDynamicShortcuts();
                        shortcutManager.addDynamicShortcuts(newShortcuts);
                    }
@@ -228,19 +233,6 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
            handleNotAuthorizedAccount();
        }

        try { // to get current account from SingleAccountHelper
            selectAccount(SingleAccountHelper.getCurrentSingleSignOnAccount(getApplicationContext()).name);
            Log.v(getClass().getSimpleName(), "NextcloudRequest account: " + localAccount);
        } catch (NextcloudFilesAppAccountNotFoundException e) {
            e.printStackTrace();
        } catch (NoCurrentAccountSelectedException e) {
            if (db.hasAccounts()) { // If nothing is stored in SingleAccountHelper, check db for accounts
                selectAccount(db.getAccounts().get(0).getAccountName());
            } else {
                askForNewAccount(this);
            }
        }

        // refresh and sync every time the activity gets
        if (localAccount != null) {
            refreshLists();
@@ -275,16 +267,32 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
    }

    private void selectAccount(String accountName) {
        fabCreate.hide();
        SingleAccountHelper.setCurrentAccount(getApplicationContext(), accountName);
        localAccount = db.getLocalAccountByAccountName(accountName);
        try {
            db.getNoteServerSyncHelper().updateAccount();
            synchronize();
            refreshLists();
            fabCreate.show();
        } catch (NextcloudFilesAppAccountNotFoundException e) {
            handleNotAuthorizedAccount();
        }
        setupHeader();
        setupNavigationList(ADAPTER_KEY_RECENT);
        updateUsernameInDrawer();
    }

    private void handleNotAuthorizedAccount() {
        fabCreate.hide();
        swipeRefreshLayout.setRefreshing(false);
        if (db.hasAccounts()) {
            SSOUtil.authorizeExistingAccount(this, db.getAccounts().get(0).getAccountName());
        } else {
            askForNewAccount(this);
        }
    }

    private void setupHeader() {
        accountChooser.removeAllViews();
        for (LocalAccount account : db.getAccounts()) {
@@ -297,9 +305,9 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                    .apply(RequestOptions.circleCropTransform())
                    .into(((ImageView) v.findViewById(R.id.accountItemAvatar)));
            v.setOnClickListener(clickedView -> {
                selectAccount(account.getAccountName());
                clickHeader();
                drawerLayout.closeDrawer(GravityCompat.START);
                selectAccount(account.getAccountName());
            });
            v.findViewById(R.id.delete).setOnClickListener(clickedView -> {
                db.deleteAccount(account.getId());
@@ -400,7 +408,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap

                // update views
                if (closeNavigation) {
                    drawerLayout.closeDrawers();
                    drawerLayout.closeDrawer(GravityCompat.START);
                }
                refreshLists(true);
            }
@@ -591,7 +599,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                        db.deleteNoteAndSync((dbNote).getId());
                        adapter.remove(dbNote);
                        refreshLists();
                        Log.v(getClass().getSimpleName(), "Item deleted through swipe ----------------------------------------------");
                        Log.v(TAG, "Item deleted through swipe ----------------------------------------------");
                        Snackbar.make(swipeRefreshLayout, R.string.action_note_deleted, Snackbar.LENGTH_LONG)
                                .setAction(R.string.action_undo, (View v) -> {
                                    db.addNoteAndSync(dbNote.getAccountId(), dbNote);
@@ -703,9 +711,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                    if (currentVisibility == View.VISIBLE) {
                        fabCreate.hide();
                    } else {
                        new Handler().postDelayed(() -> {
                            fabCreate.show();
                        }, 150);
                        new Handler().postDelayed(() -> fabCreate.show(), 150);
                    }

                    oldVisibility = currentVisibility;
@@ -735,7 +741,6 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
            searchView.setQuery(intent.getStringExtra(SearchManager.QUERY), true);
        }
        super.onNewIntent(intent);
        Log.d(getClass().getSimpleName(), "onNewIntent: ");
    }

    /**
@@ -749,14 +754,6 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);

        AccountImporter.onActivityResult(requestCode, resultCode, data, this, (SingleSignOnAccount account) -> {
            Log.v(getClass().getSimpleName(), "Added account: " + "name:" + account.name + ", " + account.url + ", userId" + account.userId);
            db.addAccount(account.url, account.userId, account.name);
            selectAccount(account.name);
            clickHeader();
            drawerLayout.closeDrawer(GravityCompat.START);
        });

        // Check which request we're responding to
        if (requestCode == create_note_cmd) {
            // Make sure the request was successful
@@ -769,10 +766,10 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                    if (createdNote != null) {
                        adapter.add(createdNote);
                    } else {
                        Log.w(NotesListViewActivity.class.getSimpleName(), "createdNote is null");
                        Log.w(TAG, "createdNote is null");
                    }
                } else {
                    Log.w(NotesListViewActivity.class.getSimpleName(), "bundle is null");
                    Log.w(TAG, "bundle is null");
                }
            }
            listView.scrollToPosition(0);
@@ -780,6 +777,20 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
            // Recreate activity completely, because theme switchting makes problems when only invalidating the views.
            // @see https://github.com/stefan-niedermann/nextcloud-notes/issues/529
            recreate();
        } else {
            AccountImporter.onActivityResult(requestCode, resultCode, data, this, (SingleSignOnAccount account) -> {
                Log.v(TAG, "Added account: " + "name:" + account.name + ", " + account.url + ", userId" + account.userId);
                try {
                    db.addAccount(account.url, account.userId, account.name);
                } catch(SQLiteConstraintException e) {
                    if(db.getAccounts().size() > 1) { // TODO ideally only show snackbar when this is a not migrated account
                        Snackbar.make(coordinatorLayout, R.string.account_already_imported, Snackbar.LENGTH_LONG).show();
                    }
                }
                selectAccount(account.name);
                clickHeader();
                drawerLayout.closeDrawer(GravityCompat.START);
            });
        }
    }

@@ -787,13 +798,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
        try {
            String url = localAccount.getUrl();
            if (url != null) {
                String croppedUrl = url;
                try {
                    croppedUrl = new URL(url).getHost();
                } catch (MalformedURLException e) {
                    e.printStackTrace();
                }
                this.account.setText(localAccount.getUserName() + "@" + croppedUrl);
                this.account.setText(localAccount.getAccountName());
                Glide
                        .with(this)
                        .load(url + "/index.php/avatar/" + Uri.encode(localAccount.getUserName()) + "/64")
@@ -801,16 +806,16 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                        .apply(RequestOptions.circleCropTransform())
                        .into(this.currentAccountImage);
            } else {
                Log.w(NotesListViewActivity.class.getSimpleName(), "url is null");
                Log.w(TAG, "url is null");
            }
        } catch (NullPointerException e) {
        } catch (NullPointerException e) { // No local account - show generic header
            this.account.setText(R.string.app_name_long);
            Glide
                    .with(this)
                    .load(R.mipmap.ic_launcher)
                    .apply(RequestOptions.circleCropTransform())
                    .into(this.currentAccountImage);
            Log.w(getClass().getSimpleName(), "Tried to update username in drawer, but localAccount was null");
            Log.w(TAG, "Tried to update username in drawer, but localAccount was null");
        }
    }

@@ -824,7 +829,7 @@ public class NotesListViewActivity extends AppCompatActivity implements ItemAdap
                v.setSelected(true);
            }
            int size = adapter.getSelected().size();
            mActionMode.setTitle(String.valueOf(getResources().getQuantityString(R.plurals.ab_selected, size, size)));
            mActionMode.setTitle(getResources().getQuantityString(R.plurals.ab_selected, size, size));
            int checkedItemCount = adapter.getSelected().size();
            boolean hasCheckedItems = checkedItemCount > 0;

Loading