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;
}
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();
}
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);
}
}
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);
}
}
}
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;
}
Aggregations