Search in sources :

Example 11 with Item

use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.

the class SinglePageItemRecyclerViewAdapter method attach.

@Override
public void attach(Context context, RecyclerView recyclerView) {
    super.attach(context, recyclerView);
    mLevelIndicatorWidth = AppUtils.getDimensionInDp(mContext, R.dimen.level_indicator_width);
    mColors = mResourcesProvider.obtainTypedArray(R.array.color_codes);
    mItemTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.RIGHT) {

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            return false;
        }

        @Override
        public int getSwipeDirs(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            Item item = getItem(viewHolder.getAdapterPosition());
            if (item == null || item.getKidCount() == 0) {
                return 0;
            }
            return super.getSwipeDirs(recyclerView, viewHolder);
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            int position = viewHolder.getAdapterPosition();
            Item item = getItem(position);
            if (item != null) {
                notifyItemChanged(position);
                toggleKids(item);
            }
        }

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
            float swipeWidth = viewHolder.itemView.getWidth() * getSwipeThreshold(viewHolder);
            dX = Math.max(dX, -swipeWidth);
            dX = Math.min(dX, swipeWidth);
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }

        @Override
        public float getSwipeThreshold(RecyclerView.ViewHolder viewHolder) {
            return 0.1f;
        }
    });
    mItemTouchHelper.attachToRecyclerView(recyclerView);
    recyclerView.addOnScrollListener(mScrollListener);
}
Also used : ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) Item(io.github.hidroh.materialistic.data.Item) Canvas(android.graphics.Canvas) RecyclerView(android.support.v7.widget.RecyclerView)

Example 12 with Item

use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.

the class WebFragment method setUpWebControls.

private void setUpWebControls(View view) {
    view.findViewById(R.id.toolbar_web).setOnClickListener(v -> scrollToTop());
    view.findViewById(R.id.button_back).setOnClickListener(v -> mWebView.goBack());
    view.findViewById(R.id.button_forward).setOnClickListener(v -> mWebView.goForward());
    view.findViewById(R.id.button_clear).setOnClickListener(v -> {
        mSystemUiHelper.setFullscreen(true);
        reset();
        mControls.showNext();
    });
    view.findViewById(R.id.button_find).setOnClickListener(v -> {
        mEditText.requestFocus();
        toggleSoftKeyboard(true);
        mControls.showNext();
    });
    mButtonRefresh.setOnClickListener(v -> {
        if (mWebView.getProgress() < 100) {
            mWebView.stopLoading();
        } else {
            mWebView.reload();
        }
    });
    view.findViewById(R.id.button_exit).setOnClickListener(v -> LocalBroadcastManager.getInstance(getActivity()).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(EXTRA_FULLSCREEN, false)));
    mButtonNext.setOnClickListener(v -> mWebView.findNext(true));
    mButtonMore.setOnClickListener(v -> mPopupMenu.create(getActivity(), mButtonMore, Gravity.NO_GRAVITY).inflate(R.menu.menu_web).setOnMenuItemClickListener(item -> {
        if (item.getItemId() == R.id.menu_font_options) {
            showPreferences();
            return true;
        }
        if (item.getItemId() == R.id.menu_zoom_in) {
            mWebView.zoomIn();
            return true;
        }
        if (item.getItemId() == R.id.menu_zoom_out) {
            mWebView.zoomOut();
            return true;
        }
        return false;
    }).setMenuItemVisible(R.id.menu_font_options, fontEnabled()).show());
    mEditText.setOnEditorActionListener((v, actionId, event) -> {
        findInPage();
        return true;
    });
}
Also used : Context(android.content.Context) ImageButton(android.widget.ImageButton) PopupMenu(io.github.hidroh.materialistic.widget.PopupMenu) AdBlockWebViewClient(io.github.hidroh.materialistic.widget.AdBlockWebViewClient) Bundle(android.os.Bundle) ProgressBar(android.widget.ProgressBar) Uri(android.net.Uri) Intent(android.content.Intent) NonNull(android.support.annotation.NonNull) LocalBroadcastManager(android.support.v4.content.LocalBroadcastManager) DialogFragment(android.support.v4.app.DialogFragment) MenuItem(android.view.MenuItem) InputMethodManager(android.view.inputmethod.InputMethodManager) Inject(javax.inject.Inject) ReadabilityClient(io.github.hidroh.materialistic.data.ReadabilityClient) SuppressLint(android.annotation.SuppressLint) WebView(io.github.hidroh.materialistic.widget.WebView) MenuInflater(android.view.MenuInflater) Toast(android.widget.Toast) Menu(android.view.Menu) View(android.view.View) VISIBLE(android.view.View.VISIBLE) Synthetic(io.github.hidroh.materialistic.annotation.Synthetic) NestedScrollView(android.support.v4.widget.NestedScrollView) Named(javax.inject.Named) Build(android.os.Build) WeakReference(java.lang.ref.WeakReference) ViewSwitcher(android.widget.ViewSwitcher) LayoutInflater(android.view.LayoutInflater) IntentFilter(android.content.IntentFilter) Fragment(android.support.v4.app.Fragment) WebItem(io.github.hidroh.materialistic.data.WebItem) TextUtils(android.text.TextUtils) Item(io.github.hidroh.materialistic.data.Item) BroadcastReceiver(android.content.BroadcastReceiver) ViewGroup(android.view.ViewGroup) ResponseListener(io.github.hidroh.materialistic.data.ResponseListener) Color(android.graphics.Color) CacheableWebView(io.github.hidroh.materialistic.widget.CacheableWebView) Gravity(android.view.Gravity) GONE(android.view.View.GONE) Bitmap(android.graphics.Bitmap) ItemManager(io.github.hidroh.materialistic.data.ItemManager) Nullable(android.support.annotation.Nullable) EditText(android.widget.EditText) Intent(android.content.Intent)

Example 13 with Item

use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.

the class StoryRecyclerViewAdapter method setUpdated.

private void setUpdated(ArrayList<Item> items) {
    if (!mHighlightUpdated || getItems() == null) {
        return;
    }
    mUpdated.clear();
    mUpdatedPositions.clear();
    mPromoted.clear();
    for (Item item : items) {
        Integer position = mItemPositions.get(item.getLongId());
        if (position == null) {
            mUpdated.add(item);
            mUpdatedPositions.put(item.getLongId(), mUpdated.size() - 1);
        } else {
            Item currentRevision = mItems.get(position);
            item.setLastKidCount(currentRevision.getLastKidCount());
            int lastRank = currentRevision.getRank();
            if (lastRank > item.getRank()) {
                mPromoted.put(item.getId(), lastRank - item.getRank());
            }
        }
    }
    if (!mUpdated.isEmpty()) {
        notifyUpdated();
    }
}
Also used : Item(io.github.hidroh.materialistic.data.Item)

Example 14 with Item

use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.

the class StoryView method setStory.

public void setStory(@NonNull WebItem story, int hotThreshold) {
    if (!mIsLocal && story instanceof Item) {
        Item item = (Item) story;
        boolean hot = item.getScore() >= hotThreshold * AppUtils.HOT_FACTOR;
        mScoreTextView.setTextColor(hot ? mHotColorResId : mSecondaryTextColorResId);
        mRankTextView.setText(String.valueOf(item.getRank()));
        mScoreTextView.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, hot ? R.drawable.ic_whatshot_orange500_18dp : 0);
        mScoreTextView.setText(getContext().getResources().getQuantityString(R.plurals.score, item.getScore(), item.getScore()));
        if (item.getKidCount() > 0) {
            hot = item.getKidCount() >= hotThreshold;
            mCommentButton.setTextColor(hot ? mHotColorResId : mAccentColorResId);
            if (hot) {
                mCommentButton.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_whatshot_orange500_24dp, 0, 0, 0);
            } else {
                mCommentButton.setCompoundDrawablesWithIntrinsicBounds(mCommentDrawable, null, null, null);
            }
            mCommentButton.setText(String.valueOf(item.getKidCount()));
        } else {
            mCommentButton.setTextColor(mAccentColorResId);
            mCommentButton.setText(null);
            mCommentButton.setCompoundDrawablesWithIntrinsicBounds(mCommentDrawable, null, null, null);
        }
    }
    mCommentButton.setVisibility(View.VISIBLE);
    mTitleTextView.setText(getContext().getString(R.string.loading_text));
    mTitleTextView.setText(story.getDisplayedTitle());
    mPostedTextView.setText(story.getDisplayedTime(getContext()));
    mPostedTextView.append(story.getDisplayedAuthor(getContext(), false, 0));
    switch(story.getType()) {
        case Item.JOB_TYPE:
            mSourceTextView.setText(null);
            mSourceTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_work_white_18dp, 0, 0, 0);
            break;
        case Item.POLL_TYPE:
            mSourceTextView.setText(null);
            mSourceTextView.setCompoundDrawablesWithIntrinsicBounds(R.drawable.ic_poll_white_18dp, 0, 0, 0);
            break;
        default:
            mSourceTextView.setText(story.getSource());
            mSourceTextView.setCompoundDrawables(null, null, null, null);
            break;
    }
}
Also used : WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item)

Example 15 with Item

use of io.github.hidroh.materialistic.data.Item in project materialistic by hidroh.

the class AppUtils method toggleFabAction.

public static void toggleFabAction(FloatingActionButton fab, WebItem item, boolean commentMode) {
    Context context = fab.getContext();
    fab.setImageResource(commentMode ? R.drawable.ic_reply_white_24dp : R.drawable.ic_zoom_out_map_white_24dp);
    fab.setOnClickListener(v -> {
        if (commentMode) {
            context.startActivity(new Intent(context, ComposeActivity.class).putExtra(ComposeActivity.EXTRA_PARENT_ID, item.getId()).putExtra(ComposeActivity.EXTRA_PARENT_TEXT, item instanceof Item ? ((Item) item).getText() : null));
        } else {
            LocalBroadcastManager.getInstance(context).sendBroadcast(new Intent(WebFragment.ACTION_FULLSCREEN).putExtra(WebFragment.EXTRA_FULLSCREEN, true));
        }
    });
}
Also used : Context(android.content.Context) WebItem(io.github.hidroh.materialistic.data.WebItem) Item(io.github.hidroh.materialistic.data.Item) CustomTabsIntent(android.support.customtabs.CustomTabsIntent) PendingIntent(android.app.PendingIntent) Intent(android.content.Intent)

Aggregations

Item (io.github.hidroh.materialistic.data.Item)16 WebItem (io.github.hidroh.materialistic.data.WebItem)6 Bundle (android.os.Bundle)4 Fragment (android.support.v4.app.Fragment)4 RecyclerView (android.support.v7.widget.RecyclerView)4 Intent (android.content.Intent)3 MenuItem (android.view.MenuItem)3 Context (android.content.Context)2 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)2 Synthetic (io.github.hidroh.materialistic.annotation.Synthetic)2 TestHnItem (io.github.hidroh.materialistic.data.TestHnItem)2 TestItem (io.github.hidroh.materialistic.test.TestItem)2 SlowTest (io.github.hidroh.materialistic.test.suite.SlowTest)2 Test (org.junit.Test)2 RoboMenuItem (org.robolectric.fakes.RoboMenuItem)2 SuppressLint (android.annotation.SuppressLint)1 PendingIntent (android.app.PendingIntent)1 BroadcastReceiver (android.content.BroadcastReceiver)1 ContentResolver (android.content.ContentResolver)1 IntentFilter (android.content.IntentFilter)1