Search in sources :

Example 11 with Shelf

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);
    }
}
Also used : Shelf(com.orgzly.android.Shelf)

Example 12 with Shelf

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();
}
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 13 with Shelf

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();
    }
}
Also used : Shelf(com.orgzly.android.Shelf) DropboxClient(com.orgzly.android.repos.DropboxClient) DropboxRepoFragment(com.orgzly.android.ui.fragments.DropboxRepoFragment) ReposFragment(com.orgzly.android.ui.fragments.ReposFragment) FileBrowserFragment(com.orgzly.android.ui.fragments.browser.FileBrowserFragment) Fragment(android.support.v4.app.Fragment) DirectoryRepoFragment(com.orgzly.android.ui.fragments.DirectoryRepoFragment) Toolbar(android.support.v7.widget.Toolbar)

Example 14 with Shelf

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;
}
Also used : Query(com.orgzly.android.query.Query) Book(com.orgzly.android.Book) DottedQueryParser(com.orgzly.android.query.user.DottedQueryParser) Shelf(com.orgzly.android.Shelf) IOException(java.io.IOException) Uri(android.net.Uri) File(java.io.File)

Example 15 with Shelf

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());
}
Also used : Shelf(com.orgzly.android.Shelf)

Aggregations

Shelf (com.orgzly.android.Shelf)16 Book (com.orgzly.android.Book)4 Intent (android.content.Intent)3 AppIntent (com.orgzly.android.AppIntent)3 Note (com.orgzly.android.Note)3 IOException (java.io.IOException)3 Uri (android.net.Uri)2 Fragment (android.support.v4.app.Fragment)2 Toolbar (android.support.v7.widget.Toolbar)2 Query (com.orgzly.android.query.Query)2 File (java.io.File)2 SuppressLint (android.annotation.SuppressLint)1 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 IntentFilter (android.content.IntentFilter)1 Configuration (android.content.res.Configuration)1 TypedArray (android.content.res.TypedArray)1