Search in sources :

Example 11 with GitHubClient

use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.

the class StarContentTask method onPreExecute.

@Override
protected void onPreExecute() {
    context = fragment.getContentView().getContext();
    flag = fragment.getFlag();
    adapter = fragment.getContentItemAdapter();
    list = fragment.getContentItemList();
    bookmark = fragment.getBookmark();
    GitHubClient client = fragment.getClient();
    dataService = new DataService(client);
    owner = fragment.getOwner();
    name = fragment.getName();
    root = fragment.getRoot();
    entry = fragment.getEntry();
    if (flag == Flag.STAR_CONTENT_FIRST || flag == Flag.STAR_CONTENT_REFRESH) {
        fragment.setContentEmpty(false);
        fragment.setContentShown(false);
        bookmark.setVisible(false);
    }
}
Also used : GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) DataService(org.eclipse.egit.github.core.service.DataService)

Example 12 with GitHubClient

use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.

the class MainFragment method onActivityCreated.

@Override
public void onActivityCreated(Bundle savedInstanceState) {
    super.onActivityCreated(savedInstanceState);
    setContentView(R.layout.main_fragment);
    view = getContentView();
    setContentEmpty(false);
    setContentShown(true);
    listView = (ListView) view.findViewById(R.id.main_fragment_listview);
    actionBar = getActivity().getActionBar();
    ViewGroup group = (ViewGroup) view;
    pull = new PullToRefreshLayout(group.getContext());
    ActionBarPullToRefresh.from(getActivity()).insertLayoutInto(group).setup(pull);
    imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
    final Drawable searchIcon = getResources().getDrawable(R.drawable.ic_action_cancel);
    search.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            if (searchIcon != null && event.getAction() == MotionEvent.ACTION_UP) {
                int eventX = (int) event.getRawX();
                int eventY = (int) event.getRawY();
                Rect rectR = new Rect();
                search.getGlobalVisibleRect(rectR);
                rectR.left = rectR.right - 100;
                if (rectR.contains(eventX, eventY)) {
                    search.setText("");
                }
            }
            return false;
        }
    });
    search.setOnEditorActionListener(new TextView.OnEditorActionListener() {

        @Override
        public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
            if (actionId == EditorInfo.IME_ACTION_SEND) {
                String query = search.getText().toString();
                if (query.length() > 0) {
                    if (addTask != null && addTask.getStatus() == AsyncTask.Status.FINISHED) {
                        addTask = new AddTask(MainFragment.this, query);
                        addTask.execute();
                    } else if (addTask == null) {
                        addTask = new AddTask(MainFragment.this, query);
                        addTask.execute();
                    } else {
                    /* Do nothing */
                    }
                }
            }
            return false;
        }
    });
    search.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            clickWhenSearchItem(view);
        }
    });
    repoItemAdapter = new RepoItemAdapter(MainFragment.this, view.getContext(), R.layout.repo_item, repoItemList);
    repoItemAdapter.notifyDataSetChanged();
    listView.setAdapter(repoItemAdapter);
    starItemAdapter = new StarItemAdapter(MainFragment.this, view.getContext(), R.layout.repo_item, starItemList);
    starItemAdapter.notifyDataSetChanged();
    bookmarkItemAdapter = new BookmarkItemAdapter(view.getContext(), R.layout.bookmark_item, bookmarkItemList);
    bookmarkItemAdapter.notifyDataSetChanged();
    contentItemAdapter = new ContentItemAdapter(view.getContext(), R.layout.content_item, contentItemList);
    contentItemAdapter.notifyDataSetChanged();
    commitItemAdapter = new CommitItemAdapter(view.getContext(), R.layout.commit_item, commitItemList);
    commitItemAdapter.notifyDataSetChanged();
    sp = getActivity().getSharedPreferences(getString(R.string.login_sp), Context.MODE_PRIVATE);
    String OAuth = sp.getString(getString(R.string.login_sp_oauth), null);
    client = new GitHubClient();
    client.setOAuth2Token(OAuth);
    Intent intent = getActivity().getIntent();
    if (intent.getBooleanExtra(getString(R.string.login_intent), false)) {
        flag = Flag.REPO_FIRST;
        repoTask = new RepoTask(MainFragment.this);
        repoTask.execute();
    } else {
        flag = Flag.REPO_SECOND;
        repoTask = new RepoTask(MainFragment.this);
        repoTask.execute();
    }
    currentId = REPO_ID;
    toggle = false;
    listView.setChoiceMode(ListView.CHOICE_MODE_MULTIPLE_MODAL);
    listView.setMultiChoiceModeListener(new AbsListView.MultiChoiceModeListener() {

        @Override
        public void onItemCheckedStateChanged(ActionMode mode, int position, long id, boolean checked) {
            Integer integer = listView.getCheckedItemCount();
            mode.setTitle(integer.toString());
        }

        @Override
        public boolean onCreateActionMode(ActionMode mode, Menu menu) {
            MenuInflater inflater = getActivity().getMenuInflater();
            switch(currentId) {
                case BOOKMARK_ID:
                    inflater.inflate(R.menu.bookmark_choice_menu, menu);
                    return true;
                case REPO_CONTENT_ID:
                    inflater.inflate(R.menu.content_choice_menu, menu);
                    return true;
                case STAR_CONTENT_ID:
                    inflater.inflate(R.menu.content_choice_menu, menu);
                    return true;
                default:
                    break;
            }
            return false;
        }

        @Override
        public boolean onPrepareActionMode(ActionMode mode, Menu menu) {
            /* Do nothing */
            return false;
        }

        @Override
        public boolean onActionItemClicked(ActionMode mode, MenuItem item) {
            return clickWhenActionItem(item, view.getContext());
        }

        @Override
        public void onDestroyActionMode(ActionMode mode) {
            SparseBooleanArray array = listView.getCheckedItemPositions();
            for (int i = 0; i < array.size(); i++) {
                if (array.valueAt(i)) {
                    listView.setItemChecked(i, false);
                }
            }
        }
    });
    listView.setOnItemClickListener(new AdapterView.OnItemClickListener() {

        @Override
        public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
            switch(currentId) {
                case REPO_ID:
                    clickWhenRepo(position);
                    break;
                case STAR_ID:
                    clickWhenStar(position);
                    break;
                case BOOKMARK_ID:
                    clickWhenBookmark(position);
                    break;
                case REPO_CONTENT_ID:
                    clickWhenRepoContent(position);
                    break;
                case STAR_CONTENT_ID:
                    clickWhenStarContent(position);
                    break;
                default:
                    break;
            }
        }
    });
}
Also used : StarItemAdapter(io.github.mthli.Bitocle.Star.StarItemAdapter) GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) SparseBooleanArray(android.util.SparseBooleanArray) BookmarkItemAdapter(io.github.mthli.Bitocle.Bookmark.BookmarkItemAdapter) PullToRefreshLayout(uk.co.senab.actionbarpulltorefresh.library.PullToRefreshLayout) ContentItemAdapter(io.github.mthli.Bitocle.Content.ContentItemAdapter) Rect(android.graphics.Rect) Drawable(android.graphics.drawable.Drawable) CommitItemAdapter(io.github.mthli.Bitocle.Commit.CommitItemAdapter) Intent(android.content.Intent)

Example 13 with GitHubClient

use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.

the class StarTask method onPreExecute.

@Override
protected void onPreExecute() {
    adapter = fragment.getStarItemAdapter();
    list = fragment.getStarItemList();
    bookmark = fragment.getBookmark();
    GitHubClient client = fragment.getClient();
    service = new WatcherService(client);
    fragment.setContentEmpty(false);
    fragment.setContentShown(false);
    bookmark.setVisible(false);
}
Also used : GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) WatcherService(org.eclipse.egit.github.core.service.WatcherService)

Example 14 with GitHubClient

use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.

the class CommitTask method onPreExecute.

@Override
protected void onPreExecute() {
    flag = fragment.getFlag();
    GitHubClient client = fragment.getClient();
    commitService = new CommitService(client);
    adapter = fragment.getCommitItemAdapter();
    list = fragment.getCommitItemList();
    fragment.setContentShown(false);
}
Also used : GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) CommitService(org.eclipse.egit.github.core.service.CommitService)

Example 15 with GitHubClient

use of org.eclipse.egit.github.core.client.GitHubClient in project Bitocle by mthli.

the class WebViewTask method doInBackground.

@Override
protected Boolean doInBackground(Void... params) {
    GitHubClient client = fragment.getClient();
    RepositoryId id = RepositoryId.create(owner, name);
    DataService dataService = new DataService(client);
    MarkdownService markdownService = new MarkdownService(client);
    Blob blob;
    try {
        blob = dataService.getBlob(id, sha);
    } catch (IOException i) {
        return false;
    }
    if (isCancelled()) {
        return false;
    }
    String base64 = blob.getContent();
    if (!MimeType.isImage(filename)) {
        byte[] bytes = EncodingUtils.fromBase64(base64);
        content = new String(bytes);
    }
    if (MimeType.isImage(filename)) {
        String imageUrl = GetImage.getImageUrl(base64, MimeType.getImageExtension(filename));
        image = GetImage.getImage(imageUrl);
    } else if (MimeType.isMarkdown(filename)) {
        try {
            content = markdownService.getHtml(content, MarkdownService.MODE_GFM);
            content = StyleMarkdown.styleMarkdown(content);
        } catch (IOException i) {
            return false;
        }
    } else {
        content = SyntaxCode.syntaxCode(content, css);
    }
    if (isCancelled()) {
        return false;
    }
    return true;
}
Also used : GitHubClient(org.eclipse.egit.github.core.client.GitHubClient) Blob(org.eclipse.egit.github.core.Blob) MarkdownService(org.eclipse.egit.github.core.service.MarkdownService) IOException(java.io.IOException) RepositoryId(org.eclipse.egit.github.core.RepositoryId) DataService(org.eclipse.egit.github.core.service.DataService)

Aggregations

GitHubClient (org.eclipse.egit.github.core.client.GitHubClient)16 Intent (android.content.Intent)3 IOException (java.io.IOException)3 DataService (org.eclipse.egit.github.core.service.DataService)3 RepositoryService (org.eclipse.egit.github.core.service.RepositoryService)3 WatcherService (org.eclipse.egit.github.core.service.WatcherService)3 ArrayList (java.util.ArrayList)2 OAuthUserProvider (net.idlesoft.android.apps.github.authenticator.OAuthUserProvider)2 User (org.eclipse.egit.github.core.User)2 UserService (org.eclipse.egit.github.core.service.UserService)2 Account (android.accounts.Account)1 AccountsException (android.accounts.AccountsException)1 NetworkErrorException (android.accounts.NetworkErrorException)1 SharedPreferences (android.content.SharedPreferences)1 Rect (android.graphics.Rect)1 Drawable (android.graphics.drawable.Drawable)1 Bundle (android.os.Bundle)1 SparseBooleanArray (android.util.SparseBooleanArray)1 View (android.view.View)1 WebSettings (android.webkit.WebSettings)1