Search in sources :

Example 6 with Repo

use of com.orgzly.android.repos.Repo in project orgzly-android by orgzly.

the class ReposClient method getAll.

private static Map<String, Repo> getAll(Context context, Cursor cursor) {
    Map<String, Repo> result = new HashMap<>();
    try {
        for (cursor.moveToFirst(); !cursor.isAfterLast(); cursor.moveToNext()) {
            String repoUrl = cursor.getString(0);
            Repo repo = RepoFactory.getFromUri(context, repoUrl);
            if (repo != null) {
                result.put(repoUrl, repo);
            } else {
                Log.e(TAG, "Unsupported repository URL\"" + repoUrl + "\"");
            }
        }
    } finally {
        cursor.close();
    }
    return result;
}
Also used : Repo(com.orgzly.android.repos.Repo) HashMap(java.util.HashMap)

Example 7 with Repo

use of com.orgzly.android.repos.Repo in project orgzly-android by orgzly.

the class MainActivity method onBookLinkSetRequest.

@Override
public void onBookLinkSetRequest(final long bookId) {
    final Book book = BooksClient.get(this, bookId);
    if (book == null) {
        return;
    }
    Map<String, Repo> repos = ReposClient.getAll(this);
    if (repos.size() == 0) {
        showSnackbarWithReposLink(getString(R.string.no_repos));
        return;
    }
    LinkedHashMap<String, Integer> items = new LinkedHashMap<>();
    int itemIndex = 0;
    /* Add "no link" item. */
    items.put(getString(R.string.no_link), itemIndex++);
    /* Add repositories. */
    for (String repoUri : repos.keySet()) {
        items.put(repoUri, itemIndex++);
    }
    View view = getLayoutInflater().inflate(R.layout.dialog_spinner, null, false);
    final Spinner spinner = (Spinner) view.findViewById(R.id.dialog_spinner);
    ArrayAdapter<String> adapter = new ArrayAdapter<>(spinner.getContext(), R.layout.spinner_item, new ArrayList<>(items.keySet()));
    adapter.setDropDownViewResource(R.layout.dropdown_item);
    spinner.setAdapter(adapter);
    /* Set spinner to current book's link. */
    if (book.hasLink()) {
        Integer pos = items.get(book.getLinkRepo().toString());
        if (pos != null) {
            spinner.setSelection(pos);
        }
    }
    DialogInterface.OnClickListener dialogClickListener = (dialog, which) -> {
        switch(which) {
            case DialogInterface.BUTTON_POSITIVE:
                Shelf shelf = new Shelf(MainActivity.this);
                String repoUrl = (String) spinner.getSelectedItem();
                if (getString(R.string.no_link).equals(repoUrl)) {
                    shelf.setLink(book, null);
                } else {
                    shelf.setLink(book, repoUrl);
                }
                break;
            case DialogInterface.BUTTON_NEGATIVE:
                break;
        }
    };
    new AlertDialog.Builder(this).setTitle("Link " + MiscUtils.quotedString(book.getName()) + " to repository").setView(view).setPositiveButton(R.string.set, dialogClickListener).setNegativeButton(R.string.cancel, dialogClickListener).show();
}
Also used : NavigationView(android.support.design.widget.NavigationView) Shelf(com.orgzly.android.Shelf) Bundle(android.os.Bundle) Notifications(com.orgzly.android.Notifications) FilterFragment(com.orgzly.android.ui.fragments.FilterFragment) SearchView(android.support.v7.widget.SearchView) Uri(android.net.Uri) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) Note(com.orgzly.android.Note) TextInputLayout(android.support.design.widget.TextInputLayout) BooksClient(com.orgzly.android.provider.clients.BooksClient) ActivityUtils(com.orgzly.android.ui.util.ActivityUtils) CheckBox(android.widget.CheckBox) Query(com.orgzly.android.query.Query) BookPrefaceFragment(com.orgzly.android.ui.fragments.BookPrefaceFragment) Handler(android.os.Handler) Map(java.util.Map) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) Repo(com.orgzly.android.repos.Repo) ActionMode(android.support.v7.view.ActionMode) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) NotesBatch(com.orgzly.android.NotesBatch) Set(java.util.Set) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) AlertDialog(android.app.AlertDialog) TextView(android.widget.TextView) BookFragment(com.orgzly.android.ui.fragments.BookFragment) SyncFragment(com.orgzly.android.ui.fragments.SyncFragment) Book(com.orgzly.android.Book) BuildConfig(com.orgzly.BuildConfig) SimpleOneLinerDialog(com.orgzly.android.ui.dialogs.SimpleOneLinerDialog) NoteListFragment(com.orgzly.android.ui.fragments.NoteListFragment) BooksFragment(com.orgzly.android.ui.fragments.BooksFragment) Snackbar(android.support.design.widget.Snackbar) OrgDateTime(com.orgzly.org.datetime.OrgDateTime) TextWatcher(android.text.TextWatcher) DottedQueryBuilder(com.orgzly.android.query.user.DottedQueryBuilder) MiscUtils(com.orgzly.android.util.MiscUtils) Context(android.content.Context) Intent(android.content.Intent) StringRes(android.support.annotation.StringRes) NonNull(android.support.annotation.NonNull) Editable(android.text.Editable) AppPermissions(com.orgzly.android.util.AppPermissions) TypedArray(android.content.res.TypedArray) MenuItem(android.view.MenuItem) SettingsActivity(com.orgzly.android.ui.settings.SettingsActivity) ArrayList(java.util.ArrayList) GravityCompat(android.support.v4.view.GravityCompat) LinkedHashMap(java.util.LinkedHashMap) AppPreferences(com.orgzly.android.prefs.AppPreferences) NoteFragment(com.orgzly.android.ui.fragments.NoteFragment) R(com.orgzly.R) Menu(android.view.Menu) AppIntent(com.orgzly.android.AppIntent) DrawerLayout(android.support.v4.widget.DrawerLayout) FiltersFragment(com.orgzly.android.ui.fragments.FiltersFragment) DialogInterface(android.content.DialogInterface) CompoundButton(android.widget.CompoundButton) TextUtils(android.text.TextUtils) IOException(java.io.IOException) File(java.io.File) Spinner(android.widget.Spinner) Filter(com.orgzly.android.filter.Filter) ArrayAdapter(android.widget.ArrayAdapter) ReposClient(com.orgzly.android.provider.clients.ReposClient) Toolbar(android.support.v7.widget.Toolbar) Configuration(android.content.res.Configuration) Condition(com.orgzly.android.query.Condition) ActionService(com.orgzly.android.ActionService) BookName(com.orgzly.android.BookName) Activity(android.app.Activity) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) EditText(android.widget.EditText) LogUtils(com.orgzly.android.util.LogUtils) AlertDialog(android.app.AlertDialog) DialogInterface(android.content.DialogInterface) Spinner(android.widget.Spinner) Shelf(com.orgzly.android.Shelf) NavigationView(android.support.design.widget.NavigationView) SearchView(android.support.v7.widget.SearchView) View(android.view.View) DrawerNavigationView(com.orgzly.android.ui.drawer.DrawerNavigationView) TextView(android.widget.TextView) LinkedHashMap(java.util.LinkedHashMap) Repo(com.orgzly.android.repos.Repo) Book(com.orgzly.android.Book) ArrayAdapter(android.widget.ArrayAdapter)

Example 8 with Repo

use of com.orgzly.android.repos.Repo in project orgzly-android by orgzly.

the class ReposActivity method onRepoEditRequest.

@Override
public void onRepoEditRequest(long id) {
    String url = ReposClient.getUrl(this, id);
    Repo repo = RepoFactory.getFromUri(this, url);
    if (repo instanceof DropboxRepo || repo instanceof MockRepo) {
        // TODO: Remove Mock from here
        displayRepoFragment(DropboxRepoFragment.getInstance(id), DropboxRepoFragment.FRAGMENT_TAG);
    } else if (repo instanceof DirectoryRepo || repo instanceof ContentRepo) {
        displayRepoFragment(DirectoryRepoFragment.getInstance(id), DirectoryRepoFragment.FRAGMENT_TAG);
    } else {
        showSimpleSnackbarLong(R.string.message_unsupported_repository_type);
    }
}
Also used : MockRepo(com.orgzly.android.repos.MockRepo) DropboxRepo(com.orgzly.android.repos.DropboxRepo) ContentRepo(com.orgzly.android.repos.ContentRepo) Repo(com.orgzly.android.repos.Repo) DirectoryRepo(com.orgzly.android.repos.DirectoryRepo) MockRepo(com.orgzly.android.repos.MockRepo) DirectoryRepo(com.orgzly.android.repos.DirectoryRepo) DropboxRepo(com.orgzly.android.repos.DropboxRepo) ContentRepo(com.orgzly.android.repos.ContentRepo)

Example 9 with Repo

use of com.orgzly.android.repos.Repo in project orgzly-android by orgzly.

the class DirectoryRepoFragment method save.

private void save() {
    String uriString = mUriView.getText().toString().trim();
    if (TextUtils.isEmpty(uriString)) {
        directoryInputLayout.setError(getString(R.string.can_not_be_empty));
        return;
    } else {
        directoryInputLayout.setError(null);
    }
    Uri uri = Uri.parse(uriString);
    Repo repo = RepoFactory.getFromUri(getActivity(), uri);
    if (repo == null) {
        directoryInputLayout.setError(getString(R.string.invalid_repo_url, uri));
        return;
    }
    /* Check for storage permission. */
    if (repo instanceof DirectoryRepo && !AppPermissions.INSTANCE.isGrantedOrRequest((CommonActivity) getActivity(), AppPermissions.Usage.LOCAL_REPO)) {
        return;
    }
    if (getArguments() != null && getArguments().containsKey(ARG_REPO_ID)) {
        // Existing repo
        long repoId = getArguments().getLong(ARG_REPO_ID);
        if (mListener != null) {
            mListener.onRepoUpdateRequest(repoId, repo);
        }
    } else {
        if (mListener != null) {
            mListener.onRepoCreateRequest(repo);
        }
    }
}
Also used : Repo(com.orgzly.android.repos.Repo) DirectoryRepo(com.orgzly.android.repos.DirectoryRepo) DirectoryRepo(com.orgzly.android.repos.DirectoryRepo) Uri(android.net.Uri)

Example 10 with Repo

use of com.orgzly.android.repos.Repo in project orgzly-android by orgzly.

the class Shelf method groupAllNotebooksByName.

/**
 * Compares every local book with every remote one and calculates the status for each link.
 *
 * @return number of links (unique book names)
 * @throws IOException
 */
public Map<String, BookNamesake> groupAllNotebooksByName() throws IOException {
    if (BuildConfig.LOG_DEBUG)
        LogUtils.d(TAG, "Collecting all local and remote books ...");
    Map<String, Repo> repos = ReposClient.getAll(mContext);
    List<Book> localBooks = getBooks();
    List<VersionedRook> versionedRooks = getBooksFromAllRepos(repos);
    /* Group local and remote books by name. */
    Map<String, BookNamesake> namesakes = BookNamesake.getAll(mContext, localBooks, versionedRooks);
    /* If there is no local book, create empty "dummy" one. */
    for (BookNamesake namesake : namesakes.values()) {
        if (namesake.getBook() == null) {
            Book book = createDummyBook(namesake.getName());
            namesake.setBook(book);
        }
        namesake.updateStatus(repos.size());
    }
    return namesakes;
}
Also used : VersionedRook(com.orgzly.android.repos.VersionedRook) Repo(com.orgzly.android.repos.Repo) BookNamesake(com.orgzly.android.sync.BookNamesake)

Aggregations

Repo (com.orgzly.android.repos.Repo)11 VersionedRook (com.orgzly.android.repos.VersionedRook)5 IOException (java.io.IOException)4 Uri (android.net.Uri)3 DirectoryRepo (com.orgzly.android.repos.DirectoryRepo)2 OrgParsedFile (com.orgzly.org.parser.OrgParsedFile)2 File (java.io.File)2 Activity (android.app.Activity)1 AlertDialog (android.app.AlertDialog)1 BroadcastReceiver (android.content.BroadcastReceiver)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 Intent (android.content.Intent)1 IntentFilter (android.content.IntentFilter)1 Configuration (android.content.res.Configuration)1 TypedArray (android.content.res.TypedArray)1 Bundle (android.os.Bundle)1 Handler (android.os.Handler)1 NonNull (android.support.annotation.NonNull)1 StringRes (android.support.annotation.StringRes)1