use of com.orgzly.android.Shelf in project orgzly-android by orgzly.
the class MainActivity method actionModeDestroyed.
@Override
public void actionModeDestroyed() {
if (mActionMode != null) {
if ("M".equals(mActionMode.getTag()) && mPromoteDemoteOrMoveRequested) {
Shelf shelf = new Shelf(this);
shelf.syncOnNoteUpdate();
}
}
mPromoteDemoteOrMoveRequested = false;
mActionMode = null;
/* Unlock drawer. */
if (mDrawerLayout != null) {
mDrawerLayout.setDrawerLockMode(DrawerLayout.LOCK_MODE_UNLOCKED);
}
}
use of com.orgzly.android.Shelf 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.Shelf in project orgzly-android by orgzly.
the class ReposActivity method onCreate.
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_repos);
Toolbar myToolbar = findViewById(R.id.toolbar);
setSupportActionBar(myToolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
getSupportActionBar().setHomeButtonEnabled(true);
getSupportActionBar().setTitle(R.string.repositories);
mShelf = new Shelf(getApplicationContext());
mDropboxClient = new DropboxClient(getApplicationContext());
if (savedInstanceState == null) {
Fragment fragment = ReposFragment.getInstance();
getSupportFragmentManager().beginTransaction().replace(R.id.activity_repos_frame, fragment, ReposFragment.FRAGMENT_TAG).commit();
}
}
use of com.orgzly.android.Shelf in project orgzly-android by orgzly.
the class ShareActivity method getDataFromIntent.
public Data getDataFromIntent(Intent intent) {
Data data = new Data();
mError = null;
String action = intent.getAction();
String type = intent.getType();
if (action == null) {
// mError = getString(R.string.share_action_not_set);
} else if (type == null) {
// mError = getString(R.string.share_type_not_set);
} else if (action.equals(Intent.ACTION_SEND)) {
if (type.startsWith("text/")) {
if (intent.hasExtra(Intent.EXTRA_TEXT)) {
data.title = intent.getStringExtra(Intent.EXTRA_TEXT);
} else if (intent.hasExtra(Intent.EXTRA_STREAM)) {
Uri uri = intent.getParcelableExtra(Intent.EXTRA_STREAM);
data.title = uri.getLastPathSegment();
/*
* Store file's content as note content.
*/
try {
File file = new File(uri.getPath());
/* Don't read large files. */
if (file.length() > MAX_TEXT_FILE_LENGTH_FOR_CONTENT) {
mError = "File has " + file.length() + " bytes (refusing to read files larger then " + MAX_TEXT_FILE_LENGTH_FOR_CONTENT + " bytes)";
} else {
data.content = MiscUtils.readStringFromFile(file);
}
} catch (IOException e) {
e.printStackTrace();
mError = "Failed reading the content of " + uri.toString() + ": " + e.toString();
}
}
if (data.title != null && data.content == null && intent.hasExtra(Intent.EXTRA_SUBJECT)) {
data.content = data.title;
data.title = intent.getStringExtra(Intent.EXTRA_SUBJECT);
}
if (intent.hasExtra(AppIntent.EXTRA_FILTER)) {
Query query = new DottedQueryParser().parse(intent.getStringExtra(AppIntent.EXTRA_FILTER));
String bookName = QueryUtils.INSTANCE.extractFirstBookNameFromQuery(query.getCondition());
if (bookName != null) {
Book book = new Shelf(this).getBook(bookName);
if (book != null) {
data.bookId = book.getId();
}
}
}
} else {
mError = getString(R.string.share_type_not_supported, type);
}
} else if (action.equals("com.google.android.gm.action.AUTO_SEND")) {
if (type.startsWith("text/") && intent.hasExtra(Intent.EXTRA_TEXT)) {
data.title = intent.getStringExtra(Intent.EXTRA_TEXT);
}
} else {
mError = getString(R.string.share_action_not_supported, action);
}
/* Make sure that title is never empty. */
if (data.title == null) {
data.title = "";
}
return data;
}
use of com.orgzly.android.Shelf in project orgzly-android by orgzly.
the class NoteListFragment method onActivityCreated.
@Override
public void onActivityCreated(@Nullable Bundle savedInstanceState) {
super.onActivityCreated(savedInstanceState);
mShelf = new Shelf(getActivity());
}
Aggregations