Search in sources :

Example 96 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project Douya by DreaminginCodeZH.

the class NotificationAdapter method onBindViewHolder.

@Override
public void onBindViewHolder(final ViewHolder holder, int position) {
    final Context context = RecyclerViewUtils.getContext(holder);
    final Notification notification = getItem(position);
    holder.itemView.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View view) {
            if (mListener != null) {
                mListener.onMarkNotificationAsRead(notification);
            }
            UriHandler.open(notification.targetUri, context);
        }
    });
    holder.textText.setText(notification.text);
    holder.textText.setTextColor(notification.read ? mTextColorSecondary : mTextColorPrimary);
    holder.timeText.setDoubanTime(notification.time);
}
Also used : Context(android.content.Context) TimeTextView(me.zhanghai.android.douya.ui.TimeTextView) BindView(butterknife.BindView) RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View) Notification(me.zhanghai.android.douya.network.api.info.frodo.Notification)

Example 97 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project ChipsLayoutManager by BelooS.

the class RecyclerViewAdapter method onCreateViewHolder.

@Override
public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    View itemView;
    switch(viewType) {
        case ITEM_TYPE_INCREASED:
            itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_increased, parent, false);
            break;
        default:
            itemView = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_simple, parent, false);
            break;
    }
    viewHolderCount++;
    //        Timber.w(TAG, "created holders = " + viewHolderCount);
    return new ViewHolder(itemView);
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) TextView(android.widget.TextView) View(android.view.View)

Example 98 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project AntennaPod by AntennaPod.

the class NewEpisodesFragment method onCreateView.

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View root = super.onCreateViewHelper(inflater, container, savedInstanceState, R.layout.all_episodes_fragment);
    ItemTouchHelper.SimpleCallback simpleItemTouchCallback = new ItemTouchHelper.SimpleCallback(0, ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {

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

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int swipeDir) {
            AllEpisodesRecycleAdapter.Holder holder = (AllEpisodesRecycleAdapter.Holder) viewHolder;
            Log.d(TAG, "remove(" + holder.getItemId() + ")");
            if (subscription != null) {
                subscription.unsubscribe();
            }
            FeedItem item = holder.getFeedItem();
            // we're marking it as unplayed since the user didn't actually play it
            // but they don't want it considered 'NEW' anymore
            DBWriter.markItemPlayed(FeedItem.UNPLAYED, item.getId());
            final Handler h = new Handler(getActivity().getMainLooper());
            final Runnable r = () -> {
                FeedMedia media = item.getMedia();
                if (media != null && media.hasAlmostEnded() && UserPreferences.isAutoDelete()) {
                    DBWriter.deleteFeedMediaOfItem(getActivity(), media.getId());
                }
            };
            Snackbar snackbar = Snackbar.make(root, getString(R.string.marked_as_seen_label), Snackbar.LENGTH_LONG);
            snackbar.setAction(getString(R.string.undo), v -> {
                DBWriter.markItemPlayed(FeedItem.NEW, item.getId());
                h.removeCallbacks(r);
            });
            snackbar.show();
            h.postDelayed(r, (int) Math.ceil(snackbar.getDuration() * 1.05f));
        }

        @Override
        public void onSelectedChanged(RecyclerView.ViewHolder viewHolder, int actionState) {
            // We only want the active item
            if (actionState != ItemTouchHelper.ACTION_STATE_IDLE) {
                if (viewHolder instanceof AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) {
                    AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder itemViewHolder = (AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) viewHolder;
                    itemViewHolder.onItemSelected();
                }
            }
            super.onSelectedChanged(viewHolder, actionState);
        }

        @Override
        public void clearView(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
            super.clearView(recyclerView, viewHolder);
            if (viewHolder instanceof AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) {
                AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder itemViewHolder = (AllEpisodesRecycleAdapter.ItemTouchHelperViewHolder) viewHolder;
                itemViewHolder.onItemClear();
            }
        }
    };
    ItemTouchHelper itemTouchHelper = new ItemTouchHelper(simpleItemTouchCallback);
    itemTouchHelper.attachToRecyclerView(recyclerView);
    return root;
}
Also used : AllEpisodesRecycleAdapter(de.danoeh.antennapod.adapter.AllEpisodesRecycleAdapter) Handler(android.os.Handler) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) FeedItem(de.danoeh.antennapod.core.feed.FeedItem) FeedMedia(de.danoeh.antennapod.core.feed.FeedMedia) RecyclerView(android.support.v7.widget.RecyclerView) Snackbar(android.support.design.widget.Snackbar)

Example 99 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project bilibili-android-client by HotBitmapGG.

the class SectionedRecyclerViewAdapter method onCreateViewHolder.

@Override
public RecyclerView.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
    RecyclerView.ViewHolder viewHolder = null;
    View view = null;
    for (Map.Entry<String, Integer> entry : sectionViewTypeNumbers.entrySet()) {
        if (viewType >= entry.getValue() && viewType < entry.getValue() + VIEW_TYPE_QTY) {
            Section section = sections.get(entry.getKey());
            int sectionViewType = viewType - entry.getValue();
            switch(sectionViewType) {
                case VIEW_TYPE_HEADER:
                    {
                        Integer resId = section.getHeaderResourceId();
                        if (resId == null) {
                            throw new NullPointerException("Missing 'header' resource id");
                        }
                        view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
                        // get the header viewholder from the section
                        viewHolder = section.getHeaderViewHolder(view);
                        break;
                    }
                case VIEW_TYPE_FOOTER:
                    {
                        Integer resId = section.getFooterResourceId();
                        if (resId == null) {
                            throw new NullPointerException("Missing 'footer' resource id");
                        }
                        view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
                        // get the footer viewholder from the section
                        viewHolder = section.getFooterViewHolder(view);
                        break;
                    }
                case VIEW_TYPE_ITEM_LOADED:
                    {
                        view = LayoutInflater.from(parent.getContext()).inflate(section.getItemResourceId(), parent, false);
                        // get the item viewholder from the section
                        viewHolder = section.getItemViewHolder(view);
                        break;
                    }
                case VIEW_TYPE_LOADING:
                    {
                        Integer resId = section.getLoadingResourceId();
                        if (resId == null) {
                            throw new NullPointerException("Missing 'loading state' resource id");
                        }
                        view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
                        // get the loading viewholder from the section
                        viewHolder = section.getLoadingViewHolder(view);
                        break;
                    }
                case VIEW_TYPE_FAILED:
                    {
                        Integer resId = section.getFailedResourceId();
                        if (resId == null) {
                            throw new NullPointerException("Missing 'failed state' resource id");
                        }
                        view = LayoutInflater.from(parent.getContext()).inflate(resId, parent, false);
                        // get the failed load viewholder from the section
                        viewHolder = section.getFailedViewHolder(view);
                        break;
                    }
                default:
                    throw new IllegalArgumentException("Invalid viewType");
            }
        }
    }
    return viewHolder;
}
Also used : RecyclerView(android.support.v7.widget.RecyclerView) RecyclerView(android.support.v7.widget.RecyclerView) View(android.view.View) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) HashMap(java.util.HashMap)

Example 100 with ViewHolder

use of android.support.v7.widget.RecyclerView.ViewHolder in project Gadgetbridge by Freeyourgadget.

the class ControlCenterv2 method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState) {
    if (GBApplication.isDarkThemeEnabled()) {
        setTheme(R.style.GadgetbridgeThemeDark_NoActionBar);
    } else {
        setTheme(R.style.GadgetbridgeTheme_NoActionBar);
    }
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_controlcenterv2);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);
    FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
    fab.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
            launchDiscoveryActivity();
        }
    });
    DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
    ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(this, drawer, toolbar, R.string.controlcenter_navigation_drawer_open, R.string.controlcenter_navigation_drawer_close);
    drawer.setDrawerListener(toggle);
    toggle.syncState();
    NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
    navigationView.setNavigationItemSelectedListener(this);
    //end of material design boilerplate
    deviceManager = ((GBApplication) getApplication()).getDeviceManager();
    deviceListView = (RecyclerView) findViewById(R.id.deviceListView);
    deviceListView.setHasFixedSize(true);
    deviceListView.setLayoutManager(new LinearLayoutManager(this));
    background = (ImageView) findViewById(R.id.no_items_bg);
    deviceList = deviceManager.getDevices();
    mGBDeviceAdapter = new GBDeviceAdapterv2(this, deviceList);
    deviceListView.setAdapter(this.mGBDeviceAdapter);
    ItemTouchHelper swipeToDismissTouchHelper = new ItemTouchHelper(new ItemTouchHelper.SimpleCallback(ItemTouchHelper.LEFT, ItemTouchHelper.RIGHT) {

        @Override
        public void onChildDraw(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
            if (dX > 50)
                dX = 50;
            super.onChildDraw(c, recyclerView, viewHolder, dX, dY, actionState, isCurrentlyActive);
        }

        @Override
        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
            GB.toast(getBaseContext(), "onMove", Toast.LENGTH_LONG, GB.ERROR);
            return false;
        }

        @Override
        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
            GB.toast(getBaseContext(), "onSwiped", Toast.LENGTH_LONG, GB.ERROR);
        }

        @Override
        public void onChildDrawOver(Canvas c, RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, float dX, float dY, int actionState, boolean isCurrentlyActive) {
        }
    });
    //uncomment to enable fixed-swipe to reveal more actions
    //swipeToDismissTouchHelper.attachToRecyclerView(deviceListView);
    registerForContextMenu(deviceListView);
    IntentFilter filterLocal = new IntentFilter();
    filterLocal.addAction(GBApplication.ACTION_QUIT);
    filterLocal.addAction(DeviceManager.ACTION_DEVICES_CHANGED);
    LocalBroadcastManager.getInstance(this).registerReceiver(mReceiver, filterLocal);
    refreshPairedDevices();
    /*
         * Ask for permission to intercept notifications on first run.
         */
    Prefs prefs = GBApplication.getPrefs();
    if (prefs.getBoolean("firstrun", true)) {
        prefs.getPreferences().edit().putBoolean("firstrun", false).apply();
        Intent enableIntent = new Intent("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS");
        startActivity(enableIntent);
    }
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
        checkAndRequestPermissions();
    }
    ChangeLog cl = new ChangeLog(this);
    if (cl.isFirstRun()) {
        cl.getLogDialog().show();
    }
    GBApplication.deviceService().start();
    if (GB.isBluetoothEnabled() && deviceList.isEmpty() && Build.VERSION.SDK_INT < Build.VERSION_CODES.M) {
        startActivity(new Intent(this, DiscoveryActivity.class));
    } else {
        GBApplication.deviceService().requestDeviceInfo();
    }
}
Also used : IntentFilter(android.content.IntentFilter) NavigationView(android.support.design.widget.NavigationView) Canvas(android.graphics.Canvas) ActionBarDrawerToggle(android.support.v7.app.ActionBarDrawerToggle) GBDeviceAdapterv2(nodomain.freeyourgadget.gadgetbridge.adapter.GBDeviceAdapterv2) Intent(android.content.Intent) LinearLayoutManager(android.support.v7.widget.LinearLayoutManager) Prefs(nodomain.freeyourgadget.gadgetbridge.util.Prefs) NavigationView(android.support.design.widget.NavigationView) ImageView(android.widget.ImageView) View(android.view.View) RecyclerView(android.support.v7.widget.RecyclerView) ItemTouchHelper(android.support.v7.widget.helper.ItemTouchHelper) FloatingActionButton(android.support.design.widget.FloatingActionButton) RecyclerView(android.support.v7.widget.RecyclerView) ChangeLog(de.cketti.library.changelog.ChangeLog) DrawerLayout(android.support.v4.widget.DrawerLayout) Toolbar(android.support.v7.widget.Toolbar)

Aggregations

RecyclerView (android.support.v7.widget.RecyclerView)248 View (android.view.View)233 TextView (android.widget.TextView)117 ImageView (android.widget.ImageView)87 ViewHolder (android.support.v7.widget.RecyclerView.ViewHolder)47 ViewGroup (android.view.ViewGroup)30 LayoutInflater (android.view.LayoutInflater)27 ItemTouchHelper (android.support.v7.widget.helper.ItemTouchHelper)26 LinearLayoutManager (android.support.v7.widget.LinearLayoutManager)25 Intent (android.content.Intent)24 ArrayList (java.util.ArrayList)24 Context (android.content.Context)17 ViewPropertyAnimatorCompat (android.support.v4.view.ViewPropertyAnimatorCompat)17 CardView (android.support.v7.widget.CardView)15 BindView (butterknife.BindView)15 Paint (android.graphics.Paint)11 ParallaxRecyclerAdapter (com.poliveira.parallaxrecycleradapter.ParallaxRecyclerAdapter)8 ExampleData (de.madcyph3r.example.data.ExampleData)8 Test (org.junit.Test)7 Drawable (android.graphics.drawable.Drawable)6